@@ -22,8 +22,8 @@ use pingora_error::{
2222} ;
2323use pingora_rustls:: {
2424 load_ca_file_into_store, load_certs_and_key_files, load_platform_certs_incl_env_into_store,
25- version, CertificateDer , ClientConfig as RusTlsClientConfig , PrivateKeyDer , RootCertStore ,
26- TlsConnector as RusTlsConnector ,
25+ version, CertificateDer , ClientConfig as RusTlsClientConfig , KeyLogFile , PrivateKeyDer ,
26+ RootCertStore , TlsConnector as RusTlsConnector ,
2727} ;
2828
2929use crate :: protocols:: tls:: { client:: handshake, TlsStream } ;
@@ -75,7 +75,6 @@ impl TlsConnector {
7575 if let Some ( ( cert, key) ) = conf. cert_key_file . as_ref ( ) {
7676 certs_key = load_certs_and_key_files ( cert, key) ?;
7777 }
78- // TODO: support SSLKEYLOGFILE
7978 } else {
8079 load_platform_certs_incl_env_into_store ( & mut ca_certs) ?;
8180 }
@@ -88,7 +87,7 @@ impl TlsConnector {
8887 RusTlsClientConfig :: builder_with_protocol_versions ( & [ & version:: TLS12 , & version:: TLS13 ] )
8988 . with_root_certificates ( ca_certs. clone ( ) ) ;
9089
91- let config = match certs_key {
90+ let mut config = match certs_key {
9291 Some ( ( certs, key) ) => {
9392 match builder. with_client_auth_cert ( certs. clone ( ) , key. clone_key ( ) ) {
9493 Ok ( config) => config,
@@ -102,6 +101,13 @@ impl TlsConnector {
102101 None => builder. with_no_client_auth ( ) ,
103102 } ;
104103
104+ // Enable SSLKEYLOGFILE support for debugging TLS traffic
105+ if let Some ( options) = options. as_ref ( ) {
106+ if options. debug_ssl_keylog {
107+ config. key_log = Arc :: new ( KeyLogFile :: new ( ) ) ;
108+ }
109+ }
110+
105111 Ok ( Connector {
106112 ctx : Arc :: new ( TlsConnector {
107113 config : Arc :: new ( config) ,
@@ -155,10 +161,12 @@ where
155161 . with_root_certificates ( Arc :: clone ( & tls_ctx. ca_certs ) ) ;
156162 debug ! ( "added root ca certificates" ) ;
157163
158- let updated_config = builder. with_client_auth_cert ( certs, private_key) . or_err (
164+ let mut updated_config = builder. with_client_auth_cert ( certs, private_key) . or_err (
159165 InvalidCert ,
160166 "Failed to use peer cert/key to update Rustls config" ,
161167 ) ?;
168+ // Preserve keylog setting from original config
169+ updated_config. key_log = Arc :: clone ( & config. key_log ) ;
162170 Some ( updated_config)
163171 }
164172 } ;
0 commit comments