[][src]Trait sspi::Sspi

pub trait Sspi where
    Self: Sized + SspiImpl
{ fn complete_auth_token(
        &mut self,
        token: &mut [SecurityBuffer]
    ) -> Result<SecurityStatus>;
fn encrypt_message(
        &mut self,
        flags: EncryptionFlags,
        message: &mut [SecurityBuffer],
        sequence_number: u32
    ) -> Result<SecurityStatus>;
fn decrypt_message(
        &mut self,
        message: &mut [SecurityBuffer],
        sequence_number: u32
    ) -> Result<DecryptionFlags>;
fn query_context_sizes(&mut self) -> Result<ContextSizes>;
fn query_context_names(&mut self) -> Result<ContextNames>;
fn query_context_package_info(&mut self) -> Result<PackageInfo>;
fn query_context_cert_trust_status(&mut self) -> Result<CertTrustStatus>; fn acquire_credentials_handle(
        &mut self
    ) -> EmptyAcquireCredentialsHandle<Self, Self::CredentialsHandle, Self::AuthenticationData> { ... }
fn initialize_security_context(
        &mut self
    ) -> EmptyInitializeSecurityContext<Self, Self::CredentialsHandle> { ... }
fn accept_security_context(
        &mut self
    ) -> EmptyAcceptSecurityContext<Self, Self::CredentialsHandle> { ... } }

This trait provides interface for all available SSPI functions. The acquire_credentials_handle, initialize_security_context, and accept_security_context methods return Builders that make it easier to assemble the list of arguments for the function and then execute it.

MSDN

Required methods

fn complete_auth_token(
    &mut self,
    token: &mut [SecurityBuffer]
) -> Result<SecurityStatus>

Completes an authentication token. This function is used by protocols, such as DCE, that need to revise the security information after the transport application has updated some message parameters.

Parameters

  • token: SecurityBuffer that contains the buffer descriptor for the entire message

Returns

  • SspiOk on success
  • Error on error

Example

let result = ntlm
    .complete_auth_token(&mut output_buffer)
    .unwrap();

MSDN

fn encrypt_message(
    &mut self,
    flags: EncryptionFlags,
    message: &mut [SecurityBuffer],
    sequence_number: u32
) -> Result<SecurityStatus>

Encrypts a message to provide privacy. The function allows the application to choose among cryptographic algorithms supported by the chosen mechanism. Some packages do not have messages to be encrypted or decrypted but rather provide an integrity hash that can be checked.

Parameters

  • flags: package-specific flags that indicate the quality of protection. A security package can use this parameter to enable the selection of cryptographic algorithms
  • message: on input, the structure accepts one or more SecurityBuffer structures that can be of type SecurityBufferType::Data. That buffer contains the message to be encrypted. The message is encrypted in place, overwriting the original contents of the structure.
  • sequence_number: the sequence number that the transport application assigned to the message. If the transport application does not maintain sequence numbers, this parameter must be zero

Example

let mut msg_buffer = vec![sspi::SecurityBuffer::new(Vec::new(), sspi::SecurityBufferType::Token),
    sspi::SecurityBuffer::new(Vec::from("This is a message".as_bytes()), sspi::SecurityBufferType::Data)];

println!("Unencrypted: {:?}", msg_buffer[1].buffer);

let result = ntlm
    .encrypt_message(sspi::EncryptionFlags::empty(), &mut msg_buffer, 0).unwrap();

println!("Encrypted: {:?}", msg_buffer[1].buffer);

Returns

  • SspiOk on success
  • Error on error

MSDN

fn decrypt_message(
    &mut self,
    message: &mut [SecurityBuffer],
    sequence_number: u32
) -> Result<DecryptionFlags>

Decrypts a message. Some packages do not encrypt and decrypt messages but rather perform and check an integrity hash.

Parameters

  • message: on input, the structure references one or more SecurityBuffer structures. At least one of these must be of type SecurityBufferType::Data. That buffer contains the encrypted message. The encrypted message is decrypted in place, overwriting the original contents of its buffer
  • sequence_number: the sequence number that the transport application assigned to the message. If the transport application does not maintain sequence numbers, this parameter must be zero

Returns

  • DecryptionFlags upon success
  • Error on error

Example

let encryption_flags = ntlm
    .decrypt_message(&mut msg_buffer, 0)
    .unwrap();

println!("Decrypted message: {:?}", msg_buffer[1].buffer);

MSDN

fn query_context_sizes(&mut self) -> Result<ContextSizes>

Retrieves information about the bounds of sizes of authentication information of the current security principal.

