Skip to content

Commit

Permalink
Implement SSL_session_reused
Browse files Browse the repository at this point in the history
  • Loading branch information
ctz committed Apr 17, 2024
1 parent 86a516a commit 1e2fbec
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion rustls-libssl/MATRIX.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@
| `SSL_rstate_string_long` | | | |
| `SSL_select_next_proto` | | :white_check_mark: | :white_check_mark: |
| `SSL_sendfile` | | | |
| `SSL_session_reused` | | :white_check_mark: | :exclamation: [^stub] |
| `SSL_session_reused` | | :white_check_mark: | :white_check_mark: |
| `SSL_set0_CA_list` | | | |
| `SSL_set0_rbio` | | | :white_check_mark: |
| `SSL_set0_security_ex_data` | | | |
Expand Down
14 changes: 10 additions & 4 deletions rustls-libssl/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1633,6 +1633,16 @@ entry! {
}
}

entry! {
pub fn _SSL_session_reused(ssl: *const SSL) -> c_int {
let ssl = try_clone_arc!(ssl);
ssl.lock()
.ok()
.map(|ssl| ssl.was_session_reused() as c_int)
.unwrap_or_default()
}
}

impl Castable for SSL {
type Ownership = OwnershipArc;
type RustType = Mutex<SSL>;
Expand Down Expand Up @@ -1891,10 +1901,6 @@ entry_stub! {
pub fn _SSL_set_session(_ssl: *mut SSL, _session: *mut SSL_SESSION) -> c_int;
}

entry_stub! {
pub fn _SSL_session_reused(_ssl: *const SSL) -> c_int;
}

entry_stub! {
pub fn _SSL_get1_session(_ssl: *mut SSL) -> *mut SSL_SESSION;
}
Expand Down
11 changes: 9 additions & 2 deletions rustls-libssl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use rustls::crypto::aws_lc_rs as provider;
use rustls::pki_types::{CertificateDer, ServerName};
use rustls::server::{Accepted, Acceptor};
use rustls::{
CipherSuite, ClientConfig, ClientConnection, Connection, ProtocolVersion, RootCertStore,
ServerConfig,
CipherSuite, ClientConfig, ClientConnection, Connection, HandshakeKind, ProtocolVersion,
RootCertStore, ServerConfig,
};

mod bio;
Expand Down Expand Up @@ -1216,6 +1216,13 @@ impl Ssl {
None => HandshakeState::Before,
}
}

fn was_session_reused(&self) -> bool {
match self.conn() {
Some(conn) => conn.handshake_kind() == Some(HandshakeKind::Resumed),
None => false,
}
}
}

/// This is a reduced-fidelity version of `OSSL_HANDSHAKE_STATE`.
Expand Down

0 comments on commit 1e2fbec

Please sign in to comment.