Cdm

class Cdm : CdmApi

Widevine CDM helper that can:

  • open/close sessions

  • build signed license requests from a PSSH

  • parse signed license responses and expose decrypted Keys

Typical flow:

  1. Construct from a Widevine Device via fromDevice

  2. open a session and optionally setServiceCertificate

  3. Build a license challenge with getLicenseChallenge

  4. Send the challenge to a license server (not provided by this library)

  5. Parse the response with parseLicense

  6. Read keys with getKeys and close the session

This class is Kotlin Multiplatform and uses the same protobuf models as pywidevine.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Security level of the device this CDM was built from, or 0 when unknown.

Link copied to clipboard
val systemId: Int = 0

System id of the device this CDM was built from, or 0 when unknown.

Functions

Link copied to clipboard
open suspend override fun close(sessionId: ByteString)

Close and remove a session.

Link copied to clipboard
open suspend override fun getKeys(sessionId: ByteString, type: License.KeyContainer.KeyType?): List<Key>

Convenience to get decrypted keys for the session. Optionally filter by License.KeyContainer.KeyType.

Link copied to clipboard
suspend fun getKeysFromEntitlement(sessionId: ByteString, entitledPssh: PSSH): List<Key>

Unwrap the content keys carried by an ENTITLED_KEY PSSH.

Link copied to clipboard
suspend fun getLicense(sessionId: ByteString): License?

The license parsed by the most recent parseLicense call for this session, or null when none has been parsed.

Link copied to clipboard
open suspend override fun getLicenseChallenge(sessionId: ByteString, pssh: PSSH, licenseType: LicenseType, privacyMode: Boolean, requestType: LicenseRequest.RequestType): ByteArray

Build and sign a Widevine license request for the provided pssh. Stores internal request context needed to later parseLicense for this session.

Link copied to clipboard
suspend fun getServiceCertificate(sessionId: ByteString): SignedDrmCertificate?
Link copied to clipboard
open suspend override fun getServiceCertificateBase64(sessionId: ByteString): String?

The service certificate set for the session, re-encoded as Base64, or null.

Link copied to clipboard
open suspend override fun open(): ByteString

Open a new session.

Link copied to clipboard
open suspend override fun parseLicense(sessionId: ByteString, licenseMessage: ByteArray)

Parse and verify a Widevine license response for the provided sessionId. This consumes the previously stored request context created by getLicenseChallenge, decrypts contained keys and stores them on the session.

Link copied to clipboard
suspend fun setServiceCertificate(sessionId: ByteString, certificate: ByteArray?): String?

Set or clear a service certificate for a session. When set and privacyMode is true in getLicenseChallenge, the client_id will be encrypted with this certificate as per Widevine privacy mode.

open suspend override fun setServiceCertificate(sessionId: ByteString, certificateBase64: String?): String?

Overload of setServiceCertificate accepting a Base64-encoded certificate string. Pass null to clear the currently set certificate.