我尝试通过 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 的方式是否正确?
最佳答案
您遇到的问题是 .pem
证书始终应该是加密文件。根据OpenSSL docs for the pkcs12 command当您使用 -nodes
它没有加密任何东西,而是将每个节点放入纯文本,这导致 .pem
证书无效并且您的 SoapClient
无法解析无效文件。
要解决此问题,希望您没有删除原始的 cert.pfx
,只需使用以下行重新转换它即可:
openssl pkcs12 -in cert.pfx -out cert.pem -clcerts
并且您的 cert.pem
文件将是正确的。
关于php - 不接受证书。无法设置私钥文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33497083/