PHP SOAP client with certificates over SSL

I am trying to configure 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 provided with a .p12 key file with a .crt certification file. Using openssl, I converted the .p12 file to a .pem file and then combined it with a .crt file. CertWithKey.pem looks good to me, two certificate files are in the file.

No matter what I try to do, I get 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 a call with the remote party, they acknowledge that the request is received, but they register this error: ssl handshake interrupted by system [hint: stop button pressed in browser?!] .

Since I have not found any useful information on the web so far, I decided to ask you guys to get some idea on this.

Any suggestions what you can try? I am running PHP 5.3.8, and the server IP address is white, specified in the firewall on the remote side.

+5
source share
2 answers

I fixed this problem. I think because of the number of questions regarding this problem and the number of different solutions, others will benefit from the solution. Here:

I used the openssl CLI program to convert the .p12 key file to a .pem key file. The trick is how the transformation happens.

First, I converted it using this command, and I had a problem as described in the question:

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

While the command below did the trick:

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

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

+4
source

Same suggestions:

  • I use SoapClient to connect to SSL services and everything works fine without specifying the endpoint URL. Then I recommend that you try without this option;

  • Php SoapClient has an option called "ssl_method" where you can change some variations of this protocol. Try changing / specifying this parameter if you know which protocol is used;

  • Specify "verifypeer => false" and "verifyhost => false" in the parameter list;

-1
source

Source: https://habr.com/ru/post/1207409/


All Articles