FairPlay Streaming Programming Guide
FairPlay Streaming Programming Guide
Programming Guide
Developer
Contents
About FairPlay Streaming ....................................................................................................................6
At a Glance ...........................................................................................................................................................................6
A Key Security Module Wraps a Key for Delivery .........................................................................................8
An FPS-Aware Playback App Asks the Key Security Module for a Key ...............................................8
FPS Sends Content Keys Securely ......................................................................................................................8
Content Server Delivers the Content Stream ..............................................................................................10
FairPlay Streaming SDK Contents .....................................................................................................................10
See Also ...............................................................................................................................................................................10
Programming the Key Security Module .........................................................................................11
Overview of Processing Steps ....................................................................................................................................11
Cryptographic Formula Syntax ..................................................................................................................................11
SPC and CKC Messages .................................................................................................................................................12
TLLV Block Structure...............................................................................................................................................12
The SPC Message .............................................................................................................................................................14
The SPC Payload ......................................................................................................................................................14
Session Key and Random Value Block ............................................................................................................17
Session Key and Random Value Integrity Block .........................................................................................18
Protocol Version Blocks .........................................................................................................................................18
Constructing the CKC Message .................................................................................................................................21
CKC Payload ...............................................................................................................................................................21
Encrypting the Content Key ...............................................................................................................................22
Returning SPC Blocks in the CKC Payload ....................................................................................................23
Encrypting the CKC Payload...............................................................................................................................23
Understanding the TLLVs...................................................................................................................25
Capabilities ........................................................................................................................................................................25
Device Info Support .......................................................................................................................................................27
Kext Deny List ...................................................................................................................................................................28
Device Identity .................................................................................................................................................................29
Security Level Support ..................................................................................................................................................31
HDCP Enforcement.........................................................................................................................................................34
Renting and Leasing the Content Key ............................................................................................35
• Apple TV.
This will enable playback of encrypted video content. This content is delivered over the Web using HTTP
Live Streaming (HLS) technology.
For simplicity, these devices will collectively be referred to as “Apple devices” throughout the remainder
of this document.
Note that FPS also delivers keys to FPS-enabled TVs and STBs via AirPlay protocol.
FPS protects the delivery of keys that decrypt streamed audio and video media. An Apple device can
securely acquire a key from a content provider's key server. The operating system uses the key to
decrypt the media before playback.
At a Glance
As an approved Apple FPS developer, you implement FPS by writing code to run on your key server and
in your playback app, so that both recognize FPS messages. When an Apple device plays a media stream
with a playlist containing an FPS-speci c tag, the operating system asks the app to obtain the
decryption key. To do so, the app calls an API that invokes FPS, causing the operating system to prepare
an encrypted request for the key for that media. When the app sends the request to the server, the FPS
code on the server wraps the required key in an encrypted message and sends it to the app. The app
then asks the operating system to unwrap the message and decrypt the stream, so the Apple device can
play the media.
• Writing a Key Security Module that is installed in a key server's software. This module exchanges
messages with the Apple device during the FPS process.
An FPS-Aware Playback App Asks the Key Security Module for a Key
A FPS-aware playback app uses an operating system programming interface to obtain the encrypted
request for the key, send it to the KSM, and receive the key for the media asset decryption. Your app will
also need code supporting user interactions.
After the FPS software receives the CKC, it extracts the content key and provides the key to the OS. The
OS uses the key to decrypt and play the content requested in step 1 of Figure 1-2.
The streaming media playlist contains a list of versions of FPS that the key server supports. The
operating system discerns and lists the mutually recognized FPS versions in the operating system’s
encrypted key request. The key server then picks which version to use.
Throughout this process, the app and the server can communicate through any transport link chosen by
the app developer.
The content streams in conformance with the HLS protocol, using H.264 video and audio formats.
Part 1. The FairPlay Streaming Server SDK contains a reference implementation of the Key Security
Module, a client sample, a speci cation and a set of test vectors. The test vectors can help establish and
test the Key Security Module.
Part 2. The FPS Deployment Package contains the D Function and speci cation along with instructions
on how to generate the FairPlay Streaming Certi cate, private key and Application Secret key (ASk).
An FPS transaction round-trip between the server Key Security Module and a client requires both parts.
The content owner must request the FPS Deployment Package materials to complete the Key Security
Module for production deployment.
See Also
The following documents contain speci cations and instructions that supplement the material in this
programming guide:
• See HTTP Live Streaming Overview for general guidance on Apple streaming technology used
with FairPlay Streaming.
• See MPEG-2 Stream Encryption Format for HTTP Live Streaming for information on the
FairPlay Streaming media formats.
• See HTTP Live Streaming Protocol for the IETF Internet-Draft of the HLS speci cation.
• See the following industry standards, relevant to FPS:
• Information technology—generic coding of moving pictures and associated audio
information: Systems is the ITU-T Recommendation H.222.0 document, also published as
ISO/IEC International Standard 13818-1:2013.
• Advanced video coding for generic audiovisual services is the ITU-T Recommendation
H.264 document, also published as ISO/IEC International Standard 14496-10:2014.
• Information technology—Coding of audio-visual objects—Part 3: Audio is the ISO/IEC
International Standard 14496-3:2009.
• Digital Audio Compression Standard (AC-3) is the Advanced Television Systems Committee
(ATSC) standard A/52:2012.
The KSM serves as a liaison between the playback app and the Apple device. The initial message from
app to Apple device contains the server playback context (SPC). The Apple device’s operating system
parses the SPC and generates the content key context (CKC). The KSM encrypts and delivers the content
key to the Apple device. The Apple device uses the content key to decrypt the FPS media sent from the
content server. Requesting a Content Key from the Key Server describes this SPC exchange.
1 Receive an SPC message from an app running on an Apple device and parse it. See The SPC
Message.
2 Check the SPC's certi cate hash value against the AC. See Identifying Your FPS App with an
Application Certi cate and Table 2-3.
5 Decrypt the session key and random value block in the SPC payload. See Decrypting the
[SK...R1] Payload.
6 Check the integrity of the SPC message. See Session Key and Random Value Integrity Block.
Block length 8-11 The number of bytes in the value plus padding elds of the
TLLV (following the tag, block length, and value length
elds). The block length must be lled out to a multiple of
16 bytes by extending the padding eld.
Value length 12-15 The number of bytes in the value eld. This number may be
any amount, including 0x0000.
Value 16 . . . k The payload of the TLLV, starting with byte 16 of the block.
Padding k+1 . . . n A eld that begins with the next byte after the value eld
(padding_size) (byte k+1). It must ll out the TLLV to a multiple of 16 bytes,
but may be randomly extended in increments of 16 bytes.
Thus the following relation holds:
padding_size = block_length - value_length
The padding eld must contain random values, not all 0x00
or 0xFF bytes.
Note: An SPC message may contain reserved TLLV blocks with tag values not covered in this
documentation. Such blocks should be ignored by the KSM.
SPC version 0-3 The version number of the SPC. The version number
covered by this programming guide is 0x00000001.
Encrypted 24-151 The key for decrypting the SPC payload. This key is itself
AES-128 key encrypted, using RSA public key encryption with Optimal
Asymmetric Encryption Padding (OAEP), as described in
SPC Payload Decryption.
Certi cate hash 152-171 The SHA-1 hash value of the encrypted Application
Certi cate, which identi es the private key of the developer
that generated the SPC. See Identifying Your FPS App with
an Application Certi cate.
SPC payload 172-175 The number of bytes in the encrypted SPC payload.
length Because the payload consists of blocks whose lengths are
multiples of 16 bytes, this number is a multiple of 16.
Obtain the key for the AES decryption of the SPC payload (called SPCK) by decrypting bytes 24-151 of
the SPC message using the RSA cryptography standard with Optimal Asymmetric Encryption Padding
(OAEP). The key for the RSA decryption of the SPCK is the server's RSA private key. An example of such a
key is in the FPS developer support package; see Using the FPS SDK and Tools.
In cryptographic formula syntax, decrypting the payload of the SPC consists of the following two
decryption processes:
[SK...R1] 0x3d1a10b8bffac2ec A combination of values that the KSM will use to encrypt
the content key and the CKC payload. Parse and decrypt
this block as described in Session Key and Random
Value Block. Return the R1 value to FPS in the payload of
the CKC message, as described in CKC Payload.
[SK...R1] integrity 0xb349d4809e910687 A 16-byte value used to check the integrity of the
contents of the [SK...R1] block. See Session Key and
Random Value Integrity Block.
Anti-replay (AR) 0x89c90f12204106b2 A 16-byte value used in the encryption of the CKC
seed payload. See Encrypting the CKC Payload.
Tag return 0x19f9d4e5ab7609cb A TLLV block that contains zero or more concatenated 8-
request byte values, each of which is the tag for a di erent TLLV
block in the SPC. Retrieve and return all of the TLLV as is
in the CKC payload. See Returning SPC Blocks in the CKC
Payload.
Asset ID 0x1bf7f53f5d5d5a1f A content provider ID that tells the key server which
content needs to be decrypted. The playback app may
generate this value, or the FPS implementer may create
it. Its length can range from 2 to 200 bytes, inclusive. The
asset ID content is padded to a multiple of 16 bytes,
regardless of the original length.
Protocol version 0x5d81bcbcc7f61703 A 4-byte value that identi es the version of FPS that the
used Apple device is using for this FPS transaction. See
Protocol Version Blocks.
Media playback 0xeb8efdf2b25ab3a0 Media playback information for rental and lease. See
state TLLV for Rental and Lease.
Value Description
0xabb0256a31843974 AirPlay will send content to an Apple TV box.
• The 16-byte session key, SK, which is used to encrypt the content key as described in Encrypting
the Content Key.
• A 44-byte random number, R1, which is used in the encryption of the CKC payload as described
in Encrypting the CKC Payload. These bytes are also returned to the Apple device in the CKC
payload, as shown in Table 2-11.
The structure of the whole [SK...R1] block, including its tag and length elds, is listed in Table 2-6.
Decrypt the payload contained in this block as described in Decrypting the [SK...R1] Payload.
Value length 12-15 The length of the content of this TLLV block in bytes,
0x00000070 (decimal 112). The content consists of the
initialization vector and payload elds.
Payload 32-127 The 96-byte payload of the block. Decrypt this payload as
described in Decrypting the [SK...R1] Payload to yield its
contents.
In cryptographic formula syntax, decrypt the payload of the [SK...R1] block using the following process:
Session key (SK) 0-15 A 16-byte value used in the encryption of the content key. See
Encrypting the Content Key.
R1 36-79 A 44-byte random number used in the encryption of the CKC payload
and returned to the Apple device in the CKC payload. See Encrypting
the CKC Payload.
Integrity bytes 80-95 16 bytes used to check the integrity of this SPC message, as explained
in Session Key and Random Value Integrity Block.
The streaming content’s playlist contains a list of the FPS versions that the key server supports for that
content. As a good practice, your KSM should compare this list with the list of FPS versions in the
protocol versions supported block. The protocol version used block should contain the ID of the most
recent version common to both platforms. If the Apple device is not using the most recent common
version, the app may be trying to attack FPS security. If there is no common version, the Apple device
should not have generated an SPC and the KSM should reject the transaction.
Note: Versioning should be decided between the server and the Apple device. The playback app should
never contain embedded version information.
Table 2-9 displays other con gurations that do not follow good practices and why these con gurations
should be avoided.
Table 2-9 Version con gurations that do NOT follow good practices
Version 1 Versions Used = 1 The server veri es the version used and uses
1 and 2 Supported = 1 and 2 version 1. However, a newer version of FPS is
available, so the server should be updated.
Versions Versions Used = 1 An app may have tried to exploit the server by
1 and 2 1 and 2 Supported = 1 and 2 forcing it to use an old version of FPS.
CKC version 0-3 The version number of the CKC. The version number
covered by this programming guide is 0x00000001.
CKC payload length 24-27 The number of bytes in the encrypted CKC payload.
Because the payload consists of blocks whose lengths are
multiples of 16 bytes, this number is a multiple of 16.
CKC Payload
The KSM uses the session key (SK) to encrypt the content key. The payload of a CKC message contains
the content key that the Apple device uses to decrypt the media for playback.
Table 2-11 lists the TLLV blocks in the CKC payload. The order of these blocks should be random.
Content key 0x47acf6a418cd091a A TLLV that speci es the period of validity of the content
duration key. This TLLV may be present only if the KSM receives an
SPC with a Media Playback State TLLV. See Establishing
the Rental and Lease Period.
Blocks speci ed The CKC must return, unchanged, the TLLV blocks that
by a tag return the SPC requested in a tag return request. See Returning
request SPC Blocks in the CKC Payload.
Required Security 0x644cb1dac0313250 An optional TLLV, that speci es the minimum required
Level Security Level of the client device. See Security Level
Support.
O ine Key 0x6375d9727060218c Support for o ine playback. See O ine Rental support.
Because all the blocks listed above are padded to multiples of 16 bytes, the CKC payload as a whole does
not require further padding.
The encrypted content key must be 16 bytes long. It becomes the content of the content key TLLV,
shown in Table 2-12, which is encrypted and made part of the CKC payload (see Table 2-11). The CKC
payload is further encrypted as described in Encrypting the CKC Payload.
Value length 12-15 The length of the content of this TLLV block in bytes,
0x00000020 (decimal 32).
Initialization vector 16-31 A 16-byte CBC initialization vector used in AES encryption
(IV) and decryption of audio and video assets.
Content key (CK) 32-47 The 16-byte content key encrypted using the SK.
Padding 48-n Random values that ll out the TLLV to a multiple of 16
bytes. See the description of the Padding eld in Table
2-2.
• An encrypted content key TLLV block containing the 16-byte encrypted content key, as
described in Encrypting the Content Key.
• The R1 TLLV block from the SPC payload; see Session Key and Random Value Block.
• All TLLV blocks from the SPC payload that must be returned in the CKC payload, as described in
Returning SPC Blocks in the CKC Payload.
To encrypt the CKC payload, compute the AR_key value by taking the rst 16 bytes of an SHA-1 digest
of the R1 value sent in the payload of the SPC; see Session Key and Random Value Integrity Block. That
AR_key value is then used as a key to encrypt the AR seed obtained from the SPC payload (see Table
2-4).
The resulting encrypted AR seed is the key that encrypts the CKC data section using AES-128 with cipher
block chaining (CBC). The KSM generates the CKC data initialization vector, sent to the Apple device in
bytes 8-23 of the CKC message, shown in Table 2-10.
In cryptographic formula syntax, encrypting the payload of the CKC consists of the following process.
Value length 12-15 The length of the content of this TLLV block in bytes,
0x00000010 (decimal 16).
Capabilities bits 16-23 An 8-byte eld containing capability bits 64-127. See Table
(high) 3-2.
The two capabilities bits elds are e ectively a 128-bit long value which is split into two 64-bit values for
ease of processing. Each capability bit indicates whether the Apple device supports a speci c feature.
HDCP Enforcement 0 When set, indicates that the Apple device can enforce the
HDCP restrictions given in the HDCP Enforcement TLLV.
When not set, the device cannot guarantee the HDCP
restrictions given in the HDCP Enforcement TLLV, and
therefore it is not recommended to release keys requiring
HDCP Type 1 to the device. Regardless of the setting of this
bit, if the HDCP Enforcement TLLV is not present, the device
will enforce HDCP Type 0. See Table 3-13.
Secure Invalidation 2 When set, indicates that the Apple device is capable of
supporting secure invalidation requests.
O ine Key TLLV v2 3 When set, indicates that the Apple device can support O ine
Key TTLV version 2.
Value length 12-15 The length of the content of this TLLV block in bytes.
“0x358c41b1ec78f599” Mac
“0xc1500767c86c1fae” AppleTV, FPS-enabled TV or STB
“0x8551fd5e31f479b3” iPhone, iPad, iPod
Table 3-5 Kext Deny List TLLV (included in the SPC sent to the server)
Value length 12-15 The length of the content of this TLLV block in bytes.
KDL version 16-19 Kext Deny List version.
Padding 20-n Random values that ll out the TLLV to a multiple of 16
(padding_size) bytes.
Device Class:
enum
{
kFPDIDeviceClassUnknown = 0,
// Apple devices
kFPDIDeviceClassAppleLiving = 1,
kFPDIDeviceClassAppleMobile = 2,
kFPDIDeviceClassAppleDesktop = 3,
kFPDIDeviceClassAppleSpatial = 4,
kFPDIDeviceClassAppleUnknown = 127,
kFPDIDeviceClassMax = 255,
};
The SPC reports the Security Level of the Apple device in the Security Level Support TLLV. The Key
Security Module can enforce a policy based on this. For example, the Key Security Module can refuse to
deliver high-value assets (4K / HDR) to AppleBaseline or Baseline devices.
See Table 3-7 and Table 3-8.
Using the optional Required Security Level TLLV, the Key Security Module may indicate the minimum
required Security Level of the client device to allow playback of the requested asset.
AppleBaseline/Baseline Platforms will not play video content restricted to AppleMain/Main devices.
AppleBaseline, Baseline, AppleMain and Main Security Level should only be used for video content.
Audio content must use Audio Security Level.
These are further described in Table 3-9, Table 3-10, and Table 3-11.
Table 3-7 Security Level Report TLLV (included in the SPC sent to the server)
Value length 12-15 The length of the content of this TLLV block in bytes.
Version 16-19 TLLV version. Currently supported version is 1.
Reserved 20-23 This eld is reserved
Security Level 24-31 Security Level of the Apple device.
See Table 8-2.
Table 3-9 Required Security Level TLLV (included in the CKC sent by the server)
Value length 12-15 The length of the content of this TLLV block in bytes.
Version 16-19 TLLV version. Currently supported version is 1.
Reserved 20-23 This eld is reserved and should be set to 0.
Security Level 24-31 Security Level. See Table 8-4.
Table 3-10
Name Value
Audio “0x17d99d574eed567d"
AppleBaseline/Baseline "0x32f0004966a5c4f8"
AppleMain/Main "0x4e7fd92421d588b4"
Message Description
-42811 The FPS library returns this error code when there is a Security Level violation.
Value Length 12-15 The length of the content of this TLLV block in bytes,
0x00000010 (decimal 16).
HDCP requirement 16-31 A 16-byte eld containing the HDCP level values. See
Table 3-13.
Value Description
0xEF72894CA7895B78 HDCP not required.
Video Rental
The content key is a rental type. FPS does not start the decryption if the content key has expired.
However, FPS continues the user experience if the content key expires during the playback. When
started again with an expired key, the Apple device declines the playback.
Secure Lease
The content key is a lease type. Typically, a content provider policy would restrict the number of
simultaneous playbacks (slots) for a user account. The server associates a slot to a device, and the server
delivers the content key with the expiration that represents the lease. The Apple device may request that
the key be renewed by the server before the lease expires. The server provides a new expiration time for
the content key, and playback continues uninterrupted. If the content key is not renewed, the Apple
device stops the playback when the lease expires. The server recognizes that playback has stopped and
frees the device slot.
This design ensures that a device is not orphaned (in a stale state) based on time rather than messaging
and garbage collection. The expiration triggers a server event to securely release the device slot. The
server knows playback stopped and frees the device slot as soon as the content key expires and the
PlayContent is discarded. Using the secure lease and the device identi cation, the server can implement
a robust solution for the management of simultaneous streams maintaining a seamless user experience.
Value Length 12-15 The length of the content of this TLLV block in bytes,
0x00000010 (decimal 16).
Creation Date 16-19 The time in seconds from Jan 1, 1970 to the time when the
SPC was created.
Playback State 20-23 The playback state of the Apple device at the time the SPC
was created. Possible values are listed in Table 4-2.
Padding 32-n (padding_size) Random values to ll out the TLLV to a multiple of 16 bytes.
See the description of the Padding eld in Table 2-2.
0x4f834330 State 3: The playback stream is playing, but the lease is about to expire. The
response CKC must contain a valid content key.
Note: The app is unable to modify or overrule the rental and lease periods speci ed in the CKC.
Value Length 12-15 The length of the content of this TLLV block in bytes, 0x00000010
(decimal 16).
See O ine FairPlay Streaming for additional rental and lease key types to support persistent keys.
• A rental period covers the initial delivery of a content key and the start of a stream. If the rental
period expires during playback, the stream continues to play until the media playback stops.
• A lease period covers the validity of the content key for media playback. If the lease period
expires during playback, the media playback stops.
Apps can save HTTP Live Streaming assets onto Apple devices. This is known as O ine HLS. This new
capability allows users to download and store their HLS movies while they have access to a fast, reliable
network, and watch them later without a network connection.
• iOS: 10.0
• macOS: 10.15
O ine HLS assets can be SAMPLE-AES encrypted. There are a few additional steps required for
downloading and managing encrypted O ine HLS assets to ensure the playability of downloaded assets
when no network connection is present.
When creating an AVURLAsset for use in downloading an O ine HLS asset, apps must install a
delegate to handle encryption keys. The persistent keys are not stored with downloaded HLS assets.
Instead, apps must store and manage persistent keys, using an AVAssetResourceLoader and a
delegate object implementing the AVAssetResourceLoaderDelegate protocol.The server may
enable an Apple device to persist the key either inde nitely or for the provided validity duration. To
enable persistence of the content key, the server’s CKC response shall contain a Content key duration
TLLV (TLLV tag 0x47acf6a418cd091a). See Table 4-3.
AVAssetResourceLoadingRequest
finishLoading
[Persistent Bundle]
The nal policy decision as to which content keys can be persisted on the device belongs to the Key
Security Module vending the CKC. The server has the option to allow the Apple device to persist the key
either inde nitely, or for a speci ed duration. To enable persistence of the content key, the server’s CKC
response shall contain a Content key duration TLLV.
FairPlay Streaming on the Apple device does not start the decryption if the persisted content key has
expired. However, playback on the Apple device continues even if the content key expires during
playback.
The diagram below shows the life cycle of a persistent key request.
AVAssetResourceLoadingRequest
streamingContentKeyDataForApp
[AVAssetResourceLoadingRequestStreamingContentKeyRequestRequiresPersistentKey]
SPC
CKC (persistent)
persistentContentKeyFromKeyVendorResponse
[CKC (persistent)]
Persistent Bundle
Store to app container
(inc. certificate and version list)
finishLoading
[Persistent Bundle]
Message Description
-42799 FPS returns this error code when Apple issues a security update and the existing
persistent key format is no longer supported. In this case, the application must request a
new persistent key from the server.
In iOS 12.2 and later, FPS supports relating multiple streams belonging to the same program. O ine Key
TTLV version 2 adds a new eld called Title ID. All sub-streams for a given program should have a
common Title ID. When the application requests the FairPlay Streaming component to create a Sync
SPC or invalidate a persistent key, FPS ensures that all persistent keys identi ed by the same Title ID
are invalidated. The updated Sync TLLV will include a list of all the invalidated Stream/Content IDs.
This eliminates the need to invalidate persistent keys on a one by one basis when multiple sub-streams
were downloaded for the program.
Note that FPS supports O ine Rental in all versions of iPadOS, and in macOS 10.15 and newer.
1. Storage duration (seconds). This speci es the maximum time the key stays valid prior to playback
being started. Measured from license acquisition time.
2. Playback duration (seconds). This speci es the maximum time the key stays valid after playback has
been started. Measured from the rst playback start time.
After content is downloaded and the content license is acquired, the app may report to the server the
remaining key validity duration using a Sync SPC (see below). This allows the server and the client to be
synchronized on when the license to play the downloaded asset will expire.
Example: A user rents a movie; the server sets the storage duration to 2,592,000 (30 days) and the
playback duration to 86,400 (24 hours). The user has up to 30 days to start watching the movie and 24
hours to nish watching it after starting the playback. If the app requests a Sync SPC to be created prior
to user starting playback, the “Duration to expiry” eld of the Sync TLLV will be set to 2,592,000 minus
the number of seconds passed since license was downloaded. The same SPC requested after playback
has started will contain a Sync TLLV with the “Duration to expiry” eld set to 86,400 minus the number of
seconds since playback was started.
O ine Key
Value length 12-15 The length of the content of this TLLV block in bytes.
Version 16-19 TLLV version. Currently supported version is 2. Supported
in iOS 12.2 and higher.
Storage duration 40-43 Asset storage validity duration in seconds. Starts at license
acquisition time. A value of zero means no limit.
Playback duration 44-47 Asset playback validity duration in seconds. Starts at asset
rst playback time. A value of zero means no limit.
Title ID 48-63 (Version 2 only) Unique ID common to all streams for the
ve content. The server receives this value in a Sync TLLV.
To enable dual expiry for an asset, the KSM should add an O ine Key TLLV to the returned CKC.
Note: An O ine Key TLLV cannot be used in the same CKC payload as an already existing Content Key
Duration TLLV. If both of these TLLVs are in the CKC, the processing of the CKC stops and an Invalid CKC
error is returned.
Since the CKC cannot be interpreted by the app, the server should notify the app that the asset is using
dual expiry so that the app knows that a Sync SPC can be generated.
Sync
An app can obtain a Sync SPC via the method [AVContentKeySession
makeSecureTokenForExpirationDateOfPersistableContentKey:completionHandler:].
The app should send the resulting SPC to the KSM. The KSM should distinguish between Sync SPCs and
other SPCs. Any SPC may contain a Sync TLLV, so you need to check the Sync TLLV for validity. Valid Sync
TLLVs will have the Version eld set to 1 or 2. Any other value is invalid. A Sync SPC is one with a valid
Sync TLLV.
Value length 12-15 The length of the content of this TLLV block in bytes.
Value length 12-15 The length of the content of this TLLV block in bytes.
Title ID 40-55 The 128 bit title ID provided in the O ine Key TLLV.
55-59 Remaining license validity time in seconds. It will be set to
Duration to expiry 0 if the license has expired, and to 0xFFFFFFFF if the
license doesn’t have an expiry date.
The following table contains the possible values for the Flag eld:
Once you have a working KSM you can request the FPS Deployment Package at https://
developer.apple.com/contact/fps/ which contains the D Function, instructions about how to generate
your Application Certi cate and Application Secret key (ASk) values. You need these to test your KSM
implementation with an FPS client.
Typically, playback apps provide a user interface for browsing and selecting the content to be streamed,
support user identi cation, and facilitate other user and content provider transactions. Additionally, an
FPS-aware playback app must establish two-way communication between the Apple device and a key
server to support FPS functions.
For general information about writing apps for Apple iOS devices, visit the Developer Center.
Every playback app that uses FPS must nd the media’s key server and establish communication with
that server. When the Apple device and the key server can exchange messages, the app must send the
server an FPS-created SPC message. This message contains a hash of the Application Certi cate
identifying your private key.
The app uses the resourceLoader property of the AVURLAsset subclass to obtain the instance of
AVAssetResourceLoader associated with the class. It uses the AVAssetResourceLoader method
You must create a Key Session to provide a context for message exchange with the Content Decryption
Module (CDM)/Key System. Per the EME speci cation, each Key Session is associated with a single
instance of Initialization Data provided in the createSession() call.
For FPS, this Initialization Data must be the following byte array.
AssetID + Certificate
In this expression, AssetId represents the byte array de ned in Table 2-4, Certificate represents the
Application Certi cate provided by Apple, and the + indicates concatenation of the two values. The
AssetId can be any string you choose.
Use the following events in your JavaScript for Safari to support FPS.
encrypted
The encrypted event nds the CDM, identi ed with the string com.apple.fps and allows for
creation of the keySession. The event triggers when a process requests playback of FPS protected
content.
message
The message event sends the SPC and obtains a CKC from the Key Server Module. The update()
function adds the CKC to the keySession.
keystatuseschange
The keystatuseschange event triggers when a change occurred in the keys in the session or their
status. See https://w3c.github.io/encrypted-media/#mediakeystatusmap-interface for more
information.
Apple provides samples in the FPS SDK, including a JavaScript implementation of the API for Safari on
macOS.
When the request is for a content key, the app invokes the delegate -
[AVAssetResourceLoadingRequest
streamingContentKeyRequestDataForApp:contentIdentifier:options:error:] method.
This method obtains the SPC message from the operating system. Then the app sends the SPC to the
key server, as shown in Figure 8-1, using appropriate transport forms and protocols.
If you want the application to report the error to the user at this stage of the process, use the
localizedDescription of NSError from
-streamingContentKeyRequestDataForApp:contentIdentifier:error:. You can access
another error instance through the NSUnderlyingErrorKey in the userInfo dictionary of the
NSError instance provided by
-streamingContentKeyRequestDataForApp:contentIdentifier:error:. This NSError
instance provides additional information of interest when debugging an application that tries to obtain
an SPC. It can contain one of the codes listed in Table 8-1.
Message Description
Beyond this chapter, the following books provide instruction on formatting and encrypting streams.
• HTTP Live Streaming IETF draft details the media formatting required to send your content via
HTTP. The advantages of HLS and implementation instructions are provided in HTTP Live
Streaming Overview.
• MPEG-2 Stream Encryption Format for HTTP Live Streaming explains features of the MPEG-2
standard.
• FPS does not support IVs listed in the EXT-X-KEY tag's IV attribute in an m3u8 playlist. The FPS-
aware app ignores any IV in the playlist. The Key Security Module only delivers the IV in the
content key context (CKC).
• -P is the short form of --streaming-key-delivery. Either form indicates that the key le is
32 bytes long, where the rst 16 bytes is the content key and the second 16 bytes is the
initialization vector (IV). This option is necessary for
KEYFORMAT="com.apple.streamingkeydelivery" streaming.
• The option --encrypt-iv is incompatible with FPS.
• If an existing key le is supplied to --encrypt-key-file, it must be 32 bytes long. The rst
16 bytes hold the content key, and the second 16 bytes hold the IV. The segment /tmp/
key.bin in Listing 9-2 represents a 32-byte le.
• The --stream-encrypt option is necessary if the key is to be delivered via FPS.
Listing 9-2 uses the mediafilesegmenter command to produce an m3u8 playlist for use with FPS.
Baseline Any non-Apple device that supports FairPlay Streaming. For example, any
AirPlay 2–enabled smart TV.
Main Any non-Apple device that supports FairPlay Streaming and guarantees
enhanced content protection robustness (su cient for studio 4K / HDR
playback).
The optional ALLOWED-CPC attribute of the EXT-X-STREAM-INF tag indicates which Security Level the
stream requires. Leverage it to avoid requesting assets that the device will not be able to play because it
does not have the required Security Level.
#EXT-X-STREAM-INF:AVERAGE-BANDWIDTH=2266124,_AVG-
BANDWIDTH=2266124,BANDWIDTH=3752516,VIDEO-
RANGE=SDR,CODECS="avc1.64001f,mp4a.40.2",AUDIO="audio-stereo-160",FRAME-
RATE=23.976,HDCP-LEVEL=TYPE-0,RESOLUTION=1186x494,ALLOWED-
CPC="com.apple.streamingkeydelivery:AppleBaseline/Baseline"
Note that you can only use this utility to test your KSM implementation when using the test values for
the private key and xed DASk value. You cannot use it to test your application, nor to validate CKCs
produced with your KSM implementation using production credentials.
1. Use the private key provided in the Development Certi cate and Private Key le in the pKeyPem
variable in the SKDServerUtils.c le
2. Use the DASk provided in the spc_internal_values_v2.txt le in the Verify CKC tool
(verify_ckc). Populate this value into spcData->DAS_k in the
SKDServer.c:SKDServerProcessEncrypted_SK_R1 function as a replacement for the
Dfunction.
3. Use the verify_ckc tool and test vectors to ensure the KSM can produce a valid CKC.
Make use of the SPC test vectors to simulate the client and exercise the KSM logic. The verify_ckc
command-line tool veri es CKCs that the KSM returns.
AR Tag -- 89c90f12204106b2
Tag size: 0x10
Tag length: 0xd0
Tag value:
f3 c6 9d 1e 8c c4 27 5a 6d 32 86 d3 32 61 3e 13
R2 tag -- 71b5595ac1521133
Tag size: 0x15
Tag length: 0xb0
Tag value:
11 f7 be 61 2c a9 5e f5 e0 07 ce 51 89 6a e4 50
2c a3 d8 80 1b -- -- -- -- -- -- -- -- -- -- --
DASk Value:
d8 7c e7 a2 60 81 de 2e 8e b8 ac ef 3a 6d c1 79
SPC SK Value:
You can use this information when debugging your KSM implementation. For example you can print out
TLLVs decrypted by your KSM and compare these values against the data reported by verify_ckc
utility.
AR Tag -- 89c90f12204106b2
Tag size: 0x10
Tag length: 0xd0
R2 tag -- 71b5595ac1521133
Tag size: 0x15
Tag length: 0xb0
Tag value:
11 f7 be 61 2c a9 5e f5 e0 07 ce 51 89 6a e4 50
2c a3 d8 80 1b -- -- -- -- -- -- -- -- -- -- --
DASk Value:
d8 7c e7 a2 60 81 de 2e 8e b8 ac ef 3a 6d c1 79
SPC SK Value:
af b4 6e 7b f5 f3 15 96 c1 c6 76 dc 15 e1 4d c6
AR Key Value:
R1 Tag -- ea74c4645d5efee9
Tag size: 0x2c
Tag length: 0x40
Tag value:
27 52 00 8e 1c 11 e2 24 e8 eb 07 ee c4 a0 9d 17
44 0a 63 72 d5 dc 21 09 e5 50 ec ac 98 60 61 3f
8b 7a 8b e6 b4 5a 69 83 2d 9e 8c e7 -- -- -- --
For example, you can inspect the CK Tag TLLV (58b38165af0e3d5a), which contains the Content Key
encrypted with the session key, and compare it against values printed by your KSM. If you are using the
Server Reference Implementation, locate the Content Key and encrypted Content Key in SKDServer.c,
function SKDServerFillCKCData(), variable ckcData->ck. This variable contains the unencrypted
Content Key prior to calling SKDServerAESEncryptDecrypt(), and the encrypted Content Key after
this call is completed.
Date Notes
2022-12-01 Updated description of Version eld in Device Identity TLLV (Table 3-6).
2021-06-11 Fixed an incorrect reference in the CKC version description in Table 2-10.
2021-03-10 Updated external links and renamed events in “Integrating FPS in Safari.”
2017-08-21 Added Capabilities TLLV and sections on O ine FairPlay Streaming and
O ine Rental Support.
Apple Inc.
One Apple Park Way
Cupertino, CA 95014