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