From 67c794bac351d0c15e00b5aca12cf3408e9bfe19 Mon Sep 17 00:00:00 2001 From: Fred Gylys-Colwell Date: Tue, 1 Oct 2013 19:02:16 -0700 Subject: [PATCH] Add unit test for empty mac key Merge of change https://widevine-internal-review.googlesource.com/7950. In the OEMCrypto library, it is valid to call LoadKeys with an empty mac key. The library should not update the mac and enc keys and should not throw an error. Since we have seen this behavior in several implementations, a unit test should be added that verifies the correct behavior. bug: 11032674 Change-Id: I011ba39c8abc47547226a722143e92dac3f63dc5 --- libwvdrmengine/oemcrypto/test/Android.mk | 3 -- .../oemcrypto/test/oemcrypto_test.cpp | 37 ++++++++++++++----- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/libwvdrmengine/oemcrypto/test/Android.mk b/libwvdrmengine/oemcrypto/test/Android.mk index 71368e90..be56d7e2 100644 --- a/libwvdrmengine/oemcrypto/test/Android.mk +++ b/libwvdrmengine/oemcrypto/test/Android.mk @@ -8,9 +8,6 @@ LOCAL_SRC_FILES:= \ LOCAL_MODULE_TAGS := tests -# Define CAN_INSTALL_KEYBOX and the unit test will install a known keybox and test decryption. -LOCAL_CFLAGS += -DCAN_INSTALL_KEYBOX - LOCAL_C_INCLUDES += \ bionic \ external/gtest/include \ diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp index 9ecd2f95..1b386aa3 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp @@ -1738,14 +1738,6 @@ TEST_F(OEMCryptoClientTest, GenerateDerivedKeys) { testTearDown(); } -// Define CAN_INSTALL_KEYBOX if you are compiling with the reference -// implementation of OEMCrypto, or if your version of OEMCrypto supports -// OEMCrypto_InstallKeybox with a clear keybox. -// The Below tests are based on a specific keybox which is installed for testing. -// They are disabled by default. Just because you can install a test keybox, -// does not mean you want to install a test keybox. -#if defined(CAN_INSTALL_KEYBOX) - /////////////////////////////////////////////////// // AddKey Tests /////////////////////////////////////////////////// @@ -1926,6 +1918,34 @@ TEST_F(DISABLED_TestKeybox, LoadKeyWithNonce) { testTearDown(); } +TEST_F(DISABLED_TestKeybox, LoadKeyWithNoMAC) { + testSetUp(); + InstallKeybox(kDefaultKeybox, true); + Session& s = createSession("ONE"); + s.open(); + + s.GenerateDerivedKeys(); + + MessageData data; + s.FillSimpleMessage(&data, 0, 0, 0); + + MessageData encrypted; + s.EncryptMessage(data, &encrypted); + std::vector signature; + s.ServerSignMessage(encrypted, &signature); + OEMCrypto_KeyObject key_array[kNumKeys]; + const uint8_t* message_ptr = reinterpret_cast(&encrypted); + s.FillKeyArray(encrypted, key_array); + OEMCryptoResult sts = OEMCrypto_LoadKeys(s.session_id(), + message_ptr, sizeof(encrypted), + &signature[0], signature.size(), + NULL, NULL, + kNumKeys, key_array); + ASSERT_EQ(OEMCrypto_SUCCESS, sts); + s.close(); + testTearDown(); +} + /* The Bad Range tests verify that OEMCrypto_LoadKeys checks the range of all the pointers. It should reject a message if the pointer does not point into the message buffer */ @@ -3719,5 +3739,4 @@ TEST_F(DISABLED_GenericDRMTest, KeyDurationVerify) { s.close(); testTearDown(); } -#endif // CAN_INSTALL_KEYBOX } // namespace wvoec