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
This commit is contained in:
Fred Gylys-Colwell
2013-10-01 19:02:16 -07:00
parent fc0c408c8d
commit 67c794bac3
2 changed files with 28 additions and 12 deletions

View File

@@ -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 \

View File

@@ -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<uint8_t> signature;
s.ServerSignMessage(encrypted, &signature);
OEMCrypto_KeyObject key_array[kNumKeys];
const uint8_t* message_ptr = reinterpret_cast<const uint8_t*>(&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