Returns

  • ContextSizes upon success
  • Error on error

Example

let sizes = ntlm.query_context_sizes().unwrap();
println!("Max token: {}", sizes.max_token);
println!("Max signature: {}", sizes.max_signature);
println!("Block: {}", sizes.block);
println!("Security trailer: {}", sizes.security_trailer);

MSDN

fn query_context_names(&mut self) -> Result<ContextNames>

Retrieves the username of the credential associated to the context.

Returns

  • ContextNames upon success
  • Error on error

Example

let names = ntlm.query_context_names().unwrap();
println!("Username: {:?}", names.username);
println!("Domain: {:?}", names.domain);

MSDN

fn query_context_package_info(&mut self) -> Result<PackageInfo>

Retrieves information about the specified security package. This information includes the bounds of sizes of authentication information, credentials, and contexts.

Returns

  • PackageInfo containing the information about the package
  • Error on error

Example

let info = ntlm.query_context_package_info().unwrap();
println!("Package name: {:?}", info.name);

MSDN

fn query_context_cert_trust_status(&mut self) -> Result<CertTrustStatus>

Retrieves the trust information of the certificate.

Returns

  • CertTrustStatus on success

Example

let cert_info = ntlm.query_context_package_info().unwrap();

MSDN

Loading content...

Provided methods

fn acquire_credentials_handle(
    &mut self
) -> EmptyAcquireCredentialsHandle<Self, Self::CredentialsHandle, Self::AuthenticationData>

Acquires a handle to preexisting credentials of a security principal. The preexisting credentials are available only for sspi::winapi module. This handle is required by the initialize_security_context and accept_security_context functions. These can be either preexisting credentials, which are established through a system logon, or the caller can provide alternative credentials. Alternative credentials are always required to specify when using platform independent SSPs.

Returns

  • AcquireCredentialsHandle builder

Requirements for execution

These methods are required to be called before calling the execute method of the AcquireCredentialsHandle builder:

Example

let identity = sspi::AuthIdentity {
    username: "user".to_string(),
    password: "password".to_string(),
    domain: None,
};

let result = ntlm
    .acquire_credentials_handle()
    .with_credential_use(sspi::CredentialUse::Outbound)
    .with_auth_data(&identity)
    .execute()
    .unwrap();

MSDN

fn initialize_security_context(
    &mut self
) -> EmptyInitializeSecurityContext<Self, Self::CredentialsHandle>

Initiates the client side, outbound security context from a credential handle. The function is used to build a security context between the client application and a remote peer. The function returns a token that the client must pass to the remote peer, which the peer in turn submits to the local security implementation through the accept_security_context call.

Returns

  • InitializeSecurityContext builder

Requirements for execution

These methods are required to be called before calling the execute method

Example

let mut output_buffer = vec![sspi::SecurityBuffer::new(Vec::new(), sspi::SecurityBufferType::Token)];

let result = ntlm
    .initialize_security_context()
    .with_credentials_handle(&mut credentials_handle)
    .with_context_requirements(
        sspi::ClientRequestFlags::CONFIDENTIALITY | sspi::ClientRequestFlags::ALLOCATE_MEMORY,
    )
    .with_target_data_representation(sspi::DataRepresentation::Native)
    .with_output(&mut output_buffer)
    .execute()
    .unwrap();

MSDN

fn accept_security_context(
    &mut self
) -> EmptyAcceptSecurityContext<Self, Self::CredentialsHandle>

Lets the server component of a transport application establish a security context between the server and a remote client. The remote client calls the initialize_security_context function to start the process of establishing a security context. The server can require one or more reply tokens from the remote client to complete establishing the security context.

Returns

  • AcceptSecurityContext builder

Requirements for execution

These methods are required to be called before calling the execute method of the AcceptSecurityContext builder:

Example

let mut ntlm = sspi::Ntlm::new();
let mut output_buffer = vec![sspi::SecurityBuffer::new(Vec::new(), sspi::SecurityBufferType::Token)];

let result = ntlm
    .accept_security_context()
    .with_credentials_handle(&mut credentials_handle)
    .with_context_requirements(sspi::ServerRequestFlags::ALLOCATE_MEMORY)
    .with_target_data_representation(sspi::DataRepresentation::Native)
    .with_input(&mut client_output_buffer)
    .with_output(&mut output_buffer)
    .execute()
    .unwrap();

MSDN

Loading content...

Implementors

impl Sspi for sspi::Ntlm[src]

impl Sspi for sspi::winapi::Ntlm[src]

impl Sspi for SecurityPackage[src]

Loading content...