Reputation: 11
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!
Upvotes: 1
Views: 2850
Reputation: 31
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'));
Upvotes: 1