You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@santuario.apache.org by def abc <an...@yahoo.fr> on 2005/02/01 17:33:53 UTC
Enveloping signature: wrong document err.
Hi all,
I'm trying to build an enveloping signature:
- the input is a Document. I want to sign this.
- the output is a FileOutputStream. I want to write
the enveloping signature in this file.
But it doesn't work: I get a
"org.apache.crimson.tree.DomEx: WRONG_DOCUMENT_ERR :
Ce noeud n''appartient pas à ce document." (this node
does not belong to this document) from the first
appendChild.
I do understand the error (obj is built from Document
input but we append it in Document doc)... but not the
way to resolve this.
Thanks for any help,
Axelle.
// create the ds:Object
Document doc = db.newDocument();
ObjectContainer obj = new ObjectContainer(input);
doc.appendChild(obj.getElement());
// sign the object
XMLSignature signature;
signature = new XMLSignature(doc,
outputURI.toString(),
XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1);
signature.addDocument(inputURI.toString());
signature.appendObject(obj);
signature.sign(prvkey);
// output result to file
doc.appendChild(signature.getElement());
XMLUtils.outputDOM(doc, output);
Découvrez le nouveau Yahoo! Mail : 250 Mo d'espace de stockage pour vos mails !
Créez votre Yahoo! Mail sur http://fr.mail.yahoo.com/
Re: Enveloping signature: wrong document err.
Posted by Heiner Westphal <He...@verit.de>.
> Axelle wrote:
[ snip ]
Wow, you are fast.
Sounds familiar. Took me some time to sort it out once upon a time...
>
> // create the ds:Object
> Document doc = db.newDocument();
> ObjectContainer obj = new ObjectContainer(input);
Instead of:
> doc.appendChild(obj.getElement());
use:
boolean deepCopy = true;
Node payloadElem
= signedDoc.importNode(doc.getDocumentElement(), deepCopy);
obj.appendChild(payloadElem);
doc.appendObject(obj);
That should do the trick.
Regards,
Heiner
Re: Enveloping signature: wrong document err.
Posted by def abc <an...@yahoo.fr>.
Raul, Heiner,
Bonjour :-)
Thanks very much for your help: I now have a beautiful
enveloping signature :-)
Thanks too for the link to the CreateEnveloping
sample. I was using the AxisSigner but hadn't seen
that other example !
BTW, as for the intent, it's just to try out this API.
I'm (quite) familiar with XML Signature, but a
beginner to this API.
May I suggest the following for the documentation of
XMLSignature (I don't know why, in my version,
information is scattered through all constructors).
[do please check it correct however].
Best regards,
Axelle.
/**
*
* Builds an object representing the ds:Signature
* XML element for a given document.
* Initially,
* - this object contains an empty ds:SignedInfo
* - it isn't signed (call sign())
* - it is only prepared for the given document
* but not actually written to it (call
doc.appendChild() on the signature element).
*
* @param doc the document in which the ds:Signature
* is created. This document may be different from
* the document that is being signed.
* @param baseURI the base URI to use to expand URIs
* within doc.
* @param signatureMethodURI the name of the signature
algorithm. For example, ALGO_ID_SIGNATURE_RSA_SHA1.
* @throws XMLSecurityException
*/
Découvrez le nouveau Yahoo! Mail : 250 Mo d'espace de stockage pour vos mails !
Créez votre Yahoo! Mail sur http://fr.mail.yahoo.com/
Re: Enveloping signature: wrong document err.
Posted by Raul Benito <ra...@gmail.com>.
Bon Soir,
Axelle,
First of all don´t use crimson as XML parser it can you give some head aches.
Anyway, your problem can be fix by using doc.importNode function. But
I don't understand your intends.
Regards,
Raul
http://r-bg.com
On Tue, 1 Feb 2005 17:33:53 +0100 (CET), def abc <an...@yahoo.fr> wrote:
> Hi all,
>
> I'm trying to build an enveloping signature:
> - the input is a Document. I want to sign this.
> - the output is a FileOutputStream. I want to write
> the enveloping signature in this file.
>
> But it doesn't work: I get a
> "org.apache.crimson.tree.DomEx: WRONG_DOCUMENT_ERR :
> Ce noeud n''appartient pas à ce document." (this node
> does not belong to this document) from the first
> appendChild.
>
> I do understand the error (obj is built from Document
> input but we append it in Document doc)... but not the
> way to resolve this.
>
> Thanks for any help,
>
> Axelle.
>
> // create the ds:Object
> Document doc = db.newDocument();
> ObjectContainer obj = new ObjectContainer(input);
> doc.appendChild(obj.getElement());
>
> // sign the object
> XMLSignature signature;
> signature = new XMLSignature(doc,
> outputURI.toString(),
> XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1);
> signature.addDocument(inputURI.toString());
> signature.appendObject(obj);
> signature.sign(prvkey);
>
> // output result to file
> doc.appendChild(signature.getElement());
> XMLUtils.outputDOM(doc, output);
>
> Découvrez le nouveau Yahoo! Mail : 250 Mo d'espace de stockage pour vos mails !
> Créez votre Yahoo! Mail sur http://fr.mail.yahoo.com/
>