mirror of https://github.com/ctz/rustls
parent
869306f6b3
commit
9fc1e8404c
|
@ -54,17 +54,24 @@ pub trait StoresClientSessions: Send + Sync {
|
|||
|
||||
/// Remember a TLS1.2 session. At most one of these can be remembered at a time, per
|
||||
/// `server_name`.
|
||||
#[cfg(feature = "tls12")]
|
||||
fn put_tls12_session(&self, server_name: &ServerName, value: persist::Tls12ClientSessionValue);
|
||||
|
||||
/// Get the most recently saved TLS1.2 session for `server_name` provided to `put_tls12_session`.
|
||||
#[cfg(feature = "tls12")]
|
||||
fn get_tls12_session(
|
||||
&self,
|
||||
server_name: &ServerName,
|
||||
) -> Option<persist::Tls12ClientSessionValue>;
|
||||
|
||||
/// Forget any saved TLS1.2 session for `server_name`.
|
||||
#[cfg(feature = "tls12")]
|
||||
fn forget_tls12_session(&self, server_name: &ServerName);
|
||||
|
||||
/// Forget any saved TLS1.2 session for `server_name`.
|
||||
#[cfg(not(feature = "tls12"))]
|
||||
fn forget_tls12_session(&self, _: &ServerName) {}
|
||||
|
||||
/// Remember a TLS1.3 ticket that might be retrieved later from `take_tls13_ticket`, allowing
|
||||
/// resumption of this session. This can be called multiple times for a given session, allowing
|
||||
/// multiple independent tickets to be valid at once. The number of times this is called
|
||||
|
|
|
@ -21,12 +21,15 @@ impl client::StoresClientSessions for NoClientSessionStorage {
|
|||
None
|
||||
}
|
||||
|
||||
#[cfg(feature = "tls12")]
|
||||
fn put_tls12_session(&self, _: &ServerName, _: persist::Tls12ClientSessionValue) {}
|
||||
|
||||
#[cfg(feature = "tls12")]
|
||||
fn get_tls12_session(&self, _: &ServerName) -> Option<persist::Tls12ClientSessionValue> {
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(feature = "tls12")]
|
||||
fn forget_tls12_session(&self, _: &ServerName) {}
|
||||
|
||||
fn add_tls13_ticket(&self, _: &ServerName, _: persist::Tls13ClientSessionValue) {}
|
||||
|
@ -42,6 +45,7 @@ struct ServerData {
|
|||
kx_hint: Option<NamedGroup>,
|
||||
|
||||
// Zero or one TLS1.2 sessions.
|
||||
#[cfg(feature = "tls12")]
|
||||
tls12: Option<persist::Tls12ClientSessionValue>,
|
||||
|
||||
// Up to MAX_TLS13_TICKETS_PER_SERVER TLS1.3 tickets, oldest first.
|
||||
|
@ -52,6 +56,7 @@ impl Default for ServerData {
|
|||
fn default() -> Self {
|
||||
Self {
|
||||
kx_hint: None,
|
||||
#[cfg(feature = "tls12")]
|
||||
tls12: None,
|
||||
tls13: VecDeque::with_capacity(MAX_TLS13_TICKETS_PER_SERVER),
|
||||
}
|
||||
|
@ -93,6 +98,7 @@ impl client::StoresClientSessions for ClientSessionMemoryCache {
|
|||
.and_then(|sd| sd.kx_hint)
|
||||
}
|
||||
|
||||
#[cfg(feature = "tls12")]
|
||||
fn put_tls12_session(&self, server_name: &ServerName, value: persist::Tls12ClientSessionValue) {
|
||||
self.servers
|
||||
.lock()
|
||||
|
@ -100,6 +106,7 @@ impl client::StoresClientSessions for ClientSessionMemoryCache {
|
|||
.get_or_insert_default_and_edit(server_name.clone(), |data| data.tls12 = Some(value));
|
||||
}
|
||||
|
||||
#[cfg(feature = "tls12")]
|
||||
fn get_tls12_session(
|
||||
&self,
|
||||
server_name: &ServerName,
|
||||
|
@ -111,6 +118,7 @@ impl client::StoresClientSessions for ClientSessionMemoryCache {
|
|||
.and_then(|sd| sd.tls12.as_ref().cloned())
|
||||
}
|
||||
|
||||
#[cfg(feature = "tls12")]
|
||||
fn forget_tls12_session(&self, server_name: &ServerName) {
|
||||
self.servers
|
||||
.lock()
|
||||
|
|
|
@ -48,10 +48,16 @@ fn find_session(
|
|||
.take_tls13_ticket(server_name)
|
||||
.map(persist::ClientSessionValue::from)
|
||||
.or_else(|| {
|
||||
config
|
||||
.session_storage
|
||||
.get_tls12_session(server_name)
|
||||
.map(persist::ClientSessionValue::from)
|
||||
#[cfg(feature = "tls12")]
|
||||
{
|
||||
config
|
||||
.session_storage
|
||||
.get_tls12_session(server_name)
|
||||
.map(persist::ClientSessionValue::from)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "tls12"))]
|
||||
None
|
||||
})
|
||||
.and_then(|resuming| {
|
||||
let retrieved = persist::Retrieved::new(resuming, TimeBase::now().ok()?);
|
||||
|
|
|
@ -421,7 +421,9 @@ pub mod client {
|
|||
#[cfg(feature = "dangerous_configuration")]
|
||||
pub use client_conn::danger::DangerousClientConfig;
|
||||
|
||||
pub use crate::msgs::persist::{Tls12ClientSessionValue, Tls13ClientSessionValue};
|
||||
#[cfg(feature = "tls12")]
|
||||
pub use crate::msgs::persist::Tls12ClientSessionValue;
|
||||
pub use crate::msgs::persist::Tls13ClientSessionValue;
|
||||
}
|
||||
|
||||
pub use client::{ClientConfig, ClientConnection, ServerName};
|
||||
|
|
|
@ -2718,6 +2718,7 @@ impl rustls::client::StoresClientSessions for ClientStorage {
|
|||
rc
|
||||
}
|
||||
|
||||
#[cfg(feature = "tls12")]
|
||||
fn put_tls12_session(
|
||||
&self,
|
||||
server_name: &rustls::ServerName,
|
||||
|
@ -2731,6 +2732,7 @@ impl rustls::client::StoresClientSessions for ClientStorage {
|
|||
.put_tls12_session(server_name, value)
|
||||
}
|
||||
|
||||
#[cfg(feature = "tls12")]
|
||||
fn get_tls12_session(
|
||||
&self,
|
||||
server_name: &rustls::ServerName,
|
||||
|
@ -2748,6 +2750,7 @@ impl rustls::client::StoresClientSessions for ClientStorage {
|
|||
rc
|
||||
}
|
||||
|
||||
#[cfg(feature = "tls12")]
|
||||
fn forget_tls12_session(&self, server_name: &rustls::ServerName) {
|
||||
self.ops
|
||||
.lock()
|
||||
|
@ -3726,6 +3729,7 @@ fn test_client_config_keyshare_mismatch() {
|
|||
assert!(do_handshake_until_error(&mut client, &mut server).is_err());
|
||||
}
|
||||
|
||||
#[cfg(feature = "tls12")]
|
||||
#[test]
|
||||
fn test_client_sends_helloretryrequest() {
|
||||
// client sends a secp384r1 key share
|
||||
|
|
Loading…
Reference in New Issue