DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
widevine_encryption_flags.cc
1 // Copyright 2014 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 // Defines command line flags for widevine_encryption.
8 
9 #include "packager/app/widevine_encryption_flags.h"
10 
11 #include "packager/app/validate_flag.h"
12 #include "packager/base/logging.h"
13 #include "packager/base/strings/string_piece.h"
14 #include "packager/base/strings/string_util.h"
15 
16 DEFINE_bool(enable_widevine_encryption,
17  false,
18  "Enable encryption with Widevine license server/proxy. User should "
19  "provide either AES signing key (--aes_signing_key, "
20  "--aes_signing_iv) or RSA signing key (--rsa_signing_key_path).");
21 DEFINE_bool(enable_widevine_decryption,
22  false,
23  "Enable decryption with Widevine license server/proxy. User should "
24  "provide either AES signing key (--aes_signing_key, "
25  "--aes_signing_iv) or RSA signing key (--rsa_signing_key_path).");
26 DEFINE_bool(include_common_pssh,
27  false,
28  "When using Widevine encryption, include an additional v1 PSSH box "
29  "for the common system ID that includes the key IDs. See: "
30  "https://goo.gl/s8RIhr");
31 DEFINE_string(key_server_url, "", "Key server url. Required for encryption and "
32  "decryption");
33 DEFINE_string(content_id, "", "Content Id (hex).");
34 DEFINE_string(policy,
35  "",
36  "The name of a stored policy, which specifies DRM content "
37  "rights.");
38 DEFINE_int32(max_sd_pixels,
39  768 * 576,
40  "The video track is considered SD if its max pixels per frame is "
41  "no higher than max_sd_pixels. Default: 442368 (768 x 576).");
42 DEFINE_int32(max_hd_pixels,
43  1920 * 1080,
44  "The video track is considered HD if its max pixels per frame is "
45  "higher than max_sd_pixels, but no higher than max_hd_pixels. "
46  "Default: 2073600 (1920 x 1080).");
47 DEFINE_int32(max_uhd1_pixels,
48  4096 * 2160,
49  "The video track is considered UHD1 if its max pixels per frame "
50  "is higher than max_hd_pixels, but no higher than max_uhd1_pixels."
51  " Otherwise it is UHD2. Default: 8847360 (4096 x 2160).");
52 DEFINE_string(signer, "", "The name of the signer.");
53 DEFINE_string(aes_signing_key,
54  "",
55  "AES signing key in hex string. --aes_signing_iv is required. "
56  "Exclusive with --rsa_signing_key_path.");
57 DEFINE_string(aes_signing_iv,
58  "",
59  "AES signing iv in hex string.");
60 DEFINE_string(rsa_signing_key_path,
61  "",
62  "Stores PKCS#1 RSA private key for request signing. Exclusive "
63  "with --aes_signing_key.");
64 DEFINE_int32(crypto_period_duration,
65  0,
66  "Crypto period duration in seconds. If it is non-zero, key "
67  "rotation is enabled.");
68 
69 namespace shaka {
70 
72  bool success = true;
73 
74  const bool widevine_crypto =
75  FLAGS_enable_widevine_encryption || FLAGS_enable_widevine_decryption;
76  const char widevine_crypto_label[] =
77  "--enable_widevine_encryption/decryption";
78  // key_server_url and signer (optional) are associated with
79  // enable_widevine_encryption and enable_widevine_descryption.
80  if (!ValidateFlag("key_server_url",
81  FLAGS_key_server_url,
82  widevine_crypto,
83  false,
84  widevine_crypto_label)) {
85  success = false;
86  }
87  if (!ValidateFlag("signer",
88  FLAGS_signer,
89  widevine_crypto,
90  true,
91  widevine_crypto_label)) {
92  success = false;
93  }
94  if (widevine_crypto && FLAGS_signer.empty() &&
95  base::StartsWith(base::StringPiece(FLAGS_key_server_url), "http",
96  base::CompareCase::INSENSITIVE_ASCII)) {
97  LOG(WARNING) << "--signer is likely required with "
98  "--enable_widevine_encryption/decryption.";
99  }
100 
101  const char widevine_encryption_label[] = "--enable_widevine_encryption";
102  // content_id and policy (optional) are associated with
103  // enable_widevine_encryption.
104  if (!ValidateFlag("content_id",
105  FLAGS_content_id,
106  FLAGS_enable_widevine_encryption,
107  false,
108  widevine_encryption_label)) {
109  success = false;
110  }
111  if (!ValidateFlag("policy",
112  FLAGS_policy,
113  FLAGS_enable_widevine_encryption,
114  true,
115  widevine_encryption_label)) {
116  success = false;
117  }
118  if (FLAGS_include_common_pssh && !FLAGS_enable_widevine_encryption) {
119  PrintError("--include_common_pssh is only valid with "
120  "--enable_widevine_encryption");
121  success = false;
122  }
123 
124  if (FLAGS_max_sd_pixels <= 0) {
125  PrintError("--max_sd_pixels must be positive.");
126  success = false;
127  }
128  if (FLAGS_max_hd_pixels <= 0) {
129  PrintError("--max_hd_pixels must be positive.");
130  success = false;
131  }
132  if (FLAGS_max_uhd1_pixels <= 0) {
133  PrintError("--max_uhd1_pixels must be positive.");
134  success = false;
135  }
136  if (FLAGS_max_hd_pixels <= FLAGS_max_sd_pixels) {
137  PrintError("--max_hd_pixels must be greater than --max_sd_pixels.");
138  success = false;
139  }
140  if (FLAGS_max_uhd1_pixels <= FLAGS_max_hd_pixels) {
141  PrintError("--max_uhd1_pixels must be greater than --max_hd_pixels.");
142  success = false;
143  }
144 
145  const bool aes = !FLAGS_signer.empty() && FLAGS_rsa_signing_key_path.empty();
146  const char aes_label[] =
147  "--signer is specified and exclusive with --rsa_signing_key_path";
148  // aes_signer_key and aes_signing_iv are associated with aes signing.
149  if (!ValidateFlag(
150  "aes_signing_key", FLAGS_aes_signing_key, aes, true, aes_label)) {
151  success = false;
152  }
153  if (!ValidateFlag(
154  "aes_signing_iv", FLAGS_aes_signing_iv, aes, true, aes_label)) {
155  success = false;
156  }
157 
158  const bool rsa = !FLAGS_signer.empty() && FLAGS_aes_signing_key.empty() &&
159  FLAGS_aes_signing_iv.empty();
160  const char rsa_label[] =
161  "--signer is specified and exclusive with --aes_signing_key/iv";
162  // rsa_signing_key_path is associated with rsa_signing.
163  if (!ValidateFlag("rsa_signing_key_path",
164  FLAGS_rsa_signing_key_path,
165  rsa,
166  true,
167  rsa_label)) {
168  success = false;
169  }
170 
171  if (!FLAGS_signer.empty() &&
172  (FLAGS_aes_signing_key.empty() || FLAGS_aes_signing_iv.empty()) &&
173  FLAGS_rsa_signing_key_path.empty()) {
174  PrintError(
175  "--aes_signing_key/iv or --rsa_signing_key_path is required with "
176  "--signer.");
177  success = false;
178  }
179 
180  if (FLAGS_crypto_period_duration < 0) {
181  PrintError("--crypto_period_duration should not be negative.");
182  success = false;
183  }
184  return success;
185 }
186 
187 } // namespace shaka
void PrintError(const std::string &error_message)
bool ValidateWidevineCryptoFlags()
bool ValidateFlag(const char *flag_name, const std::string &flag_value, bool condition, bool optional, const char *label)