【发布时间】: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。由于某些原因,我无法使用 Requests 或 urllib3 python pacakges 并且只能使用 curl。以上让我相信有一些设置 Windows Cmd 和 Git 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