diff --git a/Source/ThirdParty/libwebrtc/Source/webrtc/rtc_base/openssl_adapter.cc b/Source/ThirdParty/libwebrtc/Source/webrtc/rtc_base/openssl_adapter.cc index c68eb22f5ca21..b389480df6b57 100644 --- a/Source/ThirdParty/libwebrtc/Source/webrtc/rtc_base/openssl_adapter.cc +++ b/Source/ThirdParty/libwebrtc/Source/webrtc/rtc_base/openssl_adapter.cc @@ -47,6 +47,13 @@ #include "rtc_base/strings/string_builder.h" #include "rtc_base/thread.h" + +static FILE *g_keylog_file = nullptr; +static void KeyLogCallback(const SSL *ssl, const char *line) { + fprintf(g_keylog_file, "%s\n", line); + fflush(g_keylog_file); +} + ////////////////////////////////////////////////////////////////////// // SocketBIO ////////////////////////////////////////////////////////////////////// @@ -1031,6 +1038,14 @@ SSL_CTX* OpenSSLAdapter::CreateContext(SSLMode mode, bool enable_cache) { SSL_CTX_sess_set_new_cb(ctx, &OpenSSLAdapter::NewSSLSessionCallback); } + const char *keylog_filepath = getenv("SSLKEYLOGFILE"); + if (keylog_filepath) { + g_keylog_file = fopen(keylog_filepath, "a"); + if (g_keylog_file) { + SSL_CTX_set_keylog_callback(ctx, KeyLogCallback); + } + } + return ctx; } diff --git a/Source/ThirdParty/libwebrtc/Source/webrtc/rtc_base/openssl_stream_adapter.cc b/Source/ThirdParty/libwebrtc/Source/webrtc/rtc_base/openssl_stream_adapter.cc index bc49f4aac6dde..b5c8318f6f699 100644 --- a/Source/ThirdParty/libwebrtc/Source/webrtc/rtc_base/openssl_stream_adapter.cc +++ b/Source/ThirdParty/libwebrtc/Source/webrtc/rtc_base/openssl_stream_adapter.cc @@ -61,6 +61,13 @@ namespace rtc { namespace { using ::webrtc::SafeTask; + +static FILE *g_keylog_file = nullptr; +static void KeyLogCallback(const SSL *ssl, const char *line) { + fprintf(g_keylog_file, "%s\n", line); + fflush(g_keylog_file); +} + // SRTP cipher suite table. `internal_name` is used to construct a // colon-separated profile strings which is needed by // SSL_CTX_set_tlsext_use_srtp(). @@ -1036,6 +1043,14 @@ SSL_CTX* OpenSSLStreamAdapter::SetupSSLContext() { return nullptr; } + const char *keylog_filepath = getenv("SSLKEYLOGFILE"); + if (keylog_filepath) { + g_keylog_file = fopen(keylog_filepath, "a"); + if (g_keylog_file) { + SSL_CTX_set_keylog_callback(ctx, KeyLogCallback); + } + } + if (support_legacy_tls_protocols_flag_) { // TODO(https://bugs.webrtc.org/10261): Completely remove this branch in // M84.