Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP SOAP client with certificates over SSL

I'm trying to set up a Soap client with the following code:

<?php
$wsdl           = 'https://domain.com/?wsdl';
$endpoint       = 'https://domain.com';
$certificate    = dirname(__FILE__) . '/CertWithKey.pem';
$password       = 'pwd';

$options = array(
    'location'      => $endpoint,
    'keep_alive'    => true,
    'trace'         => true,
    'local_cert'    => $certificate,
    'passphrase'    => $password,
    'cache_wsdl'    => WSDL_CACHE_NONE
);

try {
    $soapClient = new SoapClient($wsdl, $options);
} catch(Exception $e) {
    var_dump($e);
}

I was given a .p12 key-file with a .crt certification file. Using openssl I've converted the .p12-file to a .pem-file and then merged it with the .crt-file. The CertWithKey.pem looks good to me, two certificate-blocks are in the file.

No matter what I try to do, I keep getting an exception with the message SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://domain.com/?wsdl' : failed to load external entity "https://domain.com/?wsdl".

After phoning with the remote party they acknowlegde that a request is coming in but they're logging this error: ssl handshake interrupted by system [hint: stop button pressed in browser?!].

Since I didn't find any useful information on the net so far I figured to ask you guys for some insight on the matter.

Any suggestions what can be tried? I'm running PHP 5.3.8 and the server's IP-address is white listed in the firewall at the remote party.

like image 814
Ben Fransen Avatar asked Nov 21 '14 13:11

Ben Fransen


1 Answers

I've fixed this problem. I think, due to the number of questions regarding this issue and number of different solutions, others will benefit from the solution. Here goes:

I used the openssl CLI program to convert the .p12 key-file to a .pem key-file. The trick is the way the conversion takes place.

First I converted it with this command and I had the issue as described in the question:

openssl pkcs12 -in key.p12 -out key.pem -nodes -clcerts

While the command below did the actual trick:

openssl pkcs12 -in key.p12 -out key.pem -clcerts

For more info please see the source I used: https://community.qualys.com/docs/DOC-3273

like image 115
Ben Fransen Avatar answered Nov 04 '22 00:11

Ben Fransen