forked from kenzuya/unshackle
refactor(drm): build PlayReady from base64 with PlayReady.from_pssh_b64 in server keys and the wire rebuild
This commit is contained in:
@@ -20,20 +20,20 @@ from unshackle.core.drm import PlayReady, Widevine
|
||||
from unshackle.core.manifests.dash import DASH
|
||||
from unshackle.core.manifests.hls import HLS
|
||||
from unshackle.core.manifests.ism import ISM
|
||||
from unshackle.core.wire import drm_from_dict
|
||||
from unshackle.core.wire import drm_from_dict, pssh_drm
|
||||
|
||||
KID = UUID("00112233-4455-6677-8899-aabbccddeeff")
|
||||
KID_B64 = base64.b64encode(KID.bytes_le).decode()
|
||||
PR_URN = "urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95"
|
||||
WV_URN = "urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"
|
||||
|
||||
|
||||
def bare_header(version: str) -> str:
|
||||
def bare_header(version: str, kid: UUID = KID) -> str:
|
||||
"""Base64 of a bare WRMHEADER, with the KID where the given header version puts it."""
|
||||
kid_b64 = base64.b64encode(kid.bytes_le).decode()
|
||||
if version == "4.0.0.0":
|
||||
data = f"<PROTECTINFO><KEYLEN>16</KEYLEN><ALGID>AESCTR</ALGID></PROTECTINFO><KID>{KID_B64}</KID>"
|
||||
data = f"<PROTECTINFO><KEYLEN>16</KEYLEN><ALGID>AESCTR</ALGID></PROTECTINFO><KID>{kid_b64}</KID>"
|
||||
else:
|
||||
data = f'<PROTECTINFO><KIDS><KID ALGID="AESCTR" VALUE="{KID_B64}"></KID></KIDS></PROTECTINFO>'
|
||||
data = f'<PROTECTINFO><KIDS><KID ALGID="AESCTR" VALUE="{kid_b64}"></KID></KIDS></PROTECTINFO>'
|
||||
xml = (
|
||||
f'<WRMHEADER xmlns="http://schemas.microsoft.com/DRM/2007/03/PlayReadyHeader" version="{version}">'
|
||||
f"<DATA>{data}<LA_URL>https://example.invalid/pr</LA_URL></DATA></WRMHEADER>"
|
||||
@@ -61,6 +61,10 @@ def test_dash_loads_a_bare_header(child: str, version: str) -> None:
|
||||
assert KID in drm_from_dict(drm[0].to_dict()).kids
|
||||
|
||||
|
||||
def test_the_wire_rebuilds_a_bare_header() -> None:
|
||||
assert pssh_drm("playready", bare_header("4.0.0.0"), None).kids == [KID]
|
||||
|
||||
|
||||
def test_wrapped_header_bytes_are_unchanged() -> None:
|
||||
header = bare_header("4.0.0.0")
|
||||
drm = PlayReady.from_pssh_b64(header)
|
||||
|
||||
@@ -1060,12 +1060,8 @@ def test_reconstruct_rest_drm_skips_what_it_cannot_parse(caplog: pytest.LogCaptu
|
||||
entries = [{"type": "widevine"}, {"type": "playready", "pssh": "!!"}, {"type": "clearkeycenc", "kids": ["x"]}]
|
||||
with caplog.at_level(logging.WARNING):
|
||||
assert reconstruct_drm(entries) == []
|
||||
assert [(r.name, r.getMessage()) for r in caplog.records] == [
|
||||
(
|
||||
"remote_service",
|
||||
"Skipping unparseable playready DRM entry from server: InvalidPssh('Data must not be empty')",
|
||||
)
|
||||
]
|
||||
assert [r.name for r in caplog.records] == ["remote_service"]
|
||||
assert caplog.messages[0].startswith("Skipping unparseable playready DRM entry from server: InvalidPssh(")
|
||||
|
||||
|
||||
def test_export_drm_decode() -> None:
|
||||
|
||||
Reference in New Issue
Block a user