-
Notifications
You must be signed in to change notification settings - Fork 162
Extend ClientConfig to allow for setting key_log #308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,14 @@ | ||
| #[cfg(feature = "rustls-native-certs")] | ||
| use std::io; | ||
| use std::sync::Arc; | ||
|
|
||
| #[cfg(any( | ||
| feature = "rustls-platform-verifier", | ||
| feature = "rustls-native-certs", | ||
| feature = "webpki-roots" | ||
| ))] | ||
| use rustls::client::WantsClientCert; | ||
| use rustls::{ClientConfig, ConfigBuilder, WantsVerifier}; | ||
| use rustls::{ClientConfig, ConfigBuilder, KeyLog, KeyLogFile, WantsVerifier}; | ||
| #[cfg(feature = "rustls-native-certs")] | ||
| use rustls_native_certs::CertificateResult; | ||
| #[cfg(feature = "rustls-platform-verifier")] | ||
|
|
@@ -125,6 +126,37 @@ impl ConfigBuilderExt for ConfigBuilder<ClientConfig, WantsVerifier> { | |
| } | ||
| } | ||
|
|
||
| /// Methods for enabling TLS key logging on a `ClientConfig`. | ||
| /// | ||
| /// This sets `config.key_log` to a `KeyLogFile` which writes | ||
| /// to the path in the `SSLKEYLOGFILE` env var (if set). If the variable is | ||
| /// not set, it becomes a no-op. | ||
|
||
| pub trait ClientConfigKeyLogExt { | ||
| /// Replace the `key_log` sink with a custom implementation. | ||
| fn with_key_log(self, key_log: Arc<dyn KeyLog>) -> Self; | ||
|
|
||
| // Enable NSS-style key logging to the file named by `SSLKEYLOGFILE`. | ||
| /// | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe worth using the word "replace" somewhere here similar to the other fn to emphasize if you call |
||
| /// If `SSLKEYLOGFILE` is unset, this is a no-op (matches `rustls`’ behavior). | ||
| fn with_key_log_file(self) -> Self; | ||
| } | ||
|
|
||
| impl ClientConfigKeyLogExt for ClientConfig { | ||
| fn with_key_log(mut self, key_log: Arc<dyn KeyLog>) -> Self { | ||
| self.key_log = key_log; | ||
|
|
||
| self | ||
| } | ||
|
|
||
| fn with_key_log_file(mut self) -> Self { | ||
| // `KeyLogFile::new()` internally reads SSLKEYLOGFILE and either opens the file | ||
| // or becomes a sink that does nothing. Safe to enable unconditionally. | ||
| self.key_log = Arc::new(KeyLogFile::new()); | ||
|
|
||
| self | ||
| } | ||
| } | ||
|
|
||
| mod sealed { | ||
| use super::*; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be tempted to put a warning after this headline similar to the one the Rusts docs have for
KeyLogto emphasize this should be used carefully: