$ curl https://expired.badssl.comcurl: (60) SSL certificate problem: certificate has expiredMore details here: https://curl.se/docs/sslcerts.htmlcurl failed to verify the legitimacy of the server and therefore could notestablish a secure connection to it. To learn more about this situation andhow to fix it, please visit the web page mentioned above.
这是因为在默认情况下,cURL 使用 SSL 证书进行连接,如果指定的网站配置错误或证书过期,则会引发错误。
下面我们看一下如何忽略其中的 SSL 证书错误。
使用 cURL 忽略 SSL 证书错误
一般来说,直接忽略错误然后继续连接故障网站是不推荐的。但是如果你信任该网站,那就可以。
$ curl --insecure https://expired.badssl.com<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="shortcut icon" href="/icons/favicon-red.ico"/><link rel="apple-touch-icon" href="/icons/icon-red.png"/><title>expired.badssl.com</title><link rel="stylesheet" href="/style.css"><style>body { background: red; }</style></head><body><div id="content"><h1 style="font-size: 12vw;">expired.<br>badssl.com</h1></div></body></html>
$ curl -k https://expired.badssl.com<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="shortcut icon" href="/icons/favicon-red.ico"/><link rel="apple-touch-icon" href="/icons/icon-red.png"/><title>expired.badssl.com</title><link rel="stylesheet" href="/style.css"><style>body { background: red; }</style></head><body><div id="content"><h1 style="font-size: 12vw;">expired.<br>badssl.com</h1></div></body></html>
对所有 SSL 连接都使用 --insecure 选项
注意:除非在隔离或测试环境下可以执行此操作,否则不建议这样做。
echo "insecure" >> ~/.curlrc
然后,在不使用 --insecure 选项的情况下,再次直接使用 curl 连接 html地址,也是可以成功的:
$ curl https://expired.badssl.com<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="shortcut icon" href="/icons/favicon-red.ico"/><link rel="apple-touch-icon" href="/icons/icon-red.png"/><title>expired.badssl.com</title><link rel="stylesheet" href="/style.css"><style>body { background: red; }</style></head><body><div id="content"><h1 style="font-size: 12vw;">expired.<br>badssl.com</h1></div></body></html>
忽略 wget 的 SSL 证书错误
$ wget https://expired.badssl.com--2022-11-17 14:35:55-- https://expired.badssl.com/Resolving expired.badssl.com (expired.badssl.com)... 104.154.89.105Connecting to expired.badssl.com (expired.badssl.com)|104.154.89.105|:443... connected.ERROR: cannot verify expired.badssl.com's certificate, issued by ‘CN=COMODO RSA Domain Validation Secure Server CA,O=COMODO CA Limited,L=Salford,ST=Greater Manchester,C=GB’:Issued certificate has expired.To connect to expired.badssl.com insecurely, use `--no-check-certificate'.
默认情况下,wget会检查有效的SSL证书,以便您可以建立可靠的连接,如果没有,则会抛出一个错误,表示颁发的证书已过期。
$ wget --no-check-certificate https://expired.badssl.com--2022-11-17 15:18:07-- https://expired.badssl.com/Resolving expired.badssl.com (expired.badssl.com)... 104.154.89.105Connecting to expired.badssl.com (expired.badssl.com)|104.154.89.105|:443... connected.WARNING: cannot verify expired.badssl.com's certificate, issued by ‘CN=COMODO RSA Domain Validation Secure Server CA,O=COMODO CA Limited,L=Salford,ST=Greater Manchester,C=GB’:Issued certificate has expired.HTTP request sent, awaiting response... 200 OKLength: 494 [text/html]Saving to: ‘index.html.1’index.html.1 100%[===================>] 494 --.-KB/s in 0s2022-11-17 15:18:08 (209 MB/s) - ‘index.html.1’ saved [494/494]
跳过认证检查
$ wget https://expired.badssl.com--2022-11-17 15:41:50-- https://expired.badssl.com/Resolving expired.badssl.com (expired.badssl.com)... 104.154.89.105Connecting to expired.badssl.com (expired.badssl.com)|104.154.89.105|:443... connected.WARNING: cannot verify expired.badssl.com's certificate, issued by ‘CN=COMODO RSA Domain Validation Secure Server CA,O=COMODO CA Limited,L=Salford,ST=Greater Manchester,C=GB’:Issued certificate has expired.HTTP request sent, awaiting response... 200 OKLength: 494 [text/html]Saving to: ‘index.html.2’index.html.2 100%[===================>] 494 --.-KB/s in 0s2022-11-17 15:41:51 (191 MB/s) - ‘index.html.2’ saved [494/494]
文章转载自TIAP,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




