【发布时间】:2020-05-04 14:04:13
【问题描述】:
所以我有一个简单的 GO 服务器在端口 8080 上运行,使用的是我使用以下命令创建的自签名证书:
openssl req -new -newkey rsa:4096 -x509 -sha256 -days 365 -nodes -out local.crt -keyout local.key
创建它时,我将字段设置为以下值:
如您所见,我跳过了除fully qualified host name 之外的所有内容,我将其设置为go-auth
我使用 local.key 和 local.crt 文件成功启动了我的 go 服务器。
我尝试过 cURLing 如下:
➜ certs git:(master) ✗ curl --proxy-cacert local.crt https://go-auth/
curl: (6) Could not resolve host: go-auth
➜ certs git:(master) ✗ curl --proxy-cacert local.crt https://localhost:8080/
curl: (60) SSL certificate problem: self signed certificate
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.
之后我尝试从正在运行的服务器获取证书并将其保存到 cacert.pem 文件并再次尝试:
➜ certs git:(master) ✗ echo quit | openssl s_client -showcerts -servername go-auth -connect localhost:8080 > cacert.pem
depth=0 CN = go-auth
verify error:num=18:self signed certificate
verify return:1
depth=0 CN = go-auth
verify return:1
DONE
➜ certs git:(master) ✗ curl --cacert cacert.pem https://go-auth/
curl: (6) Could not resolve host: go-auth
➜ certs git:(master) ✗ curl --proxy-cacert cacert.pem https://go-auth/
curl: (6) Could not resolve host: go-auth
此时我不知道,我试图按照这个问题的答案:Use self signed certificate with cURL? 但没有得到想要的结果。
【问题讨论】:
-
“无法解析主机”是 DNS 错误,而不是与证书相关的错误。您需要首先确保您的
go-auth名称在您的系统上正确解析,例如使用/etc/hosts或等效名称。但这与编程无关。 -
试试这个
curl --cacert cacert.pem https://localhost:8080/,--proxy-cacert用于HTTPS代理 -
尝试使用标志
--insecure禁用 curl 的证书验证。您可以查看github.com/FiloSottile/mkcert 中的mkcert工具来生成本地CA 和本地开发证书。 -
根据你拥有的卷发,你在本地主机上运行它。您的主机名不是
go-auth。即使你使用正确的证书与curl,它也会失败,因为主机名不是go-auth,所以你必须使用localhost对其进行curl,使用curl -k来禁用证书验证。