2013-08-27 22 views
2

當使用PHP做一個SOAP請求到HTTPS SOAP服務器:■SoapClient的失敗,一個的SOAPFault:PHP的SoapClient的verify_peer =>真正的失敗,CA簽發的證書

 
faultstring: Could not connect to host 
faultcode: HTTP 

我必須肯定的是,肥皂服務器ssl證書是有效的,所以我使用

<?php 
$soap=new SoapClient("mwsdl.wsdl" 
      ,array(
        "location"=>"https:examplesoapserver.com" 
        ,"trace"=>1 
        ,"stream_context"=>stream_context_create(array(
         "ssl"=>array(
             "verify_peer"=>true 
             ,"allow_self_signed"=>false 
            ) 
          ) 
          ) 
         ) 
        ); 

但是,這給了我SoapFault。

我有不同的設置進行了測試:

OK 
location: has self-signed certificate 
verify_peer=>true 
allow_self_signed=>true
OK (without setting verify_peer) 
location: has self-signed certificate 
allow_self_signed=>false
NOT OK 
location: has self-signed certificate 
verify_peer=>true 
allow_self_signed=>false
OK (without setting verify_peer) 
location: ca-signed certificate 
allow_self_signed=>false
NOT OK 
location: ca-signed certificate 
verify_peer=>true 
allow_self_signed=>false

我:

php version: 5.3.3 
CentOS 6.4 
Apache/2.2.15

要求提供更多的細節,如果有幫助圖解決問題。

非常感謝您的幫助!

回答

5

問題是,PHP默認情況下不安全的設置來處理https請求。它不會驗證證書或檢查證書中的域是否正確。

您必須自行下載用於驗證證書的文件。

你可以下載一個在:http://curl.haxx.se/ca/cacert.pem

的設置正確處理它們是

<?php 
$client = new SoapClient("my-wsdlfile.wsdl" 
       ,array(
         "location"=>"https://examplesoapserver.com" 
         ,"stream_context"=>stream_context_create(
          array(
          "ssl"=>array(
           "verify_peer"=>true 
           ,"allow_self_signed"=>false 
           ,"cafile"=>"path/to/cacert.pem" 
           ,"verify_depth"=>5 
           ,"CN_match"=>"examplesoapserver.com" 
           ) 
          ) 
         ) 
        ) 
       ); 

沒有與其他PHP函數同樣的問題,可以使用https(如file_get_contents),所以同樣的解決方案爲了保證它的安全,應該可以工作。

默認情況下,CURL具有安全設置,所以如果可能的話,它更容易使用它。

這裏是PHP如何處理HTTPS偉大和更詳細的解釋:

http://phpsecurity.readthedocs.org/en/latest/Transport-Layer-Security-(HTTPS-SSL-and-TLS).html#php-streams

相關問題