I am attempting to create a PHP SOAP connection to a .NET Web Service that has a self-signed certificate in order to lock down the service for communication over HTTPS. I continue to get error's and I'm not sure if it has something to do with the way I create the certificate, my Apache/PHP setup, the way I attempt to establish the SOAP request or something else. If anyone has any pointers they will be greatly appreciated. Thanks in advance.
Certificate Generation
This is how I am creating the certificate.
Create the trusted root private key:
genrsa -out ca_authority_prv.pem 2048
Create the trusted root authority cert:
req -new -key ca_authority_prv.pem -x509 -out ca_authority_cert.pem
Make the cert authority trusted:
x509 -in ca_authority_cert.pem -out ca_authority_trust.pem -trustout
Exit OpenSSL and create a serial file:
echo 1000 > ca_authority.srl
Create the client private key:
genrsa -out Client_prv.pem 2048
Create the client request:
req -new -key Client_prv.pem -out Client_req.pem
Sign the client request with the CA:
x509 -req -CA ca_authority_trust.pem -CAserial ca_authority.srl -CAkey ca_authority_prv.pem -in Client_req.pem -out Client_cert.pem
Make the pfx for the client cert
pkcs12 -export -in Client_cert.pem -inkey Client_prv.pem -out Client_cert.pfx
IIS Setup
Once this certificate is created I follow the same steps for a server certificate and:
Add the trusted root CA to the Machine Trusted Root Store
Add the server certificate to the machine store
Setup IIS to use the server certificate and require client certificates
PHP SOAP Request
This is the code I am using to establish the PHP SOAP request (below is the error):
$wsdl = "https://localhost/MyService/MyService.asmx";
$local_cert = "C:\\Certs\client_cert.pem";
$passphrase = "openSaysMe";
$soapClient = new SoapClient($wsdl, array('local_cert'=> $local_cert,'passphrase'=>$passphrase));
$theResponse = $soapClient->test();
ERROR
Warning: SoapClient::SoapClient() [soapclient.soapclient]: Unable to set private key file `C:\Certs\client_cert.pem' in C:\Program Files\Apache Group\Apache2\htdocs\soapWithAuth.php on line 53
Warning: SoapClient::SoapClient() [soapclient.soapclient]: failed to create an SSL handle in C:\Program Files\Apache Group\Apache2\htdocs\soapWithAuth.php on line 53
Warning: SoapClient::SoapClient() [soapclient.soapclient]: Failed to enable crypto in C:\Program Files\Apache Group\Apache2\htdocs\soapWithAuth.php on line 53
Warning: SoapClient::SoapClient(https://localhost/MyService/MyService.asmx) [soapclient.soapclient]: failed to open stream: operation failed in C:\Program Files\Apache Group\Apache2\htdocs\soapWithAuth.php on line 53
Warning: SoapClient::SoapClient() [soapclient.soapclient]: I/O warning : failed to load external entity "https://localhost/MyService/MyService.asmx" in C:\Program Files\Apache Group\Apache2\htdocs\soapWithAuth.php on line 53
Error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://localhost/MyService/MyService.asmx'
ERROR LOG
PHP Warning: SoapClient::SoapClient() [<a href='soapclient.soapclient'>soapclient.soapclient</a>]: failed to create an SSL handle in C:\\Program Files\\Apache Group\\Apache2\\htdocs\\soapWithAuth.php on line 54