mirror of
https://github.com/n0-computer/noq.git
synced 2026-09-24 12:13:05 +00:00
Improve reason descriptions for TLS errors
This commit is contained in:
committed by
Benjamin Saunders
parent
eb01d30be0
commit
47bc2886c2
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
|
||||
@@ -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<frame::Type>,
|
||||
pub reason: &'static str,
|
||||
pub reason: String,
|
||||
}
|
||||
|
||||
impl Error {
|
||||
pub fn new(code: Code, frame: Option<frame::Type>, reason: &'static str) -> Self {
|
||||
pub fn new<T>(code: Code, frame: Option<frame::Type>, reason: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
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<Code> 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<T>(reason: T) -> Self where T: Into<String> {
|
||||
Self {
|
||||
code: Code::$name,
|
||||
frame: None,
|
||||
reason,
|
||||
reason: reason.into(),
|
||||
}
|
||||
}
|
||||
)*
|
||||
|
||||
+1
-1
@@ -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(),
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user