Struggling to use soap client with SSL certificate

I’m using a SOAP service which uses SSL. I’ve got the digital certificate from the service provider, installed it on windows, and managed to connect to the API endpoint using a browser. However I can’t seem to get the soap client to connect, getting “SoapFault exception: [HTTP] Could not connect to host”

The code seems not unlike other examples which were reportedly successful:

[CODE]

$cert_file = ‘combined_certs.pem’;
$wsdl_file = ‘mywdsl.wsdl’;

$soap_client = new SoapClient($wsdl_file, array(
“trace” => 1,
“exceptions” => true,
“local_cert” => $cert_file,
“style” => SOAP_RPC,
“use” => SOAP_ENCODED,
“soap_version” => SOAP_1_2
)
);

$soap_call = “someAction”;

$request_data = array(“foo”=>“bar”,“animal”=>“pigeon”);

try{
$response = $soap_client->$soap_call($request_data);
}
catch(Exception $e){
echo $e;
var_dump($soap_client);
}[/CODE]

If the code is right, then the problem is probably with the certificate.

The certificate I was provided was a .p12 file, and is a collection of 4 character hexadecimal words. I got no joy passing this file to the soap client.

I converted these the .pem cert/key files using openssl:

openssl pkcs12 -in mycert.p12 -clcerts -nokeys -out mycert.pem
openssl pkcs12 -in mycert.p12 -nocerts -nodes -out mykey.pem 

I then combined these into a single file using a text editor, so the resulting file looked something like this:

-----BEGIN CERTIFICATE-----
BLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAH
BLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAH
[32 lines of this]
-----END CERTIFICATE-----
-----BEGIN RSA PRIVATE KEY-----
BLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAH
BLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAH
[25 lines of this]
-----END RSA PRIVATE KEY-----

The non-concatenated files contained some header information such as bag attributes, localKeyID, friendlyName, Key Attributes. I tried including them in the concatenation and then removed them.

Any tips as to where I’m going wrong?

Crazy thing: it seems to work when run from the command line, but not when run from the browser on the same machine.

What can cause this? How do I fix it? :confused:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.