dqoys62082 2011-10-06 14:47
浏览 43

如何使用证书在PHP5中实现WS-Security 1.0?

I have found very interesting the answer to how to implement ws-security 1.1 in php5 but I need to use certificates to authenticate the connection to the WebService.

Does anyone know a way to do such a thing on PHP5?

Many thanks in advance!

  • 写回答

1条回答 默认 最新

  • donxbje866688 2011-10-10 10:26
    关注

    Here is my script. With this script it returns me:

    An error occurred when verifying security for the message. And i Want to find a way to debug this message. The .pem file is generated from the key file signed certificate and the ca-file. .crt is ca-certificate. I have no information what server expect exactly....... Later I`ll check server holders for more info and could they provide me with some debug information

    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'));
    
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于#flink#的问题:关于docker部署flink集成hadoop的yarn,请教个问题flink启动yarn-session.sh连不上hadoop
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题