Example #1
0
def test_full_widevine_cpix():
    full_cpix = cpix.CPIX(
        content_keys=cpix.ContentKeyList(
            cpix.ContentKey(
                kid="0DC3EC4F-7683-548B-81E7-3C64E582E136",
                cek="WADwG2qCqkq5TVml+U5PXw=="
            ),
            cpix.ContentKey(
                kid="1447B7ED-2F66-572B-BD13-06CE7CF3610D",
                cek="ydugVLA+K017XoGM4mjxvA=="
            ),
            cpix.ContentKey(
                kid="00000000-0000-0000-0000-000000000002",
                cek="AAAAAAAAAAAAAAAAAAAAAg=="
            )
        ),
        drm_systems=cpix.DRMSystemList(
            cpix.DRMSystem(
                kid="0DC3EC4F-7683-548B-81E7-3C64E582E136",
                system_id="EDEF8BA9-79D6-4ACE-A3C8-27DCD51D21ED",
                pssh="AAAAxnBzc2gBAAAA7e+LqXnWSs6jyCfc1R0h7QAAAAINw+xPdoNUi4HnPGTlguE2FEe37S9mVyu9EwbOfPNhDQAAAIISEBRHt+0vZlcrvRMGznzzYQ0SEFrGoR6qL17Vv2aMQByBNMoSEG7hNRbI51h7rp9+zT6Zom4SEPnsEqYaJl1Hj4MzTjp40scSEA3D7E92g1SLgec8ZOWC4TYaDXdpZGV2aW5lX3Rlc3QiEXVuaWZpZWQtc3RyZWFtaW5nSOPclZsG",
                content_protection_data="PCEtLSBXaWRldmluZSAtLT4KPENvbnRlbnRQcm90ZWN0aW9uCiAgeG1sbnM9InVybjptcGVnOmRhc2g6c2NoZW1hOm1wZDoyMDExIgogIHhtbG5zOmNlbmM9InVybjptcGVnOmNlbmM6MjAxMyIKICBzY2hlbWVJZFVyaT0idXJuOnV1aWQ6RURFRjhCQTktNzlENi00QUNFLUEzQzgtMjdEQ0Q1MUQyMUVEIj4KICA8Y2VuYzpwc3NoPkFBQUF4bkJ6YzJnQkFBQUE3ZStMcVhuV1NzNmp5Q2ZjMVIwaDdRQUFBQUlOdyt4UGRvTlVpNEhuUEdUbGd1RTJGRWUzN1M5bVZ5dTlFd2JPZlBOaERRQUFBSUlTRUJSSHQrMHZabGNydlJNR3puenpZUTBTRUZyR29SNnFMMTdWdjJhTVFCeUJOTW9TRUc3aE5SYkk1MWg3cnA5K3pUNlpvbTRTRVBuc0VxWWFKbDFIajRNelRqcDQwc2NTRUEzRDdFOTJnMVNMZ2VjOFpPV0M0VFlhRFhkcFpHVjJhVzVsWDNSbGMzUWlFWFZ1YVdacFpXUXRjM1J5WldGdGFXNW5TT1BjbFpzRzwvY2VuYzpwc3NoPgo8L0NvbnRlbnRQcm90ZWN0aW9uPg==",
                hls_signaling_data="I0VYVC1YLUtFWTpNRVRIT0Q9U0FNUExFLUFFUyxLRVlJRD0weDBEQzNFQzRGNzY4MzU0OEI4MUU3M0M2NEU1ODJFMTM2LFVSST0iZGF0YTp0ZXh0L3BsYWluO2Jhc2U2NCxBQUFBb25CemMyZ0FBQUFBN2UrTHFYbldTczZqeUNmYzFSMGg3UUFBQUlJU0VCUkh0KzB2WmxjcnZSTUd6bnp6WVEwU0VGckdvUjZxTDE3VnYyYU1RQnlCTk1vU0VHN2hOUmJJNTFoN3JwOSt6VDZab200U0VQbnNFcVlhSmwxSGo0TXpUanA0MHNjU0VBM0Q3RTkyZzFTTGdlYzhaT1dDNFRZYURYZHBaR1YyYVc1bFgzUmxjM1FpRVhWdWFXWnBaV1F0YzNSeVpXRnRhVzVuU09QY2xac0ciLEtFWUZPUk1BVD0idXJuOnV1aWQ6ZWRlZjhiYTktNzlkNi00YWNlLWEzYzgtMjdkY2Q1MWQyMWVkIixLRVlGT1JNQVRWRVJTSU9OUz0iMSIK"
            ),
            cpix.DRMSystem(
                kid="1447B7ED-2F66-572B-BD13-06CE7CF3610D",
                system_id="EDEF8BA9-79D6-4ACE-A3C8-27DCD51D21ED",
                pssh="AAAAxnBzc2gBAAAA7e+LqXnWSs6jyCfc1R0h7QAAAAINw+xPdoNUi4HnPGTlguE2FEe37S9mVyu9EwbOfPNhDQAAAIISEBRHt+0vZlcrvRMGznzzYQ0SEFrGoR6qL17Vv2aMQByBNMoSEG7hNRb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TFoN3JwOSt6VDZab200U0VQbnNFcVlhSmwxSGo0TXpUanA0MHNjU0VBM0Q3RTkyZzFTTGdlYzhaT1dDNFRZYURYZHBaR1YyYVc1bFgzUmxjM1FpRVhWdWFXWnBaV1F0YzNSeVpXRnRhVzVuU09QY2xac0ciLEtFWUZPUk1BVD0idXJuOnV1aWQ6ZWRlZjhiYTktNzlkNi00YWNlLWEzYzgtMjdkY2Q1MWQyMWVkIixLRVlGT1JNQVRWRVJTSU9OUz0iMSIK"
            ),
            cpix.DRMSystem(
                kid="00000000-0000-0000-0000-000000000002",
                system_id="EDEF8BA9-79D6-4ACE-A3C8-27DCD51D21ED",
                pssh="AAAAxnBzc2gBAAAA7e+LqXnWSs6jyCfc1R0h7QAAAAINw+xPdoNUi4HnPGTlguE2FEe37S9mVyu9EwbOfPNhDQAAAIISEBRHt+0vZlcrvRMGznzzYQ0SEFrGoR6qL17Vv2aMQByBNMoSEG7hNRbI51h7rp9+zT6Zom4SEPnsEqYaJl1Hj4MzTjp40scSEA3D7E92g1SLgec8ZOWC4TYaDXdpZGV2aW5lX3Rlc3QiEXVuaWZpZWQtc3RyZWFtaW5nSOPclZsG",
                content_protection_data="",
                hls_signaling_data="I0VYVC1YLUtFWTpNRVRIT0Q9U0FNUExFLUFFUyxLRVlJRD0weDE0NDdCN0VEMkY2NjU3MkJCRDEzMDZDRTdDRjM2MTBELFVSST0iZGF0YTp0ZXh0L3BsYWluO2Jhc2U2NCxBQUFBb25CemMyZ0FBQUFBN2UrTHFYbldTczZqeUNmYzFSMGg3UUFBQUlJU0VCUkh0KzB2WmxjcnZSTUd6bnp6WVEwU0VGckdvUjZxTDE3VnYyYU1RQnlCTk1vU0VHN2hOUmJJNTFoN3JwOSt6VDZab200U0VQbnNFcVlhSmwxSGo0TXpUanA0MHNjU0VBM0Q3RTkyZzFTTGdlYzhaT1dDNFRZYURYZHBaR1YyYVc1bFgzUmxjM1FpRVhWdWFXWnBaV1F0YzNSeVpXRnRhVzVuU09QY2xac0ciLEtFWUZPUk1BVD0idXJuOnV1aWQ6ZWRlZjhiYTktNzlkNi00YWNlLWEzYzgtMjdkY2Q1MWQyMWVkIixLRVlGT1JNQVRWRVJTSU9OUz0iMSIK"
            )
        ),
        usage_rules=cpix.UsageRuleList(
            cpix.UsageRule(
                kid="0DC3EC4F-7683-548B-81E7-3C64E582E136",
                filters=[cpix.AudioFilter()]
            ),
            cpix.UsageRule(
                kid="1447B7ED-2F66-572B-BD13-06CE7CF3610D",
                filters=[cpix.VideoFilter(max_pixels=38912)]
            ),
            cpix.UsageRule(
                kid="00000000-0000-0000-0000-000000000002",
                filters=[cpix.VideoFilter(min_pixels=38913)]
            )
        )
    )

    assert full_cpix.validate_content()[0]

    xml = etree.tostring(full_cpix.element())

    assert xml == b'<CPIX xmlns:pskc="urn:ietf:params:xml:ns:keyprov:pskc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:dashif:org:cpix" xsi:schemaLocation="urn:dashif:org:cpix cpix.xsd"><ContentKeyList><ContentKey kid="0dc3ec4f-7683-548b-81e7-3c64e582e136"><Data><pskc:Secret><pskc:PlainValue>WADwG2qCqkq5TVml+U5PXw==</pskc:PlainValue></pskc:Secret></Data></ContentKey><ContentKey kid="1447b7ed-2f66-572b-bd13-06ce7cf3610d"><Data><pskc:Secret><pskc:PlainValue>ydugVLA+K017XoGM4mjxvA==</pskc:PlainValue></pskc:Secret></Data></ContentKey><ContentKey kid="00000000-0000-0000-0000-000000000002"><Data><pskc:Secret><pskc:PlainValue>AAAAAAAAAAAAAAAAAAAAAg==</pskc:PlainValue></pskc:Secret></Data></ContentKey></ContentKeyList><DRMSystemList><DRMSystem kid="0dc3ec4f-7683-548b-81e7-3c64e582e136" systemId="edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"><PSSH>AAAAxnBzc2gBAAAA7e+LqXnWSs6jyCfc1R0h7QAAAAINw+xPdoNUi4HnPGTlguE2FEe37S9mVyu9EwbOfPNhDQAAAIISEBRHt+0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2JPZlBOaERRQUFBSUlTRUJSSHQrMHZabGNydlJNR3puenpZUTBTRUZyR29SNnFMMTdWdjJhTVFCeUJOTW9TRUc3aE5SYkk1MWg3cnA5K3pUNlpvbTRTRVBuc0VxWWFKbDFIajRNelRqcDQwc2NTRUEzRDdFOTJnMVNMZ2VjOFpPV0M0VFlhRFhkcFpHVjJhVzVsWDNSbGMzUWlFWFZ1YVdacFpXUXRjM1J5WldGdGFXNW5TT1BjbFpzRzwvY2VuYzpwc3NoPgo8L0NvbnRlbnRQcm90ZWN0aW9uPg==</ContentProtectionData><HLSSignalingData>I0VYVC1YLUtFWTpNRVRIT0Q9U0FNUExFLUFFUyxLRVlJRD0weDE0NDdCN0VEMkY2NjU3MkJCRDEzMDZDRTdDRjM2MTBELFVSST0iZGF0YTp0ZXh0L3BsYWluO2Jhc2U2NCxBQUFBb25CemMyZ0FBQUFBN2UrTHFYbldTczZqeUNmYzFSMGg3UUFBQUlJU0VCUkh0KzB2WmxjcnZSTUd6bnp6WVEwU0VGckdvUjZxTDE3VnYyYU1RQnlCTk1vU0VHN2hOUmJJNTFoN3JwOSt6VDZab200U0VQbnNFcVlhSmwxSGo0TXpUanA0MHNjU0VBM0Q3RTkyZzFTTGdlYzhaT1dDNFRZYURYZHBaR1YyYVc1bFgzUmxjM1FpRVhWdWFXWnBaV1F0YzNSeVpXRnRhVzVuU09QY2xac0ciLEtFWUZPUk1BVD0idXJuOnV1aWQ6ZWRlZjhiYTktNzlkNi00YWNlLWEzYzgtMjdkY2Q1MWQyMWVkIixLRVlGT1JNQVRWRVJTSU9OUz0iMSIK</HLSSignalingData></DRMSystem><DRMSystem kid="00000000-0000-0000-0000-000000000002" systemId="edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"><PSSH>AAAAxnBzc2gBAAAA7e+LqXnWSs6jyCfc1R0h7QAAAAINw+xPdoNUi4HnPGTlguE2FEe37S9mVyu9EwbOfPNhDQAAAIISEBRHt+0vZlcrvRMGznzzYQ0SEFrGoR6qL17Vv2aMQByBNMoSEG7hNRbI51h7rp9+zT6Zom4SEPnsEqYaJl1Hj4MzTjp40scSEA3D7E92g1SLgec8ZOWC4TYaDXdpZGV2aW5lX3Rlc3QiEXVuaWZpZWQtc3RyZWFtaW5nSOPclZsG</PSSH><ContentProtectionData></ContentProtectionData><HLSSignalingData>I0VYVC1YLUtFWTpNRVRIT0Q9U0FNUExFLUFFUyxLRVlJRD0weDE0NDdCN0VEMkY2NjU3MkJCRDEzMDZDRTdDRjM2MTBELFVSST0iZGF0YTp0ZXh0L3BsYWluO2Jhc2U2NCxBQUFBb25CemMyZ0FBQUFBN2UrTHFYbldTczZqeUNmYzFSMGg3UUFBQUlJU0VCUkh0KzB2WmxjcnZSTUd6bnp6WVEwU0VGckdvUjZxTDE3VnYyYU1RQnlCTk1vU0VHN2hOUmJJNTFoN3JwOSt6VDZab200U0VQbnNFcVlhSmwxSGo0TXpUanA0MHNjU0VBM0Q3RTkyZzFTTGdlYzhaT1dDNFRZYURYZHBaR1YyYVc1bFgzUmxjM1FpRVhWdWFXWnBaV1F0YzNSeVpXRnRhVzVuU09QY2xac0ciLEtFWUZPUk1BVD0idXJuOnV1aWQ6ZWRlZjhiYTktNzlkNi00YWNlLWEzYzgtMjdkY2Q1MWQyMWVkIixLRVlGT1JNQVRWRVJTSU9OUz0iMSIK</HLSSignalingData></DRMSystem></DRMSystemList><ContentKeyUsageRuleList><ContentKeyUsageRule kid="0dc3ec4f-7683-548b-81e7-3c64e582e136"><AudioFilter/></ContentKeyUsageRule><ContentKeyUsageRule kid="1447b7ed-2f66-572b-bd13-06ce7cf3610d"><VideoFilter maxPixels="38912"/></ContentKeyUsageRule><ContentKeyUsageRule kid="00000000-0000-0000-0000-000000000002"><VideoFilter minPixels="38913"/></ContentKeyUsageRule></ContentKeyUsageRuleList></CPIX>'
