Uploaded image for project: 'Santuario'
  1. Santuario
  2. SANTUARIO-139

Canonicalizer.canonicalizeSubtree(Node) omits namespaces for Documents created with DocumentBuilder.newDocument()

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Incomplete
    • None
    • None
    • Java
    • Security Level: Public (Public issues, viewable by everyone)
    • None
    • Operating System: Linux
      Platform: PC
    • 43197

    Description

      The output of Canonicalizer.canonicalizeSubtree(Node) omits namespaces when a
      Document is passed that was created from scratch, i.e. using
      DocumentBuilder.newDocument() and appending children manually. This problem
      doesn't occur when a Document is passed that was created by parsing, i.e. by
      using DocumentBuilder.parse(...).

      Reproducible under:
      ibm-jdk-1.5.0.4
      sun-jdk-1.5.0.12

      Using XML-security from Subversion, revision 568937 (checked out on Aug 23, 2007)

      The following JUnit test reproduces the bug:

      import java.io.IOException;
      import java.io.StringReader;
      import java.io.StringWriter;

      import javax.xml.parsers.DocumentBuilder;
      import javax.xml.parsers.DocumentBuilderFactory;
      import javax.xml.parsers.ParserConfigurationException;
      import javax.xml.transform.OutputKeys;
      import javax.xml.transform.Transformer;
      import javax.xml.transform.TransformerException;
      import javax.xml.transform.TransformerFactory;
      import javax.xml.transform.dom.DOMSource;
      import javax.xml.transform.stream.StreamResult;

      import junit.framework.TestCase;

      import org.apache.xml.security.c14n.CanonicalizationException;
      import org.apache.xml.security.c14n.Canonicalizer;
      import org.apache.xml.security.c14n.InvalidCanonicalizerException;
      import org.w3c.dom.Document;
      import org.w3c.dom.Element;
      import org.xml.sax.InputSource;
      import org.xml.sax.SAXException;

      public class CanonicalizationTestCase extends TestCase {
      public void test() throws ParserConfigurationException, SAXException,
      IOException, TransformerException, InvalidCanonicalizerException,
      CanonicalizationException

      { org.apache.xml.security.Init.init(); DocumentBuilderFactory _documentBuilderFactory = DocumentBuilderFactory .newInstance(); _documentBuilderFactory.setNamespaceAware(true); TransformerFactory _transformerFactory = TransformerFactory .newInstance(); String dummyXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><dummy xmlns=\"http://dummyNS\"><child>this is a child</child></dummy>"; String dummyNS = "http://dummyNS"; Document d1; // Document created from scratch Document d2; // Document created by parsing DocumentBuilder db1 = _documentBuilderFactory.newDocumentBuilder(); d1 = db1.newDocument(); Element dummyElement = d1.createElementNS(dummyNS, "dummy"); Element childElement = d1.createElementNS(dummyNS, "child"); childElement.setTextContent("this is a child"); dummyElement.appendChild(childElement); d1.appendChild(dummyElement); DocumentBuilder db2 = _documentBuilderFactory.newDocumentBuilder(); d2 = db2.parse(new InputSource(new StringReader(dummyXML))); // compare documents by serializing them to a String Transformer t = _transformerFactory.newTransformer(); t.setOutputProperty(OutputKeys.METHOD, "xml"); DOMSource source1 = new DOMSource(d1); StringWriter sw1 = new StringWriter(); t.transform(source1, new StreamResult(sw1)); DOMSource source2 = new DOMSource(d2); StringWriter sw2 = new StringWriter(); t.transform(source2, new StreamResult(sw2)); System.out.println(sw1.toString()); System.out.println(sw2.toString()); assertEquals(sw2.toString(), sw1.toString()); // compare canonicalizations Canonicalizer c14n; c14n = Canonicalizer .getInstance("http://www.w3.org/TR/2001/REC-xml-c14n-20010315"); String output1 = new String(c14n.canonicalizeSubtree(d1)); String output2 = new String(c14n.canonicalizeSubtree(d2)); System.out.println(new String(output1)); System.out.println(new String(output2)); assertEquals(output2, output1); }

      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            dbw@zurich.ibm.com Daniela Bourges
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: