Update partner repo

This change includes:
- disbale the provider key in WORSPACE
- update the boringssl
- add AEAD tests
This commit is contained in:
Hua Wu
2022-10-25 19:47:45 -07:00
parent 3542f76362
commit 791eafa4bc
8 changed files with 237 additions and 17 deletions

View File

@@ -26,7 +26,7 @@ git_repository(
git_repository(
name = "boringssl_repo",
commit = "4fb158925f7753d80fb858cb0239dff893ef9f15", # 2021-11-01
commit = "d345d68d5c4b5471290ebe13f090f1fd5b7e8f58", # 2022-09-14
remote = "https://github.com/google/boringssl.git",
)

View File

@@ -16,7 +16,8 @@ cc_library(
"//:is_old_api": [],
"//:is_old_vmpra": [],
"//conditions:default": [
"HAS_PROVIDER_KEYS",
# Comment out HAS_PROVIDER_KEYS temporarily
# "HAS_PROVIDER_KEYS",
],
}) + select({
"//:is_chromeos": ["WV_ENABLE_HW_VERIFICATION=1"],

View File

@@ -14,6 +14,14 @@ std::vector<uint8_t> GetValidAeadInitData();
// Returns init data that the aead white-box will reject.
std::vector<uint8_t> GetInvalidAeadInitData();
struct AeadBackwardsCompatibleData {
std::vector<uint8_t> context;
std::vector<uint8_t> encrypted_data;
std::vector<uint8_t> original_data;
};
std::vector<AeadBackwardsCompatibleData> GetAeadBackwardsCompatibleData();
} // namespace widevine
#endif // WHITEBOX_API_AEAD_TEST_DATA_H_

View File

@@ -13,15 +13,8 @@ namespace widevine {
class AeadWhiteboxDecryptTest : public ::testing::Test {
protected:
void SetUp() override {
const std::vector<uint8_t> init_data = GetValidAeadInitData();
const std::vector<uint8_t> context = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
ASSERT_EQ(WB_Aead_Create(init_data.data(), init_data.size(), context.data(),
context.size(), &whitebox_),
ASSERT_EQ(WB_Aead_Create(init_data_.data(), init_data_.size(),
context_.data(), context_.size(), &whitebox_),
WB_RESULT_OK);
// Regardless of implementation, we need to have enough room in our cipher
@@ -40,6 +33,12 @@ class AeadWhiteboxDecryptTest : public ::testing::Test {
WB_Aead_Whitebox* whitebox_ = nullptr;
const std::vector<uint8_t> init_data_ = GetValidAeadInitData();
const std::vector<uint8_t> context_ = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
// Since we are going to verify decryption, we need the plaintext to be
// recognizable after it is encrypted and then decrypted.
const std::vector<uint8_t> plaintext_ = {
@@ -66,6 +65,90 @@ TEST_F(AeadWhiteboxDecryptTest, Success) {
ASSERT_EQ(plaintext, plaintext_);
}
TEST_F(AeadWhiteboxDecryptTest, SameContextDecryptionSucceeds) {
// Create a new whitebox with same init_data and context as |whitebox_|.
WB_Aead_Whitebox* whitebox = nullptr;
ASSERT_EQ(WB_Aead_Create(init_data_.data(), init_data_.size(),
context_.data(), context_.size(), &whitebox),
WB_RESULT_OK);
// Decrypt |ciphertext_| with the new whitebox.
size_t plaintext_size = ciphertext_.size();
std::vector<uint8_t> plaintext(plaintext_size);
ASSERT_EQ(WB_Aead_Decrypt(whitebox, ciphertext_.data(), ciphertext_.size(),
plaintext.data(), &plaintext_size),
WB_RESULT_OK);
plaintext.resize(plaintext_size);
ASSERT_EQ(plaintext_, plaintext);
}
TEST_F(AeadWhiteboxDecryptTest, DifferentContextDecryptionFails) {
// Create a new whitebox with same init_data as |whitebox_| but with a
// different context.
WB_Aead_Whitebox* whitebox = nullptr;
const std::vector<uint8_t> new_context = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
};
ASSERT_NE(new_context, context_);
ASSERT_EQ(WB_Aead_Create(init_data_.data(), init_data_.size(),
new_context.data(), new_context.size(), &whitebox),
WB_RESULT_OK);
// Decrypt |ciphertext_| with the new whitebox.
size_t plaintext_size = ciphertext_.size();
std::vector<uint8_t> plaintext(plaintext_size);
ASSERT_EQ(WB_Aead_Decrypt(whitebox, ciphertext_.data(), ciphertext_.size(),
plaintext.data(), &plaintext_size),
WB_RESULT_DATA_VERIFICATION_ERROR);
}
TEST_F(AeadWhiteboxDecryptTest, CrossPackageDecrypt) {
// Cross-package tests to verify that new packages can decrypt data
// encrypted by older packages, if the key and context is the same.
const auto& tests = GetAeadBackwardsCompatibleData();
ASSERT_GT(tests.size(), 0);
for (const auto& test : tests) {
WB_Aead_Whitebox* whitebox = nullptr;
ASSERT_EQ(
WB_Aead_Create(init_data_.data(), init_data_.size(),
test.context.data(), test.context.size(), &whitebox),
WB_RESULT_OK);
size_t decrypted_size = test.original_data.size();
std::vector<uint8_t> decrypted(decrypted_size);
ASSERT_EQ(WB_Aead_Decrypt(whitebox, test.encrypted_data.data(),
test.encrypted_data.size(), decrypted.data(),
&decrypted_size),
WB_RESULT_OK);
ASSERT_EQ(decrypted, test.original_data);
}
}
TEST_F(AeadWhiteboxDecryptTest, LargeDataSuccess) {
// Test decryption of data that is not a multiple of 16 bytes.
const std::vector<uint8_t> originaltext = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13,
0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24,
};
size_t ciphertext_size = 256;
std::vector<uint8_t> ciphertext(ciphertext_size);
ASSERT_EQ(WB_Aead_Encrypt(whitebox_, originaltext.data(), originaltext.size(),
ciphertext.data(), &ciphertext_size),
WB_RESULT_OK);
ciphertext.resize(ciphertext_size);
size_t plaintext_size = ciphertext_size;
std::vector<uint8_t> plaintext(plaintext_size);
ASSERT_EQ(WB_Aead_Decrypt(whitebox_, ciphertext.data(), ciphertext.size(),
plaintext.data(), &plaintext_size),
WB_RESULT_OK);
plaintext.resize(plaintext_size);
ASSERT_EQ(plaintext, originaltext);
}
TEST_F(AeadWhiteboxDecryptTest, InvalidParameterForNullWhitebox) {
// The plaintext should be smaller than the input, but we use the input so
// that we will always have enough.

View File

@@ -268,8 +268,8 @@ std::string WrapContentKey(const std::vector<uint8_t>& unwrapped_content_key,
// If |provider_key_id| is used, then mask the resulting key.
if (provider_key_id_valid) {
const auto& mask = provider_keys[provider_key_id - 1].mask;
for (size_t i = 0; i < encrypted_key.size(); ++i)
encrypted_key[i] ^= mask[i];
for (size_t i = 0; i < mask.size(); ++i)
encrypted_key[i] ^= mask.at(i);
}
return encrypted_key;

View File

@@ -10,8 +10,8 @@ std::vector<uint8_t> GetValidAeadInitData() {
// Valid init data for our AEAD implementation is any AES key, so it just
// needs to be 16 bytes.
return {
0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x0,
0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
}
@@ -21,4 +21,132 @@ std::vector<uint8_t> GetInvalidAeadInitData() {
return {0x00};
}
std::vector<AeadBackwardsCompatibleData> GetAeadBackwardsCompatibleData() {
// clang-format off
return {
{
{
// context
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
{
// encrypted_data
0x08, 0x78, 0x0e, 0x03, 0x05, 0xf2, 0xf9, 0x04, 0x27, 0xdd, 0xd1,
0xf3, 0x13, 0xe7, 0x4a, 0x15, 0x02, 0x49, 0x53, 0x61, 0x21, 0x13,
0x01, 0xc4, 0x69, 0x7d, 0x29, 0x6b, 0x4c, 0xcd, 0x41, 0xc6, 0xa7,
0x55, 0xdf, 0xed, 0xbc, 0x9c, 0xb4, 0xb1, 0x77, 0xf7, 0x1c, 0xfb,
},
{
// original_data
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
},
},
{
{
// context
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
{
// encrypted_data
0xeb, 0x76, 0x36, 0xe9, 0xd9, 0x6e, 0x36, 0x55, 0xa0, 0x32, 0xfc,
0x5f, 0x38, 0x6d, 0x7e, 0x78, 0x9a, 0x48, 0x6d, 0x13, 0x01, 0x48,
0xf5, 0xd7, 0x7c, 0x4a, 0xdf, 0xeb, 0x66, 0x4e, 0x23, 0x3c, 0x70,
0x08, 0xee, 0x73, 0x37, 0x8f, 0x8a, 0x0b, 0x40, 0xe2, 0xc5, 0x1f,
},
{
// original_data
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
},
},
{
{
// context
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
{
// encrypted_data
0xad, 0x5c, 0x37, 0x12, 0xd5, 0x0b, 0x10, 0x36, 0x09, 0x6d, 0x76,
0x27, 0x2f, 0x56, 0x1d, 0xa6, 0x46, 0x62, 0x23, 0xe1, 0xe3, 0x4d,
0xac, 0xc6, 0xf2, 0x9d, 0x0b, 0x22, 0xb2, 0x6e, 0x3b, 0x56, 0xc0,
0xe9, 0xfc, 0x97, 0x69, 0x40, 0x48, 0x1b, 0xd6, 0xbd, 0x8d, 0x6a,
},
{
// original_data
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
},
},
{
{
// context
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
},
{
// encrypted_data
0xbf, 0xcb, 0x46, 0x63, 0x79, 0x2a, 0x57, 0xc0, 0xd6, 0x37, 0xa0,
0x02, 0x55, 0x36, 0xd8, 0xa2, 0x51, 0xd4, 0x00, 0x11, 0xea, 0x0b,
0x36, 0xd7, 0xcd, 0xd2, 0x05, 0xff, 0xb3, 0x21, 0x76, 0x29, 0x8c,
0x33, 0x64, 0x29, 0x30, 0xe0, 0xcd, 0x9d, 0x88, 0x2d, 0xcd, 0x86,
0xad, 0x5b, 0x42, 0x41,
},
{
// original_data (20 bytes)
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a,
0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24,
},
},
{
{
// context
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
},
{
// encrypted_data
0xd9, 0xf1, 0x0f, 0xcc, 0x26, 0xdc, 0x88, 0x4b, 0x6d, 0x8f, 0x8d,
0x78, 0xfc, 0x38, 0xea, 0x2a, 0x7d, 0x3a, 0x42, 0x37, 0x3e, 0x2c,
0x0f, 0x29, 0x56, 0xe6, 0xff, 0xd7, 0xe1, 0x16, 0x20, 0x0a, 0x21,
0x49, 0x7c, 0x85, 0x35, 0x5c, 0x46, 0xd1, 0xa2, 0xe0, 0x37, 0xce,
0xd7, 0x7c, 0xb3, 0xae,
},
{
// original_data (20 bytes)
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a,
0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24,
},
},
{
{
// context
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
{
// encrypted_data
0x6f, 0x9b, 0xb0, 0xf4, 0xa4, 0xbf, 0xcf, 0x86, 0x99, 0x6d, 0xff,
0x07, 0x1e, 0x30, 0x26, 0x4c, 0xb8, 0xed, 0x07, 0xc2, 0x28, 0x32,
0x9e, 0x0c, 0xaf, 0x4a, 0xa5, 0xd4, 0x18, 0x10, 0xa3, 0xc4, 0xd6,
0xf3, 0x11, 0x88, 0x34, 0x43, 0x15, 0xca, 0xbe, 0xc1, 0x46, 0x49,
0x66, 0x52, 0x52, 0xf2, 0x1e, 0xda, 0x4d, 0xd1, 0xed, 0x76, 0x54,
0x10, 0x63, 0xe2, 0x1f, 0xc7, 0xf3, 0xd1, 0xa7, 0x3f, 0x83,
},
{
// original_data (37 bytes)
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x20, 0x21, 0x22, 0x23, 0x24,
},
},
};
// clang-format on
}
} // namespace widevine

View File

@@ -45,7 +45,7 @@ bool LicenseParser::UnwrapKey(
if (provider_key_id_valid) {
const auto& mask = provider_keys[provider_key_id - 1].mask;
for (size_t i = 0; i < key.size(); ++i)
key[i] ^= mask[i];
key[i] ^= mask.at(i);
}
// Now decrypt the key using the Key Encryption Key.

View File

@@ -910,7 +910,7 @@ WB_Result WB_License_MaskedDecrypt(const WB_License_Whitebox* whitebox,
const auto mask = GetSecretStringFor(mode);
for (size_t i = 0; i < output.size(); ++i) {
masked_output_data[i] =
InverseMaskingFunction1(output[i] ^ mask[i % mask.size()]);
InverseMaskingFunction1(output[i] ^ mask.at(i % mask.size()));
}
return WB_RESULT_OK;