Skip to content

Support native certificate store #275

Closed

Description

@SpyMachine

Did you search for existing issues already?

Yes

Is your feature request related to a problem? Please describe.

Yes, I can't really use this without disabling TLS validation because my company MITMs my connection and all my requests are invalid without using the certificates installed locally in my cert store.

Describe the solution you'd like

rustls doesn't support the native cert store by default, but it can if used in combination with rustls-native-certs.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered

Another option would be to switch to native-tls which also solves this problem.

I could obviously disable TLS certs but that's not ideal obviously.

Additional context

I threw together a super quick PoC just to ensure that would actually solve my issue.

use reqwest::Client;
use rustls::ClientConfig;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    rustls::crypto::ring::default_provider()
        .install_default()
        .expect("Failed to install rustls crypto provider");

    let mut roots = rustls::RootCertStore::empty();
    for cert in rustls_native_certs::load_native_certs().expect("could not load platform certs") {
        roots.add(cert).unwrap();
    }

    let config = ClientConfig::builder()
        .with_root_certificates(roots)
        .with_no_client_auth();

    // Create a reqwest client with the custom TLS configuration
    let client = Client::builder().use_preconfigured_tls(config).build()?;

    // Make a request
    let response = client.get("https://httpbin.org/get").send().await?;

    println!("Status: {}", response.status());
    println!("Headers:\n{:#?}", response.headers());
    let body = response.text().await?;
    println!("Body:\n{}", body);

    Ok(())
}

Activity

  1. added a commit that references this issue on Jul 6, 2024
    be22097
  2. LucasPickering commented on Jul 6, 2024

    @LucasPickering
    Owner

    Thanks for the very detailed issue, it made it easier for me to work on this. Turns out reqwest has a feature rustls-tls-native-roots which I imagine does more or less the same thing as your PoC (it also pulls in the rustls-native-certs crate). Do you mind testing out the branch I made to make sure this works for you?

    cargo install --git https://github.com/LucasPickering/slumber --branch native-certs
    
  3. SpyMachine commented on Jul 6, 2024

    @SpyMachine
    Author

    Oh hah, didn't even think to check that! Yes, this indeed works for me :) Thank you!

  4. LucasPickering commented on Jul 7, 2024

    @LucasPickering
    Owner

    Thanks for testing! I just released 1.6.0 which includes this fix

  5. added a commit that references this issue on Dec 22, 2024
    f075a91
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions