跳转到主要内容

使用本地系统信任存储库验证证书

项目描述

信任存储库

PyPI CI

信任存储库是一个库,它通过类似于ssl.SSLContext的API公开本地系统证书存储(即“信任存储库”)。这意味着Python应用程序不再需要依赖于certifi作为根证书存储。与certifi这样的静态证书包相比,本地系统证书存储具有许多有用的功能。

  • 自动更新证书,当新的CA被创建和删除时
  • 抓取缺失的中级证书
  • 将证书与证书吊销列表(CRL)进行比对,以避免中间人攻击
  • 由操作/IT团队按系统管理,而不是按应用程序管理
  • PyPI不再作为CA分发渠道 🥳

目前,truststore是一个可以全局安装在应用程序中的独立库,可以立即利用Python 3.10+的好处。truststore也已集成到pip 24.2+中,作为验证HTTPS证书的默认方法(后备为certifi)。

长期目标是将此功能集成到Python本身中。祝我们好运!

安装

truststore可以通过pip从PyPI安装

$ python -m pip install truststore

truststore 需要Python 3.10或更高版本,并支持以下平台

用户指南

警告 请阅读: 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")

您可以在文档中的用户指南中了解更多信息。

许可证

MIT

项目详情


下载文件

下载您平台上的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分发

truststore-0.9.2.tar.gz (23.6 kB 查看散列)

上传时间

构建分发

truststore-0.9.2-py3-none-any.whl (17.5 kB 查看散列)

上传时间 Python 3

由...