Cla*_*diu 37 linux certificate curl
要检查 google.com 的证书是否已被吊销,我尝试了以下命令:
curl https://www.google.com --cacert GeoTrust_Global_CA.pem --crlfile gtglobal.pem -v
Run Code Online (Sandbox Code Playgroud)
,但我遇到了可怕的“SSL 证书问题”错误:
* About to connect() to www.google.com port 443 (#0)
* Trying 81.24.29.91... connected
* successfully set certificate verify locations:
* CAfile: GeoTrust_Global_CA.pem
CApath: /etc/ssl/certs
* successfully load CRL file:
* CRLfile: gtglobal.pem
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS alert, Server hello (2):
* SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
* Closing connection #0
curl: (60) SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
More details here: http://curl.haxx.se/docs/sslcerts.html
Run Code Online (Sandbox Code Playgroud)
我猜这个错误是不正确的,因为谷歌应该有一个有效的证书。
您知道我如何发出正确执行此操作的 curl 命令吗?
更多细节
如果你想知道我为什么在 curl 命令中使用这些特定文件(GeoTrust_Global_CA.pem 和 gtglobal.pem),我是这样进行的:
Ant*_*sta 21
这是我的日常脚本:
curl --insecure -vvI https://www.google.com 2>&1 | awk 'BEGIN { cert=0 } /^\* Server certificate:/ { cert=1 } /^\*/ { if (cert) print }'
Run Code Online (Sandbox Code Playgroud)
输出:
* Server certificate:
* subject: C=US; ST=California; L=Mountain View; O=Google Inc; CN=www.google.com
* start date: 2016-01-07 11:34:33 GMT
* expire date: 2016-04-06 00:00:00 GMT
* issuer: C=US; O=Google Inc; CN=Google Internet Authority G2
* SSL certificate verify ok.
* Server GFE/2.0 is not blacklisted
* Connection #0 to host www.google.com left intact
Run Code Online (Sandbox Code Playgroud)
MKa*_*ama 15
显然,您不能仅通过一个简单的请求来验证站点。请参阅/sf/ask/1137085911/?lq=1和有关 stackoverflow 的旧相关问题。
curl 也不适用于我的证书吊销列表,无论是在 Windows 上,还是在 Linux 上。为什么要使用curl?Openssl似乎更合适:
openssl s_client -connect www.google.com:443
Run Code Online (Sandbox Code Playgroud)
我们得到
---
Certificate chain
0 s:/C=US/ST=California/L=Mountain View/O=Google Inc/CN=www.google.com
i:/C=US/O=Google Inc/CN=Google Internet Authority G2
1 s:/C=US/O=Google Inc/CN=Google Internet Authority G2
i:/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA
2 s:/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA
i:/C=US/O=Equifax/OU=Equifax Secure Certificate Authority
---
Run Code Online (Sandbox Code Playgroud)
然后我们可以检查一些证书:
curl http://pki.google.com/GIAG2.crt | openssl x509 -inform der -text
Run Code Online (Sandbox Code Playgroud)
grep crl
在上述命令的输出中。有趣的部分是:
X509v3 CRL Distribution Points:
URI:http://crl.geotrust.com/crls/gtglobal.crl
Authority Information Access:
OCSP - URI:http://gtglobal-ocsp.geotrust.com
Run Code Online (Sandbox Code Playgroud)
现在我们可以手动检查 crl:
curl http://crl.geotrust.com/crls/gtglobal.crl | openssl crl -inform der -text
curl http://pki.google.com/GIAG2.crl | openssl crl -inform der -text
Run Code Online (Sandbox Code Playgroud)
现在我们看到一个吊销证书的列表。恕我直言,使用 curl 是不够的,需要另一个程序来检查证书。通过做一个简单的
strace curl https://www.google.com -v
Run Code Online (Sandbox Code Playgroud)
我们看到 curl 没有检查撤销(甚至没有连接到相关位置)。它只是说
* Server certificate:
* subject: C=US; ST=California; L=Mountain View; O=Google Inc; CN=www.google.com
* start date: 2014-04-09 11:40:11 GMT
* expire date: 2014-07-08 00:00:00 GMT
* subjectAltName: www.google.com matched
* issuer: C=US; O=Google Inc; CN=Google Internet Authority G2
* SSL certificate verify ok.
Run Code Online (Sandbox Code Playgroud)
小智 6
自 7.41.0 起,curl 有一个--cert-status
选项,但它对我不起作用:
$ curl --cert-status https://www.google.com
curl: (91) No OCSP response received
Run Code Online (Sandbox Code Playgroud)
看来只有在服务器配置了 OCSP 装订时它才有效,并且不会导致curl 发出自己的 OCSP 请求。
我按照https://raymii.org/s/articles/OpenSSL_Manually_Verify_a_certificate_against_an_OCSP.html中的步骤使用 openssl 取得了更好的成功
获取证书:
$ openssl s_client -connect www.google.com:443 2>&1 < /dev/null | sed -n '/-----BEGIN/,/-----END/p' > /tmp/google.pem
Run Code Online (Sandbox Code Playgroud)
输出证书的 OCSP URI:
$ openssl x509 -noout -ocsp_uri -in /tmp/google.pem
http://ocsp.pki.goog/gts1o1
Run Code Online (Sandbox Code Playgroud)
通过以下方式从 certs 1-n 输出构建 /tmp/chain.pem:
openssl s_client -connect www.google.com:443 -showcerts 2>&1 < /dev/null
Run Code Online (Sandbox Code Playgroud)
将每个证书复制到 chain.pem 文件中,包括 -----BEGIN CERTIFICATE----- 和 -----END CERTIFICATE----- 以及其间的所有内容。不要包含第 0 个证书,因为它位于 google.pem 文件中。
发出 OCSP 请求:
openssl ocsp -issuer /tmp/chain.pem -cert /tmp/google.pem -text -url http://ocsp.pki.goog/gts1o1
...
Response verify OK
/tmp/google.pem: good
This Update: Mar 24 12:40:59 2020 GMT
Next Update: Mar 31 12:40:59 2020 GMT
Run Code Online (Sandbox Code Playgroud)
显然,这是 Windows 上一个非常常见的问题,正如stackoverflow 上的这个问题所示。我特别指的是用户 \xd0\x90\xd1\x80\xd1\x82\xd1\x83\xd1\x80 \xd0\x9a\xd1\x83\xd1\x80\xd0\xb8\xd1\x86\ 的答案xd1\x8b\xd0\xbd,为了您的方便我在这里引用:
\n\n\n\n\n这是 Windows 中非常常见的问题。您只需将\n 设置
\n\ncacert.pem
为curl.cainfo
。从 PHP 5.3.7 开始你可以这样做:
\n\n\n
\n\n- 下载http://curl.haxx.se/ca/cacert.pem并将其保存在某处。
\n- 更新
\nphp.ini
--添加curl.cainfo =“PATH_TO/cacert.pem”否则,您需要对每个 cURL 资源执行以下操作:
\n\nRun Code Online (Sandbox Code Playgroud)\ncurl_setopt ($ch, CURLOPT_CAINFO, "PATH_TO/cacert.pem");\n
另外,这篇文章可能也有用。
\n 归档时间: |
|
查看次数: |
112223 次 |
最近记录: |