From a615671f4809656d639fe367c2b9fc96813937b8 Mon Sep 17 00:00:00 2001 From: Fred Gylys-Colwell Date: Sat, 30 May 2020 20:49:01 -0700 Subject: [PATCH] Unit test for loading nonce-free offline license Merge from Widevine repo of http://go/wvgerrit/100964 The previous nonce-free test used the same session to generate the request as to load the license. However, it is a realistic use case to have a new session used for loading the license. The use case relates to a pre-loaded, shared license. Test: Ran unit tests on taimen and on v16 ref implementation Bug: 156853321 Change-Id: Ibc07744a16edcd3952d88d73660a75d0c3e8eeb8 --- libwvdrmengine/oemcrypto/test/oec_session_util.cpp | 6 +++--- libwvdrmengine/oemcrypto/test/oec_session_util.h | 2 +- libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp | 8 +++++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/libwvdrmengine/oemcrypto/test/oec_session_util.cpp b/libwvdrmengine/oemcrypto/test/oec_session_util.cpp index 769aec75..26a98f5e 100644 --- a/libwvdrmengine/oemcrypto/test/oec_session_util.cpp +++ b/libwvdrmengine/oemcrypto/test/oec_session_util.cpp @@ -635,7 +635,7 @@ OEMCryptoResult LicenseRoundTrip::LoadResponse(Session* session) { // Note: we verify content licenses here. For entitlement license, we verify // the key control blocks after loading entitled content keys. - if (license_type_ == OEMCrypto_ContentLicense) VerifyTestKeys(); + if (license_type_ == OEMCrypto_ContentLicense) VerifyTestKeys(session); } return result; } @@ -649,12 +649,12 @@ OEMCryptoResult LicenseRoundTrip::ReloadResponse(Session* session) { // with the truth key control block. Failures in this function probably // indicate the OEMCrypto_LoadLicense/LoadKeys did not correctly process the key // control block. -void LicenseRoundTrip::VerifyTestKeys() { +void LicenseRoundTrip::VerifyTestKeys(Session* session) { for (unsigned int i = 0; i < num_keys_; i++) { KeyControlBlock block; size_t size = sizeof(block); OEMCryptoResult sts = OEMCrypto_QueryKeyControl( - session_->session_id(), response_data_.keys[i].key_id, + session->session_id(), response_data_.keys[i].key_id, response_data_.keys[i].key_id_length, reinterpret_cast(&block), &size); if (sts != OEMCrypto_ERROR_NOT_IMPLEMENTED) { diff --git a/libwvdrmengine/oemcrypto/test/oec_session_util.h b/libwvdrmengine/oemcrypto/test/oec_session_util.h index 36848d52..54ee3187 100644 --- a/libwvdrmengine/oemcrypto/test/oec_session_util.h +++ b/libwvdrmengine/oemcrypto/test/oec_session_util.h @@ -298,7 +298,7 @@ class LicenseRoundTrip // Reload an offline license into a different session. This derives new mac // keys and then calls LoadResponse. OEMCryptoResult ReloadResponse(Session* session); - void VerifyTestKeys(); + void VerifyTestKeys(Session* session); // Set the default key control block for all keys. This is used in // CreateDefaultResponse. The key control block determines the restrictions // that OEMCrypto should place on a key's use. For example, it specifies the diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp index e584e20f..02e4e838 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp @@ -854,7 +854,13 @@ TEST_P(OEMCryptoLicenseTest, LoadKeyWithNoRequest) { 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()); + + // Load license in a different session, which did not create the request. + Session session2; + ASSERT_NO_FATAL_FAILURE(session2.open()); + ASSERT_NO_FATAL_FAILURE(InstallTestRSAKey(&session2)); + ASSERT_NO_FATAL_FAILURE(session2.GenerateDerivedKeysFromSessionKey()); + ASSERT_EQ(OEMCrypto_SUCCESS, license_messages_.LoadResponse(&session2)); } // Verify that a license may be loaded with a nonce.