2015-11-03 48 views
6

我尝试通过SoapClient建立连接。我需要这个证书。我收到了.pfx证书。我使用下面的命令来创建一个.pem文件。证书未被接受。无法设置私钥文件

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

证书中有一个密码,所以我需要在获取cert.pem文件之前输入密码。我认为目前为止这么好。

现在我尝试连接到WSDL服务。

$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)); 

我得到以下错误:

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

我认为这个问题是该证书。我以正确的方式将.pfx转换为.pem的方式?

+0

我仍然有问题这个。找到了这个。 注意:在这里包括“-nodes”标志将阻止使用密码来加密私钥。 白色或没有密码我得到相同的错误。 –

+0

是证明公共还是私人的? –

+2

你为什么使用'-nodes'而不是'-clcerts'? –

回答

6

您遇到的问题是.pem证书始终应该是加密文件。根据OpenSSL docs for the pkcs12 command,当您使用-nodes时,它并未加密任何内容,而是将每个节点都置于纯文本中,导致.pem证书无效,并且SoapClient无法分析无效文件。

为了解决这个问题,希望你没有删除原来的cert.pfx,只是用这条线重新转换,:

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

和你cert.pem文件将是正确的。

相关问题