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  StartsWithASCII(FLAGS_key_server_url, "http", false)) {
80  LOG(WARNING) << "--signer is likely required with "
81  "--enable_widevine_encryption/decryption.";
82  }
83 
84  const char widevine_encryption_label[] = "--enable_widevine_encryption";
85  // content_id and policy (optional) are associated with
86  // enable_widevine_encryption.
87  if (!ValidateFlag("content_id",
88  FLAGS_content_id,
89  FLAGS_enable_widevine_encryption,
90  false,
91  widevine_encryption_label)) {
92  success = false;
93  }
94  if (!ValidateFlag("policy",
95  FLAGS_policy,
96  FLAGS_enable_widevine_encryption,
97  true,
98  widevine_encryption_label)) {
99  success = false;
100  }
101 
102  if (FLAGS_max_sd_pixels <= 0) {
103  PrintError("--max_sd_pixels must be positive.");
104  success = false;
105  }
106 
107  const bool aes = !FLAGS_signer.empty() && FLAGS_rsa_signing_key_path.empty();
108  const char aes_label[] =
109  "--signer is specified and exclusive with --rsa_signing_key_path";
110  // aes_signer_key and aes_signing_iv are associated with aes signing.
111  if (!ValidateFlag(
112  "aes_signing_key", FLAGS_aes_signing_key, aes, true, aes_label)) {
113  success = false;
114  }
115  if (!ValidateFlag(
116  "aes_signing_iv", FLAGS_aes_signing_iv, aes, true, aes_label)) {
117  success = false;
118  }
119 
120  const bool rsa = !FLAGS_signer.empty() && FLAGS_aes_signing_key.empty() &&
121  FLAGS_aes_signing_iv.empty();
122  const char rsa_label[] =
123  "--signer is specified and exclusive with --aes_signing_key/iv";
124  // rsa_signing_key_path is associated with rsa_signing.
125  if (!ValidateFlag("rsa_signing_key_path",
126  FLAGS_rsa_signing_key_path,
127  rsa,
128  true,
129  rsa_label)) {
130  success = false;
131  }
132 
133  if (!FLAGS_signer.empty() &&
134  (FLAGS_aes_signing_key.empty() || FLAGS_aes_signing_iv.empty()) &&
135  FLAGS_rsa_signing_key_path.empty()) {
136  PrintError(
137  "--aes_signing_key/iv or --rsa_signing_key_path is required with "
138  "--signer.");
139  success = false;
140  }
141 
142  if (FLAGS_crypto_period_duration < 0) {
143  PrintError("--crypto_period_duration should not be negative.");
144  success = false;
145  }
146  return success;
147 }
148 
149 } // 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)