Skip to content

Commit c5f139c

Browse files
Expose TLS error to Subscribers using on_tls_handshake_failed (#2855)
1 parent 6aa5933 commit c5f139c

File tree

24 files changed

+47
-33
lines changed

24 files changed

+47
-33
lines changed

dc/s2n-quic-dc/src/stream/recv/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl fmt::Display for Error {
3737
}
3838
}
3939

40-
impl std::error::Error for Error {}
40+
impl core::error::Error for Error {}
4141

4242
impl IntoEvent<Error> for Error {
4343
fn into_event(self) -> Error {

dc/s2n-quic-dc/src/stream/send/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl fmt::Display for Error {
3434
}
3535
}
3636

37-
impl std::error::Error for Error {}
37+
impl core::error::Error for Error {}
3838

3939
impl IntoEvent<Error> for Error {
4040
fn into_event(self) -> Error {

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/application/error.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ use core::{fmt, ops};
1818
#[derive(Copy, Clone, Eq, PartialEq)]
1919
pub struct Error(VarInt);
2020

21-
#[cfg(feature = "std")]
22-
impl std::error::Error for Error {}
21+
impl core::error::Error for Error {}
2322

2423
impl fmt::Debug for Error {
2524
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

quic/s2n-quic-core/src/buffer/deque.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,7 @@ impl fmt::Display for FillError {
225225
}
226226
}
227227

228-
#[cfg(feature = "std")]
229-
impl std::error::Error for FillError {}
228+
impl core::error::Error for FillError {}
230229

231230
#[cfg(feature = "std")]
232231
impl From<FillError> for std::io::Error {

quic/s2n-quic-core/src/connection/error.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ pub enum Error {
101101
},
102102
}
103103

104-
#[cfg(feature = "std")]
105-
impl std::error::Error for Error {}
104+
impl core::error::Error for Error {}
106105

107106
impl fmt::Display for Error {
108107
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {

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
}

0 commit comments

Comments
 (0)