Updates to OEMCrytpo Mock

Squash merge from the widevine repo of several changes to oemcrypto
unit tests and the mock reference code.

http://go/wvgerrit/16264 Use unsigned int for count in usage table (more mock)
http://go/wvgerrit/16262 Use unsigned int for count in usage table (mock version)
http://go/wvgerrit/16247 Fix mock OEMCrypto_DeleteUsageTable
http://go/wvgerrit/16070 Fix OEMCrypto_GenerateRSASignature return values
http://go/wvgerrit/15991 Fix buffer overflow for 32-bit systems
http://go/wvgerrit/15993 Return Correct Value from OEMCrypto_RefreshKeys
http://go/wvgerrit/15880 Cast RSA_size() to int
http://go/wvgerrit/15831 Be strict about warnings for CE CDM

b/23729420
b/25221168

Change-Id: I97b91dfc672db8c586ae317977871b7d6afac4bb
This commit is contained in:
Fred Gylys-Colwell
2015-12-05 11:39:26 -08:00
parent 6886b1fa12
commit 6d7dcb8cba
7 changed files with 67 additions and 74 deletions

View File

@@ -678,7 +678,7 @@ class Session {
}
void RefreshTestKeys(const size_t key_count, uint32_t control_bits,
uint32_t nonce, bool expect_good) {
uint32_t nonce, OEMCryptoResult expected_result) {
// Note: we store the message in encrypted_license_, but the refresh key
// message is not actually encrypted. It is, however, signed.
FillRefreshMessage(key_count, control_bits, nonce);
@@ -688,17 +688,13 @@ class Session {
OEMCryptoResult sts = OEMCrypto_RefreshKeys(
session_id(), message_ptr(), sizeof(MessageData), &signature_[0],
signature_.size(), key_count, key_array);
if (expect_good) {
ASSERT_EQ(OEMCrypto_SUCCESS, sts);
} else {
ASSERT_NE(OEMCrypto_SUCCESS, sts);
}
ASSERT_EQ(expected_result, sts);
TestDecryptCTR();
sleep(kShortSleep); // Should still be valid key.
TestDecryptCTR(false);
sleep(kShortSleep + kLongSleep); // Should be after first expiration.
if (expect_good) {
if (expected_result == OEMCrypto_SUCCESS) {
TestDecryptCTR(false, OEMCrypto_SUCCESS);
} else {
TestDecryptCTR(false, OEMCrypto_ERROR_UNKNOWN_FAILURE);
@@ -2157,7 +2153,8 @@ TEST_P(SessionTestRefreshKeyTest, RefreshWithNonce) {
s.LoadTestKeys("", new_mac_keys_);
uint32_t nonce;
s.GenerateNonce(&nonce);
s.RefreshTestKeys(num_keys_, wvoec_mock::kControlNonceEnabled, nonce, true);
s.RefreshTestKeys(num_keys_, wvoec_mock::kControlNonceEnabled, nonce,
OEMCrypto_SUCCESS);
}
TEST_P(SessionTestRefreshKeyTest, RefreshNoNonce) {
@@ -2169,7 +2166,7 @@ TEST_P(SessionTestRefreshKeyTest, RefreshNoNonce) {
s.LoadTestKeys("", new_mac_keys_);
uint32_t nonce;
s.GenerateNonce(&nonce);
s.RefreshTestKeys(num_keys_, 0, 0, true);
s.RefreshTestKeys(num_keys_, 0, 0, OEMCrypto_SUCCESS);
}
TEST_P(SessionTestRefreshKeyTest, RefreshOldNonce) {
@@ -2181,7 +2178,8 @@ TEST_P(SessionTestRefreshKeyTest, RefreshOldNonce) {
s.EncryptAndSign();
s.LoadTestKeys("", new_mac_keys_);
uint32_t nonce = s.get_nonce();
s.RefreshTestKeys(num_keys_, wvoec_mock::kControlNonceEnabled, nonce, false);
s.RefreshTestKeys(num_keys_, wvoec_mock::kControlNonceEnabled, nonce,
OEMCrypto_ERROR_INVALID_NONCE);
}
TEST_P(SessionTestRefreshKeyTest, RefreshBadNonce) {
@@ -2195,7 +2193,8 @@ TEST_P(SessionTestRefreshKeyTest, RefreshBadNonce) {
uint32_t nonce;
s.GenerateNonce(&nonce);
nonce ^= 42;
s.RefreshTestKeys(num_keys_, wvoec_mock::kControlNonceEnabled, nonce, false);
s.RefreshTestKeys(num_keys_, wvoec_mock::kControlNonceEnabled, nonce,
OEMCrypto_ERROR_INVALID_NONCE);
}
// Of only one key control block in the refesh, we update all the keys.
@@ -5286,9 +5285,7 @@ TEST_P(UsageTableTestWithMAC, OfflineBadNonce) {
Session s;
s.open();
s.GenerateTestSessionKeys();
s.FillSimpleMessage(
0, wvoec_mock::kControlNonceEnabled | wvoec_mock::kControlNonceOrEntry,
42, pst);
s.FillSimpleMessage(0, wvoec_mock::kControlNonceOrEntry, 42, pst);
s.EncryptAndSign();
uint8_t* pst_ptr = s.encrypted_license().pst;
OEMCryptoResult sts = OEMCrypto_LoadKeys(
@@ -5306,9 +5303,7 @@ TEST_P(UsageTableTestWithMAC, OfflineEmptyPST) {
Session s;
s.open();
s.GenerateTestSessionKeys();
s.FillSimpleMessage(
0, wvoec_mock::kControlNonceEnabled | wvoec_mock::kControlNonceOrEntry,
s.get_nonce());
s.FillSimpleMessage(0, wvoec_mock::kControlNonceOrEntry, s.get_nonce());
s.EncryptAndSign();
OEMCryptoResult sts = OEMCrypto_LoadKeys(
s.session_id(), s.message_ptr(), sizeof(MessageData), &s.signature()[0],
@@ -5368,8 +5363,7 @@ TEST_P(UsageTableTestWithMAC, BadRange) {
Session s;
s.open();
s.GenerateTestSessionKeys();
s.FillSimpleMessage(0, wvoec_mock::kControlNonceOrEntry,
s.get_nonce(), pst);
s.FillSimpleMessage(0, wvoec_mock::kControlNonceOrEntry,s.get_nonce(), pst);
s.EncryptAndSign();
uint8_t* pst_ptr = s.license().pst; // Bad: not in encrypted_license.
ASSERT_NE(