There were no new changes to the OEMCrypto code. However, the ODK library changed, so we rolled the minor version number to 3. The ODK library was updated to support a nonce-free offline license. An offline license would not require a nonce if, for example, it is preloaded onto the device and does not have an entry in the usage table. Also, the following unit tests have been updated: 1. Various tests: Keys are not derived if they are not used. This is more in line with the “OEMCrypto state” diagram below. 2. The decrypt hash is not verified when there are multiple samples or no key is selected. 3. LoadKeyWithNoRequest. A nonce-free license is loaded in a session that did not sign the request. (Requires 16.3 ODK library) 4. RefreshLargeBuffer. The renewal message was set to the large size. Previously, only the license request was set to the larger size. 5. OEMCryptoGenericCryptoTest.*LargeBuffer. The correct buffer size is now being used. 6. ShrinkOverOpenSessions: The correct error code OEMCrypto_ERROR_ENTRY_IN_USE is now verified. 7. TimeRollbackPrevention: The test was refactored and fixed. Comments were added.
76 lines
2.8 KiB
C++
76 lines
2.8 KiB
C++
// Copyright 2019 Google LLC. All Rights Reserved. This file and proprietary
|
|
// source code may only be used and distributed under the Widevine Master
|
|
// License Agreement.
|
|
//
|
|
// TestSleep - Controls sleep and clock adjustment during tests.
|
|
//
|
|
#ifndef WVCDM_UTIL_TEST_SLEEP_H_
|
|
#define WVCDM_UTIL_TEST_SLEEP_H_
|
|
|
|
#include <stdint.h>
|
|
|
|
namespace wvcdm {
|
|
|
|
class TestSleep {
|
|
public:
|
|
// The callback is called when the clock should be advanced.
|
|
class CallBack {
|
|
public:
|
|
virtual void ElapseTime(int64_t milliseconds) = 0;
|
|
|
|
protected:
|
|
virtual ~CallBack(){};
|
|
};
|
|
|
|
// If real_sleep_ is true, then this sleeps for |seconds| of time. If
|
|
// real_sleep_ is false, then the fake clock is advanced by |seconds|. If the
|
|
// callback exists, this calls the callback.
|
|
static void Sleep(unsigned int seconds);
|
|
|
|
// If we are using a real clock and a fake clock, then the real clock advances
|
|
// a little while we are doing work, but the fake one only advances when we
|
|
// sleep. This function advances the fake clock to be in sync with the real
|
|
// clock. This function should be called to prevent a slow flaky test from
|
|
// failing due to this drift.
|
|
static void SyncFakeClock();
|
|
|
|
// Roll the system clock back by |seconds|. Returns true on success. A well
|
|
// mannered test will call CanChangeSystemTime before attempting to call this
|
|
// function and then assert that this is true. This function should *NOT* roll
|
|
// back the clock used by OEMCrypto -- in fact, there are several tests that
|
|
// verify this function does not roll back the clock used by OEMCrypto.
|
|
static bool RollbackSystemTime(int seconds);
|
|
|
|
// Roll the system clock forward to undo all previous calls to
|
|
// RollBackSystemTime. Returns true on success.
|
|
static bool ResetRollback() {
|
|
return total_clock_rollback_ == 0 ||
|
|
RollbackSystemTime(-total_clock_rollback_);
|
|
}
|
|
|
|
// Returns true if the system time can be rolled back. This is true on some
|
|
// devices if the tests are run as root. It is also true when using a fake
|
|
// clock with the reference version of OEMCrypto. This function is about the
|
|
// system clock, *NOT* the clock used by OEMCrypto.
|
|
static bool CanChangeSystemTime();
|
|
|
|
static void set_real_sleep(bool real_sleep) { real_sleep_ = real_sleep; }
|
|
static bool real_sleep() { return real_sleep_; }
|
|
|
|
// The callback is notified whenever sleep is called.
|
|
static void set_callback(CallBack* callback) { callback_ = callback; }
|
|
|
|
private:
|
|
// Controls if the test sleep should use real sleep.
|
|
static bool real_sleep_;
|
|
// Called when the clock should advance.
|
|
static CallBack* callback_;
|
|
// The sum of all calls to RollBackSystemTime. Kept so we can undo all changes
|
|
// at the end of a test.
|
|
static int total_clock_rollback_;
|
|
};
|
|
|
|
} // namespace wvcdm
|
|
|
|
#endif // WVCDM_UTIL_TEST_SLEEP_H_
|