diff --git a/quinn-proto/src/connection.rs b/quinn-proto/src/connection.rs index f4fc5b146..ef682de7f 100644 --- a/quinn-proto/src/connection.rs +++ b/quinn-proto/src/connection.rs @@ -908,10 +908,7 @@ impl Connection { return Ok(()); } trace!(self.log, "read {} TLS bytes", n); - if let Err(e) = self.tls.read_handshake(&buf[..n]) { - debug!(self.log, "reading handshake bytes resulted in error {}", e); - return Err(e); - } + self.tls.read_handshake(&buf[..n])?; } } @@ -1155,7 +1152,7 @@ impl Connection { debug!( self.log, "closing connection due to transport error: {error}", - error = err + error = &err ); State::closed(err) } diff --git a/quinn-proto/src/crypto.rs b/quinn-proto/src/crypto.rs index 15d402d84..645624d40 100644 --- a/quinn-proto/src/crypto.rs +++ b/quinn-proto/src/crypto.rs @@ -60,11 +60,11 @@ impl CryptoSession for TlsSession { } fn read_handshake(&mut self, buf: &[u8]) -> Result<(), TransportError> { - self.read_hs(buf).map_err(|_| { + self.read_hs(buf).map_err(|e| { if let Some(alert) = self.get_alert() { - TransportError::crypto(alert.get_u8()) + TransportError::crypto(alert.get_u8(), e.to_string()) } else { - TransportError::PROTOCOL_VIOLATION("TLS error") + TransportError::PROTOCOL_VIOLATION(format!("TLS error: {}", e)) } }) } diff --git a/quinn-proto/src/tests.rs b/quinn-proto/src/tests.rs index da7991775..341257aaa 100644 --- a/quinn-proto/src/tests.rs +++ b/quinn-proto/src/tests.rs @@ -589,7 +589,7 @@ fn reject_self_signed_cert() { .unwrap(); pair.drive(); assert_matches!(pair.client.poll(), - Some((conn, Event::ConnectionLost { reason: ConnectionError::TransportError(error)})) + Some((conn, Event::ConnectionLost { reason: ConnectionError::TransportError(ref error)})) if conn == client_ch && error.code == TransportErrorCode::crypto(AlertDescription::BadCertificate.get_u8())); } diff --git a/quinn-proto/src/transport_error.rs b/quinn-proto/src/transport_error.rs index d3f064f12..848ece0a9 100644 --- a/quinn-proto/src/transport_error.rs +++ b/quinn-proto/src/transport_error.rs @@ -7,24 +7,27 @@ use crate::coding::{self, BufExt, BufMutExt}; use crate::frame; use rustls::internal::msgs::{codec::Codec, enums::AlertDescription}; -#[derive(Debug, Copy, Clone, Eq, PartialEq)] +#[derive(Debug, Clone, Eq, PartialEq)] pub struct Error { pub code: Code, pub frame: Option, - pub reason: &'static str, + pub reason: String, } impl Error { - pub fn new(code: Code, frame: Option, reason: &'static str) -> Self { + pub fn new(code: Code, frame: Option, reason: T) -> Self + where + T: Into, + { Self { code, frame, - reason, + reason: reason.into(), } } - pub fn crypto(code: u8) -> Self { - Self::new(Code::crypto(code), None, "") + pub fn crypto(code: u8, reason: String) -> Self { + Self::new(Code::crypto(code), None, reason) } } @@ -46,7 +49,7 @@ impl From for Error { Self { code: x, frame: None, - reason: "", + reason: "".to_string(), } } } @@ -91,11 +94,11 @@ macro_rules! errors { #[allow(non_snake_case, unused)] impl Error { $( - pub(crate) fn $name(reason: &'static str) -> Self { + pub(crate) fn $name(reason: T) -> Self where T: Into { Self { code: Code::$name, frame: None, - reason, + reason: reason.into(), } } )* diff --git a/quinn/src/lib.rs b/quinn/src/lib.rs index 196ab7d1d..9cee52a80 100644 --- a/quinn/src/lib.rs +++ b/quinn/src/lib.rs @@ -501,7 +501,7 @@ impl Drop for Driver { ch.fail(ConnectionError::TransportError(quinn::TransportError { code: quinn::TransportErrorCode::INTERNAL_ERROR, frame: None, - reason: "driver future was dropped", + reason: "driver future was dropped".to_string(), })); } }