Skip to main content

Session

Struct Session 

Source
pub struct Session {
    pub session_id: SessionId,
    pub signing_key: Vec<u8>,
    pub encryption_key: Option<Vec<u8>>,
    pub decryption_key: Option<Vec<u8>>,
    pub signing_algorithm: SigningAlgorithm,
    pub should_sign: bool,
    pub should_encrypt: bool,
}
Expand description

An authenticated SMB2 session with derived keys.

Fields§

§session_id: SessionId

The session ID assigned by the server.

§signing_key: Vec<u8>

Key used to sign outgoing messages.

§encryption_key: Option<Vec<u8>>

Key used to encrypt outgoing messages (SMB 3.x).

§decryption_key: Option<Vec<u8>>

Key used to decrypt incoming messages (SMB 3.x).

§signing_algorithm: SigningAlgorithm

The signing algorithm to use.

§should_sign: bool

Whether outgoing messages should be signed.

§should_encrypt: bool

Whether outgoing messages should be encrypted.

Implementations§

Source§

impl Session

Source

pub async fn setup( conn: &mut Connection, username: &str, password: &str, domain: &str, ) -> Result<Session>

Perform the multi-round-trip SESSION_SETUP exchange.

Steps:

  1. Send NTLM NEGOTIATE_MESSAGE in SESSION_SETUP.
  2. Receive STATUS_MORE_PROCESSING_REQUIRED with CHALLENGE_MESSAGE.
  3. Update preauth hash with request+response.
  4. Send NTLM AUTHENTICATE_MESSAGE in SESSION_SETUP.
  5. Receive STATUS_SUCCESS with session flags.
  6. Update preauth hash with request+response.
  7. Derive signing/encryption keys.
  8. Activate signing on the connection.
Source

pub async fn setup_kerberos_from_ccache( conn: &mut Connection, credentials: &KerberosCredentials, server_hostname: &str, ccache: &CCache, ) -> Result<Session>

Perform Kerberos-based SESSION_SETUP.

Authenticates against the KDC first (AS + TGS), then sends the SPNEGO-wrapped AP-REQ in SESSION_SETUP. Handles both single-round (STATUS_SUCCESS) and mutual-auth (STATUS_MORE_PROCESSING_REQUIRED) flows.

The session key comes from the Kerberos TGS exchange, not from the SMB server response. Perform Kerberos-based SESSION_SETUP using a credential cache.

Reads cached tickets from the ccache. If a service ticket for cifs/<server_hostname> is cached, uses it directly (no KDC needed). If only a TGT is cached, does a TGS exchange for the service ticket.

Source

pub async fn setup_kerberos( conn: &mut Connection, credentials: &KerberosCredentials, server_hostname: &str, ) -> Result<Session>

Perform Kerberos-based SESSION_SETUP.

Authenticates against the KDC first (AS + TGS), then sends the SPNEGO-wrapped AP-REQ in SESSION_SETUP. Handles both single-round (STATUS_SUCCESS) and mutual-auth (STATUS_MORE_PROCESSING_REQUIRED) flows.

The session key comes from the Kerberos TGS exchange, not from the SMB server response.

Trait Implementations§

Source§

impl Debug for Session

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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, 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> Same for T

Source§

type Output = T

Should always be Self
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.