【问题标题】:Understanding curl implementation了解 curl 实现
【发布时间】:2017-05-19 12:22:48
【问题描述】:

我无法将文档中的内容付诸实践。我正在尝试使用证书对保管库服务进行身份验证。 documentation 说:

通过 API

登录的端点是 /login。客户端只需连接 他们的 TLS 证书,当登录端点被命中时,auth 后端将确定是否有匹配的可信证书 验证客户端。或者,您可以指定单个 要进行身份验证的证书角色。

$ curl --cacert ca.pem --cert cert.pem --key key.pem -d name=web \
     $VAULT_ADDR/v1/auth/cert/login -XPOST

现在我要验证的节点 IP:Port 是 17.2.24.13:8200

以下是我在远程服务器上所做的事情。

openssl s_client -showcerts -connect 17.2.24.13:8200

这会导致一个巨大的输出,其中包含一个部分 ::

-----BEGIN CERTIFICATE-----
XXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXX
-----END CERTIFICATE-----

现在我相信这是 Vault 需要的证书。

所以我把上面的输出写入vault.cer文件

现在我将使用vault.cer 进行身份验证。所以我运行下面的命令。

curl  --cert vault.crt  https://17.2.24.13:8200/v1/auth/cert/login -XPOST

但我得到的错误是:

curl: (60) Certificate key usage inadequate for attempted operation.
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
 of Certificate Authority (CA) public keys (CA certs). If the default
 bundle file isn't adequate, you can specify an alternate file
 using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
 the bundle, the certificate verification probably failed due to a
 problem with the certificate (it might be expired, or the name might
 not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
 the -k (or --insecure) option.

如果我添加 -k 标志,我会收到以下错误。

# curl -k  --cert vault.crt  https://17.2.24.13:8200/v1/auth/cert/login -XPOST
{"errors":["client certificate must be supplied"]}

所以我真的很困惑,在这种情况下我真正错过了什么。

【问题讨论】:

    标签: ssl curl https


    【解决方案1】:

    openssl s_client -showcerts -connect 17.2.24.13:8200 的输出中显示的证书是 服务器 证书,而不是 客户端 证书。前者用于向客户端验证服务器。您宁愿寻求向服务器验证客户端的身份,您需要为其提供服务器信任的证书并且您拥有该证书的公钥和私钥。

    服务器信任哪些客户端证书以及如何获取此类证书是您应该询问服务所有者的问题。

    【讨论】:

      【解决方案2】:

      您通过以下命令获取的证书是网络服务器的公钥。

      openssl s_client -showcerts -connect 17.2.24.13:8200
      

      在下面的引用中,“他们的 TLS 证书”是指客户端 (curl) 将向服务器提供的证书。

      客户端只需使用其 TLS 证书进行连接

      您需要的是一个签名的私钥。我发现@Paul Kehrer 对问题“How to create .pem files for https web server”的回答给出了关于如何生成自签名证书的良好步骤。如果您需要 CA 对其进行签名,您只需将 CSR 发送给 CA 进行签名。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-04-29
        • 2013-10-11
        • 1970-01-01
        • 1970-01-01
        • 2014-02-23
        • 2019-04-28
        • 2021-09-15
        • 2019-10-06
        相关资源
        最近更新 更多