DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs
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_util.h"
14 
15 DEFINE_bool(enable_widevine_encryption,
16  false,
17  "Enable encryption with Widevine license server/proxy. User should "
18  "provide either AES signing key (--aes_signing_key, "
19  "--aes_signing_iv) or RSA signing key (--rsa_signing_key_path).");
20 DEFINE_bool(enable_widevine_decryption,
21  false,
22  "Enable decryption with Widevine license server/proxy. User should "
23  "provide either AES signing key (--aes_signing_key, "
24  "--aes_signing_iv) or RSA signing key (--rsa_signing_key_path).");
25 DEFINE_string(key_server_url, "", "Key server url. Required for encryption and "
26  "decryption");
27 DEFINE_string(content_id, "", "Content Id (hex).");
28 DEFINE_string(policy,
29  "",
30  "The name of a stored policy, which specifies DRM content "
31  "rights.");
32 DEFINE_int32(max_sd_pixels,
33  768 * 576,
34  "If the video track has more pixels per frame than max_sd_pixels, "
35  "it is considered as HD, SD otherwise. Default: 768 * 576.");
36 DEFINE_string(signer, "", "The name of the signer.");
37 DEFINE_string(aes_signing_key,
38  "",
39  "AES signing key in hex string. --aes_signing_iv is required. "
40  "Exclusive with --rsa_signing_key_path.");
41 DEFINE_string(aes_signing_iv,
42  "",
43  "AES signing iv in hex string.");
44 DEFINE_string(rsa_signing_key_path,
45  "",
46  "Stores PKCS#1 RSA private key for request signing. Exclusive "
47  "with --aes_signing_key.");
48 DEFINE_int32(crypto_period_duration,
49  0,
50  "Crypto period duration in seconds. If it is non-zero, key "
51  "rotation is enabled.");
52 
53 namespace edash_packager {
54 
56  bool success = true;
57 
58  const bool widevine_crypto =
59  FLAGS_enable_widevine_encryption || FLAGS_enable_widevine_decryption;
60  const char widevine_crypto_label[] =
61  "--enable_widevine_encryption/decryption";
62  // key_server_url and signer (optional) are associated with
63  // enable_widevine_encryption and enable_widevine_descryption.
64  if (!ValidateFlag("key_server_url",
65  FLAGS_key_server_url,
66  widevine_crypto,
67  false,
68  widevine_crypto_label)) {
69  success = false;
70  }
71  if (!ValidateFlag("signer",
72  FLAGS_signer,
73  widevine_crypto,
74  true,
75  widevine_crypto_label)) {
76  success = false;
77  }
78  if (widevine_crypto && FLAGS_signer.empty() &&
79  base::StartsWith(FLAGS_key_server_url, "http",
80  base::CompareCase::INSENSITIVE_ASCII)) {
81  LOG(WARNING) << "--signer is likely required with "
82  "--enable_widevine_encryption/decryption.";
83  }
84 
85  const char widevine_encryption_label[] = "--enable_widevine_encryption";
86  // content_id and policy (optional) are associated with
87  // enable_widevine_encryption.
88  if (!ValidateFlag("content_id",
89  FLAGS_content_id,
90  FLAGS_enable_widevine_encryption,
91  false,
92  widevine_encryption_label)) {
93  success = false;
94  }
95  if (!ValidateFlag("policy",
96  FLAGS_policy,
97  FLAGS_enable_widevine_encryption,
98  true,
99  widevine_encryption_label)) {
100  success = false;
101  }
102 
103  if (FLAGS_max_sd_pixels <= 0) {
104  PrintError("--max_sd_pixels must be positive.");
105  success = false;
106  }
107 
108  const bool aes = !FLAGS_signer.empty() && FLAGS_rsa_signing_key_path.empty();
109  const char aes_label[] =
110  "--signer is specified and exclusive with --rsa_signing_key_path";
111  // aes_signer_key and aes_signing_iv are associated with aes signing.
112  if (!ValidateFlag(
113  "aes_signing_key", FLAGS_aes_signing_key, aes, true, aes_label)) {
114  success = false;
115  }
116  if (!ValidateFlag(
117  "aes_signing_iv", FLAGS_aes_signing_iv, aes, true, aes_label)) {
118  success = false;
119  }
120 
121  const bool rsa = !FLAGS_signer.empty() && FLAGS_aes_signing_key.empty() &&
122  FLAGS_aes_signing_iv.empty();
123  const char rsa_label[] =
124  "--signer is specified and exclusive with --aes_signing_key/iv";
125  // rsa_signing_key_path is associated with rsa_signing.
126  if (!ValidateFlag("rsa_signing_key_path",
127  FLAGS_rsa_signing_key_path,
128  rsa,
129  true,
130  rsa_label)) {
131  success = false;
132  }
133 
134  if (!FLAGS_signer.empty() &&
135  (FLAGS_aes_signing_key.empty() || FLAGS_aes_signing_iv.empty()) &&
136  FLAGS_rsa_signing_key_path.empty()) {
137  PrintError(
138  "--aes_signing_key/iv or --rsa_signing_key_path is required with "
139  "--signer.");
140  success = false;
141  }
142 
143  if (FLAGS_crypto_period_duration < 0) {
144  PrintError("--crypto_period_duration should not be negative.");
145  success = false;
146  }
147  return success;
148 }
149 
150 } // namespace edash_packager
bool ValidateFlag(const char *flag_name, const std::string &flag_value, bool condition, bool optional, const char *label)
void PrintError(const std::string &error_message)