2015-11-03 49 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文件將是正確的。

相關問題