views:

219

answers:

2

Hi, I need to use PHP's SoapClient with myfile-ca.crt. How can I tell SoapClient constructor to work with client certificate (crt file) ?

I am experienced with php SoapClient, but I never needed to work with secure soap client.

Thanks for any help

+2  A: 

When constructing your SoapClient, you can pass in a configuration array as the second parameter. This array allows the options local_cert. The local_cert option should point to the certificate file (in my experience the absolute path was needed to get it to work).

$wsdl = "service.wsdl";
$cert = "c:\secure_cert\webservice.pem";
$client = new SoapClient($wsdl, array('local_cert' => $local_cert);

See also the examples at the SoapClient manual page

Note: I've always been given .pem files; not sure if .crt is the same / works the same...?

kander
Thanks a lot.Of course, I tried to use it before, but I never succeed, probably becouse of relative path.
Michal Drozd
So I need make pem file from crt, dont ?I found this way:openssl x509 -in input.crt -out input.der -outform DERthenopenssl x509 -in input.der -inform DER -out output.pem -outform PEM
Michal Drozd
I started getting new (catched) exception:Could not connect to hostNo idea what this really means. Is there any way to get more info?
Michal Drozd
Is there anything more in the exception object itself? Do you have OpenSSL compiled in (I'm assuming you do, if you got this far)? Is there anything in your server error log (or are warnings/errors on)?Nothing quite useful I can add here, apart from the usual pain-staking debug process, I'm afraid.
kander
Note sure about the PEM / CRT question; the webservice supplier gave me the PEM so that's what I rolled with. They offered example code (which the above is based on), and things pretty much 'just worked', apart from the relative path issue.
kander
I am getting this error after calling method, so connection (constructing soapClient = new SoapClient(...)) is without any exception, but calling method $soapClient->GetXMLCatalogue() throws this exception.
Michal Drozd
A: 

After first problem with client certificate (which seems to be solved), I went to another error: After calling method $soapClient->GetXMLCatalogue(..) I am getting:

Could not connect to host

My code is:

$soapClient = new SoapClient('/......./service.wsdl',
        array(
                            'local_cert'=> "/............/alltoys-ca.pem",
                         'style'    => SOAP_DOCUMENT,
                         'use'      => SOAP_LITERAL,
                            'exceptions' => true,
                            'trace' => true);
try {
   $soapClient->GetXMLCatalogue(array('login' => 'xxx', 'password' => 'xxx'));
} catch (Exception $exp) {
   die("Exp: " . var_export($exp, 1) . "\n"); // here I get error
}

I get following when dumping exception object:

...
'faultstring' => 'Could not connect to host',
'faultcode' => 'HTTP',
...

WSDL is publicly avilable at https://factorws.alltoys.cz:444/factorws.asmx?WSDL

Michal Drozd
Hmm.. when I connect to some of the endpoitns defined in the WSDL, I get HTTP 404 errors... that might be part of the problem?
kander
When you talk about endpoint you mean https://factorws.alltoys.cz/GetXMLCatalogue ?
Michal Drozd
Yes, that's what I meant.
kander
You are right, it throws error when accessing. Question is, is this feature or bug ?
Michal Drozd