473,508 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML Signatures and namespace problems

Hi all,

I'm having problems importing an XML Signature element into a SOAP
envelope. I can create the signature without problem, but when I
import the signature element into the SOAP header, all of the elements
in the entire SOAP envelope have a default namespace declaration of
xmlns="" added to them. Also, all sub-elements of the <ds:Signature
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> element have the
following redundant namespace declaration added to them:

xmlns:ds="http://www.w3.org/2000/09/xmldsig#"

Any idea how to prevent these changes from happening? (Note: the
problem also happens if I attempt to create the signature directly in
the soap header.)

Here are some code fragments I'm using to generate the signature and
import it into the soap header:
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbf.newDocumentBuilder();
Document doc = docBuilder.newDocument();

org.apache.xml.security.utils.Constants.setSignatu reSpecNSprefix("ds");

String baseURI = null;
XMLSignature signature = new XMLSignature(doc, baseURI,
XMLSignature.ALGO_ID_SIGNATURE_DSA);

signature.addResourceResolver(
new InputStreamReferenceResolver(getInputStream(),getC ontentType())
);

doc.appendChild(signature.getElement());

signature.addDocument(null, null,
org.apache.xml.security.utils.Constants.ALGO_ID_DI GEST_SHA1);

signature.sign(privateKey);

// Now import the signature into the SOAP header
SOAPMessage message = ...
SOAPPart soapPart = message.getSOAPPart();
SOAPHeader soapHeader = message.getSOAPHeader();

org.w3c.dom.Node signatureNode =
soapPart.importNode(signature.getElement(),true);
soapHeader.appendChild(signatureNode);
The resulting SOAP Envelope looks like this:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns="">
<SOAP-ENV:Header xmlns="">
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns="">
<ds:SignedInfo xmlns=""
xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:CanonicalizationMethod
Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315 "
xmlns="" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"/>
<ds:SignatureMethod
Algorithm="http://www.w3.org/2000/09/xmldsig#dsa-sha1" xmlns=""
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"/>
<ds:Reference xmlns=""
xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:DigestMethod
Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" xmlns=""
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"/>
<ds:DigestValue xmlns=""
xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
Vf8a/Rvic27UJqOhMqyIHYimSLw=
</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue xmlns=""
xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
bMabvDDzk0g2KmP3Yb+ybaL+GwBN4sDFT+yuUuapWoZfILgNkx h90g==
</ds:SignatureValue>
</ds:Signature>
</SOAP-ENV:Header>
<SOAP-ENV:Body xmlns="">
...
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

When what I really want is this:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>
<ds:CanonicalizationMethod
Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315 "/>
<ds:SignatureMethod
Algorithm="http://www.w3.org/2000/09/xmldsig#dsa-sha1"/>
<ds:Reference>
<ds:DigestMethod
Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>
Vf8a/Rvic27UJqOhMqyIHYimSLw=
</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>
bMabvDDzk0g2KmP3Yb+ybaL+GwBN4sDFT+yuUuapWoZfILgNkx h90g==
</ds:SignatureValue>
</ds:Signature>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
...
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Thanks in advance ...

Steve
Jul 17 '05 #1
0 2238

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

88
5055
by: Tim Tyler | last post by:
PHP puts most of its functions into a big flat global namespace. That leads to short function names - but creates a namespace minefield for programmers. Lots of the functions are legacies from...
5
7374
by: Alexander Gnauck | last post by:
Hello, i have problems with the Namespaces and the .Net XML Parser My XML looks like this: <query xmlns="jabber:iq:roster"> <item jid="srlee@localhost" name="srlee"...
1
2892
by: karflips33 | last post by:
Is it possible to automate the signing of Word 2003 docs with Digital Signatures? My problem with the code approach using ActiveDocument.Signatures.Add
32
30459
by: toolmaster | last post by:
Since many of the modern computer languages have built-in namespace features, I can't understand why not add this feature into standard C. I've heard many people complain of the lacking of...
4
2349
by: jianyi | last post by:
Hi, I am working on an xml project, and I am trying to understand something. if the author needs to sign one xml file, then his manager will counter-sign, and a third witness will sign, can...
7
4536
by: zahy[dot]bnaya[At]gmail[dot]com | last post by:
Hi all, Since I am always confusing this, I want to know once and for all what is the right way of doing this. I've noticed that some programs use: std::cout<< "yadayada"<<endl;
30
4064
by: Pep | last post by:
Is it best to include the code "using namespace std;" in the source or should each keyword in the std namespace be qualified by the namespace tag, such as std::cout << "using std namespace" <<...
3
2609
by: mrstephengross | last post by:
Hi folks. I've got a weird situation--gcc doesn't like the folllowing code snippet, but I don't know if it's correct or not. Here's the situation: In the global namespace, I've got a operator<<...
4
1727
by: jmDesktop | last post by:
In the code below from MSDN How do the PeopleEnum methods ever get called? foreach (Person p in peopleList) Console.WriteLine(p.firstName + " " + p.lastName); What is going on behind the...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7405
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7066
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5643
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
435
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.