cUrl 中的 --key 是什么意思

What means --key in cUrl

我开始“玩”curl 和 Ssl。我正在使用客户端证书,并且正在使用 curl 将 api 请求发送到服务器。在 curl 命令中,我指定了客户端证书、私钥文件和密码。为什么我需要使用 --key 选项指定私钥?我是将文件发送到服务器还是只是通知 curl 如何解密接收到的数据的一种方式?

您没有将私钥发送到服务器。使用 key 以便服务器可以验证您提供的客户端证书确实已颁发给您并且您拥有相应的私钥。它用于对服务器发送的一段数据进行签名。只有这个签名的数据被传输而不是密钥。服务器然后使用您的证书(由服务器信任的 CA 签名)解密数据并确认您拥有相应的私钥。 (有关 TLS 在 TLS 握手期间如何检查客户端证书的更多信息,请参阅 this answer or this shorter one one

这类似于您需要向浏览器提供(通常是 PKCS#12 文件)以便访问需要客户端证书身份验证的网页。 PCKS#12 是一种包含捆绑证书和私钥的存档格式。 curl 也允许您在 --cert 选项中使用此格式,来自 man page:

-E, --cert <certificate[:password]>
(TLS) Tells curl to use the specified client certificate file when getting a file with HTTPS, FTPS or another SSL-based protocol. The certificate must be in PKCS#12 format if using Secure Transport, or PEM format if using any other engine.