Example #2
0
def test_empty_cpix():
    empty_cpix = cpix.CPIX()

    assert len(empty_cpix.content_keys) == 0
    assert len(empty_cpix.drm_systems) == 0
    assert len(empty_cpix.usage_rules) == 0

    xml = etree.tostring(empty_cpix.element())

    assert xml == b'<CPIX xmlns:pskc="urn:ietf:params:xml:ns:keyprov:pskc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:dashif:org:cpix" xsi:schemaLocation="urn:dashif:org:cpix cpix.xsd"/>'
Example #3
0
def test_valid_cpix_with_period():
    cpix_doc = cpix.CPIX(
        periods = cpix.PeriodList(
            cpix.Period(
                id="test",
                start="2018-08-06T00:00:00Z",
                end="2018-08-07T00:00:00Z"
            )
        )
    )

    xml=etree.tostring(cpix_doc.element())

    assert xml == b'<CPIX xmlns:pskc="urn:ietf:params:xml:ns:keyprov:pskc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:dashif:org:cpix" xsi:schemaLocation="urn:dashif:org:cpix cpix.xsd"><ContentKeyPeriodList><ContentKeyPeriod id="test" start="2018-08-06T00:00:00Z" end="2018-08-07T00:00:00Z"/></ContentKeyPeriodList></CPIX>'

    valid = cpix.validate(xml)

    assert valid[0]
