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.
rustls-native-certs is mature and widely used.
If you'd like to help out, please see CONTRIBUTING.md.
- 0.7.0 (2023-12-03)
- Switched to using the pki-types crate.
load_native_certs
now returnsVec<pki_types::CertificateDer<'static>>
instead ofVec<Certificate>
- the
Certificate
newtype has been removed.
- Update dependencies.
- Switched to using the pki-types crate.
- 0.6.3 (2023-06-14)
- Bump MSRV to 1.60.
- Windows: avoid storing certificates which are currently invalid.
- Implement
AsRef<[u8]>
forCertificate
.
- 0.6.2 (2022-04-14):
- Update dependencies.
- 0.6.1 (2021-10-25):
- Allow overrides using
SSL_CERT_FILE
on all platforms.
- Allow overrides using
- 0.6.0 (2021-10-24):
- Remove rustls dependency entirely.
- 0.5.0 (2020-11-22):
- Update dependencies.
- Make rustls dependency optional, for use with reqwest's certificate types. Thanks to @est31.
- 0.4.0 (2020-07-05):
- Update dependencies.
- 0.3.0 (2020-02-24):
- Support wider range of UNIX platforms.
- Update dependencies.
- 0.2.0 (2020-01-26):
- Return valid certificates even in the presence of invalid ones. This allows callers to opt-in to "best effort" behaviour.
- 0.1.0 (2019-11-04):
- Initial release.
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.
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.
See examples/google.rs
.
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.