20 releases

new 0.8.1 Nov 21, 2024
0.7.3 Aug 28, 2024
0.7.1 Jul 3, 2024
0.7.0 Dec 3, 2023
0.1.0 Nov 4, 2019

#4 in Network programming

Download history 1314952/week @ 2024-08-01 1355148/week @ 2024-08-08 1334213/week @ 2024-08-15 1383236/week @ 2024-08-22 1316729/week @ 2024-08-29 1569532/week @ 2024-09-05 1533704/week @ 2024-09-12 1517474/week @ 2024-09-19 1660512/week @ 2024-09-26 1687797/week @ 2024-10-03 1637525/week @ 2024-10-10 1718922/week @ 2024-10-17 1720240/week @ 2024-10-24 1703982/week @ 2024-10-31 1693044/week @ 2024-11-07 1778042/week @ 2024-11-14

7,237,099 downloads per month
Used in 2,852 crates (201 directly)

Apache-2.0 OR ISC OR MIT

32KB
473 lines

Logo

rustls-native-certs allows rustls to use the platform's native certificate store when operating as a TLS client.

[!IMPORTANT] Instead of this crate, we suggest using rustls-platform-verifier, which provides a more robust solution with a simpler API. This crate is still maintained, but mostly for use inside the platform verifier on platforms where no other solution is available. For more context, see deployment considerations.

Status

rustls-native-certs is mature and widely used.

If you'd like to help out, please see CONTRIBUTING.md.

rustls Documentation

Release notes can be found on GitHub.

API

This library exposes a single function with this signature:

pub fn load_native_certs() -> Result<Vec<pki_types::CertificateDer<'static>>, std::io::Error>

On success, this returns a Vec<pki_types::CertificateDer<'static>> loaded with a snapshot of the root certificates found on this platform. This function fails in a platform-specific way, expressed in a std::io::Error.

This function can be expensive: on some platforms it involves loading and parsing a ~300KB disk file. It's therefore prudent to call this sparingly.

Platform support

This is supported on Windows, macOS and Linux:

  • On all platforms, the SSL_CERT_FILE environment variable is checked first. If that's set, certificates are loaded from the path specified by that variable, or an error is returned if certificates cannot be loaded from the given path. If it's not set, then the platform-specific certificate source is used.
  • On Windows, certificates are loaded from the system certificate store. The schannel crate is used to access the Windows certificate store APIs.
  • On macOS, certificates are loaded from the keychain. The user, admin and system trust settings are merged together as documented by Apple. The security-framework crate is used to access the keystore APIs.
  • On Linux and other UNIX-like operating systems, the openssl-probe crate is used to discover the filename of the system CA bundle.

Worked example

See examples/google.rs.

License

rustls-native-certs is distributed under the following three licenses:

  • Apache License version 2.0.
  • MIT license.
  • ISC license.

These are included as LICENSE-APACHE, LICENSE-MIT and LICENSE-ISC respectively. You may use this software under the terms of any of these licenses, at your option.

Dependencies

~0.1–7MB
~44K SLoC