Skip to main content

FairPlay Configuration

Through FairPlay Configuration, you can specify the desired FairPlay license specification within the license request.

This API requires encoded_data in the query param for authentication.

POST: https://app.tpstreams.com/api/v1/<org_code>/drm_license/?data=<encoded_data>/

Fields

NameTypeDescriptionRequired
spcstringServer Playback Context (SPC) — the key message from the player, typically base64-encoded.Yes
fairplayjsonSee the FairPlay table below for available fields.No

FairPlay

Name

Description

lease_duration_seconds (optional)

How long a streaming (online) license is valid (secon

rental_duration_seconds (optional)

How long offline licenses remain valid (seconds). Def

Sample Payload:

{
"spc": "base64EncodedSPCFromPlayer",
"fairplay": {
"lease_duration_seconds": 1800,
"rental_duration_seconds": 86400
}
}

You can obtain the encoded data by performing the following steps in Python:

Generate Encoded Data

import base64
import binascii
import hashlib
import json

from Cryptodome.Cipher import AES
from Cryptodome.Util.Padding import pad

encoded_content_data = generate_content_data(<content_id>)
signature = generate_signature(encoded_content_data)
data = {"content_data": encoded_content_data, "signature": signature}
data = json.dumps(data, separators=(',', ':'))
encoded_data = base64.urlsafe_b64encode(data).decode()

To generate encoded data you need content data Generating Content Data and Generate Signature.

Generating Content Data

You can obtain the content data by performing the following steps in Python:

import json
import base64

def generate_content_data(content_id, download=False, drm_type="fairplay"):
data = {
"content_id": content_id,
"download": download,
"drm_type": drm_type,
}
data_str = json.dumps(data, separators=(',', ':'))
return base64.urlsafe_b64encode(data_str.encode()).decode()

Generating Signature

You can obtain the signature field by performing the following steps in Python:

import base64
import binascii
import hashlib
import json

from Cryptodome.Cipher import AES
from Cryptodome.Util.Padding import pad

def generate_signature(data, key, iv):
hash = hashlib.sha1(data.encode()).digest()
cipher = AES.new(
binascii.unhexlify(key),
AES.MODE_CBC,
binascii.unhexlify(iv),
)
padded_hash = pad(hash, AES.block_size, style="pkcs7")
signature = cipher.encrypt(padded_hash)
return base64.b64encode(signature).decode()

key = "xxxx" # AES Signing key
iv = "yyy" # AES Signing iv
encoded_content_data = generate_content_data("cf6c30dd50c1492e82344ea3e139da1d")
signature = generate_signature(encoded_content_data, key, iv)

Parameters

NameTypeDescriptionRequired
org_codestringThe organization code for API endpointYes
content_idstringThe unique identifier for the content (UUID used when encrypting the video).Yes
AES_SIGNING_KEYstringThe AES key used for signing the content dataYes
AES_SIGNING_IVstringThe initialization vector (IV) for signingYes
info

AES_SIGNING_KEY, AES_SIGNING_IV and org_code will be provided by us.

You can retrieve the organization code and DRM keys by making a GET request to the API. Organization

Security Considerations:

The recommendation is to invoke the DRM license endpoint on the server, rather than on the client. This precaution is taken because passing the license configuration and calling it from the client could expose configurations to users.