【问题标题】:Invoking mutual 2 way SSL webservice using CURL使用 CURL 调用双向 SSL Web 服务
【发布时间】:2021-06-21 16:08:04
【问题描述】:

1)我使用以下命令创建了 myfile.csr

req -out myfile.csr -new -newkey rsa:2048 -nodes -keyout myfile-pr.key
  1. 我将 myfile.csr 发送给第 3 方进行签名
  2. 第三方应用程序签名并发送给我 serverfile.pem

使用这些文件,我将能够使用 curl 命令调用 REST Web 服务。我尝试了以下命令,但它返回了未经授权的错误

curl --cacert ./serverfile.pem --key ./myfile-pr.key --cert ./myfile.csr --pass <password>   https://serverpost:port/getEmployeeInfo

【问题讨论】:

  • 可能是服务器端的错误配置、您的站点上缺少链证书、仅证书不足以进行身份​​验证、使用了错误的证书(即使您认为它是正确的)、错误的 URL 等等。不幸的是,不可能根据您问题中的信息重现任何内容,因此只能推测常见问题。
  • 感谢@SteffenUllrich 的cmets。我可以通过添加密钥库文件(由第 3 方提供的签名证书)serverfile.pem 和密码来使用soap-ui 调用Web 服务。我按照downey.io/notes/dev/curl-using-mutual-tls 中的说明进行操作。但我不确定 --cacert 是否是我从 3rd 方网络服务应用程序收到的签名证书
  • 如果应用程序返回 "unauthorized",那么 TLS 握手本身就起作用了。因此,问题可能是在握手之后对客户端证书进行了更深入的检查,并且失败了。但它也可能与证书完全无关并抱怨因为错误的用户代理、错误的访问方法、错误的 HTTP 标头等。不可能说。
  • 实际消息是 "Status": { "code": "401-01", "message": "Unauthorized client failed to present a valid digital certificate",
  • 能否提供使用curl -v时的完整输出@

标签: web-services ssl curl tls1.2


【解决方案1】:

--cacert 用于指定带有证书颁发机构 (CA) 的公共证书的文件。如果您在系统上安装了第 3 方 CA 证书,则不需要此选项。

使用--cert,您可以指定根据您的 CSR 颁发给您的签名客户端证书。来自man curl

-E, --cert
告诉 curl 在使用 HTTPS、FTPS 或其他基于 SSL 的协议获取文件时使用指定的客户端证书文件。如果使用安全传输,证书必须是 PKCS#12 格式,如果使用的是 PEM 格式 使用任何其他引擎。如果未指定可选密码,将在终端上查询。请注意,此选项假定一个“证书”文件是私钥和客户端证书连接。 内定!请参阅 -E、--cert 和 --key 以独立指定它们。

目前,您正在通过 --cert 参数传递 CSR(证书签名请求)。您的命令应如下所示:

curl --cacert ./3rd-party-ca-cert.pem --key ./myfile-pr.key --cert ./serverfile.pem --pass <password>   https://serverpost:port/getEmployeeInfo

正如我所提到的,如果您已经添加了此 CA(例如在 ubuntu 上 https://superuser.com/a/719047),则可能不需要 --cacert

检查serverfile.pem 以确保它仅包含客户端证书,而不包含第 3 方 CA 证书链。

【讨论】:

  • 它确实有效。我之前应该看过你的评论。我现在试过了,它可以工作。我试过
    curl --cacert ./serverfile.pem --key ./myfile-pr.key --cert ./serverfile.pem --pass test43@ serverpost:port/getEmployeeInfo
【解决方案2】:

... schannel:发送初始握手数据:发送 ....

curl 不支持 SChannel 命令行上的客户端证书。见this bug reportthis todo

【讨论】:

    【解决方案3】:

    @SteffenUllrich:抱歉,我应该格式化得更好。

    问题是我在 windows (curl 7.55.1) 中尝试 curl。不知道是不是版本问题。在 Linux 中执行了以下命令,它可以工作

    openssl pkcs12 -export -out combine.p12 -inkey client-cert-pr.key -in serverSelfSigned-cert.pem 
    openssl pkcs12 -in combine.p12 -out ile.key.pem -nocerts -nodes 
    openssl pkcs12 -in combine.p12 -out   file.crt.pem -clcerts -nokeys 
    curl -E ./file.crt.pem --key ./file.key.pem https://thirdpartyserver.com/employee
    

    注意事项:
    client-cert-pr.key:客户端私钥
    serverselfsigned-cert.pem:第三方发送的自签名证书

    以下其他 2 个选项也适用。谢谢@bagljas

    curl --cacert ./serverfile.pem  --key ./myfile-pr.key --cert ./serverfile.pem  --pass <passwrod>  https://serverpost:port/getEmployeeInfo
    
    curl --key ./myfile-pr.key --cert ./serverfile.pem  --pass <passwrod>  https://serverpost:port/getEmployeeInfo
    

    相同的命令在 Windows 中不起作用

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-08
      • 2018-11-13
      • 1970-01-01
      • 2019-01-05
      • 1970-01-01
      • 1970-01-01
      • 2015-04-25
      • 1970-01-01
      相关资源
      最近更新 更多