openssl,python 请求错误:“证书验证失败"; [英] openssl, python requests error: "certificate verify failed"

查看:33
本文介绍了openssl,python 请求错误:“证书验证失败";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我从我的开发框中运行以下命令:

$ openssl s_client -connect github.com:443

我得到以下最后一行输出:

验证返回码:20(无法获取本地颁发者证书)

如果我尝试对请求执行此操作,则会收到另一个失败的请求:

<预><代码>>>>进口请求>>>r = requests.get('https://github.com/', verify=True)

出现异常:

SSLError: [Errno 1] _ssl.c:507: error:14090086:SSL 例程:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

我也可以运行带有验证标志的第一个命令并得到类似的输出:

$ openssl s_client -connect github.com:443 -verify 9...验证返回码:27(证书不受信任)

基本上这告诉我证书有问题.我可以用这两种方法指定一个特定的证书,它会起作用:

$ openssl s_client -connect github.com:443 -CAfile/etc/ssl/certs/DigiCert_High_Assurance_EV_Root_CA.pem -verify 9...验证返回码:0(确定)

和:

<预><代码>>>>r = requests.get('https://github.com/', verify='/etc/ssl/certs/DigiCert...pem')<响应[200]>

那么,对于我的问题,这里到底有什么问题?请求/openssl 不应该知道在哪里可以找到有效的证书吗?

其他信息:

  • Python==2.7.6
  • 请求==2.2.1
  • openssl 0.9.8h

另外,我知道将 verify=False 传递给 requests.get 方法也可以,但我确实想验证.

编辑

我已经确认,正如@Heikki Toivonen 在回答中指出的那样,为我正在运行的 openssl 版本指定了 -CAfile 标志.

$ openssl s_client -connect github.com:443 -CAfile `python -c'导入请求;打印(requests.certs.where())'`...验证返回码:0(确定)

所以我运行的 openssl 版本没有问题,requests 提供的默认 cacert.pem 文件也没有问题.

既然我知道 openssl 就是这样工作的,必须指定 CAfile 或查找证书的位置,我更关心让请求起作用.

如果我跑:

<预><代码>>>>r = requests.get('https://github.com/', verify='cacert.pem 文件的路径')

我仍然遇到和以前一样的错误.我什至尝试从 http://curl.haxx.se/ca 下载 cacert.pem 文件,但仍然无法正常工作.如果我指定了特定的供应商证书文件,则请求似乎只在(在这台特定机器上)工作.

附注:在我的本地机器上,一切都按预期工作.两台机器之间有几个区别.到目前为止,我还无法确定导致此问题的具体区别是什么.

解决方案

如果我从我的开发框中运行以下命令:

$ openssl s_client -connect github.com:443

我得到以下最后一行输出:

验证返回码:20(无法获取本地颁发者证书)

您缺少作为信任根的 DigiCert High Assurance EV CA-1:

$ openssl s_client -connect github.com:443已连接(00000003)depth=1 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert High Assurance EV CA-1验证错误:num=20:无法获得本地颁发者证书验证返回:0---证书链0 s:/businessCategory=Private Organization/1.3.6.1.4.1.311.60.2.1.3=US/1.3.6.1.4.1.311.60.2.1.2=Delaware/serialNumber=5157550/street=548 4th Street/1.3.6.1.4.1.311.60.2.1.2=Delaware/serialNumber=5157550/street=548/C=US/ST=加利福尼亚/L=旧金山/O=GitHub, Inc./CN=github.comi:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assurance EV CA-11 s:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assurance EV CA-1i:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assurance EV Root CA---服务器证书...开始时间:1393392088超时:300(秒)验证返回码:20(无法获取本地颁发者证书)

DigiCert 可信根授权证书下载DigiCert High Assurance EV CA-1一个>:

$ wget https://www.digicert.com/CACerts/DigiCertHighAssuranceEVCA-1.crt--2014-02-26 00:27:50-- https://www.digicert.com/CACerts/DigiCertHighAssuranceEVCA-1.crt正在解析 www.digicert.com (www.digicert.com)... 64.78.193.234...

将 DER 编码的证书转换为 PEM:

$ openssl x509 -in DigiCertHighAssuranceEVCA-1.crt -inform DER -out DigiCertHighAssuranceEVCA-1.pem -outform PEM

然后,通过 -CAfile 将其与 OpenSSL 一起使用:

