diff --git a/quinn-proto/src/connection.rs b/quinn-proto/src/connection.rs index 6f10335f3..68d90a231 100644 --- a/quinn-proto/src/connection.rs +++ b/quinn-proto/src/connection.rs @@ -909,12 +909,8 @@ impl Connection { } trace!(self.log, "read {} TLS bytes", n); if let Err(e) = self.tls.read_handshake(&buf[..n]) { - debug!(self.log, "TLS error: {}", e); - return Err(if let Some(alert) = self.tls.alert() { - TransportError::crypto(alert) - } else { - TransportError::PROTOCOL_VIOLATION("TLS error") - }); + debug!(self.log, "reading handshake bytes resulted in error {}", e); + return Err(e); } } } diff --git a/quinn-proto/src/crypto.rs b/quinn-proto/src/crypto.rs index 6644cc6e4..e92c9a1da 100644 --- a/quinn-proto/src/crypto.rs +++ b/quinn-proto/src/crypto.rs @@ -10,7 +10,6 @@ use ring::aead::{self, Aad, Nonce}; use ring::digest; use ring::hkdf; use ring::hmac::{self, SigningKey}; -use rustls::internal::msgs::enums::AlertDescription; use rustls::quic::{ClientQuicExt, Secrets, ServerQuicExt}; use rustls::ProtocolVersion; pub use rustls::{Certificate, NoClientAuth, PrivateKey, TLSError}; @@ -45,10 +44,6 @@ impl TlsSession { } impl CryptoSession for TlsSession { - fn alert(&self) -> Option { - self.get_alert() - } - fn alpn_protocol(&self) -> Option<&[u8]> { self.get_alpn_protocol() } @@ -65,8 +60,14 @@ impl CryptoSession for TlsSession { } } - fn read_handshake(&mut self, buf: &[u8]) -> Result<(), TLSError> { - self.read_hs(buf) + fn read_handshake(&mut self, buf: &[u8]) -> Result<(), TransportError> { + self.read_hs(buf).map_err(|_| { + if let Some(alert) = self.get_alert() { + TransportError::crypto(alert.get_u8()) + } else { + TransportError::PROTOCOL_VIOLATION("TLS error") + } + }) } fn sni_hostname(&self) -> Option<&str> { @@ -101,11 +102,10 @@ impl CryptoSession for TlsSession { } pub trait CryptoSession { - fn alert(&self) -> Option; fn alpn_protocol(&self) -> Option<&[u8]>; fn early_crypto(&self) -> Option; fn is_handshaking(&self) -> bool; - fn read_handshake(&mut self, buf: &[u8]) -> Result<(), TLSError>; + fn read_handshake(&mut self, buf: &[u8]) -> Result<(), TransportError>; fn sni_hostname(&self) -> Option<&str>; fn transport_parameters(&self) -> Result, TransportError>; fn write_handshake(&mut self, buf: &mut Vec) -> Option; diff --git a/quinn-proto/src/tests.rs b/quinn-proto/src/tests.rs index 0c22d11e8..da7991775 100644 --- a/quinn-proto/src/tests.rs +++ b/quinn-proto/src/tests.rs @@ -590,7 +590,7 @@ fn reject_self_signed_cert() { pair.drive(); assert_matches!(pair.client.poll(), Some((conn, Event::ConnectionLost { reason: ConnectionError::TransportError(error)})) - if conn == client_ch && error.code == TransportErrorCode::crypto(AlertDescription::BadCertificate)); + if conn == client_ch && error.code == TransportErrorCode::crypto(AlertDescription::BadCertificate.get_u8())); } #[test] diff --git a/quinn-proto/src/transport_error.rs b/quinn-proto/src/transport_error.rs index 0111f5288..d3f064f12 100644 --- a/quinn-proto/src/transport_error.rs +++ b/quinn-proto/src/transport_error.rs @@ -23,8 +23,8 @@ impl Error { } } - pub fn crypto(alert: AlertDescription) -> Self { - Self::new(Code::crypto(alert), None, "") + pub fn crypto(code: u8) -> Self { + Self::new(Code::crypto(code), None, "") } } @@ -66,8 +66,8 @@ impl slog::Value for Error { pub struct Code(u16); impl Code { - pub fn crypto(alert: AlertDescription) -> Self { - Code(0x100 | alert.get_u8() as u16) + pub fn crypto(code: u8) -> Self { + Code(0x100 | code as u16) } }