curl:(58)无法加载客户端密钥-8178

hzr*_*ari 24 ssl curl client-server

我正面临着该curl命令的SSL问题.我想使用我的SSL客户端证书和私钥来访问URL.

这是我的命令:

$ curl -k -v "https://myurl.com/" --cert ./certificate.pem --key ./private.key

* About to connect() to xx.xx.xx.xx port 23444 (#0)
*   Trying xx.xx.xx.xx... connected
* Connected to xx.xx.xx.xx (xx.xx.xx.xx) port 23444 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* warning: ignoring value of ssl.verifyhost
* Unable to load client key -8178.
* NSS error -8178
* Closing connection #0
curl: (58) Unable to load client key -8178.
Run Code Online (Sandbox Code Playgroud)

密钥是密码保护的,curl不要求我输入密码,这很奇怪.即使我传递了密码--pass,我仍然会得到同样的错误.

似乎--key没有考虑参数,因为如果我替换了foo.key,我的文件系统上不存在,我仍然得到相同的错误.

但是,如果使用:

$ wget --certificate=./certificate.pem --private-key=private.key "https://myurl.com/" --no-check-certificate
Run Code Online (Sandbox Code Playgroud)

我能够访问我的网址.

你有什么主意吗?

jfl*_*fly 24

我遇到了同样的问题,最后找到了解决方案,也许它可以帮助你.

失败是由PKCS#8格式的私钥引起的:

  • PKCS#8私钥以-----BEGIN ENCRYPTED PRIVATE KEY-----标头

    -----BEGIN PRIVATE KEY-----标头 开头

    使用此键curl+ openssl将起作用,但curl+ nss+ libnsspem.so不会.

  • 使用以
    -----BEGIN RSA PRIVATE KEY-----标头 开头的RSA私钥

    两个curl+ opensslcurl+ nss+ libnsspem.so会工作.

所以使用这个命令

openssl pkcs8 -in path/to/your/pkcs8/key -out path/to/rsa/key
Run Code Online (Sandbox Code Playgroud)

将PKCS#8密钥转换为传统的RSA密钥.

  • @Brad只需将密码短语添加到RSA私钥:`openssl rsa -des3 -in your.key -out your.encrypted.key`。-des3表示加密算法,您可以使用其他算法,例如aes128,aes192。 (3认同)