$ openssl s_client -CAfile DigiCertHighAssuranceEVCA-1.pem -connect github.com:443已连接(00000003)depth=2 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert High Assurance EV Root CA验证返回:1depth=1 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert High Assurance EV CA-1验证返回:1depth=0 businessCategory = Private Organization, 1.3.6.1.4.1.311.60.2.1.3 = US, 1.3.6.1.4.1.311.60.2.1.2 = Delaware, serialNumber = 5157550, street = 548 4th Street, postalCodeC = 美国,ST = 加利福尼亚,L = 旧金山,O = "GitHub, Inc.", CN = github.com验证返回:1---证书链0 s:/businessCategory=Private Organization/1.3.6.1.4.1.311.60.2.1.3=US/1.3.6.1.4.1.311.60.2.1.2=Delaware/serialNumber=5157550/street=548 4th Street/1.3.6.1.4.1.311.60.2.1.2=Delaware/serialNumber=5157550/street=548/C=US/ST=加利福尼亚/L=旧金山/O=GitHub, Inc./CN=github.comi:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assurance EV CA-11 s:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assurance EV CA-1i:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assurance EV Root CA---服务器证书-----开始认证-----MIIHOjCCBiKgAwIBAgIQBH++LkveAITSyvjj7P5wWDANBgkqhkiG9w0BAQUFADBpMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSgwJgYDVQQDEx9EaWdpQ2VydCBIaWdoIEFzc3VyYW5jZSBFViBDQS0xMB4XDTEzMDYxMDAwMDAwMFoXDTE1MDkwMjEyMDAwMFowgfAxHTAbBgNVBA8MFFByaXZhdGUgT3JnYW5pemF0aW9uMRMwEQYLKwYBBAGCNzwCAQMTAlVTMRkwFwYLKwYBBAGCNzwCAQITCERlbGF3YXJlMRAwDgYDVQQFEwc1MTU3NTUwMRcwFQYDVQQJEw41NDggNHRoIFN0cmVldDEOMAwGA1UEERMFOTQxMDcxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TY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AgAGEAYwBjAGUAcAB0AGEAbgBjAGUAIABvAGYAIAB0AGgAZQAgAEQAaQBnAGkAQwBlAHIAAdAAgAEMAUAAvAEMAUABTACAAYQBuAGQAIAB0AGgAZQAGAFIAZQBsAHkAaQBuAGcAIABQAGEAcgB0AHkAIABBAGcAcgBlAGUAbQBlAG4AdAAgAHcAaABpAGMAaAAgAGwAaQBtAGkAdAAgAGwAaQBhAGIAaQBsAGkAdAB5ACAAYQBuAGQAIABhAHIAZQAgAGkAbgBjAG8AcgBwAG8AcgBhAHQAZQBkACAAaABlAHIAZQBpAG4AIABiAHkAIAByAGUAZgBlAHIAZQBuAGMAZQAuMH0GCCsGAQUFBwEBBHEwbzAkBggrBgEFBQcwAYYYaHR0cDovL29jc3AuZGlnaWNlcnQuY29tMEcGCCsGAQUFBzAChjtodHRwOi8vY2FjZXJ0cy5kaWdpY2VydC5jb20vRGlnaUNlcnRIaWdoQXNzdXJhbmNlRVZDQS0xLmNydDAMBgNVHRMBAf8EAjAAMA0GCSqGSIb3DQEBBQUAA4IBAQBfFW1nwzrVo94WnEUzJtU9yRZ0NMqHSBsUkG31q0eGufW44wFFZWjuqRJ1n3Ym7xF8fTjP3fdKGQnxIHKSsE0nuuh/XbQX5DpBJknHdGFoLwY8xZ9JPI57vgvzLo8+fwHyZp3Vm/o5IYLEQViSo+nlOSUQ8YAVqu6KcsP/e612UiqS+UMBmgdx9KPDDzZy4MJZC2hbfUoXj9A54mJN8cuEOPyw3c3yKOcq/h48KzVguQXiSdJbwfqNIbQ9oJM+YzDjzS62+TCtNSNWzWbwABZCmuQxK0oEOSbTmbhxUF7rND3/+mx9u8cY//7uAxLWYS5gIZlCbxcf0lkiKSHJB319-----结束证书-----subject=/businessCategory=Private Organization/1.3.6.1.4.1.311.60.2.1.3=US/1.3.6.1.4.1.311.60.2.1.2=Delaware/serialNumber=5157550/street=548 4th Street/postalCodeC=US/ST=California/L=San Francisco/O=GitHub, Inc./CN=github.comissuer=/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assurance EV CA-1---未发送客户端证书 CA 名称---SSL 握手已读取 4139 个字节并写入 446 个字节---新,TLSv1/SSLv3,密码是 ECDHE-RSA-AES128-GCM-SHA256服务器公钥为 2048 位支持安全重新协商压缩:无扩展:无SSL 会话:协议:TLSv1.2密码:ECDHE-RSA-AES128-GCM-SHA256会话 ID:59D2883BBCE8E81E63E5551FAE7D1ACC00C49A9473C1618237BBBB0DD9016B8D会话 ID-ctx:万能钥匙:B6D2763FF29E77C67AD83296946A4D44CDBA4F37ED6F20BC27602F1B1A2D137FACDEAC862C11279C01095594F9776F79键参数:无PSK 身份:无PSK 身份提示:无SRP 用户名:无开始时间:1393392673超时:300(秒)验证返回码:0(确定)

