Skip to content
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

feat: has_peer_certificates #11

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ impl Debug for TlsStream {
pub struct TlsHandshake {
pub alpn: Option<Vec<u8>>,
pub sni: Option<String>,
/// For client-to-server connections, will always return true. For server-to-client connections, returns
/// true if the client provided a valid certificate.
pub has_peer_certificates: bool,
}

impl TlsStream {
Expand Down Expand Up @@ -126,14 +129,25 @@ impl TlsStream {
let res = handshake_task_internal(tcp_handshake, tls, test_options).await;
match &res {
Ok(res) => {
// TODO(mmastrac): we should expose peer certificates _somehow_, but we need to solve the copy
// problem.
let has_peer_certificates = res
.1
.peer_certificates()
.map(|c| !c.is_empty())
.unwrap_or_default();
let alpn = res.1.alpn_protocol().map(|v| v.to_owned());
let sni = match &res.1 {
Connection::Server(server) => {
server.server_name().map(|s| s.to_owned())
}
_ => None,
};
_ = tx.send(Some(Ok(TlsHandshake { alpn, sni })));
_ = tx.send(Some(Ok(TlsHandshake {
alpn,
sni,
has_peer_certificates,
})));
}
Err(err) => {
let kind = err.kind();
Expand Down