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_
All the methods that are virtual are virtual for mocking.
ProtectionSystem
Definition: crypto_params.h:31
@ kCommon
The common key system from EME: https://goo.gl/s8RIhr.
Decryption parameters.
Encrypted stream information that is used to determine stream label.
Encryption parameters.
double clear_lead_in_seconds
Clear lead duration in seconds.
static constexpr uint32_t kProtectionSchemeCenc
The protection scheme: "cenc", "cens", "cbc1", "cbcs".
bool vp9_subsample_encryption
Enable/disable subsample encryption for VP9.
std::string playready_extra_header_data
Extra XML data to add to PlayReady data.
std::function< std::string(const EncryptedStreamAttributes &stream_attributes)> stream_label_func
ProtectionSystem protection_systems
The protection systems to generate, multiple can be OR'd together.
static constexpr double kNoKeyRotation
std::string client_cert_private_key_file
Absolute path to the private key file.
std::string client_cert_private_key_password
Password to the private key file.
std::string program_identifier
PlayReady program identifier.
std::string client_cert_file
Absolute path to client certificate file.
std::string key_server_url
PlayReady license / key server URL.
Raw key encryption/decryption parameters, i.e. with key parameters provided.
std::map< StreamLabel, KeyInfo > key_map
std::vector< uint8_t > pssh
std::vector< uint8_t > iv
Widevine decryption parameters.
WidevineSigner signer
Signer credential for Widevine license / key server.
std::string key_server_url
Widevine license / key server URL.
Widevine encryption parameters.
Definition: crypto_params.h:88
WidevineSigner signer
Signer credential for Widevine license / key server.
Definition: crypto_params.h:96
std::string policy
The name of a stored policy, which specifies DRM content rights.
Definition: crypto_params.h:94
bool enable_entitlement_license
Enables entitlement license when set to true.
std::vector< uint8_t > content_id
Content identifier.
Definition: crypto_params.h:92
std::vector< uint8_t > group_id
Group identifier, if present licenses will belong to this group.
Definition: crypto_params.h:98
std::string key_server_url
Widevine license / key server URL.
Definition: crypto_params.h:90
Signer credential for Widevine license server.
Definition: crypto_params.h:63
std::string key
RSA signing private key.
Definition: crypto_params.h:83
SigningKeyType signing_key_type
Definition: crypto_params.h:74
std::string signer_name
Name of the signer / content provider.
Definition: crypto_params.h:65
std::vector< uint8_t > iv
AES signing IV.
Definition: crypto_params.h:79
std::vector< uint8_t > key
AES signing key.
Definition: crypto_params.h:77