Source release v3.0.1 + third_party

This commit is contained in:
Joey Parrish
2015-09-11 16:15:34 -07:00
parent 0546ee6732
commit b5d6be97cb
32 changed files with 1344 additions and 129 deletions

View File

@@ -60,6 +60,7 @@ const int kShortSleep = 1 * kSpeedMultiplier;
const int kLongSleep = 2 * kSpeedMultiplier;
const uint32_t kDuration = 2 * kSpeedMultiplier;
const uint32_t kLongDuration = 5 * kSpeedMultiplier;
const int32_t kAlmostRange = 3 * kSpeedMultiplier;
} // namespace
typedef struct {
@@ -739,9 +740,9 @@ static void dump_openssl_error() {
}
// We don't expect exact timing.
#define EXPECT_ALMOST(A, B) \
EXPECT_GE(A + kSpeedMultiplier, B); \
EXPECT_LE(A - kSpeedMultiplier, B);
#define EXPECT_ALMOST(A, B) \
EXPECT_GE(A + kAlmostRange, B); \
EXPECT_LE(A - kAlmostRange, B);
class Session {
public:
@@ -768,7 +769,7 @@ class Session {
}
void open() {
EXPECT_TRUE(!open_);
EXPECT_FALSE(open_);
session_status_ = OEMCrypto_OpenSession(&session_id_);
if (OEMCrypto_SUCCESS == session_status_) {
open_ = true;
@@ -1386,7 +1387,7 @@ class Session {
vector<uint8_t> mac_context;
vector<uint8_t> enc_context;
FillDefaultContext(&mac_context, &enc_context);
ASSERT_EQ(OEMCrypto_ERROR_INVALID_RSA_KEY,
ASSERT_NE(OEMCrypto_SUCCESS,
OEMCrypto_DeriveKeysFromSessionKey(
session_id(), &enc_session_key[0], enc_session_key.size(),
&mac_context[0], mac_context.size(), &enc_context[0],
@@ -1663,7 +1664,10 @@ TEST_F(OEMCryptoClientTest, MaxSessionsOpenCloseAPI10) {
// We expect OEMCrypto implementations support at least 8 sessions.
const size_t kMinimumSupportedMaxNumberOfSessions = 8u;
ASSERT_GE(max_sessions, kMinimumSupportedMaxNumberOfSessions);
// We allow GetMaxNumberOfSessions to return an estimate. This tests with a
// pad of 5%. Even if it's just an estimate, we still require 8 sessions.
size_t max_sessions_with_pad = max(max_sessions * 19/20,
kMinimumSupportedMaxNumberOfSessions);
vector<OEMCrypto_SESSION> sessions;
// Limit the number of sessions for testing.
const size_t kMaxNumberOfSessionsForTesting = 0x100u;
@@ -1677,7 +1681,7 @@ TEST_F(OEMCryptoClientTest, MaxSessionsOpenCloseAPI10) {
// OEMCrypto_ERROR_TOO_MANY_SESSIONS if too many sessions are open.
if (sts != OEMCrypto_SUCCESS) {
ASSERT_EQ(OEMCrypto_ERROR_TOO_MANY_SESSIONS, sts);
ASSERT_GE(i, max_sessions);
ASSERT_GE(i, max_sessions_with_pad);
break;
}
ASSERT_EQ(OEMCrypto_SUCCESS,
@@ -2536,8 +2540,8 @@ TEST_F(OEMCryptoSessionTests, DecryptZeroDuration) {
class OEMCryptoSessionTestsDecryptEdgeCases : public OEMCryptoSessionTests {
public:
// Increment counter for AES-CTR. The CENC spec specifies we increment only
// the low 64 bits of the IV counter, and leave the high 64 bits alone. This is
// different from the OpenSSL implementation, so we implement the CTR loop
// the low 64 bits of the IV counter, and leave the high 64 bits alone. This
// is different from the OpenSSL implementation, so we implement the CTR loop
// ourselves.
void ctr128_inc64(int64_t increaseBy, uint8_t* iv) {
uint64_t* counterBuffer = reinterpret_cast<uint64_t*>(&iv[8]);
@@ -2688,6 +2692,15 @@ TEST_F(OEMCryptoSessionTestsDecryptEdgeCases, OddOffset) {
subsample_size);
}
// This tests that the algorithm used to increment the counter for
// AES-CTR mode is correct. There are two possible implementations:
// 1) increment the counter as if it were a 128 bit number,
// 2) increment the low 64 bits as a 64 bit number and leave the high bits alone.
// For CENC, the algorithm we should use is the second one. OpenSSL defaults to
// the first. If this test is not passing, you should look at the way you
// increment the counter. Look at the example code in ctr128_inc64 above.
// If you start with an IV of 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE, after you
// increment twice, you should get 0xFFFFFFFFFFFFFFFF0000000000000000.
TEST_F(OEMCryptoSessionTestsDecryptEdgeCases, DecryptWithNearWrap) {
vector<size_t> subsample_size;
subsample_size.push_back(150);
@@ -3410,7 +3423,6 @@ class OEMCryptoCastReceiverTest : public OEMCryptoLoadsCertificateAlternates {
vector<uint8_t> field_e = encode(0x02, wvcdm::a2b_hex("010001"));
vector<uint8_t> field_d =
encode(0x02, wvcdm::a2b_hex(
"00"
"5bd910257830dce17520b03441a51a8c"
"ab94020ac6ecc252c808f3743c95b7c8"
"3b8c8af1a5014346ebc4242cdfb5d718"
@@ -3462,7 +3474,6 @@ class OEMCryptoCastReceiverTest : public OEMCryptoLoadsCertificateAlternates {
"0dcbbc9b528f64a01706e05b0b91106f"));
vector<uint8_t> field_exp2 =
encode(0x02, wvcdm::a2b_hex(
"00"
"6827924a85e88b55ba00f8219128bd37"
"24c6b7d1dfe5629ef197925fecaff5ed"
"b9cdf3a7befd8ea2e8dd3707138b3ff8"
@@ -3473,7 +3484,6 @@ class OEMCryptoCastReceiverTest : public OEMCryptoLoadsCertificateAlternates {
"eec82d7f5458ec19e71b90eeef7dff61"));
vector<uint8_t> field_invq =
encode(0x02, wvcdm::a2b_hex(
"00"
"57b73888d183a99a6307422277551a3d"
"9e18adf06a91e8b55ceffef9077c8496"
"948ecb3b16b78155cb2a3a57c119d379"
@@ -5424,6 +5434,11 @@ TEST_P(UsageTableTestWithMAC, ReloadOfflineLicense) {
Session s;
LoadOfflineLicense(s, pst);
// If there are errors in LoadOfflineLicense, that function will exit but this
// test will continue. The session will be left open and in an unknown state.
// Best just to abort in that case.
ASSERT_FALSE(s.isOpen()) << "LoadOfflineLicense() failed. Aborting.";
s.open(); // Offline license can be reused.
s.GenerateTestSessionKeys();
// We will reuse the encrypted and signed message, so we don't call
@@ -5452,6 +5467,11 @@ TEST_P(UsageTableTestWithMAC, BadReloadOfflineLicense) {
Session s;
LoadOfflineLicense(s, pst);
// If there are errors in LoadOfflineLicense, that function will exit but this
// test will continue. The session will be left open and in an unknown state.
// Best just to abort in that case.
ASSERT_FALSE(s.isOpen()) << "LoadOfflineLicense() failed. Aborting.";
// Offline license with new mac keys should fail.
Session s2;
s2.open();
@@ -5523,6 +5543,11 @@ TEST_P(UsageTableTestWithMAC, DeactivateOfflineLicense) {
Session s;
LoadOfflineLicense(s, pst);
// If there are errors in LoadOfflineLicense, that function will exit but this
// test will continue. The session will be left open and in an unknown state.
// Best just to abort in that case.
ASSERT_FALSE(s.isOpen()) << "LoadOfflineLicense() failed. Aborting.";
s.open();
s.GenerateTestSessionKeys();
s.LoadTestKeys(pst, new_mac_keys_); // Reload the license
@@ -5589,6 +5614,13 @@ TEST_F(UsageTableTest, TimingTest) {
LoadOfflineLicense(s3, pst3);
time_t loaded3 = time(NULL);
// If there are errors in LoadOfflineLicense, that function will exit but this
// test will continue. The sessions will be left open and in an unknown state.
// Best just to abort in that case.
ASSERT_FALSE(s1.isOpen()) << "LoadOfflineLicense() failed. Aborting.";
ASSERT_FALSE(s2.isOpen()) << "LoadOfflineLicense() failed. Aborting.";
ASSERT_FALSE(s3.isOpen()) << "LoadOfflineLicense() failed. Aborting.";
sleep(kLongSleep);
s1.open();
s1.GenerateTestSessionKeys();