2011-10-06 69 views
1

我发现非常有趣的回答how to implement ws-security 1.1 in php5 但我需要使用证书来验证与WebService的连接。如何使用证书在PHP5中实现WS-Security 1.0?

有没有人知道在PHP5上做这种事情的方法?

非常感谢提前!

+0

我真的。 我现在发现的是两个图书馆,但现在我没有运气。 http://code.google.com/p/wse-php/ http://phpwebservices.blogspot.com/如果您有任何成功,我将非常感谢您分享它。 –

+0

嘿朱利安,非常感谢信息。我正在下载wse-php来尝试一下。我还发现有趣的下面的扩展[PHP的wssecurity](www.docweb.provincia.pu.it/download/wssecurity.html)我会分享我的发现。 – Marc

回答

1

这是我的脚本。有了这个脚本,它返回给我:

验证邮件的安全性时发生错误。 而我想找到一种方法来调试此消息。 .pem文件是从密钥文件签名证书和ca文件生成的。 .crt是ca-certificate。我没有什么信息服务器能确切....... 后来我心底检查服务器持有人的详细信息,并能将它们提供我在同一个麻烦些调试信息

require('wse/soap-wsa.php'); 
require('wse/soap-wsse.php'); 
define('PRIVATE_KEY', dirname(__FILE__).'/cert/B_13925_Cert.pem'); 
define('CERT_FILE', dirname(__FILE__).'/cert/Generali-Root.crt'); 

class mySoap extends SoapClient { 

function __doRequest($request, $location, $saction, $version) { 
    $dom = new DOMDocument(); 
    $dom->loadXML($request); 

    $objWSA = new WSASoap($dom); 
    $objWSA->addAction($saction); 
    $objWSA->addTo($location); 
    $objWSA->addMessageID(); 
    $objWSA->addReplyTo(); 

    $dom = $objWSA->getDoc(); 

    $objWSSE = new WSSESoap($dom); 
    /* Sign all headers to include signing the WS-Addressing headers */ 
    $objWSSE->signAllHeaders = TRUE; 

    $objWSSE->addTimestamp(3600); 

    /* create new XMLSec Key using RSA SHA-1 and type is private key */ 
    $objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA1, array('type'=>'private')); 

    /* load the private key from file - last arg is bool if key in file (TRUE) or is string (FALSE) */ 
    $objKey->loadKey(PRIVATE_KEY, TRUE); 

    /* Sign the message - also signs appropraite WS-Security items */ 
    $objWSSE->signSoapDoc($objKey); 

    /* Add certificate (BinarySecurityToken) to the message and attach pointer to Signature */ 
    $token = $objWSSE->addBinaryToken(file_get_contents(CERT_FILE)); 
    $objWSSE->attachTokentoSig($token); 

    $request = $objWSSE->saveXML(); 
    $f = fopen('debug.txt','w'); 
    fwrite($f,print_r($request,true)); 
    fclose($f); 
    return parent::__doRequest($request, $location, $saction, $version); 
    } 
    } 


    $soap_url = 'https://test.domain.bg:9443/GPM/GPMPolicyService.svc/gpm?wsdl'; 
    $soap_client = new mySoap($soap_url); 
    $getNomenclaturesRequest = new getNomenclaturesRequest(array(1,2,3,4)); 
    $request = new GetNomenclatures($getNomenclaturesRequest); 
    try { 
      $out = $soap_client->GetNomenclatures($request); 
     var_dump($out);die(); 
    } catch (SoapFault $fault) { 
    // var_dump($fault); 
    } 
    header('Content-type:text/xml'); 
    print_r(file_get_contents('debug.txt')); 
相关问题