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 2006/01/27 22:00:36 UTC

svn commit: r372984 [1/4] - in /xml/security/branches/jsr105_0_16/src_unitTests/javax: ./ xml/ xml/crypto/ xml/crypto/test/ xml/crypto/test/dsig/ xml/crypto/test/dsig/dom/ xml/crypto/test/dsig/keyinfo/

Author: mullan
Date: Fri Jan 27 13:00:17 2006
New Revision: 372984

URL: http://svn.apache.org/viewcvs?rev=372984&view=rev
Log:
JSR 105 Tests.

Added:
    xml/security/branches/jsr105_0_16/src_unitTests/javax/
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/KeySelectorExceptionTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/KeySelectorTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/KeySelectors.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/OctetStreamDataTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/Baltimore18Test.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/Baltimore23Test.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/BaltimoreExcC14n1Test.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/BaltimoreIaik2Test.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/BaltimoreXPathFilter2ThreeTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/CanonicalizationMethodTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/ComRSASecurityTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/CreateBaltimore23Test.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/CreateInteropExcC14NTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/CreateInteropXFilter2Test.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/CreatePhaosXMLDSig3Test.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/DetachedTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/DigestMethodTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/IaikCoreFeaturesTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/IaikSignatureAlgosTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/IaikTransformsTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/InteropC14nTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/ManifestTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/PhaosXMLDSig3Test.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/ReferenceTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/SignatureMethodTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/SignaturePropertiesTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/SignaturePropertyTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/SignatureValidator.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/SignedInfoTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/TestUtils.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/TransformTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/X509KeySelector.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/XMLObjectTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/XMLSignContextTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/XMLSignatureFactoryTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/XMLSignatureTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/XMLValidateContextTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/dom/
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/dom/DOMValidateContextTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/KeyInfoFactoryTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/KeyInfoTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/KeyNameTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/KeyValueTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/PGPDataTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/RetrievalMethodTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/X509DataTest.java
    xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/X509IssuerSerialTest.java

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/KeySelectorExceptionTest.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/KeySelectorExceptionTest.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/KeySelectorExceptionTest.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/KeySelectorExceptionTest.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,99 @@
+/*
+ * Copyright  2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ */
+package javax.xml.crypto.test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.Arrays;
+import javax.xml.crypto.KeySelectorException;
+
+import junit.framework.*;
+
+/**
+ * Unit test for javax.xml.crypto.KeySelectorException
+ *
+ * @version $Id$
+ * @author Valerie Peng
+ */
+public class KeySelectorExceptionTest extends TestCase {
+
+    public KeySelectorExceptionTest() {
+	super("KeySelectorExceptionTest");
+    }
+
+    public KeySelectorExceptionTest(String name) {
+	super(name);
+    }
+
+    public void setUp() throws Exception { }
+
+    public void tearDown() { }
+
+    public void testConstructor() {
+	// test KeySelectorException()
+	KeySelectorException kse = new KeySelectorException();
+	assertNull(kse.getMessage());
+	assertNull(kse.getCause());
+
+	// test KeySelectorException(String)
+	kse = new KeySelectorException("test");
+	assertEquals("test", kse.getMessage());
+	assertNull(kse.getCause());
+	
+	// test KeySelectorException(String, Throwable)
+	IllegalArgumentException iae = new IllegalArgumentException("iae");
+	kse = new KeySelectorException("random", iae);
+	assertEquals("random", kse.getMessage());
+	assertTrue(compareThrowable(iae, kse.getCause()));
+
+	// test KeySelectorException(Throwable)
+	kse = new KeySelectorException(iae);
+	assertEquals(iae.toString(), kse.getMessage());
+	assertTrue(compareThrowable(iae, kse.getCause()));
+    }
+    private static boolean compareThrowable(Throwable t1, Throwable t2) {
+	boolean result = false;
+	// first compare their toString presentation
+	if (t1.toString().equals(t2.toString())) {
+	    ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
+	    ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
+	    // then compare their StackTrace
+	    PrintStream ps = new PrintStream(baos1);
+	    t1.printStackTrace(ps);
+	    ps.close();
+	    ps = new PrintStream(baos2);
+	    t2.printStackTrace(ps);
+	    ps.close();
+
+	    if (Arrays.equals(baos1.toByteArray(), baos2.toByteArray())) {
+		result = true;
+	    } else {
+		System.out.println("StackTrace comparison failed");
+		t1.printStackTrace(System.out);
+		t2.printStackTrace(System.out);
+	    }
+	} else {
+	    System.out.println("ToString comparison failed");
+	    System.out.println(t1);
+	    System.out.println(t2);
+	}
+	return result;
+    }
+}

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/KeySelectorTest.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/KeySelectorTest.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/KeySelectorTest.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/KeySelectorTest.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ */
+package javax.xml.crypto.test;
+
+import java.util.*;
+import java.security.Key;
+import java.security.cert.X509Certificate;
+import javax.xml.crypto.*;
+import javax.xml.crypto.dsig.keyinfo.*;
+import javax.xml.crypto.dsig.*;
+
+import junit.framework.*;
+
+/**
+ * Unit test for javax.xml.crypto.KeySelector
+ *
+ * @version $Id$
+ * @author Valerie Peng
+ */
+public class KeySelectorTest extends TestCase {
+    private Key key;
+    private KeySelector selector1;
+
+    private class MyOwnKey implements Key {
+	private String algo;
+	private byte[] val;
+	MyOwnKey(String algorithm, byte[] value) {
+	    algo = algorithm;
+	    val = (byte[]) value.clone();
+	}
+	
+	public String getAlgorithm() {
+	    return algo;
+	}
+	public byte[] getEncoded() {
+	    return val;
+	}
+	public String getFormat() {
+	    return "RAW";
+	}
+    }
+
+    public KeySelectorTest() {
+	super("KeySelectorTest");
+    }
+
+    public KeySelectorTest(String name) {
+	super(name);
+    }
+
+    public void setUp() throws Exception {
+	// selector1: singletonKeySelector
+	key = new MyOwnKey("test", new byte[16]);
+	selector1 = KeySelector.singletonKeySelector(key);
+    }
+
+    public void tearDown() { }
+
+    public void testselect() throws Exception {
+	KeyInfoFactory factory = KeyInfoFactory.getInstance
+	    ("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
+	X509Data obj = factory.newX509Data(Collections.singletonList("CN=foo"));
+	KeyInfo info = factory.newKeyInfo(Collections.singletonList(obj));
+	//@@@@@what about other types of X509Data, i.e. subject name String,
+	// X509IssuerSerial objects, etc?
+	XMLSignatureFactory dsigFac = XMLSignatureFactory.getInstance
+	    ("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
+	SignatureMethod sm1 = 
+	    dsigFac.newSignatureMethod(SignatureMethod.DSA_SHA1, null);
+	SignatureMethod sm2 = 
+	    dsigFac.newSignatureMethod(SignatureMethod.RSA_SHA1, null);
+
+	assertTrue(compareKey(key, selector1.select
+	    (info, KeySelector.Purpose.VERIFY, sm1, null).getKey()));
+	assertTrue(compareKey(key, selector1.select
+	    (info, KeySelector.Purpose.VERIFY, sm2, null).getKey()));
+    }
+    
+    private static boolean compareKey(Object answer, Key key) {
+	boolean result = false;
+	if (answer instanceof MyOwnKey) {
+	    result = ((MyOwnKey) answer == key);
+	} else if (answer instanceof X509Certificate) {
+	    result =
+	        ((X509Certificate)answer).getPublicKey().equals(key);
+	}
+	return result;
+    }
+}

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/KeySelectors.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/KeySelectors.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/KeySelectors.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/KeySelectors.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,410 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ */
+package javax.xml.crypto.test;
+
+import java.io.*;
+import java.security.*;
+import java.security.cert.*;
+import java.util.*;
+import javax.xml.crypto.*;
+import javax.xml.crypto.dsig.*;
+import javax.xml.crypto.dom.*;
+import javax.xml.crypto.dsig.keyinfo.*;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.DocumentBuilder;
+import javax.crypto.SecretKey;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+import org.w3c.dom.traversal.*;
+import sun.security.util.DerValue;
+import sun.security.x509.X500Name;
+
+import junit.framework.*;
+
+/**
+ * This is a class which supplies several KeySelector implementations
+ *
+ * @author Sean Mullan
+ * @author Valerie Peng
+ */
+public class KeySelectors {
+
+    /**
+     * KeySelector which would always return the secret key specified in its 
+     * constructor.
+     */
+    public static class SecretKeySelector extends KeySelector {
+	private SecretKey key;
+	public SecretKeySelector(byte[] bytes) {
+	    key = wrapBytes(bytes);
+	}
+	public SecretKeySelector(SecretKey key) {
+	    this.key = key;
+	}
+    
+	public KeySelectorResult select(KeyInfo ki, 
+					KeySelector.Purpose purpose,
+					AlgorithmMethod method, 
+					XMLCryptoContext context) 
+	    throws KeySelectorException {
+	    return new SimpleKSResult(key);
+	}
+	
+	private SecretKey wrapBytes(final byte[] bytes) {
+	    return new SecretKey() {
+		    public String getFormat() {
+			return "RAW";
+		    }
+		    
+		    public String getAlgorithm() {
+			return "Secret key";
+		    }
+		    
+		    public byte[] getEncoded() {
+			return bytes;
+		    }
+		};
+	}
+    }
+
+    /**
+     * KeySelector which would retrieve the X509Certificate out of the 
+     * KeyInfo element and return the public key.
+     * NOTE: If there is an X509CRL in the KeyInfo element, then revoked
+     * certificate will be ignored.
+     */
+    public static class RawX509KeySelector extends KeySelector {
+     
+	public KeySelectorResult select(KeyInfo keyInfo, 
+					KeySelector.Purpose purpose, 
+					AlgorithmMethod method, 
+					XMLCryptoContext context) 
+	    throws KeySelectorException {
+	    if (keyInfo == null) {
+		throw new KeySelectorException("Null KeyInfo object!");
+	    } 
+	    // search for X509Data in keyinfo
+	    Iterator iter = keyInfo.getContent().iterator();
+	    while (iter.hasNext()) {
+		XMLStructure kiType = (XMLStructure) iter.next();
+		if (kiType instanceof X509Data) {
+		    X509Data xd = (X509Data) kiType;
+		    Object[] entries = xd.getContent().toArray();
+		    X509CRL crl = null;
+		    // Looking for CRL before finding certificates
+		    for (int i = 0; (i<entries.length&&crl != null); i++) {
+			if (entries[i] instanceof X509CRL) {
+			    crl = (X509CRL) entries[i];
+			}
+		    }
+		    Iterator xi = xd.getContent().iterator();
+		    boolean hasCRL = false;
+		    while (xi.hasNext()) {
+			Object o = xi.next();
+			// skip non-X509Certificate entries
+			if (o instanceof X509Certificate) {
+			    if ((purpose != KeySelector.Purpose.VERIFY) && 
+				(crl != null) && 
+				crl.isRevoked((X509Certificate)o)) {
+				continue;
+			    } else {
+				return new SimpleKSResult
+				    (((X509Certificate)o).getPublicKey());
+			    }
+			}
+		    }
+		}
+	    }
+	    throw new KeySelectorException("No X509Certificate found!");
+	}
+    }
+
+    /**
+     * KeySelector which would retrieve the public key out of the 
+     * KeyValue element and return it.
+     * NOTE: If the key algorithm doesn't match signature algorithm,
+     * then the public key will be ignored.
+     */
+    public static class KeyValueKeySelector extends KeySelector {
+	public KeySelectorResult select(KeyInfo keyInfo, 
+					KeySelector.Purpose purpose, 
+					AlgorithmMethod method, 
+					XMLCryptoContext context) 
+	    throws KeySelectorException {
+	    if (keyInfo == null) {
+		throw new KeySelectorException("Null KeyInfo object!");
+	    }
+	    SignatureMethod sm = (SignatureMethod) method;
+	    List list = keyInfo.getContent();
+	    
+	    for (int i = 0; i < list.size(); i++) {
+		XMLStructure xmlStructure = (XMLStructure) list.get(i);
+		if (xmlStructure instanceof KeyValue) {
+		    PublicKey pk = null;
+		    try {
+			pk = ((KeyValue)xmlStructure).getPublicKey();
+		    } catch (KeyException ke) {
+			throw new KeySelectorException(ke);
+		    }
+		    // make sure algorithm is compatible with method
+		    if (algEquals(sm.getAlgorithm(), pk.getAlgorithm())) {
+			return new SimpleKSResult(pk);
+		    } 
+		}
+	    }
+	    throw new KeySelectorException("No KeyValue element found!");
+	}
+	
+	//@@@FIXME: this should also work for key types other than DSA/RSA
+	static boolean algEquals(String algURI, String algName) {
+	    if (algName.equalsIgnoreCase("DSA") && 
+		algURI.equalsIgnoreCase(SignatureMethod.DSA_SHA1)) {
+		return true;
+	    } else if (algName.equalsIgnoreCase("RSA") &&
+		       algURI.equalsIgnoreCase(SignatureMethod.RSA_SHA1)) {
+		return true;
+	    } else {
+		return false;
+	    }
+	}
+    }
+
+    /**
+     * KeySelector which would perform special lookup as documented
+     * by the ie/baltimore/merlin-examples testcases and return the 
+     * matching public key.
+     */
+    public static class CollectionKeySelector extends KeySelector {
+	private CertificateFactory certFac;
+	private File certDir;
+	private Vector certs;
+	private static final int MATCH_SUBJECT = 0;
+	private static final int MATCH_ISSUER = 1;
+	private static final int MATCH_SERIAL = 2;
+	private static final int MATCH_SUBJECT_KEY_ID = 3;
+	private static final int MATCH_CERTIFICATE = 4;
+	
+	public CollectionKeySelector(File dir) {
+	    certDir = dir;
+	    try {
+		certFac = CertificateFactory.getInstance("X509");
+	    } catch (CertificateException ex) {
+		// not going to happen
+	    }
+	    certs = new Vector();
+	    File[] files = new File(certDir, "certs").listFiles();
+	    for (int i = 0; i < files.length; i++) {
+		try {
+		    certs.add((X509Certificate)certFac.generateCertificate
+			      (new FileInputStream(files[i])));
+		} catch (Exception ex) {
+		    // ignore non-cert files
+		}
+	    }
+	}
+	
+	public Vector match(int matchType, Object value, Vector pool) {
+	    Vector matchResult = new Vector();
+	    for (int j=0; j < pool.size(); j++) {
+		X509Certificate c = (X509Certificate) pool.get(j);
+		switch (matchType) {
+		case MATCH_SUBJECT:
+		    try {
+		        if (c.getSubjectDN().equals(new X500Name((String)value))) {
+			    matchResult.add(c);
+		        }
+		    } catch (IOException ioe) { }
+		    break;
+		case MATCH_ISSUER:
+		    try {
+		        if (c.getIssuerDN().equals(new X500Name((String)value))) {
+			    matchResult.add(c);
+		        }
+		    } catch (IOException ioe) { }
+		    break;
+		case MATCH_SERIAL:
+		    if (c.getSerialNumber().equals(value)) {
+			matchResult.add(c);
+		    }
+		    
+		    break;
+		case MATCH_SUBJECT_KEY_ID:
+		    byte[] extension = c.getExtensionValue("2.5.29.14");
+		    if (extension != null) {
+			try {
+			    DerValue derValue = new DerValue(extension);
+			    DerValue derValue2 = new DerValue(derValue.getOctetString());
+			    byte[] extVal = derValue2.getOctetString();
+			    
+			    if (Arrays.equals(extVal, (byte[]) value)) {
+				matchResult.add(c);
+			    }
+			} catch (IOException ex) { }
+		    }
+		    break;
+		case MATCH_CERTIFICATE:
+		    if (c.equals(value)) {
+			matchResult.add(c);
+		    }
+		    break;
+		}
+	    }
+	    return matchResult;
+	}
+	
+	public KeySelectorResult select(KeyInfo keyInfo, 
+					KeySelector.Purpose purpose, 
+					AlgorithmMethod method, 
+					XMLCryptoContext context) 
+	    throws KeySelectorException {
+	    if (keyInfo == null) {
+		throw new KeySelectorException("Null KeyInfo object!");
+	    }
+	    Iterator iter = keyInfo.getContent().iterator();
+	    while (iter.hasNext()) {
+		XMLStructure xmlStructure = (XMLStructure) iter.next();
+		try {
+		    if (xmlStructure instanceof KeyName) {
+			String name = ((KeyName)xmlStructure).getName();
+			PublicKey pk = null;
+			try {
+			    // Lookup the public key using the key name 'Xxx', 
+			    // i.e. the public key is in "certs/xxx.crt".
+			    File certFile = new File(new File(certDir, "certs"),
+				name.toLowerCase()+".crt");
+			    X509Certificate cert = (X509Certificate) 
+			        certFac.generateCertificate
+			        (new FileInputStream(certFile));
+			    pk = cert.getPublicKey();
+		        } catch (FileNotFoundException e) {
+			    // assume KeyName contains subject DN and search
+			    // collection of certs for match
+			    Vector result = match(MATCH_SUBJECT, name, certs);
+			    int numOfMatches = (result==null? 0:result.size());
+			    if (numOfMatches != 1) {
+			        throw new KeySelectorException
+				    ((numOfMatches==0?"No":"More than one") + 
+				     " match found");
+			    }
+			    pk =((X509Certificate)result.get(0)).getPublicKey();
+			}
+			return new SimpleKSResult(pk);
+		    } else if (xmlStructure instanceof RetrievalMethod) {
+			// Lookup the public key using the retrievel method.
+			// NOTE: only X509Certificate type is supported.
+			RetrievalMethod rm = (RetrievalMethod) xmlStructure;
+			String type = rm.getType();
+			if (type.equals(X509Data.RAW_X509_CERTIFICATE_TYPE)) {
+			    String uri = rm.getURI();
+			    X509Certificate cert = (X509Certificate) 
+				certFac.generateCertificate
+				(new FileInputStream(new File(certDir, uri)));
+			    return new SimpleKSResult(cert.getPublicKey());
+			} else {
+			    throw new KeySelectorException
+				("Unsupported RetrievalMethod type");
+			}
+		    } else if (xmlStructure instanceof X509Data) {
+			List content = ((X509Data)xmlStructure).getContent();
+			int size = content.size();
+			Vector result = null;
+			// Lookup the public key using the information 
+			// specified in X509Data element, i.e. searching
+			// over the collection of certificate files under
+			// "certs" subdirectory and return those match.
+			for (int k = 0; k<size; k++) {
+			    Object obj = content.get(k);
+			    if (obj instanceof String) {
+				result = match(MATCH_SUBJECT, obj, certs);
+			    } else if (obj instanceof byte[]) {
+				result = match(MATCH_SUBJECT_KEY_ID, obj, 
+					       certs);
+			    } else if (obj instanceof X509Certificate) {
+				result = match(MATCH_CERTIFICATE, obj, certs);
+			    } else if (obj instanceof X509IssuerSerial) {
+				X509IssuerSerial is = (X509IssuerSerial) obj;
+				result = match(MATCH_SERIAL, 
+					       is.getSerialNumber(), certs);
+				result = match(MATCH_ISSUER, 
+					       is.getIssuerName(), result);
+			    } else {
+				throw new KeySelectorException("Unsupported X509Data: " + obj);
+			    }
+			}
+			int numOfMatches = (result==null? 0:result.size());
+			if (numOfMatches != 1) {
+			    throw new KeySelectorException
+				((numOfMatches==0?"No":"More than one") + 
+				 " match found");
+			}
+			return new SimpleKSResult(((X509Certificate)
+					  result.get(0)).getPublicKey());
+		    }
+		} catch (Exception ex) {
+		    throw new KeySelectorException(ex);
+		}
+	    }
+	    throw new KeySelectorException("No matching key found!");
+	}
+    }
+    
+    public static class ByteUtil {
+	
+	private static String mapping = "0123456789ABCDEF";
+	private static int numBytesPerRow = 6;
+	
+	private static String getHex(byte value) {
+	    int low = value & 0x0f;
+	    int high = ((value >> 4) & 0x0f);
+	    char[] res = new char[2];
+	    res[0] = mapping.charAt(high);
+	    res[1] = mapping.charAt(low);
+	    return new String(res);
+	}
+
+	public static String dumpArray(byte[] in) {
+	    int numDumped = 0;
+	    StringBuffer buf = new StringBuffer(512);
+	    buf.append("{");
+	    for (int i=0;i<(in.length/numBytesPerRow); i++) {
+		for (int j=0; j<(numBytesPerRow); j++) {
+		    buf.append("(byte)0x" + getHex(in[i*numBytesPerRow+j]) + 
+			       ", ");
+		}
+		numDumped += numBytesPerRow;
+	    }
+	    while (numDumped < in.length) {
+		buf.append("(byte)0x" + getHex(in[numDumped]) + " ");
+		numDumped += 1;
+	    }
+	    buf.append("}");
+	    return buf.toString();
+	}
+    }
+}
+
+class SimpleKSResult implements KeySelectorResult {
+    private final Key key;
+    
+    SimpleKSResult(Key key) { this.key = key; }
+    
+    public Key getKey() { return key; }
+}

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/OctetStreamDataTest.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/OctetStreamDataTest.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/OctetStreamDataTest.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/OctetStreamDataTest.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ */
+package javax.xml.crypto.test;
+
+import java.io.*;
+import java.util.*;
+import javax.xml.crypto.*;
+
+import junit.framework.*;
+
+/**
+ * Unit test for javax.xml.crypto.OctetStreamData
+ *
+ * @version $Id$
+ * @author Valerie Peng
+ */
+public class OctetStreamDataTest extends TestCase {
+
+    public OctetStreamDataTest() {
+	super("OctetStreamDataTest");
+    }
+
+    public OctetStreamDataTest(String name) {
+	super(name);
+    }
+
+    public void setUp() throws Exception { 
+    }
+    
+    public void tearDown() {}
+    
+    public void testConstructor() {
+	// test OctetStreamData(InputStream) and 
+	// OctetStreamData(InputStream, String, String)
+	OctetStreamData osdata;
+	try {
+	    osdata = new OctetStreamData(null); 
+	    fail("Should raise a NPE for null input stream"); 
+	} catch (NullPointerException npe) {}	
+	try {
+	    osdata = new OctetStreamData(null, "uri", "mimeType");
+	    fail("Should raise a NPE for null input stream"); 
+	} catch (NullPointerException npe) {}
+
+	int len = 300;
+	byte[] in = new byte[len];
+	new Random().nextBytes(in);
+	ByteArrayInputStream bais = new ByteArrayInputStream(in);
+	try {
+	    osdata = new OctetStreamData(bais); 
+	    assertNotNull(osdata);
+	    assertEquals(osdata.getOctetStream(), bais);
+	    assertNull(osdata.getURI());
+	    assertNull(osdata.getMimeType());
+	
+	    osdata = new OctetStreamData(bais, null, null);
+	    assertNotNull(osdata);
+	    assertEquals(osdata.getOctetStream(), bais);
+	    assertNull(osdata.getURI());
+	    assertNull(osdata.getMimeType());
+	} catch (Exception ex) {
+	    fail("Unexpected Exception: " + ex);
+	}
+
+	String uri="testUri";
+	String mimeType="test";
+	try {
+	    osdata = new OctetStreamData(bais, uri, mimeType);
+	    assertNotNull(osdata);
+	    assertEquals(osdata.getOctetStream(), bais);
+	    assertEquals(osdata.getURI(), uri);
+	    assertEquals(osdata.getMimeType(), mimeType);
+	} catch (Exception ex) {
+	    fail("Unexpected Exception: " + ex);
+	}
+    }
+}

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/Baltimore18Test.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/Baltimore18Test.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/Baltimore18Test.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/Baltimore18Test.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package javax.xml.crypto.test.dsig;
+
+import java.io.File;
+import java.security.Security;
+import javax.xml.crypto.KeySelector;
+
+import junit.framework.*;
+
+import javax.xml.crypto.test.KeySelectors;
+
+/**
+ * This is a testcase to validate all "merlin-xmldsig-eighteen" 
+ * testcases from Baltimore
+ */
+public class Baltimore18Test extends TestCase {
+
+    private SignatureValidator validator;
+    private File dir;
+    private KeySelector cks;
+
+    static {
+	Security.insertProviderAt
+	    (new org.jcp.xml.dsig.internal.dom.XMLDSigRI(), 1);
+    }
+
+    public Baltimore18Test(String name) {
+        super(name);
+	String fs = System.getProperty("file.separator");
+	dir = new File(System.getProperty("basedir") + fs + "data" + fs + "ie" +
+	    fs + "baltimore" + fs + "merlin-examples",
+            "merlin-xmldsig-eighteen");
+	validator = new SignatureValidator(dir);
+	cks = new KeySelectors.CollectionKeySelector(dir);
+    }
+    
+    public void test_signature_keyname() throws Exception {
+        String file = "signature-keyname.xml";
+	
+	boolean coreValidity = validator.validate(file, cks);
+	assertTrue("Signature failed core validation", coreValidity);
+    }
+    
+    public void test_signature_retrievalmethod_rawx509crt() throws Exception {
+        String file = "signature-retrievalmethod-rawx509crt.xml";
+
+	boolean coreValidity = validator.validate(file, cks);
+	assertTrue("Signature failed core validation", coreValidity);
+    }
+    
+    public void test_signature_x509_crt_crl() throws Exception {
+        String file = "signature-x509-crt-crl.xml";
+
+	boolean coreValidity = validator.validate(file, cks);
+	assertTrue("Signature failed core validation", coreValidity);
+    }
+
+    public void test_signature_x509_crt() throws Exception {
+        String file = "signature-x509-crt.xml";
+
+	boolean coreValidity = validator.validate(file, cks);
+	assertTrue("Signature failed core validation", coreValidity);
+    }
+    
+    public void test_signature_x509_is() throws Exception {
+        String file = "signature-x509-is.xml";
+
+	boolean coreValidity = validator.validate(file, cks);
+	assertTrue("Signature failed core validation", coreValidity);
+    }
+    
+    public void test_signature_x509_ski() throws Exception {
+        String file = "signature-x509-ski.xml";
+
+	boolean coreValidity = validator.validate(file, cks);
+	assertTrue("Signature failed core validation", coreValidity);
+    }
+
+    public void test_signature_x509_sn() throws Exception {
+        String file = "signature-x509-sn.xml";
+
+	boolean coreValidity = validator.validate(file, cks);
+	assertTrue("Signature failed core validation", coreValidity);
+    }
+
+    public static void main(String[] args) throws Exception {
+        Baltimore18Test bt = new Baltimore18Test("");
+	bt.test_signature_keyname();
+	bt.test_signature_retrievalmethod_rawx509crt();
+	bt.test_signature_x509_crt_crl();
+	bt.test_signature_x509_crt();
+	bt.test_signature_x509_is();
+	bt.test_signature_x509_ski();
+	bt.test_signature_x509_sn();
+    }
+}

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/Baltimore23Test.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/Baltimore23Test.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/Baltimore23Test.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/Baltimore23Test.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,206 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package javax.xml.crypto.test.dsig;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.security.KeyStore;
+import java.security.Security;
+import javax.xml.crypto.KeySelector;
+
+import junit.framework.*;
+
+import javax.xml.crypto.test.KeySelectors;
+
+/**
+ * This is a testcase to validate all "merlin-xmldsig-twenty-three" 
+ * testcases from Baltimore
+ */
+public class Baltimore23Test extends TestCase {
+
+    private SignatureValidator validator;
+    private File dir;
+
+    static {
+        Security.insertProviderAt
+            (new org.jcp.xml.dsig.internal.dom.XMLDSigRI(), 1);
+    }
+
+    public Baltimore23Test(String name) {
+        super(name);
+	String fs = System.getProperty("file.separator");
+	dir = new File(System.getProperty("basedir") + fs + "data" + fs 
+	    + "ie" + fs + "baltimore" + fs + "merlin-examples",
+            "merlin-xmldsig-twenty-three");
+	validator = new SignatureValidator(dir);
+    }
+
+    public void test_signature_enveloped_dsa() throws Exception {
+        String file = "signature-enveloped-dsa.xml";
+
+	boolean coreValidity = validator.validate
+	    (file, new KeySelectors.KeyValueKeySelector());
+	assertTrue("Signature failed core validation", coreValidity);
+    }
+    
+    public void test_signature_enveloping_b64_dsa() throws Exception {
+        String file = "signature-enveloping-b64-dsa.xml";
+     
+	boolean coreValidity = validator.validate
+	    (file, new KeySelectors.KeyValueKeySelector());
+	assertTrue("Signature failed core validation", coreValidity);
+    }
+    
+    public void test_signature_enveloping_dsa() throws Exception {
+        String file = "signature-enveloping-dsa.xml";
+       
+	boolean coreValidity = validator.validate
+	    (file, new KeySelectors.KeyValueKeySelector());
+	assertTrue("Signature failed core validation", coreValidity);
+    }
+
+    public void test_signature_external_b64_dsa() throws Exception {
+        String file = "signature-external-b64-dsa.xml";
+       
+	boolean coreValidity = validator.validate
+	    (file, new KeySelectors.KeyValueKeySelector());
+	assertTrue("Signature failed core validation", coreValidity);
+    }
+
+    public void test_signature_external_dsa() throws Exception {
+        String file = "signature-external-dsa.xml";
+        
+	boolean coreValidity = validator.validate
+	    (file, new KeySelectors.KeyValueKeySelector());
+	assertTrue("Signature failed core validation", coreValidity);
+    }
+    
+    public void test_signature_enveloping_rsa() throws Exception {
+        String file = "signature-enveloping-rsa.xml";
+       
+	boolean coreValidity = validator.validate
+	    (file, new KeySelectors.KeyValueKeySelector());
+	assertTrue("Signature failed core validation", coreValidity);
+    }
+
+    public void test_signature_enveloping_hmac_sha1() throws Exception {
+        String file = "signature-enveloping-hmac-sha1.xml";
+        
+	KeySelector ks = new KeySelectors.SecretKeySelector
+	    ("secret".getBytes("ASCII") );
+	boolean coreValidity = validator.validate(file, ks);
+	assertTrue("Signature failed core validation", coreValidity);
+    }
+
+    public void test_signature_enveloping_hmac_sha1_40() throws Exception {
+        String file = "signature-enveloping-hmac-sha1-40.xml";
+        
+	KeySelector ks = new KeySelectors.SecretKeySelector
+	    ("secret".getBytes("ASCII") );
+	boolean coreValidity = validator.validate(file, ks);
+	assertTrue("Signature failed core validation", coreValidity);
+    }
+
+    public void test_signature_keyname() throws Exception {
+        String file = "signature-keyname.xml";
+        
+	boolean coreValidity = validator.validate
+	    (file, new KeySelectors.CollectionKeySelector(dir));
+	assertTrue("Signature failed core validation", coreValidity);
+    }
+    
+    public void test_signature_retrievalmethod_rawx509crt() throws Exception {
+        String file = "signature-retrievalmethod-rawx509crt.xml";
+        
+	boolean coreValidity = validator.validate
+	    (file, new KeySelectors.CollectionKeySelector(dir));
+	assertTrue("Signature failed core validation", coreValidity);
+    }
+    
+    public void test_signature_x509_crt_crl() throws Exception {
+        String file = "signature-x509-crt-crl.xml";
+        
+	boolean coreValidity = validator.validate
+	    (file, new KeySelectors.RawX509KeySelector());
+	assertTrue("Signature failed core validation", coreValidity);
+    }
+
+    public void test_signature_x509_crt() throws Exception {
+        String file = "signature-x509-crt.xml";
+       
+	boolean coreValidity = validator.validate
+	    (file, new KeySelectors.RawX509KeySelector());
+	assertTrue("Signature failed core validation", coreValidity);
+    }
+    
+    public void test_signature_x509_is() throws Exception {
+        String file = "signature-x509-is.xml";
+        
+	boolean coreValidity = validator.validate
+	    (file, new KeySelectors.CollectionKeySelector(dir));
+	assertTrue("Signature failed core validation", coreValidity);
+    }
+    
+    public void test_signature_x509_ski() throws Exception {
+        String file = "signature-x509-ski.xml";
+        
+	boolean coreValidity = validator.validate
+	    (file, new KeySelectors.CollectionKeySelector(dir));
+	assertTrue("Signature failed core validation", coreValidity);
+    }
+
+    public void test_signature_x509_sn() throws Exception {
+        String file = "signature-x509-sn.xml";
+        
+	boolean coreValidity = validator.validate
+	    (file, new KeySelectors.CollectionKeySelector(dir));
+	assertTrue("Signature failed core validation", coreValidity);
+    }
+
+    public void test_signature() throws Exception {
+        String file = "signature.xml";
+	String fs = System.getProperty("file.separator");
+	String keystore = System.getProperty("basedir") + fs + "data" + fs +
+	     "ie" + fs + "baltimore" + fs + "merlin-examples" + fs +
+	     "merlin-xmldsig-twenty-three" + fs + "certs" + fs + "xmldsig.jks";
+	KeyStore ks = KeyStore.getInstance("JKS");
+	ks.load(new FileInputStream(keystore), "changeit".toCharArray());
+
+        boolean cv = validator.validate(file, new X509KeySelector(ks, false));
+        assertTrue("Signature failed core validation", cv);
+    }
+
+    public static void main(String[] args) throws Exception {
+        Baltimore23Test bt = new Baltimore23Test("");
+        bt.test_signature_enveloped_dsa();
+	bt.test_signature(); 
+	bt.test_signature_enveloping_b64_dsa();
+	bt.test_signature_enveloping_dsa();
+	bt.test_signature_enveloping_hmac_sha1();
+	bt.test_signature_enveloping_hmac_sha1_40();
+	bt.test_signature_enveloping_rsa();
+	bt.test_signature_external_b64_dsa();
+	bt.test_signature_external_dsa();
+	bt.test_signature_keyname();
+	bt.test_signature_retrievalmethod_rawx509crt();
+	bt.test_signature_x509_crt_crl();
+	bt.test_signature_x509_crt();
+	bt.test_signature_x509_is();
+	bt.test_signature_x509_ski();
+	bt.test_signature_x509_sn();
+    }
+}

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/BaltimoreExcC14n1Test.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/BaltimoreExcC14n1Test.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/BaltimoreExcC14n1Test.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/BaltimoreExcC14n1Test.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package javax.xml.crypto.test.dsig;
+
+import java.io.File;
+import java.security.Security;
+
+import junit.framework.*;
+
+import javax.xml.crypto.test.KeySelectors;
+
+/**
+ * This is a testcase to validate all "merlin-exc-c14n-one" 
+ * testcases from Baltimore
+ */
+public class BaltimoreExcC14n1Test extends TestCase {
+
+    private SignatureValidator validator;
+
+    static {
+        Security.insertProviderAt
+            (new org.jcp.xml.dsig.internal.dom.XMLDSigRI(), 1);
+    }
+
+    public BaltimoreExcC14n1Test(String name) {
+        super(name);
+	String fs = System.getProperty("file.separator");
+	String base = System.getProperty("basedir") + fs + "data" + fs + "ie" +
+	    fs + "baltimore" + fs + "merlin-examples";
+	validator = new SignatureValidator(new File
+	    (base, "merlin-exc-c14n-one"));
+    }
+
+    public void test_exc_signature() throws Exception {
+        String file = "exc-signature.xml";
+
+	boolean coreValidity = validator.validate
+	    (file, new KeySelectors.KeyValueKeySelector());
+	assertTrue("Signature failed core validation", coreValidity);
+    }
+
+    public static void main(String[] args) throws Exception {
+        BaltimoreExcC14n1Test bt = new BaltimoreExcC14n1Test("");
+	bt.test_exc_signature();
+    }
+}

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/BaltimoreIaik2Test.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/BaltimoreIaik2Test.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/BaltimoreIaik2Test.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/BaltimoreIaik2Test.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package javax.xml.crypto.test.dsig;
+
+import java.io.File;
+import java.security.Security;
+
+import junit.framework.*;
+
+import javax.xml.crypto.test.KeySelectors;
+
+/**
+ * This is a testcase to validate all "ec-merlin-iaikTests-two" 
+ * testcases from Baltimore
+ */
+public class BaltimoreIaik2Test extends TestCase {
+
+    private SignatureValidator validator;
+    private File dir;
+
+    static {
+        Security.insertProviderAt
+            (new org.jcp.xml.dsig.internal.dom.XMLDSigRI(), 1);
+    }
+
+    public BaltimoreIaik2Test(String name) {
+        super(name);
+	String fs = System.getProperty("file.separator");
+	dir = new File(System.getProperty("basedir") + fs + "data" + fs +
+	    "ie" + fs + "baltimore" + fs + "merlin-examples",
+            "ec-merlin-iaikTests-two");
+	validator = new SignatureValidator(dir);
+    }
+
+    public void test_signature() throws Exception {
+        String file = "signature.xml";
+	boolean coreValidity = validator.validate
+	    (file, new KeySelectors.KeyValueKeySelector());
+        assertTrue("Signature failed core validation", coreValidity);
+    }    
+
+    public static void main(String[] args) throws Exception {
+        BaltimoreIaik2Test bt = new BaltimoreIaik2Test("");
+	bt.test_signature();
+    }
+}

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/BaltimoreXPathFilter2ThreeTest.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/BaltimoreXPathFilter2ThreeTest.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/BaltimoreXPathFilter2ThreeTest.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/BaltimoreXPathFilter2ThreeTest.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package javax.xml.crypto.test.dsig;
+
+import java.io.File;
+import java.security.Security;
+
+import junit.framework.*;
+
+import javax.xml.crypto.test.KeySelectors;
+
+/**
+ * This is a testcase to validate the "merlin-xpath-filter2-three" testcases
+ * under data/vectors/ie/baltimore/merlin-examples directory
+ */
+public class BaltimoreXPathFilter2ThreeTest extends TestCase {
+
+    private SignatureValidator validator = null;
+
+    static {
+        Security.insertProviderAt
+            (new org.jcp.xml.dsig.internal.dom.XMLDSigRI(), 1);
+    }
+
+    public BaltimoreXPathFilter2ThreeTest(String name) {
+        super(name);
+	String fs = System.getProperty("file.separator");
+	String base = System.getProperty("basedir") + fs + "data"
+	    + fs + "interop" + fs + "xfilter2";
+	validator = new SignatureValidator(new File
+	    (base, "merlin-xpath-filter2-three"));
+    }
+    public void test_sign_spec() throws Exception {
+        String file = "sign-spec.xml";
+
+	boolean coreValidity = validator.validate(file, 
+		    new KeySelectors.KeyValueKeySelector());
+	assertTrue("Signature failed core validation#1", coreValidity);
+
+ 	coreValidity = validator.validate(file, 
+		    new KeySelectors.RawX509KeySelector());
+	assertTrue("Signature failed core validation#2", coreValidity);
+    }
+    public void test_sign_xfdl() throws Exception {
+        String file = "sign-xfdl.xml";
+
+	boolean coreValidity = validator.validate(file, 
+		    new KeySelectors.KeyValueKeySelector());
+	assertTrue("Signature failed core validation#1", coreValidity);
+
+ 	coreValidity = validator.validate(file, 
+		    new KeySelectors.RawX509KeySelector());
+	assertTrue("Signature failed core validation#2", coreValidity);
+    }
+    public static void main(String[] args) throws Exception {
+        BaltimoreXPathFilter2ThreeTest it = 
+	    new BaltimoreXPathFilter2ThreeTest("");
+	it.test_sign_spec();
+	it.test_sign_xfdl();
+    }
+}

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/CanonicalizationMethodTest.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/CanonicalizationMethodTest.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/CanonicalizationMethodTest.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/CanonicalizationMethodTest.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,133 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package javax.xml.crypto.test.dsig;
+
+import java.io.File;
+import java.security.*;
+import java.security.spec.AlgorithmParameterSpec;
+import javax.xml.crypto.dsig.*;
+import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec;
+import javax.xml.crypto.dsig.spec.ExcC14NParameterSpec;
+
+import junit.framework.*;
+
+/**
+ * Unit test for javax.xml.crypto.dsig.CanonicalizationMethod
+ *
+ * @version $Id$
+ * @author Valerie Peng
+ */
+public class CanonicalizationMethodTest extends TestCase {
+
+    XMLSignatureFactory factory;
+
+    static {
+        Security.insertProviderAt
+            (new org.jcp.xml.dsig.internal.dom.XMLDSigRI(), 1);
+    }
+
+    private static final String C14N_ALGOS[] = {
+	CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS,
+	CanonicalizationMethod.INCLUSIVE,
+	CanonicalizationMethod.EXCLUSIVE_WITH_COMMENTS,
+	CanonicalizationMethod.EXCLUSIVE
+    };
+
+    public CanonicalizationMethodTest() {
+	super("CanonicalizationMethodTest");
+    }
+
+    public CanonicalizationMethodTest(String name) {
+	super(name);
+    }
+
+    public void setUp() throws Exception { 
+	factory = XMLSignatureFactory.getInstance
+            ("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
+    }
+
+    public void tearDown() { }
+
+    public void testisFeatureSupported() throws Exception {
+	CanonicalizationMethod cm; 
+	for (int i = 0; i < C14N_ALGOS.length; i++) {
+	    String algo = C14N_ALGOS[i];
+	    ExcC14NParameterSpec params = null;
+	    if (i >= 2) {
+		params = new ExcC14NParameterSpec();
+	    }
+	    cm = factory.newCanonicalizationMethod(algo, params);
+	    try {
+		cm.isFeatureSupported(null); 
+		fail("Should raise a NPE for null feature"); 
+	    } catch (NullPointerException npe) {}
+	    
+	    assertTrue(!cm.isFeatureSupported("not supported"));
+	}
+    }
+
+    public void testConstructor() throws Exception {
+	// test newAlgorithmMethod(String algorithm, 
+	//                         AlgorithmParameterSpec params)
+	// for generating CanonicalizationMethod objects
+	CanonicalizationMethod cm; 
+	for (int i = 0; i < C14N_ALGOS.length; i++) {
+	    String algo = C14N_ALGOS[i];
+	    cm = factory.newCanonicalizationMethod(algo, 
+		(C14NMethodParameterSpec) null);
+	    assertNotNull(cm);
+	    assertEquals(cm.getAlgorithm(), algo);
+	    assertNull(cm.getParameterSpec());
+	    
+	    try {
+		cm = factory.newCanonicalizationMethod
+		    (algo, new TestUtils.MyOwnC14nParameterSpec());
+		fail("Should raise an IAPE for invalid c14n parameters"); 
+	    } catch (InvalidAlgorithmParameterException iape) {
+	    } catch (Exception ex) {
+		fail("Should raise a IAPE instead of " + ex); 
+	    }
+	    if (algo.equals(CanonicalizationMethod.EXCLUSIVE_WITH_COMMENTS) ||
+		algo.equals(CanonicalizationMethod.EXCLUSIVE)) {
+		cm = factory.newCanonicalizationMethod
+		    (CanonicalizationMethod.EXCLUSIVE,
+		     new ExcC14NParameterSpec());
+		AlgorithmParameterSpec aps = cm.getParameterSpec();
+		assertNotNull(aps);
+		assertTrue(aps instanceof ExcC14NParameterSpec);	
+	    }
+	}
+
+	try {
+	    cm = factory.newCanonicalizationMethod(null, 
+		(C14NMethodParameterSpec) null); 
+	    fail("Should raise a NPE for null algo"); 
+	} catch (NullPointerException npe) {
+	} catch (Exception ex) {
+	    fail("Should raise a NPE instead of " + ex); 
+	}
+
+	try {
+	    cm = factory.newCanonicalizationMethod("non-existent", 
+		(C14NMethodParameterSpec) null); 
+	    fail("Should raise an NSAE for non-existent algos"); 
+	} catch (NoSuchAlgorithmException nsae) {
+	} catch (Exception ex) {
+	    fail("Should raise an NSAE instead of " + ex); 
+	}
+    }
+}

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/ComRSASecurityTest.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/ComRSASecurityTest.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/ComRSASecurityTest.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/ComRSASecurityTest.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package javax.xml.crypto.test.dsig;
+
+import java.io.File;
+import java.security.Security;
+
+import junit.framework.*;
+
+import javax.xml.crypto.test.KeySelectors;
+
+/**
+ * This is a testcase to validate all "bdournaee" 
+ * testcases from RSA
+ */
+public class ComRSASecurityTest extends TestCase {
+
+    private SignatureValidator validator;
+
+    static {
+        Security.insertProviderAt
+            (new org.jcp.xml.dsig.internal.dom.XMLDSigRI(), 1);
+    }
+
+    public ComRSASecurityTest(String name) {
+        super(name);
+	String fs = System.getProperty("file.separator");
+	String base = System.getProperty("basedir") + fs + "data" + fs + "com";
+	validator = new SignatureValidator(new File
+	    (base, "rsasecurity/bdournaee"));
+    }
+    public void test_certj201_enveloping() throws Exception {
+        String file = "certj201_enveloping.xml";
+
+	boolean coreValidity = validator.validate
+	    (file, new KeySelectors.KeyValueKeySelector());
+	assertTrue("Signature failed core validation", coreValidity);
+    }
+    public void test_certj201_enveloped() throws Exception {
+        String file = "certj201_enveloped.xml";
+
+	boolean coreValidity = validator.validate
+	    (file, new KeySelectors.KeyValueKeySelector());
+	assertTrue("Signature failed core validation", coreValidity);
+    }
+    public static void main(String[] args) throws Exception {
+        ComRSASecurityTest ct = new ComRSASecurityTest("");
+	ct.test_certj201_enveloped();
+	ct.test_certj201_enveloping();
+    }
+}

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/CreateBaltimore23Test.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/CreateBaltimore23Test.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/CreateBaltimore23Test.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/CreateBaltimore23Test.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,661 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package javax.xml.crypto.test.dsig;
+
+import java.io.*;
+import java.math.BigInteger;
+import java.security.Key;
+import java.security.KeyStore;
+import java.security.PublicKey;
+import java.security.Security;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
+import java.security.cert.X509CRL;
+import java.util.*;
+import javax.xml.parsers.*;
+import org.w3c.dom.*;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXParseException;
+import javax.xml.crypto.KeySelector;
+import javax.xml.crypto.dsig.*;
+import javax.xml.crypto.dom.*;
+import javax.xml.crypto.dsig.dom.DOMSignContext;
+import javax.xml.crypto.dsig.dom.DOMValidateContext;
+import javax.xml.crypto.dsig.keyinfo.*;
+import javax.xml.crypto.dsig.spec.*;
+import javax.xml.transform.*;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.xml.security.utils.Constants;
+
+import junit.framework.*;
+
+import javax.xml.crypto.test.KeySelectors;
+
+/**
+ * Test that recreates merlin-xmldsig-twenty-three test vectors but with
+ * different keys and X.509 data.
+ *
+ * @author Sean Mullan
+ */
+public class CreateBaltimore23Test extends TestCase {
+
+    private XMLSignatureFactory fac;
+    private KeyInfoFactory kifac;
+    private DocumentBuilder db;
+    private CanonicalizationMethod withoutComments;
+    private Transform withComments;
+    private SignatureMethod dsaSha1, rsaSha1;
+    private DigestMethod sha1;
+    private KeyInfo dsa, rsa;
+    private KeySelector kvks = new KeySelectors.KeyValueKeySelector();
+    private KeySelector sks; 
+    private Key signingKey;
+    private PublicKey validatingKey;
+    private Certificate signingCert;
+    private KeyStore ks;
+
+    static {
+        Security.insertProviderAt
+            (new org.jcp.xml.dsig.internal.dom.XMLDSigRI(), 1);
+    }
+
+    public CreateBaltimore23Test(String name) {
+	super(name);
+    }
+
+    public void setUp() throws Exception {
+	fac = XMLSignatureFactory.getInstance
+	    ("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
+	kifac = fac.getKeyInfoFactory();
+	DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+	dbf.setNamespaceAware(true);
+	db = dbf.newDocumentBuilder();
+
+	// get key & self-signed certificate from keystore
+	String fs = System.getProperty("file.separator");
+	FileInputStream fis = new FileInputStream
+	    (System.getProperty("basedir") + fs + "data" + fs + "test.jks");
+	ks = KeyStore.getInstance("JKS");
+	ks.load(fis, "changeit".toCharArray());
+	signingKey = ks.getKey("mullan", "changeit".toCharArray());
+	signingCert = ks.getCertificate("mullan");
+	validatingKey = signingCert.getPublicKey();
+
+	// create common objects
+	withoutComments = fac.newCanonicalizationMethod
+	    (CanonicalizationMethod.INCLUSIVE, (C14NMethodParameterSpec) null);
+	withComments = fac.newTransform
+	    (CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS, 
+	     (TransformParameterSpec) null);
+	dsaSha1 = fac.newSignatureMethod(SignatureMethod.DSA_SHA1, null);
+	sha1 = fac.newDigestMethod(DigestMethod.SHA1, null);
+	dsa = kifac.newKeyInfo(Collections.singletonList
+	    (kifac.newKeyValue(validatingKey)));
+	rsa = kifac.newKeyInfo(Collections.singletonList
+	    (kifac.newKeyValue(TestUtils.getPublicKey("RSA"))));
+	rsaSha1 = fac.newSignatureMethod(SignatureMethod.RSA_SHA1, null);
+        sks = new KeySelectors.SecretKeySelector("secret".getBytes("ASCII"));
+
+    }
+
+    public void test_create_signature_enveloped_dsa() throws Exception {
+	// create SignedInfo
+	SignedInfo si = fac.newSignedInfo
+	    (withoutComments, dsaSha1, Collections.singletonList
+		(fac.newReference
+		    ("", sha1, Collections.singletonList
+	                (fac.newTransform(Transform.ENVELOPED, 
+			 (TransformParameterSpec) null)), 
+	         null, null)));
+
+	// create XMLSignature
+	XMLSignature sig = fac.newXMLSignature(si, dsa);
+
+	Document doc = db.newDocument();
+	Element envelope = doc.createElementNS
+	    ("http://example.org/envelope", "Envelope");
+	envelope.setAttributeNS
+	    (Constants.NamespaceSpecNS, "xmlns", "http://example.org/envelope");
+	doc.appendChild(envelope);
+
+	DOMSignContext dsc = new DOMSignContext(signingKey, envelope);
+
+	sig.sign(dsc);
+
+	DOMValidateContext dvc = new DOMValidateContext
+	    (kvks, envelope.getFirstChild());
+	XMLSignature sig2 = fac.unmarshalXMLSignature(dvc);
+
+	assertTrue(sig.equals(sig2));
+
+	assertTrue(sig2.validate(dvc));
+    }
+
+    public void test_create_signature_enveloping_b64_dsa() throws Exception {
+	test_create_signature_enveloping(dsaSha1, dsa, signingKey, kvks, true);
+    }
+
+    public void test_create_signature_enveloping_dsa() throws Exception {
+	test_create_signature_enveloping(dsaSha1, dsa, signingKey, kvks, false);
+    }
+
+    public void test_create_signature_enveloping_hmac_sha1_40() 
+	throws Exception {
+	SignatureMethod hmacSha1 = fac.newSignatureMethod
+	    (SignatureMethod.HMAC_SHA1, new HMACParameterSpec(40));
+        test_create_signature_enveloping(hmacSha1, null,
+	    TestUtils.getSecretKey("secret".getBytes("ASCII")), sks, false);
+    }
+
+    public void test_create_signature_enveloping_hmac_sha1()
+	throws Exception {
+	SignatureMethod hmacSha1 = fac.newSignatureMethod
+	    (SignatureMethod.HMAC_SHA1, null);
+        test_create_signature_enveloping(hmacSha1, null,
+	    TestUtils.getSecretKey("secret".getBytes("ASCII")), sks, false);
+    }
+
+    public void test_create_signature_enveloping_rsa() throws Exception {
+	test_create_signature_enveloping(rsaSha1, rsa, 
+	    TestUtils.getPrivateKey("RSA"), kvks, false);
+    }
+
+    public void test_create_signature_external_b64_dsa() throws Exception {
+	test_create_signature_external(dsaSha1, dsa, signingKey, kvks, true);
+    }
+
+    public void test_create_signature_external_dsa() throws Exception {
+	test_create_signature_external(dsaSha1, dsa, signingKey, kvks, false);
+    }
+
+    public void test_create_signature_keyname() throws Exception {
+	KeyInfo kn = kifac.newKeyInfo(Collections.singletonList
+	    (kifac.newKeyName("mullan")));
+	test_create_signature_external(dsaSha1, kn, signingKey,
+	    new X509KeySelector(ks), false);
+    }
+
+    public void test_create_signature_retrievalmethod_rawx509crt() 
+	throws Exception {
+	KeyInfo rm = kifac.newKeyInfo(Collections.singletonList
+	    (kifac.newRetrievalMethod
+	    ("certs/mullan.crt", X509Data.RAW_X509_CERTIFICATE_TYPE, null)));
+	test_create_signature_external(dsaSha1, rm, signingKey,
+	    new X509KeySelector(ks), false);
+    }
+
+    public void test_create_signature_x509_crt_crl() throws Exception {
+	List xds = new ArrayList();
+	CertificateFactory cf = CertificateFactory.getInstance("X.509");
+	xds.add(signingCert);
+	String fs = System.getProperty("file.separator");
+	FileInputStream fis = new FileInputStream
+	    (System.getProperty("basedir") + fs + "data" + fs + "ie" + fs +
+	     "baltimore" + fs + "merlin-examples" + fs + 
+	     "merlin-xmldsig-twenty-three" + fs + "certs" + fs + "crl");
+	X509CRL crl = (X509CRL) cf.generateCRL(fis);
+	fis.close();
+	xds.add(crl);
+	KeyInfo crt_crl = kifac.newKeyInfo(Collections.singletonList
+            (kifac.newX509Data(xds)));
+
+	test_create_signature_external(dsaSha1, crt_crl, signingKey,
+	    new X509KeySelector(ks), false);
+    }
+
+    public void test_create_signature_x509_crt() throws Exception {
+	KeyInfo crt = kifac.newKeyInfo(Collections.singletonList
+            (kifac.newX509Data(Collections.singletonList(signingCert))));
+
+	test_create_signature_external(dsaSha1, crt, signingKey,
+	    new X509KeySelector(ks), false);
+    }
+
+    public void test_create_signature_x509_is() throws Exception {
+	KeyInfo is = kifac.newKeyInfo(Collections.singletonList
+	    (kifac.newX509Data(Collections.singletonList
+	    (kifac.newX509IssuerSerial
+	    ("CN=Sean Mullan,DC=sun,DC=com",
+	    new BigInteger("3f451a6a", 16))))));
+	test_create_signature_external(dsaSha1, is, signingKey,
+	    new X509KeySelector(ks), false);
+    }
+
+    public void test_create_signature_x509_ski() throws Exception {
+	KeyInfo ski = kifac.newKeyInfo(Collections.singletonList
+            (kifac.newX509Data(Collections.singletonList
+	    ("keyid".getBytes("ASCII")))));
+
+	test_create_signature_external(dsaSha1, ski, signingKey,
+	    KeySelector.singletonKeySelector(validatingKey), false);
+    }
+
+    public void test_create_signature_x509_sn() throws Exception {
+	KeyInfo sn = kifac.newKeyInfo(Collections.singletonList
+            (kifac.newX509Data(Collections.singletonList
+	    ("CN=Sean Mullan,DC=sun,DC=com"))));
+
+	test_create_signature_external(dsaSha1, sn, signingKey,
+	    new X509KeySelector(ks), false);
+    }
+
+    private void donottest_create_signature() throws Exception {
+	// set up reusable objects
+	Transform env = fac.newTransform(Transform.ENVELOPED, 
+	    (TransformParameterSpec) null);
+
+	// create references
+	List refs = new ArrayList();
+	
+	// Reference 1
+	refs.add(fac.newReference("http://www.w3.org/TR/xml-stylesheet", sha1));
+
+	// Reference 2
+        refs.add(fac.newReference
+	    ("http://www.w3.org/Signature/2002/04/xml-stylesheet.b64", 
+	    sha1, Collections.singletonList
+            (fac.newTransform(Transform.BASE64, 
+	     (TransformParameterSpec) null)), null, null));
+
+	// Reference 3
+        refs.add(fac.newReference("#object-1", sha1, Collections.singletonList
+	    (fac.newTransform(Transform.XPATH, 
+	    new XPathFilterParameterSpec("self::text()"))), 
+	    XMLObject.TYPE, null));
+
+	// Reference 4
+	String expr = "\n"
+          + " ancestor-or-self::dsig:SignedInfo			 " + "\n"
+          + "  and                                               " + "\n"
+          + " count(ancestor-or-self::dsig:Reference |		 " + "\n"
+          + "	   here()/ancestor::dsig:Reference[1]) >	 " + "\n"
+          + " count(ancestor-or-self::dsig:Reference)		 " + "\n"
+          + "  or                                                " + "\n"
+          + " count(ancestor-or-self::node() |			 " + "\n"
+          + "	   id('notaries')) =				 " + "\n"
+          + " count(ancestor-or-self::node())			 " + "\n";
+
+	XPathFilterParameterSpec xfp = new XPathFilterParameterSpec(expr,
+	    Collections.singletonMap("dsig", XMLSignature.XMLNS));
+//        refs.add(fac.newReference("", sha1, Collections.singletonList
+//	    (fac.newTransform(Transform.XPATH, xfp)),
+//	    XMLObject.TYPE, null));
+
+	// Reference 5
+        refs.add(fac.newReference("#object-2", sha1, Collections.singletonList
+	    (fac.newTransform(Transform.BASE64, (TransformParameterSpec) null)),
+	    XMLObject.TYPE, null));
+
+	// Reference 6
+        refs.add(fac.newReference
+	    ("#manifest-1", sha1, null, Manifest.TYPE, null));
+
+	// Reference 7
+        refs.add(fac.newReference("#signature-properties-1", sha1, null, 
+	    SignatureProperties.TYPE, null));
+
+	// Reference 8
+	List transforms = new ArrayList();
+	transforms.add(env);
+        refs.add(fac.newReference("", sha1, transforms, null, null));
+
+	// Reference 9
+	transforms.add(withComments);
+        refs.add(fac.newReference("", sha1, transforms, null, null));
+
+	// Reference 10
+        refs.add(fac.newReference("#xpointer(/)",
+	    sha1, Collections.singletonList(env), null, null));
+
+	// Reference 11
+        refs.add(fac.newReference("#xpointer(/)", sha1, transforms, 
+	    null, null));
+
+	// Reference 12
+        refs.add
+	    (fac.newReference("#object-3", sha1, null, XMLObject.TYPE, null));
+
+	// Reference 13
+        refs.add(fac.newReference("#object-3", sha1, 
+	    Collections.singletonList(withComments), XMLObject.TYPE, null));
+
+	// Reference 14
+        refs.add(fac.newReference("#xpointer(id('object-3'))", sha1, null, 
+	    XMLObject.TYPE, null));
+
+	// Reference 15
+        refs.add(fac.newReference("#xpointer(id('object-3'))", sha1, 
+	    Collections.singletonList(withComments), XMLObject.TYPE, null));
+
+	// Reference 16
+        refs.add(fac.newReference("#reference-2", sha1));
+
+	// Reference 17
+        refs.add(fac.newReference("#manifest-reference-1", sha1, null,
+	    null, "reference-1"));
+
+	// Reference 18
+        refs.add(fac.newReference("#reference-1", sha1, null, null,
+	    "reference-2"));
+
+	// create SignedInfo
+	SignedInfo si = fac.newSignedInfo(withoutComments, dsaSha1, refs);
+
+	// create keyinfo
+	XPathFilterParameterSpec xpf = new XPathFilterParameterSpec(
+	    "ancestor-or-self::dsig:X509Data",
+	    Collections.singletonMap("dsig", XMLSignature.XMLNS));
+	RetrievalMethod rm = kifac.newRetrievalMethod("#object-4", 
+	    X509Data.TYPE, Collections.singletonList(fac.newTransform
+	    (Transform.XPATH, xpf)));
+	KeyInfo ki = kifac.newKeyInfo(Collections.singletonList(rm), null);
+
+	Document doc = db.newDocument();
+
+	// create objects
+	List objs = new ArrayList();
+
+	// Object 1
+	objs.add(fac.newXMLObject(Collections.singletonList
+	    (new DOMStructure(doc.createTextNode("I am the text."))), 
+	    "object-1", "text/plain", null));
+
+	// Object 2
+	objs.add(fac.newXMLObject(Collections.singletonList
+	    (new DOMStructure(doc.createTextNode("SSBhbSB0aGUgdGV4dC4="))), 
+	    "object-2", "text/plain", Transform.BASE64));
+
+	// Object 3
+	Element nc = doc.createElementNS(null, "NonCommentandus");
+	nc.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", "");
+        nc.appendChild(doc.createComment(" Commentandum "));
+	objs.add(fac.newXMLObject(Collections.singletonList
+	    (new DOMStructure(nc)), "object-3", null, null));
+
+	// Manifest
+	List manRefs = new ArrayList();
+
+	// Manifest Reference 1
+	manRefs.add(fac.newReference("http://www.w3.org/TR/xml-stylesheet",
+	    sha1, null, null, "manifest-reference-1"));
+
+	// Manifest Reference 2
+	manRefs.add(fac.newReference("#reference-1", sha1));
+
+	// Manifest Reference 3
+	List manTrans = new ArrayList();
+        String xslt = ""
+	  + "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'\n"
+	  + "		 xmlns='http://www.w3.org/TR/xhtml1/strict' \n"
+	  + "		 exclude-result-prefixes='foo' \n"
+	  + "		 version='1.0'>\n"
+	  + "  <xsl:output encoding='UTF-8' \n"
+	  + "		indent='no' \n"
+	  + "		method='xml' />\n"
+	  + "  <xsl:template match='/'>\n"
+	  + "    <html>\n"
+	  + "	<head>\n"
+	  + "	 <title>Notaries</title>\n"
+	  + "	</head>\n"
+	  + "	<body>\n"
+	  + "	 <table>\n"
+	  + "	   <xsl:for-each select='Notaries/Notary'>\n"
+	  + "		<tr>\n"
+	  + "		<th>\n"
+	  + "		 <xsl:value-of select='@name' />\n"
+	  + "		</th>\n"
+	  + "		</tr>\n"
+	  + "	   </xsl:for-each>\n"
+	  + "	 </table>\n"
+	  + "	</body>\n"
+	  + "    </html>\n"
+	  + "  </xsl:template>\n"
+	  + "</xsl:stylesheet>\n";
+	Document docxslt = db.parse(new ByteArrayInputStream(xslt.getBytes()));
+        Node xslElem = docxslt.getDocumentElement();
+
+	manTrans.add(fac.newTransform(Transform.XSLT, 
+	    new XSLTTransformParameterSpec(new DOMStructure(xslElem))));
+	manTrans.add(fac.newTransform(CanonicalizationMethod.INCLUSIVE, 
+	    (TransformParameterSpec) null));
+	manRefs.add(fac.newReference("#notaries", sha1, manTrans, null, null));
+
+	objs.add(fac.newXMLObject(Collections.singletonList
+	    (fac.newManifest(manRefs, "manifest-1")), null, null, null));
+
+	// SignatureProperties
+	Element sa = doc.createElementNS("urn:demo", "SignerAddress");
+	sa.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", "urn:demo");
+	Element ip = doc.createElementNS("urn:demo", "IP");
+	ip.appendChild(doc.createTextNode("192.168.21.138"));
+	sa.appendChild(ip);
+	SignatureProperty sp = fac.newSignatureProperty
+	    (Collections.singletonList(new DOMStructure(sa)), 
+	    "#signature", null);
+	SignatureProperties sps = fac.newSignatureProperties
+	    (Collections.singletonList(sp), "signature-properties-1");
+	objs.add(fac.newXMLObject(Collections.singletonList(sps), null, 
+	    null, null));
+
+	// Object 4
+	List xds = new ArrayList();
+	xds.add("CN=Sean Mullan,DC=sun,DC=com");
+	xds.add(kifac.newX509IssuerSerial
+	    ("CN=Sean Mullan,DC=sun,DC=com",
+	    new BigInteger("3f451a6a", 16)));
+	xds.add(signingCert);
+	objs.add(fac.newXMLObject(Collections.singletonList
+	    (kifac.newX509Data(xds)), "object-4", null, null));
+
+	// create XMLSignature
+	XMLSignature sig = fac.newXMLSignature(si, ki, objs, "signature", null);
+
+	// create envelope header
+	Element envelope = doc.createElementNS
+	    ("http://example.org/usps", "Envelope");
+	envelope.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", 
+	    "http://example.org/usps");
+        envelope.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:foo", 
+	    "http://example.org/foo");
+	doc.appendChild(envelope);
+	Element dearSir = doc.createElementNS 
+	    ("http://example.org/usps", "DearSir");
+	dearSir.appendChild(doc.createTextNode("foo"));
+	envelope.appendChild(dearSir);
+	Element body = doc.createElementNS("http://example.org/usps", "Body");
+	body.appendChild(doc.createTextNode("bar"));
+	envelope.appendChild(body);
+	Element ys = doc.createElementNS 
+	    ("http://example.org/usps", "YoursSincerely");
+	envelope.appendChild(ys);
+
+	// create envelope footer
+	Element ps = doc.createElementNS
+	    ("http://example.org/usps", "PostScript");
+	ps.appendChild(doc.createTextNode("bar"));
+	envelope.appendChild(ps);
+	Element notaries = doc.createElementNS(null, "Notaries");
+	notaries.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", "");
+	notaries.setAttributeNS(null, "Id", "notaries");
+	Element notary1 = doc.createElementNS(null, "Notary");
+	notary1.setAttributeNS(null, "name", "Great, A. T.");
+	Element notary2 = doc.createElementNS(null, "Notary");
+	notary2.setAttributeNS(null, "name", "Hun, A. T.");
+	notaries.appendChild(notary1);
+	notaries.appendChild(notary2);
+	envelope.appendChild(notaries);
+	envelope.appendChild(doc.createComment(" Commentary "));
+
+	DOMSignContext dsc = new DOMSignContext(signingKey, ys);
+	dsc.setIdAttributeNS(notaries, null, "Id");
+
+	sig.sign(dsc);
+
+	// DOM L2 does not support the creation of DOCTYPEs, so instead
+        // we insert it before the document using a StringWriter
+//	String docType = 
+//	    "<!DOCTYPE Envelope [\n"
+//  	  + "<!ENTITY dsig 'http://www.w3.org/2000/09/xmldsig#'>\n"
+//          + "<!ENTITY c14n 'http://www.w3.org/TR/2001/REC-xml-c14n-20010315'>\n"
+//          + "<!ENTITY xpath 'http://www.w3.org/TR/1999/REC-xpath-19991116'>\n"
+//          + "<!ENTITY xslt 'http://www.w3.org/TR/1999/REC-xslt-19991116'>\n"
+//          + "<!ATTLIST Notaries Id ID #IMPLIED>\n"
+//          + "]>\n";
+	StringWriter sw = new StringWriter();
+//	sw.write(docType);
+
+        dumpDocument(doc, sw);
+
+	// read document back into DOM tree
+	DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+	dbf.setNamespaceAware(true);
+	dbf.setValidating(false);
+	try {
+	    doc = dbf.newDocumentBuilder().parse
+	        (new InputSource(new StringReader(sw.toString())));
+	} catch (SAXParseException spe) {
+	    System.err.println("line:" + spe.getLineNumber());
+	    System.err.println("xml:" + sw.toString());
+	}
+	System.out.println("doc is:" + sw.toString());
+	Element sigElement = SignatureValidator.getSignatureElement(doc);
+	if (sigElement == null) {
+            throw new Exception("Couldn't find signature Element");
+	}
+
+	DOMValidateContext dvc = new DOMValidateContext
+	    (new X509KeySelector(ks), sigElement);
+	File f = new File(
+	    System.getProperty("dir.test.vector.baltimore") + 
+            System.getProperty("file.separator") +
+	    "merlin-xmldsig-twenty-three" +
+            System.getProperty("file.separator"));
+	dvc.setBaseURI(f.toURI().toString());
+
+	// register Notaries ID
+//	Element notariesElem = 
+//	    (Element) doc.getElementsByTagName("Notaries").item(0);
+//	dvc.setIdAttributeNS(notariesElem, "", "Id");
+//	notariesElem.setIdAttributeNS("", "Id", true);
+	    
+	XMLSignature sig2 = fac.unmarshalXMLSignature(dvc);
+
+	assertTrue(sig.equals(sig2));
+	assertTrue(sig2.validate(dvc));
+    }
+
+    private void dumpDocument(Document doc, Writer w) throws Exception {
+	TransformerFactory tf = TransformerFactory.newInstance();
+	Transformer trans = tf.newTransformer();
+//	trans.setOutputProperty(OutputKeys.INDENT, "yes");
+	trans.transform(new DOMSource(doc), new StreamResult(w));
+    }
+
+    private void test_create_signature_external
+	(SignatureMethod sm, KeyInfo ki, Key signingKey, KeySelector ks,
+	boolean b64) throws Exception {
+
+	// create reference
+	Reference ref;
+	if (b64) {
+	    ref = fac.newReference
+		("http://www.w3.org/Signature/2002/04/xml-stylesheet.b64", 
+		sha1, Collections.singletonList
+        	(fac.newTransform(Transform.BASE64, 
+		 (TransformParameterSpec) null)), null, null);
+	} else {
+	    ref = fac.newReference
+		("http://www.w3.org/Signature/2002/04/xml-stylesheet.b64",sha1);
+	}
+
+	// create SignedInfo
+	SignedInfo si = fac.newSignedInfo(withoutComments, sm, 
+	    Collections.singletonList(ref));
+
+	Document doc = db.newDocument();
+
+	// create XMLSignature
+	XMLSignature sig = fac.newXMLSignature(si, ki);
+
+	DOMSignContext dsc = new DOMSignContext(signingKey, doc);
+
+	sig.sign(dsc);
+
+	DOMValidateContext dvc = new DOMValidateContext
+	    (ks, doc.getDocumentElement());
+	String fs = System.getProperty("file.separator");
+	File f = new File(
+	    System.getProperty("basedir") + fs + "data" + fs + "ie" + fs +
+	    "baltimore" + fs + "merlin-examples" + fs +
+	    "merlin-xmldsig-twenty-three" + fs);
+	dvc.setBaseURI(f.toURI().toString()); 
+	    
+	XMLSignature sig2 = fac.unmarshalXMLSignature(dvc);
+
+	assertTrue(sig.equals(sig2));
+	assertTrue(sig2.validate(dvc));
+    }
+
+    private void test_create_signature_enveloping
+	(SignatureMethod sm, KeyInfo ki, Key signingKey, KeySelector ks, 
+	boolean b64) throws Exception {
+
+	// create reference
+	Reference ref;
+	if (b64) {
+	    ref = fac.newReference("#object", sha1, Collections.singletonList
+        	(fac.newTransform(Transform.BASE64, 
+		 (TransformParameterSpec) null)), null, null);
+	} else {
+	    ref = fac.newReference("#object", sha1);
+	}
+
+	// create SignedInfo
+	SignedInfo si = fac.newSignedInfo(withoutComments, sm, 
+	    Collections.singletonList(ref));
+
+	Document doc = db.newDocument();
+	// create Objects
+	XMLObject obj = fac.newXMLObject(Collections.singletonList
+	    (new DOMStructure(doc.createTextNode("some text"))), 
+	    "object", null, null);
+
+	// create XMLSignature
+	XMLSignature sig = fac.newXMLSignature
+	    (si, ki, Collections.singletonList(obj), null, null);
+
+	DOMSignContext dsc = new DOMSignContext(signingKey, doc);
+
+	sig.sign(dsc);
+
+	DOMValidateContext dvc = new DOMValidateContext
+	    (ks, doc.getDocumentElement());
+	XMLSignature sig2 = fac.unmarshalXMLSignature(dvc);
+
+	assertTrue(sig.equals(sig2));
+	assertTrue(sig2.validate(dvc));
+    }
+
+    public static void main(String[] args) throws Exception {
+	CreateBaltimore23Test test = new CreateBaltimore23Test("main");
+	test.setUp();
+//	test.test_create_signature();
+    }
+}

Added: xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/CreateInteropExcC14NTest.java
URL: http://svn.apache.org/viewcvs/xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/CreateInteropExcC14NTest.java?rev=372984&view=auto
==============================================================================
--- xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/CreateInteropExcC14NTest.java (added)
+++ xml/security/branches/jsr105_0_16/src_unitTests/javax/xml/crypto/test/dsig/CreateInteropExcC14NTest.java Fri Jan 27 13:00:17 2006
@@ -0,0 +1,177 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package javax.xml.crypto.test.dsig;
+
+import java.io.*;
+import java.security.*;
+import java.security.cert.Certificate;
+import java.util.*;
+import javax.xml.crypto.dom.DOMStructure;
+import javax.xml.crypto.dsig.*;
+import javax.xml.crypto.dsig.dom.*;
+import javax.xml.crypto.dsig.keyinfo.*;
+import javax.xml.crypto.dsig.spec.*;
+import javax.xml.parsers.*;
+import javax.xml.transform.*;
+import javax.xml.transform.dom.*;
+import javax.xml.transform.stream.*;
+import org.w3c.dom.*;
+
+import junit.framework.*;
+
+import javax.xml.crypto.test.KeySelectors;
+
+/**
+ * Test that recreates interop exc C14N test vectors
+ * but with different keys.
+ */
+public class CreateInteropExcC14NTest extends TestCase {
+
+    private XMLSignatureFactory fac;
+    private KeyInfoFactory kifac;
+    private DocumentBuilder db;
+    private KeyStore ks;
+    private Key signingKey;
+    private PublicKey validatingKey;
+
+    static {
+        Security.insertProviderAt
+            (new org.jcp.xml.dsig.internal.dom.XMLDSigRI(), 1);
+    }
+
+    public CreateInteropExcC14NTest(String name) {
+        super(name);
+    }
+
+    public void setUp() throws Exception {
+        fac = XMLSignatureFactory.getInstance
+            ("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
+        kifac = fac.getKeyInfoFactory();
+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+        dbf.setNamespaceAware(true);
+        db = dbf.newDocumentBuilder();
+
+        // get key & self-signed certificate from keystore
+	String fs = System.getProperty("file.separator");
+        FileInputStream fis = new FileInputStream
+            (System.getProperty("basedir") + fs + "data" + fs + "test.jks");
+        ks = KeyStore.getInstance("JKS");
+        ks.load(fis, "changeit".toCharArray());
+        Certificate signingCert = ks.getCertificate("mullan");
+        signingKey = ks.getKey("mullan", "changeit".toCharArray());
+        validatingKey = signingCert.getPublicKey();
+    }
+
+    public void test_create_Y1() throws Exception {
+	List refs = new ArrayList(4);
+
+	// create reference 1
+	refs.add(fac.newReference
+	    ("#xpointer(id('to-be-signed'))", 
+	     fac.newDigestMethod(DigestMethod.SHA1, null),
+	     Collections.singletonList
+		(fac.newTransform(CanonicalizationMethod.EXCLUSIVE, 
+		 (TransformParameterSpec) null)),
+	     null, null));
+
+	// create reference 2
+	List prefixList = new ArrayList(2);
+	prefixList.add("bar");
+	prefixList.add("#default");
+	ExcC14NParameterSpec params = new ExcC14NParameterSpec(prefixList);
+	refs.add(fac.newReference
+	    ("#xpointer(id('to-be-signed'))", 
+	     fac.newDigestMethod(DigestMethod.SHA1, null),
+	     Collections.singletonList
+		(fac.newTransform(CanonicalizationMethod.EXCLUSIVE, params)),
+	     null, null));
+
+	// create reference 3
+	refs.add(fac.newReference
+	    ("#xpointer(id('to-be-signed'))", 
+	     fac.newDigestMethod(DigestMethod.SHA1, null),
+	     Collections.singletonList(fac.newTransform
+		(CanonicalizationMethod.EXCLUSIVE_WITH_COMMENTS, 
+		 (TransformParameterSpec) null)),
+	     null, null));
+
+	// create reference 4
+	prefixList = new ArrayList(2);
+	prefixList.add("bar");
+	prefixList.add("#default");
+	params = new ExcC14NParameterSpec(prefixList);
+	refs.add(fac.newReference
+	    ("#xpointer(id('to-be-signed'))", 
+	     fac.newDigestMethod(DigestMethod.SHA1, null),
+	     Collections.singletonList(fac.newTransform
+		(CanonicalizationMethod.EXCLUSIVE_WITH_COMMENTS, 
+		 (TransformParameterSpec) params)),
+	     null, null));
+
+        // create SignedInfo
+        SignedInfo si = fac.newSignedInfo(
+	    fac.newCanonicalizationMethod
+	        (CanonicalizationMethod.EXCLUSIVE, 
+		 (C14NMethodParameterSpec) null),
+	    fac.newSignatureMethod(SignatureMethod.DSA_SHA1, null), refs);
+
+	// create KeyInfo
+	List kits = new ArrayList(2);
+	kits.add(kifac.newKeyValue(validatingKey));
+	KeyInfo ki = kifac.newKeyInfo(kits);
+
+        // create Objects
+        Document doc = db.newDocument();
+	Element baz = doc.createElementNS("urn:bar", "bar:Baz");
+	Comment com = doc.createComment(" comment ");
+	baz.appendChild(com);
+	XMLObject obj = fac.newXMLObject(Collections.singletonList
+	    (new DOMStructure(baz)), "to-be-signed", null, null);
+
+	// create XMLSignature
+	XMLSignature sig = fac.newXMLSignature
+	    (si, ki, Collections.singletonList(obj), null, null);
+
+        Element foo = doc.createElementNS("urn:foo", "Foo");
+        foo.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", "urn:foo");
+        foo.setAttributeNS
+	    ("http://www.w3.org/2000/xmlns/", "xmlns:bar", "urn:bar");
+	doc.appendChild(foo);
+
+        DOMSignContext dsc = new DOMSignContext(signingKey, foo);
+	dsc.putNamespacePrefix(XMLSignature.XMLNS, "dsig");
+
+        sig.sign(dsc);
+
+//	dumpDocument(doc, new FileWriter("/tmp/foo.xml"));
+
+        DOMValidateContext dvc = new DOMValidateContext
+            (new KeySelectors.KeyValueKeySelector(), foo.getLastChild());
+        XMLSignature sig2 = fac.unmarshalXMLSignature(dvc);
+
+        assertTrue(sig.equals(sig2));
+
+        assertTrue(sig2.validate(dvc));
+    }
+
+    private void dumpDocument(Document doc, Writer w) throws Exception {
+        TransformerFactory tf = TransformerFactory.newInstance();
+        Transformer trans = tf.newTransformer();
+//        trans.setOutputProperty(OutputKeys.INDENT, "yes");
+        trans.transform(new DOMSource(doc), new StreamResult(w));
+    }
+}