Example #4
0
def make_cpix(widevine_response):
    """
    Make CPIX document from Widevine response
    Returns CPIX XML
    """
    # make empty CPIX document structure
    cpix_doc = cpix.CPIX(content_keys=cpix.ContentKeyList(),
                         drm_systems=cpix.DRMSystemList(),
                         usage_rules=cpix.UsageRuleList())

    system_id = widevine_response["drm"][0]["system_id"]

    for track in widevine_response["tracks"]:
        kid = str(b16encode(b64decode(track["key_id"])), "ASCII")

        content_key = cpix.ContentKey(kid=kid, cek=track["key"])
        cpix_doc.content_keys.append(content_key)

        drm_system = cpix.DRMSystem(kid=kid,
                                    system_id=system_id,
                                    pssh=track["pssh"][0]["boxes"])
        cpix_doc.drm_systems.append(drm_system)

        if track["type"] == "AUDIO":
            usage_rule = cpix.AudioUsageRule(kid=kid)
            cpix_doc.usage_rules.append(usage_rule)

        if track["type"] == "SD":
            usage_rule = cpix.SDVideoUsageRule(kid=kid)
            cpix_doc.usage_rules.append(usage_rule)

        if track["type"] == "HD":
            usage_rule = cpix.HDVideoUsageRule(kid=kid)
            cpix_doc.usage_rules.append(usage_rule)

        if track["type"] == "UHD1":
            usage_rule = cpix.UHD1VideoUsageRule(kid=kid)
            cpix_doc.usage_rules.append(usage_rule)

        if track["type"] == "UHD2":
            usage_rule = cpix.UHD2VideoUsageRule(kid=kid)
            cpix_doc.usage_rules.append(usage_rule)

    return cpix_doc
