def fixup_document()

in src/key_server_common.py [0:0]


    def fixup_document(self, drm_system, system_id, content_id, kid):
        """
        Update the returned XML document based on the specified system ID
        """
        if system_id.lower() == HLS_AES_128_SYSTEM_ID.lower():
            ext_x_key = self.cache.url(content_id, kid)
            drm_system.find("{urn:dashif:org:cpix}URIExtXKey").text = base64.b64encode(ext_x_key.encode('utf-8')).decode('utf-8')
            drm_system.find("{urn:aws:amazon:com:speke}KeyFormat").text = base64.b64encode(HLS_AES_128_KEY_FORMAT.encode('utf-8')).decode('utf-8')
            drm_system.find("{urn:aws:amazon:com:speke}KeyFormatVersions").text = base64.b64encode(HLS_AES_128_KEY_FORMAT_VERSIONS.encode('utf-8')).decode('utf-8')
            self.safe_remove(drm_system, "{urn:dashif:org:cpix}ContentProtectionData")
            self.safe_remove(drm_system, "{urn:aws:amazon:com:speke}ProtectionHeader")
            self.safe_remove(drm_system, "{urn:dashif:org:cpix}PSSH")
        elif system_id.lower() == HLS_SAMPLE_AES_SYSTEM_ID.lower():
            ext_x_key = self.cache.url(content_id, kid)
            drm_system.find("{urn:dashif:org:cpix}URIExtXKey").text = base64.b64encode(ext_x_key.encode('utf-8')).decode('utf-8')
            drm_system.find("{urn:aws:amazon:com:speke}KeyFormat").text = base64.b64encode(HLS_SAMPLE_AES_KEY_FORMAT.encode('utf-8')).decode('utf-8')
            drm_system.find("{urn:aws:amazon:com:speke}KeyFormatVersions").text = base64.b64encode(HLS_SAMPLE_AES_KEY_FORMAT_VERSIONS.encode('utf-8')).decode('utf-8')
            self.safe_remove(drm_system, "{urn:dashif:org:cpix}ContentProtectionData")
            self.safe_remove(drm_system, "{urn:aws:amazon:com:speke}ProtectionHeader")
            self.safe_remove(drm_system, "{urn:dashif:org:cpix}PSSH")
        elif system_id.lower() == COMMON_PSSH_SYSTEM_ID.lower():
            pssh = bytearray([
                # BMFF box header(52 bytes, 'pssh')
                0x00, 0x00, 0x00, 0x34, 0x70, 0x73, 0x73, 0x68,
                0x01, 0x00, 0x00, 0x00,  # Full box header(version=1, flags=0)
                0x10, 0x77, 0xef, 0xec, 0xc0, 0xb2, 0x4d, 0x02,  # SystemID
                0xac, 0xe3, 0x3c, 0x1e, 0x52, 0xe2, 0xfb, 0x4b,
                0x00, 0x00, 0x00, 0x01,  # KID_count(1)
                # First KID("0123456789012345")
                0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
                0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
                0x00, 0x00, 0x00, 0x00,  # Size of Data(0)
            ])
            pssh[32:48] = uuid.UUID(kid).bytes
            base64pssh = base64.b64encode(pssh).decode('utf-8')
            drm_system.find(
                "{urn:dashif:org:cpix}PSSH").text = base64pssh
            content_protection_data = '<pssh xmlns="urn:mpeg:cenc:2013">' + base64pssh + '</pssh>'
            drm_system.find(
                "{urn:dashif:org:cpix}ContentProtectionData").text = base64.b64encode(content_protection_data.encode('utf-8')).decode('utf-8')
            self.safe_remove(drm_system, "{urn:aws:amazon:com:speke}KeyFormat")
            self.safe_remove(
                drm_system, "{urn:aws:amazon:com:speke}KeyFormatVersions")
            self.safe_remove(
                drm_system, "{urn:aws:amazon:com:speke}ProtectionHeader")
            self.safe_remove(drm_system, "{urn:dashif:org:cpix}URIExtXKey")
        elif system_id.lower() == DASH_CENC_SYSTEM_ID.lower():
            drm_system.find("{urn:dashif:org:cpix}PSSH").text = WIDEVINE_PSSH_BOX
            self.safe_remove(drm_system, "{urn:aws:amazon:com:speke}KeyFormat")
            self.safe_remove(drm_system, "{urn:aws:amazon:com:speke}KeyFormatVersions")
            self.safe_remove(drm_system, "{urn:aws:amazon:com:speke}ProtectionHeader")
            self.safe_remove(drm_system, "{urn:dashif:org:cpix}URIExtXKey")
        elif system_id.lower() == PLAYREADY_SYSTEM_ID.lower():
            drm_system.find("{urn:aws:amazon:com:speke}ProtectionHeader").text = PLAYREADY_PROTECTION_HEADER
            drm_system.find("{urn:dashif:org:cpix}PSSH").text = PLAYREADY_PSSH_BOX
            self.safe_remove(drm_system, "{urn:dashif:org:cpix}ContentProtectionData")
            self.safe_remove(drm_system, "{urn:aws:amazon:com:speke}KeyFormat")
            self.safe_remove(drm_system, "{urn:aws:amazon:com:speke}KeyFormatVersions")
            self.safe_remove(drm_system, "{urn:dashif:org:cpix}URIExtXKey")
            self.use_playready_content_key = True
        else:
            raise Exception("Invalid system ID {}".format(system_id))