- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
简而言之
我得到:[SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书 (_ssl.c:1129)
什么是比 [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败更糟糕的错误:证书链中的自签名证书 (_ssl.c:1129)
而且我怀疑是python还是我自己的代码,但是纯openSSL也会出现同样的错误:
openssl s_client -connect my-domain.com:443 -CAfile root.pem -verify 2
......
Verify return code: 21 (unable to verify the first certificate)
Extended master secret: no
Max Early Data: 0
---
......
如果 openSSL 不起作用,python 也将不起作用。确保这是针对 TLS 握手时的任何错误。 ;-)
Authority Key Identifier
中找到了根本原因条目
DirName
和
serial
.他们以前不存在的地方:
openssl x509 -in my-domain.pem -text
The only diff and root cause was Authority Key Identifier with two new entries:
X509v3 Authority Key Identifier:
keyid:1D:E8:38:95:85:65:A2:D9:44:99:96:30:D1:81:D5:5B:F7:38:CC:8C
DirName:/C=DE/O=My Company/OU=My OU/CN=My Sub-CA
serial:02
新的也是最后一个问题:为什么 openSSL 不适用于
DirName
和
serial
在
AKI
内?
context.load_default_certs()
加载 Windows 商店
import certifi
import json
import os
import requests
class MyHttpAdapter(HTTPAdapter):
def init_poolmanager(self, *args, **kwargs):
# Google: "SSL failure on Windows using python requests" -- usage of Windows Truststore
# https://stackoverflow.com/questions/42981429/ssl-failure-on-windows-using-python-requests
context = create_urllib3_context()
我尝试了这 3 个设置来加载不同的 ca 包(每次尝试只有一个代码行处于事件状态)
## --------------------
# variant 1: usage of Windows Truststore where I imported my root-ca and sub-ca into local computer storage
# load_default_certs() --> this loads the OS defaults of Windows Truststore!!!!
context.load_default_certs()
# variant 2: my special ca bundle contains only my private CA only with 3 entries: root-ca, sub-ca and server cert
# load_verify_locations() --> this loads just a specific CA bundle !!!!
context.load_verify_locations(cafile="C:/Users/...../my_ca_bundle.pem")
# variant 3: I added my private CA with root-ca, sub-ca and server cert to certifi cacert.pem file as a hack
# certifi.where(): C:\Users\........\Python39\Lib\site-packages\certifi\cacert.pem
# load_verify_locations() --> this loads just a specific CA bundle !!!!
context.load_verify_locations(cafile=certifi.where())
## --------------------
为了验证我的私有(private) CA 是否在所选存储中,我执行
assert
在我的 CA 的 CommonName 上,因此如果找不到它会很快失败。如果没问题,稍后会将上下文添加到 session.mount 中:
# get and print all CAs from loaded list to verify that my CA is within the list
# notice the server certificate of pem file is not loaded into the list, don't no why, maybe because it's no CA
json_ca_certs = context.get_ca_certs()
print("All current context CA certs: {}".format(json.dumps(json_ca_certs, indent=1, sort_keys=True)))
length=len(json_ca_certs)
print("Number of certificates in bundle: {}".format(length))
# fail fast:
assert "MY CommonName" in str(json_ca_certs), "private CA not found in used bundle"
kwargs['ssl_context'] = context
return super().init_poolmanager(*args, **kwargs)
我没有设置那些环境变量,它们是
None
def __init__(self, **kwargs):
print("REQUESTS_CA_BUNDLE: '{}'".format(os.environ.get('REQUESTS_CA_BUNDLE')))
print("CURL_CA_BUNDLE: '{}'".format(os.environ.get('CURL_CA_BUNDLE')))
我创建了一个 session ,并且由于使用我的信任库创建上下文不再起作用,我尝试了 3 种不同的方式来使用 session.verify(每次尝试仅激活一个代码行):
self.session = requests.Session()
# variant 1: default not working anymore:
self.session.verify = True
# variant 2: usage of my special ca bundle does not work
self.session.verify = "C:/Users/...../my_ca_bundle.pem"
# variant 3: certifi cacert.pem file contains my private CA and does not work
# certifi.where(): C:\Users\........\Python39\Lib\site-packages\certifi\cacert.pem
self.session.verify = certifi.where()
在这里,我终于将我的适配器安装到 session :
# mount with Schema only as prefix to use them for all my calls (this worked in past and should not be a new problem)
adapter = self.MyHttpAdapter()
self.session.mount("https://", adapter)
现在我做我的
self.session.get()
来电。我再次尝试了这些设置,因为
context cafile
也不是
session.verify
作品,直接在
requests
session 内:
_api_url = 'https://my-domain.com/api/function'
###
# variant 1: does not longer work, no setting above for session.verify nor context.load...():
response = self.session.get(_api_url)
# variant 2: verify = my special ca bundle work around does not work:
response = self.session.get(_api_url, verify="C:/Users/...../my_ca_bundle.pem")
# variant 3: verify = certifi cacert.pem work around does not work:
response = self.session.get(_api_url, verify=certifi.where())
我在 requests/sessions.py 中添加了一些打印调试输出,以查看使用了什么
settings = self.merge_environment_settings(
prep.url, proxies, stream, verify, cert
)
print(f"DEBUG: request settings: {settings}")
sessions merge_environment_settings()就在 return () 之前
print(f"DEBUG: merge_environment_settings() before return: verify={verify}")
return {'verify': verify, 'proxies': proxies, 'stream': stream,
'cert': cert}
只是看看,我的设置被使用:
DEBUG: merge_environment_settings() before return: verify=path_to_ca_bundle.pem
DEBUG: request settings: {'verify': 'path_to_ca_bundle.pem', 'proxies': OrderedDict(), 'stream': False, 'cert': None}
Python 和安装的模块是最新的:
最佳答案
带有简短问题和解决方案的初始条目已经太长了。由于它现在可以与新的 CA 和服务器证书一起使用,我将把最新的问题放在这个答案上。
在 rfc3280 4.2.1.1授权 key 标识符
The authority key identifier extension provides a means of
identifying the public key corresponding to the private key used to
sign a certificate. This extension is used where an issuer has
multiple signing keys (either due to multiple concurrent key pairs or
due to changeover). The identification MAY be based on either the
key identifier (the subject key identifier in the issuer's
certificate) or on the issuer name and serial number.
The keyIdentifier field of the authorityKeyIdentifier extension MUST
be included in all certificates generated by conforming CAs to
facilitate certification path construction......
...
id-ce-authorityKeyIdentifier OBJECT IDENTIFIER ::= { id-ce 35 }
AuthorityKeyIdentifier ::= SEQUENCE {
keyIdentifier [0] KeyIdentifier OPTIONAL,
authorityCertIssuer [1] GeneralNames OPTIONAL,
authorityCertSerialNumber [2] CertificateSerialNumber OPTIONAL }
注意:所有三个 AuthorityKeyIdentifier 属性都是可选的,并且没有链接在一起。
...
NOTE: Although required to be present by [RFC3280], it is extremely
important that KIDs be used only as sorting criteria or as hints
during certification path building. KIDs are not required to match
during certification path validation and cannot be used to eliminate
certificates. This is of critical importance for interoperating
across domains and multi-vendor implementations where the KIDs may
not be calculated in the same fashion.
它只是一个排序标准,而不是验证标准。
It doesn’t: this extension is often the cause of confusion.
Consider a certificate chain A->B->C so that A signs B and B signs C. Suppose certificate C contains AKID.
The purpose of this extension is to identify the authority certificate B. This can be done either by including the subject key identifier of B or its issuer name and serial number.
In this latter case because it is identifying certificate B it must contain the issuer name and serial number of B.
It is often wrongly assumed that it should contain the subject name of B. If it did this would be redundant information because it would duplicate the issuer name of C.
所以,他们是这个意思???
关于python - 由于 AKI DirName 扩展 : Python [SSL: CERTIFICATE_VERIFY_FAILED] . 在 openSSL 中找到根本原因 ..:无法获取本地颁发者证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71337116/
你知道为什么会调用 badCertificateCallback 吗?证书( Dart 声称无效)与我设置为受信任证书的证书完全相同(相等性检查为真!)。 import 'dart:convert';
我最近将一个项目从 1.22.1 升级到 1.24.3。随后,pub get 失败了 Handshake error in client (OS Error: CERTIFICATE_VERIFY_F
我有一个使用 VirusTotal API 的 python 脚本。它一直没有问题,但是当我运行脚本时突然出现以下错误: urllib2.URLError: 我认为可能是我们的网络代理导致了这个问题
我使用以下代码通过 XMLRPC api 与 Magento 网上商店进行交互。 Magento API Python XMLRPC 一切正常,直到我们将 Web 服务器更改为 SSL 现在我收到以下
在使用 Windows 8.1 的相当新的机器上使用 Python 2.7.12 连接到 www.mydomain.com 时出现错误。错误是 SSL: CERTIFICATE_VERIFY_FAIL
我正在尝试创建一个虚拟环境,过去我可以通过诗歌安装来做到这一点。但是现在当尝试执行 poetry install 时,我收到了这条消息: Max retries exceeded with url:
我使用 python + boto3 在 bitbucket 管道中为 AWS IOT 运行测试脚本 直到最近它工作正常,现在我收到以下错误: Traceback (most recent call
这个问题在这里已经有了答案: youtube-dl gave me an error about ssl (2 个回答) 去年关闭。 我在 Python 中运行了这段代码: from __future
我正在尝试按照 Google 的文档构建我自己的 Android 版本,但它在“repo init”状态下失败(第 2 部分的第 2 步): https://source.android.com/so
好吧,我正在尝试为我的旅馆 wifi 创建一个自动登录脚本,我需要登录到 wifi 才能获得网络访问权限。如果我连接到 wifi,该网页在本地网络上保持打开状态。我只需要访问该网页并在那里登录即可。所
所以我目前正在制作一个 Xamarin.Android 应用程序,一段时间以来它一直使用我制作的 REST API 来与数据来回通信。 不过,我最近将我的 SSL 证书切换到了 LetsEncrypt
在证书有效的某些站点上,在 python 3.5 中使用 urllib3 发出 GET 请求失败并出现错误 CERTIFICATE_VERIFY_FAILED。 import certifi impo
我正在努力解决这个问题 requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed
from lxml import html import requests url = "https://website.com/" page = requests.get(url) tree = h
我对我学校网站的请求有疑问。我在网上搜索了解决方案,但没有一个对我有用。我已经通过 pip 安装了 certifi,它不起作用。我已经重新安装了 openssl,但它不起作用。 >>> import
更新 (2019-02-07):issue现已修复,因此如果您仍然遇到此问题,请尝试 gcloud components update。 在过去几个月的某个时候,我的 bq 工具停止工作了。即使是一个
我正在使用 python 2.7.10 request = urllib2.Request(url, data=urllib.urlencode(params)) f = urllib2.urlope
如果这是一个愚蠢的问题,我深表歉意,但我一直在尝试自学如何使用 BeautifulSoup,以便我可以创建一些项目。 我正在关注此链接作为教程:https://www.youtube.com/watc
我本来想解决 [SSL: CERTIFICATE_VERIFY_FAILED] 问题,因为我使用 mac 和 python 3,很多人说我应该运行/Applications/Python\3.6/In
我收到以下错误: Exception in thread Thread-3: Traceback (most recent call last): File "/Library/Frameworks/
我是一名优秀的程序员,十分优秀!