mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-04 06:55:09 +00:00
feat(drm)!: load DRM systems beyond the built-ins from plugins in directories.plugins
This commit is contained in:
@@ -231,7 +231,9 @@ accepted URL/ID formats and options there.
|
||||
`is_widevine_cdm()` / `is_playready_cdm()` from `unshackle.core.cdm.detect`
|
||||
to classify it. These work correctly for local *and* remote CDMs, so never
|
||||
hand-roll an `isinstance` check. Services often pick a device profile or
|
||||
manifest endpoint based on which DRM the CDM speaks.
|
||||
manifest endpoint based on which DRM the CDM speaks. A service whose DRM
|
||||
plugin licenses locally gets its device from `ctx.obj.cdm_for("<plugin id>")`.
|
||||
`ctx.obj.cdm_for` is `None` where nothing licenses, for example in a search.
|
||||
|
||||
### `authenticate`: optional login
|
||||
|
||||
|
||||
@@ -386,7 +386,7 @@ When you give both `season` and `episode`, the server combines them into a `"{se
|
||||
|
||||
The server sorts tracks by bitrate, descending. Episodes the server cannot get go into `unavailable_episodes`, rather than failing the whole request. Track objects here do **not** include a download `url`. Only the remote session endpoints give segment URLs.
|
||||
|
||||
The `drm` array on a track is a list of `{type, pssh?, kids?, content_keys?, license_url?}` objects.
|
||||
The `drm` array on a track is a list of `{type, pssh?, kids?, content_keys?, license_url?}` objects. Only a `widevine`, `playready` or `clearkeycenc` entry carries `content_keys`.
|
||||
|
||||
Every track carries the same fields as a local track: `is_original_lang`, `name`, `needs_repack`, `edition`, `note`, and `data`. `name` is the name the service set, or null. `note` is display text the service set, such as an encoding profile, or null: `--list` shows it, but the filename and the mux do not use it. `track_name` is the name `--list` shows and the mux writes to an audio or subtitle track: `name` when the service set one, else the name of the language (English, or in the language itself when the server sets `muxing.track_names: native`, or no name when it sets `none`), then the server's `muxing.original_label` on an original-language track, then the SDH, CC, Forced or Descriptive label. `bitrate` is in kb/s, and `bitrate_bps` gives the exact bits/s. `data` holds the part of the service-set `track.data` that fits in JSON, without the `hls`, `dash`, and `ism` parser keys. Audio keeps `is_original` and `atmos` for clients that read them, and adds the exact `joc` object count. Audio `bit_depth` and `sample_rate` (Hz) are integers, or null when the manifest and the service do not give them.
|
||||
|
||||
@@ -1262,7 +1262,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. 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. |
|
||||
| `drm_type` | `widevine` (default), `playready`, or the id of a DRM plugin that both peers load. 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 track of a DRM plugin that licenses locally takes the plugin id with no `pssh` and `mode` `server_cdm`: the server answers in `keys` with the content key that its service licensed, 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. |
|
||||
|
||||
@@ -327,6 +327,11 @@ There are two ways DRM keys get resolved, chosen by the client's `server_cdm` fl
|
||||
already answered. The client proves it, and a server key waits as the next
|
||||
candidate.
|
||||
|
||||
!!! note "A DRM type that the client does not know"
|
||||
The client rebuilds the DRM of each track from the track list of the server. When the server
|
||||
sends a DRM `type` that the client does not know, the client stops the title with one
|
||||
`DRM_ERROR` line that names the type. Update the client to the version of the server.
|
||||
|
||||
!!! note "A height limit on the server CDM"
|
||||
An API key with `server_cdm_max_height` gets the server CDM only up to that height. The
|
||||
session create response tells the client who licenses the session in `server_cdm` and gives
|
||||
@@ -491,7 +496,7 @@ session when the new one is stored, and the server answers the ID of another API
|
||||
`credentials`, `cookies` (base64 of zlib-compressed Netscape cookie file), `proxy`,
|
||||
`no_proxy`, `profile`, `cache` (a map of `filename → base64(zlib(bytes))`),
|
||||
`client_region`, `server_cdm` (`false` when the user picked the local CDM), `cdm_type`, `cdm_security_level`, `cdm_relay` (`true` when the client
|
||||
answers CDM calls), `cdm_system_id` and `cdm_device_type` (Widevine only), `service_config`
|
||||
answers CDM calls; a plugin `cdm_type` gets no relay), `cdm_system_id` and `cdm_device_type` (Widevine only), `service_config`
|
||||
(the identity config keys the service lists in `client_config`), `client` (a freeform identity
|
||||
object the dashboard shows as sent), and the track-selection hints `range_`, `vcodec`,
|
||||
`quality`, `best_available`, `generate_dv`, plus arbitrary service CLI options
|
||||
|
||||
@@ -448,7 +448,7 @@ least one and no track is left.
|
||||
## DRM hooks
|
||||
|
||||
If a track carries DRM, the framework licenses and decrypts it, but it needs your
|
||||
service to talk to the platform's license server. unshackle recognizes seven DRM systems:
|
||||
service to talk to the platform's license server. unshackle recognizes six DRM classes:
|
||||
|
||||
| DRM class | System | License flow |
|
||||
|---|---|---|
|
||||
@@ -456,8 +456,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. 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 |
|
||||
| `CustomDRM` | a system that a DRM plugin adds | `CustomDRM("<plugin id>", kids=..., data=...)`. For a plugin that holds its key, put the key in `data`. For a plugin that licenses locally, call `drm.license(cdm)` with a device of the plugin from `load_cdm`. The plugin decrypts. Its README names the `data` it reads |
|
||||
| `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 |
|
||||
|
||||
!!! warning "`ClearKey` vs `ClearKeyCENC`"
|
||||
|
||||
@@ -1047,6 +1047,10 @@ An import uses only the content keys in the file and in your vaults. It never ge
|
||||
from a CDM. When a track needs a content key that neither has, the import stops and names the
|
||||
KID. To fix this, export the title again with that track selected.
|
||||
|
||||
An import also stops when the export names a DRM system that this version of unshackle does not
|
||||
know, and the message names that system. An HLS AES-128 entry from another tool does not stop the
|
||||
import, because the playlist gives that content key.
|
||||
|
||||
!!! warning "The export file is a secret"
|
||||
It holds the content keys and usually a signed manifest URL. Hand it over on purpose,
|
||||
not by accident.
|
||||
|
||||
@@ -41,8 +41,9 @@ then decrypts the file with those keys.
|
||||
|
||||
## Supported DRM systems
|
||||
|
||||
unshackle implements seven DRM systems. Only the first two need a device file and a
|
||||
license-server handshake. The rest are special cases.
|
||||
unshackle has five DRM systems built in. Only the first two need a device file and a
|
||||
license-server handshake. The rest are special cases. A DRM plugin adds another system (see
|
||||
[DRM plugins](#drm-plugins)).
|
||||
|
||||
| System | Device file | License flow | Decryption |
|
||||
|--------|-------------|--------------|------------|
|
||||
@@ -50,8 +51,6 @@ 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. 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 |
|
||||
|
||||
!!! warning "Three different ClearKeys"
|
||||
@@ -602,6 +601,39 @@ unshackle dl --skip-dl --all-drm --export EXAMPLE 81234567
|
||||
shows a warning and ignores the flag.
|
||||
- A remote CDM that stores content keys can answer without a challenge to the service.
|
||||
|
||||
## DRM plugins
|
||||
|
||||
A DRM system that is not built in comes from a plugin. A plugin is a zip file or a folder that holds
|
||||
one Python package. Put it in [`directories.plugins`](../reference/configuration/directories.md).
|
||||
unshackle loads the plugins once per process, at the first DRM lookup, and never from a peer or a URL.
|
||||
Restart `unshackle serve` after you add or replace a plugin. A plugin that
|
||||
does not load gives one warning that names its file. A track that needs a plugin that is not loaded
|
||||
stops with `No DRM plugin '<id>' is installed`.
|
||||
|
||||
A plugin sets the facts of its system: its id, its label, how it gets the content key, and how it
|
||||
decrypts. The service gives the content key of a plugin that holds its key. A plugin device licenses
|
||||
a plugin that licenses locally. A plugin decrypts each segment and then the merged file, or the
|
||||
merged file once. The README of each plugin gives its device files, its tools and its limits.
|
||||
|
||||
- **Devices:** a plugin device file is `<name><suffix>`, with the suffix that the plugin sets. A plugin
|
||||
can carry its own device files and name a default device. unshackle looks for a device in
|
||||
`directories.wvds`, then in `directories.prds`, then in the device files of the plugin, so your own
|
||||
file comes first. A service that needs a plugin device gets the default device of the plugin when
|
||||
its [`cdm`](#selecting-which-device-to-use-the-cdm-config) entry names no device of that system.
|
||||
To use another device, name it under the plugin id in the `cdm` mapping, as you name a device
|
||||
under `widevine`.
|
||||
- **`--remote`:** the server and each client must load the same plugin. The server sends the plugin
|
||||
id, the KIDs, the label and the data that the plugin lets a peer carry; never a content key or a
|
||||
path. A client without the plugin stops the title with `Unknown DRM type '<id>' from the server`.
|
||||
The server sends the content key of a plugin DRM that licenses locally
|
||||
only in a remote session that uses the server CDM. The server loads the plugin device, so a client
|
||||
needs no device.
|
||||
- **Export:** an export writes a plugin DRM under the plugin id, with the same fields as `--remote`.
|
||||
An import without the plugin stops with `Unknown DRM system '<id>' in the export`.
|
||||
- **Decode check:** FFmpeg checks the content key of a plugin DRM that licenses locally after the
|
||||
merge, as for a vault key. A content key that does not decode stops the track (see
|
||||
[Vaults](vaults.md#wrong-keys-from-a-poisoned-vault)).
|
||||
|
||||
## Keys, vaults, and caching
|
||||
|
||||
Fetching a license is comparatively slow and, for some services, rate-limited.
|
||||
|
||||
@@ -303,11 +303,10 @@ 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 plugin DRM track stops after its decryption"
|
||||
**Symptom:** the download of a track of a DRM plugin stops with `The <label> content key of KID <kid> does not decrypt track <id>`, and unshackle keeps no output file.
|
||||
|
||||
**Inspect:** FFmpeg could not decode the decrypted track. The content key is wrong, or the platform changed its format and the plugin decrypter no longer fits it. unshackle flags the pair in the local vaults and does not copy it to another vault. Read the README of the plugin for its other decrypter. See [DRM plugins](drm-and-cdm.md#drm-plugins).
|
||||
!!! 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.
|
||||
|
||||
|
||||
@@ -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, 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.
|
||||
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 track of a DRM plugin that licenses locally. A plugin track gets the check of the whole file after the merge of its decrypted segments. 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 plugin that decrypts each segment can fix the merged file 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 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.
|
||||
Per-segment decryption gives up the retry. With `decrypt_segments` on, and always with a plugin that decrypts each segment, 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`.
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ directories:
|
||||
| `exports` | path | `<data>/exports` | Yes | Export JSON files. |
|
||||
| `wvds` | path | `<data>/WVDs` | Yes | Widevine device files (`.wvd`). |
|
||||
| `prds` | path | `<data>/PRDs` | Yes | PlayReady device files (`.prd`). |
|
||||
| `plugins` | path | `unshackle/plugins` | Yes | DRM plugins: zip files or folders (see [DRM plugins](../../guide/drm-and-cdm.md#drm-plugins)). |
|
||||
| `dcsl` | path | `<data>/DCSL` | Yes | DCSL data. |
|
||||
| `commands` | path | `unshackle/commands` | Yes | CLI command modules. |
|
||||
| `services` | list \| path | `[unshackle/services]` | Yes | Service search paths and/or remote repo specs (see below). |
|
||||
|
||||
@@ -80,7 +80,9 @@ needs a device for each system from one of these shapes.
|
||||
unshackle finds the resolved name in [`remote_cdm`](#remote_cdm) by `name` first. If no entry
|
||||
matches, unshackle loads it as a local device file, in this order: `<name>.prd` in
|
||||
`directories.prds`, `<name>.prd` in `directories.wvds`, then `<name>.wvd` in
|
||||
`directories.wvds`.
|
||||
`directories.wvds`, then a device file of a DRM plugin, `<name><suffix>` in `directories.wvds` or
|
||||
`directories.prds`, then in the device files of the plugin. A service that needs a plugin device gets
|
||||
the default device of the plugin when its entry names no device of that system.
|
||||
|
||||
## `remote_cdm`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user