Pekko Tuomisto
Pekko Tuomisto

Reputation: 11

cUrl can't load pem certs from specified path

This is a strange one: trying to connect to a server that requires local pem files, but I get this error:
cURL error 58: unable to load client key: -8178 (SEC_ERROR_BAD_KEY)

Strange thing is, that if I navigate to the path where the pem files are, it works. If I give the exact path, it gives the error.

Here are the commands that work:
cd /path/to
curl --insecure --key key.pem --cacert ca.pem --cert client.pem:xxxxxxxxx https://server.com/action/id
(replies with proper HTML)

These ones give the error:
cd /path/to
curl --insecure --key /path/to/key.pem --cacert /path/to/ca.pem --cert /path/to/client.pem:xxxxxxxxx https://server.com/action/file

Any ideas on how to run the command while also giving the exact paths? I'm completely bamboozled...

EDIT: Just realized it could be helpful:

curl --version:
curl 7.51.0 (x86_64-redhat-linux-gnu) libcurl/7.51.0 NSS/3.28.4 zlib/1.2.8 libidn2/0.16 libpsl/0.6.2 (+libicu/50.1.2) libssh2/1.4.2 nghttp2/1.21.1 Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz HTTP2 UnixSockets PSL

uname -a:
4.9.20-11.31.amzn1.x86_64 #1 SMP Thu Apr 13 01:53:57 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Upvotes: 0

Views: 9194

Answers (1)

Pekko Tuomisto
Pekko Tuomisto

Reputation: 11

Here is the solution that worked:

1st convert the .p12 file to key & cert .pem files:
openssl pkcs12 -in given_keystore.p12 -out key.pem -nodes
openssl pkcs12 -in given_keystore.p12 -out cert.pem -nokeys

2nd test it works:
curl --cert ./cert.pem --key ./key.pem https://provider.com/service/foobar -v
→ result is correctly 404 not found (instead of errors or 403)

Upvotes: 1

Related Questions