feat(drm): license a plugin DRM at the licence step and over --remote with the client's plugin device

This commit is contained in:
imSp4rky
2026-12-03 15:51:42 -07:00
parent f1f91a7d5c
commit 0536056ed6
24 changed files with 803 additions and 136 deletions
+3 -1
View File
@@ -232,7 +232,9 @@ accepted URL/ID formats and options there.
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. A service whose DRM
plugin licenses locally gets its device from `ctx.obj.cdm_for("<plugin id>")`.
plugin licenses locally puts only the plugin data on the track: unshackle
licenses it at the licence step. To pick streams by the device, read the
device with `ctx.obj.cdm_for("<plugin id>")`.
`ctx.obj.cdm_for` is `None` where nothing licenses, for example in a search.
### `authenticate`: optional login
+2 -2
View File
@@ -999,7 +999,7 @@ the newlines must go out at once.
### `POST /api/session/create`
Make a remote session for a service and title. Authentication runs asynchronously in the background. This call returns immediately with `status: "authenticating"`, and you then poll the prompt endpoint. The body accepts `service` and `title_id` (both required). It also accepts a broad set of optional keys, because the body allows `additionalProperties`. These are `session_id`, `credentials` (`{username, password, extra?}`), `cookies` (base64 of zlib-compressed Netscape cookie file), `proxy`, `no_proxy`, `profile`, `cache` (map of forwarded cache files, keyed by the file path relative to the service cache directory with `/` separators and no `.json` suffix, so a nested key such as `session_web/<sha1>` lands in a subdirectory), `client_region`, `proxy_region`, `cdm_type`, `range_`, `vcodec`, `quality`, `best_available`, `dl_params`, `client`, and any service CLI options. `proxy_region` is the country code the client resolved `proxy` from; the server matches it against its own accounts. `client` is a freeform object the dashboard shows as sent (the CLI puts `version`, `code_hash`, `platform` and a redacted `argv` in it); the server ignores it above 4096 bytes of JSON.
Make a remote session for a service and title. Authentication runs asynchronously in the background. This call returns immediately with `status: "authenticating"`, and you then poll the prompt endpoint. The body accepts `service` and `title_id` (both required). It also accepts a broad set of optional keys, because the body allows `additionalProperties`. These are `session_id`, `credentials` (`{username, password, extra?}`), `cookies` (base64 of zlib-compressed Netscape cookie file), `proxy`, `no_proxy`, `profile`, `cache` (map of forwarded cache files, keyed by the file path relative to the service cache directory with `/` separators and no `.json` suffix, so a nested key such as `session_web/<sha1>` lands in a subdirectory), `client_region`, `proxy_region`, `cdm_type`, `range_`, `vcodec`, `quality`, `best_available`, `dl_params`, `plugins`, `client`, and any service CLI options. `plugins` maps the id of each DRM plugin that the client loads to `{version, device?}`; `device` holds the plain values of the device attributes that the plugin names in `device_facts`. The server refuses a title with a track of a plugin that is not in `plugins` (or a body with no `plugins`) on `POST /api/session/{id}/tracks` with `DRM_ERROR`, and gives `device` to the service only in a remote session that the client's device licenses. A `plugins` value over 16384 bytes of JSON, or of another shape, gets `INVALID_INPUT`. `proxy_region` is the country code the client resolved `proxy` from; the server matches it against its own accounts. `client` is a freeform object the dashboard shows as sent (the CLI puts `version`, `code_hash`, `platform` and a redacted `argv` in it); the server ignores it above 4096 bytes of JSON.
`session_id` is the ID that you give the remote session, so that you can delete it before this call answers. It must be the canonical text of a version 4 UUID. Without it, the server makes the ID. A remote session with your ID ends when you send no request for it and open no channel within 150s of the create. A second create with the same ID from the same API key and IP ends the first one if the first one has not answered, and replaces its remote session when the new one is stored. A second create that fails leaves that remote session open.
@@ -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), `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. |
| `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 from a server vault or from a licence of its own plugin device, only in a session that uses the server CDM, and only under the licence cap (`SERVER_CDM_CAPPED` above it). |
| `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. |
+3 -1
View File
@@ -497,7 +497,9 @@ session when the new one is stored, and the server answers the ID of another API
`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; 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
(the identity config keys the service lists in `client_config`), `plugins` (the version of each DRM plugin of the
client and the values of the plugin device attributes that the plugin names in `device_facts`; see
[endpoints](endpoints.md#post-apisessioncreate)), `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
(`additionalProperties: true`).
+1 -1
View File
@@ -456,7 +456,7 @@ service to talk to the platform's license server. unshackle recognizes six DRM c
| `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 |
| `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 |
| `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, put only the data the plugin reads: unshackle licenses it at the licence step. 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`"
+17 -7
View File
@@ -612,7 +612,8 @@ 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
a plugin that licenses locally, at the licence step of a download, after the vault lookup, as for a CDM
track: `--list` sends no licence, and `--vaults-only` and `--cdm-only` apply. 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
@@ -622,12 +623,21 @@ merged file once. The README of each plugin gives its device files, its tools an
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.
- **`--remote`:** the server and each client must load the same plugin. When a client opens a
remote session, it sends the id and the version of each plugin it loads. For a plugin device, it also sends
the values of the device attributes that the plugin names (for example the security level), never a
path or a device file. 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. The server refuses a title with a track of
a plugin that the client did not send with `This title needs the DRM plugin '<id>', which your
unshackle does not have`, before it sends the track list. A client that sends no plugin list (an
older unshackle) gets `This title needs the DRM plugin '<id>', and your unshackle sends no plugin
list`. In a remote session that the client's device licenses, the service on the server reads the
values that the client sent, so it picks the data that the client's device can license.
In a remote session that uses the server CDM, the server licenses a plugin DRM that licenses locally
with its own plugin device, under the licence cap of the API key. With `--cdm-only`, in a session
that the client licenses, and for a track above the cap, the client licenses with its own plugin
device. The plugin data can be bound to the device that the service on the server read, so a
different client device can fail to read it.
- **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