使用本地系统信任存储验证证书
项目描述
信任存储
注意
这是一个truststore
软件包的分支,它为Robocorp项目增加了额外的配置选项
Truststore是一个库,它通过类似于ssl.SSLContext
的API公开了本机系统证书存储(即“信任存储”)。这意味着Python应用程序不再需要依赖certifi作为根证书存储。与certifi这样的静态证书包相比,本机系统证书存储具有许多有用的功能
- 自动更新证书,随着新CA的创建和删除
- 检索缺失的中间证书
- 将证书与证书吊销列表(CRLs)进行比较,以避免中间人(MITM)攻击
- 由运维/IT团队按系统管理,而不是按应用程序管理
- PyPI不再是一个CA分发渠道🥳
目前,Truststore是一个独立的库,可以全局安装到您的应用程序中,以立即利用Python 3.10+的好处。Truststore还作为pip的一个可选方法集成到pip中,用于使用Truststore而不是certifi来验证HTTPS证书。
长期目标是使Truststore成为pip中验证HTTPS证书的默认方式,并将此功能添加到Python本身中。祝我们好运!
安装
Truststore可以通过pip从PyPI安装
$ python -m pip install truststore
Truststore 需要Python 3.10或更高版本,并支持以下平台
- macOS 10.8+通过Security框架
- Windows通过CryptoAPI
- Linux通过OpenSSL
用户指南
警告 请务必阅读:
inject_into_ssl()
不应由库或包使用,因为它在与其他库集成时会引起导入时间问题。库和包应改直接使用以下详细说明中的truststore.SSLContext
。
inject_into_ssl()
函数仅适用于应用程序和脚本。
您可以将truststore
注入到标准库的ssl
模块中,以便默认情况下由每个库使用该功能。为此,请使用truststore.inject_into_ssl()
函数
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")
如果您希望有更细粒度的控制或正在开发库或包,您可以为truststore.SSLContext
创建自己的实例,并在需要使用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")
您可以在[文档的用户指南](https://truststore.readthedocs.io/en/latest/#user-guide)中了解更多信息。
许可
MIT
项目详情
下载文件
下载适用于您的平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源分发
构建分发
robocorp_truststore-0.9.1.tar.gz的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | a1abfd9c5b7fe22152a8eeb9510812800dca741851c720742c598c0f78ee4f3f |
|
MD5 | 9a7250bdc9a9576d37719a0338d0516a |
|
BLAKE2b-256 | 16441a723f5079d842cef35523c0fd3e99ff1e072df5c34d6e777ad5c76f4b69 |
robocorp_truststore-0.9.1-py3-none-any.whl的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | dfdd4812dffce8a91134e8b69a3c55072fc9785dbdd583d4047f323779ac2f39 |
|
MD5 | 172e3d80292034621e914d5aaf1e37b6 |
|
BLAKE2b-256 | 24608a3965aa9dd707eab8d489589360a28960ae53889c60b72d149dbce6455b |