Shaka Packager SDK
crypto_params.h
1 // Copyright 2017 Google Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #ifndef PACKAGER_MEDIA_PUBLIC_CRYPTO_PARAMS_H_
8 #define PACKAGER_MEDIA_PUBLIC_CRYPTO_PARAMS_H_
9 
10 #include <functional>
11 #include <map>
12 #include <string>
13 #include <vector>
14 
15 #include "packager/status.h"
16 
17 namespace shaka {
18 
21 enum class KeyProvider {
22  kNone,
23  kRawKey,
24  kWidevine,
25  kPlayReady,
26 };
27 
31 enum class ProtectionSystem : uint16_t {
32  kNone = 0,
34  kCommon = (1 << 0),
35  kWidevine = (1 << 1),
36  kPlayReady = (1 << 2),
37  kFairPlay = (1 << 3),
38  kMarlin = (1 << 4),
39 };
40 
41 inline ProtectionSystem operator|(ProtectionSystem a, ProtectionSystem b) {
42  return static_cast<ProtectionSystem>(static_cast<uint16_t>(a) |
43  static_cast<uint16_t>(b));
44 }
45 inline ProtectionSystem& operator|=(ProtectionSystem& a, ProtectionSystem b) {
46  return a = a | b;
47 }
48 inline ProtectionSystem operator&(ProtectionSystem a, ProtectionSystem b) {
49  return static_cast<ProtectionSystem>(static_cast<uint16_t>(a) &
50  static_cast<uint16_t>(b));
51 }
52 inline ProtectionSystem& operator&=(ProtectionSystem& a, ProtectionSystem b) {
53  return a = a & b;
54 }
55 inline ProtectionSystem operator~(ProtectionSystem a) {
56  return static_cast<ProtectionSystem>(~static_cast<uint16_t>(a));
57 }
58 inline bool has_flag(ProtectionSystem value, ProtectionSystem flag) {
59  return (value & flag) == flag;
60 }
61 
65  std::string signer_name;
66 
67  enum class SigningKeyType {
68  kNone,
69  kAes,
70  kRsa,
71  };
74  SigningKeyType signing_key_type = SigningKeyType::kNone;
75  struct {
77  std::vector<uint8_t> key;
79  std::vector<uint8_t> iv;
80  } aes;
81  struct {
83  std::string key;
84  } rsa;
85 };
86 
90  std::string key_server_url;
92  std::vector<uint8_t> content_id;
94  std::string policy;
98  std::vector<uint8_t> group_id;
101 };
102 
108  std::string key_server_url;
110  std::string program_identifier;
113  std::string ca_file;
115  std::string client_cert_file;
120 };
121 
123 struct RawKeyParams {
127  std::vector<uint8_t> iv;
131  std::vector<uint8_t> pssh;
132 
133  using StreamLabel = std::string;
134  struct KeyInfo {
135  std::vector<uint8_t> key_id;
136  std::vector<uint8_t> key;
137  std::vector<uint8_t> iv;
138  };
142  std::map<StreamLabel, KeyInfo> key_map;
143 };
144 
150  KeyProvider key_provider = KeyProvider::kNone;
151  // Only one of the three fields is valid.
152  WidevineEncryptionParams widevine;
153  PlayReadyEncryptionParams playready;
154  RawKeyParams raw_key;
155 
160 
164  static constexpr uint32_t kProtectionSchemeCenc = 0x63656E63;
165  static constexpr uint32_t kProtectionSchemeCbc1 = 0x63626331;
166  static constexpr uint32_t kProtectionSchemeCens = 0x63656E73;
167  static constexpr uint32_t kProtectionSchemeCbcs = 0x63626373;
168  uint32_t protection_scheme = kProtectionSchemeCenc;
174  uint8_t crypt_byte_block = 1;
178  uint8_t skip_byte_block = 9;
181  static constexpr double kNoKeyRotation = 0;
182  double crypto_period_duration_in_seconds = kNoKeyRotation;
185 
188  enum StreamType {
189  kUnknown,
190  kVideo,
191  kAudio,
192  };
193 
194  StreamType stream_type = kUnknown;
195  union OneOf {
196  OneOf() {}
197 
198  struct {
199  int width = 0;
200  int height = 0;
201  float frame_rate = 0;
202  int bit_depth = 0;
203  } video;
204 
205  struct {
206  int number_of_channels = 0;
207  } audio;
208  } oneof;
209  };
215  std::function<std::string(const EncryptedStreamAttributes& stream_attributes)>
217 };
218 
222  std::string key_server_url;
225 };
226 
232  KeyProvider key_provider = KeyProvider::kNone;
233  // Only one of the two fields is valid.
234  WidevineDecryptionParams widevine;
235  RawKeyParams raw_key;
236 };
237 
238 } // namespace shaka
239 
240 #endif // PACKAGER_MEDIA_PUBLIC_CRYPTO_PARAMS_H_
shaka::WidevineDecryptionParams::signer
WidevineSigner signer
Signer credential for Widevine license / key server.
Definition: crypto_params.h:224
shaka::PlayReadyEncryptionParams::client_cert_private_key_file
std::string client_cert_private_key_file
Absolute path to the private key file.
Definition: crypto_params.h:117
shaka::WidevineEncryptionParams
Widevine encryption parameters.
Definition: crypto_params.h:88
shaka::WidevineDecryptionParams
Widevine decryption parameters.
Definition: crypto_params.h:220
shaka::DecryptionParams::key_provider
KeyProvider key_provider
Definition: crypto_params.h:232
shaka::WidevineDecryptionParams::key_server_url
std::string key_server_url
Widevine license / key server URL.
Definition: crypto_params.h:222
shaka::PlayReadyEncryptionParams::client_cert_private_key_password
std::string client_cert_private_key_password
Password to the private key file.
Definition: crypto_params.h:119
shaka::ProtectionSystem::kCommon
@ kCommon
The common key system from EME: https://goo.gl/s8RIhr.
shaka::WidevineEncryptionParams::enable_entitlement_license
bool enable_entitlement_license
Enables entitlement license when set to true.
Definition: crypto_params.h:100
shaka::EncryptionParams::crypt_byte_block
uint8_t crypt_byte_block
Definition: crypto_params.h:174
shaka::EncryptionParams::EncryptedStreamAttributes
Encrypted stream information that is used to determine stream label.
Definition: crypto_params.h:187
shaka::EncryptionParams::kNoKeyRotation
static constexpr double kNoKeyRotation
Definition: crypto_params.h:181
shaka
All the methods that are virtual are virtual for mocking.
Definition: gflags_hex_bytes.cc:11
shaka::PlayReadyEncryptionParams::program_identifier
std::string program_identifier
PlayReady program identifier.
Definition: crypto_params.h:110
shaka::EncryptionParams::kProtectionSchemeCenc
static constexpr uint32_t kProtectionSchemeCenc
The protection scheme: "cenc", "cens", "cbc1", "cbcs".
Definition: crypto_params.h:164
shaka::EncryptionParams::protection_systems
ProtectionSystem protection_systems
The protection systems to generate, multiple can be OR'd together.
Definition: crypto_params.h:157
shaka::WidevineEncryptionParams::group_id
std::vector< uint8_t > group_id
Group identifier, if present licenses will belong to this group.
Definition: crypto_params.h:98
shaka::RawKeyParams::KeyInfo
Definition: crypto_params.h:134
shaka::WidevineSigner::key
std::string key
RSA signing private key.
Definition: crypto_params.h:83
shaka::EncryptionParams::key_provider
KeyProvider key_provider
Definition: crypto_params.h:150
shaka::RawKeyParams::key_map
std::map< StreamLabel, KeyInfo > key_map
Definition: crypto_params.h:142
shaka::KeyProvider
KeyProvider
Definition: crypto_params.h:21
shaka::WidevineEncryptionParams::policy
std::string policy
The name of a stored policy, which specifies DRM content rights.
Definition: crypto_params.h:94
shaka::WidevineSigner
Signer credential for Widevine license server.
Definition: crypto_params.h:63
shaka::WidevineSigner::iv
std::vector< uint8_t > iv
AES signing IV.
Definition: crypto_params.h:79
shaka::WidevineSigner::signer_name
std::string signer_name
Name of the signer / content provider.
Definition: crypto_params.h:65
shaka::EncryptionParams::playready_extra_header_data
std::string playready_extra_header_data
Extra XML data to add to PlayReady data.
Definition: crypto_params.h:159
shaka::WidevineSigner::key
std::vector< uint8_t > key
AES signing key.
Definition: crypto_params.h:77
shaka::RawKeyParams
Raw key encryption/decryption parameters, i.e. with key parameters provided.
Definition: crypto_params.h:123
shaka::WidevineEncryptionParams::key_server_url
std::string key_server_url
Widevine license / key server URL.
Definition: crypto_params.h:90
shaka::EncryptionParams::vp9_subsample_encryption
bool vp9_subsample_encryption
Enable/disable subsample encryption for VP9.
Definition: crypto_params.h:184
shaka::PlayReadyEncryptionParams
Definition: crypto_params.h:106
shaka::PlayReadyEncryptionParams::ca_file
std::string ca_file
Definition: crypto_params.h:113
shaka::WidevineSigner::signing_key_type
SigningKeyType signing_key_type
Definition: crypto_params.h:74
shaka::ProtectionSystem
ProtectionSystem
Definition: crypto_params.h:31
shaka::PlayReadyEncryptionParams::client_cert_file
std::string client_cert_file
Absolute path to client certificate file.
Definition: crypto_params.h:115
shaka::DecryptionParams
Decryption parameters.
Definition: crypto_params.h:228
shaka::EncryptionParams
Encryption parameters.
Definition: crypto_params.h:146
shaka::EncryptionParams::EncryptedStreamAttributes::OneOf
Definition: crypto_params.h:195
shaka::EncryptionParams::clear_lead_in_seconds
double clear_lead_in_seconds
Clear lead duration in seconds.
Definition: crypto_params.h:162
shaka::WidevineEncryptionParams::signer
WidevineSigner signer
Signer credential for Widevine license / key server.
Definition: crypto_params.h:96
shaka::RawKeyParams::pssh
std::vector< uint8_t > pssh
Definition: crypto_params.h:131
shaka::EncryptionParams::stream_label_func
std::function< std::string(const EncryptedStreamAttributes &stream_attributes)> stream_label_func
Definition: crypto_params.h:216
shaka::EncryptionParams::skip_byte_block
uint8_t skip_byte_block
Definition: crypto_params.h:178
shaka::WidevineEncryptionParams::content_id
std::vector< uint8_t > content_id
Content identifier.
Definition: crypto_params.h:92
shaka::RawKeyParams::iv
std::vector< uint8_t > iv
Definition: crypto_params.h:127
shaka::PlayReadyEncryptionParams::key_server_url
std::string key_server_url
PlayReady license / key server URL.
Definition: crypto_params.h:108