Skip to content

Commit

Permalink
wolfssl: tests: Use keylogger if debug is enabled.
Browse files Browse the repository at this point in the history
e.g.
```console
$ cargo test --features debug --test ping_pong -- --nocapture
```
  • Loading branch information
xv-ian-c committed Nov 9, 2023
1 parent 526660c commit f08dbd0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions wolfssl/tests/ping_pong.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![deny(unsafe_code)] // unsafety should all be in the library.

#[cfg(feature = "debug")]
use wolfssl::Tls13SecretCallbacks;
use wolfssl::{
ContextBuilder, IOCallbacks, Protocol, ProtocolVersion, RootCertificate, Secret, SessionConfig,
};
Expand Down Expand Up @@ -102,6 +104,16 @@ impl SockIO for tokio::net::UnixStream {
}
}

#[cfg(feature = "debug")]
struct KeyLogger;

#[cfg(feature = "debug")]
impl Tls13SecretCallbacks for KeyLogger {
fn wireshark_keylog(&self, secret: String) {
eprintln!("{}", secret);
}
}

async fn client<S: SockIO>(sock: S, protocol: Protocol, exp_protocol_version: ProtocolVersion) {
let sock = std::rc::Rc::new(sock);

Expand All @@ -115,6 +127,10 @@ async fn client<S: SockIO>(sock: S, protocol: Protocol, exp_protocol_version: Pr

let io = SockIOCallbacks(sock);
let session_config = SessionConfig::new(io.clone()).with_dtls_nonblocking(true);

#[cfg(feature = "debug")]
let session_config = session_config.with_key_logger(std::sync::Arc::new(KeyLogger));

let session = ctx
.new_session(session_config)
.expect("[Client] Create Client SSL session");
Expand Down

0 comments on commit f08dbd0

Please sign in to comment.