Example #5
0
def make_cpix(keys, pssh):
    """
    Make a Playready CPIX document based on array of keys and PSSH
    """
    cpix_doc = cpix.CPIX(content_keys=cpix.ContentKeyList(),
                         drm_systems=cpix.DRMSystemList(),
                         usage_rules=cpix.UsageRuleList())

    for key in keys:
        content_key = cpix.ContentKey(kid=key["key_id"],
                                      cek=b64encode(b16decode(key["key"])))
        cpix_doc.content_keys.append(content_key)

        drm_system = cpix.DRMSystem(kid=key["key_id"],
                                    system_id=PLAYREADY_SYSTEM_ID,
                                    pssh=pssh)
        cpix_doc.drm_systems.append(drm_system)

        if key["type"] == "AUDIO":
            usage_rule = cpix.AudioUsageRule(kid=key["key_id"])
            cpix_doc.usage_rules.append(usage_rule)

        if key["type"] == "SD":
            usage_rule = cpix.SDVideoUsageRule(kid=key["key_id"])
            cpix_doc.usage_rules.append(usage_rule)

        if key["type"] == "HD":
            usage_rule = cpix.HDVideoUsageRule(kid=key["key_id"])
            cpix_doc.usage_rules.append(usage_rule)

        if key["type"] == "UHD1":
            usage_rule = cpix.UHD1VideoUsageRule(kid=key["key_id"])
            cpix_doc.usage_rules.append(usage_rule)

        if key["type"] == "UHD2":
            usage_rule = cpix.UHD2VideoUsageRule(kid=key["key_id"])
            cpix_doc.usage_rules.append(usage_rule)

    return cpix_doc
