Update tests for license release

Merge from Widevine repo of http://go/wvgerrit/95403

This updates the test code CreateDefaultResponse to make sure that
license releases do not have a core message, and that the key control
block is correctly set for renewals.

Also, the unit test OEMCryptoUsageTableTest.TimingTest is changed to
only a license release when the license is inactive. If the license is
still active, then the license is loaded before generating a usage
report.

Test: Ran full unit tests
Bug: 151092673
Change-Id: I7c01fd17f9b66e88ab3c57aa0f3d40740f13507c
This commit is contained in:
Fred Gylys-Colwell
2020-03-09 13:14:56 -07:00
parent bf5c819046
commit 037918aa49
2 changed files with 15 additions and 24 deletions

View File

@@ -844,7 +844,7 @@ void RenewalRoundTrip::FillAndVerifyCoreRequest(
} }
void RenewalRoundTrip::CreateDefaultResponse() { void RenewalRoundTrip::CreateDefaultResponse() {
if (license_messages_->api_version() < kCoreMessagesAPI) { if (license_messages_->api_version() < kCoreMessagesAPI || is_release_) {
uint32_t control = 0; uint32_t control = 0;
uint32_t nonce = 0; uint32_t nonce = 0;
// If this is a v15 device, and a v15 license, and the license used a nonce, // If this is a v15 device, and a v15 license, and the license used a nonce,
@@ -859,12 +859,9 @@ void RenewalRoundTrip::CreateDefaultResponse() {
constexpr size_t index = 0; constexpr size_t index = 0;
response_data_.keys[index].key_id_length = 0; response_data_.keys[index].key_id_length = 0;
response_data_.keys[index].key_id[0] = '\0'; response_data_.keys[index].key_id[0] = '\0';
std::string kcVersion = const uint32_t renewal_api =
"kc" + std::to_string(core_request_.api_major_version); std::max<uint32_t>(core_request_.api_major_version, 15u);
if (global_features.api_version < kCoreMessagesAPI) { std::string kcVersion = "kc" + std::to_string(renewal_api);
// For v15 or earlier devices, we use the api of the device.
kcVersion = "kc" + std::to_string(global_features.api_version);
}
memcpy(response_data_.keys[index].control.verification, kcVersion.c_str(), memcpy(response_data_.keys[index].control.verification, kcVersion.c_str(),
4); 4);
const uint32_t duration = static_cast<uint32_t>( const uint32_t duration = static_cast<uint32_t>(

View File

@@ -1694,15 +1694,15 @@ class OEMCryptoSessionTestDecryptWithHDCP : public OEMCryptoSessionTests,
// reported if OEMCrypto_WARNING_MIXED_OUTPUT_PROTECTION is expected. // reported if OEMCrypto_WARNING_MIXED_OUTPUT_PROTECTION is expected.
ASSERT_NO_FATAL_FAILURE( ASSERT_NO_FATAL_FAILURE(
s.TestDecryptCTR(true, OEMCrypto_WARNING_MIXED_OUTPUT_PROTECTION)) s.TestDecryptCTR(true, OEMCrypto_WARNING_MIXED_OUTPUT_PROTECTION))
<< "Failed when current HDCP = " << HDCPCapabilityAsString(current) << "Failed when current HDCP = " << HDCPCapabilityAsString(current)
<< ", maximum HDCP = " << HDCPCapabilityAsString(maximum) << ", maximum HDCP = " << HDCPCapabilityAsString(maximum)
<< ", license HDCP = " << HDCPCapabilityAsString(version); << ", license HDCP = " << HDCPCapabilityAsString(version);
} else { } else {
ASSERT_NO_FATAL_FAILURE( ASSERT_NO_FATAL_FAILURE(
s.TestDecryptCTR(true, OEMCrypto_ERROR_INSUFFICIENT_HDCP)) s.TestDecryptCTR(true, OEMCrypto_ERROR_INSUFFICIENT_HDCP))
<< "Failed when current HDCP = " << HDCPCapabilityAsString(current) << "Failed when current HDCP = " << HDCPCapabilityAsString(current)
<< ", maximum HDCP = " << HDCPCapabilityAsString(maximum) << ", maximum HDCP = " << HDCPCapabilityAsString(maximum)
<< ", license HDCP = " << HDCPCapabilityAsString(version); << ", license HDCP = " << HDCPCapabilityAsString(version);
} }
} else { } else {
ASSERT_NO_FATAL_FAILURE(s.TestDecryptCTR(true, OEMCrypto_SUCCESS)) ASSERT_NO_FATAL_FAILURE(s.TestDecryptCTR(true, OEMCrypto_SUCCESS))
@@ -2804,7 +2804,8 @@ TEST_F(OEMCryptoLoadsCertificate, CertificateProvisionBadRSAKey) {
// Test that RewrapDeviceRSAKey verifies the RSA key is valid. // Test that RewrapDeviceRSAKey verifies the RSA key is valid.
// TODO(b/144186970): This test should also run on Prov 3.0 devices. // TODO(b/144186970): This test should also run on Prov 3.0 devices.
TEST_F(OEMCryptoLoadsCertificate, CertificateProvisionBadRSAKeyKeyboxTestAPI16) { TEST_F(OEMCryptoLoadsCertificate,
CertificateProvisionBadRSAKeyKeyboxTestAPI16) {
Session s; Session s;
ProvisioningRoundTrip provisioning_messages(&s, encoded_rsa_key_); ProvisioningRoundTrip provisioning_messages(&s, encoded_rsa_key_);
provisioning_messages.PrepareSession(keybox_); provisioning_messages.PrepareSession(keybox_);
@@ -6065,17 +6066,10 @@ TEST_P(OEMCryptoUsageTableTest, TimingTest) {
ASSERT_NO_FATAL_FAILURE(s2.close()); ASSERT_NO_FATAL_FAILURE(s2.close());
ASSERT_NO_FATAL_FAILURE(s1.open()); ASSERT_NO_FATAL_FAILURE(s1.open());
ASSERT_NO_FATAL_FAILURE(s2.open());
ASSERT_NO_FATAL_FAILURE(s3.open());
ASSERT_NO_FATAL_FAILURE(entry1.ReloadUsageEntry()); ASSERT_NO_FATAL_FAILURE(entry1.ReloadUsageEntry());
ASSERT_NO_FATAL_FAILURE(entry2.ReloadUsageEntry()); ASSERT_NO_FATAL_FAILURE(entry2.OpenAndReload(this));
ASSERT_NO_FATAL_FAILURE(entry3.ReloadUsageEntry()); ASSERT_NO_FATAL_FAILURE(entry3.OpenAndReload(this));
// Sending a release from an offline license that has been deactivate will
// only work if the license server can handle v16 licenses. This is a rare
// condition, so it is OK to break it during the transition months.
entry1.license_messages().set_api_version(global_features.api_version);
entry2.license_messages().set_api_version(global_features.api_version);
entry3.license_messages().set_api_version(global_features.api_version);
wvcdm::TestSleep::Sleep(kLongSleep); wvcdm::TestSleep::Sleep(kLongSleep);
ASSERT_NO_FATAL_FAILURE(s1.UpdateUsageEntry(&encrypted_usage_header_)); ASSERT_NO_FATAL_FAILURE(s1.UpdateUsageEntry(&encrypted_usage_header_));
ASSERT_NO_FATAL_FAILURE(entry1.GenerateVerifyReport(kInactiveUsed)); ASSERT_NO_FATAL_FAILURE(entry1.GenerateVerifyReport(kInactiveUsed));