(1) Move the CryptoMode enum definition to media_cas_packager_sdk partners can use it when calling libraries in the SDK.
(2) Add a new enum value for kDvbCsa. (3) Allow caller to specify CTR, CBC, as well as CSA when using the ecm genertor from the SDK. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=219707788
This commit is contained in:
@@ -32,6 +32,7 @@ cc_library(
|
||||
"//common:aes_cbc_util",
|
||||
"//common:random_util",
|
||||
"//common:string_util",
|
||||
"//media_cas_packager_sdk/public:wv_cas_types",
|
||||
"//protos/public:media_cas_encryption_proto",
|
||||
"//protos/public:media_cas_proto",
|
||||
],
|
||||
@@ -45,6 +46,7 @@ cc_test(
|
||||
":ecm",
|
||||
"//testing:gunit_main",
|
||||
"//util:status",
|
||||
"//media_cas_packager_sdk/public:wv_cas_types",
|
||||
"//protos/public:media_cas_encryption_proto",
|
||||
],
|
||||
)
|
||||
@@ -91,6 +93,7 @@ cc_library(
|
||||
"@abseil_repo//absl/strings",
|
||||
"//util:status",
|
||||
"//example:constants",
|
||||
"//media_cas_packager_sdk/public:wv_cas_types",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "common/aes_cbc_util.h"
|
||||
#include "common/random_util.h"
|
||||
#include "common/string_util.h"
|
||||
#include "protos/public/media_cas.pb.h"
|
||||
#include "protos/public/media_cas_encryption.pb.h"
|
||||
|
||||
namespace widevine {
|
||||
@@ -40,7 +39,7 @@ static constexpr int kNumBitsEcmVersionField = 8;
|
||||
|
||||
// Byte 3
|
||||
static constexpr int kNumBitsEcmGenerationCountField = 5;
|
||||
// Values for Decrypt Mode are from enum CasCryptoMode
|
||||
// Values for Decrypt Mode are from enum CryptoMode
|
||||
static constexpr int kNumBitsDecryptModeField = 2;
|
||||
static constexpr int kNumBitsRotationEnabledField = 1;
|
||||
|
||||
@@ -140,10 +139,8 @@ util::Status CasEcm::Initialize(const std::string& content_id,
|
||||
"Parameter content_iv_size must be kIvSize8 or kIvSize16."};
|
||||
}
|
||||
|
||||
if (ecm_init_parameters.crypto_mode != CasCryptoMode::CTR &&
|
||||
ecm_init_parameters.crypto_mode != CasCryptoMode::CBC) {
|
||||
return {util::error::INVALID_ARGUMENT,
|
||||
"Crypto mode setting is out of range."};
|
||||
if (ecm_init_parameters.crypto_mode == CryptoMode::kCryptoModeUnspecified) {
|
||||
return {util::error::INVALID_ARGUMENT, "Invalid crypto mode."};
|
||||
} else {
|
||||
crypto_mode_ = ecm_init_parameters.crypto_mode;
|
||||
}
|
||||
@@ -391,7 +388,8 @@ std::string CasEcm::SerializeEcm(const std::vector<EntitledKeyInfo*>& keys) {
|
||||
std::bitset<kNumBitsEcmVersionField> ecm_version(kEcmVersion);
|
||||
std::bitset<kNumBitsEcmGenerationCountField> ecm_generation_count(
|
||||
generation());
|
||||
std::bitset<kNumBitsDecryptModeField> decrypt_mode(crypto_mode());
|
||||
std::bitset<kNumBitsDecryptModeField> decrypt_mode(
|
||||
static_cast<int>(crypto_mode()));
|
||||
std::bitset<kNumBitsRotationEnabledField> rotation_enabled(
|
||||
RotationFieldValue(paired_keys_required()));
|
||||
std::bitset<kNumBitsWrappedKeyIvSizeField> wrapped_key_iv_size(
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "util/status.h"
|
||||
#include "media_cas_packager_sdk/public/wv_cas_types.h"
|
||||
#include "protos/public/media_cas.pb.h"
|
||||
|
||||
namespace widevine {
|
||||
@@ -49,13 +50,13 @@ enum EcmIvSize { kIvSize8 = 0, kIvSize16 = 1 };
|
||||
// A constant of type CasEcmSize specifying 8 or 16.
|
||||
// |key_rotation_enabled| the encryption uses multiple keys in rotation.
|
||||
// |crypto_mode| the encryption mode used for the content stream.
|
||||
// A constant of type CasCryptoMode.
|
||||
// A constant of type CryptoMode.
|
||||
// |track_types| a vector of track ID (std::string) that specify the set of track
|
||||
// types of interest; controls the entitlement keys returned by the server.
|
||||
struct EcmInitParameters {
|
||||
EcmIvSize content_iv_size = kIvSize8;
|
||||
bool key_rotation_enabled = true;
|
||||
CasCryptoMode crypto_mode = CasCryptoMode::CTR;
|
||||
CryptoMode crypto_mode = CryptoMode::kAesCtr;
|
||||
std::vector<std::string> track_types;
|
||||
};
|
||||
|
||||
@@ -216,7 +217,7 @@ class CasEcm {
|
||||
virtual util::Status ParseEntitlementResponse(const std::string& response_string);
|
||||
|
||||
virtual uint32_t generation() const { return generation_; }
|
||||
virtual CasCryptoMode crypto_mode() const { return crypto_mode_; }
|
||||
virtual CryptoMode crypto_mode() const { return crypto_mode_; }
|
||||
virtual bool paired_keys_required() const { return paired_keys_required_; }
|
||||
virtual size_t content_iv_size() const { return content_iv_size_; }
|
||||
|
||||
@@ -235,7 +236,7 @@ class CasEcm {
|
||||
std::vector<std::string> track_types_;
|
||||
// Remember if a pair of keys is required (for key rotation).
|
||||
bool paired_keys_required_ = false;
|
||||
CasCryptoMode crypto_mode_ = CasCryptoMode::CTR;
|
||||
CryptoMode crypto_mode_ = CryptoMode::kAesCtr;
|
||||
// Entitlement keys needed for ECM generation.
|
||||
// The keys are added when the CasEncryptionResponse is processed.
|
||||
std::map<std::string, std::list<EntitlementKeyInfo>> entitlement_keys_;
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "testing/gmock.h"
|
||||
#include "testing/gunit.h"
|
||||
#include "util/status.h"
|
||||
#include "media_cas_packager_sdk/public/wv_cas_types.h"
|
||||
#include "protos/public/media_cas_encryption.pb.h"
|
||||
|
||||
using ::testing::Return;
|
||||
@@ -59,7 +60,7 @@ class MockCasEcm : public CasEcm {
|
||||
~MockCasEcm() override = default;
|
||||
|
||||
MOCK_CONST_METHOD0(generation, uint32_t());
|
||||
MOCK_CONST_METHOD0(crypto_mode, CasCryptoMode());
|
||||
MOCK_CONST_METHOD0(crypto_mode, CryptoMode());
|
||||
MOCK_CONST_METHOD0(paired_keys_required, bool());
|
||||
MOCK_CONST_METHOD0(content_iv_size, size_t());
|
||||
|
||||
@@ -78,7 +79,7 @@ class MockCasEcm : public CasEcm {
|
||||
}
|
||||
|
||||
void MockSetup(bool two_keys, const std::string& track_type, uint32_t generation,
|
||||
CasCryptoMode crypto_mode, size_t civ_size) {
|
||||
CryptoMode crypto_mode, size_t civ_size) {
|
||||
EXPECT_CALL(*this, generation()).WillRepeatedly(Return(generation));
|
||||
EXPECT_CALL(*this, crypto_mode()).WillRepeatedly(Return(crypto_mode));
|
||||
EXPECT_CALL(*this, paired_keys_required()).WillRepeatedly(Return(two_keys));
|
||||
@@ -187,7 +188,7 @@ class CasEcmTest : public testing::Test {
|
||||
class CasEcmSerializeEcmTest : public CasEcmTest {
|
||||
public:
|
||||
void ValidateEcmHeaderFields(const std::string& ecm_string, bool rotation_enabled,
|
||||
int gen, CasCryptoMode crypto_mode,
|
||||
int gen, CryptoMode crypto_mode,
|
||||
EcmIvSize content_iv) {
|
||||
EXPECT_THAT('\x4A', ecm_string[0]);
|
||||
EXPECT_THAT('\xD4', ecm_string[1]);
|
||||
@@ -201,8 +202,7 @@ class CasEcmSerializeEcmTest : public CasEcmTest {
|
||||
}
|
||||
|
||||
void ValidateEcmFieldsOneKey(const std::string& buf_string, int gen,
|
||||
CasCryptoMode crypto_mode,
|
||||
EcmIvSize content_iv) {
|
||||
CryptoMode crypto_mode, EcmIvSize content_iv) {
|
||||
size_t expected_size = kEcmHeaderSize + kEcmKeyInfoSize + kEcmIvSize16 +
|
||||
IvExpectedSize(content_iv);
|
||||
size_t ecm_len = buf_string.size();
|
||||
@@ -211,8 +211,7 @@ class CasEcmSerializeEcmTest : public CasEcmTest {
|
||||
}
|
||||
|
||||
void ValidateEcmFieldsTwoKeys(const std::string& buf_string, int gen,
|
||||
CasCryptoMode crypto_mode,
|
||||
EcmIvSize content_iv) {
|
||||
CryptoMode crypto_mode, EcmIvSize content_iv) {
|
||||
size_t expected_size =
|
||||
kEcmHeaderSize +
|
||||
(2 * (kEcmKeyInfoSize + kEcmIvSize16 + IvExpectedSize(content_iv)));
|
||||
@@ -559,7 +558,7 @@ TEST_F(CasEcmSerializeEcmTest, SerializeEcmDoubleKey16ByteIvs) {
|
||||
EntitledKeyInfo key1 = valid3_iv_16_16_;
|
||||
EntitledKeyInfo key2 = valid4_iv_16_16_;
|
||||
|
||||
ecm_gen.MockSetup(true, kTrackTypeSD, 0, CasCryptoMode::CTR, 16);
|
||||
ecm_gen.MockSetup(true, kTrackTypeSD, 0, CryptoMode::kAesCtr, 16);
|
||||
|
||||
std::vector<EntitledKeyInfo*> keys;
|
||||
keys.push_back(&key1);
|
||||
@@ -568,20 +567,20 @@ TEST_F(CasEcmSerializeEcmTest, SerializeEcmDoubleKey16ByteIvs) {
|
||||
|
||||
std::string buf_string = ecm_gen.CallSerializeEcm(keys);
|
||||
|
||||
ValidateEcmFieldsTwoKeys(buf_string, 0, CasCryptoMode::CTR, kIvSize16);
|
||||
ValidateEcmFieldsTwoKeys(buf_string, 0, CryptoMode::kAesCtr, kIvSize16);
|
||||
|
||||
EXPECT_CALL(ecm_gen, generation()).WillRepeatedly(Return(1));
|
||||
|
||||
buf_string = ecm_gen.CallSerializeEcm(keys);
|
||||
|
||||
ValidateEcmFieldsTwoKeys(buf_string, 1, CasCryptoMode::CTR, kIvSize16);
|
||||
ValidateEcmFieldsTwoKeys(buf_string, 1, CryptoMode::kAesCtr, kIvSize16);
|
||||
}
|
||||
|
||||
TEST_F(CasEcmSerializeEcmTest, SerializeEcmSingleKey16ByteIvs) {
|
||||
MockCasEcm ecm_gen;
|
||||
EntitledKeyInfo key1 = valid3_iv_16_16_;
|
||||
|
||||
ecm_gen.MockSetup(false, kTrackTypeSD, 0, CasCryptoMode::CTR, 16);
|
||||
ecm_gen.MockSetup(false, kTrackTypeSD, 0, CryptoMode::kAesCtr, 16);
|
||||
|
||||
std::vector<EntitledKeyInfo*> keys;
|
||||
keys.push_back(&key1);
|
||||
@@ -589,13 +588,13 @@ TEST_F(CasEcmSerializeEcmTest, SerializeEcmSingleKey16ByteIvs) {
|
||||
|
||||
std::string buf_string = ecm_gen.CallSerializeEcm(keys);
|
||||
|
||||
ValidateEcmFieldsOneKey(buf_string, 0, CasCryptoMode::CTR, kIvSize16);
|
||||
ValidateEcmFieldsOneKey(buf_string, 0, CryptoMode::kAesCtr, kIvSize16);
|
||||
|
||||
EXPECT_CALL(ecm_gen, generation()).WillRepeatedly(Return(1));
|
||||
|
||||
buf_string = ecm_gen.CallSerializeEcm(keys);
|
||||
|
||||
ValidateEcmFieldsOneKey(buf_string, 1, CasCryptoMode::CTR, kIvSize16);
|
||||
ValidateEcmFieldsOneKey(buf_string, 1, CryptoMode::kAesCtr, kIvSize16);
|
||||
}
|
||||
|
||||
TEST_F(CasEcmSerializeEcmTest, SerializeEcmDoubleKey16x8ByteIvs) {
|
||||
@@ -603,7 +602,7 @@ TEST_F(CasEcmSerializeEcmTest, SerializeEcmDoubleKey16x8ByteIvs) {
|
||||
EntitledKeyInfo key1 = valid1_iv_16_8_;
|
||||
EntitledKeyInfo key2 = valid2_iv_16_8_;
|
||||
|
||||
ecm_gen.MockSetup(true, kTrackTypeSD, 0, CasCryptoMode::CTR, 8);
|
||||
ecm_gen.MockSetup(true, kTrackTypeSD, 0, CryptoMode::kAesCtr, 8);
|
||||
|
||||
std::vector<EntitledKeyInfo*> keys;
|
||||
keys.push_back(&key1);
|
||||
@@ -612,20 +611,20 @@ TEST_F(CasEcmSerializeEcmTest, SerializeEcmDoubleKey16x8ByteIvs) {
|
||||
|
||||
std::string buf_string = ecm_gen.CallSerializeEcm(keys);
|
||||
|
||||
ValidateEcmFieldsTwoKeys(buf_string, 0, CasCryptoMode::CTR, kIvSize8);
|
||||
ValidateEcmFieldsTwoKeys(buf_string, 0, CryptoMode::kAesCtr, kIvSize8);
|
||||
|
||||
EXPECT_CALL(ecm_gen, generation()).WillRepeatedly(Return(1));
|
||||
|
||||
buf_string = ecm_gen.CallSerializeEcm(keys);
|
||||
|
||||
ValidateEcmFieldsTwoKeys(buf_string, 1, CasCryptoMode::CTR, kIvSize8);
|
||||
ValidateEcmFieldsTwoKeys(buf_string, 1, CryptoMode::kAesCtr, kIvSize8);
|
||||
}
|
||||
|
||||
TEST_F(CasEcmSerializeEcmTest, SerializeEcmSingleKey16x8ByteIvs) {
|
||||
MockCasEcm ecm_gen;
|
||||
EntitledKeyInfo key1 = valid1_iv_16_8_;
|
||||
|
||||
ecm_gen.MockSetup(false, kTrackTypeSD, 0, CasCryptoMode::CTR, 8);
|
||||
ecm_gen.MockSetup(false, kTrackTypeSD, 0, CryptoMode::kAesCtr, 8);
|
||||
|
||||
std::vector<EntitledKeyInfo*> keys;
|
||||
keys.push_back(&key1);
|
||||
@@ -633,13 +632,13 @@ TEST_F(CasEcmSerializeEcmTest, SerializeEcmSingleKey16x8ByteIvs) {
|
||||
|
||||
std::string buf_string = ecm_gen.CallSerializeEcm(keys);
|
||||
|
||||
ValidateEcmFieldsOneKey(buf_string, 0, CasCryptoMode::CTR, kIvSize8);
|
||||
ValidateEcmFieldsOneKey(buf_string, 0, CryptoMode::kAesCtr, kIvSize8);
|
||||
|
||||
EXPECT_CALL(ecm_gen, generation()).WillRepeatedly(Return(1));
|
||||
|
||||
buf_string = ecm_gen.CallSerializeEcm(keys);
|
||||
|
||||
ValidateEcmFieldsOneKey(buf_string, 1, CasCryptoMode::CTR, kIvSize8);
|
||||
ValidateEcmFieldsOneKey(buf_string, 1, CryptoMode::kAesCtr, kIvSize8);
|
||||
}
|
||||
|
||||
} // namespace cas
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "glog/logging.h"
|
||||
#include "absl/memory/memory.h"
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "media_cas_packager_sdk/internal/ecm_generator.h"
|
||||
#include "media_cas_packager_sdk/internal/ecmg_constants.h"
|
||||
#include "media_cas_packager_sdk/internal/util.h"
|
||||
#include "media_cas_packager_sdk/public/wv_cas_types.h"
|
||||
|
||||
namespace widevine {
|
||||
namespace cas {
|
||||
@@ -225,8 +226,8 @@ util::Status Ecmg::ProcessCwProvisionMessage(const char* message,
|
||||
EcmInitParameters ecm_init_params;
|
||||
ecm_init_params.content_iv_size = kIvSize8;
|
||||
ecm_init_params.key_rotation_enabled = key_rotation_enabled;
|
||||
// Only CTR is supported for now.
|
||||
ecm_init_params.crypto_mode = CasCryptoMode::CTR;
|
||||
// TODO(user): Allow caller to specify the crypto mode.
|
||||
ecm_init_params.crypto_mode = CryptoMode::kAesCtr;
|
||||
// Only encrypt one video track.
|
||||
ecm_init_params.track_types.push_back(kDefaultTrackTypeSd);
|
||||
std::string entitlement_request;
|
||||
|
||||
Reference in New Issue
Block a user