Attached is the testcase that shows the problem. I'll check-in the test into the
workspace later.
Vishal
Berin Lautenbach wrote:
>
> Vishal,
>
> Not good! Be interested to see what Raul comes back with. Either way
> it would be great to have a test case in the interop tests that can
> replicate the problem.
>
> Cheers,
> Berin
>
> Vishal Mahajan wrote:
>
> > All,
> >
> > In the Java Library, I observe a couple of things whose combined result
> > seems to be erroneous.
> >
> > Consider the following example document -
> > <foo>text1
> > text2</foo>
> > Also assume that the dom representation of this document as - A DOM
> > element named "foo" having two child text nodes - "text1" and "\ntext2".
> >
> > 1. In XMLSignatureInput, method getNodeSet() delegates the task of
> > forming the resultant node-set to XMLUtils.getSetWith*Comments(). This
> > method populates the node-set with both the text nodes.
> >
> > 2. When this node-set is sent for exclusive canonicalization, the method
> > CanonicalizerBase.canonicalizeXPathNodeSet(Node, NameSpaceSymbTable)
> > comes into picture. In the switch block of this method, for the
> > TEXT_NODE case, the text node as well all its right hand side siblings
> > are written to the output stream. Hence, for the above example, the c14n
> > output would come out to be:
> >
> > <foo>text1
> > text2
> > text2</foo>
> >
> > I am not sending a testcase along but that shouldn't be difficult to
> > write. Comments?
> >
> > Regards,
> > Vishal
> >
> >
> >
import java.io.*;
import org.w3c.dom.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
import javax.xml.transform.dom.*;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import
org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclOmitComments;
import org.apache.xml.security.signature.XMLSignatureInput;
public class C14nTest {
public static void main(String[] args) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.newDocument();
Element foo = doc.createElement("foo");
Text text1 = doc.createTextNode("text1");
Text text2 = doc.createTextNode("text2");
doc.appendChild(foo);
foo.appendChild(text1);
foo.appendChild(text2);
nodeToString(foo);
org.apache.xml.security.Init.init();
Canonicalizer20010315ExclOmitComments c14n =
new Canonicalizer20010315ExclOmitComments();
byte[] buf =
c14n.engineCanonicalizeXPathNodeSet(
(new XMLSignatureInput(foo)).getNodeSet());
System.out.println("\n" + new String(buf));
}
private static void nodeToString(Node node) throws Exception {
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
DOMSource source = new DOMSource(node);
StreamResult result = new StreamResult(System.out);
transformer.transform(source, result);
}
}