【问题标题】:OpenSSL error:02001002:system library:fopen:No such file or directory no key found, wrong pass phrase, or wrong file format, git bash vs cmdOpenSSL错误:02001002:系统库:fopen:没有这样的文件或目录没有找到密钥,错误的密码或错误的文件格式,git bash vs cmd
【发布时间】:2020-08-15 05:49:45
【问题描述】:

我有一个使用相互身份验证公开 url 的应用程序。现在我正在编写一个 python 脚本,它使用 Popen 运行 curl 命令以连接到应用程序并获取所需的数据。但是当我运行 python 脚本时,出现以下错误。

curl: (58) could not load PEM client certificate, OpenSSL error error:02001002:system library:fopen:No such file or directory, (no key found, wrong pass phrase, or wrong file format?)

我在 Windows 7 机器上运行该应用程序。我安装了 curl 和 openssl。下面给出了运行的命令

curl -v https://localhost:9400/<URL> -H "Connection:close" --cacert 'C:/local_cert/root.crt' --cert 'C:/local_cert/client.crt' --key 'C:/local_cert/client.key' --pass client_key_passwd

现在为了测试,我在 Git Bash for windows 中运行了相同的命令。我成功地得到了结果。 但是当我在 Git Cmd for windows 或 Windows Cmd 中运行相同的命令时,我得到了同样的上述错误。

我检查了证书的路径是否正确,它们是 PEM 格式,我安装了 openssl 和 curl。由于某些原因,我无法使用 Requestsurllib3 python pacakges 并且只能使用 curl。以上让我相信有一些设置 Windows CmdGit Cmd for windows 缺少一些设置,但我不确定它可能是什么。

【问题讨论】:

  • 为清楚起见,root.crt 是用于签署客户端 crt 的自签名证书。两者都是使用 openssl 和 windows CLI 生成的。
  • 对 curl 中的证书一无所知,但您不应该使用反斜杠吗?又名 C:\local_cert\root.crt 而不是 C:/local_cert/root.crt
  • 使用正斜杠是指定路径的unix风格。它是一种平台中立的方式,从某种意义上说,Windows 系统也尊重这种指定路径的方式

标签: python bash curl openssl mutual-authentication


【解决方案1】:

在尝试了很多事情之后,我终于找到了答案。错误表示找不到文件、密码错误或格式错误。由于该命令在 git bash 中工作,我确信它不是文件或密码的问题。专注于没有找到我在下面的链接中找到的文件

Windows PATH to posix path conversion in bash

这给了我一个想法,可能是我指定路径的方式不正确,具体取决于我们使用的 curl 版本。因此,在尝试了各种组合之后,我发现如果你在 git bash 中使用普通 curl,那么两个 cmd 都可以工作

curl -v https://localhost:9400/<URL> -H "Connection:close" --cacert 'C:/local_cert/root.crt' --cert 'C:/local_cert/client.crt' --key 'C:/local_cert/client.key' --pass client_key_passwd

curl -v https://localhost:9400/<URL> -H "Connection:close" --cacert C:/local_cert/root.crt --cert C:/local_cert/client.crt --key C:/local_cert/client.key --pass client_key_passwd

但是在 windows Cmd 中或从 python 调用 curl 时,只有在 cmd 之后才能工作

curl -v https://localhost:9400/<URL> -H "Connection:close" --cacert C:/local_cert/root.crt --cert C:/local_cert/client.crt --key C:/local_cert/client.key --pass client_key_passwd

所以简而言之,引号是个问题,因为调用 curl 实用程序的方式以及使用的 curl 版本(是否为 Windows 编译)对引号的解释会有所不同。

【讨论】:

  • 你的最后两个命令对我来说看起来一样。为什么一个工作而不是另一个?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-06-25
  • 1970-01-01
  • 1970-01-01
  • 2021-03-29
  • 2018-02-09
  • 2021-04-29
  • 2022-07-21
相关资源
最近更新 更多