TlsSession

Struct TlsSession 

Source
pub struct TlsSession { /* private fields */ }
Expand description

A TLS session that can decrypt traffic.

Manages the full lifecycle:

  1. Collect handshake data (client_random, server_random, cipher_suite)
  2. Look up keys from SSLKEYLOGFILE
  3. Derive encryption keys
  4. Create decryption contexts for both directions
  5. Decrypt application data records

Implementations§

Source§

impl TlsSession

Source

pub fn new(keylog: Arc<KeyLog>) -> Self

Create a new TLS session with a keylog reference.

Source

pub fn state(&self) -> SessionState

Get the current session state.

Source

pub fn handshake(&self) -> &HandshakeData

Get the handshake data.

Source

pub fn process_client_hello(&mut self, client_random: [u8; 32])

Process a ClientHello message.

Extracts the client_random from the handshake.

Source

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.

Source

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
Source

pub fn can_decrypt(&self) -> bool

Check if the session can decrypt traffic.

Source

pub fn is_tls13_handshake_phase(&self) -> bool

Check if we’re in TLS 1.3 handshake encryption mode.

Source

pub fn tls13_handshake_phase(&self) -> Tls13HandshakePhase

Get the current TLS 1.3 handshake phase.

Source

pub fn transition_to_application_data(&mut self)

Transition to TLS 1.3 application data phase. Called when both Finished messages have been processed.

Source

pub fn mark_server_finished(&mut self)

Mark that the server has sent its Finished message.

Source

pub fn mark_client_finished(&mut self)

Mark that the client has sent its Finished message. This also transitions to application data mode.

Source

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.

Source

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.

Source

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.

Source

pub fn cipher_suite_name(&self) -> Option<&'static str>

Get the cipher suite name if available.

Source

pub fn client_sequence(&self) -> Option<u64>

Get the client’s sequence number (for debugging).

Source

pub fn server_sequence(&self) -> Option<u64>

Get the server’s sequence number (for debugging).

Source

pub fn close(&mut self)

Close the session.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more