Add unit test for preloaded license
Merge from Widevine repo of http://go/wvgerrit/96508 This adds a unit test for to verify that a preloaded license may be loaded into OEMCrypto. A preloaded license is a license that does not have a nonce, and for which there is no license request. This is used in CAS and ATSC. I also updated the test version string to OEMCrypto unit tests for API 16.2. Tests last updated 2020-03-27 Bug: 144105097 Test: ran oemcrypto unit tests on taimen and with v16 modmock. Change-Id: I6a4926917f36a084d15defa7b908d067612c4dcf
This commit is contained in:
@@ -190,6 +190,7 @@ SessionContext::SessionContext(CryptoEngine* ce, SessionId sid,
|
|||||||
id_(sid),
|
id_(sid),
|
||||||
current_content_key_(nullptr),
|
current_content_key_(nullptr),
|
||||||
session_keys_(nullptr),
|
session_keys_(nullptr),
|
||||||
|
license_request_hash_(),
|
||||||
rsa_key_(rsa_key),
|
rsa_key_(rsa_key),
|
||||||
allowed_schemes_(kSign_RSASSA_PSS),
|
allowed_schemes_(kSign_RSASSA_PSS),
|
||||||
decrypt_started_(false),
|
decrypt_started_(false),
|
||||||
|
|||||||
@@ -586,9 +586,6 @@ void LicenseRoundTrip::EncryptAndSignResponse() {
|
|||||||
memcpy(encrypted_response_.data() + serialized_core_message_.size(),
|
memcpy(encrypted_response_.data() + serialized_core_message_.size(),
|
||||||
reinterpret_cast<const uint8_t*>(&encrypted_response_data_),
|
reinterpret_cast<const uint8_t*>(&encrypted_response_data_),
|
||||||
sizeof(encrypted_response_data_));
|
sizeof(encrypted_response_data_));
|
||||||
if (global_features.provisioning_method == OEMCrypto_OEMCertificate) {
|
|
||||||
session()->GenerateDerivedKeysFromSessionKey();
|
|
||||||
}
|
|
||||||
session()->key_deriver().ServerSignBuffer(encrypted_response_.data(),
|
session()->key_deriver().ServerSignBuffer(encrypted_response_.data(),
|
||||||
encrypted_response_.size(),
|
encrypted_response_.size(),
|
||||||
&response_signature_);
|
&response_signature_);
|
||||||
|
|||||||
@@ -283,7 +283,8 @@ class LicenseRoundTrip
|
|||||||
update_mac_keys_(true),
|
update_mac_keys_(true),
|
||||||
api_version_(kCurrentAPI),
|
api_version_(kCurrentAPI),
|
||||||
expect_request_has_correct_nonce_(true),
|
expect_request_has_correct_nonce_(true),
|
||||||
license_type_(OEMCrypto_ContentLicense) {}
|
license_type_(OEMCrypto_ContentLicense),
|
||||||
|
request_hash_() {}
|
||||||
void CreateDefaultResponse() override;
|
void CreateDefaultResponse() override;
|
||||||
// Create a license with four keys. Each key is responsible for one of generic
|
// Create a license with four keys. Each key is responsible for one of generic
|
||||||
// encrypt (key 0), decrypt (key 1), sign (key 2) and verify (key 3). Each key
|
// encrypt (key 0), decrypt (key 1), sign (key 2) and verify (key 3). Each key
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ class OEMCryptoClientTest : public ::testing::Test, public SessionUtil {
|
|||||||
// tests are failing when the device has the wrong keybox installed.
|
// tests are failing when the device has the wrong keybox installed.
|
||||||
TEST_F(OEMCryptoClientTest, VersionNumber) {
|
TEST_F(OEMCryptoClientTest, VersionNumber) {
|
||||||
const std::string log_message =
|
const std::string log_message =
|
||||||
"OEMCrypto unit tests for API 16.2. Tests last updated 2020-03-18";
|
"OEMCrypto unit tests for API 16.2. Tests last updated 2020-03-27";
|
||||||
cout << " " << log_message << "\n";
|
cout << " " << log_message << "\n";
|
||||||
LOGI("%s", log_message.c_str());
|
LOGI("%s", log_message.c_str());
|
||||||
// If any of the following fail, then it is time to update the log message
|
// If any of the following fail, then it is time to update the log message
|
||||||
@@ -874,6 +874,25 @@ TEST_P(OEMCryptoLicenseTest, LoadKeyNoNonce) {
|
|||||||
ASSERT_EQ(OEMCrypto_SUCCESS, license_messages_.LoadResponse());
|
ASSERT_EQ(OEMCrypto_SUCCESS, license_messages_.LoadResponse());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify that a preloaded license may be loaded without first signing the
|
||||||
|
// request. This test is important for the preloaded licenses used by ATSC and
|
||||||
|
// CAS.
|
||||||
|
TEST_P(OEMCryptoLicenseTest, LoadKeyWithNoRequest) {
|
||||||
|
if (license_api_version_ > global_features.api_version) {
|
||||||
|
// We should not attempt to preload a license with an API higher than that
|
||||||
|
// of OEMCrypto.
|
||||||
|
license_api_version_ = global_features.api_version;
|
||||||
|
license_messages_.set_api_version(license_api_version_);
|
||||||
|
}
|
||||||
|
license_messages_.set_control(0);
|
||||||
|
// The test code uses the core request to create the core response.
|
||||||
|
license_messages_.core_request().api_major_version = ODK_MAJOR_VERSION;
|
||||||
|
license_messages_.core_request().api_minor_version = ODK_MINOR_VERSION;
|
||||||
|
ASSERT_NO_FATAL_FAILURE(license_messages_.CreateDefaultResponse());
|
||||||
|
ASSERT_NO_FATAL_FAILURE(license_messages_.EncryptAndSignResponse());
|
||||||
|
ASSERT_EQ(OEMCrypto_SUCCESS, license_messages_.LoadResponse());
|
||||||
|
}
|
||||||
|
|
||||||
// Verify that a license may be loaded with a nonce.
|
// Verify that a license may be loaded with a nonce.
|
||||||
TEST_P(OEMCryptoLicenseTest, LoadKeyWithNonce) {
|
TEST_P(OEMCryptoLicenseTest, LoadKeyWithNonce) {
|
||||||
ASSERT_NO_FATAL_FAILURE(session_.GenerateNonce());
|
ASSERT_NO_FATAL_FAILURE(session_.GenerateNonce());
|
||||||
|
|||||||
Reference in New Issue
Block a user