mirror of
https://github.com/n0-computer/noq.git
synced 2026-09-19 09:45:20 +00:00
Replace TLSError with TransportError in CryptoSession interface
This commit is contained in:
committed by
Benjamin Saunders
parent
ee19ea7c8c
commit
2e0ee41aea
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<AlertDescription> {
|
||||
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<AlertDescription>;
|
||||
fn alpn_protocol(&self) -> Option<&[u8]>;
|
||||
fn early_crypto(&self) -> Option<Crypto>;
|
||||
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<Option<TransportParameters>, TransportError>;
|
||||
fn write_handshake(&mut self, buf: &mut Vec<u8>) -> Option<Crypto>;
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user