feat(drm): license MonaLisa over --remote on the server and decrypt it in core, with or without bbtsdecrypt

This commit is contained in:
imSp4rky
2026-12-02 15:23:58 -07:00
parent b1497c77a2
commit ac4425cdca
29 changed files with 1518 additions and 121 deletions
+1 -1
View File
@@ -1260,7 +1260,7 @@ A slow answer arrives as a [slow response](#slow-responses).
| `track_id` / `track_ids` | Single track, or a batch of tracks. |
| `challenge` | Base64 CDM challenge (proxy mode). |
| `pssh` | Base64 PSSH. Server-CDM mode licenses this PSSH. Proxy mode gives it to the service licence callback as `pssh` (Widevine) or `pssh_b64` (PlayReady), the PSSH of the header the challenge is for. A proxy-mode PSSH that names a KID the track does not carry goes to no callback. |
| `drm_type` | `widevine` (default) or `playready`. In server-CDM mode the server's `cdm` mapping for the service decides the DRM system and the response `drm_type` names the system that licensed. A mapping with a device for each system takes the system of the device the remote session loaded. With no mapping, the client's value decides when the track carries that system; else a system the track carries decides, PlayReady first. The tracks response `server_cdm_type` names the system the same order gives for the title's tracks. A track whose DRM is a whole-file cipher takes `clearkeyctr` with no `pssh`: the service on the server licenses it. |
| `drm_type` | `widevine` (default) or `playready`. In server-CDM mode the server's `cdm` mapping for the service decides the DRM system and the response `drm_type` names the system that licensed. A mapping with a device for each system takes the system of the device the remote session loaded. With no mapping, the client's value decides when the track carries that system; else a system the track carries decides, PlayReady first. The tracks response `server_cdm_type` names the system the same order gives for the title's tracks. A track whose DRM is a whole-file cipher takes `clearkeyctr` with no `pssh`: the service on the server licenses it. A MonaLisa track takes `monalisa` with no `pssh` and `mode` `server_cdm`: the server answers in `keys` with the content key that its service extracted, and only in a session that uses the server CDM. |
| `mode` | `proxy` (default) or `server_cdm`. |
| `clear_tracks` (response) | Requested track ids that carry no DRM, so they have no keys. Absent when every requested track is encrypted. |
| `file_keys` (response) | Content keys of whole-file ciphers, by track id, for a single track and for a batch. Absent when no requested track holds such a cipher. |
+1 -1
View File
@@ -446,7 +446,7 @@ service to talk to the platform's license server. unshackle recognizes seven DRM
| `PlayReady` | PlayReady | CDM challenge (WRM header) → license server → content keys (`.prd` device) |
| `ClearKeyCENC` | W3C `org.w3.clearkey` or W3C common PSSH over CENC | JSON KID request → JWK set; no CDM |
| `ClearKey` | HLS AES-128 | content key fetched directly from a URI; no CDM, no challenge |
| `MonaLisa` | Proprietary WASM DRM | keys extracted locally; no license server. `command_builder` sets the command of the decryption backend, and `segment_decrypt=False` runs it once on the merged file |
| `MonaLisa` | Proprietary WASM DRM | keys extracted locally; no license server. Without `tool_path`, core uses `bbtsdecrypt` per segment, else its built-in decrypter (`core/drm/bbts.py`) per segment. `command_builder` sets the command of the decryption backend, and `segment_decrypt=False` runs it once on the merged file. Over `--remote` only the KID goes to the client, and the server sends the content key under the server CDM. An export also holds only the KID as its DRM, never the tool or the command. One process extracts the keys of one ticket at a time, because the wasmtime bindings are not thread-safe |
| `BlowfishStripe` | Blowfish CBC stripe cipher | the service gives the per-track key; no CDM, no license server |
| `ClearKeyCTR` | AES-128-CTR over a whole file | the service gives the IV and licenses the content key at the licence step; no CDM, no license server |
+1 -1
View File
@@ -283,7 +283,7 @@ Reconstruct a download (download → decrypt → mux) from an `--export` JSON fi
unshackle import EXPORT_FILE [DL_ARGS...]
```
unshackle forwards any `dl` options after the file verbatim, so you can override quality, range, proxy, and so on.
unshackle forwards any `dl` options after the file verbatim, so you can override quality, range, proxy, and so on. The import selects tracks with the `dl` defaults, not with the selection of the export. Give the selection options of the export again, for example `-r HYBRID` for an export of HDR tracks.
!!! example
```shell
+1 -1
View File
@@ -50,7 +50,7 @@ license-server handshake. The rest are special cases.
| **PlayReady** (Microsoft) | `.prd` | CDM challenge (WRM header) → license server → CDM parses → keys | shaka-packager / mp4decrypt |
| **ClearKey (CENC)**, W3C EME `org.w3.clearkey` or the W3C common PSSH | none | JSON `{"kids":[...],"type":"temporary"}` → license server returns a JWK Set. No CDM. | shaka-packager / mp4decrypt |
| **ClearKey (HLS)**, AES-128 `EXT-X-KEY` | none | Key fetched directly from a URI or `data:` URL. No CDM, no challenge. | in-process AES-CBC |
| **MonaLisa** (proprietary, WASM) | `.mld` | Ticket from the service API; keys extracted locally via WASM. No license server. | External tool that the service names, per segment or on the whole track |
| **MonaLisa** (proprietary, WASM) | `.mld` | Ticket from the service API; keys extracted locally via WASM. No license server. Over `--remote` the server extracts the content key and sends it to the client, only when the remote session uses the server CDM. | The tool that the service names, else `bbtsdecrypt` per segment, else the built-in decrypter per segment, which needs no tool. Over `--remote` the client decrypts with its own tool or the built-in decrypter. An export holds the KID and the content key, and an import decrypts like a `--remote` client. After the merge FFmpeg decode-checks the video track; a content key that does not decode stops the track. |
| **Blowfish stripe** | none | The service gives the per-track key. No CDM, no license server. | in-process Blowfish-CBC on every third 2048-byte chunk |
| **ClearKey (CTR)**, AES-128-CTR | none | The service gives the per-track key and IV. No CDM, no license server. | in-process AES-CTR over the whole file |
+5
View File
@@ -303,6 +303,11 @@ Each command reports how many files it removed and how much space it freed, then
**Inspect:** the licence server gave no content key for a key ID of the init segments, or gave a PlayReady or Widevine content key that is not the FairPlay one. unshackle flags a content key that does not decode. The next licence of that key ID clears the flag, so each run licenses and checks the key again. Operate unshackle with `-d` and read the `Key check on` debug line for the result of each window. See [DRM & CDM](drm-and-cdm.md).
!!! example "A MonaLisa track stops after its decryption"
**Symptom:** the download of a MonaLisa video track stops with `The MonaLisa content key of KID <kid> does not decrypt track <id>`, and unshackle keeps no output file.
**Inspect:** FFmpeg could not decode the decrypted track, so the content key is wrong, or the platform changed its BBTS format and the decrypter no longer fits it. unshackle flags the pair in the local vaults and does not copy it to another vault. Run again with the other decrypter: hide `bbtsdecrypt` to use the built-in one, or install it. If both fail, the content key is wrong. See [DRM & CDM](drm-and-cdm.md).
!!! example "A network request fails at the connection or TLS layer"
**Symptom:** timeouts, connection resets, or handshake errors, and unshackle's own logs do not give the full cause.
+2 -2
View File
@@ -36,7 +36,7 @@ unshackle pushes keys from every source, not only a local CDM. A run against a r
### Wrong keys from a poisoned vault
A public vault can return the right KID with a wrong content key. The decrypters accept a wrong content key and write noise. unshackle therefore trusts a content key from a vault only after FFmpeg decodes the decrypted track with strict error detection. For a fragmented MP4, unshackle reads from the encrypted file which fragments each KID encrypts, and FFmpeg decodes up to three windows of each KID: from its first, middle and last fragment on through the next fragments of that KID, for up to 4 seconds. A window never runs into a fragment of another KID or a clear fragment. A clear lead or a lead under another KID therefore cannot hide a wrong content key, and only the KID that fails is flagged. When every KID in the map has a content key, the map is complete, and a KID that is not in it does not encrypt this file. This file does not judge that KID; the file of its own track judges it. A file with no encrypted sample entry and no encrypted fragment, for example a clear audio track, judges no KID, so it neither flags nor copies a content key. A KID that is not in an incomplete map, for example one with an all-zero KID, and every KID of any other file, gets one check of the whole file. FFmpeg decodes the first seconds and the last seconds. A failure there flags each of those KIDs. When a mapped KID fails, the KIDs that are not in the map get no verdict from that pass; the retry with the replaced key judges them. Content keys from a licence skip this check, except those of a FairPlay-only track that the FairPlay bridge licensed. An import also checks these content keys when it reads them from an export file. When one of these fails, unshackle flags the pair, stops the track and keeps no output file. A file this FFmpeg build cannot judge counts as a pass, never as a wrong content key: a codec it has no decoder for, or a header it cannot read. A pass is not proof. A wrong content key for HEVC video can decode without an error for some seconds, most often at a low resolution, and that content key passes the check. Without FFmpeg there is no check at all.
A public vault can return the right KID with a wrong content key. The decrypters accept a wrong content key and write noise. unshackle therefore trusts a content key from a vault only after FFmpeg decodes the decrypted track with strict error detection. For a fragmented MP4, unshackle reads from the encrypted file which fragments each KID encrypts, and FFmpeg decodes up to three windows of each KID: from its first, middle and last fragment on through the next fragments of that KID, for up to 4 seconds. A window never runs into a fragment of another KID or a clear fragment. A clear lead or a lead under another KID therefore cannot hide a wrong content key, and only the KID that fails is flagged. When every KID in the map has a content key, the map is complete, and a KID that is not in it does not encrypt this file. This file does not judge that KID; the file of its own track judges it. A file with no encrypted sample entry and no encrypted fragment, for example a clear audio track, judges no KID, so it neither flags nor copies a content key. A KID that is not in an incomplete map, for example one with an all-zero KID, and every KID of any other file, gets one check of the whole file. FFmpeg decodes the first seconds and the last seconds. A failure there flags each of those KIDs. When a mapped KID fails, the KIDs that are not in the map get no verdict from that pass; the retry with the replaced key judges them. Content keys from a licence skip this check, with two exceptions: a FairPlay-only track that the FairPlay bridge licensed, and a MonaLisa video track. A MonaLisa track is MPEG-TS, so it gets the check of the whole file after the merge of its decrypted segments. This applies to both decrypters. An import also checks these content keys when it reads them from an export file. When one of these fails, unshackle flags the pair, stops the track and keeps no output file. A file this FFmpeg build cannot judge counts as a pass, never as a wrong content key: a codec it has no decoder for, or a header it cannot read. A BBTS decrypter keeps the continuity counter of a TS packet that it empties, so unshackle corrects the counters of a MonaLisa track before the check. A pass is not proof. A wrong content key for HEVC video can decode without an error for some seconds, most often at a low resolution, and that content key passes the check. Damage to a small part of the slice data, such as one corrupt NAL unit, also often decodes without an error. Without FFmpeg there is no check at all.
When the decode fails, unshackle:
@@ -46,7 +46,7 @@ When the decode fails, unshackle:
The download stops with an error instead of writing noise when no ciphertext is left to retry with, or when every vault and the CDM are used up. Without a local SQLite vault nothing remembers a flag, so the same vault serves the same pair again and the download stops there.
Per-segment decryption gives up the retry. With `decrypt_segments` on, and always with a MonaLisa tool that decrypts segments, the plaintext replaces each segment as it arrives, so no ciphertext is left. A failed decode then flags the pair and stops the download. The next run skips the flagged pair.
Per-segment decryption gives up the retry. With `decrypt_segments` on, and always with a per-segment MonaLisa decrypter, the plaintext replaces each segment as it arrives, so no ciphertext is left. A failed decode then flags the pair and stops the download. The next run skips the flagged pair.
unshackle copies a content key from one vault to the others only after this check passes, so a content key that fails the check does not spread. Without FFmpeg, a content key from a vault is not copied at all. To see or clear the flags, open the SQLite file and read or delete rows in `bad_keys`.