3

The following code returns Exit code 58.

From cURL documentation: CURLE_SSL_CERTPROBLEM (58) problem with the local client certificate.

// create a new CURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_HEADER, false);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

curl_setopt($ch, CURLOPT_SSLCERT, getcwd() . $CERT);
curl_setopt($ch, CURLOPT_SSLCERTPASSWD,"XXXXX");

curl_setopt($ch, CURLOPT_SSLVERSION, 3);

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content Type: text/xml',
    'User-Agent: XXXXX',
    'User-Name: XXXXX'
));

$RESPONSE = curl_exec($ch);  

var_dump($RESPONSE);

// close CURL resource, and free up system resources
curl_close($ch);

Is there something I'm missing?

2 Answers 2

6

Make sure the file in getcwd() . $CERT exists and is a valid PEM certificate. If it seems ok, set the following option to get more SSL certification details output to STDERR:

curl_setopt($ch, CURLOPT_CERTINFO, true);

Note that this setting only has effect if CURLOPT_VERBOSE is set to true, which you already have.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Kaivosukeltaja! It was actually a silly problem with the certificate path on the server!
No problem, Ren! If either of the answers proved useful, don't forget to upvote and/or mark them as accepted. :)
0

problem with the local client certificate

hmm a bit vague. Seems to mean Curl doen't like the certificate, rather than the remote system doesn't like it. Is it in PEM format? Public and private keys in certificate? Readable by webserver uid?

1 Comment

Yeah I agree I wish it could be more specific. It is in PEM format. Also, there are no issues accessing it through the CLI (curl -v -k --cert xxx.pem --pass xxx xxx) so it shouldn't be a problem with the certificates? It seems to be a problem with how I'm using it in PHP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.