diff --git a/libwvdrmengine/cdm/core/src/oemcrypto_adapter_dynamic.cpp b/libwvdrmengine/cdm/core/src/oemcrypto_adapter_dynamic.cpp index 99aa561d..35a2df13 100644 --- a/libwvdrmengine/cdm/core/src/oemcrypto_adapter_dynamic.cpp +++ b/libwvdrmengine/cdm/core/src/oemcrypto_adapter_dynamic.cpp @@ -25,7 +25,7 @@ #include "file_store.h" #include "properties.h" -using namespace wvoec_level3; +using namespace wvoec3; namespace wvcdm { diff --git a/libwvdrmengine/level3/arm/libwvlevel3.a b/libwvdrmengine/level3/arm/libwvlevel3.a index dee658cf..bfd2aa30 100644 Binary files a/libwvdrmengine/level3/arm/libwvlevel3.a and b/libwvdrmengine/level3/arm/libwvlevel3.a differ diff --git a/libwvdrmengine/level3/mips/libwvlevel3.a b/libwvdrmengine/level3/mips/libwvlevel3.a index 208dc60b..7bf3ea79 100644 Binary files a/libwvdrmengine/level3/mips/libwvlevel3.a and b/libwvdrmengine/level3/mips/libwvlevel3.a differ diff --git a/libwvdrmengine/level3/x86/libwvlevel3.a b/libwvdrmengine/level3/x86/libwvlevel3.a index 08bd2854..ce51425b 100644 Binary files a/libwvdrmengine/level3/x86/libwvlevel3.a and b/libwvdrmengine/level3/x86/libwvlevel3.a differ diff --git a/libwvdrmengine/oemcrypto/include/level3.h b/libwvdrmengine/oemcrypto/include/level3.h index b8e81d92..d8cb3a7f 100644 --- a/libwvdrmengine/oemcrypto/include/level3.h +++ b/libwvdrmengine/oemcrypto/include/level3.h @@ -14,7 +14,7 @@ #include "OEMCryptoCENC.h" -namespace wvoec_level3 { +namespace wvoec3 { #define Level3_Initialize _lcc01 #define Level3_Terminate _lcc02 diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_mock.cpp b/libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_mock.cpp index a3d70e51..a993f8b3 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_mock.cpp +++ b/libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_mock.cpp @@ -36,7 +36,7 @@ void ctr128_inc(uint8_t* counter) { uint32_t n = 16; do { if (++counter[--n] != 0) return; - } while (n); + } while (n>8); } void dump_openssl_error() { while (unsigned long err = ERR_get_error()) { diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_mock.cpp b/libwvdrmengine/oemcrypto/mock/src/oemcrypto_mock.cpp index 1a6338c0..0c36afc3 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_mock.cpp +++ b/libwvdrmengine/oemcrypto/mock/src/oemcrypto_mock.cpp @@ -240,7 +240,7 @@ OEMCryptoResult OEMCrypto_GenerateSignature( } return OEMCrypto_SUCCESS; } - return OEMCrypto_ERROR_UNKNOWN_FAILURE;; + return OEMCrypto_ERROR_UNKNOWN_FAILURE; } bool RangeCheck(const uint8_t* message, diff --git a/libwvdrmengine/oemcrypto/mock/src/wvcrc.cpp b/libwvdrmengine/oemcrypto/mock/src/wvcrc.cpp index 506315a5..334c4f36 100644 --- a/libwvdrmengine/oemcrypto/mock/src/wvcrc.cpp +++ b/libwvdrmengine/oemcrypto/mock/src/wvcrc.cpp @@ -6,11 +6,12 @@ * Compte CRC32 Checksum. Needed for verification of WV Keybox. *********************************************************************/ +#include #include "wvcrc32.h" #define INIT_CRC32 0xffffffff -uint32_t wvrunningcrc32(uint8_t* p_begin, int i_count, uint32_t i_crc) { +uint32_t wvrunningcrc32(const uint8_t* p_begin, int i_count, uint32_t i_crc) { static uint32_t CRC32[256] = { 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005, @@ -88,6 +89,10 @@ uint32_t wvrunningcrc32(uint8_t* p_begin, int i_count, uint32_t i_crc) { return(i_crc); } -uint32_t wvcrc32(uint8_t* p_begin, int i_count) { +uint32_t wvcrc32(const uint8_t* p_begin, int i_count) { return(wvrunningcrc32(p_begin, i_count, INIT_CRC32)); } + +uint32_t wvcrc32n(const uint8_t* p_begin, int i_count) { + return htonl(wvrunningcrc32(p_begin, i_count, INIT_CRC32)); +} diff --git a/libwvdrmengine/oemcrypto/mock/src/wvcrc32.h b/libwvdrmengine/oemcrypto/mock/src/wvcrc32.h index 94e3f7e9..cfafba46 100644 --- a/libwvdrmengine/oemcrypto/mock/src/wvcrc32.h +++ b/libwvdrmengine/oemcrypto/mock/src/wvcrc32.h @@ -11,6 +11,8 @@ #include -uint32_t wvcrc32(uint8_t* p_begin, int i_count); +uint32_t wvcrc32(const uint8_t* p_begin, int i_count); +uint32_t wvcrc32n(const uint8_t* p_begin, int i_count); // Convert to network byte + // order. #endif // WV_CRC_32_H_ diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp index 1b386aa3..50db642c 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp @@ -31,9 +31,17 @@ using namespace std; namespace { const size_t kNumKeys = 4; -const size_t kDuration = 2; -const size_t kLongDuration = 5; const size_t kBufferMaxLength = 256; +#if defined(TEST_SPEED_MULTIPLIER) // Can slow test time limits when + // debugging is slowing everything. +const int kSpeedMultiplier = TEST_SPEED_MULTIPLIER1; +#else +const int kSpeedMultiplier = 1; +#endif +const int kShortSleep = 1 * kSpeedMultiplier; +const int kLongSleep = 2 * kSpeedMultiplier; +const uint32_t kDuration = 2 * kSpeedMultiplier; +const uint32_t kLongDuration = 5 * kSpeedMultiplier; } namespace wvoec { @@ -320,7 +328,7 @@ static const uint8_t kTestPKCS1RSAPrivateKey2_2048[] = { 0x39, 0x28, 0x33, 0xe0, 0xdb, 0x03 }; // 2048 bit RSA key in PKCS#8 PrivateKeyInfo -static const char kTestRSAPKCS8PrivateKeyInfo2_2048[] = { +static const uint8_t kTestRSAPKCS8PrivateKeyInfo2_2048[] = { 0x30, 0x82, 0x04, 0xbc, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, @@ -662,7 +670,7 @@ static const uint8_t kTestPKCS1RSAPrivateKey3_2048[] = { 0x21, 0xdc, 0x86, 0x17, 0x6e, 0xc8, 0xee, 0x24 }; // 2048 bit RSA key in PKCS#8 PrivateKeyInfo -static const char kTestRSAPKCS8PrivateKeyInfo3_2048[] = { +static const uint8_t kTestRSAPKCS8PrivateKeyInfo3_2048[] = { 0x30, 0x82, 0x04, 0xbe, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, @@ -1014,7 +1022,7 @@ class Session { ASSERT_EQ(0, memcmp(&unencryptedData[0], outputBuffer, unencryptedData.size())); - sleep(1); // Should still be valid key. + sleep(kShortSleep); // Should still be valid key. memset(outputBuffer, 0, sizeof(outputBuffer)); destBuffer.type = OEMCrypto_BufferType_Clear; @@ -1030,7 +1038,7 @@ class Session { ASSERT_EQ(0, memcmp(&unencryptedData[0], outputBuffer, unencryptedData.size())); - sleep(3); // Should be after first expiration. + sleep(kShortSleep + kLongSleep); // Should be after first expiration. memset(outputBuffer, 0, sizeof(outputBuffer)); destBuffer.type = OEMCrypto_BufferType_Clear; @@ -1398,7 +1406,11 @@ class OEMCryptoClientTest : public ::testing::Test { return !alive_; } - void testSetUp() { + void testSetUp() { // TODO(fredgc): Wha... + // All these tests should be using Setup() and Teardown() so that you + // don't need to call them manually... + // https://code.google.com/p/googletest/wiki/Primer#Test_Fixtures: + // _Using_the_Same_Data_Configuration_for_Multiple_Te init(); } @@ -1828,7 +1840,7 @@ TEST_F(DISABLED_TestKeybox, DefaultKeybox) { TEST_F(DISABLED_TestKeybox, BadCRCKeybox) { testSetUp(); wvoec_mock::WidevineKeybox keybox = kValidKeybox02; - keybox.crc_[1] = 42; + keybox.crc_[1] ^= 42; OEMCryptoResult sts; InstallKeybox(keybox, false); sts = OEMCrypto_IsKeyboxValid(); @@ -1838,7 +1850,7 @@ TEST_F(DISABLED_TestKeybox, BadCRCKeybox) { TEST_F(DISABLED_TestKeybox, BadMagicKeybox) { testSetUp(); wvoec_mock::WidevineKeybox keybox = kValidKeybox02; - keybox.magic_[1] = 42; + keybox.magic_[1] ^= 42; OEMCryptoResult sts; InstallKeybox(keybox, false); sts = OEMCrypto_IsKeyboxValid(); @@ -1848,7 +1860,7 @@ TEST_F(DISABLED_TestKeybox, BadMagicKeybox) { TEST_F(DISABLED_TestKeybox, BadDataKeybox) { testSetUp(); wvoec_mock::WidevineKeybox keybox = kValidKeybox02; - keybox.data_[1] = 42; + keybox.data_[1] ^= 42; OEMCryptoResult sts; InstallKeybox(keybox, false); sts = OEMCrypto_IsKeyboxValid(); @@ -2269,7 +2281,7 @@ TEST_F(DISABLED_TestKeybox, LoadKeysBadSignature) { const uint8_t* message_ptr = reinterpret_cast(&encrypted); s.FillKeyArray(encrypted, key_array); - signature[0] = 42; // Bad signature. + signature[0] ^= 42; // Bad signature. OEMCryptoResult sts = OEMCrypto_LoadKeys( s.session_id(), @@ -2363,7 +2375,7 @@ class DISABLED_RefreshKeyTest : public DISABLED_TestKeybox { s.LoadTestKeys(kDuration, wvoec_mock::kControlNonceEnabled, s.get_nonce()); uint32_t nonce; s.GenerateNonce(&nonce); - nonce = 42; + nonce ^= 42; s.RefreshTestKeys(key_count, wvoec_mock::kControlNonceEnabled, nonce, false); s.close(); @@ -2764,7 +2776,7 @@ TEST_F(DISABLED_TestKeybox, KeyDuration) { ASSERT_EQ(0, memcmp(&unencryptedData[0], outputBuffer, unencryptedData.size())); - sleep(1); // Should still be valid key. + sleep(kShortSleep); // Should still be valid key. memset(outputBuffer, 0, sizeof(outputBuffer)); destBuffer.type = OEMCrypto_BufferType_Clear; @@ -2780,7 +2792,7 @@ TEST_F(DISABLED_TestKeybox, KeyDuration) { ASSERT_EQ(0, memcmp(&unencryptedData[0], outputBuffer, unencryptedData.size())); - sleep(2); // Should be expired key. + sleep(kLongSleep); // Should be expired key. memset(outputBuffer, 0, sizeof(outputBuffer)); destBuffer.type = OEMCrypto_BufferType_Clear; @@ -2990,7 +3002,7 @@ TEST_F(DISABLED_TestKeybox, CertificateProvisionBadSignature) { &wrapped_key_length)); wrapped_key.clear(); wrapped_key.resize(wrapped_key_length); - signature[4] = 42; // bad signature. + signature[4] ^= 42; // bad signature. ASSERT_NE(OEMCrypto_SUCCESS, OEMCrypto_RewrapDeviceRSAKey(s.session_id(), message_ptr, sizeof(encrypted), &signature[0], @@ -3027,7 +3039,7 @@ TEST_F(DISABLED_TestKeybox, CertificateProvisionBadNonce) { &wrapped_key_length)); wrapped_key.clear(); wrapped_key.resize(wrapped_key_length); - encrypted.nonce = 42; // Almost surely a bad nonce. + encrypted.nonce ^= 42; // Almost surely a bad nonce. ASSERT_NE(OEMCrypto_SUCCESS, OEMCrypto_RewrapDeviceRSAKey(s.session_id(), message_ptr, sizeof(encrypted), &signature[0], @@ -3064,7 +3076,7 @@ TEST_F(DISABLED_TestKeybox, CertificateProvisionBadRSAKey) { &wrapped_key_length)); wrapped_key.clear(); wrapped_key.resize(wrapped_key_length); - encrypted.rsa_key[1] = 42; // Almost surely a bad key. + encrypted.rsa_key[1] ^= 42; // Almost surely a bad key. ASSERT_NE(OEMCrypto_SUCCESS, OEMCrypto_RewrapDeviceRSAKey(s.session_id(), message_ptr, sizeof(encrypted), &signature[0], @@ -3588,7 +3600,7 @@ TEST_F(DISABLED_GenericDRMTest, KeyDurationEncrypt) { unsigned int key_index = 0; uint8_t encrypted[kBufferSize]; - sleep(1); // Should still be valid key. + sleep(kShortSleep); // Should still be valid key. memset(encrypted, 0, kBufferSize); sts = OEMCrypto_SelectKey(s.session_id(), message_data_.keys[key_index].key_id, @@ -3599,8 +3611,7 @@ TEST_F(DISABLED_GenericDRMTest, KeyDurationEncrypt) { ASSERT_EQ(OEMCrypto_SUCCESS, sts); ASSERT_EQ(0, memcmp(encrypted, expected_encrypted, kBufferSize)); - - sleep(2); // Should be expired key. + sleep(kLongSleep); // Should be expired key. memset(encrypted, 0, kBufferSize); sts = OEMCrypto_Generic_Encrypt(s.session_id(), clear_buffer_, kBufferSize, iv_, @@ -3633,7 +3644,7 @@ TEST_F(DISABLED_GenericDRMTest, KeyDurationDecrypt) { ASSERT_EQ(OEMCrypto_SUCCESS, sts); uint8_t resultant[kBufferSize]; - sleep(1); // Should still be valid key. + sleep(kShortSleep); // Should still be valid key. memset(resultant, 0, kBufferSize); sts = OEMCrypto_Generic_Decrypt(s.session_id(), encrypted, kBufferSize, iv_, @@ -3641,7 +3652,7 @@ TEST_F(DISABLED_GenericDRMTest, KeyDurationDecrypt) { ASSERT_EQ(OEMCrypto_SUCCESS, sts); ASSERT_EQ(0, memcmp(clear_buffer_, resultant, kBufferSize)); - sleep(2); // Should be expired key. + sleep(kLongSleep); // Should be expired key. memset(resultant, 0, kBufferSize); sts = OEMCrypto_Generic_Decrypt(s.session_id(), encrypted, kBufferSize, iv_, @@ -3678,7 +3689,7 @@ TEST_F(DISABLED_GenericDRMTest, KeyDurationSign) { kTestKeyIdLength); ASSERT_EQ(OEMCrypto_SUCCESS, sts); - sleep(1); // Should still be valid key. + sleep(kShortSleep); // Should still be valid key. memset(signature, 0, SHA256_DIGEST_LENGTH); sts = OEMCrypto_Generic_Sign(s.session_id(), clear_buffer_, kBufferSize, @@ -3687,7 +3698,7 @@ TEST_F(DISABLED_GenericDRMTest, KeyDurationSign) { ASSERT_EQ(OEMCrypto_SUCCESS, sts); ASSERT_EQ(0, memcmp(signature, expected_signature, SHA256_DIGEST_LENGTH)); - sleep(2); // Should be expired key. + sleep(kLongSleep); // Should be expired key. memset(signature, 0, SHA256_DIGEST_LENGTH); sts = OEMCrypto_Generic_Sign(s.session_id(), clear_buffer_, kBufferSize, @@ -3722,14 +3733,14 @@ TEST_F(DISABLED_GenericDRMTest, KeyDurationVerify) { kTestKeyIdLength); ASSERT_EQ(OEMCrypto_SUCCESS, sts); - sleep(1); // Should still be valid key. + sleep(kShortSleep); // Should still be valid key. sts = OEMCrypto_Generic_Verify(s.session_id(), clear_buffer_, kBufferSize, OEMCrypto_HMAC_SHA256,signature, SHA256_DIGEST_LENGTH); ASSERT_EQ(OEMCrypto_SUCCESS, sts); - sleep(2); // Should be expired key. + sleep(kLongSleep); // Should be expired key. sts = OEMCrypto_Generic_Verify(s.session_id(), clear_buffer_, kBufferSize, OEMCrypto_HMAC_SHA256,signature,