因此,我有一个简单的GO服务器在端口上运行8080,使用我使用以下命令创建的自签名证书:
openssl req -new -newkey rsa:4096 -x509 -sha256 -days 365 -nodes -out local.crt -keyout local.key\nRun Code Online (Sandbox Code Playgroud)\n\n创建它时,我将字段设置为以下值:\n
\n如你所见,我跳过了除fully qualified host name我设置的之外的所有内容go-auth
local.key我使用和文件成功启动了我的 go 服务器local.crt。
我尝试像这样卷曲它:
\n\n\xe2\x9e\x9c certs git:(master) \xe2\x9c\x97 curl --proxy-cacert local.crt https://go-auth/\ncurl: (6) Could not resolve host: go-auth\n\n\xe2\x9e\x9c certs git:(master) \xe2\x9c\x97 curl --proxy-cacert local.crt https://localhost:8080/\ncurl: (60) SSL certificate problem: self signed certificate\nMore details here: https://curl.haxx.se/docs/sslcerts.html\n\ncurl failed to verify the legitimacy of the server and therefore could not\nestablish a secure connection to it. To learn more about this situation and\nhow to fix it, please visit the web page mentioned above.\nRun Code Online (Sandbox Code Playgroud)\n\n之后,我尝试从正在运行的服务器获取证书并将其保存到cacert.pem文件中,然后再次尝试:
\n\n\xe2\x9e\x9c certs git:(master) \xe2\x9c\x97 echo quit | openssl s_client -showcerts -servername go-auth -connect localhost:8080 > cacert.pem\ndepth=0 CN = go-auth\nverify error:num=18:self signed certificate\nverify return:1\ndepth=0 CN = go-auth\nverify return:1\nDONE\n\n\xe2\x9e\x9c certs git:(master) \xe2\x9c\x97 curl --cacert cacert.pem https://go-auth/\ncurl: (6) Could not resolve host: go-auth\n\n\xe2\x9e\x9c certs git:(master) \xe2\x9c\x97 curl --proxy-cacert cacert.pem https://go-auth/\ncurl: (6) Could not resolve host: go-auth\nRun Code Online (Sandbox Code Playgroud)\n\n此时我不知道,我试图遵循这个问题的答案:使用带有 cURL 的自签名证书?但没有得到想要的结果。
\n您可以使用该-k参数来跳过证书验证。
您的命令必须类似于以下命令:
curl -vk https://localhost:8080/
Run Code Online (Sandbox Code Playgroud)
-v启用一些调试信息-k禁用证书验证如果要启用证书验证,有两种方法:
将证书添加并信任到您当前的 CA 列表
通过这种方式,您将“接受”您的自签名证书作为有效证书,并且您将能够使用任何类型的(显然是从您的计算机)调用该服务HTTP 客户端(Java、Go、cURL 等)。
使用--cacert命令的参数cURL来指定与要使用的证书相关的路径,以便对服务进行身份验证。