Example #6
0
def make_cpix(widevine_response):
    """
    Make CPIX document from Widevine response
    Returns CPIX XML
    """
    # make empty CPIX document structure
    cpix_doc = cpix.CPIX(content_keys=cpix.ContentKeyList(),
                         drm_systems=cpix.DRMSystemList(),
                         usage_rules=cpix.UsageRuleList())

    system_id = widevine_response["drm"][0]["system_id"]

    # generate playready PSSH
    keys = [{
        "key_id":
        uuid.UUID(str(b16encode(b64decode(track["key_id"])), "ASCII")),
        "key":
        b16encode(b64decode(track["key"]))
    } for track in widevine_response["tracks"]]

    # make playready LA URL with all keys as query params
    la_url = "{base}?cfg={keys}".format(
        base=PLAYREADY_TEST_LA_URL,
        keys=",".join([
            "(kid:{kid},contentkey:{cek})".format(
                kid=str(b64encode(key["key_id"].bytes_le), "ASCII"),
                cek=str(b64encode(b16decode(key["key"])), "ASCII"))
            for key in keys
        ]))

    logger.debug("Playready LA_URL: {}".format(la_url))

    playready_pssh = b64encode(playready.generate_pssh(keys, la_url))

    for track in widevine_response["tracks"]:
        kid = str(b16encode(b64decode(track["key_id"])), "ASCII")

        content_key = cpix.ContentKey(kid=kid, cek=track["key"])
        cpix_doc.content_keys.append(content_key)

        drm_system_wv = cpix.DRMSystem(kid=kid,
                                       system_id=system_id,
                                       pssh=track["pssh"][0]["boxes"])
        cpix_doc.drm_systems.append(drm_system_wv)

        drm_system_pr = cpix.DRMSystem(kid=kid,
                                       system_id=PLAYREADY_SYSTEM_ID,
                                       pssh=playready_pssh)
        cpix_doc.drm_systems.append(drm_system_pr)

        if track["type"] == "AUDIO":
            usage_rule = cpix.AudioUsageRule(kid=kid)
            cpix_doc.usage_rules.append(usage_rule)

        if track["type"] == "SD":
            usage_rule = cpix.SDVideoUsageRule(kid=kid)
            cpix_doc.usage_rules.append(usage_rule)

        if track["type"] == "HD":
            usage_rule = cpix.HDVideoUsageRule(kid=kid)
            cpix_doc.usage_rules.append(usage_rule)

        if track["type"] == "UHD1":
            usage_rule = cpix.UHD1VideoUsageRule(kid=kid)
            cpix_doc.usage_rules.append(usage_rule)

        if track["type"] == "UHD2":
            usage_rule = cpix.UHD2VideoUsageRule(kid=kid)
            cpix_doc.usage_rules.append(usage_rule)

    return cpix_doc