<小时><块引用>

requests/openssl 不应该知道在哪里可以找到有效的证书吗?

没有.默认情况下,OpenSSL 不信任任何内容.它与浏览器模型截然相反,在浏览器模型中,默认情况下几乎所有内容都是可信的.

<小时>

 $ openssl s_client -connect github.com:443 -CAfile `python -c' 导入请求;打印(requests.certs.where())'`...>>>r = requests.get('https://github.com/', verify='cacert.pem 文件的路径')

当您知道一个认证站点公钥的 CA 时,您为什么还要信任数百个 CA 和从属 CA(re:cacert.pem)?信任所需的根,仅此而已:DigiCert High Assurance EV CA-1.

信任一切 - 就像在浏览器模型中一样 - 这使得 Comodo Hacker 在 Diginotar 根目录遭到破坏时可以欺骗 Gmail、Hotmail、Yahoo 等的证书.

If I run the following command from my development box:

$ openssl s_client -connect github.com:443

I get the following last line of output:

Verify return code: 20 (unable to get local issuer certificate)

If I try to do this with requests I get another failed request:

>>> import requests
>>> r = requests.get('https://github.com/', verify=True)

With an exception raised:

SSLError: [Errno 1] _ssl.c:507: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

I can also run the first command with the verify flag and get similar output:

$ openssl s_client -connect github.com:443 -verify 9
...
Verify return code: 27 (certificate not trusted)

Basically this is telling me that there is a problem with the certificates. I can specify a specific certificate with both methods and it will work:

$ openssl s_client -connect github.com:443 -CAfile /etc/ssl/certs/DigiCert_High_Assurance_EV_Root_CA.pem -verify 9
...
Verify return code: 0 (ok)

and:

>>> r = requests.get('https://github.com/', verify='/etc/ssl/certs/DigiCert...pem')
<Response [200]>

So, to my question, what exactly is wrong here? Shouldn't requests/openssl already know where to find valid certs?

Other Info:

  • Python==2.7.6
  • requests==2.2.1
  • openssl 0.9.8h

Also, I know passing verify=False to the requests.get method will work too, but I do want to verify.

EDIT

I've confirmed that, as @Heikki Toivonen indicated in an answer, specifying the -CAfile flag for the version of openssl that I'm running works.

$ openssl s_client -connect github.com:443 -CAfile `python -c 'import requests; print(requests.certs.where())'`
...
Verify return code: 0 (ok)

So there is nothing wrong with the version of openssl that I'm running, and there is nothing wrong with the default cacert.pem file that requests provides.

Now that I know openssl is meant to work that way, that the CAfile or the place to find certs has to be specified, I'm more concerned about getting requests to work.

If I run:

>>> r = requests.get('https://github.com/', verify='path to cacert.pem file')

I'm still getting the same error as before. I even tried downloading the cacert.pem file from http://curl.haxx.se/ca and it still didn't work. requests only seems to work (on this specific machine) if I specify a specific vendor cert file.

A side note: On my local machine everything is working as expected. There are several difference between the two machines though. I so far haven't been able to determine what the specific difference is that causes this issue.

解决方案

If I run the following command from my development box:

$ openssl s_client -connect github.com:443

I get the following last line of output:

Verify return code: 20 (unable to get local issuer certificate)

You are missing DigiCert High Assurance EV CA-1 as a root of trust:

$ openssl s_client -connect github.com:443
CONNECTED(00000003)
depth=1 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert High Assurance EV CA-1
verify error:num=20:unable to get local issuer certificate
verify return:0
---
Certificate chain
 0 s:/businessCategory=Private Organization/1.3.6.1.4.1.311.60.2.1.3=US/1.3.6.1.4.1.311.60.2.1.2=Delaware/serialNumber=5157550/street=548 4th Street/postalCode=94107/C=US/ST=California/L=San Francisco/O=GitHub, Inc./CN=github.com
   i:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assurance EV CA-1
 1 s:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assurance EV CA-1
   i:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assurance EV Root CA
---
Server certificate
...
Start Time: 1393392088
Timeout   : 300 (sec)
Verify return code: 20 (unable to get local issuer certificate)

