我发现how to implement ws-security 1.1 in php5的答案非常有趣 但我需要使用证书来验证与WebService的连接。
有没有人知道如何在PHP5上做这样的事情?
非常感谢提前!
答案 0 :(得分: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'));