跳转到主要内容

一个在Linux/FreeBSD上使用系统信任存储的certifi黑客工具

项目描述

certifi-system-store,一个用于系统信任存储的certifi黑客工具

certifi-system-storecertifi 的替代品和黑客工具。它用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-storecertifi 命令有一个额外的参数 --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,...)
  • 基于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-py3-none-any.whl (12.0 kB 查看哈希值

上传时间 Python 3