Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Unified Diff: webrtc/base/opensslstreamadapter.cc

Issue 2526433002: Only use BoringSSL time callback in unit tests. (Closed)
Patch Set: Merging with master. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/base/opensslstreamadapter.h ('k') | webrtc/base/sslstreamadapter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/opensslstreamadapter.cc
diff --git a/webrtc/base/opensslstreamadapter.cc b/webrtc/base/opensslstreamadapter.cc
index 6943cd32ff0e495ea0a7e7d5b4980be714b56637..873f7b1398749d3d27fe420583abe1fc06bd8493 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) {
int64_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;
+}
+
} // namespace rtc
#endif // HAVE_OPENSSL_SSL_H
« no previous file with comments | « webrtc/base/opensslstreamadapter.h ('k') | webrtc/base/sslstreamadapter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698