rdproxy prototype fork of Devolutions/sspi-rs; upstream https://github.com/Devolutions/sspi-rs
Find a file
Pavlo Myroniuk a9dfaec9b0
refactor!: enable as_conversions lint (#721)
https://rust-lang.github.io/rust-clippy/master/#as_conversions

> Checks for usage of `as` conversions.
>
> `as` conversions will perform many kinds of conversions, including
silently lossy conversions and dangerous coercions.

---------

Co-authored-by: Pavlo Myroniuk <pavlo.myroniuk@apriorit.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-08-15 00:36:03 +09:00
.github ci: run the client_server test suite (enable __test-data in the matrix) 2026-06-24 18:00:34 +09:00
crates refactor!: enable as_conversions lint (#721) 2026-08-15 00:36:03 +09:00
examples refactor!: enable as_conversions lint (#721) 2026-08-15 00:36:03 +09:00
ffi refactor!: enable as_conversions lint (#721) 2026-08-15 00:36:03 +09:00
fuzz chore: bump Rust edition to 2024 (#591) 2026-02-12 22:10:47 +09:00
proptest-regressions refactor: clarify naming of user-facing options (#184) 2023-11-08 23:53:26 +00:00
src refactor!: enable as_conversions lint (#721) 2026-08-15 00:36:03 +09:00
test_assets feat(sspi): improve domain->realm mapping in kerberos backend (#604) 2026-02-17 14:47:31 +00:00
tests/sspi refactor!: enable as_conversions lint (#721) 2026-08-15 00:36:03 +09:00
tools fix: improve NTLM fallback (#627) 2026-03-23 11:49:06 +00:00
.gitignore build: checkout Cargo.lock files 2023-09-07 17:51:00 -04:00
Cargo.lock chore: bump md4 from 0.10.2 to 0.11.0 in the crypto group across 1 directory (#701) 2026-08-13 12:55:01 +09:00
Cargo.toml refactor!: enable as_conversions lint (#721) 2026-08-15 00:36:03 +09:00
CHANGELOG.md chore(release): prepare for publishing (#713) 2026-08-08 01:58:26 +09:00
cliff.toml ci: automate crate publishing (#359) 2025-02-04 18:21:51 -05:00
clippy.toml chore: bump Rust version to 1.97.1 and MSRV to 1.93; (#715) 2026-07-31 18:36:22 +09:00
Info.plist Android and iOS packaging (#52) 2022-09-28 14:43:28 -04:00
LICENSE-APACHE sspi-rs: initial import from Apriorit deliverable 2019-05-30 09:30:41 -04:00
LICENSE-MIT sspi-rs: initial import from Apriorit deliverable 2019-05-30 09:30:41 -04:00
README.md chore(docs): remove dead links (#598) 2026-02-12 22:12:35 +09:00
release-plz.toml ci: automate crate publishing (#359) 2025-02-04 18:21:51 -05:00
rust-toolchain.toml chore: bump Rust version to 1.97.1 and MSRV to 1.93; (#715) 2026-07-31 18:36:22 +09:00
rustfmt.toml Kerberos protocol implementation and C-bindings (#11) 2022-05-20 11:26:16 -04:00

sspi-rs

sspi-rs is a Rust implementation of Security Support Provider Interface (SSPI). It ships with platform-independent implementations of Security Support Providers (SSP), and is able to utilize native Microsoft libraries when ran under Windows.

The purpose of sspi-rs is to clean the original interface from cluttering and provide users with Rust-friendly SSPs for execution under *nix or any other platform that is able to compile Rust.

Overview

The sspi-rs works in accordance with the MSDN documentation. At the moment, NT LAN Manager (NTLM) is implemented and available for platform independent execution. It is also possible to create your own SSPs by implementing the SspiImpl trait.

Ease of use

Some SSPI functions tend to be cumbersome, that's why sspi-rs allows to use SSPI in a convenient way by utilizing builders.

Example

The usage of the SSPs is as simple as creating an instance of the security provider and calling its functions.

Here is an example of acquiring a credentials handle and a timestamp of their validity:

use sspi::{CredentialUse, Ntlm, Sspi, Username, builders::EmptyInitializeSecurityContext, SecurityBuffer, ClientRequestFlags, DataRepresentation, BufferType, SspiImpl};

fn main() {
    let account_name = "example_user";
    let computer_name = "example_computer";
    let mut ntlm = Ntlm::new();
    let username = Username::new(&account_name, Some(&computer_name)).unwrap();
    let identity = sspi::AuthIdentity {
        username,
        password: String::from("example_password").into(),
    };

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

    let mut output_buffer = vec![SecurityBuffer::new(Vec::new(), BufferType::Token)];
    // first time calling initialize_security_context, the input buffer should be empty
    let mut input_buffer = vec![SecurityBuffer::new(Vec::new(), BufferType::Token)];

    // create a builder for the first call to initialize_security_context
    // the target should start with the protocol name, e.g. "HTTP/example.com" or "LDAP/example.com"
    let mut builder = EmptyInitializeSecurityContext::<<Ntlm as SspiImpl>::CredentialsHandle>::new()
        .with_credentials_handle(&mut acq_cred_result.credentials_handle)
        .with_context_requirements(ClientRequestFlags::CONFIDENTIALITY | ClientRequestFlags::ALLOCATE_MEMORY)
        .with_target_data_representation(DataRepresentation::Native)
        .with_target_name("LDAP/example.com")
        .with_input(&mut input_buffer)
        .with_output(&mut output_buffer);

    // call initialize_security_context
    // Note: the initialize_security_context_impl returns a generator, for NTLM, 
    // this generator will never yield as NTLM requires no network communication to a third party
    // but negotiate and kerberos do require network communication, so the generator is used to
    // allow the caller to provide the network information through the generator.resume() method
    // take a look at the examples/kerberos.rs for more information
    let _result = ntlm
        .initialize_security_context_impl(&mut builder)
        .resolve_to_result()
        .unwrap();
    // ... exchange your token in output buffer with the server and repeat the process until either server is satisfied or an error is thrown
}

Example of acquiring an SSP provided by Windows:

let mut negotiate = SecurityPackage::from_package_type(
    SecurityPackageType::Other(String::from("Negotiate"))
);

Projects using sspi-rs

(Feel free to open a PR if you know about other projects!)

License

Licensed under either of:

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.