<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" SOAP-ENV:mustUnderstand="1">
<wsse:BinarySecurityToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
EncodingType="http://docs.oasisopen.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"
ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-tokenprofile-1.0#X509v3"
wsu:Id="XWSSGID-1228983064922-2083150424">
Tokenvalue comes here (encoded client certificate)
</wsse:BinarySecurityToken>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsasha1"/>
<ds:Reference URI="#XWSSGID-1228983066435886564840">
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>...Digest Value comes here...
</ds:DigestValue>
</ds:Reference>
<ds:Reference URI="#XWSSGID-1228983066435569450084">
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>...Digest Value comes here...</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>
... Signature Value comes here
(encoded from request message and timestamp?)
</ds:SignatureValue>
<ds:KeyInfo>
<wsse:SecurityTokenReference xmlns:wsu="http://docs.oasisopen.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
wsu:Id="XWSSGID-1228983066104-1256849878">
<wsse:Reference URI="#XWSSGID-1228983064922-2083150424"
ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wssx509-token-profile-1.0#X509v3"/>
</wsse:SecurityTokenReference>
</ds:KeyInfo>
</ds:Signature>
<wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss- wssecurity-utility-1.0.xsd" wsu:Id="XWSSGID-1228983066435569450084">
<wsu:Created>2008-12-11T08:11:05.674Z</wsu:Created>
<wsu:Expires>2008-12-11T08:11:10.674Z</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurityutility-1.0.xsd" wsu:Id="XWSSGID-1228983066435886564840">
<rqn:Requestname xmlns:rqn="http://......">
...payload comes here...
</rqn:Requestname>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
define('PRIVATE_KEY', '/home/mso/ssl/united.key');
define('CERT_FILE', '/home/mso/ssl/united.pem');
define('LOCAL_CRT', '/home/mso/ssl/localcert.pem');
require __DIR__ . '/vendor/autoload.php';
use RobRichards\WsePhp\WSASoap;
use RobRichards\WsePhp\WSSESoap;
use RobRichards\XMLSecLibs\XMLSecurityKey;
class MySoap extends SoapClient
{
public 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();
/* 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();
/* Uncomment here if you wish to write your xml request to a file)
$filename = time() . '.xml';
sleep(2);
writetoFile($request, $filename);
*/
return parent::__doRequest($request, $location, $saction, $version);
}
}
$sc = new MySoap($wsdl, array(
'trace' => 1,
'local_cert' => LOCAL_CRT
));
$data = array('data1' => 'value2);
$out = $sc->Requestname($data);
this will generate signature and token value together with all wsse-security value.
<?php
include __DIR__ . "/src/WSASoap.php";
include __DIR__ . "/src/WSSESoap.php";
include __DIR__ . "/src/xmlseclibs.php";
$privateKey = __DIR__ . "/keystore/my.key";
$myCert = __DIR__ . "/keystore/my_cert.cert";
$serverCert = __DIR__ . "/keystore/cacert.cert";
define('PRIVATE_KEY', $privateKey);
define('CERT_FILE', $myCert);
class MySoap extends SoapClient
{
public function __doRequest($request, $location, $saction, $version, $one_way = NULL)
{
$dom = new DOMDocument();
$dom->loadXML($request);
$objWSA = new WSASoap($dom);
$objWSA->addAction($saction);
$objWSA->addTo($location);
$objWSA->addMessageID();
$objWSA->addReplyTo();
$dom_x = $objWSA->getDoc();
$objWSSE = new WSSESoap($dom_x);
/* Sign all headers to include signing the WS-Addressing headers */
$objWSSE->signAllHeaders = false;
$objWSSE->addTimestamp();
/* 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), false);
$objWSSE->attachTokentoSig($token);
$request = $objWSSE->saveXML();
/* Write response to a file */
$filename = 'test_' . time() . '.xml';
sleep(2);
file_put_contents($filename, $request);
//return parent::__doRequest($request, $location, $saction, $version);
}
}
$wsdl = "https://path_to_wsdl_file.wsdl";
$soap = new MySoap($wsdl, array(
'trace' => 1,
'local_cert' => $serverCert
));
/* build payload */
$data = array(
'xyz' => "123456789",
'abc' => "false"
);
/* call method */
$out = $soap->mehtodname($data);
print_r($out);
--
You received this message because you are subscribed to the Google Groups "wse-php" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wse-php+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/wse-php/41f2f9d4-730c-46ef-a891-ed8007e2d6fb%40googlegroups.com.