证书未被接受。无法设置私钥文件。

8
我尝试通过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));

我遇到了以下错误:

(警告) SoapClient::SoapClient(): 无法设置私钥文件 `/var/www/vhosts/............./cert.pem'

我认为问题出在证书上。我将.pfx转换成.pem的方式正确吗?


我仍然在这个问题上遇到困难。找到了这个。注意:在这里包括“-nodes”标志将防止使用密码短语加密私钥。无论是否使用密码短语,我都会收到相同的错误。 - Leon van der Veen
这个证书是公钥还是私钥? - iam-decoder
2
你为什么使用了“-nodes”而不是“-clcerts”? - iam-decoder
2个回答

11
你遇到的问题是 .pem 证书文件总是应该是一个加密文件。根据 OpenSSL pkcs12 命令文档 ,当你使用了 -nodes 选项时,它没有加密任何内容,而是将每个节点放入纯文本中,这导致 .pem 证书文件无效,因此你的 SoapClient 无法解析它。
为了解决这个问题,希望你没有删除原始的 cert.pfx 文件,只需使用以下命令重新转换即可:
openssl pkcs12 -in cert.pfx -out cert.pem -clcerts

并且你的 cert.pem 文件将正确无误。


1
你今天是我最喜欢的人!谢谢!在尝试了一百零一种方法获取正确的证书后,终于成功了。然后使用 $soapClient = new \SoapClient($wsdl, ['local_cert' => 'cert.pem', 'passphrase' => 'Entered PEM pass phrase', 'trace' => 1, 'exceptions' => 0]);,你可以通过 $soapClient->__getFunctions(); 检索所有给定的方法。 - s3c

3
今天我遇到了一个无效的证书/私钥组合问题,这意味着证书不属于指定的密钥。 您可以使用以下方法验证此问题:
openssl rsa  -noout -modulus -in server.key | openssl md5
openssl x509 -noout -modulus -in server.crt | openssl md5

密钥和证书应该返回相同的校验和。如果不是,就意味着有人搞混了一些文件。

对于证书签名请求(CSR)也适用相同的过程:

# and for a CSR
openssl req -noout -modulus -in server.csr | openssl md5

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接