Hoichoi client platform · DRM

How the DRM licence works

The device's DRM module (CDM) creates a challenge; the page sends it to Hoichoi's licence server with the user's token; the licence goes back to the CDM. The native player only moves bytes. This page follows one key request end to end, with real sizes.

Mapped by Claude (agent) from source at a950df76e · kwry 29b36e1Public · every page in this group shares one access rule

The short answer

Yes, the challenge is a few KB. A FairPlay SPC is 9.3–11.9k characters of base64 (about 7–9 KB of bytes), as measured in the contract's own doc (PlayerSessionTypes.kt:395). The contract caps it at 16,384 base64 characters and the licence answer at 24,576. Both fit easily in kwry's 64 KiB per-message cap (Contract.kt:116), so one key request is one bridge message each way, with no chunking.

9.3–11.9kchars ≈ 7–9 KB bytes
Real FairPlay SPC (base64)
16,384base64 chars
Challenge cap on the wire
24,576base64 chars
Licence / CKC cap
64 KiB16 KiB normal target
kwry max message
30 s→ LICENCE_NO_ANSWER
No answer after

One key request, step by step

SequencePlayback and DRM licenceOpen full reader ↗
Playback + DRM licence: the page answers every key requestAndroid Media3 path; iOS FairPlay uses the same brokersession.open(Open)coordinator.openprepare(manifest)challenge bytesEffect.LicenseRequestPOST challenge + tokenlicenceCommand.ProvideLicenseprovide(id)state · QoS effectsOpen (JS chose rendition + DRM)Key request round-tripPlayingPlayer (JS) · native-main.ts · Sequence participantPlayer (JS)native-main.tsSessionWire · contract ↔ engine · Sequence participantSessionWirecontract ↔ engineSessionCoordinator · one surface · retry · Sequence participantSessionCoordinatorone surface · retryMedia3Engine · ExoPlayer + CDM · Sequence participantMedia3EngineExoPlayer + CDMLicenceBroker · timeout → NO_ANSWER · Sequence participantLicenceBrokertimeout → NO_ANSWERLicence server · Hoichoi contents API · Sequence participantLicence serverHoichoi contents APILegendmain requestreturnsecurityasync tracemessage

Same flow on Android (Widevine through Media3) and iOS (FairPlay through AVContentKeySession). Only the CDM and the challenge name differ.

1 · The page opens a session JS

openFor() picks the rendition, manifest URL and key system, and for FairPlay fetches the certificate itself and passes it as bytes (native-main.ts). The open carries no licence URL and no token: the contract has no field for them (PlayerSessionTypes.kt).

↓

2 · The CDM produces a challenge native

Media3 asks the Widevine CDM for a key request when it meets encrypted content; AVFoundation asks for an SPC. Media3 calls the engine's fetchLicense, whose URL is only a marker (VIA_JS) and is never fetched (Media3Engine.kt:623).

↓

3 · The bytes go to the page bridge

licenceViaJs base64-encodes the challenge and hands it to the LicenceBroker, which emits Effect.LicenseRequest {sessionId, requestId, keySystem, challengeB64} on the session's effects stream (Media3Engine.kt:341, LicenceBroker.kt:46). A timer starts after the request is registered, so a fast timeout can never leave it waiting forever.

↓

4 · The page calls the licence server JS

sessionLicence() builds the entitlement URL (key system, codec, app version) and POSTs the challenge bytes with the user's bearer or anonymous token. A 401/403 refreshes the token once and retries (license.ts). The POST leaves from the WebView's fetch, inside a playback.licence trace span (fetchPost).

↓

5 · The licence goes back bridge

The page sends Command.ProvideLicense {requestId, licenseB64}; SessionWire routes it to the broker, which completes the waiting key request exactly once (LicenceBroker.kt:68). Media3 / AVFoundation installs the key and playback starts.

↓

6 · Failure is bounded safety

No answer within 30 s, or the session is released, fails the key request as DRM LICENCE_NO_ANSWER, never a hang (Media3Engine.kt:337).

Why the page does it, not native

ConcernOwnerWhy
Licence URL, query params, codecJSThe entitlement API changes with the backend; a web deploy fixes it the same day
Token, refresh on 401/403JSThe page already owns the session; native held a second copy before (PlayerAuth, removed)
Body envelope / error parsingJS{data: base64} vs raw bytes is a server detail (license.ts:68)
Challenge bytes, key install, offline key storageNativeOnly the OS CDM can create the challenge or hold the key
Timeout backstopNativeA dead page must not hang the decoder

Cost of the round-trip

Extra hops
Two bridge messages (challenge out, licence in), each well under the 16 KiB target. In-process WebMessage, no network.
Encoding
Base64 grows bytes by 4/3, so an ~9 KB SPC becomes ~12k characters. The contract's limits are set in base64 characters for that reason.
When it happens
Once per key, at start (and on key rotation). Not per segment.
Offline downloads
Same broker, with a dl- session prefix, and the page answers with a persistent licence (SessionWire.kt:65).
Cast receiver
The TV asks the phone's page over the Cast peer bridge, with the same 16,384 / 24,576 caps (CastPeer.kt:90).

Left over from the old path

Dead native licence code is still compiled

CustomDrmCallback in videoplayer-core still has its own DefaultHttpDataSource and a runBlocking licence fetch (CustomDrmCallback.kt). On the session path its provider.fetchLicense is the DumbEnvironment, which hands the bytes to the page, so no native licence POST happens. Its provisioning request (executeProvisionRequest, a one-time Widevine device provisioning POST to Google) does still go out natively, which is correct: it carries no Hoichoi token.