I found the problem, it is a bug in JDOM 2.0.4 ( https://github.com/hunterhacker/jdom/issues/115): 'xmlns' prefix and URI for Namespace declarations are not correctly set by DOMOutputter. This bug has been fixed in the latest release, 2.0.5.
2013/5/2 Giovanni D'Ascola <[email protected]> > Sorry, there is no extra whitespace between the left angle bracket and the > tag name "CommandMessage" in the xml documents. > > > 2013/5/2 Giovanni D'Ascola <[email protected]> > >> I added a test case. >> >> Here is the original XML Document: >> >> < >> CommandMessage xmlns=*"http://www.cryptomathic.com/ckms"* xmlns:xsi=*" >> http://www.w3.org/2001/XMLSchema-instance"*><Commands Count=*"1"*>< >> PushServerPublicKeyCommand><SerialNumber>202</SerialNumber><Target>COPS</ >> Target><KeyInfo xmlns=*"http://www.w3.org/2000/09/xmldsig#"*><KeyValue>< >> RSAKeyValue><Modulus> >> 8RYsssohlzZit+OKHp2C/r88g4Q2DosbJZvnO0SDlFeCAZmsTbR8JSR1dBaD3DKAyirBYZAzs13MtsT0phyppuO7rOEO6OimkNAV/4n03/0xLkH/gnGbjs7H+ntfoLnoftLwf7YCzZPhHy5GfERUHXzoVoO3t9aMBZzVxY/u2T3za2445y7Bhhed2zJQpwZTCnDGS6RH9WBCRxvJAJ/oocsl/84UC4lJobXTVQY476AeOwWsmtEs7E5UNstVxsJ88YmB7lVxxOYdq3W14jkxwItpCMzU6xJZzdAu+sqng4QU8jx6sgwVU55Nnfrw4nkoxiwMGjREBF/M8OxXrgPoww== >> </Modulus><Exponent>AQAB</Exponent></RSAKeyValue></KeyValue></KeyInfo></ >> PushServerPublicKeyCommand></Commands></CommandMessage> >> >> Here is the canonicalized XML Document: >> >> < >> CommandMessage xmlns=*"http://www.cryptomathic.com/ckms"*><Commands Count >> =*"1"*><PushServerPublicKeyCommand><SerialNumber>202</SerialNumber>< >> Target>COPS</Target><KeyInfo xmlns=*"http://www.w3.org/2000/09/xmldsig#"* >> ><KeyValue><RSAKeyValue><Modulus> >> 8RYsssohlzZit+OKHp2C/r88g4Q2DosbJZvnO0SDlFeCAZmsTbR8JSR1dBaD3DKAyirBYZAzs13MtsT0phyppuO7rOEO6OimkNAV/4n03/0xLkH/gnGbjs7H+ntfoLnoftLwf7YCzZPhHy5GfERUHXzoVoO3t9aMBZzVxY/u2T3za2445y7Bhhed2zJQpwZTCnDGS6RH9WBCRxvJAJ/oocsl/84UC4lJobXTVQY476AeOwWsmtEs7E5UNstVxsJ88YmB7lVxxOYdq3W14jkxwItpCMzU6xJZzdAu+sqng4QU8jx6sgwVU55Nnfrw4nkoxiwMGjREBF/M8OxXrgPoww== >> </Modulus><Exponent>AQAB</Exponent></RSAKeyValue></KeyValue></KeyInfo></ >> PushServerPublicKeyCommand></Commands></CommandMessage> >> >> Below is the code if the test case: >> >> *public* *void* test2() >> >> *throws* IOException, FileNotFoundException, SAXException, >> ParserConfigurationException, CanonicalizationException, >> >> InvalidCanonicalizerException, TransformerException, >> XMLSignatureException, XMLSecurityException, JDOMException { >> >> Document doc = >> *this*.db.parse(getAbsolutePath("src/mytest/example1.xml")); >> >> // From W3C Document to JDOM Document >> >> org.jdom2.input.DOMBuilder jdomBuilder = >> *new* org.jdom2.input.DOMBuilder(); >> >> org.jdom2.Document jdomDocument = jdomBuilder.build(doc); >> >> // From JDOM Document to W3C Document >> >> org.jdom2.output.DOMOutputter outputter = >> *new* org.jdom2.output.DOMOutputter(); >> >> Document doc2= outputter.output(jdomDocument); >> >> Node root2 = doc2.getElementsByTagNameNS( >> "http://www.cryptomathic.com/ckms", "CommandMessage").item(0); >> >> Canonicalizer20010315Excl c = >> *new* Canonicalizer20010315ExclOmitComments(); >> >> *byte*[] reference = JavaUtils.*getBytesFromFile*(getAbsolutePath( >> "src/mytest/example1_c14nized.xml")); >> >> *byte* >> [] result = c.engineCanonicalizeSubTree(root2); >> >> *boolean* equals = java.security.MessageDigest.*isEqual*(reference, >> result); >> >> *assertTrue*(equals); >> >> } >> >> >> 2013/4/29 Giovanni D'Ascola <[email protected]> >> >>> Hi, >>> >>> here is the problem: start with a W3C Document (JDK6), modify it with >>> JDOM >>> 2.0.4, create a new W3C Document from the modified JDOM Document whith >>> the >>> DOMOutputter output() method, apply ExclC14N to it, canonicalization >>> fails >>> with Apache Santuario 1.4.7 (but not with IBM XML Crypto Provider). For >>> instance, superfluos xml namespace declarations are not removed. If I >>> write the modified JDOM Document to a String and then parse this String >>> to >>> a W3C document, Santuario canonicalization on thisi document works >>> perfectly. >>> >>> >>> >>> >> >
