Update test data for entitled license test

[ Merge of http://go/wvgerrit/199355 ]

A new set of license data was created on UAT so that we
could have keys that match those in the license returned by
a License SDK and by those generated by UAT.

It should be more clear now which data is just made up, and
which data has to match some golden values based on the made
up data.

Bug: 338323091
Test: WVTS
Change-Id: Ic112b4594afb99c6f43e011f59ee7592d4809189
This commit is contained in:
Alex Dale
2024-10-03 14:29:37 -07:00
parent b8a80cf3e8
commit d4e11f1727
3 changed files with 39 additions and 1 deletions

View File

@@ -683,7 +683,7 @@ void InitializationData::DumpToLogs() const {
if (!is_supported()) {
LOGD("InitData: Not supported");
}
if (!IsEmpty()) {
if (IsEmpty()) {
LOGD("InitData: Empty");
}
std::string type_info = type();
@@ -738,6 +738,9 @@ void InitializationData::DumpToLogs() const {
LOGD("InitData: entitlement_key_id %d: %s -> %s", i,
wvutil::b2a_hex(key.entitlement_key_id()).c_str(),
wvutil::b2a_hex(key.key_id()).c_str());
LOGD("InitData: entitled_key %d: %s", i,
wvutil::b2a_hex(key.key()).c_str());
LOGD("InitData: iv %d: %s", i, wvutil::b2a_hex(key.iv()).c_str());
}
}

View File

@@ -144,6 +144,17 @@ void show_menu(const char* prog_name, const std::string& extra_help_text) {
std::cout << extra_help_text << std::endl;
}
// Increment counter for AES-CTR. The CENC spec specifies we increment only
// the low 64 bits of the IV counter, and leave the high 64 bits alone. This
// is different from the BoringSSL implementation, so we implement the CTR loop
// ourselves.
void ctr128_inc64(int64_t increaseBy, std::vector<uint8_t>& iv) {
uint64_t* counterBuffer = reinterpret_cast<uint64_t*>(&(iv[8]));
(*counterBuffer) =
wvutil::htonll64(wvutil::ntohll64(*counterBuffer) + increaseBy);
}
} // namespace
std::unique_ptr<ConfigTestEnv> WvCdmTestBase::default_config_;
@@ -157,6 +168,26 @@ void WvCdmTestBase::StripeBuffer(std::vector<uint8_t>* buffer, size_t size,
}
}
// Encrypt a block of data using CTR mode.
std::vector<uint8_t> WvCdmTestBase::Aes128CtrEncrypt(
const std::vector<uint8_t>& key, const std::vector<uint8_t>& starting_iv,
const std::vector<uint8_t>& in_buffer) {
AES_KEY aes_key;
AES_set_encrypt_key(key.data(), AES_BLOCK_SIZE * 8, &aes_key);
std::vector<uint8_t> out_buffer(in_buffer.size());
std::vector<uint8_t> iv = starting_iv;
size_t l = 0; // byte index into encrypted subsample.
while (l < in_buffer.size()) {
uint8_t aes_output[AES_BLOCK_SIZE];
AES_encrypt(iv.data(), aes_output, &aes_key);
for (size_t n = 0; n < AES_BLOCK_SIZE && l < in_buffer.size(); n++, l++) {
out_buffer[l] = aes_output[n] ^ in_buffer[l];
}
ctr128_inc64(1, iv);
}
return out_buffer;
}
std::string WvCdmTestBase::Aes128CbcEncrypt(std::vector<uint8_t> key,
const std::vector<uint8_t>& clear,
const std::vector<uint8_t> iv) {

View File

@@ -62,6 +62,10 @@ class WvCdmTestBase : public ::testing::Test {
const std::vector<uint8_t>& clear,
const std::vector<uint8_t> iv);
// Helper method for doing cryptography.
static std::vector<uint8_t> Aes128CtrEncrypt(
const std::vector<uint8_t>& key, const std::vector<uint8_t>& starting_iv,
const std::vector<uint8_t>& in_buffer);
// Helper method for doing cryptography.
static std::string SignHMAC(const std::string& message,
const std::vector<uint8_t>& key);