You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by mu...@apache.org on 2008/10/16 17:43:45 UTC
svn commit: r705262 - in
/xml/security/trunk/src_unitTests/org/apache/xml/security/test/c14n/implementations:
Bug45961Test.java MockCanonicalizationMethod.java
Author: mullan
Date: Thu Oct 16 08:43:45 2008
New Revision: 705262
URL: http://svn.apache.org/viewvc?rev=705262&view=rev
Log:
Fixed bug 45961: verify with own canonicalization method
Modified:
xml/security/trunk/src_unitTests/org/apache/xml/security/test/c14n/implementations/Bug45961Test.java
xml/security/trunk/src_unitTests/org/apache/xml/security/test/c14n/implementations/MockCanonicalizationMethod.java
Modified: xml/security/trunk/src_unitTests/org/apache/xml/security/test/c14n/implementations/Bug45961Test.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src_unitTests/org/apache/xml/security/test/c14n/implementations/Bug45961Test.java?rev=705262&r1=705261&r2=705262&view=diff
==============================================================================
--- xml/security/trunk/src_unitTests/org/apache/xml/security/test/c14n/implementations/Bug45961Test.java (original)
+++ xml/security/trunk/src_unitTests/org/apache/xml/security/test/c14n/implementations/Bug45961Test.java Thu Oct 16 08:43:45 2008
@@ -11,13 +11,16 @@
import org.apache.xml.security.Init;
import org.apache.xml.security.c14n.Canonicalizer;
+import org.apache.xml.security.keys.KeyInfo;
import org.apache.xml.security.signature.ObjectContainer;
import org.apache.xml.security.signature.XMLSignature;
import org.apache.xml.security.signature.XMLSignatureException;
+import org.apache.xml.security.transforms.Transforms;
import org.apache.xml.security.utils.Constants;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
import junit.framework.TestCase;
@@ -39,17 +42,21 @@
_builder = factory.newDocumentBuilder();
}
- public void testBug() throws Exception {
- Document document = getSignedDocument();
- try {
- Element element = (Element) document.getFirstChild();
- assertEquals(Constants.getSignatureSpecNSprefix() + ":"
- + Constants._TAG_SIGNATURE, element.getNodeName());
- new XMLSignature(element, null);
- } catch (XMLSignatureException e) {
- fail(e.getMessage());
- }
- }
+ public void testBug() throws Exception {
+ Document document = getSignedDocument();
+ NodeList list = document.getElementsByTagNameNS(
+ Constants.SignatureSpecNS, Constants._TAG_SIGNATURE);
+ Element element = (Element) list.item(0);
+ XMLSignature signature = new XMLSignature(element, null);
+ KeyInfo keyInfo = signature.getKeyInfo();
+ X509Certificate certificate = keyInfo.getX509Certificate();
+ assertNotNull(certificate);
+ try {
+ signature.checkSignatureValue(certificate);
+ } catch (XMLSignatureException e) {
+ fail(e.getMessage());
+ }
+ }
private Document getSignedDocument() throws Exception {
KeyStore ks = KeyStore.getInstance("JKS");
@@ -66,21 +73,33 @@
XMLSignature.ALGO_ID_SIGNATURE_DSA,
MOCK_CANONICALIZATION_METHOD);
- document.appendChild(signature.getElement());
+ Element root = document.createElementNS("", "RootElement");
+ root.appendChild(document.createTextNode("Some simple test\n"));
+ root.appendChild(signature.getElement());
+ document.appendChild(root);
+
+// document.appendChild(signature.getElement());
- Element root = document.createElementNS("", "RootElement");
- root.appendChild(document.createTextNode("Some simple test\n"));
+ Element root2 = document.createElementNS("", "RootElement");
+ root2.appendChild(document.createTextNode("Some simple test\n"));
ObjectContainer object = new ObjectContainer(document);
- object.appendChild(root);
+ object.appendChild(root2);
object.setId(OBJECT_ID);
signature.addDocument("#" + OBJECT_ID);
+ signature.addDocument("", getTransforms(document));
signature.addKeyInfo(signingCert);
signature.sign(privateKey);
return document;
}
+ private Transforms getTransforms(Document document) throws Exception {
+ Transforms transforms = new Transforms(document);
+ transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
+ return transforms;
+ }
+
private String getAbsolutePath(String path)
{
String basedir = System.getProperty("basedir");
Modified: xml/security/trunk/src_unitTests/org/apache/xml/security/test/c14n/implementations/MockCanonicalizationMethod.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src_unitTests/org/apache/xml/security/test/c14n/implementations/MockCanonicalizationMethod.java?rev=705262&r1=705261&r2=705262&view=diff
==============================================================================
--- xml/security/trunk/src_unitTests/org/apache/xml/security/test/c14n/implementations/MockCanonicalizationMethod.java (original)
+++ xml/security/trunk/src_unitTests/org/apache/xml/security/test/c14n/implementations/MockCanonicalizationMethod.java Thu Oct 16 08:43:45 2008
@@ -1,89 +1,52 @@
package org.apache.xml.security.test.c14n.implementations;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
import java.io.OutputStream;
import java.util.Set;
import org.apache.xml.security.c14n.CanonicalizationException;
import org.apache.xml.security.c14n.CanonicalizerSpi;
-import org.apache.xml.security.utils.UnsyncByteArrayOutputStream;
-import org.apache.xml.security.utils.XMLUtils;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
+import org.apache.xml.security.c14n.implementations.Canonicalizer11_OmitComments;
-import com.sun.org.apache.xml.internal.serialize.OutputFormat;
-import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
+import org.w3c.dom.Node;
@SuppressWarnings("unchecked")
public class MockCanonicalizationMethod extends CanonicalizerSpi {
public static final String MOCK_CANONICALIZATION_METHOD = "mock.canonicalization.method";
- private OutputStream _os;
+ private Canonicalizer11_OmitComments _impl;
+
+ public MockCanonicalizationMethod() {
+ _impl = new Canonicalizer11_OmitComments();
+ }
@Override
public byte[] engineCanonicalizeSubTree(Node rootNode)
throws CanonicalizationException {
- return canonicalize(rootNode);
- }
-
- private byte[] canonicalize(Node rootNode) throws CanonicalizationException {
- try {
- XMLSerializer serializer = new XMLSerializer(getOutputStream(),
- new OutputFormat());
- serializer.setNamespaces(true);
- serializer.serialize((Element) rootNode);
- return toByteArray();
- } catch (IOException e) {
- throw new CanonicalizationException(e.getMessage(), e);
- }
- }
-
- private byte[] toByteArray() {
- OutputStream os = getOutputStream();
- if (os instanceof ByteArrayOutputStream) {
- ByteArrayOutputStream os2 = (ByteArrayOutputStream) os;
- byte[] result = os2.toByteArray();
- os2.reset();
- return result;
- }
- if (os instanceof UnsyncByteArrayOutputStream) {
- UnsyncByteArrayOutputStream os2 = (UnsyncByteArrayOutputStream) os;
- byte[] result = os2.toByteArray();
- os2.reset();
- return result;
- }
- return null;
- }
-
- private OutputStream getOutputStream() {
- if (_os == null) {
- _os = new ByteArrayOutputStream();
- }
- return _os;
+ return _impl.engineCanonicalizeSubTree(rootNode);
}
@Override
public byte[] engineCanonicalizeSubTree(Node rootNode,
String inclusiveNamespaces) throws CanonicalizationException {
- return canonicalize(rootNode);
+ return _impl.engineCanonicalizeSubTree(rootNode, inclusiveNamespaces);
}
@Override
public byte[] engineCanonicalizeXPathNodeSet(Set xpathNodeSet)
throws CanonicalizationException {
- return canonicalize(XMLUtils.getOwnerDocument(xpathNodeSet));
+ return _impl.engineCanonicalizeXPathNodeSet(xpathNodeSet);
}
@Override
public byte[] engineCanonicalizeXPathNodeSet(Set xpathNodeSet,
String inclusiveNamespaces) throws CanonicalizationException {
- return canonicalize(XMLUtils.getOwnerDocument(xpathNodeSet));
+ return _impl.engineCanonicalizeXPathNodeSet(xpathNodeSet,
+ inclusiveNamespaces);
}
@Override
public boolean engineGetIncludeComments() {
- return false;
+ return _impl.engineGetIncludeComments();
}
@Override
@@ -93,6 +56,7 @@
@Override
public void setWriter(OutputStream os) {
- _os = os;
+ _impl.setWriter(os);
}
+
}