XML SOAP signature sample

The sample in the xml/soap folder generates an XML signature for a SOAP document according to WS-Security.

Compiling the SOAP signature sample

Run the following command line in the etjava/examples directory.

javac -sourcepath source -d classes -classpath ../lib/enttoolkit.jar;<xalan.jar>;<xercesImpl.jar>;<xml-apis.jar> \
source/com/entrust/toolkit/examples/xml/soap/SoapSigner.java \
source/com/entrust/toolkit/examples/xml/soap/SigningWorker.java \
source/com/entrust/toolkit/examples/xml/utils/Utils.java

Parameter

Value

<xalan.jar>

The path of the xalan.jar third-party library.

<xercesImpl.jar>

The path of the xercesImpl.jar third-party library.

<xml-apis.jar>

The path of the xml-apis.jar third-party library.

Running the SOAP signature sample

Run the following command line in the etjava/examples directory.

java -classpath ../lib/enttoolkit.jar;<xalan.jar>;<xercesImpl.jar>;<xml-apis.jar> com.entrust.toolkit.examples.xml.soap.SoapSigner <epf_file> <epf_pwd> <init.properties> <in_xml> <out_xml> [<xml_element>]

Parameter

Value

<xalan.jar>

The path of the xalan.jar third-party library.

<xercesImpl.jar>

The path of the xercesImpl.jar third-party library.

<xml-apis.jar>

The path of the xml-apis.jar third-party library.

<epf_file>

The path of an Entrust user profile in .epf file format.

<epf_pwd>

The path of an Entrust user profile in .epf file format.

<init.properties>

The URI of the init.properties initialization file for the IXSIL library.

<in_xml>

The URI of an XML resource to be signed, for example file:/c:/test/tobesigned.xml

<out_xml>

The path of the resulting XML signed file.

<xml_element>

The name of the XML element in the document being signed where the Signature is to be inserted, For example "s:Body".

For example:

