fix(drm): stop a bridged FairPlay track whose server-CDM answer or licence key does not decrypt it

This commit is contained in:
imSp4rky
2026-12-01 21:07:27 -07:00
parent ed6ed02033
commit cefd5295ac
15 changed files with 350 additions and 25 deletions
+10 -4
View File
@@ -49,6 +49,7 @@ from unshackle.core.drm import cbcs, real_kids, whole_file_cipher
from unshackle.core.drm.cenc import PLACEHOLDER_KIDS, drm_stub
from unshackle.core.drm.discovery import track_pssh
from unshackle.core.launch import launch_keys
from unshackle.core.manifests import HLS
from unshackle.core.manifests.snapshot import match_track
from unshackle.core.proxies.resolve import is_loopback
from unshackle.core.remote_protocol import (
@@ -1527,8 +1528,9 @@ class RemoteService(TitleSource):
Called by dl.py between track selection and download. The server
decides which CDM device to use and tells the client through
server_cdm_type. We send track IDs and the server does the full
CDM flow, returning KID:KEY pairs. A capped track this machine's device cannot license
waits in ``deferred_refusals``, so dl reads the local vaults before ``license_track`` raises it.
CDM flow, returning KID:KEY pairs. The stub of a track the server bridged names the KIDs of its init
segments, so a licence without their content keys stops it. A capped track this machine's device cannot
license waits in ``deferred_refusals``, so dl reads the local vaults before ``license_track`` raises it.
"""
# track ids can repeat across titles, so a refusal for the last title must not carry over
self.client_licensed.clear()
@@ -1577,6 +1579,7 @@ class RemoteService(TitleSource):
server_drm_type = resp.get("drm_type", drm_type)
drm_types_by_track = resp.get("drm_types", {})
capped = resp.get("capped_tracks") or {}
bridge_kids = resp.get("bridge_kids", {})
self.server_cdm_type = server_drm_type
self.log.debug(f"Server responded with drm_type={server_drm_type}, keys for {len(keys_by_track)} track(s)")
@@ -1595,9 +1598,12 @@ class RemoteService(TitleSource):
self.log.warning(f"Server CDM returned no content keys for track {track_log_label(track)}")
continue
named = {kid.hex for drm in track.drm or [] for kid in real_kids(drm)} & track_keys.keys()
track_drm_type = drm_types_by_track.get(server_id, server_drm_type)
drm_obj = drm_stub(track_drm_type, sorted(named) or list(track_keys))
if bridged := bridge_kids.get(server_id):
drm_obj = HLS.bridge_stub(track_drm_type, [UUID(hex=kid) for kid in bridged])
else:
named = {kid.hex for drm in track.drm or [] for kid in real_kids(drm)} & track_keys.keys()
drm_obj = drm_stub(track_drm_type, sorted(named) or list(track_keys))
for kid_hex, key_hex in track_keys.items():
drm_obj.content_keys[UUID(hex=kid_hex)] = key_hex
track.drm = [drm_obj]