From 15cf441d17e98f5d0b89f2510b8f852a7108d298 Mon Sep 17 00:00:00 2001 From: Jeff Tinker Date: Thu, 25 Apr 2013 05:55:10 -0700 Subject: [PATCH] Fix RefreshKey Test The test for refresh keys with a stale nonce was not performed correctly. It was supposed to test that RefreshKeys fails when the nonce is stale. However, the nonce in the test was not stale. The reference implementation did fail, but it failed because the control bits were in network byte order instead of host byte order. Both of these problems are fixed in this CL. This CL changes test code only. The change has already been communicated with Qualcomm. bug: 8621521 Merge of https://widevine-internal-review.googlesource.com/#/c/5263/ from Widevine CDM repo. Change-Id: I0821eff914d1680481006b9b68d49e8f2c5b9cd8 --- .../oemcrypto/test/oemcrypto_test.cpp | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp index b43ea2ab..d01debf9 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp @@ -2137,12 +2137,11 @@ class OEMCryptoRefreshKeyTest : public OEMCryptoClientTest { Session& s = createSession("ONE"); s.open(); s.GenerateDerivedKeys(); - s.LoadTestKeys(kDuration, 0); + s.LoadTestKeys(kDuration, wvoec_mock::kControlNonceEnabled); uint32_t nonce; s.GenerateNonce(&nonce); - s.RefreshTestKeys(key_count, - htonl(wvoec_mock::kControlNonceEnabled), nonce, - true ); + s.RefreshTestKeys(key_count, wvoec_mock::kControlNonceEnabled, nonce, + true); s.close(); } @@ -2153,7 +2152,7 @@ class OEMCryptoRefreshKeyTest : public OEMCryptoClientTest { s.LoadTestKeys(kDuration, 0); uint32_t nonce; s.GenerateNonce(&nonce); - s.RefreshTestKeys(key_count,0, 0, true ); + s.RefreshTestKeys(key_count,0, 0, true); s.close(); } @@ -2161,37 +2160,41 @@ class OEMCryptoRefreshKeyTest : public OEMCryptoClientTest { Session& s = createSession("ONE"); s.open(); s.GenerateDerivedKeys(); - s.LoadTestKeys(kDuration, 0); + s.LoadTestKeys(kDuration, wvoec_mock::kControlNonceEnabled); uint32_t nonce = s.get_nonce(); - s.RefreshTestKeys(key_count, - htonl(wvoec_mock::kControlNonceEnabled), nonce, - false ); + s.RefreshTestKeys(key_count, wvoec_mock::kControlNonceEnabled, nonce, + false); s.close(); } void RefreshBadNonce(const int key_count) { Session& s = createSession("ONE"); s.open(); s.GenerateDerivedKeys(); - s.LoadTestKeys(kDuration, 0); + s.LoadTestKeys(kDuration, wvoec_mock::kControlNonceEnabled); uint32_t nonce; s.GenerateNonce(&nonce); nonce = 42; - s.RefreshTestKeys(key_count, - htonl(wvoec_mock::kControlNonceEnabled), nonce, - false ); + s.RefreshTestKeys(key_count, wvoec_mock::kControlNonceEnabled, nonce, + false); s.close(); } }; -TEST_F(OEMCryptoRefreshKeyTest, RefreshKeys) { +TEST_F(OEMCryptoRefreshKeyTest, RefreshAllKeys) { testSetUp(); InstallKeybox(kDefaultKeybox); - RefreshWithNonce(1); - RefreshWithNonce(kNumKeys); + RefreshWithNonce(1); // One key control block to refresh all keys. RefreshOldNonce(1); - RefreshOldNonce(kNumKeys); RefreshBadNonce(1); + testTearDown(); +} + +TEST_F(OEMCryptoRefreshKeyTest, RefreshEachKeys) { + testSetUp(); + InstallKeybox(kDefaultKeybox); + RefreshWithNonce(kNumKeys); // Each key control block updates a different key. + RefreshOldNonce(kNumKeys); RefreshBadNonce(kNumKeys); testTearDown(); }