D:\java\etjava\examples>java -classpath classes;..\lib\enttoolkit.jar;..\lib\xalan.jar;..\lib\xercesImpl.jar;..\lib\xml-apis.jar
com.entrust.toolkit.examples.xml.soap.SoapSigner data\userdata\RSAUser1.epf ~Sample7~
file:/d:/java/etjava/examples/data/xml/init/properties/init.properties
file:data/xml/soap/soapSignMe.xml data\xml\soap\soapSigned.xml signmeId
Logging in to: data\userdata\RSAUser1.epf
Initializing IXSIL properties from "file:/d:/java/etjava/examples/data/xml/init/properties/init.properties"...
IXSIL is initialized.
WS Schema locations: " http://schemas.xmlsoap.org/ws/2002/07/utility file:/d:/ja
va/etjava/examples/data/xml/init/schemas/schemas-xmlsoap-org-ws-2002-07-utility.
xsd http://schemas.xmlsoap.org/ws/2002/12/secext file:/d:/java/etjava/examples/d
ata/xml/init/schemas/schemas-xmlsoap-org-ws-2002-12-secext.xsd http://schemas.xm
lsoap.org/soap/envelope/ file:/d:/java/etjava/examples/data/xml/init/schemas/sch
emas-xmlsoap-org-soap-envelope.xsd"
Created a signature over content at Id "signmeId" in the SOAP document at "file:
data/xml/soap/soapSignMe.xml"
 
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse
="http://schemas.xmlsoap.org/ws/2002/12/secext" xmlns:wsu="http://schemas.xmlsoa
p.org/ws/2002/07/utility" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/ http://schemas.xml
soap.org/soap/envelope/ http://schemas.xmlsoap.org/ws/2002/07/utility http://sch
emas.xmlsoap.org/ws/2002/07/utility/ http://schemas.xmlsoap.org/ws/2002/12/secex
t http://schemas.xmlsoap.org/ws/2002/12/secext/"><soap:Header><wsse:Security><ws
se:BinarySecurityToken EncodingType="wsse:Base64Binary" ValueType="wsse:X509v3"
wsu:Id="X509Token">MIIDiDCCAnCgAwIBAgIEP3l9djANBgkqhkiG9w0BAQUFADA7MQswCQYDVQQGE
wJDQTEdMBsGA1UEChMUSmF2YSBUb29sa2l0IFNhbXBsZXMxDTALBgNVBAsTBFBLSTcwHhcNMDMxMDAxM
TQ1MjIwWhcNMDgxMDAxMTUyMjIwWjBPMQswCQYDVQQGEwJDQTEdMBsGA1UEChMUSmF2YSBUb29sa2l0I
FNhbXBsZXMxDTALBgNVBAsTBFBLSTcxEjAQBgNVBAMTCVJTQSBVc2VyMTCBnzANBgkqhkiG9w0BAQEFA
AOBjQAwgYkCgYEA0RqETfqyWrn7vMmHbikcnDRg+BLF+4xNTngGM4kMAZnepbXzHLeE+eEYlHV6aDfHb
qoe+bxRaqbqahUYyoqgeLPRjNBhczd/ystM6QISaGa+AgnQ/SZja3FSz2axnvMlUSghOQ8ih52P/IJv4
AeqgZTC9lUeqeLQA9yNAKChn38CAwEAAaOCAQIwgf8wCwYDVR0PBAQDAgeAMCsGA1UdEAQkMCKADzIwM
DMxMDAxMTQ1MjIwWoEPMjAwNzA0MDIxMjIyMjBaMF0GA1UdHwRWMFQwUqBQoE6kTDBKMQswCQYDVQQGE
wJDQTEdMBsGA1UEChMUSmF2YSBUb29sa2l0IFNhbXBsZXMxDTALBgNVBAsTBFBLSTcxDTALBgNVBAMTB
ENSTDEwHwYDVR0jBBgwFoAUV3GOJrFdh093mk0NWO/1W4td18cwHQYDVR0OBBYEFDpNqeL94Ls85pwAi
zoedB7+rIUZMAkGA1UdEwQCMAAwGQYJKoZIhvZ9B0EABAwwChsEVjcuMAMCBLAwDQYJKoZIhvcNAQEFB
QADggEBAHl1NBMt1EtCQzqInasKvUYtw/sjpOf6IeNBZ8Gs/0K29OT69EKSiZBA7rTJoF6XZrJqQWV5Z
DCpfYXjEVFp4YfWjOKceI/kxZIZj4thn727RAfUbO0T9Q3zvwWzZzdkf+w8G/RWEEp8K4RM0DjQPw60W
etJcj3Gt4TtOZbYDNwy6sKH5Ivh/C2tt2BIlRLT4iuvaeG+qHPPXWAR0lihNkFKQAQuIEb4qz/dv7D1e
8KN8T+P8SryktJcWehNeMLhauc8mDLHBf8YV9Exrf3NXrnhFHCKFu0f8EXhpWwpp1X/0bqjEh0dmrAde
jQ6r7MaxoSVuevBaSWhWvxxVGgLQ9o=</wsse:BinarySecurityToken><dsig:Signature Id="Si
gnature001" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:wsse="http://s
chemas.xmlsoap.org/ws/2002/12/secext"><dsig:SignedInfo><dsig:CanonicalizationMet
hod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/><dsig:SignatureMethod A
lgorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><dsig:Reference URI="#sig
nmeId"><dsig:Transforms><dsig:Transform Algorithm="http://www.w3.org/2001/04/dec
rypt#"/></dsig:Transforms><dsig:DigestMethod Algorithm="http://www.w3.org/2000/0
9/xmldsig#sha1"/><dsig:DigestValue>FnwNksOoGNEYIMMrkmd9QAmPhLs=</dsig:DigestValu
e></dsig:Reference></dsig:SignedInfo><dsig:SignatureValue>dB+a6PW1pzJrhmKgjV/ez/
uhedhlurigvHpzk41s2X1eeF3zJRhGOABscj/3Srns85okuf5hxfU8KrxM/ZmRkuFkkGDfzqxDB7oCW3
rvE5VhZdrqcoOmV72SI+WV+RJLv6SkzELJ7nZGFHpRgAsxHGMMF9m5ZgjH/ezw6rz+ZE8=</dsig:Sig
natureValue><dsig:KeyInfo Id="KeyInfo001"><wsse:SecurityTokenReference><wsse:Ref
erence URI="#X509Token"/></wsse:SecurityTokenReference></dsig:KeyInfo></dsig:Sig
nature></wsse:Security></soap:Header>
<soap:Body wsu:Id="signmeId">
<confirmOrder>
<sendTo>
<name>John Doe</name>
<address>123 Circle Road</address>
<zip>K1B 0R4</zip>
<city>Ottawa</city>
<country>Canada</country>
<phone>555 456 7890</phone>
</sendTo>
<item>
<name>Swing Set</name>
<serialNumber>4151986942</serialNumber>
<quantity>1</quantity>
<price>200</price>
</item>
</confirmOrder>
</soap:Body>
</soap:Envelope>
 
