2022-08-26 15:44:59 +00:00
|
|
|
// Copyright 2014 Google LLC. All rights reserved.
|
2014-05-08 21:02:36 +00:00
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
//
|
|
|
|
// Defines command line flags for widevine_encryption.
|
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/app/widevine_encryption_flags.h"
|
2014-05-08 21:02:36 +00:00
|
|
|
|
2023-09-09 00:44:17 +00:00
|
|
|
#include <absl/flags/flag.h>
|
|
|
|
#include <absl/strings/ascii.h>
|
|
|
|
#include <absl/strings/match.h>
|
|
|
|
#include <absl/strings/str_format.h>
|
|
|
|
#include <glog/logging.h>
|
|
|
|
#include <string_view>
|
2014-10-13 22:06:48 +00:00
|
|
|
#include "packager/app/validate_flag.h"
|
2023-09-09 00:44:17 +00:00
|
|
|
#include "packager/utils/absl_flag_hexbytes.h"
|
2014-05-08 21:02:36 +00:00
|
|
|
|
2023-09-09 00:44:17 +00:00
|
|
|
ABSL_FLAG(bool,
|
|
|
|
enable_widevine_encryption,
|
|
|
|
false,
|
|
|
|
"Enable encryption with Widevine key server. User should provide "
|
|
|
|
"either AES signing key (--aes_signing_key, --aes_signing_iv) or "
|
|
|
|
"RSA signing key (--rsa_signing_key_path).");
|
|
|
|
ABSL_FLAG(bool,
|
|
|
|
enable_widevine_decryption,
|
|
|
|
false,
|
|
|
|
"Enable decryption with Widevine license server/proxy. User should "
|
|
|
|
"provide either AES signing key (--aes_signing_key, "
|
|
|
|
"--aes_signing_iv) or RSA signing key (--rsa_signing_key_path).");
|
|
|
|
ABSL_FLAG(std::string,
|
|
|
|
key_server_url,
|
|
|
|
"",
|
|
|
|
"Key server url. Required for encryption and "
|
|
|
|
"decryption");
|
|
|
|
ABSL_FLAG(shaka::HexBytes, content_id, {}, "Content Id (hex).");
|
|
|
|
ABSL_FLAG(std::string,
|
|
|
|
policy,
|
|
|
|
"",
|
|
|
|
"The name of a stored policy, which specifies DRM content "
|
|
|
|
"rights.");
|
|
|
|
ABSL_FLAG(int32_t,
|
|
|
|
max_sd_pixels,
|
|
|
|
768 * 576,
|
|
|
|
"The video track is considered SD if its max pixels per frame is "
|
|
|
|
"no higher than max_sd_pixels. Default: 442368 (768 x 576).");
|
|
|
|
ABSL_FLAG(int32_t,
|
|
|
|
max_hd_pixels,
|
|
|
|
1920 * 1080,
|
|
|
|
"The video track is considered HD if its max pixels per frame is "
|
|
|
|
"higher than max_sd_pixels, but no higher than max_hd_pixels. "
|
|
|
|
"Default: 2073600 (1920 x 1080).");
|
|
|
|
ABSL_FLAG(int32_t,
|
|
|
|
max_uhd1_pixels,
|
|
|
|
4096 * 2160,
|
|
|
|
"The video track is considered UHD1 if its max pixels per frame "
|
|
|
|
"is higher than max_hd_pixels, but no higher than max_uhd1_pixels."
|
|
|
|
" Otherwise it is UHD2. Default: 8847360 (4096 x 2160).");
|
|
|
|
ABSL_FLAG(std::string, signer, "", "The name of the signer.");
|
|
|
|
ABSL_FLAG(shaka::HexBytes,
|
|
|
|
aes_signing_key,
|
|
|
|
{},
|
|
|
|
"AES signing key in hex string. --aes_signing_iv is required. "
|
|
|
|
"Exclusive with --rsa_signing_key_path.");
|
|
|
|
ABSL_FLAG(shaka::HexBytes, aes_signing_iv, {}, "AES signing iv in hex string.");
|
|
|
|
ABSL_FLAG(std::string,
|
|
|
|
rsa_signing_key_path,
|
|
|
|
"",
|
|
|
|
"Stores PKCS#1 RSA private key for request signing. Exclusive "
|
|
|
|
"with --aes_signing_key.");
|
|
|
|
ABSL_FLAG(int32_t,
|
|
|
|
crypto_period_duration,
|
|
|
|
0,
|
|
|
|
"Crypto period duration in seconds. If it is non-zero, key "
|
|
|
|
"rotation is enabled.");
|
|
|
|
ABSL_FLAG(shaka::HexBytes,
|
|
|
|
group_id,
|
|
|
|
{},
|
|
|
|
"Identifier for a group of licenses (hex).");
|
|
|
|
ABSL_FLAG(bool,
|
|
|
|
enable_entitlement_license,
|
|
|
|
false,
|
|
|
|
"Enable entitlement license when using Widevine key server.");
|
2014-05-08 21:02:36 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2017-06-14 23:18:16 +00:00
|
|
|
namespace {
|
|
|
|
const bool kOptional = true;
|
|
|
|
} // namespace
|
2014-05-08 21:02:36 +00:00
|
|
|
|
2014-10-13 22:06:48 +00:00
|
|
|
bool ValidateWidevineCryptoFlags() {
|
|
|
|
bool success = true;
|
2014-08-20 23:51:15 +00:00
|
|
|
|
2014-10-13 22:06:48 +00:00
|
|
|
const bool widevine_crypto =
|
2023-09-09 00:44:17 +00:00
|
|
|
absl::GetFlag(FLAGS_enable_widevine_encryption) ||
|
|
|
|
absl::GetFlag(FLAGS_enable_widevine_decryption);
|
2014-10-13 22:06:48 +00:00
|
|
|
const char widevine_crypto_label[] =
|
|
|
|
"--enable_widevine_encryption/decryption";
|
|
|
|
// key_server_url and signer (optional) are associated with
|
|
|
|
// enable_widevine_encryption and enable_widevine_descryption.
|
2023-09-09 00:44:17 +00:00
|
|
|
if (!ValidateFlag("key_server_url", absl::GetFlag(FLAGS_key_server_url),
|
|
|
|
widevine_crypto, !kOptional, widevine_crypto_label)) {
|
2014-10-13 22:06:48 +00:00
|
|
|
success = false;
|
|
|
|
}
|
2023-09-09 00:44:17 +00:00
|
|
|
if (!ValidateFlag("signer", absl::GetFlag(FLAGS_signer), widevine_crypto,
|
|
|
|
kOptional, widevine_crypto_label)) {
|
2014-10-13 22:06:48 +00:00
|
|
|
success = false;
|
|
|
|
}
|
2023-09-09 00:44:17 +00:00
|
|
|
if (widevine_crypto && absl::GetFlag(FLAGS_signer).empty() &&
|
|
|
|
absl::StartsWith(
|
|
|
|
absl::AsciiStrToLower(absl::GetFlag(FLAGS_key_server_url)), "http")) {
|
2014-10-13 22:06:48 +00:00
|
|
|
LOG(WARNING) << "--signer is likely required with "
|
|
|
|
"--enable_widevine_encryption/decryption.";
|
2014-08-20 23:51:15 +00:00
|
|
|
}
|
2014-05-08 21:02:36 +00:00
|
|
|
|
2014-10-13 22:06:48 +00:00
|
|
|
const char widevine_encryption_label[] = "--enable_widevine_encryption";
|
|
|
|
// content_id and policy (optional) are associated with
|
|
|
|
// enable_widevine_encryption.
|
2023-09-09 00:44:17 +00:00
|
|
|
if (!ValidateFlag("content_id", absl::GetFlag(FLAGS_content_id).bytes,
|
|
|
|
absl::GetFlag(FLAGS_enable_widevine_encryption), !kOptional,
|
2014-10-13 22:06:48 +00:00
|
|
|
widevine_encryption_label)) {
|
|
|
|
success = false;
|
|
|
|
}
|
2023-09-09 00:44:17 +00:00
|
|
|
if (!ValidateFlag("policy", absl::GetFlag(FLAGS_policy),
|
|
|
|
absl::GetFlag(FLAGS_enable_widevine_encryption), kOptional,
|
2014-10-13 22:06:48 +00:00
|
|
|
widevine_encryption_label)) {
|
|
|
|
success = false;
|
|
|
|
}
|
2014-05-08 21:02:36 +00:00
|
|
|
|
2023-09-09 00:44:17 +00:00
|
|
|
if (absl::GetFlag(FLAGS_max_sd_pixels) <= 0) {
|
2014-10-13 22:06:48 +00:00
|
|
|
PrintError("--max_sd_pixels must be positive.");
|
|
|
|
success = false;
|
|
|
|
}
|
2023-09-09 00:44:17 +00:00
|
|
|
if (absl::GetFlag(FLAGS_max_hd_pixels) <= 0) {
|
2016-11-11 23:17:17 +00:00
|
|
|
PrintError("--max_hd_pixels must be positive.");
|
|
|
|
success = false;
|
|
|
|
}
|
2023-09-09 00:44:17 +00:00
|
|
|
if (absl::GetFlag(FLAGS_max_uhd1_pixels) <= 0) {
|
2016-11-11 23:17:17 +00:00
|
|
|
PrintError("--max_uhd1_pixels must be positive.");
|
|
|
|
success = false;
|
|
|
|
}
|
2023-09-09 00:44:17 +00:00
|
|
|
if (absl::GetFlag(FLAGS_max_hd_pixels) <=
|
|
|
|
absl::GetFlag(FLAGS_max_sd_pixels)) {
|
2016-11-11 23:17:17 +00:00
|
|
|
PrintError("--max_hd_pixels must be greater than --max_sd_pixels.");
|
|
|
|
success = false;
|
|
|
|
}
|
2023-09-09 00:44:17 +00:00
|
|
|
if (absl::GetFlag(FLAGS_max_uhd1_pixels) <=
|
|
|
|
absl::GetFlag(FLAGS_max_hd_pixels)) {
|
2016-11-11 23:17:17 +00:00
|
|
|
PrintError("--max_uhd1_pixels must be greater than --max_hd_pixels.");
|
|
|
|
success = false;
|
|
|
|
}
|
2014-10-13 22:06:48 +00:00
|
|
|
|
2023-09-09 00:44:17 +00:00
|
|
|
const bool aes = !absl::GetFlag(FLAGS_aes_signing_key).bytes.empty() ||
|
|
|
|
!absl::GetFlag(FLAGS_aes_signing_iv).bytes.empty();
|
|
|
|
if (aes && (absl::GetFlag(FLAGS_aes_signing_key).bytes.empty() ||
|
|
|
|
absl::GetFlag(FLAGS_aes_signing_iv).bytes.empty())) {
|
2017-06-14 23:18:16 +00:00
|
|
|
PrintError("--aes_signing_key/iv is required if using aes signing.");
|
2014-10-13 22:06:48 +00:00
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
2023-09-09 00:44:17 +00:00
|
|
|
const bool rsa = !absl::GetFlag(FLAGS_rsa_signing_key_path).empty();
|
2017-06-14 23:18:16 +00:00
|
|
|
|
2023-09-09 00:44:17 +00:00
|
|
|
if (absl::GetFlag(FLAGS_signer).empty() && (aes || rsa)) {
|
2017-06-14 23:18:16 +00:00
|
|
|
PrintError("--signer is required if using aes/rsa signing.");
|
2014-10-13 22:06:48 +00:00
|
|
|
success = false;
|
2014-05-08 21:02:36 +00:00
|
|
|
}
|
2023-09-09 00:44:17 +00:00
|
|
|
if (!absl::GetFlag(FLAGS_signer).empty() && !aes && !rsa) {
|
2014-10-13 22:06:48 +00:00
|
|
|
PrintError(
|
|
|
|
"--aes_signing_key/iv or --rsa_signing_key_path is required with "
|
|
|
|
"--signer.");
|
|
|
|
success = false;
|
|
|
|
}
|
2017-06-14 23:18:16 +00:00
|
|
|
if (aes && rsa) {
|
|
|
|
PrintError(
|
|
|
|
"Only one of --aes_signing_key/iv and --rsa_signing_key_path should be "
|
|
|
|
"specified.");
|
|
|
|
success = false;
|
|
|
|
}
|
2014-10-13 22:06:48 +00:00
|
|
|
|
2023-09-09 00:44:17 +00:00
|
|
|
if (absl::GetFlag(FLAGS_crypto_period_duration) < 0) {
|
2014-10-13 22:06:48 +00:00
|
|
|
PrintError("--crypto_period_duration should not be negative.");
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
return success;
|
|
|
|
}
|
2014-05-08 21:02:36 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|