mirror of
https://github.com/n0-computer/noq.git
synced 2026-09-25 04:35:17 +00:00
Erase crypto::Session::HandshakeTokenKey
This commit is contained in:
+12
-12
@@ -8,7 +8,7 @@ use crate::crypto::types::{Certificate, CertificateChain, PrivateKey};
|
||||
use crate::{
|
||||
cid_generator::{ConnectionIdGenerator, RandomConnectionIdGenerator},
|
||||
congestion,
|
||||
crypto::{self, HandshakeTokenKey as _, HmacKey},
|
||||
crypto::{self, HandshakeTokenKey, HmacKey},
|
||||
VarInt, VarIntBoundsExceeded, DEFAULT_SUPPORTED_VERSIONS,
|
||||
};
|
||||
|
||||
@@ -430,7 +430,7 @@ where
|
||||
pub crypto: S::ServerConfig,
|
||||
|
||||
/// Used to generate one-time AEAD keys to protect handshake tokens
|
||||
pub(crate) token_key: Arc<S::HandshakeTokenKey>,
|
||||
pub(crate) token_key: Arc<dyn HandshakeTokenKey>,
|
||||
|
||||
/// Whether to require clients to prove ownership of an address before committing resources.
|
||||
///
|
||||
@@ -453,13 +453,13 @@ impl<S> ServerConfig<S>
|
||||
where
|
||||
S: crypto::Session,
|
||||
{
|
||||
/// Create a default config with a particular `master_key`
|
||||
pub fn new(crypto: S::ServerConfig, prk: S::HandshakeTokenKey) -> Self {
|
||||
/// Create a default config with a particular handshake token key
|
||||
pub fn new(crypto: S::ServerConfig, token_key: Arc<dyn HandshakeTokenKey>) -> Self {
|
||||
Self {
|
||||
transport: Arc::new(TransportConfig::default()),
|
||||
crypto,
|
||||
|
||||
token_key: Arc::new(prk),
|
||||
token_key,
|
||||
use_stateless_retry: false,
|
||||
retry_token_lifetime: Duration::from_secs(15),
|
||||
|
||||
@@ -470,8 +470,11 @@ where
|
||||
}
|
||||
|
||||
/// Private key used to authenticate data included in handshake tokens.
|
||||
pub fn token_key(&mut self, master_key: &[u8]) -> Result<&mut Self, ConfigError> {
|
||||
self.token_key = Arc::new(S::HandshakeTokenKey::from_secret(master_key));
|
||||
pub fn token_key(
|
||||
&mut self,
|
||||
value: Arc<dyn HandshakeTokenKey>,
|
||||
) -> Result<&mut Self, ConfigError> {
|
||||
self.token_key = value;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
@@ -536,12 +539,9 @@ impl ServerConfig<crypto::rustls::TlsSession> {
|
||||
let rng = &mut rand::thread_rng();
|
||||
let mut master_key = [0u8; 64];
|
||||
rng.fill_bytes(&mut master_key);
|
||||
let master_key =
|
||||
<crypto::rustls::TlsSession as crypto::Session>::HandshakeTokenKey::from_secret(
|
||||
&master_key,
|
||||
);
|
||||
let master_key = ring::hkdf::Salt::new(ring::hkdf::HKDF_SHA256, &[]).extract(&master_key);
|
||||
|
||||
Self::new(crypto, master_key)
|
||||
Self::new(crypto, Arc::new(master_key))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,6 @@ pub(crate) mod types;
|
||||
pub trait Session: Send + Sized {
|
||||
/// Type used to hold configuration for client sessions
|
||||
type ClientConfig: ClientConfig<Self>;
|
||||
/// Key used to generate one-time-use handshake token keys
|
||||
type HandshakeTokenKey: HandshakeTokenKey;
|
||||
/// Type of keys used to protect packet headers
|
||||
type HeaderKey: HeaderKey;
|
||||
/// Type used to represent packet protection keys
|
||||
@@ -200,8 +198,6 @@ pub struct ExportKeyingMaterialError;
|
||||
pub trait HandshakeTokenKey: Send + Sync {
|
||||
/// Derive AEAD using hkdf
|
||||
fn aead_from_hkdf(&self, random_bytes: &[u8]) -> Box<dyn AeadKey>;
|
||||
/// Method to build pseudo random key from existing bytes
|
||||
fn from_secret(secret: &[u8]) -> Self;
|
||||
}
|
||||
|
||||
/// A key for sealing data with AEAD-based algorithms
|
||||
|
||||
@@ -27,10 +27,6 @@ impl crypto::HandshakeTokenKey for hkdf::Prk {
|
||||
let key = aead::UnboundKey::new(&aead::AES_256_GCM, &key_buffer).unwrap();
|
||||
Box::new(aead::LessSafeKey::new(key))
|
||||
}
|
||||
|
||||
fn from_secret(bytes: &[u8]) -> Self {
|
||||
hkdf::Salt::new(hkdf::HKDF_SHA256, &[]).extract(bytes)
|
||||
}
|
||||
}
|
||||
|
||||
impl crypto::AeadKey for aead::LessSafeKey {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::{any::Any, convert::TryInto, io, str, sync::Arc};
|
||||
|
||||
use bytes::BytesMut;
|
||||
use ring::{aead, hkdf};
|
||||
use ring::aead;
|
||||
pub use rustls::Error;
|
||||
use rustls::{
|
||||
self,
|
||||
@@ -37,7 +37,6 @@ impl TlsSession {
|
||||
|
||||
impl crypto::Session for TlsSession {
|
||||
type ClientConfig = Arc<rustls::ClientConfig>;
|
||||
type HandshakeTokenKey = hkdf::Prk;
|
||||
type PacketKey = PacketKey;
|
||||
type HeaderKey = HeaderProtectionKey;
|
||||
type ServerConfig = Arc<rustls::ServerConfig>;
|
||||
|
||||
@@ -25,7 +25,7 @@ pub struct RetryToken<'a> {
|
||||
impl<'a> RetryToken<'a> {
|
||||
pub fn encode(
|
||||
&self,
|
||||
key: &impl HandshakeTokenKey,
|
||||
key: &dyn HandshakeTokenKey,
|
||||
address: &SocketAddr,
|
||||
retry_src_cid: &ConnectionId,
|
||||
) -> Vec<u8> {
|
||||
@@ -52,7 +52,7 @@ impl<'a> RetryToken<'a> {
|
||||
}
|
||||
|
||||
pub fn from_bytes(
|
||||
key: &impl HandshakeTokenKey,
|
||||
key: &dyn HandshakeTokenKey,
|
||||
address: &SocketAddr,
|
||||
retry_src_cid: &ConnectionId,
|
||||
raw_token_bytes: &'a [u8],
|
||||
@@ -158,7 +158,7 @@ mod test {
|
||||
fn token_sanity() {
|
||||
use super::*;
|
||||
use crate::cid_generator::{ConnectionIdGenerator, RandomConnectionIdGenerator};
|
||||
use crate::{crypto, MAX_CID_SIZE};
|
||||
use crate::MAX_CID_SIZE;
|
||||
|
||||
use rand::RngCore;
|
||||
use std::{
|
||||
@@ -177,7 +177,7 @@ mod test {
|
||||
let mut master_key = vec![0u8; 64];
|
||||
rng.fill_bytes(&mut master_key);
|
||||
|
||||
let prk: ring::hkdf::Prk = crypto::HandshakeTokenKey::from_secret(&master_key);
|
||||
let prk = ring::hkdf::Salt::new(ring::hkdf::HKDF_SHA256, &[]).extract(&master_key);
|
||||
|
||||
let addr = SocketAddr::new(Ipv6Addr::LOCALHOST.into(), 4433);
|
||||
let retry_src_cid = RandomConnectionIdGenerator::new(MAX_CID_SIZE).generate_cid();
|
||||
@@ -199,7 +199,7 @@ mod test {
|
||||
fn invalid_token_returns_err() {
|
||||
use super::*;
|
||||
use crate::cid_generator::{ConnectionIdGenerator, RandomConnectionIdGenerator};
|
||||
use crate::{crypto, MAX_CID_SIZE};
|
||||
use crate::MAX_CID_SIZE;
|
||||
use rand::RngCore;
|
||||
use std::net::Ipv6Addr;
|
||||
|
||||
@@ -211,7 +211,7 @@ mod test {
|
||||
let mut random_bytes = [0; 32];
|
||||
rng.fill_bytes(&mut random_bytes);
|
||||
|
||||
let prk: ring::hkdf::Prk = crypto::HandshakeTokenKey::from_secret(&master_key);
|
||||
let prk = ring::hkdf::Salt::new(ring::hkdf::HKDF_SHA256, &[]).extract(&master_key);
|
||||
|
||||
let addr = SocketAddr::new(Ipv6Addr::LOCALHOST.into(), 4433);
|
||||
let retry_src_cid = RandomConnectionIdGenerator::new(MAX_CID_SIZE).generate_cid();
|
||||
|
||||
Reference in New Issue
Block a user