Verify certificates using native system trust stores
Project description
Truststore
Truststore is a library which exposes native system certificate stores (ie "trust stores")
through an ssl.SSLContext
-like API. This means that Python applications no longer need to
rely on certifi as a root certificate store. Native system certificate stores
have many helpful features compared to a static certificate bundle like certifi:
- Automatically update certificates as new CAs are created and removed
- Fetch missing intermediate certificates
- Check certificates against certificate revocation lists (CRLs) to avoid monster-in-the-middle (MITM) attacks
- Managed per-system rather than per-application by a operations/IT team
- PyPI is no longer a CA distribution channel 🥳
Right now truststore is a stand-alone library that can be installed globally in your application to immediately take advantage of the benefits in Python 3.10+. Truststore has also been integrated into pip as an opt-in method for verifying HTTPS certificates with truststore instead of certifi.
Long-term the hope is to make truststore the default way to verify HTTPS certificates in pip and to add this functionality into Python itself. Wish us luck!
Installation
Truststore is installed from PyPI with pip:
$ python -m pip install truststore
Truststore requires Python 3.10 or later and supports the following platforms:
- macOS 10.8+ via Security framework
- Windows via CryptoAPI
- Linux via OpenSSL
User Guide
You can inject truststore
into the standard library ssl
module so the functionality is used
by every library by default. To do so use the truststore.inject_into_ssl()
function:
import truststore
truststore.inject_into_ssl()
# Automatically works with urllib3, requests, aiohttp, and more:
import urllib3
http = urllib3.PoolManager()
resp = http.request("GET", "https://example.com")
import aiohttp
http = aiohttp.ClientSession()
resp = await http.request("GET", "https://example.com")
import requests
resp = requests.get("https://example.com")
If you'd like finer-grained control you can create your own truststore.SSLContext
instance
and use it anywhere you'd use an ssl.SSLContext
:
import ssl
import truststore
ctx = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
import urllib3
http = urllib3.PoolManager(ssl_context=ctx)
resp = http.request("GET", "https://example.com")
You can read more in the user guide in the documentation.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for truststore-0.8.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e37a5642ae9fc48caa8f120b6283d77225d600d224965a672c9e8ef49ce4bb4c |
|
MD5 | 98b51fa17764fc79ddab4926986bb162 |
|
BLAKE2b-256 | 20567811d5439b6a56374f274a8672d8f18b4deadadeb3a9f0c86424b98b6f96 |