forked from kenzuya/unshackle
refactor(drm): read PlayReady KIDs from pyplayready WRM headers and drop the hand XML scan
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
from types import SimpleNamespace
|
||||
from typing import Any
|
||||
from uuid import UUID
|
||||
|
||||
@@ -9,6 +10,7 @@ import pytest
|
||||
from pyplayready.misc.exceptions import InvalidLicense, InvalidXmrLicense
|
||||
from pyplayready.system.pssh import PSSH
|
||||
from pyplayready.system.wrmheader import WRMHeader
|
||||
from pywidevine.key import Key as WidevineKey
|
||||
|
||||
from unshackle.core.cdm.http_cdm import HttpCdm
|
||||
from unshackle.core.drm import PlayReady
|
||||
@@ -283,10 +285,6 @@ def test_a_track_carrying_playready_survives_deepcopy() -> None:
|
||||
assert len(clone.drm[0].distinct_headers()) == 2
|
||||
|
||||
|
||||
def _pro_b64(*headers: bytes) -> str:
|
||||
return base64.b64encode(_pro(*headers)).decode()
|
||||
|
||||
|
||||
def _xml_header(version: str, body: str) -> bytes:
|
||||
return (
|
||||
f'<WRMHEADER xmlns="http://schemas.microsoft.com/DRM/2007/03/PlayReadyHeader" version="{version}">'
|
||||
@@ -313,11 +311,15 @@ def _b64le(kid: UUID) -> str:
|
||||
f'<KID ALGID="AESCTR" VALUE="{_b64le(KID_B)}"></KID></KIDS></PROTECTINFO>',
|
||||
[KID_A, KID_B],
|
||||
),
|
||||
(
|
||||
"4.3.0.0",
|
||||
f'<PROTECTINFO><KIDS><KID ALGID="AESCBC" VALUE="{_b64le(KID_B)}"></KID></KIDS></PROTECTINFO>',
|
||||
[KID_B],
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_kids_are_read_from_every_header_version(version: str, body: str, expected: list[UUID]) -> None:
|
||||
header = _xml_header(version, body)
|
||||
assert PlayReady(pssh=PSSH(_pro(header)), pssh_b64=_pro_b64(header)).kids == expected
|
||||
assert PlayReady(pssh=PSSH(_pro(_xml_header(version, body)))).kids == expected
|
||||
|
||||
|
||||
def test_customattributes_kids_follow_the_header_kids() -> None:
|
||||
@@ -328,13 +330,44 @@ def test_customattributes_kids_follow_the_header_kids() -> None:
|
||||
f'<CUSTOMATTRIBUTES><KIDS><KID VALUE="{_b64le(KID_B)}"/><KID VALUE="{_b64le(kid_c)}"/></KIDS></CUSTOMATTRIBUTES>',
|
||||
)
|
||||
|
||||
drm = PlayReady(pssh=PSSH(_pro(header)), pssh_b64=_pro_b64(header))
|
||||
drm = PlayReady(pssh=PSSH(_pro(header)))
|
||||
|
||||
# the header KID leads (it is what the licence server acts on); CUSTOMATTRIBUTES KIDs stay reachable
|
||||
assert drm.kids == [KID_A, KID_B, kid_c]
|
||||
assert drm.kid == KID_A
|
||||
|
||||
|
||||
def test_kids_of_every_header_lead_then_customattributes_then_the_given_kid() -> None:
|
||||
kid_c = UUID("11111111-2222-3333-4444-555555555555")
|
||||
kid_d = UUID("66666666-7777-8888-9999-000000000000")
|
||||
custom = f'<CUSTOMATTRIBUTES><KIDS><KID VALUE="{_b64le(kid_c)}"/><KID VALUE="{_b64le(KID_A)}"/></KIDS></CUSTOMATTRIBUTES>'
|
||||
first = _xml_header(
|
||||
"4.3.0.0", f'<PROTECTINFO><KIDS><KID ALGID="AESCTR" VALUE="{_b64le(KID_A)}"></KID></KIDS></PROTECTINFO>{custom}'
|
||||
)
|
||||
|
||||
drm = PlayReady(pssh=PSSH(_pro(first, _wrm_header(KID_B))), kid=kid_d)
|
||||
|
||||
assert drm.kids == [KID_A, KID_B, kid_c, kid_d]
|
||||
|
||||
|
||||
def test_a_customattributes_value_that_is_not_a_kid_is_skipped() -> None:
|
||||
header = _xml_header(
|
||||
"4.3.0.0",
|
||||
f'<PROTECTINFO><KIDS><KID ALGID="AESCTR" VALUE="{_b64le(KID_A)}"></KID></KIDS></PROTECTINFO>'
|
||||
f'<CUSTOMATTRIBUTES><KIDS><KID VALUE="AAEC"/><KID/><KID VALUE="{_b64le(KID_B)}"/></KIDS></CUSTOMATTRIBUTES>',
|
||||
)
|
||||
|
||||
assert PlayReady(pssh=PSSH(_pro(header))).kids == [KID_A, KID_B]
|
||||
|
||||
|
||||
def test_session_keys_of_both_key_shapes_map_kid_to_hex() -> None:
|
||||
cdm = SimpleNamespace(
|
||||
get_keys=lambda _: [FakeKey(KID_A, KEY_A), WidevineKey("CONTENT", KID_B, bytes.fromhex(KEY_B), [])]
|
||||
)
|
||||
|
||||
assert _drm(_wrm_header(KID_A)).extract_keys_from_cdm(cdm, b"s") == {KID_A: KEY_A, KID_B: KEY_B}
|
||||
|
||||
|
||||
def test_device_revoked_on_the_first_header_is_not_swallowed() -> None:
|
||||
drm = _drm(_wrm_header(KID_A), _wrm_header(KID_B))
|
||||
cdm = FakeCdm({KID_A: KEY_A, KID_B: KEY_B})
|
||||
|
||||
Reference in New Issue
Block a user