From 4733167f914c5fc27b138f6cca414d7addcb1729 Mon Sep 17 00:00:00 2001 From: Lucas Pardue Date: Thu, 3 Oct 2019 16:24:36 +0100 Subject: [PATCH] Add SSLKEYLOGFILE support --- src/h2load.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/h2load.cc b/src/h2load.cc index 9654a295..ebb7ec24 100644 --- a/src/h2load.cc +++ b/src/h2load.cc @@ -75,6 +75,15 @@ bool recorded(const std::chrono::steady_clock::time_point &t) { } } // namespace +namespace { +std::ofstream keylog_file; +void keylog_callback(const SSL *ssl, const char *line) { + keylog_file.write(line, strlen(line)); + keylog_file.put('\n'); + keylog_file.flush(); +} +} // namespace + Config::Config() : ciphers(tls::DEFAULT_CIPHER_LIST), tls13_ciphers("TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_" @@ -2723,6 +2732,14 @@ int main(int argc, char **argv) { SSL_CTX_set_alpn_protos(ssl_ctx, proto_list.data(), proto_list.size()); #endif // OPENSSL_VERSION_NUMBER >= 0x10002000L + auto keylog_filename = getenv("SSLKEYLOGFILE"); + if (keylog_filename) { + keylog_file.open(keylog_filename, std::ios_base::app); + if (keylog_file) { + SSL_CTX_set_keylog_callback(ssl_ctx, keylog_callback); + } + } + std::string user_agent = "h2load nghttp2/" NGHTTP2_VERSION; Headers shared_nva; shared_nva.emplace_back(":scheme", config.scheme);