Skip to content

Commit 6378802

Browse files
Expose TLS error to Subscribers using on_tls_handshake_failed
This allows propagating out the Display/Debug impl for the error, rather than just the &'static str we can capture into s2n-quic-transport's Errors.
1 parent 73c9278 commit 6378802

File tree

10 files changed

+33
-10
lines changed

10 files changed

+33
-10
lines changed

quic/s2n-quic-core/events/connection.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ struct TlsExporterReady<'a> {
345345
#[event("connectivity:tls_handshake_failed")]
346346
struct TlsHandshakeFailed<'a> {
347347
session: crate::event::TlsSession<'a>,
348+
error: &'a (dyn core::error::Error + Send + Sync + 'static),
348349
}
349350

350351
#[event("connectivity:path_challenge_updated")]

quic/s2n-quic-core/src/crypto/tls.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ pub trait Context<Crypto: crate::crypto::CryptoSuite> {
166166
fn on_tls_handshake_failed(
167167
&mut self,
168168
session: &impl TlsSession,
169+
error: &(dyn core::error::Error + Send + Sync + 'static),
169170
) -> Result<(), crate::transport::Error>;
170171

171172
/// Receives data from the initial packet space

quic/s2n-quic-core/src/crypto/tls/offload.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ pub trait Executor {
2121

2222
/// Allows access to the TlsSession on handshake failure and when the exporter secret is ready.
2323
pub trait ExporterHandler {
24-
fn on_tls_handshake_failed(&self, session: &impl TlsSession) -> Option<Box<dyn Any + Send>>;
24+
fn on_tls_handshake_failed(
25+
&self,
26+
session: &impl TlsSession,
27+
e: &(dyn core::error::Error + Send + Sync + 'static),
28+
) -> Option<Box<dyn Any + Send>>;
2529
fn on_tls_exporter_ready(&self, session: &impl TlsSession) -> Option<Box<dyn Any + Send>>;
2630
}
2731

@@ -30,6 +34,7 @@ impl ExporterHandler for () {
3034
fn on_tls_handshake_failed(
3135
&self,
3236
_session: &impl TlsSession,
37+
_e: &(dyn core::error::Error + Send + Sync + 'static),
3338
) -> Option<Box<dyn std::any::Any + Send>> {
3439
None
3540
}
@@ -559,8 +564,9 @@ impl<S: CryptoSuite, H: ExporterHandler> tls::Context<S> for RemoteContext<'_, R
559564
fn on_tls_handshake_failed(
560565
&mut self,
561566
session: &impl tls::TlsSession,
567+
e: &(dyn core::error::Error + Send + Sync + 'static),
562568
) -> Result<(), crate::transport::Error> {
563-
if let Some(context) = self.exporter_handler.on_tls_handshake_failed(session) {
569+
if let Some(context) = self.exporter_handler.on_tls_handshake_failed(session, e) {
564570
match self.send_to_quic.push(Request::TlsContext(context)) {
565571
Ok(_) => (),
566572
Err(_) => self.error = Some(SLICE_ERROR),

quic/s2n-quic-core/src/crypto/tls/slow_tls.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@ where
167167
fn on_tls_handshake_failed(
168168
&mut self,
169169
session: &impl tls::TlsSession,
170+
e: &(dyn core::error::Error + Send + Sync + 'static),
170171
) -> Result<(), transport::Error> {
171-
self.0.on_tls_exporter_ready(session)
172+
self.0.on_tls_handshake_failed(session, e)
172173
}
173174

174175
fn receive_initial(&mut self, max_len: Option<usize>) -> Option<tls::Bytes> {

quic/s2n-quic-core/src/crypto/tls/testing.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,7 @@ where
779779
fn on_tls_handshake_failed(
780780
&mut self,
781781
_: &impl super::TlsSession,
782+
_: &(dyn std::error::Error + Send + Sync),
782783
) -> Result<(), crate::transport::Error> {
783784
Ok(())
784785
}

quic/s2n-quic-core/src/event.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,14 @@ ident_into_event!(
6666
connection::Error,
6767
endpoint::Location,
6868
);
69-
borrowed_into_event!([u8; 4], [u8; 16], [u8], [u32], [&'a [u8]]);
69+
borrowed_into_event!(
70+
[u8; 4],
71+
[u8; 16],
72+
[u8],
73+
[u32],
74+
[&'a [u8]],
75+
(dyn core::error::Error + Send + Sync + 'static)
76+
);
7077

7178
impl<T: IntoEvent<U>, U> IntoEvent<Option<U>> for Option<T> {
7279
#[inline]

quic/s2n-quic-core/src/event/generated.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,12 +2468,14 @@ pub mod api {
24682468
#[non_exhaustive]
24692469
pub struct TlsHandshakeFailed<'a> {
24702470
pub session: crate::event::TlsSession<'a>,
2471+
pub error: &'a (dyn core::error::Error + Send + Sync + 'static),
24712472
}
24722473
#[cfg(any(test, feature = "testing"))]
24732474
impl<'a> crate::event::snapshot::Fmt for TlsHandshakeFailed<'a> {
24742475
fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
24752476
let mut fmt = fmt.debug_struct("TlsHandshakeFailed");
24762477
fmt.field("session", &self.session);
2478+
fmt.field("error", &self.error);
24772479
fmt.finish()
24782480
}
24792481
}
@@ -4132,8 +4134,8 @@ pub mod tracing {
41324134
event: &api::TlsHandshakeFailed,
41334135
) {
41344136
let id = context.id();
4135-
let api::TlsHandshakeFailed { session } = event;
4136-
tracing :: event ! (target : "tls_handshake_failed" , parent : id , tracing :: Level :: DEBUG , { session = tracing :: field :: debug (session) });
4137+
let api::TlsHandshakeFailed { session, error } = event;
4138+
tracing :: event ! (target : "tls_handshake_failed" , parent : id , tracing :: Level :: DEBUG , { session = tracing :: field :: debug (session) , error = tracing :: field :: debug (error) });
41374139
}
41384140
#[inline]
41394141
fn on_path_challenge_updated(
@@ -6300,13 +6302,15 @@ pub mod builder {
63006302
#[derive(Clone, Debug)]
63016303
pub struct TlsHandshakeFailed<'a> {
63026304
pub session: crate::event::TlsSession<'a>,
6305+
pub error: &'a (dyn core::error::Error + Send + Sync + 'static),
63036306
}
63046307
impl<'a> IntoEvent<api::TlsHandshakeFailed<'a>> for TlsHandshakeFailed<'a> {
63056308
#[inline]
63066309
fn into_event(self) -> api::TlsHandshakeFailed<'a> {
6307-
let TlsHandshakeFailed { session } = self;
6310+
let TlsHandshakeFailed { session, error } = self;
63086311
api::TlsHandshakeFailed {
63096312
session: session.into_event(),
6313+
error: error.into_event(),
63106314
}
63116315
}
63126316
}

quic/s2n-quic-rustls/src/session.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,8 @@ impl tls::Session for Session {
381381
context: &mut C,
382382
) -> Poll<Result<(), transport::Error>> {
383383
let result = self.poll_impl(context);
384-
if let Poll::Ready(Err(_)) = &result {
385-
context.on_tls_handshake_failed(self)?;
384+
if let Poll::Ready(Err(e)) = &result {
385+
context.on_tls_handshake_failed(self, e)?;
386386
}
387387
// attempt to emit server_name and application_protocol events prior to possibly
388388
// returning with an error

quic/s2n-quic-tls/src/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl tls::Session for Session {
162162
Poll::Ready(Ok(()))
163163
}
164164
Poll::Ready(Err(e)) => {
165-
context.on_tls_handshake_failed(self)?;
165+
context.on_tls_handshake_failed(self, &e)?;
166166

167167
Poll::Ready(Err(e
168168
.alert()

quic/s2n-quic-transport/src/space/session_context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,10 +570,12 @@ impl<Config: endpoint::Config, Pub: event::ConnectionPublisher>
570570
fn on_tls_handshake_failed(
571571
&mut self,
572572
session: &impl tls::TlsSession,
573+
e: &(dyn std::error::Error + Send + Sync + 'static),
573574
) -> Result<(), transport::Error> {
574575
self.publisher
575576
.on_tls_handshake_failed(event::builder::TlsHandshakeFailed {
576577
session: s2n_quic_core::event::TlsSession::new(session),
578+
error: e,
577579
});
578580
Ok(())
579581
}

0 commit comments

Comments
 (0)