You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@santuario.apache.org by Mike Haller <Mi...@Innovations.de> on 2005/06/06 14:14:19 UTC

Newbie question

Hi,

in hope this is the correct mailing list, here my question:

Signing works, verification works.

But after some marshalling/unmarshalling with Castor, the resulting 
Document has no newlines any more, hence the SignatureValue of the 
SignedInfo element is invalid.

How do I tell XMLSignature to add newlines into the SignedInfo before 
validation? Or should I remove the newlines before signing? And how to 
do that?

I don't know why the Canonicalization fails at the verification process, 
do I have to add the same transforms from the signing process again in 
the verification process? I thought that it's sufficient to add them in 
signing process, since the canon method is clearly visible in the 
Signature element itself.

kind regards
Mike

Re: Newbie question

Posted by Mike Haller <Mi...@Innovations.de>.
Hi Berin,

you're absolutely right, and I understand it. If it was a requirement to 
use CDATA tags for text nodes, we wouldn't have such problems. All other 
contents could be considered subject to change. However, i'm using 
Castor and it seems that the deserialisation process (marshalling) 
removes newlines.

Thanks for your comments :)

regards
Mike


Berin Lautenbach schrieb:
> Mike Haller wrote:
> 
>> i don't know why Canonicalization doesn't address this problem at all. 
>> It sounds like being incomplete to me. One the one hand, there is 
>> taken effort to "normalize" the XML document so it can be signed to 
>> avoidproblems with formattings - on the other hand something simple 
>> like newlines isn't addressed. I don't understand it.
> 
> 
> It's because newline handling is undefined.  Some applications add 
> NL/TAB, others add NL/Space etc.
> 
> If the canonicalisation was *only* performed on the <SignedInfo/> 
> element, then removing or adding this stuff would be fine, but the C14n 
> algorithm is also applied to end user XML, so we can't know whether NLs 
> have meaning.
> 
> Any characters in a TEXT node within an XML document potentially have 
> meaning to processors of that XML.  As an example - what about if my XML 
> doc is to be processed through XML to get to an output that (in order to 
> be human readable) requires New Lines.  To go further - what if removing 
> a new-line from that text changes the meaning in such a way as to 
> invalidate the purpose of the document (thus making the signature fairly 
> irrelevant).
> 
> You're right - it's not pretty - but it's an unfortunate side effect of 
> the fact that an XML processor can't know whether New lines were added 
> for a reason or just for pretty-printing.
> 
> Cheers,
>     Berin
> 


Re: Newbie question

Posted by Berin Lautenbach <be...@wingsofhermes.org>.
Mike Haller wrote:

> i don't know why Canonicalization doesn't address this problem at all. 
> It sounds like being incomplete to me. One the one hand, there is taken 
> effort to "normalize" the XML document so it can be signed to 
> avoidproblems with formattings - on the other hand something simple like 
> newlines isn't addressed. I don't understand it.

It's because newline handling is undefined.  Some applications add 
NL/TAB, others add NL/Space etc.

If the canonicalisation was *only* performed on the <SignedInfo/> 
element, then removing or adding this stuff would be fine, but the C14n 
algorithm is also applied to end user XML, so we can't know whether NLs 
have meaning.

Any characters in a TEXT node within an XML document potentially have 
meaning to processors of that XML.  As an example - what about if my XML 
doc is to be processed through XML to get to an output that (in order to 
be human readable) requires New Lines.  To go further - what if removing 
a new-line from that text changes the meaning in such a way as to 
invalidate the purpose of the document (thus making the signature fairly 
irrelevant).

You're right - it's not pretty - but it's an unfortunate side effect of 
the fact that an XML processor can't know whether New lines were added 
for a reason or just for pretty-printing.

Cheers,
	Berin


Re: Newbie question

Posted by Mike Haller <Mi...@Innovations.de>.
Yes Berin, thanks,

i don't know why Canonicalization doesn't address this problem at all. 
It sounds like being incomplete to me. One the one hand, there is taken 
effort to "normalize" the XML document so it can be signed to 
avoidproblems with formattings - on the other hand something simple like 
newlines isn't addressed. I don't understand it.

Now, i'm removing all newlines (empty text nodes after trim()) from the 
document before signing. this helped, but is hack :(

regards
Mike


Berin Lautenbach schrieb:
> Mike Haller wrote:
> 
>> But after some marshalling/unmarshalling with Castor, the resulting 
>> Document has no newlines any more, hence the SignatureValue of the 
>> SignedInfo element is invalid.
>>
>> How do I tell XMLSignature to add newlines into the SignedInfo before 
>> validation? Or should I remove the newlines before signing? And how to 
>> do that?
> 
> 
> Unfortunately, you can't get XMLSignature to add or delete new lines 
> during signing/verification.  There is no way for the library to know 
> how many new lines to add, how to indent, etc. to get back to the 
> original form.  So if you have something in the processing of your XML 
> that removes this pretty-printing, you need to make sure it happens 
> *before* you sign, so that what is signed is also what will be validated 
> (in terms of newlines/tabs/spaces etc.)
> 
>>
>> I don't know why the Canonicalization fails at the verification 
>> process, do I have to add the same transforms from the signing process 
>> again in the verification process? I thought that it's sufficient to 
>> add them in signing process, since the canon method is clearly visible 
>> in the Signature element itself.
> 
> 
> Canonicalisation doesn't remove or add newlines.  It simply transforms 
> everything in the XML into a standard bytewise format.
> 
>>
>> kind regards
>> Mike
>>
>>
> 
> Hope that helps!
> 
> Cheers,
>     Berin


Re: Newbie question

Posted by Berin Lautenbach <be...@wingsofhermes.org>.
Mike Haller wrote:

> But after some marshalling/unmarshalling with Castor, the resulting 
> Document has no newlines any more, hence the SignatureValue of the 
> SignedInfo element is invalid.
> 
> How do I tell XMLSignature to add newlines into the SignedInfo before 
> validation? Or should I remove the newlines before signing? And how to 
> do that?

Unfortunately, you can't get XMLSignature to add or delete new lines 
during signing/verification.  There is no way for the library to know 
how many new lines to add, how to indent, etc. to get back to the 
original form.  So if you have something in the processing of your XML 
that removes this pretty-printing, you need to make sure it happens 
*before* you sign, so that what is signed is also what will be validated 
(in terms of newlines/tabs/spaces etc.)

> 
> I don't know why the Canonicalization fails at the verification process, 
> do I have to add the same transforms from the signing process again in 
> the verification process? I thought that it's sufficient to add them in 
> signing process, since the canon method is clearly visible in the 
> Signature element itself.

Canonicalisation doesn't remove or add newlines.  It simply transforms 
everything in the XML into a standard bytewise format.

> 
> kind regards
> Mike
> 
> 

Hope that helps!

Cheers,
	Berin