Certificate is not accepted. Failed to install private key file

I am trying to connect through SoapClient. I need a certificate for this. I got a .pfx certificate. I used the following command to create a .pem file.

openssl pkcs12 -in cert.pfx -out cert.pem -nodes 

There is a password in the certificate, so I need to enter it before I get the cert.pem file. I think so good.

Now I am trying to connect to the WSDL service.

 $url = "https://test.website.com/webservices/transfer.asmx?WSDL"; $cert = '/path/to/cert.pem'; $passphrase = "12345678"; $soapClient = new SoapClient($url, array('local_cert'=>$cert,'passphrase'=>$passphrase)); 

I get the following error:

(Warning) SoapClient :: SoapClient (): Unable to install private key file `/var/www/vhosts/............./cert.pem '

I think the problem is the certificate. The way I converted .pfx to .pem correctly?

+6
source share
1 answer

The problem you are facing is that the .pem certificate .pem always be an encrypted file. According to the OpenSSL docs for the pkcs12 command , when you used -nodes , it didn't encrypt anything, but put each node in plain text, which caused the .pem invalid, and your SoapClient could not parse the invalid file.

To fix this, I hope you have not deleted the original cert.pfx , just convert it with this line:

 openssl pkcs12 -in cert.pfx -out cert.pem -clcerts 

and your cert.pem file will be correct.

+6
source

All Articles