9 #include <packager/app/widevine_encryption_flags.h>
11 #include <string_view>
13 #include <absl/flags/flag.h>
14 #include <absl/log/log.h>
15 #include <absl/strings/ascii.h>
16 #include <absl/strings/match.h>
18 #include <packager/app/validate_flag.h>
21 enable_widevine_encryption,
23 "Enable encryption with Widevine key server. User should provide "
24 "either AES signing key (--aes_signing_key, --aes_signing_iv) or "
25 "RSA signing key (--rsa_signing_key_path).");
27 enable_widevine_decryption,
29 "Enable decryption with Widevine license server/proxy. User should "
30 "provide either AES signing key (--aes_signing_key, "
31 "--aes_signing_iv) or RSA signing key (--rsa_signing_key_path).");
32 ABSL_FLAG(std::string,
35 "Key server url. Required for encryption and "
38 ABSL_FLAG(std::string,
41 "The name of a stored policy, which specifies DRM content "
46 "The video track is considered SD if its max pixels per frame is "
47 "no higher than max_sd_pixels. Default: 442368 (768 x 576).");
51 "The video track is considered HD if its max pixels per frame is "
52 "higher than max_sd_pixels, but no higher than max_hd_pixels. "
53 "Default: 2073600 (1920 x 1080).");
57 "The video track is considered UHD1 if its max pixels per frame "
58 "is higher than max_hd_pixels, but no higher than max_uhd1_pixels."
59 " Otherwise it is UHD2. Default: 8847360 (4096 x 2160).");
60 ABSL_FLAG(std::string, signer,
"",
"The name of the signer.");
64 "AES signing key in hex string. --aes_signing_iv is required. "
65 "Exclusive with --rsa_signing_key_path.");
66 ABSL_FLAG(
shaka::HexBytes, aes_signing_iv, {},
"AES signing iv in hex string.");
67 ABSL_FLAG(std::string,
70 "Stores PKCS#1 RSA private key for request signing. Exclusive "
71 "with --aes_signing_key.");
73 crypto_period_duration,
75 "Crypto period duration in seconds. If it is non-zero, key "
76 "rotation is enabled.");
80 "Identifier for a group of licenses (hex).");
82 enable_entitlement_license,
84 "Enable entitlement license when using Widevine key server.");
88 const bool kOptional =
true;
94 const bool widevine_crypto =
95 absl::GetFlag(FLAGS_enable_widevine_encryption) ||
96 absl::GetFlag(FLAGS_enable_widevine_decryption);
97 const char widevine_crypto_label[] =
98 "--enable_widevine_encryption/decryption";
101 if (!
ValidateFlag(
"key_server_url", absl::GetFlag(FLAGS_key_server_url),
102 widevine_crypto, !kOptional, widevine_crypto_label)) {
105 if (!
ValidateFlag(
"signer", absl::GetFlag(FLAGS_signer), widevine_crypto,
106 kOptional, widevine_crypto_label)) {
109 if (widevine_crypto && absl::GetFlag(FLAGS_signer).empty() &&
111 absl::AsciiStrToLower(absl::GetFlag(FLAGS_key_server_url)),
"http")) {
112 LOG(WARNING) <<
"--signer is likely required with "
113 "--enable_widevine_encryption/decryption.";
116 const char widevine_encryption_label[] =
"--enable_widevine_encryption";
119 if (!
ValidateFlag(
"content_id", absl::GetFlag(FLAGS_content_id).bytes,
120 absl::GetFlag(FLAGS_enable_widevine_encryption), !kOptional,
121 widevine_encryption_label)) {
124 if (!
ValidateFlag(
"policy", absl::GetFlag(FLAGS_policy),
125 absl::GetFlag(FLAGS_enable_widevine_encryption), kOptional,
126 widevine_encryption_label)) {
130 if (absl::GetFlag(FLAGS_max_sd_pixels) <= 0) {
131 PrintError(
"--max_sd_pixels must be positive.");
134 if (absl::GetFlag(FLAGS_max_hd_pixels) <= 0) {
135 PrintError(
"--max_hd_pixels must be positive.");
138 if (absl::GetFlag(FLAGS_max_uhd1_pixels) <= 0) {
139 PrintError(
"--max_uhd1_pixels must be positive.");
142 if (absl::GetFlag(FLAGS_max_hd_pixels) <=
143 absl::GetFlag(FLAGS_max_sd_pixels)) {
144 PrintError(
"--max_hd_pixels must be greater than --max_sd_pixels.");
147 if (absl::GetFlag(FLAGS_max_uhd1_pixels) <=
148 absl::GetFlag(FLAGS_max_hd_pixels)) {
149 PrintError(
"--max_uhd1_pixels must be greater than --max_hd_pixels.");
153 const bool aes = !absl::GetFlag(FLAGS_aes_signing_key).bytes.empty() ||
154 !absl::GetFlag(FLAGS_aes_signing_iv).bytes.empty();
155 if (aes && (absl::GetFlag(FLAGS_aes_signing_key).bytes.empty() ||
156 absl::GetFlag(FLAGS_aes_signing_iv).bytes.empty())) {
157 PrintError(
"--aes_signing_key/iv is required if using aes signing.");
161 const bool rsa = !absl::GetFlag(FLAGS_rsa_signing_key_path).empty();
163 if (absl::GetFlag(FLAGS_signer).empty() && (aes || rsa)) {
164 PrintError(
"--signer is required if using aes/rsa signing.");
167 if (!absl::GetFlag(FLAGS_signer).empty() && !aes && !rsa) {
169 "--aes_signing_key/iv or --rsa_signing_key_path is required with "
175 "Only one of --aes_signing_key/iv and --rsa_signing_key_path should be "
180 if (absl::GetFlag(FLAGS_crypto_period_duration) < 0) {
181 PrintError(
"--crypto_period_duration should not be negative.");
All the methods that are virtual are virtual for mocking.
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()