Code Drop Two (Update One)
This is the second code drop for the white-box api reference implementation and tests. This corrects the errors in the license white-box reference implementation and implements the remaining test cases. It should be noted that there is one test case missing, the test case for handling ChromeOS's unique policy settings. In order to make the tests easier to create and read, a license builder class was created and golden content and keys were wrapped in their own classes. How key errors are communicated was changed in the API. WB_RESULT_NO_SUCH_KEY and WB_RESULT_WRONG_KEY_TYPE were merged into WB_RESULT_KEY_UNAVAILABLE.
This commit is contained in:
@@ -6,315 +6,470 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "api/golden_data.h"
|
||||
#include "api/license_builder.h"
|
||||
#include "api/license_whitebox_test_base.h"
|
||||
#include "api/test_data.h"
|
||||
#include "crypto_utils/rsa_key.h"
|
||||
#include "testing/include/gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
namespace widevine {
|
||||
|
||||
// All decrypt tests require a valid (initialized) white-box. However, not all
|
||||
// tests need to load a license, so that is left out of SetUp().
|
||||
class LicenseWhiteboxDecryptTest : public ::testing::Test {
|
||||
class LicenseWhiteboxDecryptTest : public LicenseWhiteboxTestBase {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
// All of our tests here require a valid whitebox.
|
||||
std::vector<uint8_t> init_data = GetLicenseInitData();
|
||||
ASSERT_GT(init_data.size(), 0u);
|
||||
ASSERT_EQ(WB_License_Create(init_data.data(), init_data.size(), &whitebox_),
|
||||
LicenseWhiteboxTestBase::SetUp();
|
||||
|
||||
// Because we are using the same buffer for both CTR and CBC, need to make
|
||||
// sure that it is large enough for either one.
|
||||
plaintext_size_ = std::max(golden_data_.CBCContent().ciphertext.size(),
|
||||
golden_data_.CTRContent().ciphertext.size());
|
||||
plaintext_.resize(plaintext_size_);
|
||||
|
||||
golden_data_.MakeKeyIdDifferent(&non_content_key_id_);
|
||||
golden_data_.MakeKeyIdDifferent(&missing_key_id_);
|
||||
}
|
||||
|
||||
void LoadLicense(const std::vector<uint8_t>& padding) {
|
||||
LicenseBuilder builder;
|
||||
|
||||
builder.AddContentKey(golden_data_.CBCCryptoKey().level,
|
||||
golden_data_.CBCCryptoKey().id,
|
||||
golden_data_.CBCCryptoKey().content->key);
|
||||
|
||||
builder.AddContentKey(golden_data_.CTRCryptoKey().level,
|
||||
golden_data_.CTRCryptoKey().id,
|
||||
golden_data_.CTRCryptoKey().content->key);
|
||||
|
||||
builder.AddContentKey(golden_data_.CBCDecodeKey().level,
|
||||
golden_data_.CBCDecodeKey().id,
|
||||
golden_data_.CBCDecodeKey().content->key);
|
||||
|
||||
builder.AddContentKey(golden_data_.CBCHardwareKey().level,
|
||||
golden_data_.CBCHardwareKey().id,
|
||||
golden_data_.CBCHardwareKey().content->key);
|
||||
|
||||
builder.AddOperatorSessionKey(non_content_key_id_);
|
||||
|
||||
License license;
|
||||
builder.Build(*public_key_, &license);
|
||||
|
||||
ASSERT_EQ(WB_License_ProcessLicenseResponse(
|
||||
whitebox_, license.message.data(), license.message.size(),
|
||||
license.signature.data(), license.signature.size(),
|
||||
license.session_key.data(), license.session_key.size(),
|
||||
license.request.data(), license.request.size()),
|
||||
WB_RESULT_OK);
|
||||
ASSERT_TRUE(whitebox_);
|
||||
}
|
||||
|
||||
void TearDown() override { WB_License_Delete(whitebox_); }
|
||||
// We need two special keys for this test, one that will be used for a
|
||||
// non-content key and one that will never be in the license.
|
||||
std::vector<uint8_t> non_content_key_id_ = {0, 0, 0};
|
||||
std::vector<uint8_t> missing_key_id_ = {1, 0, 0};
|
||||
|
||||
void LoadLicense() {
|
||||
// TODO: Load the license here. It would be nice if we could do it in
|
||||
// SetUp(), but since we need to support the WB_RESULT_INVALID_STATE test
|
||||
// case, we need a way to not load a license.
|
||||
}
|
||||
|
||||
WB_License_Whitebox* whitebox_ = nullptr;
|
||||
|
||||
// TODO(vaage): Replace key ids with the key ids in the license. Since we
|
||||
// don't have a license right now, any id will do.
|
||||
const std::vector<uint8_t> crypto_key_id_ = {0xAA, 0xBB, 0xAA, 0xBB};
|
||||
const std::vector<uint8_t> decode_key_id_ = {0xAA, 0xBB, 0xAA, 0xBB};
|
||||
const std::vector<uint8_t> renewal_key_id_ = {0xAA, 0xBB, 0xAA, 0xBB};
|
||||
|
||||
// TODO(vaage): Replace with golden ciphertext that will match the golden
|
||||
// plaintext.
|
||||
const std::vector<uint8_t> ciphertext_ = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
const std::vector<uint8_t> iv_ = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
// TODO(vaage): Replace with golden plaintext that will match the golden
|
||||
// ciphertext.
|
||||
const std::vector<uint8_t> plaintext_ = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
// This is the buffer used to store the output of each decrypt call.
|
||||
size_t plaintext_size_;
|
||||
std::vector<uint8_t> plaintext_;
|
||||
};
|
||||
|
||||
TEST_F(LicenseWhiteboxDecryptTest, Success) {
|
||||
// TODO(vaage): This test will fail for now because it will attempt to look-up
|
||||
// the key before attempting to decrypt anything. Since |plaintext_| and
|
||||
// |ciphertext_| are not even set correctly, this wouldn't pass even if it had
|
||||
// a license.
|
||||
GTEST_SKIP();
|
||||
TEST_F(LicenseWhiteboxDecryptTest, CryptoKeyWithCbcDataInCbcMode) {
|
||||
LoadLicense(LicenseBuilder::NoPadding());
|
||||
|
||||
LoadLicense();
|
||||
ASSERT_EQ(
|
||||
WB_License_Decrypt(whitebox_, WB_CIPHER_MODE_CBC,
|
||||
golden_data_.CBCCryptoKey().id.data(),
|
||||
golden_data_.CBCCryptoKey().id.size(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.data(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.size(),
|
||||
golden_data_.CBCCryptoKey().content->iv.data(),
|
||||
golden_data_.CBCCryptoKey().content->iv.size(),
|
||||
plaintext_.data(), &plaintext_size_),
|
||||
WB_RESULT_OK);
|
||||
plaintext_.resize(plaintext_size_);
|
||||
ASSERT_EQ(plaintext_, golden_data_.CBCCryptoKey().content->plaintext);
|
||||
}
|
||||
|
||||
size_t plaintext_size = ciphertext_.size();
|
||||
std::vector<uint8_t> plaintext(plaintext_size);
|
||||
TEST_F(LicenseWhiteboxDecryptTest, CryptoKeyWithCtrDataInCtrMode) {
|
||||
LoadLicense(LicenseBuilder::NoPadding());
|
||||
|
||||
ASSERT_EQ(WB_License_Decrypt(
|
||||
whitebox_, WB_CIPHER_MODE_CBC, crypto_key_id_.data(),
|
||||
crypto_key_id_.size(), ciphertext_.data(), ciphertext_.size(),
|
||||
iv_.data(), iv_.size(), plaintext.data(), &plaintext_size),
|
||||
WB_RESULT_OK);
|
||||
ASSERT_EQ(
|
||||
WB_License_Decrypt(whitebox_, WB_CIPHER_MODE_CTR,
|
||||
golden_data_.CTRCryptoKey().id.data(),
|
||||
golden_data_.CTRCryptoKey().id.size(),
|
||||
golden_data_.CTRCryptoKey().content->ciphertext.data(),
|
||||
golden_data_.CTRCryptoKey().content->ciphertext.size(),
|
||||
golden_data_.CTRCryptoKey().content->iv.data(),
|
||||
golden_data_.CTRCryptoKey().content->iv.size(),
|
||||
plaintext_.data(), &plaintext_size_),
|
||||
WB_RESULT_OK);
|
||||
plaintext_.resize(plaintext_size_);
|
||||
ASSERT_EQ(plaintext_, golden_data_.CTRCryptoKey().content->plaintext);
|
||||
}
|
||||
|
||||
// Since we are not using any padding, the ciphertext and plaintext should be
|
||||
// the same size. However, in the case that something went wrong, resize the
|
||||
// plaintext so that ASSERT_EQ will operate on the correct size.
|
||||
plaintext.resize(plaintext_size);
|
||||
// We try to decrypt CBC encrypted data in CTR mode. All operations should be
|
||||
// successful, but the resulting plaintext should not match.
|
||||
TEST_F(LicenseWhiteboxDecryptTest, CryptoKeyWithCbcDataInCtrMode) {
|
||||
LoadLicense(LicenseBuilder::NoPadding());
|
||||
|
||||
ASSERT_EQ(plaintext, plaintext_);
|
||||
ASSERT_EQ(
|
||||
WB_License_Decrypt(whitebox_, WB_CIPHER_MODE_CTR,
|
||||
golden_data_.CBCCryptoKey().id.data(),
|
||||
golden_data_.CBCCryptoKey().id.size(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.data(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.size(),
|
||||
golden_data_.CBCCryptoKey().content->iv.data(),
|
||||
golden_data_.CBCCryptoKey().content->iv.size(),
|
||||
plaintext_.data(), &plaintext_size_),
|
||||
WB_RESULT_OK);
|
||||
plaintext_.resize(plaintext_size_);
|
||||
ASSERT_NE(plaintext_, golden_data_.CBCCryptoKey().content->plaintext);
|
||||
}
|
||||
|
||||
// We try to decrypt CTR encrypted data in CBC mode. All operations should be
|
||||
// successful, but the resulting plaintext should not match.
|
||||
TEST_F(LicenseWhiteboxDecryptTest, CryptoKeyWithCtrDataInCbcMode) {
|
||||
LoadLicense(LicenseBuilder::NoPadding());
|
||||
|
||||
ASSERT_EQ(
|
||||
WB_License_Decrypt(whitebox_, WB_CIPHER_MODE_CBC,
|
||||
golden_data_.CTRCryptoKey().id.data(),
|
||||
golden_data_.CTRCryptoKey().id.size(),
|
||||
golden_data_.CTRCryptoKey().content->ciphertext.data(),
|
||||
golden_data_.CTRCryptoKey().content->ciphertext.size(),
|
||||
golden_data_.CTRCryptoKey().content->iv.data(),
|
||||
golden_data_.CTRCryptoKey().content->iv.size(),
|
||||
plaintext_.data(), &plaintext_size_),
|
||||
WB_RESULT_OK);
|
||||
plaintext_.resize(plaintext_size_);
|
||||
ASSERT_NE(plaintext_, golden_data_.CTRCryptoKey().content->plaintext);
|
||||
}
|
||||
|
||||
TEST_F(LicenseWhiteboxDecryptTest, CryptoKeyWithCbcDataAndPKCS8Padding) {
|
||||
LoadLicense(LicenseBuilder::PKSC8Padding());
|
||||
|
||||
ASSERT_EQ(
|
||||
WB_License_Decrypt(whitebox_, WB_CIPHER_MODE_CBC,
|
||||
golden_data_.CBCCryptoKey().id.data(),
|
||||
golden_data_.CBCCryptoKey().id.size(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.data(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.size(),
|
||||
golden_data_.CBCCryptoKey().content->iv.data(),
|
||||
golden_data_.CBCCryptoKey().content->iv.size(),
|
||||
plaintext_.data(), &plaintext_size_),
|
||||
WB_RESULT_OK);
|
||||
plaintext_.resize(plaintext_size_);
|
||||
ASSERT_EQ(plaintext_, golden_data_.CBCCryptoKey().content->plaintext);
|
||||
}
|
||||
|
||||
TEST_F(LicenseWhiteboxDecryptTest, CryptoKeyWithCtrDataAndPKCS8Padding) {
|
||||
LoadLicense(LicenseBuilder::PKSC8Padding());
|
||||
|
||||
ASSERT_EQ(
|
||||
WB_License_Decrypt(whitebox_, WB_CIPHER_MODE_CTR,
|
||||
golden_data_.CTRCryptoKey().id.data(),
|
||||
golden_data_.CTRCryptoKey().id.size(),
|
||||
golden_data_.CTRCryptoKey().content->ciphertext.data(),
|
||||
golden_data_.CTRCryptoKey().content->ciphertext.size(),
|
||||
golden_data_.CTRCryptoKey().content->iv.data(),
|
||||
golden_data_.CTRCryptoKey().content->iv.size(),
|
||||
plaintext_.data(), &plaintext_size_),
|
||||
WB_RESULT_OK);
|
||||
plaintext_.resize(plaintext_size_);
|
||||
ASSERT_EQ(plaintext_, golden_data_.CTRCryptoKey().content->plaintext);
|
||||
}
|
||||
|
||||
// Try decrypting two different sets of content to make sure that two
|
||||
// different keys can be used at the same time.
|
||||
TEST_F(LicenseWhiteboxDecryptTest, SuccessWithMultipleKeys) {
|
||||
LoadLicense(LicenseBuilder::NoPadding());
|
||||
|
||||
ASSERT_EQ(
|
||||
WB_License_Decrypt(whitebox_, WB_CIPHER_MODE_CBC,
|
||||
golden_data_.CBCCryptoKey().id.data(),
|
||||
golden_data_.CBCCryptoKey().id.size(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.data(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.size(),
|
||||
golden_data_.CBCCryptoKey().content->iv.data(),
|
||||
golden_data_.CBCCryptoKey().content->iv.size(),
|
||||
plaintext_.data(), &plaintext_size_),
|
||||
WB_RESULT_OK);
|
||||
plaintext_.resize(plaintext_size_);
|
||||
ASSERT_EQ(plaintext_, golden_data_.CBCCryptoKey().content->plaintext);
|
||||
|
||||
// Reset our output buffer.
|
||||
plaintext_.clear();
|
||||
plaintext_size_ = golden_data_.CTRDecodeKey().content->plaintext.size();
|
||||
plaintext_.resize(plaintext_size_);
|
||||
|
||||
ASSERT_EQ(
|
||||
WB_License_Decrypt(whitebox_, WB_CIPHER_MODE_CTR,
|
||||
golden_data_.CTRCryptoKey().id.data(),
|
||||
golden_data_.CTRCryptoKey().id.size(),
|
||||
golden_data_.CTRCryptoKey().content->ciphertext.data(),
|
||||
golden_data_.CTRCryptoKey().content->ciphertext.size(),
|
||||
golden_data_.CTRCryptoKey().content->iv.data(),
|
||||
golden_data_.CTRCryptoKey().content->iv.size(),
|
||||
plaintext_.data(), &plaintext_size_),
|
||||
WB_RESULT_OK);
|
||||
|
||||
plaintext_.resize(plaintext_size_);
|
||||
ASSERT_EQ(plaintext_, golden_data_.CTRCryptoKey().content->plaintext);
|
||||
}
|
||||
|
||||
TEST_F(LicenseWhiteboxDecryptTest, InvalidParameterForNullWhitebox) {
|
||||
LoadLicense();
|
||||
LoadLicense(LicenseBuilder::NoPadding());
|
||||
|
||||
size_t plaintext_size = ciphertext_.size();
|
||||
std::vector<uint8_t> plaintext(plaintext_size);
|
||||
|
||||
ASSERT_EQ(WB_License_Decrypt(
|
||||
nullptr, WB_CIPHER_MODE_CBC, crypto_key_id_.data(),
|
||||
crypto_key_id_.size(), ciphertext_.data(), ciphertext_.size(),
|
||||
iv_.data(), iv_.size(), plaintext.data(), &plaintext_size),
|
||||
WB_RESULT_INVALID_PARAMETER);
|
||||
ASSERT_EQ(
|
||||
WB_License_Decrypt(nullptr, WB_CIPHER_MODE_CBC,
|
||||
golden_data_.CBCCryptoKey().id.data(),
|
||||
golden_data_.CBCCryptoKey().id.size(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.data(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.size(),
|
||||
golden_data_.CBCCryptoKey().content->iv.data(),
|
||||
golden_data_.CBCCryptoKey().content->iv.size(),
|
||||
plaintext_.data(), &plaintext_size_),
|
||||
WB_RESULT_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
TEST_F(LicenseWhiteboxDecryptTest, InvalidParameterForInvalidCipherMode) {
|
||||
// TODO(vaage): This test will fail for now because it will attempt to
|
||||
// look-up the key before attempting to decrypt anything.
|
||||
GTEST_SKIP();
|
||||
|
||||
LoadLicense();
|
||||
LoadLicense(LicenseBuilder::NoPadding());
|
||||
|
||||
// In order to trick the compiler into letting us pass an invalid enum value
|
||||
// to WB__License_Decrypt(), we need to cast it. If we don't do this, the
|
||||
// compiler tries to save us.
|
||||
const WB_CipherMode invalid_mode = static_cast<WB_CipherMode>(0xFF);
|
||||
|
||||
size_t plaintext_size = ciphertext_.size();
|
||||
std::vector<uint8_t> plaintext(plaintext_size);
|
||||
|
||||
ASSERT_EQ(WB_License_Decrypt(whitebox_, invalid_mode, crypto_key_id_.data(),
|
||||
crypto_key_id_.size(), ciphertext_.data(),
|
||||
ciphertext_.size(), iv_.data(), iv_.size(),
|
||||
plaintext.data(), &plaintext_size),
|
||||
ASSERT_EQ(WB_License_Decrypt(
|
||||
whitebox_, invalid_mode, golden_data_.CBCCryptoKey().id.data(),
|
||||
golden_data_.CBCCryptoKey().id.size(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.data(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.size(),
|
||||
golden_data_.CBCCryptoKey().content->iv.data(),
|
||||
golden_data_.CBCCryptoKey().content->iv.size(),
|
||||
plaintext_.data(), &plaintext_size_),
|
||||
WB_RESULT_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
TEST_F(LicenseWhiteboxDecryptTest, InvalidParameterForNullKeyId) {
|
||||
LoadLicense();
|
||||
|
||||
size_t plaintext_size = ciphertext_.size();
|
||||
std::vector<uint8_t> plaintext(plaintext_size);
|
||||
|
||||
ASSERT_EQ(WB_License_Decrypt(whitebox_, WB_CIPHER_MODE_CBC, nullptr,
|
||||
crypto_key_id_.size(), ciphertext_.data(),
|
||||
ciphertext_.size(), iv_.data(), iv_.size(),
|
||||
plaintext.data(), &plaintext_size),
|
||||
WB_RESULT_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
TEST_F(LicenseWhiteboxDecryptTest, InvalidParameterForNullZeroKeyIdSize) {
|
||||
LoadLicense();
|
||||
|
||||
size_t plaintext_size = ciphertext_.size();
|
||||
std::vector<uint8_t> plaintext(plaintext_size);
|
||||
LoadLicense(LicenseBuilder::NoPadding());
|
||||
|
||||
ASSERT_EQ(
|
||||
WB_License_Decrypt(whitebox_, WB_CIPHER_MODE_CBC, crypto_key_id_.data(),
|
||||
0, ciphertext_.data(), ciphertext_.size(), iv_.data(),
|
||||
iv_.size(), plaintext.data(), &plaintext_size),
|
||||
WB_License_Decrypt(whitebox_, WB_CIPHER_MODE_CBC, nullptr,
|
||||
golden_data_.CBCCryptoKey().id.size(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.data(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.size(),
|
||||
golden_data_.CBCCryptoKey().content->iv.data(),
|
||||
golden_data_.CBCCryptoKey().content->iv.size(),
|
||||
plaintext_.data(), &plaintext_size_),
|
||||
WB_RESULT_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
TEST_F(LicenseWhiteboxDecryptTest, InvalidParameterForZeroKeyIdSize) {
|
||||
LoadLicense(LicenseBuilder::NoPadding());
|
||||
|
||||
ASSERT_EQ(
|
||||
WB_License_Decrypt(whitebox_, WB_CIPHER_MODE_CBC,
|
||||
golden_data_.CBCCryptoKey().id.data(), 0,
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.data(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.size(),
|
||||
golden_data_.CBCCryptoKey().content->iv.data(),
|
||||
golden_data_.CBCCryptoKey().content->iv.size(),
|
||||
plaintext_.data(), &plaintext_size_),
|
||||
WB_RESULT_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
TEST_F(LicenseWhiteboxDecryptTest, InvalidParameterForNullInputData) {
|
||||
// TODO(vaage): This test will fail for now because it will attempt to
|
||||
// look-up the key before attempting to decrypt anything.
|
||||
GTEST_SKIP();
|
||||
LoadLicense(LicenseBuilder::NoPadding());
|
||||
|
||||
LoadLicense();
|
||||
|
||||
size_t plaintext_size = ciphertext_.size();
|
||||
std::vector<uint8_t> plaintext(plaintext_size);
|
||||
|
||||
ASSERT_EQ(WB_License_Decrypt(whitebox_, WB_CIPHER_MODE_CBC,
|
||||
crypto_key_id_.data(), crypto_key_id_.size(),
|
||||
nullptr, ciphertext_.size(), iv_.data(),
|
||||
iv_.size(), plaintext.data(), &plaintext_size),
|
||||
WB_RESULT_INVALID_PARAMETER);
|
||||
ASSERT_EQ(
|
||||
WB_License_Decrypt(whitebox_, WB_CIPHER_MODE_CBC,
|
||||
golden_data_.CBCCryptoKey().id.data(),
|
||||
golden_data_.CBCCryptoKey().id.size(), nullptr,
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.size(),
|
||||
golden_data_.CBCCryptoKey().content->iv.data(),
|
||||
golden_data_.CBCCryptoKey().content->iv.size(),
|
||||
plaintext_.data(), &plaintext_size_),
|
||||
WB_RESULT_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
// AES CBC requires that the input be block aligned (multiple of 16). CTR does
|
||||
// not care. Size zero input is not considered invalid input.
|
||||
TEST_F(LicenseWhiteboxDecryptTest,
|
||||
InvalidParameterForCBCAndInvalidInputDataSize) {
|
||||
// TODO(vaage): This test will fail for now because it will attempt to
|
||||
// look-up the key before attempting to decrypt anything.
|
||||
GTEST_SKIP();
|
||||
// not care.
|
||||
TEST_F(LicenseWhiteboxDecryptTest, InvalidParameterForInvalidCBCInputDataSize) {
|
||||
LoadLicense(LicenseBuilder::NoPadding());
|
||||
|
||||
LoadLicense();
|
||||
ASSERT_EQ(
|
||||
WB_License_Decrypt(whitebox_, WB_CIPHER_MODE_CBC,
|
||||
golden_data_.CBCCryptoKey().id.data(),
|
||||
golden_data_.CBCCryptoKey().id.size(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.data(),
|
||||
14, golden_data_.CBCCryptoKey().content->iv.data(),
|
||||
golden_data_.CBCCryptoKey().content->iv.size(),
|
||||
plaintext_.data(), &plaintext_size_),
|
||||
WB_RESULT_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
size_t plaintext_size = ciphertext_.size();
|
||||
std::vector<uint8_t> plaintext(plaintext_size);
|
||||
// The white-box (using any cipher mode) should reject input with size zero.
|
||||
TEST_F(LicenseWhiteboxDecryptTest, InvalidParameterForZeroInputDataSize) {
|
||||
LoadLicense(LicenseBuilder::NoPadding());
|
||||
|
||||
ASSERT_EQ(WB_License_Decrypt(whitebox_, WB_CIPHER_MODE_CBC,
|
||||
crypto_key_id_.data(), crypto_key_id_.size(),
|
||||
ciphertext_.data(), 14, iv_.data(), iv_.size(),
|
||||
plaintext.data(), &plaintext_size),
|
||||
WB_RESULT_INVALID_PARAMETER);
|
||||
ASSERT_EQ(
|
||||
WB_License_Decrypt(whitebox_, WB_CIPHER_MODE_CBC,
|
||||
golden_data_.CBCCryptoKey().id.data(),
|
||||
golden_data_.CBCCryptoKey().id.size(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.data(),
|
||||
0, golden_data_.CBCCryptoKey().content->iv.data(),
|
||||
golden_data_.CBCCryptoKey().content->iv.size(),
|
||||
plaintext_.data(), &plaintext_size_),
|
||||
WB_RESULT_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
TEST_F(LicenseWhiteboxDecryptTest, InvalidParameterForNullIV) {
|
||||
// TODO(vaage): This test will fail for now because it will attempt to
|
||||
// look-up the key before attempting to decrypt anything.
|
||||
GTEST_SKIP();
|
||||
LoadLicense(LicenseBuilder::NoPadding());
|
||||
|
||||
LoadLicense();
|
||||
|
||||
size_t plaintext_size = ciphertext_.size();
|
||||
std::vector<uint8_t> plaintext(plaintext_size);
|
||||
|
||||
ASSERT_EQ(WB_License_Decrypt(whitebox_, WB_CIPHER_MODE_CBC,
|
||||
crypto_key_id_.data(), crypto_key_id_.size(),
|
||||
ciphertext_.data(), ciphertext_.size(), nullptr,
|
||||
iv_.size(), plaintext.data(), &plaintext_size),
|
||||
WB_RESULT_INVALID_PARAMETER);
|
||||
ASSERT_EQ(
|
||||
WB_License_Decrypt(
|
||||
whitebox_, WB_CIPHER_MODE_CBC, golden_data_.CBCCryptoKey().id.data(),
|
||||
golden_data_.CBCCryptoKey().id.size(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.data(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.size(), nullptr,
|
||||
golden_data_.CBCCryptoKey().content->iv.size(), plaintext_.data(),
|
||||
&plaintext_size_),
|
||||
WB_RESULT_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
// IV size should be 16. Any number other than 16 should fail.
|
||||
TEST_F(LicenseWhiteboxDecryptTest, InvalidParameterForInvalidIVSize) {
|
||||
// TODO(vaage): This test will fail for now because it will attempt to
|
||||
// look-up the key before attempting to decrypt anything.
|
||||
GTEST_SKIP();
|
||||
LoadLicense(LicenseBuilder::NoPadding());
|
||||
|
||||
LoadLicense();
|
||||
|
||||
size_t plaintext_size = ciphertext_.size();
|
||||
std::vector<uint8_t> plaintext(plaintext_size);
|
||||
|
||||
ASSERT_EQ(WB_License_Decrypt(
|
||||
whitebox_, WB_CIPHER_MODE_CBC, crypto_key_id_.data(),
|
||||
crypto_key_id_.size(), ciphertext_.data(), ciphertext_.size(),
|
||||
iv_.data(), 9, plaintext.data(), &plaintext_size),
|
||||
WB_RESULT_INVALID_PARAMETER);
|
||||
ASSERT_EQ(
|
||||
WB_License_Decrypt(whitebox_, WB_CIPHER_MODE_CBC,
|
||||
golden_data_.CBCCryptoKey().id.data(),
|
||||
golden_data_.CBCCryptoKey().id.size(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.data(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.size(),
|
||||
golden_data_.CBCCryptoKey().content->iv.data(), 9,
|
||||
plaintext_.data(), &plaintext_size_),
|
||||
WB_RESULT_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
TEST_F(LicenseWhiteboxDecryptTest, InvalidParameterForNullOutput) {
|
||||
// TODO(vaage): This test will fail for now because it will attempt to
|
||||
// look-up the key before attempting to decrypt anything.
|
||||
GTEST_SKIP();
|
||||
LoadLicense(LicenseBuilder::NoPadding());
|
||||
|
||||
LoadLicense();
|
||||
|
||||
size_t plaintext_size = ciphertext_.size();
|
||||
|
||||
ASSERT_EQ(WB_License_Decrypt(
|
||||
whitebox_, WB_CIPHER_MODE_CBC, crypto_key_id_.data(),
|
||||
crypto_key_id_.size(), ciphertext_.data(), ciphertext_.size(),
|
||||
iv_.data(), iv_.size(), nullptr, &plaintext_size),
|
||||
WB_RESULT_INVALID_PARAMETER);
|
||||
ASSERT_EQ(
|
||||
WB_License_Decrypt(whitebox_, WB_CIPHER_MODE_CBC,
|
||||
golden_data_.CBCCryptoKey().id.data(),
|
||||
golden_data_.CBCCryptoKey().id.size(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.data(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.size(),
|
||||
golden_data_.CBCCryptoKey().content->iv.data(),
|
||||
golden_data_.CBCCryptoKey().content->iv.size(),
|
||||
nullptr, &plaintext_size_),
|
||||
WB_RESULT_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
TEST_F(LicenseWhiteboxDecryptTest, InvalidParameterForNullOutputSize) {
|
||||
// TODO(vaage): This test will fail for now because it will attempt to
|
||||
// look-up the key before attempting to decrypt anything.
|
||||
GTEST_SKIP();
|
||||
LoadLicense(LicenseBuilder::NoPadding());
|
||||
|
||||
LoadLicense();
|
||||
|
||||
size_t plaintext_size = ciphertext_.size();
|
||||
std::vector<uint8_t> plaintext(plaintext_size);
|
||||
|
||||
ASSERT_EQ(WB_License_Decrypt(
|
||||
whitebox_, WB_CIPHER_MODE_CBC, crypto_key_id_.data(),
|
||||
crypto_key_id_.size(), ciphertext_.data(), ciphertext_.size(),
|
||||
iv_.data(), iv_.size(), plaintext.data(), nullptr),
|
||||
WB_RESULT_INVALID_PARAMETER);
|
||||
ASSERT_EQ(
|
||||
WB_License_Decrypt(whitebox_, WB_CIPHER_MODE_CBC,
|
||||
golden_data_.CBCCryptoKey().id.data(),
|
||||
golden_data_.CBCCryptoKey().id.size(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.data(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.size(),
|
||||
golden_data_.CBCCryptoKey().content->iv.data(),
|
||||
golden_data_.CBCCryptoKey().content->iv.size(),
|
||||
plaintext_.data(), nullptr),
|
||||
WB_RESULT_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
TEST_F(LicenseWhiteboxDecryptTest, NoSuchKey) {
|
||||
// TODO(vaage): This test will fail for now because it will attempt to
|
||||
// look-up the key and see that there are no keys, which will result in
|
||||
// WB_RESULT_INVALID_STATE.
|
||||
GTEST_SKIP();
|
||||
// For this test, "missing key id" specifically means a key id that was never
|
||||
// in the license to start with. This is different than "non content key"
|
||||
// and "dropped content key", as those keys were in the license but ignored.
|
||||
TEST_F(LicenseWhiteboxDecryptTest, KeyUnavailableForMissingKeyId) {
|
||||
LoadLicense(LicenseBuilder::NoPadding());
|
||||
|
||||
LoadLicense();
|
||||
|
||||
// For our fake key id, it is uncommon for key ids to be short. So using a one
|
||||
// byte key id should safe as they are allowed, just not likely to appear in
|
||||
// any test license.
|
||||
std::vector<uint8_t> not_a_key_id = {0xFF};
|
||||
|
||||
size_t plaintext_size = ciphertext_.size();
|
||||
std::vector<uint8_t> plaintext(plaintext_size);
|
||||
|
||||
ASSERT_EQ(WB_License_Decrypt(
|
||||
whitebox_, WB_CIPHER_MODE_CBC, not_a_key_id.data(),
|
||||
not_a_key_id.size(), ciphertext_.data(), ciphertext_.size(),
|
||||
iv_.data(), iv_.size(), plaintext.data(), &plaintext_size),
|
||||
WB_RESULT_NO_SUCH_KEY);
|
||||
ASSERT_EQ(
|
||||
WB_License_Decrypt(whitebox_, WB_CIPHER_MODE_CBC, missing_key_id_.data(),
|
||||
missing_key_id_.size(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.data(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.size(),
|
||||
golden_data_.CBCCryptoKey().content->iv.data(),
|
||||
golden_data_.CBCCryptoKey().content->iv.size(),
|
||||
plaintext_.data(), &plaintext_size_),
|
||||
WB_RESULT_KEY_UNAVAILABLE);
|
||||
}
|
||||
|
||||
TEST_F(LicenseWhiteboxDecryptTest, WrongKeyType) {
|
||||
// TODO(vaage): This test will fail for now because it will attempt to
|
||||
// look-up the key and see that there are no keys, which will result in
|
||||
// WB_RESULT_INVALID_STATE.
|
||||
GTEST_SKIP();
|
||||
TEST_F(LicenseWhiteboxDecryptTest, KeyUnavailableForNonContentKey) {
|
||||
LoadLicense(LicenseBuilder::NoPadding());
|
||||
|
||||
LoadLicense();
|
||||
|
||||
size_t plaintext_size = ciphertext_.size();
|
||||
std::vector<uint8_t> plaintext(plaintext_size);
|
||||
|
||||
ASSERT_EQ(WB_License_Decrypt(
|
||||
whitebox_, WB_CIPHER_MODE_CBC, renewal_key_id_.data(),
|
||||
renewal_key_id_.size(), ciphertext_.data(), ciphertext_.size(),
|
||||
iv_.data(), iv_.size(), plaintext.data(), &plaintext_size),
|
||||
WB_RESULT_WRONG_KEY_TYPE);
|
||||
ASSERT_EQ(
|
||||
WB_License_Decrypt(whitebox_, WB_CIPHER_MODE_CBC,
|
||||
non_content_key_id_.data(), non_content_key_id_.size(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.data(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.size(),
|
||||
golden_data_.CBCCryptoKey().content->iv.data(),
|
||||
golden_data_.CBCCryptoKey().content->iv.size(),
|
||||
plaintext_.data(), &plaintext_size_),
|
||||
WB_RESULT_KEY_UNAVAILABLE);
|
||||
}
|
||||
|
||||
TEST_F(LicenseWhiteboxDecryptTest, InsufficientSecurityLevel) {
|
||||
// TODO(vaage): This test will fail for now because it will attempt to
|
||||
// look-up the key and see that there are no keys, which will result in
|
||||
// WB_RESULT_INVALID_STATE.
|
||||
GTEST_SKIP();
|
||||
// Under normal circumstances, a hardware key should be dropped. The exception
|
||||
// to this rule is on ChromeOS with a special license.
|
||||
TEST_F(LicenseWhiteboxDecryptTest,
|
||||
InsufficientSecurityLevelForHardwareContentKey) {
|
||||
LoadLicense(LicenseBuilder::NoPadding());
|
||||
|
||||
LoadLicense();
|
||||
ASSERT_EQ(WB_License_Decrypt(
|
||||
whitebox_, WB_CIPHER_MODE_CBC,
|
||||
golden_data_.CBCHardwareKey().id.data(),
|
||||
golden_data_.CBCHardwareKey().id.size(),
|
||||
golden_data_.CBCHardwareKey().content->ciphertext.data(),
|
||||
golden_data_.CBCHardwareKey().content->ciphertext.size(),
|
||||
golden_data_.CBCHardwareKey().content->iv.data(),
|
||||
golden_data_.CBCHardwareKey().content->iv.size(),
|
||||
plaintext_.data(), &plaintext_size_),
|
||||
WB_RESULT_INSUFFICIENT_SECURITY_LEVEL);
|
||||
}
|
||||
|
||||
size_t plaintext_size = ciphertext_.size();
|
||||
std::vector<uint8_t> plaintext(plaintext_size);
|
||||
TEST_F(LicenseWhiteboxDecryptTest, InsufficientSecurityLevelForDecodeKey) {
|
||||
LoadLicense(LicenseBuilder::NoPadding());
|
||||
|
||||
// Use the software decode key as they are limited to
|
||||
// WB_License_MaskedDecrypt().
|
||||
ASSERT_EQ(WB_License_Decrypt(
|
||||
whitebox_, WB_CIPHER_MODE_CBC, decode_key_id_.data(),
|
||||
decode_key_id_.size(), ciphertext_.data(), ciphertext_.size(),
|
||||
iv_.data(), iv_.size(), plaintext.data(), &plaintext_size),
|
||||
WB_RESULT_INSUFFICIENT_SECURITY_LEVEL);
|
||||
// WB_License_Decrypt().
|
||||
ASSERT_EQ(
|
||||
WB_License_Decrypt(whitebox_, WB_CIPHER_MODE_CBC,
|
||||
golden_data_.CBCDecodeKey().id.data(),
|
||||
golden_data_.CBCDecodeKey().id.size(),
|
||||
golden_data_.CBCDecodeKey().content->ciphertext.data(),
|
||||
golden_data_.CBCDecodeKey().content->ciphertext.size(),
|
||||
golden_data_.CBCDecodeKey().content->iv.data(),
|
||||
golden_data_.CBCDecodeKey().content->iv.size(),
|
||||
plaintext_.data(), &plaintext_size_),
|
||||
WB_RESULT_INSUFFICIENT_SECURITY_LEVEL);
|
||||
}
|
||||
|
||||
TEST_F(LicenseWhiteboxDecryptTest, BufferTooSmall) {
|
||||
LoadLicense(LicenseBuilder::NoPadding());
|
||||
|
||||
// Our ciphertext will be large enough that we should not need to worry about
|
||||
// using a constant here.
|
||||
plaintext_size_ = 8;
|
||||
|
||||
ASSERT_EQ(
|
||||
WB_License_Decrypt(whitebox_, WB_CIPHER_MODE_CBC,
|
||||
golden_data_.CBCCryptoKey().id.data(),
|
||||
golden_data_.CBCCryptoKey().id.size(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.data(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.size(),
|
||||
golden_data_.CBCCryptoKey().content->iv.data(),
|
||||
golden_data_.CBCCryptoKey().content->iv.size(),
|
||||
plaintext_.data(), &plaintext_size_),
|
||||
WB_RESULT_BUFFER_TOO_SMALL);
|
||||
|
||||
// We don't use padding so the reported plaintext size should be the same as
|
||||
// the cipher text size.
|
||||
ASSERT_EQ(plaintext_size_,
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.size());
|
||||
}
|
||||
|
||||
TEST_F(LicenseWhiteboxDecryptTest, InvalidState) {
|
||||
@@ -322,34 +477,16 @@ TEST_F(LicenseWhiteboxDecryptTest, InvalidState) {
|
||||
// WB_RESULT_INVALID_STATE is that no key can be found and keys are provided
|
||||
// via a license.
|
||||
|
||||
size_t plaintext_size = ciphertext_.size();
|
||||
std::vector<uint8_t> plaintext(plaintext_size);
|
||||
|
||||
ASSERT_EQ(WB_License_Decrypt(
|
||||
whitebox_, WB_CIPHER_MODE_CBC, crypto_key_id_.data(),
|
||||
crypto_key_id_.size(), ciphertext_.data(), ciphertext_.size(),
|
||||
iv_.data(), iv_.size(), plaintext.data(), &plaintext_size),
|
||||
WB_RESULT_INVALID_STATE);
|
||||
ASSERT_EQ(
|
||||
WB_License_Decrypt(whitebox_, WB_CIPHER_MODE_CBC,
|
||||
golden_data_.CBCCryptoKey().id.data(),
|
||||
golden_data_.CBCCryptoKey().id.size(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.data(),
|
||||
golden_data_.CBCCryptoKey().content->ciphertext.size(),
|
||||
golden_data_.CBCCryptoKey().content->iv.data(),
|
||||
golden_data_.CBCCryptoKey().content->iv.size(),
|
||||
plaintext_.data(), &plaintext_size_),
|
||||
WB_RESULT_INVALID_STATE);
|
||||
}
|
||||
|
||||
TEST_F(LicenseWhiteboxDecryptTest, BufferTooSmall) {
|
||||
// TODO(vaage): This test will fail for now because it will attempt to
|
||||
// look-up the key before attempting to decrypt anything.
|
||||
GTEST_SKIP();
|
||||
|
||||
// Our ciphertext will be large enough that we should not need to worry about
|
||||
// using a constant here.
|
||||
size_t plaintext_size = 8;
|
||||
std::vector<uint8_t> plaintext(plaintext_size);
|
||||
|
||||
ASSERT_EQ(WB_License_Decrypt(
|
||||
whitebox_, WB_CIPHER_MODE_CBC, crypto_key_id_.data(),
|
||||
crypto_key_id_.size(), ciphertext_.data(), ciphertext_.size(),
|
||||
iv_.data(), iv_.size(), plaintext.data(), &plaintext_size),
|
||||
WB_RESULT_BUFFER_TOO_SMALL);
|
||||
|
||||
// We don't use padding so the reported plaintext size should be the same as
|
||||
// the cipher text size.
|
||||
ASSERT_EQ(plaintext_size, ciphertext_.size());
|
||||
}
|
||||
} // namespace
|
||||
} // namespace widevine
|
||||
|
||||
Reference in New Issue
Block a user