9 #include "packager/app/widevine_encryption_flags.h"
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"
16 DEFINE_bool(enable_widevine_encryption,
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,
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,
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 "
33 DEFINE_hex_bytes(content_id,
"",
"Content Id (hex).");
36 "The name of a stored policy, which specifies DRM content "
38 DEFINE_int32(max_sd_pixels,
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,
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,
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_hex_bytes(aes_signing_key,
55 "AES signing key in hex string. --aes_signing_iv is required. "
56 "Exclusive with --rsa_signing_key_path.");
57 DEFINE_hex_bytes(aes_signing_iv,
"",
"AES signing iv in hex string.");
58 DEFINE_string(rsa_signing_key_path,
60 "Stores PKCS#1 RSA private key for request signing. Exclusive "
61 "with --aes_signing_key.");
62 DEFINE_int32(crypto_period_duration,
64 "Crypto period duration in seconds. If it is non-zero, key "
65 "rotation is enabled.");
69 const bool kOptional =
true;
75 const bool widevine_crypto =
76 FLAGS_enable_widevine_encryption || FLAGS_enable_widevine_decryption;
77 const char widevine_crypto_label[] =
78 "--enable_widevine_encryption/decryption";
85 widevine_crypto_label)) {
92 widevine_crypto_label)) {
95 if (widevine_crypto && FLAGS_signer.empty() &&
96 base::StartsWith(base::StringPiece(FLAGS_key_server_url),
"http",
97 base::CompareCase::INSENSITIVE_ASCII)) {
98 LOG(WARNING) <<
"--signer is likely required with "
99 "--enable_widevine_encryption/decryption.";
102 const char widevine_encryption_label[] =
"--enable_widevine_encryption";
106 FLAGS_content_id_bytes,
107 FLAGS_enable_widevine_encryption,
109 widevine_encryption_label)) {
114 FLAGS_enable_widevine_encryption,
116 widevine_encryption_label)) {
119 if (FLAGS_include_common_pssh && !FLAGS_enable_widevine_encryption) {
120 PrintError(
"--include_common_pssh is only valid with "
121 "--enable_widevine_encryption");
125 if (FLAGS_max_sd_pixels <= 0) {
126 PrintError(
"--max_sd_pixels must be positive.");
129 if (FLAGS_max_hd_pixels <= 0) {
130 PrintError(
"--max_hd_pixels must be positive.");
133 if (FLAGS_max_uhd1_pixels <= 0) {
134 PrintError(
"--max_uhd1_pixels must be positive.");
137 if (FLAGS_max_hd_pixels <= FLAGS_max_sd_pixels) {
138 PrintError(
"--max_hd_pixels must be greater than --max_sd_pixels.");
141 if (FLAGS_max_uhd1_pixels <= FLAGS_max_hd_pixels) {
142 PrintError(
"--max_uhd1_pixels must be greater than --max_hd_pixels.");
146 const bool aes = !FLAGS_aes_signing_key_bytes.empty() ||
147 !FLAGS_aes_signing_iv_bytes.empty();
148 if (aes && (FLAGS_aes_signing_key_bytes.empty() ||
149 FLAGS_aes_signing_iv_bytes.empty())) {
150 PrintError(
"--aes_signing_key/iv is required if using aes signing.");
154 const bool rsa = !FLAGS_rsa_signing_key_path.empty();
156 if (FLAGS_signer.empty() && (aes || rsa)) {
157 PrintError(
"--signer is required if using aes/rsa signing.");
160 if (!FLAGS_signer.empty() && !aes && !rsa) {
162 "--aes_signing_key/iv or --rsa_signing_key_path is required with "
168 "Only one of --aes_signing_key/iv and --rsa_signing_key_path should be "
173 if (FLAGS_crypto_period_duration < 0) {
174 PrintError(
"--crypto_period_duration should not be negative.");
void PrintError(const std::string &error_message)
bool ValidateFlag(const char *flag_name, const FlagType &flag_value, bool condition, bool optional, const char *label)
bool ValidateWidevineCryptoFlags()