Thursday, 15 January 2015

php - Curl - cannot connect using p12 certificate -



php - Curl - cannot connect using p12 certificate -

i'm trying collect info using curl, connecting service external company provided. they, in add-on address itself, sent me p12 certificate file required estabilish connection.

when i'm trying utilize curl, next error:

#58: not supported file type 'p12' certificate

so far i've tried updating curl , php-curl. nil changed.

my code:

... curl_setopt($ch, curlopt_sslcert, 'cert_path'); curl_setopt($ch, curlopt_sslcerttype, 'p12'); curl_setopt($ch, curlopt_sslcertpasswd, 'my_pass'); ...

funny thing code works on our production environment, while doesn't work on local machine (linux mint 16).

found solution.

easiest way extract .pem key , certificate .p12 file.

for illustration (tested on linux):

openssl pkcs12 -in file.p12 -out file.key.pem -nocerts -nodes openssl pkcs12 -in file.p12 -out file.crt.pem -clcerts -nokeys

will create key/cert pair in current directory.

now, utilize it:

curl_setopt($ch, curlopt_sslcert, 'file.crt.pem'); curl_setopt($ch, curlopt_sslkey, 'file.key.pem'); curl_setopt($ch, curlopt_sslcertpasswd, 'pass'); curl_setopt($ch, curlopt_sslkeypasswd, 'pass');

where pass password .p12 file.

php curl ssl

No comments:

Post a Comment