FP Streaming Programming Bad
FP Streaming Programming Bad
Programming Guide
! Developer
Contents
About FairP
FairPlay
lay Streaming.........................................................
..............................................................................
...........................................
......................................6
................6
At a Glance ...........................................................................................................................................................................6
...........................................................................................................................................................................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
......................................................................................................................8
Content Server Delivers the Content Stream ..............................................................................................1
..............................................................................................100
FairPlay
FairPlay Streaming SDK Contents.....................................................................................................................10
.....................................................................................................................10
See Also ...............................................................................................................................................................................10
...............................................................................................................................................................................10
Programm
Programming
ing the Key Security Module ....................
.........................................
...........................................
...........................................
..........................1
.....11
1
Overview of Processing
Processing Steps ....................................................................................................................................11
Cryptographic Formula
Formula Syntax ..................................................................................................................................11
..................................................................................................................................11
SPC and CKC Messages .................................................................................................................................................1
.................................................................................................................................................122
TLLV Block Structure
Structure...............................................................................................................................................12
...............................................................................................................................................12
The SPC Message.............................................................................................................................................................14
.............................................................................................................................................................14
The SPC Payload
Payload ......................................................................................................................................................14
......................................................................................................................................................14
Session Key and Random Value Block ............................................................................................................1
............................................................................................................177
Session Key and Random Value Integrity Block .........................................................................................1
.........................................................................................188
Protocol
Protocol Version
Version Blocks .........................................................................................................................................1
.........................................................................................................................................188
Constructing the CKC Message .................................................................................................................................21
.................................................................................................................................21
CKC Payload...............................................................................................................................................................2
...............................................................................................................................................................211
Encrypting the Content
Content Key ...............................................................................................................................22
...............................................................................................................................22
Listing 10-1
10-1 Parsing the SPC ..............................................................................................................................................5
..............................................................................................................................................599
Listing 10-2
10-2 Validating the CKC ........................................................................................................................................60
Note that FPS also delivers keys to FPS-enabled TVs and STBs via AirPlay protocol.
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.
FPS key delivery o"ers the following features and behaviors:
At a Glance
As an approved Apple FPS developer, you implement FPS by writing code to run on your key server and
in your
with playback
a playlist app, so that
containing both recognize
an FPS-specific tag,FPS
the messages.
operating When
systeman Apple
asks the device
app to plays
obtaina the
media stream
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.
The implementation
implementation process requires three
three programming
programming tasks:
• 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
OS thethe
uses FPSkey
software receives
to decrypt and the
playCKC,
the itcontent
extractsrequested
the content key and
in step 1 of provides the key to the OS. The
Figure 1-2.
The streaming media playlist contains
contains a list of versions
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,
Throughout process, the app and the server can communicate
communicate through any
any transport link chosen by
the app developer.
The content
content streams in conformance
conformance with the HLS protocol,
protocol, using H.264 video and audio fformats.
ormats.
Part 1. The FairPlay Streaming Server SDK contains a reference implementation of the Key Security
Module, a client sample, a specification
specification 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 specification along with instructions
on how to generate the FairPlay Streaming Certificate, 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
content owner must
must request the FPS Deployment
Deployment Package materials to complete
complete the Key
Key Security
Module for production deployment.
See Also
The following documents contain
contain specifications
specifications and instructions that supplement
supplement the material
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 specification.
• See the following industry standards, relevant to FPS:
• Information technology—generic coding of moving pictures and associated audio
Information
information: Systems is the ITU-T Recommendation H.222.0 document, also published as
ISO/IEC Internationa
Internationall Standard
S tandard 138
381
18-1:2013.
8-1:2013
• Advanced video coding for generic audiovisual services is the ITU-T Recommendation
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
onal Standard 14496-3:2009.
International
Internati
• Digital Audio Compression Standard (AC-3) is the Advanced Television Systems Committee
(ATSC) standard A/52:2012.
Overview of Proce
Processing
ssing Steps
Table 2-1 summarizes
summarizes a typical sequence of actions that a server and its KSM might
might perform to support
support
FPS.
1 Re
Rece
ceiv
ivee an
an SPC
SPC mes
messa
sage
ge fr
from
om an app
app ru
runn
nnin
ing
g on
on an
an App
Apple
le devi
device
ce an
and
d par
parse
se it
it.. See
See The SPC
Message.
2 Chec
Checkk the
the SP
SPC'
C's cer
certi
tific
ficat
atee has
hash
h val
value
ue agai
agains
nstt tthe
he AC. See
See Identifying Your FPS App with an
Application Certificate and Table 2-3.
5 Decry
Decryptpt the
the sses
essi
sion
on ke
keyy and
and rand
random
om valu
valuee blo
block
ck in the
the SPC
SPC payl
payloa
oad
d. See
See Decrypting the
[SK...R1] Payload.
6 Che
hecck th
thee in
inte
teg
gri
rity
ty of th
thee SPC
SPC messag
ssagee. Se Integrity Block.
Seee Session Key and Random Value Integrity
8 As
Asse
semb
mble
le the
the con
conte
tent
ntss of
of tthe
he CK
CKC
C pay
paylo
load
ad.. See
See Tab
able
le 2-1
2-11.
9 Encrypt the CKC payload. See Encrypting the CKC Payload.
10 Const
Constru
ruct
ct the
the CKC
CKC messa
message
ge and
and send
send itit to the
the app
app on the
the Appl
Applee de
devic
vice.
e. See Tabl
ablee 2-1
2-10.
Value length 12-15 The number of bytes in the value field. This number may be
any amount, including 0x0000 .
Value 16 . . . k The payload of
of the TLLV
TLLV, starting with byte
byte 16
16 of the block.
Padding k+1 . . . n A field that begins with the next byte after the value field
(padding_size) (byte k+1). It must fill out the TLLV to a multiple of 16 bytes,
but may be randomly extended in increments of 16 bytes.
Thus the following
following relation holds:
holds:
padding_size = block_length - value_length
The padding field must contain random
random values,
values, not
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.
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.
Certificate hash 152-171 The SHA-1 hash value of the encrypted Application
Certificate, which identifies the private key of the developer
that generated the SPC. See Identifying Your FPS App with
an Application Certificate.
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.
the content
this block askey and theinCKC
described payload.
Session Key Parse and decrypt
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.
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
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 identifies 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
T V box.
0x5f9c8132b59f2fde An Apple digital AV adapter will send content.
• The 16-byte
16-byte session key,
key, SK, which
which is used to encrypt
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
of the whole [SK...R1]
[SK...R1] block, including its tag and length fields, 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 fields.
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.
ASkrepresents
R2 representsthe
thecontents
playbackofapp's
the R2 blockkey.
secret in the SPC payload.
D represents the function described in D Function Computation Guide.
Field co
content Byte rraange Description
Se
Sess
ssio
ion
n key
key (S
(SK)
K) 0-1
-155 A 16
16-b
-byt
ytee val
valu
ue use
used
d in
in th
the enc
encry
rypt
ptio
ion
n of
of the
the cont
nten
entt kkey
ey.. See
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.
Inte
Integr
grit
ityy by
byte
tess 80-9
80-955 16 by
byte
tess us
used
ed to ch
chec
eckk the
the in
inte
tegr
grit
ityy of this
this SPC
SPC mess
messag
agee, as expl
explai
aine
ned
d
in Session Key and Random Value Integrity Block.
Note: Versioning should be decided between the server and the Apple device. The
The playback app should
never contain embedded version information.
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 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)
(SK) to encrypt the content
content key.
key. The payload of
of a CKC message
message contains
the content key that the Apple device uses to decrypt the media for playback.
Table 2-11
2-11 lists the TLLV
TLLV blocks in the CKC
CKC payload. The order of these blocks
blocks should be random.
random.
Required Security 0x644cb1dac0313250 An optional TLLV, that specifies 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.
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 fill out the TLLV to a multiple of 16
bytes. See the description of the Padding field in Table
2-2.
• An encrypted content key TLLV block containing the 16-byte encrypted content key, as
described in Encrypting the Conten
Contentt Key.
• The R1 TLLV
TLLV block from
from the SPC payload;
payload; see
see Session Key and Random Value Block.
• All TLLV
TLLV blocks from the SPC payload that must be returned in the CKC payload, as
as described in
Returning SPC Blocks in the CKC Payload.
To encrypt the CKC payload, compute the AR_key value by taking the first 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
Table
2-4).
The resulting encrypted AR seed is the key that encrypts the CKC data section
section using AES-128
AES-128 with cipher
block chaining (CBC). The KSM generates the CKC data initialization vector,
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).
Padding 32-n Random values that fill out the TLLV to a multiple of 16
(padding_size) bytes. See the description of the Padding field in Table
2-2.
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.
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 fill out the TLLV to a multiple of 16
(padding_size) bytes.
Value Length 12-15 The length of the content of this TLLV block in bytes.
FairP
airPla
lay
y ver
versi
sion
on REE
REE 40
40-4
-43
3 Versi
ersion
on o
off Fai
FairP
rPla
lay
y soft
softwa
ware
re run
runni
ning
ng in
in REE/
REE/use
userl
rlan
and.
d.
FairP
airPla
lay
y ver
versi
sion
on TEE
TEE 44-4
44-47
7 Versi
ersion
on of Fai
airP
rPla
lay
y sof
softw
twar
are
e runn
runnin
ing
g in
in TEE/
TEE/ke
kern
rnel
el..
Device Class:
enum
{
kFPDIDeviceClassUnknown = 0,
// Apple devices
kFPDIDeviceClassAppleLiving
kFPDIDeviceClassAppleLiving = 1,
kFPDIDeviceClassAppleMobile
kFPDIDeviceClassAppleMobile = 2,
kFPDIDeviceClassAppleDesktop
kFPDIDeviceClassAppleDesktop = 3,
kFPDIDeviceClassAppleSpatial
kFPDIDeviceClassAppleSpatial = 4,
kFPDIDeviceClassAppleUnknown
kFPDIDeviceClassAppleUnknown = 127,
kFPDIDeviceClassMax
kFPDIDeviceClassMax = 255,
};
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
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
further described in Table 3-9, Table 3-10,
3-10, and Ta
Table
ble 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 field is reserved
Security
ity Level 24-31 Security
ity Level of the Apple device.
See Table 8-2.
Reserved 32-35 This field is reserved.
Padding 36-n Random values that fill out the TLLV to a multiple of 16
(padding_size) bytes
Appl
AppleB
eBas
asel
elin
ine/
e/Ba
Base
seliline
ne "0
"0x3
x32f
2f00
0004
0496
966a
6a5c
5c4f
4f8"
8" An
Anyy plat
platffor
orm
m that
that sup
suppo
port
rtss FFai
airP
rPla
layy stre
stream
amin
ing
g.
Apple
leM
Main/Main "0x4e7fd92421d588b4" Any platform that support
rtss FairPlay Streaming
ing
and guarantees enhanced content protection
robustness (su#cient for studio 4K / HDR
playback).
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 field is reserved and should be set to 0.
Security Level 24-31 Security Level. See Table 8-4.
Padding 32-n Random values that fill out the TLLV to a multiple of 16
(padding_size) bytes.
Table 3-10
Name Value
Audio “0x17d99d574eed567d"
AppleBaseline/Baseline "0x32f0004966a5c4f8"
AppleMain/Main "0x4e7fd92421d588b4"
Message Description
-4
-428
28111 The
The FPS
FPS libr
library
ary ret
retur
urns
ns thi
thiss erro
errorr code
code whe
when
n ther
theree is a Sec
Secur
urity
ity Lev
Level
el vvio
iola
lati
tion
on..
Table 3-12
3-12 HDCP Enforcement TLLV
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 field containing the HDCP level values. See
Table
Table 3-13.
3-13.
Padding 32-n (padding_size) Random
Random value
valuess to fill
fill out
out the TLLV
TLLV to a mult
multipl
iplee of 16
16
bytes. See the description of the Padding field in Table
2-2.
Value Description
0xEF72894CA7895B78 HDCP not required.
Video Rental
The content
content key is a rental type. FPS does not start the decryption
decryption if the content
content key has expire
expired.
d.
However, FPS continues the user experience if the content key expires during the playback. When
started again with an expired key,
key, the Apple device declines the playback.
Secure Lease
The content
content key is a lease type. Typically,
Typically, a content
content provider
provider policy would
would restrict the number
number of
simultaneous playbacks (slots) for a user account. The
The server associates a slot to a device, and the server
delivers the content key with the expiration that represents
represents the lease. The
The Apple device may request that
the key be renewed by the server before the lease expires. The server provide
providess 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
ensures that a device
device is not orphaned (in a stale state) based
based on time rather
rather than messaging
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
PlayConte nt is discarded.
discarded. Using the secure lease and the device identification, the server can implement
a robust solution for the management of simultaneous streams maintaining a seamless user experience.
experience.
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.
Session ID 24-31 An ID that represents the playback of a media content
independently of its bit rates and content keys. When the user
closes and re-opens a movie, the Apple device generates a
new Session ID to identify the new instance.
0x4f834330 State 3: The playback stream is playing, but the lease is about to expire. The
response CKC must contain a valid content key.
Value Length 12-15 The length of the content of this TLLV block in bytes, 0x00000010
(decimal 16).
Lease Duration 16-19 The duration of the lease, if any, in seconds.
Rental D
Du
uration 20-23 The duration of the rental, if any, in se
seconds.
Key Type 24-27 The key type. Possible values are listed in Table 4-4.
Reserved 28-31 Reserved; set to a fixed value of 0x86d34a3a.
Padding 32-n Random values to fill out the TLLV to a multiple of 16 bytes. See
(padding_size) the description of the Padding field in Table 2-2.
See O!ine FairPlay Streaming for additional rental and lease key types to support persistent keys.
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.
O!ine HLS is supported starting with the following OS versions:
• iOS: 10.0
• macOS: 10.15
• iPad
iPadO
OS: al
alll ver
ersi
sio
ons
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 indefinitely 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
TLL V (TLLV tag 0x47acf6a418cd091a ). See Table 4-3.
AVAssetResourceLoadingRequest
finishLoading
[Persistent Bundle]
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
-4
-427
2799
99 FPS
FPS retu
return
rnss this
this err
error
or cod
codee when
when App
Apple
le iss
issue
uess a secu
securi
rity
ty upd
updat
atee and
and the
the exis
existi
ting
ng
persistent key format is no longer supported. In this case, the application must request a
new persistent key from the server.
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.
Reserved 20-23 This field is reserved and must be set to 0.
Content ID 24-39 Unique content ID of the downloaded asset assigned by
(Stream ID in the server. This server receives this value in a Sync TLLV.
version2)
Storage duration 40-43 Asset storage validity duration in seconds. Starts at license
acquisition time. A value of zero means no limit.
Padding 64-n Random values that fill out the TLLV to a multiple of 16
(padding_size) bytes. See the description of the Padding field in Table
2-2.
The byte range
range
for version 1 is
48-n
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
k nows that a Sync SPC can be generated.
Sync
An app can obtain a Sync SPC via the method [AVContentKeySession
makeSecureTokenForExpirationDateOfPersistableContentKey:completionHandler:] .
Value length 12-15 The length of the content of this TLLV block in bytes.
Padding 44-n Random values that fill out the TLLV to a multiple of 16
(padding_size) bytes. See the description of the Padding field in Table
2-2.
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 for the Flag field:
possible values for
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
instructions about how to generate
your Application Certificate and Application Secret key (ASk) values. You need these to test your KSM
implementation with an FPS client.
For general information about writing apps for Apple iOS devices, visit the Developer Center.
AssetID + Certificate
In this expression, AssetId represents the byte array defined in Table 2-4, Certificate represents the
Application Certificate provided by Apple, and the + indicates concatenation of the two values. The
The
AssetId can be any string you choose.
Use the following events in your JavaScript for Safari to support FPS.
encrypted
The encrypted event finds the CDM, identified 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
https://w3c.github.io/encrypted-media/#med
.io/encrypted-media/#mediakeystatusmap-interface for more
iakeystatusmap-interface
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
obtains the SPC message from the operating
operating system. Then the app sends the
the SPC to the
key server, as shown in Figure 8-1, using appropriate transport forms and protocols.
Processing
Processing the Key Server’
Ser ver’ss Response
The KSM constructs
constructs the CKC message containing
containing the content
content key as described
described in Programming the Key
Security Module. The key server returns a CKC message in response to the app’s SPC message, as shown
in Figure 8-1. After receiving this message, the app sends it to the operating system by invoking the
AVAssetResourceLoadingRequest method -[AVAssetResourceLoadingRequest
finishLoading] . The device can now decrypt and play the content stream using HLS as summarized
in HTTP Live Streaming Overview.
Message Description
-42656 Lease du
duration ha
has eexxpired.
-4
-426
2668
68 Th
Thee CK
CKC pas
passe
sed
d iin
n for
for proc
proces
essi
sing
ng is not
not vali
valid
d.
-4
-426
26772 A cer
certi
tific
ficat
atee iiss n
not
ot supp
supplilied
ed when
when cr
crea
eati
ting
ng SPC.
SPC.
-42673 assetId is not supplied when creating an SPC.
-4
-426
26774 Ver
ersi
sion
on lilist
st is no
nott su
supp
pplilied
ed when
when cr
crea
eati
ting
ng an SPC.
SPC.
-42675 The assetID supplied to SPC creation is not valid.
-4
-426
2676
76 An err
error
or occu
occurr
rred
ed du
duri
ring
ng SPC
SPC cr
crea
eati
tion
on..
-4
-426
2679
79 The
The cert
certifi
ifica
cate
te su
supp
pplilied
ed fo
forr SSPC
PC cr
crea
eati
tion
on is no
nott vval
alid
id..
-4
-426
26881 The
The ver
versio
sion
n llist
ist su
supp
pplie
lied
d to
to SPC
SPC cr
crea
eati
tion
on is no
nott vval
alid
id..
-4278
-427833 The ce
certifi
rtificat
catee ssupp
upplie
lied
d ffor
or SPC is not valid
valid and is possib
possibly
ly revok
revoked
ed..
• HTTP Live Streaming IETF draft details the media formatting required
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.
Listing 9-1
Adding FPS to an HLS Playlist
#EXT-X-KEY:METHOD=SAMPLE-AES,URI="skd://key65",
KEYFORMAT="com.apple.streamingkeydelivery",KEYFORMATVERSIONS="1"
• 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).
Baseli
lin
ne Any no
non-Apple de
device tth
hat ssu
upports
rts FFaair
irP
Play St
Streaming
ing. For ex
example, any
AirPlay 2–enabled smart TV
T V.
Main Any non-Apple device that supports FairPlay Streaming and guarantees
enhanced content protection robustness (su#cient for studio 4K / HDR
playback).
#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"
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. Th
Thee verify_ckc
command-line tool verifies 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
TLL
TLLVs
Vs decrypted by your
utility. your KSM and compare these
these values against the data reported by verify_ckc
$ ./verify_ckc -s SPC-CKC-Tes
SPC-CKC-Tests/FPS/spc1.
ts/FPS/spc1.bin
bin -c SPC-CKC-Tes
SPC-CKC-Tests/FPS/ckc1.
ts/FPS/ckc1.bin
bin
CKC/SPC Sanity Test v. 1.07
========================= Begin SPC Data ===============================
SPC container size 2688
SPC Encryption Key -
92 66 48 b9 86 1e c0 47 1b a2 17 58 85 1c 3d da
SPC Encryption IV -
5d 16 44 ea ec 11 f9 83 14 75 41 e4 6e eb 27 74
================ SPC TLLV List ================
[SK ... R1] Integrity Tag -- b349d4809e910687
Tag size: 0x10
Tag length: 0x40
Tag value:
54 a1 6b e0 13 7e f2 59 ab 3e 4f c7 96 90 82 5f
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 -- -- -- --
Date Notes
2022-12-0
-01
1 Upda
pdated de
description of
of Version fie
field in
in De
Device IId
dentity TLLV (Ta
(Table 3-
3-6).
6).
2021-06-11 Fixed an
an iin
ncorrect re
reference iin
n tth
he CK
CKC ve
version de
descript
ptiion iin
n Ta
Table 2-
2-10.
2021-03-10 Upda
pdated ext
exte
ernal lliinks an
and re
renamed ev
events iin
n “Integrating FP
FPS iin
n Sa
Safari.”
2020-11-05 Added in
intra-document lilinks an
and pe
performed a co
copy ed
edit.
2019-07-11 Added enhanced O!ine TLLV TLLV information to support grouping of sub-
streams for a particular program.
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