Curl SSL错误证书已过期

Curl SSL错误证书已过期

我正在使用 python 从 API URL 获取结果。但事情是这样的:

Traceback (most recent call last):
  File "grafana-utils.py", line 95, in <module>
    grafana_backup_all()
  File "/home/trobz/.local/lib/python2.7/site-packages/click/core.py", line 700, in __call__
    return self.main(*args, **kwargs)
  File "/home/trobz/.local/lib/python2.7/site-packages/click/core.py", line 680, in main
    rv = self.invoke(ctx)
  File "/home/trobz/.local/lib/python2.7/site-packages/click/core.py", line 873, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/trobz/.local/lib/python2.7/site-packages/click/core.py", line 508, in invoke
    return callback(*args, **kwargs)
  File "grafana-utils.py", line 56, in grafana_backup_all
    data = json.loads(api_grafana_get_data(host, key))
  File "grafana-utils.py", line 15, in api_grafana_get_data
    data = requests.get( host + '/api/search', headers=key).text
  File "/home/trobz/.local/lib/python2.7/site-packages/requests/api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "/home/trobz/.local/lib/python2.7/site-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/trobz/.local/lib/python2.7/site-packages/requests/sessions.py", line 512, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/trobz/.local/lib/python2.7/site-packages/requests/sessions.py", line 622, in send
    r = adapter.send(request, **kwargs)
  File "/home/trobz/.local/lib/python2.7/site-packages/requests/adapters.py", line 511, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='grafana.trobz.com', port=443): Max retries exceeded with url: /api/search (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))

Curl 也有同样的问题:

curl: (60) SSL certificate problem: certificate has expired
More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

我看看https://curl.haxx.se/docs/sslcerts.html但仍然不明白如何解决这个问题。

No client certificate CA names sent
Peer signing digest: SHA512
Server Temp Key: X25519, 253 bits
---
SSL handshake has read 3208 bytes and written 295 bytes
Verification error: certificate has expired
---
New, TLSv1.2, Cipher is ECDHE-RSA-AES256-GCM-SHA384
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : ECDHE-RSA-AES256-GCM-SHA384
    Session-ID: D84D38798779A0009ED548D3C05188D46793E9BCEF4F79DA65C47CF27110282F
    Session-ID-ctx: 
    Master-Key: 5F60F42E744D123FB51B271E347C9B6690F4E13D4A0D2634D9468B427D5A6C2A6D6DCB855BE2561EF34477A40190890B
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    Start Time: 1541057942
    Timeout   : 7200 (sec)
    Verify return code: 10 (certificate has expired)
    Extended master secret: yes
---
closed

我不明白这个问题只发生在这台机器上,在我的本地机器上它可以工作并连接到主机。

有些人告诉我curl -k 主机但我不喜欢这样,因为缺乏安全感。

还有一件事,我确定服务器没有问题。所以问题看起来是出在机器上。

服务器在这里:

Resolves to   grafana.trobz.com
Expiration date   Dec 31, 2018
Vendor signed Yes
Hostname  Matches
Key length    2048
Server type   nginx
Common name   *.trobz.com
SAN   *.trobz.com, trobz.com
Organization  Let's Encrypt
Common name   Let's Encrypt Authority X3 Let's Encrypt Authority X3
Serial number 03:1b:2d:bb:65:5d:b4:b2:70:c3:18:45:0a:ea:db:05:62:48
Signature algorithm   sha256WithRSAEncryption
Fingerprint (SHA-1)   A35C6987779070AB273471A0E2FA55AB87621822
Fingerprint (MD5) A4BBF42BED757F638CB273095102E807

有人可以帮忙吗?

答案1

SSL 证书问题:证书已过期

TLS 证书包含两个日期,并将在开始日期之前无效过期后无效如果客户端上的时间/日期超出该时间范围,验证将失败。

这可能有两个原因,证书实际上已过期,或者客户端的时钟偏差很大。

答案2

如果您在进行 CURL 调用时遇到此问题,您可以跳过下面的 curl 参数(PHP curl 调用示例):

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

或者

CURLOPT_SSL_VERIFYPEER => 0

建议保持生产 CURL 调用运行,直到找到错误的根本原因“Curl:SSL 错误证书已过期”

相关内容