summaryrefslogtreecommitdiffstats
path: root/src/tls.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/tls.cc')
-rw-r--r--src/tls.cc28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/tls.cc b/src/tls.cc
index 9babf2a..ad62c60 100644
--- a/src/tls.cc
+++ b/src/tls.cc
@@ -25,9 +25,11 @@
#include "tls.h"
#include <cassert>
+#include <cstring>
#include <vector>
#include <mutex>
#include <iostream>
+#include <fstream>
#include <openssl/crypto.h>
#include <openssl/conf.h>
@@ -176,6 +178,32 @@ int cert_decompress(SSL *ssl, CRYPTO_BUFFER **out, size_t uncompressed_len,
}
#endif // NGHTTP2_OPENSSL_IS_BORINGSSL && HAVE_LIBBROTLI
+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
+
+int setup_keylog_callback(SSL_CTX *ssl_ctx) {
+ auto keylog_filename = getenv("SSLKEYLOGFILE");
+ if (!keylog_filename) {
+ return 0;
+ }
+
+ keylog_file.open(keylog_filename, std::ios_base::app);
+ if (!keylog_file) {
+ return -1;
+ }
+
+ SSL_CTX_set_keylog_callback(ssl_ctx, keylog_callback);
+
+ return 0;
+}
+
} // namespace tls
} // namespace nghttp2