mirror of https://github.com/ctz/rustls
Format quic
This commit is contained in:
parent
96acad1d55
commit
59ee30545e
|
@ -1,15 +1,16 @@
|
|||
/// This module contains optional APIs for implementing QUIC TLS.
|
||||
use crate::client::{ClientConfig, ClientSession, ClientSessionImpl};
|
||||
use crate::msgs::enums::{ContentType, ProtocolVersion, AlertDescription};
|
||||
use crate::error::TLSError;
|
||||
use crate::key_schedule::hkdf_expand;
|
||||
use crate::msgs::enums::{AlertDescription, ContentType, ProtocolVersion};
|
||||
use crate::msgs::handshake::{ClientExtension, ServerExtension};
|
||||
use crate::msgs::message::{Message, MessagePayload};
|
||||
use crate::server::{ServerConfig, ServerSession, ServerSessionImpl};
|
||||
use crate::error::TLSError;
|
||||
use crate::key_schedule::hkdf_expand;
|
||||
use crate::session::{SessionCommon, Protocol};
|
||||
use crate::session::{Protocol, SessionCommon};
|
||||
use crate::suites::{BulkAlgorithm, SupportedCipherSuite, TLS13_AES_128_GCM_SHA256};
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use ring::{aead, hkdf};
|
||||
use webpki;
|
||||
|
||||
|
@ -77,9 +78,14 @@ impl QuicExt for ClientSession {
|
|||
read_hs(&mut self.imp.common, plaintext)?;
|
||||
self.imp.process_new_handshake_messages()
|
||||
}
|
||||
fn write_hs(&mut self, buf: &mut Vec<u8>) -> Option<Keys> { write_hs(&mut self.imp.common, buf) }
|
||||
|
||||
fn get_alert(&self) -> Option<AlertDescription> { self.imp.common.quic.alert }
|
||||
fn write_hs(&mut self, buf: &mut Vec<u8>) -> Option<Keys> {
|
||||
write_hs(&mut self.imp.common, buf)
|
||||
}
|
||||
|
||||
fn get_alert(&self) -> Option<AlertDescription> {
|
||||
self.imp.common.quic.alert
|
||||
}
|
||||
|
||||
fn next_1rtt_keys(&mut self) -> PacketKeySet {
|
||||
next_1rtt_keys(&mut self.imp.common)
|
||||
|
@ -102,9 +108,13 @@ impl QuicExt for ServerSession {
|
|||
read_hs(&mut self.imp.common, plaintext)?;
|
||||
self.imp.process_new_handshake_messages()
|
||||
}
|
||||
fn write_hs(&mut self, buf: &mut Vec<u8>) -> Option<Keys> { write_hs(&mut self.imp.common, buf) }
|
||||
fn write_hs(&mut self, buf: &mut Vec<u8>) -> Option<Keys> {
|
||||
write_hs(&mut self.imp.common, buf)
|
||||
}
|
||||
|
||||
fn get_alert(&self) -> Option<AlertDescription> { self.imp.common.quic.alert }
|
||||
fn get_alert(&self) -> Option<AlertDescription> {
|
||||
self.imp.common.quic.alert
|
||||
}
|
||||
|
||||
fn next_1rtt_keys(&mut self) -> PacketKeySet {
|
||||
next_1rtt_keys(&mut self.imp.common)
|
||||
|
@ -237,7 +247,8 @@ fn read_hs(this: &mut SessionCommon, plaintext: &[u8]) -> Result<(), TLSError> {
|
|||
typ: ContentType::Handshake,
|
||||
version: ProtocolVersion::TLSv1_3,
|
||||
payload: MessagePayload::new_opaque(plaintext.into()),
|
||||
}).is_none()
|
||||
})
|
||||
.is_none()
|
||||
{
|
||||
this.quic.alert = Some(AlertDescription::DecodeError);
|
||||
return Err(TLSError::CorruptMessage);
|
||||
|
@ -299,14 +310,24 @@ pub trait ClientQuicExt {
|
|||
/// Make a new QUIC ClientSession. This differs from `ClientSession::new()`
|
||||
/// in that it takes an extra argument, `params`, which contains the
|
||||
/// TLS-encoded transport parameters to send.
|
||||
fn new_quic(config: &Arc<ClientConfig>, hostname: webpki::DNSNameRef, params: Vec<u8>)
|
||||
-> ClientSession {
|
||||
assert!(config.versions.iter().all(|x| x.get_u16() >= ProtocolVersion::TLSv1_3.get_u16()), "QUIC requires TLS version >= 1.3");
|
||||
fn new_quic(
|
||||
config: &Arc<ClientConfig>,
|
||||
hostname: webpki::DNSNameRef,
|
||||
params: Vec<u8>,
|
||||
) -> ClientSession {
|
||||
assert!(
|
||||
config
|
||||
.versions
|
||||
.iter()
|
||||
.all(|x| x.get_u16() >= ProtocolVersion::TLSv1_3.get_u16()),
|
||||
"QUIC requires TLS version >= 1.3"
|
||||
);
|
||||
let mut imp = ClientSessionImpl::new(config);
|
||||
imp.common.protocol = Protocol::Quic;
|
||||
imp.start_handshake(hostname.into(), vec![
|
||||
ClientExtension::TransportParameters(params),
|
||||
]);
|
||||
imp.start_handshake(
|
||||
hostname.into(),
|
||||
vec![ClientExtension::TransportParameters(params)],
|
||||
);
|
||||
ClientSession { imp }
|
||||
}
|
||||
}
|
||||
|
@ -319,11 +340,19 @@ pub trait ServerQuicExt {
|
|||
/// in that it takes an extra argument, `params`, which contains the
|
||||
/// TLS-encoded transport parameters to send.
|
||||
fn new_quic(config: &Arc<ServerConfig>, params: Vec<u8>) -> ServerSession {
|
||||
assert!(config.versions.iter().all(|x| x.get_u16() >= ProtocolVersion::TLSv1_3.get_u16()), "QUIC requires TLS version >= 1.3");
|
||||
assert!(config.max_early_data_size == 0 || config.max_early_data_size == 0xffff_ffff, "QUIC sessions must set a max early data of 0 or 2^32-1");
|
||||
let mut imp = ServerSessionImpl::new(config, vec![
|
||||
ServerExtension::TransportParameters(params),
|
||||
]);
|
||||
assert!(
|
||||
config
|
||||
.versions
|
||||
.iter()
|
||||
.all(|x| x.get_u16() >= ProtocolVersion::TLSv1_3.get_u16()),
|
||||
"QUIC requires TLS version >= 1.3"
|
||||
);
|
||||
assert!(
|
||||
config.max_early_data_size == 0 || config.max_early_data_size == 0xffff_ffff,
|
||||
"QUIC sessions must set a max early data of 0 or 2^32-1"
|
||||
);
|
||||
let mut imp =
|
||||
ServerSessionImpl::new(config, vec![ServerExtension::TransportParameters(params)]);
|
||||
imp.common.protocol = Protocol::Quic;
|
||||
ServerSession { imp }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue