feat(hls): license a FairPlay-only SAMPLE-AES playlist through a PlayReady or Widevine CDM

This commit is contained in:
imSp4rky
2026-11-30 19:36:01 -07:00
parent c41d8ec3cf
commit b826eccb86
9 changed files with 449 additions and 98 deletions
@@ -13,8 +13,14 @@ from uuid import UUID
import pytest
from pywidevine.pssh import PSSH as WvPSSH
from tests.core.test_cenc import init, widevine_box
from tests.core.test_hls_kid_from_init import NO_KID_PSSH
from tests.core.test_hls_service_drm_keys import SKD_KEY, playlist
from tests.core.test_kid_windows import encv
from unshackle.core.api.errors import APIError
from unshackle.core.api.server_keys import require_track_pssh
from unshackle.core.drm import Widevine
from unshackle.core.drm.cenc import drm_stub
from unshackle.core.drm.discovery import ensure_track_drm, track_pssh
from unshackle.core.tracks import Track, Video
@@ -82,3 +88,45 @@ def test_a_playlist_whose_keys_all_fail_leaves_the_track_without_drm():
ensure_track_drm(track, session)
assert not track.drm
def skd_session(init_data: bytes = b"init") -> SimpleNamespace:
response = SimpleNamespace(text=playlist(SKD_KEY), ok=True, content=init_data)
return SimpleNamespace(get=lambda url, headers=None: response)
def skd_track() -> Video:
track = hls_track()
track.OnSegmentFilter = None
track.get_key_id = lambda init: KID # type: ignore[method-assign]
return track
def test_a_playlist_unshackle_cannot_license_gets_both_stubs_of_its_key_id():
"""The client sends the stub that it built, and the server must know the key id to accept it."""
track = skd_track()
ensure_track_drm(track, skd_session())
assert [type(drm).__name__ for drm in track.drm] == ["Widevine", "PlayReady"]
assert all(drm.kids == [KID] for drm in track.drm)
for system in ("widevine", "playready"):
require_track_pssh(track, track_pssh(SimpleNamespace(drm=[drm_stub(system, [KID.hex])]), system), system)
with pytest.raises(APIError, match="does not belong"):
require_track_pssh(track, drm_stub("playready", [UUID(int=5).hex]).pssh_b64, "playready")
def test_the_stubs_take_the_key_id_of_the_init_pssh_when_its_tenc_names_none():
track = skd_track()
track.get_key_id = lambda init: None # type: ignore[method-assign]
ensure_track_drm(track, skd_session(init(widevine_box(KID), encv(UUID(int=0)))))
assert [drm.kids for drm in track.drm] == [[KID], [KID]]
def test_only_the_server_builds_the_stubs_before_the_download():
track = skd_track()
assert track.load_drm_from_playlist(skd_session()) is False
assert not track.drm