Download DigiCert High Assurance EV CA-1 from DigiCert Trusted Root Authority Certificates:

$ wget https://www.digicert.com/CACerts/DigiCertHighAssuranceEVCA-1.crt
--2014-02-26 00:27:50--  https://www.digicert.com/CACerts/DigiCertHighAssuranceEVCA-1.crt
Resolving www.digicert.com (www.digicert.com)... 64.78.193.234
...

Convert the DER encoded certifcate to PEM:

$ openssl x509 -in DigiCertHighAssuranceEVCA-1.crt -inform DER -out DigiCertHighAssuranceEVCA-1.pem -outform PEM

Then, use it with OpenSSL via the -CAfile:

$ openssl s_client -CAfile DigiCertHighAssuranceEVCA-1.pem -connect github.com:443
CONNECTED(00000003)
depth=2 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert High Assurance EV Root CA
verify return:1
depth=1 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert High Assurance EV CA-1
verify return:1
depth=0 businessCategory = Private Organization, 1.3.6.1.4.1.311.60.2.1.3 = US, 1.3.6.1.4.1.311.60.2.1.2 = Delaware, serialNumber = 5157550, street = 548 4th Street, postalCode = 94107, C = US, ST = California, L = San Francisco, O = "GitHub, Inc.", CN = github.com
verify return:1
---
Certificate chain
 0 s:/businessCategory=Private Organization/1.3.6.1.4.1.311.60.2.1.3=US/1.3.6.1.4.1.311.60.2.1.2=Delaware/serialNumber=5157550/street=548 4th Street/postalCode=94107/C=US/ST=California/L=San Francisco/O=GitHub, Inc./CN=github.com
   i:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assurance EV CA-1
 1 s:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assurance EV CA-1
   i:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assur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NzdXJhbmNlRVZDQS0xLmNydDAMBgNVHRMBAf8EAjAAMA0GCSqG
SIb3DQEBBQUAA4IBAQBfFW1nwzrVo94WnEUzJtU9yRZ0NMqHSBsUkG31q0eGufW4
4wFFZWjuqRJ1n3Ym7xF8fTjP3fdKGQnxIHKSsE0nuuh/XbQX5DpBJknHdGFoLwY8
xZ9JPI57vgvzLo8+fwHyZp3Vm/o5IYLEQViSo+nlOSUQ8YAVqu6KcsP/e612UiqS
+UMBmgdx9KPDDzZy4MJZC2hbfUoXj9A54mJN8cuEOPyw3c3yKOcq/h48KzVguQXi
SdJbwfqNIbQ9oJM+YzDjzS62+TCtNSNWzWbwABZCmuQxK0oEOSbTmbhxUF7rND3/
+mx9u8cY//7uAxLWYS5gIZlCbxcf0lkiKSHJB319
-----END CERTIFICATE-----
subject=/businessCategory=Private Organization/1.3.6.1.4.1.311.60.2.1.3=US/1.3.6.1.4.1.311.60.2.1.2=Delaware/serialNumber=5157550/street=548 4th Street/postalCode=94107/C=US/ST=California/L=San Francisco/O=GitHub, Inc./CN=github.com
issuer=/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assurance EV CA-1
---
No client certificate CA names sent
---
SSL handshake has read 4139 bytes and written 446 bytes
---
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES128-GCM-SHA256
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : ECDHE-RSA-AES128-GCM-SHA256
    Session-ID: 59D2883BBCE8E81E63E5551FAE7D1ACC00C49A9473C1618237BBBB0DD9016B8D
    Session-ID-ctx: 
    Master-Key: B6D2763FF29E77C67AD83296946A4D44CDBA4F37ED6F20BC27602F1B1A2D137FACDEAC862C11279C01095594F9776F79
    Key-Arg   : None
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    Start Time: 1393392673
    Timeout   : 300 (sec)
    Verify return code: 0 (ok)


Shouldn't requests/openssl already know where to find valid certs?

No. OpenSSL trusts nothing by default. Its a polar opposite of a browser's model, where nearly everything is trusted by default.


 $ openssl s_client -connect github.com:443 -CAfile `python -c 'import requests; print(requests.certs.where())'`
 ...
 >>> r = requests.get('https://github.com/', verify='path to cacert.pem file')

Why would you trust hundreds of CAs and subordinate CAs (re: cacert.pem) when you know the one CA that is certifying the public key for the site? Trust the one required root and nothing more: DigiCert High Assurance EV CA-1.

Trusting everything - as in the browser's model - is what allowed Comodo Hacker to spoof certificates for Gmail, Hotmail, Yahoo, etc when the Diginotar root was compromised.

这篇关于openssl,python 请求错误:“证书验证失败";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