Writing to file: data\xml\soap\soapSigned.xml
Done

Verifying a SOAP signature

Run the sample application described in Running Verify to validate the generated SOAP signature. For example:

D:\java\etjava\examples>java -classpath classes;..\lib\enttoolkit.jar;..\lib\xalan.jar;..\lib\xercesImpl.jar;..\lib\xml-apis.jar
com.entrust.toolkit.examples.xml.sign.Verify data\userdata\RSAUser1.epf ~Sample7~
file:/d:/java/etjava/examples/data/xml/init/properties/init.properties
file:/d:/java/etjava/examples/data/xml/soap/soapSigned.xml
Java installation directory:C:\Program Files\Java\j2re1.4.2
JRE version: 1.4.2
Java class path:classes;..\lib\enttoolkit.jar
OS:Windows XP
OS architecture:x86
OS version:5.1
File separator: \
Path separator: ;
Line separator: 0x0D 0x0A
User's account name: [deleted]
User's home directory: [deleted]
User's current working directory:D:\java\etjava\examples
Java VM version:1.4.2-b28
Java library path: [deleted]
XML DOM parser:null
XML SAX parser:null
XML XSLT implementation:null
 
Logging in to: data\userdata\RSAUser1.epf
Initializing IXSIL properties from "file:/d:/java/etjava/examples/data/xml/init/
properties/init.properties"...
IXSIL has been initialized.
dsig schema location: "http://www.w3.org/2000/09/xmldsig# file:/d:/java/etjava/e
xamples/data/xml/init/schemas/Signature.xsd"
WS Schema locations: " http://schemas.xmlsoap.org/ws/2002/07/utility file:/d:/ja
va/etjava/examples/data/xml/init/schemas/schemas-xmlsoap-org-ws-2002-07-utility.
xsd http://schemas.xmlsoap.org/ws/2002/12/secext file:/d:/java/etjava/examples/d
ata/xml/init/schemas/schemas-xmlsoap-org-ws-2002-12-secext.xsd http://schemas.xm
lsoap.org/soap/envelope/ file:/d:/java/etjava/examples/data/xml/init/schemas/sch
emas-xmlsoap-org-soap-envelope.xsd"
Schema locations: "http://www.w3.org/2000/09/xmldsig# file:/d:/java/etjava/examp
les/data/xml/init/schemas/Signature.xsd http://schemas.xmlsoap.org/ws/2002/07/u
tility file:/d:/java/etjava/examples/data/xml/init/schemas/schemas-xmlsoap-org-w
s-2002-07-utility.xsd http://schemas.xmlsoap.org/ws/2002/12/secext file:/d:/java
/etjava/examples/data/xml/init/schemas/schemas-xmlsoap-org-ws-2002-12-secext.xsd
http://schemas.xmlsoap.org/soap/envelope/ file:/d:/java/etjava/examples/data/xm
l/init/schemas/schemas-xmlsoap-org-soap-envelope.xsd"
JAXP implementation: "jar:file:/D:/java/lib/xercesImpl.jar!/org/apache/xerces/ja
xp/DocumentBuilderFactoryImpl.class"
 
--------- START OF file:/d:/java/etjava/examples/data/xml/soap/soapSigned.xml SE
RIALIZED DOCUMENT ---------
[deleted, the content is shown in the SoapSigner output]
--------- END OF file:/d:/java/etjava/examples/data/xml/soap/soapSigned.xml SERI
ALIZED DOCUMENT ---------
 
Opening "file:/d:/java/etjava/examples/data/xml/soap/soapSigned.xml"
Creating a Verifier...
Verify sample is demonstrating Method 1
JAXP DOM implementation system property setting: null
JAXP implementation: "jar:file:/D:/java/lib/xercesImpl.jar!/org/apache/xerces/ja
xp/DocumentBuilderFactoryImpl.class"
It's an Apache parser.
Setting parser feature: namespace awareness
Setting parser feature: including ignorable whitespace in element content
Setting parser feature: not expanding entity references
 
This document validates correctly against the schema(s) provided.
Verifying...
Verified !
The signature was verified using a valid certificate.
URI of signed content: "#signmeId"
Done