From 3e5b6d74899743d5831864fe8b06c167d566aea0 Mon Sep 17 00:00:00 2001 From: Rahul Frias Date: Wed, 10 Feb 2016 14:49:09 -0800 Subject: [PATCH] Test Simultaneous decrypt and remove NULL pointer comparison [ Merge of http://go/wvgerrit/16544, http://go/wvgerrit/16639 ] * This fixes the oemcrypto unit tests to build with the ce cdm. The unit tests do not build when it is detected that a long (NULL) is compared to a pointer. * Remove NULL pointer comparison On some platforms ASSERT_NE(NULL, ptr) does not work. This CL replaces it with ASSERT_TRUE(NULL != ptr). * Test Simultaneous Decrypt With the increasing number of devices that support multiple screens or windows, it is desireable to verify that OEMCrypto can have several sessions open and actively decrypting at the same time. Calls to OEMCrypto are still serialized -- this is not a threading test -- but we still have multiple sessions open and decrypt from each of them. * Remove unused variable in initialization_data Change-Id: I1a4be38fb30a14f610544416db653a81342f16b3 --- .../cdm/core/src/initialization_data.cpp | 1 - .../oemcrypto/test/oemcrypto_test.cpp | 65 +++++++++++++++++-- 2 files changed, 58 insertions(+), 8 deletions(-) diff --git a/libwvdrmengine/cdm/core/src/initialization_data.cpp b/libwvdrmengine/cdm/core/src/initialization_data.cpp index 86bb34e8..688b5249 100644 --- a/libwvdrmengine/cdm/core/src/initialization_data.cpp +++ b/libwvdrmengine/cdm/core/src/initialization_data.cpp @@ -357,7 +357,6 @@ bool InitializationData::ConstructWidevineInitData( json_init_data.size()); // Parse the Json string using jsmn - int result = 0; jsmn_parser parser; jsmntok_t tokens[kDefaultNumJsonTokens]; jsmn_init(&parser); diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp index 5da8cca3..356a8745 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp @@ -526,7 +526,7 @@ static void dump_openssl_error() { // is different from the OpenSSL implementation, so we implement the CTR loop // ourselves. void ctr128_inc64(int64_t increaseBy, uint8_t* iv) { - ASSERT_TRUE(NULL != iv); + ASSERT_NE(static_cast(NULL), iv); uint64_t* counterBuffer = reinterpret_cast(&iv[8]); (*counterBuffer) = wvcdm::htonll64(wvcdm::ntohll64(*counterBuffer) + increaseBy); @@ -877,9 +877,9 @@ class Session { void EncryptCTR(const vector& in_buffer,const uint8_t *key, const uint8_t* starting_iv, vector* out_buffer) { - ASSERT_TRUE(NULL != key); - ASSERT_TRUE(NULL != starting_iv); - ASSERT_TRUE(NULL != out_buffer); + ASSERT_NE(static_cast(NULL), key); + ASSERT_NE(static_cast(NULL), starting_iv); + ASSERT_NE(static_cast(NULL), out_buffer); AES_KEY aes_key; AES_set_encrypt_key(key, AES_BLOCK_SIZE * 8, &aes_key); out_buffer->resize(in_buffer.size()); @@ -1646,9 +1646,7 @@ TEST_F(OEMCryptoKeyboxTest, NormalGetKeyData) { ASSERT_EQ(OEMCrypto_SUCCESS, sts); } -// TODO(fredgc): warn people that this will be turned on. It causes a -// seg fault on some devices at the moment. -TEST_F(OEMCryptoKeyboxTest, DISABLED_GetKeyDataNullPointer) { +TEST_F(OEMCryptoKeyboxTest, GetKeyDataNullPointer) { OEMCryptoResult sts; uint8_t key_data[256]; sts = OEMCrypto_GetKeyData(key_data, NULL); @@ -2366,6 +2364,59 @@ TEST_F(OEMCryptoSessionTests, DecryptZeroDuration) { ASSERT_NO_FATAL_FAILURE(s.TestDecryptCTR()); } +TEST_F(OEMCryptoSessionTests, SimultaneousDecrypt) { + vector s(8); + for (int i = 0; i < 8; i++) { + ASSERT_NO_FATAL_FAILURE(s[i].open()); + } + for (int i = 0; i < 8; i++) { + ASSERT_NO_FATAL_FAILURE(s[i].GenerateTestSessionKeys()); + ASSERT_NO_FATAL_FAILURE(s[i].FillSimpleMessage(kDuration, 0, + s[i].get_nonce())); + ASSERT_NO_FATAL_FAILURE(s[i].EncryptAndSign()); + } + for (int i = 0; i < 8; i++) { + ASSERT_NO_FATAL_FAILURE(s[i].LoadTestKeys()); + } + for (int i = 0; i < 8; i++) { + ASSERT_NO_FATAL_FAILURE(s[i].TestDecryptCTR()); + } + // Second call to decrypt for each session. + for (int i = 0; i < 8; i++) { + ASSERT_NO_FATAL_FAILURE(s[i].TestDecryptCTR()); + } +} + +TEST_F(OEMCryptoSessionTests, SimultaneousDecryptWithLostMessage) { + vector s(8); + for (int i = 0; i < 8; i++) { + ASSERT_NO_FATAL_FAILURE(s[i].open()); + } + for (int i = 0; i < 8; i++) { + ASSERT_NO_FATAL_FAILURE(s[i].GenerateTestSessionKeys()); + ASSERT_NO_FATAL_FAILURE(s[i].FillSimpleMessage(kDuration, 0, + s[i].get_nonce())); + ASSERT_NO_FATAL_FAILURE(s[i].EncryptAndSign()); + } + // First set of messages are lost. Generate second set. + for (int i = 0; i < 8; i++) { + ASSERT_NO_FATAL_FAILURE(s[i].GenerateTestSessionKeys()); + ASSERT_NO_FATAL_FAILURE(s[i].FillSimpleMessage(kDuration, 0, + s[i].get_nonce())); + ASSERT_NO_FATAL_FAILURE(s[i].EncryptAndSign()); + } + for (int i = 0; i < 8; i++) { + ASSERT_NO_FATAL_FAILURE(s[i].LoadTestKeys()); + } + for (int i = 0; i < 8; i++) { + ASSERT_NO_FATAL_FAILURE(s[i].TestDecryptCTR()); + } + // Second call to decrypt for each session. + for (int i = 0; i < 8; i++) { + ASSERT_NO_FATAL_FAILURE(s[i].TestDecryptCTR()); + } +} + struct SampleSize { size_t clear_size; size_t encrypted_size;