pub struct TlsSession { /* private fields */ }Expand description
A TLS session that can decrypt traffic.
Manages the full lifecycle:
- Collect handshake data (client_random, server_random, cipher_suite)
- Look up keys from SSLKEYLOGFILE
- Derive encryption keys
- Create decryption contexts for both directions
- Decrypt application data records
Implementations§
Source§impl TlsSession
impl TlsSession
Sourcepub fn state(&self) -> SessionState
pub fn state(&self) -> SessionState
Get the current session state.
Sourcepub fn handshake(&self) -> &HandshakeData
pub fn handshake(&self) -> &HandshakeData
Get the handshake data.
Sourcepub fn process_client_hello(&mut self, client_random: [u8; 32])
pub fn process_client_hello(&mut self, client_random: [u8; 32])
Process a ClientHello message.
Extracts the client_random from the handshake.
Sourcepub fn process_server_hello(
&mut self,
server_random: [u8; 32],
cipher_suite: u16,
version: TlsVersion,
) -> Result<(), SessionError>
pub fn process_server_hello( &mut self, server_random: [u8; 32], cipher_suite: u16, version: TlsVersion, ) -> Result<(), SessionError>
Process a ServerHello message.
Extracts server_random and cipher_suite, then attempts key derivation.
Sourcepub fn try_establish_keys(&mut self) -> Result<(), SessionError>
pub fn try_establish_keys(&mut self) -> Result<(), SessionError>
Attempt to establish decryption keys.
This requires:
- client_random and server_random from handshake
- Cipher suite selection
- Key material from SSLKEYLOGFILE
Sourcepub fn can_decrypt(&self) -> bool
pub fn can_decrypt(&self) -> bool
Check if the session can decrypt traffic.
Sourcepub fn is_tls13_handshake_phase(&self) -> bool
pub fn is_tls13_handshake_phase(&self) -> bool
Check if we’re in TLS 1.3 handshake encryption mode.
Sourcepub fn tls13_handshake_phase(&self) -> Tls13HandshakePhase
pub fn tls13_handshake_phase(&self) -> Tls13HandshakePhase
Get the current TLS 1.3 handshake phase.
Sourcepub fn transition_to_application_data(&mut self)
pub fn transition_to_application_data(&mut self)
Transition to TLS 1.3 application data phase. Called when both Finished messages have been processed.
Sourcepub fn mark_server_finished(&mut self)
pub fn mark_server_finished(&mut self)
Mark that the server has sent its Finished message.
Sourcepub fn mark_client_finished(&mut self)
pub fn mark_client_finished(&mut self)
Mark that the client has sent its Finished message. This also transitions to application data mode.
Sourcepub fn decrypt_record(
&mut self,
direction: Direction,
record_type: u8,
ciphertext: &[u8],
) -> Result<Vec<u8>, SessionError>
pub fn decrypt_record( &mut self, direction: Direction, record_type: u8, ciphertext: &[u8], ) -> Result<Vec<u8>, SessionError>
Decrypt a TLS record.
Returns the decrypted plaintext. For TLS 1.3, this automatically uses the correct keys based on the handshake phase.
Sourcepub fn decrypt_handshake_record(
&mut self,
direction: Direction,
record_type: u8,
ciphertext: &[u8],
) -> Result<Vec<u8>, SessionError>
pub fn decrypt_handshake_record( &mut self, direction: Direction, record_type: u8, ciphertext: &[u8], ) -> Result<Vec<u8>, SessionError>
Decrypt a TLS 1.3 handshake record specifically. Use this when you know you’re decrypting handshake messages.
Sourcepub fn decrypt_application_record(
&mut self,
direction: Direction,
record_type: u8,
ciphertext: &[u8],
) -> Result<Vec<u8>, SessionError>
pub fn decrypt_application_record( &mut self, direction: Direction, record_type: u8, ciphertext: &[u8], ) -> Result<Vec<u8>, SessionError>
Decrypt a TLS 1.3 application data record specifically. Use this when you know you’re decrypting application data.
Sourcepub fn cipher_suite_name(&self) -> Option<&'static str>
pub fn cipher_suite_name(&self) -> Option<&'static str>
Get the cipher suite name if available.
Sourcepub fn client_sequence(&self) -> Option<u64>
pub fn client_sequence(&self) -> Option<u64>
Get the client’s sequence number (for debugging).
Sourcepub fn server_sequence(&self) -> Option<u64>
pub fn server_sequence(&self) -> Option<u64>
Get the server’s sequence number (for debugging).