Chromium Code Reviews| Index: webrtc/base/opensslstreamadapter.cc |
| diff --git a/webrtc/base/opensslstreamadapter.cc b/webrtc/base/opensslstreamadapter.cc |
| index 5a7560e112584995044b2c22a2804ed04ec752b5..80a325530e5b4f8363eaa13c9e227869565d0443 100644 |
| --- a/webrtc/base/opensslstreamadapter.cc |
| +++ b/webrtc/base/opensslstreamadapter.cc |
| @@ -38,6 +38,10 @@ |
| #include "webrtc/base/timeutils.h" |
| #include "webrtc/base/thread.h" |
| +namespace { |
| + bool g_use_time_callback_for_testing = false; |
| +} |
| + |
| namespace rtc { |
| #if (OPENSSL_VERSION_NUMBER >= 0x10001000L) |
| @@ -63,7 +67,8 @@ static SrtpCipherMapEntry SrtpCipherMap[] = { |
| #endif |
| #ifdef OPENSSL_IS_BORINGSSL |
| -static void TimeCallback(const SSL* ssl, struct timeval* out_clock) { |
| +// Not used in production code. Actual time should be relative to Jan 1, 1970. |
| +static void TimeCallbackForTesting(const SSL* ssl, struct timeval* out_clock) { |
|
pthatcher1
2016/11/29 00:32:40
FakeClockTimeCallback?
|
| uint64_t time = TimeNanos(); |
| out_clock->tv_sec = time / kNumNanosecsPerSec; |
| out_clock->tv_usec = (time % kNumNanosecsPerSec) / kNumNanosecsPerMicrosec; |
| @@ -1059,10 +1064,9 @@ SSL_CTX* OpenSSLStreamAdapter::SetupSSLContext() { |
| DTLS1_2_VERSION : TLS1_2_VERSION); |
| break; |
| } |
| - // Set a time callback for BoringSSL because: |
| - // 1. Our time function is more accurate (doesn't just use gettimeofday). |
| - // 2. This allows us to inject a fake clock for testing. |
| - SSL_CTX_set_current_time_cb(ctx, &TimeCallback); |
| + if (g_use_time_callback_for_testing) { |
| + SSL_CTX_set_current_time_cb(ctx, &TimeCallbackForTesting); |
| + } |
| #endif |
| if (identity_ && !identity_->ConfigureIdentity(ctx)) { |
| @@ -1263,6 +1267,10 @@ bool OpenSSLStreamAdapter::IsAcceptableCipher(const std::string& cipher, |
| return false; |
| } |
| +void OpenSSLStreamAdapter::enable_time_callback_for_testing() { |
| + g_use_time_callback_for_testing = true; |
|
pthatcher1
2016/11/29 00:32:40
g_use_fake_clock?
|
| +} |
| + |
| } // namespace rtc |
| #endif // HAVE_OPENSSL_SSL_H |