2014-05-08 21:02:36 +00:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
2014-10-13 22:06:48 +00:00
|
|
|
// Defines command line flags for fixed key encryption/decryption.
|
2014-05-08 21:02:36 +00:00
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/app/fixed_key_encryption_flags.h"
|
2014-05-08 21:02:36 +00:00
|
|
|
|
2014-10-13 22:06:48 +00:00
|
|
|
#include "packager/app/validate_flag.h"
|
|
|
|
|
2014-05-08 21:02:36 +00:00
|
|
|
DEFINE_bool(enable_fixed_key_encryption,
|
|
|
|
false,
|
|
|
|
"Enable encryption with fixed key.");
|
2014-08-25 22:51:19 +00:00
|
|
|
DEFINE_bool(enable_fixed_key_decryption,
|
|
|
|
false,
|
|
|
|
"Enable decryption with fixed key.");
|
2014-05-08 21:02:36 +00:00
|
|
|
DEFINE_string(key_id, "", "Key id in hex string format.");
|
|
|
|
DEFINE_string(key, "", "Key in hex string format.");
|
2015-09-25 22:48:18 +00:00
|
|
|
DEFINE_string(iv,
|
|
|
|
"",
|
|
|
|
"Iv in hex string format. If not specified, a random iv will be "
|
|
|
|
"generated. This flag should only be used for testing.");
|
2016-02-19 20:23:37 +00:00
|
|
|
DEFINE_string(pssh,
|
|
|
|
"",
|
|
|
|
"One or more PSSH boxes in hex string format. If not specified, "
|
2017-05-22 20:28:10 +00:00
|
|
|
"will generate a v1 common PSSH box as specified in "
|
|
|
|
"https://goo.gl/s8RIhr.");
|
2014-05-08 21:02:36 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2014-10-13 22:06:48 +00:00
|
|
|
|
|
|
|
bool ValidateFixedCryptoFlags() {
|
|
|
|
bool success = true;
|
|
|
|
|
|
|
|
const bool fixed_crypto =
|
|
|
|
FLAGS_enable_fixed_key_encryption || FLAGS_enable_fixed_key_decryption;
|
|
|
|
const char fixed_crypto_label[] = "--enable_fixed_key_encryption/decryption";
|
|
|
|
// --key_id and --key are associated with --enable_fixed_key_encryption and
|
|
|
|
// --enable_fixed_key_decryption.
|
|
|
|
if (!ValidateFlag(
|
|
|
|
"key_id", FLAGS_key_id, fixed_crypto, false, fixed_crypto_label)) {
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
if (!ValidateFlag(
|
|
|
|
"key", FLAGS_key, fixed_crypto, false, fixed_crypto_label)) {
|
|
|
|
success = false;
|
|
|
|
}
|
2015-09-25 22:48:18 +00:00
|
|
|
if (!ValidateFlag("iv", FLAGS_iv, FLAGS_enable_fixed_key_encryption, true,
|
|
|
|
"--enable_fixed_key_encryption")) {
|
|
|
|
success = false;
|
|
|
|
}
|
2016-04-13 17:52:41 +00:00
|
|
|
if (!FLAGS_iv.empty()) {
|
|
|
|
if (FLAGS_iv.size() != 8 * 2 && FLAGS_iv.size() != 16 * 2) {
|
|
|
|
PrintError(
|
|
|
|
"--iv should be either 8 bytes (16 hex digits) or 16 bytes (32 hex "
|
|
|
|
"digits).");
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
}
|
2014-10-13 22:06:48 +00:00
|
|
|
|
|
|
|
// --pssh is associated with --enable_fix_key_encryption.
|
|
|
|
if (!ValidateFlag("pssh",
|
|
|
|
FLAGS_pssh,
|
|
|
|
FLAGS_enable_fixed_key_encryption,
|
2016-02-19 20:23:37 +00:00
|
|
|
true,
|
2014-10-13 22:06:48 +00:00
|
|
|
"--enable_fixed_key_encryption")) {
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
return success;
|
2014-05-08 21:02:36 +00:00
|
|
|
}
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|