20 releases

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 1381851/week @ 2024-08-21 1295161/week @ 2024-08-28 1590037/week @ 2024-09-04 1524836/week @ 2024-09-11 1493028/week @ 2024-09-18 1642928/week @ 2024-09-25 1671488/week @ 2024-10-02 1639891/week @ 2024-10-09 1728466/week @ 2024-10-16 1714952/week @ 2024-10-23 1724709/week @ 2024-10-30 1683489/week @ 2024-11-06 1771685/week @ 2024-11-13 1717361/week @ 2024-11-20 1398237/week @ 2024-11-27 1362010/week @ 2024-12-04

6,571,646 downloads per month
Used in 2,893 crates (202 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–6.5MB
~40K SLoC