一个在Linux/FreeBSD上使用系统信任存储的certifi黑客工具
项目描述
certifi-system-store,一个用于系统信任存储的certifi黑客工具
certifi-system-store 是 certifi 的替代品和黑客工具。它用Linux和某些BSD发行版的系统信任存储替换了certifi。
请注意,此软件包是全新的且 高度实验性 的。它尚未在任何生产环境中进行测试。
安装
您必须在安装软件包后运行 python -m certifi
。此命令确保您有一个正常工作的系统信任存储,并修补您当前的Python环境。它创建或替换certifi的dist-info目录为certifi-system-store的dist-info。
我建议您首先安装 certifi-system-store
并修补,然后安装您的软件包和需求。
$ python -m pip install certifi-system-store
$ python -m certifi
$ python -m pip install requests
验证
certifi-system-store
的 certifi
命令有一个额外的参数 --system-store
。此参数在标准的 certifi
软件包中不可用。您可以使用此属性来验证 certifi
软件包是由 certifi-system-store
提供的。
$ python -m venv venv
$ venv/bin/pip install certifi
$ venv/bin/python -m certifi --system-store
usage: __main__.py [-h] [-c]
__main__.py: error: unrecognized arguments: --system-store
$ echo $?
2
$ venv/bin/pip install certifi-system-store
$ venv/bin/python -m certifi --system-store
/etc/pki/tls/cert.pem
$ echo $?
0
该命令还会检查CA证书捆绑包的存在。
$ venv/bin/python -m certifi
Traceback (most recent call last):
...
FileNotFoundError: /etc/ssl/cert.pem, /etc/pki/tls/cert.pem, /etc/ssl/certs/ca-certificates.crt, /etc/ssl/ca-bundle.pem
$ echo $?
1
在运行时检查certifi-system-store
import certifi
if not getattr(certifi, "__certifi_system_store__", False):
raise ImportError("certifi-system-store is not installed")
依赖于certifi-system-store
# setup.py
from setuptools import setup
setup(
...,
install_requires=[
"certifi-system-store ; sys_platform == 'linux' or 'freebsd' in sys_platform",
"certifi > 3000 ; sys_platform == 'linux' or 'freebsd' in sys_platform",
"certifi",
],
)
平台支持
支持的平台
大多数主要的Linux发行版和FreeBSD都受到支持。
- Alpine
- 基于Debian的发行版(Ubuntu,Raspberry Pi OS,Tails,...)
- 注意:一些发行版在其最小软件包列表中没有系统信任存储。您可能需要手动安装
ca-certificates
,请参阅Debian错误#960869,Ubuntu错误#1879310。
- 注意:一些发行版在其最小软件包列表中没有系统信任存储。您可能需要手动安装
- 基于Fedora的发行版(RHEL,CentOS,CentOS Streams)
- FreeBSD
- 注意:可能需要手动安装
ca_root_nss
- 注意:可能需要手动安装
- OpenSUSE
未测试的平台
certifi-system-store
可能可以工作,但没有为这些平台进行CI。
- ArchLinux
- Gentoo
- OpenWRT
- Slackware
- VoidLinux
- 不是基于Debian或Fedora的其它Linux发行版
- OpenBSD
- NetBSD
不受支持的平台
- Windows
- macOS
- Android(有证书目录但没有PEM捆绑包)
- iOS
支持的系统信任存储
/etc/ssl/cert.pem
- Alpine
- Arch
- Fedora 34+(见rhbz#1895619)
- FreeBSD(需要
ca_root_nss
软件包) - OpenWRT
- RHEL 9
/etc/pki/tls/cert.pem
- CentOS 7,8
- Fedora 33及更早版本
- RHEL 7,8
/etc/ssl/certs/ca-certificates.crt
- Debian(需要
ca-certificates
软件包) - Gentoo
- Ubuntu(需要
ca-certificates
软件包)
/etc/ssl/ca-bundle.pem
- SUSE
如何安装自定义CA证书
Alpine
$ sudo cp my-custom-ca.pem /usr/local/share/ca-certificates/my-custom-ca.crt
$ sudo update-ca-certificates
Arch
$ sudo cp my-custom-ca.pem /etc/ca-certificates/trust-source/anchors/my-custom-ca.crt
$ sudo update-ca-trust
CentOS,Fedora,RHEL
标准的PEM或DER编码的证书(BEGIN CERTIFICATE
)
$ sudo cp my-custom-ca.pem /etc/pki/ca-trust/source/anchors/
$ sudo update-ca-trust
带有额外信任信息的证书(BEGIN TRUSTED CERTIFICATE
)
$ sudo cp my-custom-ca.pem /etc/pki/ca-trust/source/
$ sudo update-ca-trust
Debian,Ubuntu
注意:手册页update-ca-certificates(8)
提到,证书文件必须具有.crt
扩展名。
$ sudo cp my-custom-ca.pem /usr/local/share/ca-certificates/my-custom-ca.crt
$ sudo update-ca-certificates
它是如何工作的?
- 将空的
certifi/cacert.pem
用于覆盖任何现有的certifi数据。 - 使用比certifi默认dist-info元数据版本号高得多的版本号伪造
certifi dist-info
$ venv/bin/pip install certifi-system-store
$ ls -l .tox/venv/lib/python3.9/site-packages/
certifi
certifi_system_store-3000.1.dist-info
...
$ venv/bin/python -m certifi -v --system-store
certifi-system store 3000.0a1
Patched certifi.dist-info -> certifi_system_store.dist-info
/etc/pki/tls/cert.pem
$ ls -l .tox/venv/lib/python3.9/site-packages/
certifi
certifi-3000.1.dist-info -> certifi_system_store-3000.1.dist-info
certifi_system_store-3000.1.dist-info
...
特别感谢
- Cory Benfield
- Pradyun Gedam
- Wouter Bolsterlee
项目详情
下载文件
下载您平台上的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源代码分发
certifi-system-store-3021.3.16.tar.gz (18.0 kB 查看哈希值)
构建分发
关闭
certifi-system-store-3021.3.16.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 603be2b260ae2d5d025f584a219087683ff2ddcd09325ebb56b172cd07877057 |
|
MD5 | aeefb12c77e836f824fd101999c9df4d |
|
BLAKE2b-256 | 964c189f209291795fb76a2a2c14aece74a5f79cc1d228aac4f8c6753397b4dd |
关闭
哈希值 用于 certifi_system_store-3021.3.16-py3-none-any.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | f990bf52b69edf88dd879913aab5dd07e7537c2686435e3f0354e911a8327c6a |
|
MD5 | 1cff171d58b7ea689c1f44b920f024f9 |
|
BLAKE2b-256 | cefa005b38bb74472c34b8abd0a60022f2697faa764b697bbfe661206ef1bddf |