提交 571d9660 编写于 作者: M mullan

6469266: Integrate Apache XMLSec 1.4.2 into JDK 7

Reviewed-by: valeriep
上级 d0615577
...@@ -20,12 +20,9 @@ ...@@ -20,12 +20,9 @@
*/ */
package com.sun.org.apache.xml.internal.security; package com.sun.org.apache.xml.internal.security;
import java.io.InputStream; import java.io.InputStream;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
...@@ -51,7 +48,7 @@ import org.w3c.dom.Node; ...@@ -51,7 +48,7 @@ import org.w3c.dom.Node;
* done by calling {@link Init#init} which should be done in any static block * done by calling {@link Init#init} which should be done in any static block
* of the files of this library. We ensure that this call is only executed once. * of the files of this library. We ensure that this call is only executed once.
* *
* @author $Author: raul $ * @author $Author: mullan $
*/ */
public final class Init { public final class Init {
...@@ -113,19 +110,18 @@ public final class Init { ...@@ -113,19 +110,18 @@ public final class Init {
dbf.setValidating(false); dbf.setValidating(false);
DocumentBuilder db = dbf.newDocumentBuilder(); DocumentBuilder db = dbf.newDocumentBuilder();
// We don't allow users to override the Apache XML Security // We don't allow users to override the Apache XML Security
// configuration in the JRE. Users should use the standard security // configuration in the JRE. Users should use the standard security
// provider mechanism instead if implementing their own // provider mechanism instead if implementing their own
// transform or canonicalization algorithms. // transform or canonicalization algorithms.
// String cfile = System.getProperty("com.sun.org.apache.xml.internal.security.resource.config"); // InputStream is = Class.forName("com.sun.org.apache.xml.internal.security.Init").getResourceAsStream("resource/config.xml");
// InputStream is =
// Class.forName("com.sun.org.apache.xml.internal.security.Init")
// .getResourceAsStream(cfile != null ? cfile : "resource/config.xml");
InputStream is = (InputStream) AccessController.doPrivileged( InputStream is = (InputStream) AccessController.doPrivileged(
new PrivilegedAction() { new PrivilegedAction() {
public Object run() { public Object run() {
// String cfile = System.getProperty
// ("com.sun.org.apache.xml.internal.security.resource.config");
return getClass().getResourceAsStream return getClass().getResourceAsStream
// (cfile != null ? cfile : "resource/config.xml");
("resource/config.xml"); ("resource/config.xml");
} }
}); });
...@@ -202,11 +198,11 @@ public final class Init { ...@@ -202,11 +198,11 @@ public final class Init {
if (currMeth.getDeclaringClass().getName() if (currMeth.getDeclaringClass().getName()
.equals(JAVACLASS)) { .equals(JAVACLASS)) {
log.log(java.util.logging.Level.FINE, currMeth.getDeclaringClass().toString()); log.log(java.util.logging.Level.FINE, currMeth.getDe claringClass().toString());
} }
}*/ }*/
if (true) if (log.isLoggable(java.util.logging.Level.FINE))
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Canonicalizer.register(" + URI + ", " log.log(java.util.logging.Level.FINE, "Canonicalizer.register(" + URI + ", "
+ JAVACLASS + ")"); + JAVACLASS + ")");
Canonicalizer.register(URI, JAVACLASS); Canonicalizer.register(URI, JAVACLASS);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
...@@ -233,9 +229,8 @@ public final class Init { ...@@ -233,9 +229,8 @@ public final class Init {
"JAVACLASS"); "JAVACLASS");
try { try {
Class.forName(JAVACLASS); Class.forName(JAVACLASS);
if (true) if (log.isLoggable(java.util.logging.Level.FINE))
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Transform.register(" + URI + ", " + JAVACLASS log.log(java.util.logging.Level.FINE, "Transform.register(" + URI + ", " + JAVACLASS + ")");
+ ")");
Transform.register(URI, JAVACLASS); Transform.register(URI, JAVACLASS);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
Object exArgs[] = { URI, JAVACLASS }; Object exArgs[] = { URI, JAVACLASS };
...@@ -284,12 +279,11 @@ public final class Init { ...@@ -284,12 +279,11 @@ public final class Init {
// //
// if (currMeth.getDeclaringClass().getName() // if (currMeth.getDeclaringClass().getName()
// .equals(JAVACLASS)) { // .equals(JAVACLASS)) {
// log.log(java.util.logging.Level.FINE, currMeth.getDeclaringClass().toString()); // log.log(java.util.logging.Level.FINE, currMeth.getDe claringClass().toString());
// } // }
// } // }
if (true) if (log.isLoggable(java.util.logging.Level.FINE))
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "SignatureAlgorithm.register(" + URI + ", " log.log(java.util.logging.Level.FINE, "SignatureAlgorithm.register(" + URI + ", " + JAVACLASS + ")");
+ JAVACLASS + ")");
SignatureAlgorithm.register(URI, JAVACLASS); SignatureAlgorithm.register(URI, JAVACLASS);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
Object exArgs[] = { URI, JAVACLASS }; Object exArgs[] = { URI, JAVACLASS };
...@@ -320,13 +314,11 @@ public final class Init { ...@@ -320,13 +314,11 @@ public final class Init {
"DESCRIPTION"); "DESCRIPTION");
if ((Description != null) && (Description.length() > 0)) { if ((Description != null) && (Description.length() > 0)) {
if (true) if (log.isLoggable(java.util.logging.Level.FINE))
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Register Resolver: " + JAVACLASS + ": " log.log(java.util.logging.Level.FINE, "Register Resolver: " + JAVACLASS + ": " + Description);
+ Description);
} else { } else {
if (true) if (log.isLoggable(java.util.logging.Level.FINE))
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Register Resolver: " + JAVACLASS log.log(java.util.logging.Level.FINE, "Register Resolver: " + JAVACLASS + ": For unknown purposes");
+ ": For unknown purposes");
} }
try { try {
ResourceResolver.register(JAVACLASS); ResourceResolver.register(JAVACLASS);
...@@ -359,13 +351,11 @@ public final class Init { ...@@ -359,13 +351,11 @@ public final class Init {
"DESCRIPTION"); "DESCRIPTION");
if ((Description != null) && (Description.length() > 0)) { if ((Description != null) && (Description.length() > 0)) {
if (true) if (log.isLoggable(java.util.logging.Level.FINE))
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Register Resolver: " + JAVACLASS + ": " log.log(java.util.logging.Level.FINE, "Register Resolver: " + JAVACLASS + ": " + Description);
+ Description);
} else { } else {
if (true) if (log.isLoggable(java.util.logging.Level.FINE))
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Register Resolver: " + JAVACLASS log.log(java.util.logging.Level.FINE, "Register Resolver: " + JAVACLASS + ": For unknown purposes");
+ ": For unknown purposes");
} }
KeyResolver.register(JAVACLASS); KeyResolver.register(JAVACLASS);
...@@ -376,8 +366,8 @@ public final class Init { ...@@ -376,8 +366,8 @@ public final class Init {
if (tag.equals("PrefixMappings")){ if (tag.equals("PrefixMappings")){
XX_configure_reg_prefixes_start = System.currentTimeMillis(); XX_configure_reg_prefixes_start = System.currentTimeMillis();
if (true) if (log.isLoggable(java.util.logging.Level.FINE))
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Now I try to bind prefixes:"); log.log(java.util.logging.Level.FINE, "Now I try to bind prefixes:");
Element[] nl = XMLUtils.selectNodes(el.getFirstChild(), CONF_NS,"PrefixMapping"); Element[] nl = XMLUtils.selectNodes(el.getFirstChild(), CONF_NS,"PrefixMapping");
...@@ -386,8 +376,8 @@ public final class Init { ...@@ -386,8 +376,8 @@ public final class Init {
"namespace"); "namespace");
String prefix = nl[i].getAttributeNS(null, String prefix = nl[i].getAttributeNS(null,
"prefix"); "prefix");
if (true) if (log.isLoggable(java.util.logging.Level.FINE))
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Now I try to bind " + prefix + " to " + namespace); log.log(java.util.logging.Level.FINE, "Now I try to bind " + prefix + " to " + namespace);
com.sun.org.apache.xml.internal.security.utils.ElementProxy com.sun.org.apache.xml.internal.security.utils.ElementProxy
.setDefaultPrefix(namespace, prefix); .setDefaultPrefix(namespace, prefix);
} }
...@@ -398,19 +388,19 @@ public final class Init { ...@@ -398,19 +388,19 @@ public final class Init {
long XX_init_end = System.currentTimeMillis(); long XX_init_end = System.currentTimeMillis();
//J- //J-
if (true) { if (log.isLoggable(java.util.logging.Level.FINE)) {
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "XX_init " + ((int)(XX_init_end - XX_init_start)) + " ms"); log.log(java.util.logging.Level.FINE, "XX_init " + ((int)(XX_init_end - XX_init_start)) + " ms");
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, " XX_prng " + ((int)(XX_prng_end - XX_prng_start)) + " ms"); log.log(java.util.logging.Level.FINE, " XX_prng " + ((int)(XX_prng_end - XX_prng_start)) + " ms");
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, " XX_parsing " + ((int)(XX_parsing_end - XX_parsing_start)) + " ms"); log.log(java.util.logging.Level.FINE, " XX_parsing " + ((int)(XX_parsing_end - XX_parsing_start)) + " ms");
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, " XX_configure_i18n " + ((int)(XX_configure_i18n_end- XX_configure_i18n_start)) + " ms"); log.log(java.util.logging.Level.FINE, " XX_configure_i18n " + ((int)(XX_configure_i18n_end- XX_configure_i18n_start)) + " ms");
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, " XX_configure_reg_c14n " + ((int)(XX_configure_reg_c14n_end- XX_configure_reg_c14n_start)) + " ms"); log.log(java.util.logging.Level.FINE, " XX_configure_reg_c14n " + ((int)(XX_configure_reg_c14n_end- XX_configure_reg_c14n_start)) + " ms");
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, " XX_configure_reg_jcemapper " + ((int)(XX_configure_reg_jcemapper_end- XX_configure_reg_jcemapper_start)) + " ms"); log.log(java.util.logging.Level.FINE, " XX_configure_reg_jcemapper " + ((int)(XX_configure_reg_jcemapper_end- XX_configure_reg_jcemapper_start)) + " ms");
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, " XX_configure_reg_keyInfo " + ((int)(XX_configure_reg_keyInfo_end- XX_configure_reg_keyInfo_start)) + " ms"); log.log(java.util.logging.Level.FINE, " XX_configure_reg_keyInfo " + ((int)(XX_configure_reg_keyInfo_end- XX_configure_reg_keyInfo_start)) + " ms");
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, " XX_configure_reg_keyResolver " + ((int)(XX_configure_reg_keyResolver_end- XX_configure_reg_keyResolver_start)) + " ms"); log.log(java.util.logging.Level.FINE, " XX_configure_reg_keyResolver " + ((int)(XX_configure_reg_keyResolver_end- XX_configure_reg_keyResolver_start)) + " ms");
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, " XX_configure_reg_prefixes " + ((int)(XX_configure_reg_prefixes_end- XX_configure_reg_prefixes_start)) + " ms"); log.log(java.util.logging.Level.FINE, " XX_configure_reg_prefixes " + ((int)(XX_configure_reg_prefixes_end- XX_configure_reg_prefixes_start)) + " ms");
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, " XX_configure_reg_resourceresolver " + ((int)(XX_configure_reg_resourceresolver_end- XX_configure_reg_resourceresolver_start)) + " ms"); log.log(java.util.logging.Level.FINE, " XX_configure_reg_resourceresolver " + ((int)(XX_configure_reg_resourceresolver_end- XX_configure_reg_resourceresolver_start)) + " ms");
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, " XX_configure_reg_sigalgos " + ((int)(XX_configure_reg_sigalgos_end- XX_configure_reg_sigalgos_start)) + " ms"); log.log(java.util.logging.Level.FINE, " XX_configure_reg_sigalgos " + ((int)(XX_configure_reg_sigalgos_end- XX_configure_reg_sigalgos_start)) + " ms");
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, " XX_configure_reg_transforms " + ((int)(XX_configure_reg_transforms_end- XX_configure_reg_transforms_start)) + " ms"); log.log(java.util.logging.Level.FINE, " XX_configure_reg_transforms " + ((int)(XX_configure_reg_transforms_end- XX_configure_reg_transforms_start)) + " ms");
} }
} catch (Exception e) { } catch (Exception e) {
log.log(java.util.logging.Level.SEVERE, "Bad: ", e); log.log(java.util.logging.Level.SEVERE, "Bad: ", e);
......
...@@ -24,7 +24,7 @@ package com.sun.org.apache.xml.internal.security.algorithms; ...@@ -24,7 +24,7 @@ package com.sun.org.apache.xml.internal.security.algorithms;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
import com.sun.org.apache.xml.internal.security.utils.Constants; import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.ElementProxy; import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
...@@ -33,11 +33,7 @@ import org.w3c.dom.Element; ...@@ -33,11 +33,7 @@ import org.w3c.dom.Element;
* The Algorithm class which stores the Algorithm URI as a string. * The Algorithm class which stores the Algorithm URI as a string.
* *
*/ */
public abstract class Algorithm extends ElementProxy { public abstract class Algorithm extends SignatureElementProxy {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(Algorithm.class.getName());
/** /**
* *
...@@ -79,7 +75,7 @@ public abstract class Algorithm extends ElementProxy { ...@@ -79,7 +75,7 @@ public abstract class Algorithm extends ElementProxy {
*/ */
protected void setAlgorithmURI(String algorithmURI) { protected void setAlgorithmURI(String algorithmURI) {
if ((this._state == MODE_CREATE) && (algorithmURI != null)) { if ( (algorithmURI != null)) {
this._constructionElement.setAttributeNS(null, Constants._ATT_ALGORITHM, this._constructionElement.setAttributeNS(null, Constants._ATT_ALGORITHM,
algorithmURI); algorithmURI);
} }
......
...@@ -35,7 +35,7 @@ import org.w3c.dom.Element; ...@@ -35,7 +35,7 @@ import org.w3c.dom.Element;
/** /**
* This class maps algorithm identifier URIs to JAVA JCE class names. * This class maps algorithm identifier URIs to JAVA JCE class names.
* *
* @author $Author: raul $ * @author $Author: mullan $
*/ */
public class JCEMapper { public class JCEMapper {
...@@ -45,9 +45,9 @@ public class JCEMapper { ...@@ -45,9 +45,9 @@ public class JCEMapper {
private static Map uriToJCEName = new HashMap(); private static Map uriToJCEName;
private static Map algorithmsMap = new HashMap(); private static Map algorithmsMap;
private static String providerName = null; private static String providerName = null;
/** /**
...@@ -63,6 +63,8 @@ public class JCEMapper { ...@@ -63,6 +63,8 @@ public class JCEMapper {
static void loadAlgorithms( Element algorithmsEl) { static void loadAlgorithms( Element algorithmsEl) {
Element[] algorithms = XMLUtils.selectNodes(algorithmsEl.getFirstChild(),Init.CONF_NS,"Algorithm"); Element[] algorithms = XMLUtils.selectNodes(algorithmsEl.getFirstChild(),Init.CONF_NS,"Algorithm");
uriToJCEName = new HashMap( algorithms.length * 2);
algorithmsMap = new HashMap( algorithms.length * 2);
for (int i = 0 ;i < algorithms.length ;i ++) { for (int i = 0 ;i < algorithms.length ;i ++) {
Element el = algorithms[i]; Element el = algorithms[i];
String id = el.getAttribute("URI"); String id = el.getAttribute("URI");
...@@ -70,6 +72,7 @@ public class JCEMapper { ...@@ -70,6 +72,7 @@ public class JCEMapper {
uriToJCEName.put(id, jceName); uriToJCEName.put(id, jceName);
algorithmsMap.put(id, new Algorithm(el)); algorithmsMap.put(id, new Algorithm(el));
} }
} }
static Algorithm getAlgorithmMapping(String algoURI) { static Algorithm getAlgorithmMapping(String algoURI) {
...@@ -84,8 +87,8 @@ public class JCEMapper { ...@@ -84,8 +87,8 @@ public class JCEMapper {
* *
*/ */
public static String translateURItoJCEID(String AlgorithmURI) { public static String translateURItoJCEID(String AlgorithmURI) {
if (true) if (log.isLoggable(java.util.logging.Level.FINE))
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Request for URI " + AlgorithmURI); log.log(java.util.logging.Level.FINE, "Request for URI " + AlgorithmURI);
String jceName = (String) uriToJCEName.get(AlgorithmURI); String jceName = (String) uriToJCEName.get(AlgorithmURI);
return jceName; return jceName;
...@@ -100,8 +103,8 @@ public class JCEMapper { ...@@ -100,8 +103,8 @@ public class JCEMapper {
* *
*/ */
public static String getAlgorithmClassFromURI(String AlgorithmURI) { public static String getAlgorithmClassFromURI(String AlgorithmURI) {
if (true) if (log.isLoggable(java.util.logging.Level.FINE))
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Request for URI " + AlgorithmURI); log.log(java.util.logging.Level.FINE, "Request for URI " + AlgorithmURI);
return ((Algorithm) algorithmsMap.get(AlgorithmURI)).algorithmClass; return ((Algorithm) algorithmsMap.get(AlgorithmURI)).algorithmClass;
} }
......
...@@ -20,10 +20,10 @@ ...@@ -20,10 +20,10 @@
*/ */
package com.sun.org.apache.xml.internal.security.algorithms; package com.sun.org.apache.xml.internal.security.algorithms;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchProviderException; import java.security.NoSuchProviderException;
import java.util.HashMap;
import java.util.Map;
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException; import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException;
import com.sun.org.apache.xml.internal.security.utils.Constants; import com.sun.org.apache.xml.internal.security.utils.Constants;
...@@ -41,11 +41,6 @@ import org.w3c.dom.Document; ...@@ -41,11 +41,6 @@ import org.w3c.dom.Document;
*/ */
public class MessageDigestAlgorithm extends Algorithm { public class MessageDigestAlgorithm extends Algorithm {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(
MessageDigestAlgorithm.class.getName());
/** Message Digest - NOT RECOMMENDED MD5*/ /** Message Digest - NOT RECOMMENDED MD5*/
public static final String ALGO_ID_DIGEST_NOT_RECOMMENDED_MD5 = Constants.MoreAlgorithmsSpecNS + "md5"; public static final String ALGO_ID_DIGEST_NOT_RECOMMENDED_MD5 = Constants.MoreAlgorithmsSpecNS + "md5";
/** Digest - Required SHA1*/ /** Digest - Required SHA1*/
...@@ -76,6 +71,12 @@ public class MessageDigestAlgorithm extends Algorithm { ...@@ -76,6 +71,12 @@ public class MessageDigestAlgorithm extends Algorithm {
this.algorithm = messageDigest; this.algorithm = messageDigest;
} }
static ThreadLocal instances=new ThreadLocal() {
protected Object initialValue() {
return new HashMap();
};
};
/** /**
* Factory method for constructing a message digest algorithm by name. * Factory method for constructing a message digest algorithm by name.
* *
...@@ -86,7 +87,14 @@ public class MessageDigestAlgorithm extends Algorithm { ...@@ -86,7 +87,14 @@ public class MessageDigestAlgorithm extends Algorithm {
*/ */
public static MessageDigestAlgorithm getInstance( public static MessageDigestAlgorithm getInstance(
Document doc, String algorithmURI) throws XMLSignatureException { Document doc, String algorithmURI) throws XMLSignatureException {
MessageDigest md = getDigestInstance(algorithmURI);
return new MessageDigestAlgorithm(doc, md, algorithmURI);
}
private static MessageDigest getDigestInstance(String algorithmURI) throws XMLSignatureException {
MessageDigest result=(MessageDigest) ((Map)instances.get()).get(algorithmURI);
if (result!=null)
return result;
String algorithmID = JCEMapper.translateURItoJCEID(algorithmURI); String algorithmID = JCEMapper.translateURItoJCEID(algorithmURI);
if (algorithmID == null) { if (algorithmID == null) {
...@@ -113,8 +121,9 @@ public class MessageDigestAlgorithm extends Algorithm { ...@@ -113,8 +121,9 @@ public class MessageDigestAlgorithm extends Algorithm {
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs); throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
} }
return new MessageDigestAlgorithm(doc, md, algorithmURI); ((Map)instances.get()).put(algorithmURI, md);
} return md;
}
/** /**
* Returns the actual {@link java.security.MessageDigest} algorithm object * Returns the actual {@link java.security.MessageDigest} algorithm object
......
...@@ -25,6 +25,7 @@ import java.security.Key; ...@@ -25,6 +25,7 @@ import java.security.Key;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec; import java.security.spec.AlgorithmParameterSpec;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
import com.sun.org.apache.xml.internal.security.algorithms.implementations.IntegrityHmac; import com.sun.org.apache.xml.internal.security.algorithms.implementations.IntegrityHmac;
import com.sun.org.apache.xml.internal.security.exceptions.AlgorithmAlreadyRegisteredException; import com.sun.org.apache.xml.internal.security.exceptions.AlgorithmAlreadyRegisteredException;
...@@ -52,9 +53,35 @@ public class SignatureAlgorithm extends Algorithm { ...@@ -52,9 +53,35 @@ public class SignatureAlgorithm extends Algorithm {
/** All available algorithm classes are registered here */ /** All available algorithm classes are registered here */
static HashMap _algorithmHash = null; static HashMap _algorithmHash = null;
static ThreadLocal instancesSigning=new ThreadLocal() {
protected Object initialValue() {
return new HashMap();
};
};
static ThreadLocal instancesVerify=new ThreadLocal() {
protected Object initialValue() {
return new HashMap();
};
};
static ThreadLocal keysSigning=new ThreadLocal() {
protected Object initialValue() {
return new HashMap();
};
};
static ThreadLocal keysVerify=new ThreadLocal() {
protected Object initialValue() {
return new HashMap();
};
};
// boolean isForSigning=false;
/** Field _signatureAlgorithm */ /** Field _signatureAlgorithm */
protected SignatureAlgorithmSpi _signatureAlgorithm = null; protected SignatureAlgorithmSpi _signatureAlgorithm = null;
private String algorithmURI;
/** /**
* Constructor SignatureAlgorithm * Constructor SignatureAlgorithm
* *
...@@ -64,18 +91,49 @@ public class SignatureAlgorithm extends Algorithm { ...@@ -64,18 +91,49 @@ public class SignatureAlgorithm extends Algorithm {
*/ */
public SignatureAlgorithm(Document doc, String algorithmURI) public SignatureAlgorithm(Document doc, String algorithmURI)
throws XMLSecurityException { throws XMLSecurityException {
super(doc, algorithmURI); super(doc, algorithmURI);
this.algorithmURI = algorithmURI;
}
private void initializeAlgorithm(boolean isForSigning) throws XMLSignatureException {
if (_signatureAlgorithm!=null) {
return;
}
_signatureAlgorithm=isForSigning ? getInstanceForSigning(algorithmURI) : getInstanceForVerify(algorithmURI);
this._signatureAlgorithm
.engineGetContextFromElement(this._constructionElement);
}
private static SignatureAlgorithmSpi getInstanceForSigning(String algorithmURI) throws XMLSignatureException {
SignatureAlgorithmSpi result=(SignatureAlgorithmSpi) ((Map)instancesSigning.get()).get(algorithmURI);
if (result!=null) {
result.reset();
return result;
}
result=buildSigner(algorithmURI, result);
((Map)instancesSigning.get()).put(algorithmURI,result);
return result;
}
private static SignatureAlgorithmSpi getInstanceForVerify(String algorithmURI) throws XMLSignatureException {
SignatureAlgorithmSpi result=(SignatureAlgorithmSpi) ((Map)instancesVerify.get()).get(algorithmURI);
if (result!=null) {
result.reset();
return result;
}
result=buildSigner(algorithmURI, result);
((Map)instancesVerify.get()).put(algorithmURI,result);
return result;
}
private static SignatureAlgorithmSpi buildSigner(String algorithmURI, SignatureAlgorithmSpi result) throws XMLSignatureException {
try { try {
Class implementingClass = Class implementingClass =
SignatureAlgorithm.getImplementingClass(algorithmURI); SignatureAlgorithm.getImplementingClass(algorithmURI);
if (true) if (log.isLoggable(java.util.logging.Level.FINE))
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Create URI \"" + algorithmURI + "\" class \"" log.log(java.util.logging.Level.FINE, "Create URI \"" + algorithmURI + "\" class \""
+ implementingClass + "\""); + implementingClass + "\"");
result=(SignatureAlgorithmSpi) implementingClass.newInstance();
this._signatureAlgorithm = return result;
(SignatureAlgorithmSpi) implementingClass.newInstance();
} catch (IllegalAccessException ex) { } catch (IllegalAccessException ex) {
Object exArgs[] = { algorithmURI, ex.getMessage() }; Object exArgs[] = { algorithmURI, ex.getMessage() };
...@@ -92,7 +150,7 @@ public class SignatureAlgorithm extends Algorithm { ...@@ -92,7 +150,7 @@ public class SignatureAlgorithm extends Algorithm {
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs, throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs,
ex); ex);
} }
} }
/** /**
* Constructor SignatureAlgorithm * Constructor SignatureAlgorithm
...@@ -107,7 +165,8 @@ public class SignatureAlgorithm extends Algorithm { ...@@ -107,7 +165,8 @@ public class SignatureAlgorithm extends Algorithm {
throws XMLSecurityException { throws XMLSecurityException {
this(doc, algorithmURI); this(doc, algorithmURI);
this.algorithmURI=algorithmURI;
initializeAlgorithm(true);
this._signatureAlgorithm.engineSetHMACOutputLength(HMACOutputLength); this._signatureAlgorithm.engineSetHMACOutputLength(HMACOutputLength);
((IntegrityHmac)this._signatureAlgorithm) ((IntegrityHmac)this._signatureAlgorithm)
.engineAddContextToElement(this._constructionElement); .engineAddContextToElement(this._constructionElement);
...@@ -124,37 +183,7 @@ public class SignatureAlgorithm extends Algorithm { ...@@ -124,37 +183,7 @@ public class SignatureAlgorithm extends Algorithm {
throws XMLSecurityException { throws XMLSecurityException {
super(element, BaseURI); super(element, BaseURI);
algorithmURI = this.getURI();
String algorithmURI = this.getURI();
try {
Class implementingClass =
SignatureAlgorithm.getImplementingClass(algorithmURI);
if (true)
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Create URI \"" + algorithmURI + "\" class \""
+ implementingClass + "\"");
this._signatureAlgorithm =
(SignatureAlgorithmSpi) implementingClass.newInstance();
this._signatureAlgorithm
.engineGetContextFromElement(this._constructionElement);
} catch (IllegalAccessException ex) {
Object exArgs[] = { algorithmURI, ex.getMessage() };
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs,
ex);
} catch (InstantiationException ex) {
Object exArgs[] = { algorithmURI, ex.getMessage() };
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs,
ex);
} catch (NullPointerException ex) {
Object exArgs[] = { algorithmURI, ex.getMessage() };
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs,
ex);
}
} }
/** /**
...@@ -175,7 +204,12 @@ public class SignatureAlgorithm extends Algorithm { ...@@ -175,7 +204,12 @@ public class SignatureAlgorithm extends Algorithm {
* @return the result of the {@link java.security.Signature#getAlgorithm} method * @return the result of the {@link java.security.Signature#getAlgorithm} method
*/ */
public String getJCEAlgorithmString() { public String getJCEAlgorithmString() {
return this._signatureAlgorithm.engineGetJCEAlgorithmString(); try {
return getInstanceForVerify(algorithmURI).engineGetJCEAlgorithmString();
} catch (XMLSignatureException e) {
//Ignore.
return null;
}
} }
/** /**
...@@ -184,7 +218,11 @@ public class SignatureAlgorithm extends Algorithm { ...@@ -184,7 +218,11 @@ public class SignatureAlgorithm extends Algorithm {
* @return The Provider of this Signature Alogrithm * @return The Provider of this Signature Alogrithm
*/ */
public String getJCEProviderName() { public String getJCEProviderName() {
return this._signatureAlgorithm.engineGetJCEProviderName(); try {
return getInstanceForVerify(algorithmURI).engineGetJCEProviderName();
} catch (XMLSignatureException e) {
return null;
}
} }
/** /**
...@@ -231,6 +269,12 @@ public class SignatureAlgorithm extends Algorithm { ...@@ -231,6 +269,12 @@ public class SignatureAlgorithm extends Algorithm {
* @throws XMLSignatureException * @throws XMLSignatureException
*/ */
public void initSign(Key signingKey) throws XMLSignatureException { public void initSign(Key signingKey) throws XMLSignatureException {
initializeAlgorithm(true);
Map map=(Map)keysSigning.get();
if (map.get(this.algorithmURI)==signingKey) {
return;
}
map.put(this.algorithmURI,signingKey);
this._signatureAlgorithm.engineInitSign(signingKey); this._signatureAlgorithm.engineInitSign(signingKey);
} }
...@@ -244,6 +288,7 @@ public class SignatureAlgorithm extends Algorithm { ...@@ -244,6 +288,7 @@ public class SignatureAlgorithm extends Algorithm {
*/ */
public void initSign(Key signingKey, SecureRandom secureRandom) public void initSign(Key signingKey, SecureRandom secureRandom)
throws XMLSignatureException { throws XMLSignatureException {
initializeAlgorithm(true);
this._signatureAlgorithm.engineInitSign(signingKey, secureRandom); this._signatureAlgorithm.engineInitSign(signingKey, secureRandom);
} }
...@@ -258,6 +303,7 @@ public class SignatureAlgorithm extends Algorithm { ...@@ -258,6 +303,7 @@ public class SignatureAlgorithm extends Algorithm {
public void initSign( public void initSign(
Key signingKey, AlgorithmParameterSpec algorithmParameterSpec) Key signingKey, AlgorithmParameterSpec algorithmParameterSpec)
throws XMLSignatureException { throws XMLSignatureException {
initializeAlgorithm(true);
this._signatureAlgorithm.engineInitSign(signingKey, this._signatureAlgorithm.engineInitSign(signingKey,
algorithmParameterSpec); algorithmParameterSpec);
} }
...@@ -282,6 +328,12 @@ public class SignatureAlgorithm extends Algorithm { ...@@ -282,6 +328,12 @@ public class SignatureAlgorithm extends Algorithm {
* @throws XMLSignatureException * @throws XMLSignatureException
*/ */
public void initVerify(Key verificationKey) throws XMLSignatureException { public void initVerify(Key verificationKey) throws XMLSignatureException {
initializeAlgorithm(false);
Map map=(Map)keysVerify.get();
if (map.get(this.algorithmURI)==verificationKey) {
return;
}
map.put(this.algorithmURI,verificationKey);
this._signatureAlgorithm.engineInitVerify(verificationKey); this._signatureAlgorithm.engineInitVerify(verificationKey);
} }
...@@ -320,7 +372,7 @@ public class SignatureAlgorithm extends Algorithm { ...@@ -320,7 +372,7 @@ public class SignatureAlgorithm extends Algorithm {
.getLogger(SignatureAlgorithm.class.getName()); .getLogger(SignatureAlgorithm.class.getName());
} }
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Init() called"); log.log(java.util.logging.Level.FINE, "Init() called");
if (!SignatureAlgorithm._alreadyInitialized) { if (!SignatureAlgorithm._alreadyInitialized) {
SignatureAlgorithm._algorithmHash = new HashMap(10); SignatureAlgorithm._algorithmHash = new HashMap(10);
...@@ -340,8 +392,8 @@ public class SignatureAlgorithm extends Algorithm { ...@@ -340,8 +392,8 @@ public class SignatureAlgorithm extends Algorithm {
throws AlgorithmAlreadyRegisteredException,XMLSignatureException { throws AlgorithmAlreadyRegisteredException,XMLSignatureException {
{ {
if (true) if (log.isLoggable(java.util.logging.Level.FINE))
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Try to register " + algorithmURI + " " + implementingClass); log.log(java.util.logging.Level.FINE, "Try to register " + algorithmURI + " " + implementingClass);
// are we already registered? // are we already registered?
Class registeredClassClass = Class registeredClassClass =
......
...@@ -20,27 +20,20 @@ ...@@ -20,27 +20,20 @@
*/ */
package com.sun.org.apache.xml.internal.security.algorithms; package com.sun.org.apache.xml.internal.security.algorithms;
import java.security.Key; import java.security.Key;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec; import java.security.spec.AlgorithmParameterSpec;
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException; import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException;
import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
/** /**
* *
* @author $Author: raul $ * @author $Author: mullan $
*/ */
public abstract class SignatureAlgorithmSpi { public abstract class SignatureAlgorithmSpi {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(SignatureAlgorithmSpi.class.getName());
/** /**
* Returns the URI representation of <code>Transformation algorithm</code> * Returns the URI representation of <code>Transformation algorithm</code>
* *
...@@ -167,20 +160,6 @@ public abstract class SignatureAlgorithmSpi { ...@@ -167,20 +160,6 @@ public abstract class SignatureAlgorithmSpi {
protected abstract void engineSetParameter(AlgorithmParameterSpec params) protected abstract void engineSetParameter(AlgorithmParameterSpec params)
throws XMLSignatureException; throws XMLSignatureException;
/** Field _doc */
Document _doc = null;
/**
* Method engineSetDocument
*
* @param doc
*/
protected void engineSetDocument(Document doc) {
this._doc = doc;
}
/** Field _constructionElement */
Element _constructionElement = null;
/** /**
* Method engineGetContextFromElement * Method engineGetContextFromElement
...@@ -188,7 +167,6 @@ public abstract class SignatureAlgorithmSpi { ...@@ -188,7 +167,6 @@ public abstract class SignatureAlgorithmSpi {
* @param element * @param element
*/ */
protected void engineGetContextFromElement(Element element) { protected void engineGetContextFromElement(Element element) {
this._constructionElement = element;
} }
/** /**
...@@ -199,4 +177,7 @@ public abstract class SignatureAlgorithmSpi { ...@@ -199,4 +177,7 @@ public abstract class SignatureAlgorithmSpi {
*/ */
protected abstract void engineSetHMACOutputLength(int HMACOutputLength) protected abstract void engineSetHMACOutputLength(int HMACOutputLength)
throws XMLSignatureException; throws XMLSignatureException;
public void reset() {
}
} }
...@@ -45,7 +45,7 @@ import org.w3c.dom.Text; ...@@ -45,7 +45,7 @@ import org.w3c.dom.Text;
/** /**
* *
* @author $Author: raul $ * @author $Author: mullan $
*/ */
public abstract class IntegrityHmac extends SignatureAlgorithmSpi { public abstract class IntegrityHmac extends SignatureAlgorithmSpi {
...@@ -74,8 +74,8 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi { ...@@ -74,8 +74,8 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi {
public IntegrityHmac() throws XMLSignatureException { public IntegrityHmac() throws XMLSignatureException {
String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI()); String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
if (true) if (log.isLoggable(java.util.logging.Level.FINE))
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Created IntegrityHmacSHA1 using " + algorithmID); log.log(java.util.logging.Level.FINE, "Created IntegrityHmacSHA1 using " + algorithmID);
try { try {
this._macAlgorithm = Mac.getInstance(algorithmID); this._macAlgorithm = Mac.getInstance(algorithmID);
...@@ -99,6 +99,10 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi { ...@@ -99,6 +99,10 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi {
throw new XMLSignatureException("empty"); throw new XMLSignatureException("empty");
} }
public void reset() {
_HMACOutputLength=0;
}
/** /**
* Proxy method for {@link java.security.Signature#verify(byte[])} * Proxy method for {@link java.security.Signature#verify(byte[])}
* which is executed on the internal {@link java.security.Signature} object. * which is executed on the internal {@link java.security.Signature} object.
...@@ -145,6 +149,19 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi { ...@@ -145,6 +149,19 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi {
try { try {
this._macAlgorithm.init(secretKey); this._macAlgorithm.init(secretKey);
} catch (InvalidKeyException ex) { } catch (InvalidKeyException ex) {
// reinstantiate Mac object to work around bug in JDK
// see: http://bugs.sun.com/view_bug.do?bug_id=4953555
Mac mac = this._macAlgorithm;
try {
this._macAlgorithm = Mac.getInstance
(_macAlgorithm.getAlgorithm());
} catch (Exception e) {
// this shouldn't occur, but if it does, restore previous Mac
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Exception when reinstantiating Mac:" + e);
}
this._macAlgorithm = mac;
}
throw new XMLSignatureException("empty", ex); throw new XMLSignatureException("empty", ex);
} }
} }
...@@ -323,7 +340,7 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi { ...@@ -323,7 +340,7 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi {
*/ */
protected String engineGetJCEAlgorithmString() { protected String engineGetJCEAlgorithmString() {
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "engineGetJCEAlgorithmString()"); log.log(java.util.logging.Level.FINE, "engineGetJCEAlgorithmString()");
return this._macAlgorithm.getAlgorithm(); return this._macAlgorithm.getAlgorithm();
} }
...@@ -397,7 +414,8 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi { ...@@ -397,7 +414,8 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi {
/** /**
* Class IntegrityHmacSHA1 * Class IntegrityHmacSHA1
* *
* @author $Author: raul $ * @author $Author: mullan $
* @version $Revision: 1.5 $
*/ */
public static class IntegrityHmacSHA1 extends IntegrityHmac { public static class IntegrityHmacSHA1 extends IntegrityHmac {
...@@ -423,7 +441,8 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi { ...@@ -423,7 +441,8 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi {
/** /**
* Class IntegrityHmacSHA256 * Class IntegrityHmacSHA256
* *
* @author $Author: raul $ * @author $Author: mullan $
* @version $Revision: 1.5 $
*/ */
public static class IntegrityHmacSHA256 extends IntegrityHmac { public static class IntegrityHmacSHA256 extends IntegrityHmac {
...@@ -449,7 +468,8 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi { ...@@ -449,7 +468,8 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi {
/** /**
* Class IntegrityHmacSHA384 * Class IntegrityHmacSHA384
* *
* @author $Author: raul $ * @author $Author: mullan $
* @version $Revision: 1.5 $
*/ */
public static class IntegrityHmacSHA384 extends IntegrityHmac { public static class IntegrityHmacSHA384 extends IntegrityHmac {
...@@ -475,7 +495,8 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi { ...@@ -475,7 +495,8 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi {
/** /**
* Class IntegrityHmacSHA512 * Class IntegrityHmacSHA512
* *
* @author $Author: raul $ * @author $Author: mullan $
* @version $Revision: 1.5 $
*/ */
public static class IntegrityHmacSHA512 extends IntegrityHmac { public static class IntegrityHmacSHA512 extends IntegrityHmac {
...@@ -501,7 +522,8 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi { ...@@ -501,7 +522,8 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi {
/** /**
* Class IntegrityHmacRIPEMD160 * Class IntegrityHmacRIPEMD160
* *
* @author $Author: raul $ * @author $Author: mullan $
* @version $Revision: 1.5 $
*/ */
public static class IntegrityHmacRIPEMD160 extends IntegrityHmac { public static class IntegrityHmacRIPEMD160 extends IntegrityHmac {
...@@ -527,7 +549,8 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi { ...@@ -527,7 +549,8 @@ public abstract class IntegrityHmac extends SignatureAlgorithmSpi {
/** /**
* Class IntegrityHmacMD5 * Class IntegrityHmacMD5
* *
* @author $Author: raul $ * @author $Author: mullan $
* @version $Revision: 1.5 $
*/ */
public static class IntegrityHmacMD5 extends IntegrityHmac { public static class IntegrityHmacMD5 extends IntegrityHmac {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /*
* Copyright 1999-2004 The Apache Software Foundation. * Copyright 1999-2007 The Apache Software Foundation.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -20,8 +20,6 @@ ...@@ -20,8 +20,6 @@
*/ */
package com.sun.org.apache.xml.internal.security.algorithms.implementations; package com.sun.org.apache.xml.internal.security.algorithms.implementations;
import java.security.InvalidAlgorithmParameterException; import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.Key; import java.security.Key;
...@@ -38,16 +36,16 @@ import com.sun.org.apache.xml.internal.security.algorithms.SignatureAlgorithmSpi ...@@ -38,16 +36,16 @@ import com.sun.org.apache.xml.internal.security.algorithms.SignatureAlgorithmSpi
import com.sun.org.apache.xml.internal.security.signature.XMLSignature; import com.sun.org.apache.xml.internal.security.signature.XMLSignature;
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException; import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException;
/** /**
* *
* @author $Author: raul $ * @author $Author: mullan $
*/ */
public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** {@link java.util.logging} logging facility */ /** {@link java.util.logging} logging facility */
static java.util.logging.Logger log = static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(SignatureBaseRSA.class.getName()); java.util.logging.Logger.getLogger
(SignatureBaseRSA.class.getName());
/** @inheritDoc */ /** @inheritDoc */
public abstract String engineGetURI(); public abstract String engineGetURI();
...@@ -64,8 +62,8 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -64,8 +62,8 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI()); String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
if (true) if (log.isLoggable(java.util.logging.Level.FINE))
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Created SignatureDSA using " + algorithmID); log.log(java.util.logging.Level.FINE, "Created SignatureRSA using " + algorithmID);
String provider=JCEMapper.getProviderId(); String provider=JCEMapper.getProviderId();
try { try {
if (provider==null) { if (provider==null) {
...@@ -74,13 +72,11 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -74,13 +72,11 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
this._signatureAlgorithm = Signature.getInstance(algorithmID,provider); this._signatureAlgorithm = Signature.getInstance(algorithmID,provider);
} }
} catch (java.security.NoSuchAlgorithmException ex) { } catch (java.security.NoSuchAlgorithmException ex) {
Object[] exArgs = { algorithmID, Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
ex.getLocalizedMessage() };
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs); throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
} catch (NoSuchProviderException ex) { } catch (NoSuchProviderException ex) {
Object[] exArgs = { algorithmID, Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
ex.getLocalizedMessage() };
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs); throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
} }
...@@ -116,20 +112,33 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -116,20 +112,33 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
String needed = PublicKey.class.getName(); String needed = PublicKey.class.getName();
Object exArgs[] = { supplied, needed }; Object exArgs[] = { supplied, needed };
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", throw new XMLSignatureException
exArgs); ("algorithms.WrongKeyForThisOperation", exArgs);
} }
try { try {
this._signatureAlgorithm.initVerify((PublicKey) publicKey); this._signatureAlgorithm.initVerify((PublicKey) publicKey);
} catch (InvalidKeyException ex) { } catch (InvalidKeyException ex) {
// reinstantiate Signature object to work around bug in JDK
// see: http://bugs.sun.com/view_bug.do?bug_id=4953555
Signature sig = this._signatureAlgorithm;
try {
this._signatureAlgorithm = Signature.getInstance
(_signatureAlgorithm.getAlgorithm());
} catch (Exception e) {
// this shouldn't occur, but if it does, restore previous
// Signature
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Exception when reinstantiating Signature:" + e);
}
this._signatureAlgorithm = sig;
}
throw new XMLSignatureException("empty", ex); throw new XMLSignatureException("empty", ex);
} }
} }
/** @inheritDoc */ /** @inheritDoc */
protected byte[] engineSign() throws XMLSignatureException { protected byte[] engineSign() throws XMLSignatureException {
try { try {
return this._signatureAlgorithm.sign(); return this._signatureAlgorithm.sign();
} catch (SignatureException ex) { } catch (SignatureException ex) {
...@@ -146,13 +155,13 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -146,13 +155,13 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
String needed = PrivateKey.class.getName(); String needed = PrivateKey.class.getName();
Object exArgs[] = { supplied, needed }; Object exArgs[] = { supplied, needed };
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", throw new XMLSignatureException
exArgs); ("algorithms.WrongKeyForThisOperation", exArgs);
} }
try { try {
this._signatureAlgorithm.initSign((PrivateKey) privateKey, this._signatureAlgorithm.initSign
secureRandom); ((PrivateKey) privateKey, secureRandom);
} catch (InvalidKeyException ex) { } catch (InvalidKeyException ex) {
throw new XMLSignatureException("empty", ex); throw new XMLSignatureException("empty", ex);
} }
...@@ -166,8 +175,8 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -166,8 +175,8 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
String needed = PrivateKey.class.getName(); String needed = PrivateKey.class.getName();
Object exArgs[] = { supplied, needed }; Object exArgs[] = { supplied, needed };
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", throw new XMLSignatureException
exArgs); ("algorithms.WrongKeyForThisOperation", exArgs);
} }
try { try {
...@@ -179,7 +188,6 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -179,7 +188,6 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */ /** @inheritDoc */
protected void engineUpdate(byte[] input) throws XMLSignatureException { protected void engineUpdate(byte[] input) throws XMLSignatureException {
try { try {
this._signatureAlgorithm.update(input); this._signatureAlgorithm.update(input);
} catch (SignatureException ex) { } catch (SignatureException ex) {
...@@ -189,7 +197,6 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -189,7 +197,6 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */ /** @inheritDoc */
protected void engineUpdate(byte input) throws XMLSignatureException { protected void engineUpdate(byte input) throws XMLSignatureException {
try { try {
this._signatureAlgorithm.update(input); this._signatureAlgorithm.update(input);
} catch (SignatureException ex) { } catch (SignatureException ex) {
...@@ -200,7 +207,6 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -200,7 +207,6 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */ /** @inheritDoc */
protected void engineUpdate(byte buf[], int offset, int len) protected void engineUpdate(byte buf[], int offset, int len)
throws XMLSignatureException { throws XMLSignatureException {
try { try {
this._signatureAlgorithm.update(buf, offset, len); this._signatureAlgorithm.update(buf, offset, len);
} catch (SignatureException ex) { } catch (SignatureException ex) {
...@@ -221,7 +227,8 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -221,7 +227,8 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */ /** @inheritDoc */
protected void engineSetHMACOutputLength(int HMACOutputLength) protected void engineSetHMACOutputLength(int HMACOutputLength)
throws XMLSignatureException { throws XMLSignatureException {
throw new XMLSignatureException("algorithms.HMACOutputLengthOnlyForHMAC"); throw new XMLSignatureException
("algorithms.HMACOutputLengthOnlyForHMAC");
} }
/** @inheritDoc */ /** @inheritDoc */
...@@ -235,7 +242,8 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -235,7 +242,8 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** /**
* Class SignatureRSASHA1 * Class SignatureRSASHA1
* *
* @author $Author: raul $ * @author $Author: mullan $
* @version $Revision: 1.5 $
*/ */
public static class SignatureRSASHA1 extends SignatureBaseRSA { public static class SignatureRSASHA1 extends SignatureBaseRSA {
...@@ -257,7 +265,8 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -257,7 +265,8 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** /**
* Class SignatureRSASHA256 * Class SignatureRSASHA256
* *
* @author $Author: raul $ * @author $Author: mullan $
* @version $Revision: 1.5 $
*/ */
public static class SignatureRSASHA256 extends SignatureBaseRSA { public static class SignatureRSASHA256 extends SignatureBaseRSA {
...@@ -279,7 +288,8 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -279,7 +288,8 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** /**
* Class SignatureRSASHA384 * Class SignatureRSASHA384
* *
* @author $Author: raul $ * @author $Author: mullan $
* @version $Revision: 1.5 $
*/ */
public static class SignatureRSASHA384 extends SignatureBaseRSA { public static class SignatureRSASHA384 extends SignatureBaseRSA {
...@@ -301,7 +311,8 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -301,7 +311,8 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** /**
* Class SignatureRSASHA512 * Class SignatureRSASHA512
* *
* @author $Author: raul $ * @author $Author: mullan $
* @version $Revision: 1.5 $
*/ */
public static class SignatureRSASHA512 extends SignatureBaseRSA { public static class SignatureRSASHA512 extends SignatureBaseRSA {
...@@ -323,7 +334,8 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -323,7 +334,8 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** /**
* Class SignatureRSARIPEMD160 * Class SignatureRSARIPEMD160
* *
* @author $Author: raul $ * @author $Author: mullan $
* @version $Revision: 1.5 $
*/ */
public static class SignatureRSARIPEMD160 extends SignatureBaseRSA { public static class SignatureRSARIPEMD160 extends SignatureBaseRSA {
...@@ -345,7 +357,8 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi { ...@@ -345,7 +357,8 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** /**
* Class SignatureRSAMD5 * Class SignatureRSAMD5
* *
* @author $Author: raul $ * @author $Author: mullan $
* @version $Revision: 1.5 $
*/ */
public static class SignatureRSAMD5 extends SignatureBaseRSA { public static class SignatureRSAMD5 extends SignatureBaseRSA {
......
...@@ -20,8 +20,6 @@ ...@@ -20,8 +20,6 @@
*/ */
package com.sun.org.apache.xml.internal.security.algorithms.implementations; package com.sun.org.apache.xml.internal.security.algorithms.implementations;
import java.io.IOException; import java.io.IOException;
import java.security.InvalidAlgorithmParameterException; import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
...@@ -39,10 +37,9 @@ import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException; ...@@ -39,10 +37,9 @@ import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException;
import com.sun.org.apache.xml.internal.security.utils.Base64; import com.sun.org.apache.xml.internal.security.utils.Base64;
import com.sun.org.apache.xml.internal.security.utils.Constants; import com.sun.org.apache.xml.internal.security.utils.Constants;
/** /**
* *
* @author $Author: vishal $ * @author $Author: mullan $
*/ */
public class SignatureDSA extends SignatureAlgorithmSpi { public class SignatureDSA extends SignatureAlgorithmSpi {
...@@ -73,15 +70,22 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -73,15 +70,22 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
public SignatureDSA() throws XMLSignatureException { public SignatureDSA() throws XMLSignatureException {
String algorithmID = JCEMapper.translateURItoJCEID(SignatureDSA._URI); String algorithmID = JCEMapper.translateURItoJCEID(SignatureDSA._URI);
if (true) if (log.isLoggable(java.util.logging.Level.FINE))
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Created SignatureDSA using " + algorithmID); log.log(java.util.logging.Level.FINE, "Created SignatureDSA using " + algorithmID);
String provider = JCEMapper.getProviderId();
try { try {
if (provider == null) {
this._signatureAlgorithm = Signature.getInstance(algorithmID); this._signatureAlgorithm = Signature.getInstance(algorithmID);
} else {
this._signatureAlgorithm =
Signature.getInstance(algorithmID, provider);
}
} catch (java.security.NoSuchAlgorithmException ex) { } catch (java.security.NoSuchAlgorithmException ex) {
Object[] exArgs = { algorithmID, Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
ex.getLocalizedMessage() }; throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
} catch (java.security.NoSuchProviderException ex) {
Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs); throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
} }
} }
...@@ -106,8 +110,8 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -106,8 +110,8 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
throws XMLSignatureException { throws XMLSignatureException {
try { try {
if (true) if (log.isLoggable(java.util.logging.Level.FINE))
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Called DSA.verify() on " + Base64.encode(signature)); log.log(java.util.logging.Level.FINE, "Called DSA.verify() on " + Base64.encode(signature));
byte[] jcebytes = SignatureDSA.convertXMLDSIGtoASN1(signature); byte[] jcebytes = SignatureDSA.convertXMLDSIGtoASN1(signature);
...@@ -129,13 +133,27 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -129,13 +133,27 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
String needed = PublicKey.class.getName(); String needed = PublicKey.class.getName();
Object exArgs[] = { supplied, needed }; Object exArgs[] = { supplied, needed };
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", throw new XMLSignatureException
exArgs); ("algorithms.WrongKeyForThisOperation", exArgs);
} }
try { try {
this._signatureAlgorithm.initVerify((PublicKey) publicKey); this._signatureAlgorithm.initVerify((PublicKey) publicKey);
} catch (InvalidKeyException ex) { } catch (InvalidKeyException ex) {
// reinstantiate Signature object to work around bug in JDK
// see: http://bugs.sun.com/view_bug.do?bug_id=4953555
Signature sig = this._signatureAlgorithm;
try {
this._signatureAlgorithm = Signature.getInstance
(_signatureAlgorithm.getAlgorithm());
} catch (Exception e) {
// this shouldn't occur, but if it does, restore previous
// Signature
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Exception when reinstantiating Signature:" + e);
}
this._signatureAlgorithm = sig;
}
throw new XMLSignatureException("empty", ex); throw new XMLSignatureException("empty", ex);
} }
} }
...@@ -167,8 +185,8 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -167,8 +185,8 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
String needed = PrivateKey.class.getName(); String needed = PrivateKey.class.getName();
Object exArgs[] = { supplied, needed }; Object exArgs[] = { supplied, needed };
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", throw new XMLSignatureException
exArgs); ("algorithms.WrongKeyForThisOperation", exArgs);
} }
try { try {
...@@ -189,8 +207,8 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -189,8 +207,8 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
String needed = PrivateKey.class.getName(); String needed = PrivateKey.class.getName();
Object exArgs[] = { supplied, needed }; Object exArgs[] = { supplied, needed };
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", throw new XMLSignatureException
exArgs); ("algorithms.WrongKeyForThisOperation", exArgs);
} }
try { try {
...@@ -204,7 +222,6 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -204,7 +222,6 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @inheritDoc * @inheritDoc
*/ */
protected void engineUpdate(byte[] input) throws XMLSignatureException { protected void engineUpdate(byte[] input) throws XMLSignatureException {
try { try {
this._signatureAlgorithm.update(input); this._signatureAlgorithm.update(input);
} catch (SignatureException ex) { } catch (SignatureException ex) {
...@@ -216,7 +233,6 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -216,7 +233,6 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @inheritDoc * @inheritDoc
*/ */
protected void engineUpdate(byte input) throws XMLSignatureException { protected void engineUpdate(byte input) throws XMLSignatureException {
try { try {
this._signatureAlgorithm.update(input); this._signatureAlgorithm.update(input);
} catch (SignatureException ex) { } catch (SignatureException ex) {
...@@ -229,7 +245,6 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -229,7 +245,6 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
*/ */
protected void engineUpdate(byte buf[], int offset, int len) protected void engineUpdate(byte buf[], int offset, int len)
throws XMLSignatureException { throws XMLSignatureException {
try { try {
this._signatureAlgorithm.update(buf, offset, len); this._signatureAlgorithm.update(buf, offset, len);
} catch (SignatureException ex) { } catch (SignatureException ex) {
...@@ -255,7 +270,6 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -255,7 +270,6 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
return this._signatureAlgorithm.getProvider().getName(); return this._signatureAlgorithm.getProvider().getName();
} }
/** /**
* Converts an ASN.1 DSA value to a XML Signature DSA Value. * Converts an ASN.1 DSA value to a XML Signature DSA Value.
* *
...@@ -361,7 +375,8 @@ public class SignatureDSA extends SignatureAlgorithmSpi { ...@@ -361,7 +375,8 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
*/ */
protected void engineSetHMACOutputLength(int HMACOutputLength) protected void engineSetHMACOutputLength(int HMACOutputLength)
throws XMLSignatureException { throws XMLSignatureException {
throw new XMLSignatureException("algorithms.HMACOutputLengthOnlyForHMAC"); throw new XMLSignatureException(
"algorithms.HMACOutputLengthOnlyForHMAC");
} }
/** /**
......
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 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 com.sun.org.apache.xml.internal.security.algorithms.implementations;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Signature;
import java.security.SignatureException;
import java.security.spec.AlgorithmParameterSpec;
import com.sun.org.apache.xml.internal.security.algorithms.JCEMapper;
import com.sun.org.apache.xml.internal.security.algorithms.SignatureAlgorithmSpi;
import com.sun.org.apache.xml.internal.security.signature.XMLSignature;
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException;
import com.sun.org.apache.xml.internal.security.utils.Base64;
/**
*
* @author $Author: mullan $
*/
public abstract class SignatureECDSA extends SignatureAlgorithmSpi {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(SignatureECDSA.class.getName());
/** @inheritDoc */
public abstract String engineGetURI();
/** Field algorithm */
private java.security.Signature _signatureAlgorithm = null;
/**
* Converts an ASN.1 ECDSA value to a XML Signature ECDSA Value.
*
* The JAVA JCE ECDSA Signature algorithm creates ASN.1 encoded (r,s) value
* pairs; the XML Signature requires the core BigInteger values.
*
* @param asn1Bytes
* @return the decode bytes
*
* @throws IOException
* @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A>
* @see <A HREF="ftp://ftp.rfc-editor.org/in-notes/rfc4050.txt">3.3. ECDSA Signatures</A>
*/
private static byte[] convertASN1toXMLDSIG(byte asn1Bytes[])
throws IOException {
byte rLength = asn1Bytes[3];
int i;
for (i = rLength; (i > 0) && (asn1Bytes[(4 + rLength) - i] == 0); i--);
byte sLength = asn1Bytes[5 + rLength];
int j;
for (j = sLength;
(j > 0) && (asn1Bytes[(6 + rLength + sLength) - j] == 0); j--);
if ((asn1Bytes[0] != 48) || (asn1Bytes[1] != asn1Bytes.length - 2)
|| (asn1Bytes[2] != 2) || (i > 24)
|| (asn1Bytes[4 + rLength] != 2) || (j > 24)) {
throw new IOException("Invalid ASN.1 format of ECDSA signature");
}
byte xmldsigBytes[] = new byte[48];
System.arraycopy(asn1Bytes, (4 + rLength) - i, xmldsigBytes, 24 - i,
i);
System.arraycopy(asn1Bytes, (6 + rLength + sLength) - j, xmldsigBytes,
48 - j, j);
return xmldsigBytes;
}
/**
* Converts a XML Signature ECDSA Value to an ASN.1 DSA value.
*
* The JAVA JCE ECDSA Signature algorithm creates ASN.1 encoded (r,s) value
* pairs; the XML Signature requires the core BigInteger values.
*
* @param xmldsigBytes
* @return the encoded ASN.1 bytes
*
* @throws IOException
* @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A>
* @see <A HREF="ftp://ftp.rfc-editor.org/in-notes/rfc4050.txt">3.3. ECDSA Signatures</A>
*/
private static byte[] convertXMLDSIGtoASN1(byte xmldsigBytes[])
throws IOException {
if (xmldsigBytes.length != 48) {
throw new IOException("Invalid XMLDSIG format of ECDSA signature");
}
int i;
for (i = 24; (i > 0) && (xmldsigBytes[24 - i] == 0); i--);
int j = i;
if (xmldsigBytes[24 - i] < 0) {
j += 1;
}
int k;
for (k = 24; (k > 0) && (xmldsigBytes[48 - k] == 0); k--);
int l = k;
if (xmldsigBytes[48 - k] < 0) {
l += 1;
}
byte asn1Bytes[] = new byte[6 + j + l];
asn1Bytes[0] = 48;
asn1Bytes[1] = (byte) (4 + j + l);
asn1Bytes[2] = 2;
asn1Bytes[3] = (byte) j;
System.arraycopy(xmldsigBytes, 24 - i, asn1Bytes, (4 + j) - i, i);
asn1Bytes[4 + j] = 2;
asn1Bytes[5 + j] = (byte) l;
System.arraycopy(xmldsigBytes, 48 - k, asn1Bytes, (6 + j + l) - k, k);
return asn1Bytes;
}
/**
* Constructor SignatureRSA
*
* @throws XMLSignatureException
*/
public SignatureECDSA() throws XMLSignatureException {
String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
if (log.isLoggable(java.util.logging.Level.FINE))
log.log(java.util.logging.Level.FINE, "Created SignatureECDSA using " + algorithmID);
String provider=JCEMapper.getProviderId();
try {
if (provider==null) {
this._signatureAlgorithm = Signature.getInstance(algorithmID);
} else {
this._signatureAlgorithm = Signature.getInstance(algorithmID,provider);
}
} catch (java.security.NoSuchAlgorithmException ex) {
Object[] exArgs = { algorithmID,
ex.getLocalizedMessage() };
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
} catch (NoSuchProviderException ex) {
Object[] exArgs = { algorithmID,
ex.getLocalizedMessage() };
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
}
}
/** @inheritDoc */
protected void engineSetParameter(AlgorithmParameterSpec params)
throws XMLSignatureException {
try {
this._signatureAlgorithm.setParameter(params);
} catch (InvalidAlgorithmParameterException ex) {
throw new XMLSignatureException("empty", ex);
}
}
/** @inheritDoc */
protected boolean engineVerify(byte[] signature)
throws XMLSignatureException {
try {
byte[] jcebytes = SignatureECDSA.convertXMLDSIGtoASN1(signature);
if (log.isLoggable(java.util.logging.Level.FINE))
log.log(java.util.logging.Level.FINE, "Called ECDSA.verify() on " + Base64.encode(signature));
return this._signatureAlgorithm.verify(jcebytes);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
} catch (IOException ex) {
throw new XMLSignatureException("empty", ex);
}
}
/** @inheritDoc */
protected void engineInitVerify(Key publicKey) throws XMLSignatureException {
if (!(publicKey instanceof PublicKey)) {
String supplied = publicKey.getClass().getName();
String needed = PublicKey.class.getName();
Object exArgs[] = { supplied, needed };
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation",
exArgs);
}
try {
this._signatureAlgorithm.initVerify((PublicKey) publicKey);
} catch (InvalidKeyException ex) {
// reinstantiate Signature object to work around bug in JDK
// see: http://bugs.sun.com/view_bug.do?bug_id=4953555
Signature sig = this._signatureAlgorithm;
try {
this._signatureAlgorithm = Signature.getInstance
(_signatureAlgorithm.getAlgorithm());
} catch (Exception e) {
// this shouldn't occur, but if it does, restore previous
// Signature
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Exception when reinstantiating Signature:" + e);
}
this._signatureAlgorithm = sig;
}
throw new XMLSignatureException("empty", ex);
}
}
/** @inheritDoc */
protected byte[] engineSign() throws XMLSignatureException {
try {
byte jcebytes[] = this._signatureAlgorithm.sign();
return SignatureECDSA.convertASN1toXMLDSIG(jcebytes);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
} catch (IOException ex) {
throw new XMLSignatureException("empty", ex);
}
}
/** @inheritDoc */
protected void engineInitSign(Key privateKey, SecureRandom secureRandom)
throws XMLSignatureException {
if (!(privateKey instanceof PrivateKey)) {
String supplied = privateKey.getClass().getName();
String needed = PrivateKey.class.getName();
Object exArgs[] = { supplied, needed };
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation",
exArgs);
}
try {
this._signatureAlgorithm.initSign((PrivateKey) privateKey,
secureRandom);
} catch (InvalidKeyException ex) {
throw new XMLSignatureException("empty", ex);
}
}
/** @inheritDoc */
protected void engineInitSign(Key privateKey) throws XMLSignatureException {
if (!(privateKey instanceof PrivateKey)) {
String supplied = privateKey.getClass().getName();
String needed = PrivateKey.class.getName();
Object exArgs[] = { supplied, needed };
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation",
exArgs);
}
try {
this._signatureAlgorithm.initSign((PrivateKey) privateKey);
} catch (InvalidKeyException ex) {
throw new XMLSignatureException("empty", ex);
}
}
/** @inheritDoc */
protected void engineUpdate(byte[] input) throws XMLSignatureException {
try {
this._signatureAlgorithm.update(input);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
}
/** @inheritDoc */
protected void engineUpdate(byte input) throws XMLSignatureException {
try {
this._signatureAlgorithm.update(input);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
}
/** @inheritDoc */
protected void engineUpdate(byte buf[], int offset, int len)
throws XMLSignatureException {
try {
this._signatureAlgorithm.update(buf, offset, len);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
}
/** @inheritDoc */
protected String engineGetJCEAlgorithmString() {
return this._signatureAlgorithm.getAlgorithm();
}
/** @inheritDoc */
protected String engineGetJCEProviderName() {
return this._signatureAlgorithm.getProvider().getName();
}
/** @inheritDoc */
protected void engineSetHMACOutputLength(int HMACOutputLength)
throws XMLSignatureException {
throw new XMLSignatureException("algorithms.HMACOutputLengthOnlyForHMAC");
}
/** @inheritDoc */
protected void engineInitSign(
Key signingKey, AlgorithmParameterSpec algorithmParameterSpec)
throws XMLSignatureException {
throw new XMLSignatureException(
"algorithms.CannotUseAlgorithmParameterSpecOnRSA");
}
/**
* Class SignatureRSASHA1
*
* @author $Author: mullan $
* @version $Revision: 1.2 $
*/
public static class SignatureECDSASHA1 extends SignatureECDSA {
/**
* Constructor SignatureRSASHA1
*
* @throws XMLSignatureException
*/
public SignatureECDSASHA1() throws XMLSignatureException {
super();
}
/** @inheritDoc */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA1;
}
}
}
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
* reserved comment block * reserved comment block
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /*
* Copyright 1999-2004 The Apache Software Foundation. * Copyright 1999-2004 The Apache Software Foundation.
* *
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /*
* Copyright 1999-2004 The Apache Software Foundation. * Copyright 1999-2008 The Apache Software Foundation.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -20,8 +20,6 @@ ...@@ -20,8 +20,6 @@
*/ */
package com.sun.org.apache.xml.internal.security.c14n; package com.sun.org.apache.xml.internal.security.c14n;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.HashMap; import java.util.HashMap;
...@@ -37,47 +35,57 @@ import org.w3c.dom.Node; ...@@ -37,47 +35,57 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
/** /**
*
* *
* @author Christian Geuer-Pollmann * @author Christian Geuer-Pollmann
*/ */
public class Canonicalizer { public class Canonicalizer {
//J-
/** The output encoding of canonicalized data */ /** The output encoding of canonicalized data */
public static final String ENCODING = "UTF8"; public static final String ENCODING = "UTF8";
/** /**
* XPath Expresion for selecting every node and continuos comments joined in only one node * XPath Expresion for selecting every node and continuous comments joined
* in only one node
*/ */
public static final String XPATH_C14N_WITH_COMMENTS_SINGLE_NODE = "(.//. | .//@* | .//namespace::*)"; public static final String XPATH_C14N_WITH_COMMENTS_SINGLE_NODE =
"(.//. | .//@* | .//namespace::*)";
/** /**
* The URL defined in XML-SEC Rec for inclusive c14n <b>without</b> comments. * The URL defined in XML-SEC Rec for inclusive c14n <b>without</b> comments.
*/ */
public static final String ALGO_ID_C14N_OMIT_COMMENTS = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"; public static final String ALGO_ID_C14N_OMIT_COMMENTS =
"http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
/** /**
* The URL defined in XML-SEC Rec for inclusive c14n <b>with</b> comments. * The URL defined in XML-SEC Rec for inclusive c14n <b>with</b> comments.
*/ */
public static final String ALGO_ID_C14N_WITH_COMMENTS = ALGO_ID_C14N_OMIT_COMMENTS + "#WithComments"; public static final String ALGO_ID_C14N_WITH_COMMENTS =
ALGO_ID_C14N_OMIT_COMMENTS + "#WithComments";
/** /**
* The URL defined in XML-SEC Rec for exclusive c14n <b>without</b> comments. * The URL defined in XML-SEC Rec for exclusive c14n <b>without</b> comments.
*/ */
public static final String ALGO_ID_C14N_EXCL_OMIT_COMMENTS = "http://www.w3.org/2001/10/xml-exc-c14n#"; public static final String ALGO_ID_C14N_EXCL_OMIT_COMMENTS =
"http://www.w3.org/2001/10/xml-exc-c14n#";
/** /**
* The URL defined in XML-SEC Rec for exclusive c14n <b>with</b> comments. * The URL defined in XML-SEC Rec for exclusive c14n <b>with</b> comments.
*/ */
public static final String ALGO_ID_C14N_EXCL_WITH_COMMENTS = ALGO_ID_C14N_EXCL_OMIT_COMMENTS + "WithComments"; public static final String ALGO_ID_C14N_EXCL_WITH_COMMENTS =
ALGO_ID_C14N_EXCL_OMIT_COMMENTS + "WithComments";
/**
* The URI for inclusive c14n 1.1 <b>without</b> comments.
*/
public static final String ALGO_ID_C14N11_OMIT_COMMENTS =
"http://www.w3.org/2006/12/xml-c14n11";
/**
* The URI for inclusive c14n 1.1 <b>with</b> comments.
*/
public static final String ALGO_ID_C14N11_WITH_COMMENTS =
ALGO_ID_C14N11_OMIT_COMMENTS + "#WithComments";
static boolean _alreadyInitialized = false; static boolean _alreadyInitialized = false;
static Map _canonicalizerHash = null; static Map _canonicalizerHash = null;
protected CanonicalizerSpi canonicalizerSpi = null; protected CanonicalizerSpi canonicalizerSpi = null;
//J+
/** /**
* Method init * Method init
...@@ -309,16 +317,15 @@ public class Canonicalizer { ...@@ -309,16 +317,15 @@ public class Canonicalizer {
* @return the result of the c14n. * @return the result of the c14n.
* @throws CanonicalizationException * @throws CanonicalizationException
*/ */
public byte[] canonicalizeXPathNodeSet( public byte[] canonicalizeXPathNodeSet(Set xpathNodeSet,
Set xpathNodeSet, String inclusiveNamespaces) String inclusiveNamespaces) throws CanonicalizationException {
throws CanonicalizationException {
return this.canonicalizerSpi.engineCanonicalizeXPathNodeSet(xpathNodeSet, return this.canonicalizerSpi.engineCanonicalizeXPathNodeSet(xpathNodeSet,
inclusiveNamespaces); inclusiveNamespaces);
} }
/** /**
* Sets the writter where the cannocalization ends. ByteArrayOutputStream if * Sets the writer where the canonicalization ends. ByteArrayOutputStream
* none is setted. * if none is set.
* @param os * @param os
*/ */
public void setWriter(OutputStream os) { public void setWriter(OutputStream os) {
...@@ -338,17 +345,16 @@ public class Canonicalizer { ...@@ -338,17 +345,16 @@ public class Canonicalizer {
* Method getImplementingClass * Method getImplementingClass
* *
* @param URI * @param URI
* @return the name of the class that implements the give URI * @return the name of the class that implements the given URI
*/ */
private static Class getImplementingClass(String URI) { private static Class getImplementingClass(String URI) {
return (Class) _canonicalizerHash.get(URI); return (Class) _canonicalizerHash.get(URI);
} }
/** /**
* Set the canonicalizator behaviour to not reset. * Set the canonicalizer behaviour to not reset.
*
*/ */
public void notReset() { public void notReset() {
this.canonicalizerSpi.reset=false; this.canonicalizerSpi.reset = false;
} }
} }
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
* reserved comment block * reserved comment block
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /*
* Copyright 1999-2004 The Apache Software Foundation. * Copyright 1999-2004 The Apache Software Foundation.
* *
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
* reserved comment block * reserved comment block
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /*
* Copyright 1999-2004 The Apache Software Foundation. * Copyright 1999-2004 The Apache Software Foundation.
* *
...@@ -21,17 +20,17 @@ ...@@ -21,17 +20,17 @@
*/ */
package com.sun.org.apache.xml.internal.security.c14n.helper; package com.sun.org.apache.xml.internal.security.c14n.helper;
import com.sun.org.apache.xml.internal.security.utils.Constants; import com.sun.org.apache.xml.internal.security.utils.Constants;
import org.w3c.dom.Attr; import org.w3c.dom.Attr;
import java.io.Serializable;
import java.util.Comparator;
/** /**
* Compares two attributes based on the C14n specification. * Compares two attributes based on the C14n specification.
* *
* <UL> * <UL>
* <LI>Namespace nodes have a lesser document order position than attribute nodes. * <LI>Namespace nodes have a lesser document order position than attribute
* nodes.
* <LI> An element's namespace nodes are sorted lexicographically by * <LI> An element's namespace nodes are sorted lexicographically by
* local name (the default namespace node, if one exists, has no * local name (the default namespace node, if one exists, has no
* local name and is therefore lexicographically least). * local name and is therefore lexicographically least).
...@@ -40,20 +39,21 @@ import org.w3c.dom.Attr; ...@@ -40,20 +39,21 @@ import org.w3c.dom.Attr;
* key (an empty namespace URI is lexicographically least). * key (an empty namespace URI is lexicographically least).
* </UL> * </UL>
* *
* $todo$ Should we implement java.util.Comparator and import java.util.Arrays to use Arrays.sort(intarray);
* @author Christian Geuer-Pollmann * @author Christian Geuer-Pollmann
*/ */
public class AttrCompare implements java.util.Comparator { public class AttrCompare implements Comparator, Serializable {
private final int ATTR0_BEFORE_ATTR1 = -1;
private final int ATTR1_BEFORE_ATTR0 = 1;
private final static long serialVersionUID = -7113259629930576230L;
private final static int ATTR0_BEFORE_ATTR1 = -1;
private final static int ATTR1_BEFORE_ATTR0 = 1;
private final static String XMLNS=Constants.NamespaceSpecNS; private final static String XMLNS=Constants.NamespaceSpecNS;
/** /**
* Compares two attributes based on the C14n specification. * Compares two attributes based on the C14n specification.
* *
* <UL> * <UL>
* <LI>Namespace nodes have a lesser document order position than attribute nodes. * <LI>Namespace nodes have a lesser document order position than
* attribute nodes.
* <LI> An element's namespace nodes are sorted lexicographically by * <LI> An element's namespace nodes are sorted lexicographically by
* local name (the default namespace node, if one exists, has no * local name (the default namespace node, if one exists, has no
* local name and is therefore lexicographically least). * local name and is therefore lexicographically least).
...@@ -64,7 +64,8 @@ public class AttrCompare implements java.util.Comparator { ...@@ -64,7 +64,8 @@ public class AttrCompare implements java.util.Comparator {
* *
* @param obj0 casted Attr * @param obj0 casted Attr
* @param obj1 casted Attr * @param obj1 casted Attr
* @return returns a negative integer, zero, or a positive integer as obj0 is less than, equal to, or greater than obj1 * @return returns a negative integer, zero, or a positive integer as
* obj0 is less than, equal to, or greater than obj1
* *
*/ */
public int compare(Object obj0, Object obj1) { public int compare(Object obj0, Object obj1) {
...@@ -74,14 +75,11 @@ public class AttrCompare implements java.util.Comparator { ...@@ -74,14 +75,11 @@ public class AttrCompare implements java.util.Comparator {
String namespaceURI0 = attr0.getNamespaceURI(); String namespaceURI0 = attr0.getNamespaceURI();
String namespaceURI1 = attr1.getNamespaceURI(); String namespaceURI1 = attr1.getNamespaceURI();
boolean isNamespaceAttr0 = boolean isNamespaceAttr0 = XMLNS==namespaceURI0;
XMLNS.equals(namespaceURI0); boolean isNamespaceAttr1 = XMLNS==namespaceURI1;
boolean isNamespaceAttr1 =
XMLNS.equals(namespaceURI1);
if (isNamespaceAttr0) { if (isNamespaceAttr0) {
if (isNamespaceAttr1) { if (isNamespaceAttr1) {
// both are namespaces // both are namespaces
String localname0 = attr0.getLocalName(); String localname0 = attr0.getLocalName();
String localname1 = attr1.getLocalName(); String localname1 = attr1.getLocalName();
...@@ -98,46 +96,32 @@ public class AttrCompare implements java.util.Comparator { ...@@ -98,46 +96,32 @@ public class AttrCompare implements java.util.Comparator {
} }
// attr0 is a namespace, attr1 is not // attr0 is a namespace, attr1 is not
return ATTR0_BEFORE_ATTR1; return ATTR0_BEFORE_ATTR1;
} }
if (isNamespaceAttr1) {
if (isNamespaceAttr1) {
// attr1 is a namespace, attr0 is not // attr1 is a namespace, attr0 is not
return ATTR1_BEFORE_ATTR0; return ATTR1_BEFORE_ATTR0;
} }
// none is a namespae // none is a namespace
if (namespaceURI0 == null) { if (namespaceURI0 == null) {
if (namespaceURI1 == null) { if (namespaceURI1 == null) {
/*
String localName0 = attr0.getLocalName();
String localName1 = attr1.getLocalName();
return localName0.compareTo(localName1);
*/
String name0 = attr0.getName(); String name0 = attr0.getName();
String name1 = attr1.getName(); String name1 = attr1.getName();
return name0.compareTo(name1); return name0.compareTo(name1);
} }
return ATTR0_BEFORE_ATTR1; return ATTR0_BEFORE_ATTR1;
} }
if (namespaceURI1 == null) { if (namespaceURI1 == null) {
return ATTR1_BEFORE_ATTR0; return ATTR1_BEFORE_ATTR0;
} }
int a = namespaceURI0.compareTo(namespaceURI1);
int a = namespaceURI0.compareTo(namespaceURI1);
if (a != 0) { if (a != 0) {
return a; return a;
} }
/*
String localName0 = ;
String localName1 =;*/
return (attr0.getLocalName())
.compareTo( attr1.getLocalName());
return (attr0.getLocalName()).compareTo(attr1.getLocalName());
} }
} }
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2008 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 com.sun.org.apache.xml.internal.security.c14n.implementations;
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer;
/**
* @author Sean Mullan
*/
public class Canonicalizer11_OmitComments extends Canonicalizer11 {
public Canonicalizer11_OmitComments() {
super(false);
}
public final String engineGetURI() {
return Canonicalizer.ALGO_ID_C14N11_OMIT_COMMENTS;
}
public final boolean engineGetIncludeComments() {
return false;
}
}
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2008 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 com.sun.org.apache.xml.internal.security.c14n.implementations;
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer;
/**
* @author Sean Mullan
*/
public class Canonicalizer11_WithComments extends Canonicalizer11 {
public Canonicalizer11_WithComments() {
super(true);
}
public final String engineGetURI() {
return Canonicalizer.ALGO_ID_C14N11_WITH_COMMENTS;
}
public final boolean engineGetIncludeComments() {
return true;
}
}
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
* reserved comment block * reserved comment block
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /*
* Copyright 1999-2004 The Apache Software Foundation. * Copyright 1999-2004 The Apache Software Foundation.
* *
...@@ -23,20 +22,30 @@ package com.sun.org.apache.xml.internal.security.c14n.implementations; ...@@ -23,20 +22,30 @@ package com.sun.org.apache.xml.internal.security.c14n.implementations;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.TreeSet; import java.util.TreeSet;
import javax.xml.parsers.ParserConfigurationException;
import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException; import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException;
import com.sun.org.apache.xml.internal.security.c14n.helper.C14nHelper; import com.sun.org.apache.xml.internal.security.c14n.helper.C14nHelper;
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput;
import com.sun.org.apache.xml.internal.security.utils.Constants; import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
import org.w3c.dom.Attr; import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap; import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.xml.sax.SAXException;
/** /**
...@@ -44,12 +53,91 @@ import org.w3c.dom.Node; ...@@ -44,12 +53,91 @@ import org.w3c.dom.Node;
* XML Version 1.0</A>, a W3C Recommendation from 15 March 2001. * XML Version 1.0</A>, a W3C Recommendation from 15 March 2001.
* *
* @author Christian Geuer-Pollmann <geuerp@apache.org> * @author Christian Geuer-Pollmann <geuerp@apache.org>
* @version $Revision: 1.5 $
*/ */
public abstract class Canonicalizer20010315 extends CanonicalizerBase { public abstract class Canonicalizer20010315 extends CanonicalizerBase {
boolean firstCall=true; boolean firstCall=true;
final SortedSet result= new TreeSet(COMPARE); final SortedSet result= new TreeSet(COMPARE);
static final String XMLNS_URI=Constants.NamespaceSpecNS; static final String XMLNS_URI=Constants.NamespaceSpecNS;
static final String XML_LANG_URI=Constants.XML_LANG_SPACE_SpecNS; static final String XML_LANG_URI=Constants.XML_LANG_SPACE_SpecNS;
static class XmlAttrStack {
int currentLevel=0;
int lastlevel=0;
XmlsStackElement cur;
static class XmlsStackElement {
int level;
boolean rendered=false;
List nodes=new ArrayList();
};
List levels=new ArrayList();
void push(int level) {
currentLevel=level;
if (currentLevel==-1)
return;
cur=null;
while (lastlevel>=currentLevel) {
levels.remove(levels.size()-1);
if (levels.size()==0) {
lastlevel=0;
return;
}
lastlevel=((XmlsStackElement)levels.get(levels.size()-1)).level;
}
}
void addXmlnsAttr(Attr n) {
if (cur==null) {
cur=new XmlsStackElement();
cur.level=currentLevel;
levels.add(cur);
lastlevel=currentLevel;
}
cur.nodes.add(n);
}
void getXmlnsAttr(Collection col) {
int size=levels.size()-1;
if (cur==null) {
cur=new XmlsStackElement();
cur.level=currentLevel;
lastlevel=currentLevel;
levels.add(cur);
}
boolean parentRendered=false;
XmlsStackElement e=null;
if (size==-1) {
parentRendered=true;
} else {
e=(XmlsStackElement)levels.get(size);
if (e.rendered && e.level+1==currentLevel)
parentRendered=true;
}
if (parentRendered) {
col.addAll(cur.nodes);
cur.rendered=true;
return;
}
Map loa = new HashMap();
for (;size>=0;size--) {
e=(XmlsStackElement)levels.get(size);
Iterator it=e.nodes.iterator();
while (it.hasNext()) {
Attr n=(Attr)it.next();
if (!loa.containsKey(n.getName()))
loa.put(n.getName(),n);
}
//if (e.rendered)
//break;
};
//cur.nodes.clear();
//cur.nodes.addAll(loa.values());
cur.rendered=true;
col.addAll(loa.values());
}
}
XmlAttrStack xmlattrStack=new XmlAttrStack();
/** /**
* Constructor Canonicalizer20010315 * Constructor Canonicalizer20010315
* *
...@@ -86,16 +174,16 @@ public abstract class Canonicalizer20010315 extends CanonicalizerBase { ...@@ -86,16 +174,16 @@ public abstract class Canonicalizer20010315 extends CanonicalizerBase {
for (int i = 0; i < attrsLength; i++) { for (int i = 0; i < attrsLength; i++) {
Attr N = (Attr) attrs.item(i); Attr N = (Attr) attrs.item(i);
String NName=N.getLocalName();
String NValue=N.getValue();
String NUri =N.getNamespaceURI(); String NUri =N.getNamespaceURI();
if (!XMLNS_URI.equals(NUri)) { if (XMLNS_URI!=NUri) {
//It's not a namespace attr node. Add to the result and continue. //It's not a namespace attr node. Add to the result and continue.
result.add(N); result.add(N);
continue; continue;
} }
String NName=N.getLocalName();
String NValue=N.getValue();
if (XML.equals(NName) if (XML.equals(NName)
&& XML_LANG_URI.equals(NValue)) { && XML_LANG_URI.equals(NValue)) {
//The default mapping for xml must not be output. //The default mapping for xml must not be output.
...@@ -120,64 +208,13 @@ public abstract class Canonicalizer20010315 extends CanonicalizerBase { ...@@ -120,64 +208,13 @@ public abstract class Canonicalizer20010315 extends CanonicalizerBase {
//Obtain all the namespaces defined in the parents, and added to the output. //Obtain all the namespaces defined in the parents, and added to the output.
ns.getUnrenderedNodes(result); ns.getUnrenderedNodes(result);
//output the attributes in the xml namespace. //output the attributes in the xml namespace.
addXmlAttributesSubtree(E, result); xmlattrStack.getXmlnsAttr(result);
firstCall=false; firstCall=false;
} }
return result.iterator(); return result.iterator();
} }
/**
* Float the xml:* attributes of the parent nodes to the root node of c14n
* @param E the root node.
* @param result the xml:* attributes to output.
*/
private void addXmlAttributesSubtree(Element E, SortedSet result) {
// E is in the node-set
Node parent = E.getParentNode();
Map loa = new HashMap();
if ((parent != null) && (parent.getNodeType() == Node.ELEMENT_NODE)) {
// parent element is not in node set
for (Node ancestor = parent;
(ancestor != null)
&& (ancestor.getNodeType() == Node.ELEMENT_NODE);
ancestor = ancestor.getParentNode()) {
Element el=((Element) ancestor);
if (!el.hasAttributes()) {
continue;
}
// for all ancestor elements
NamedNodeMap ancestorAttrs = el.getAttributes();
for (int i = 0; i < ancestorAttrs.getLength(); i++) {
// for all attributes in the ancestor element
Attr currentAncestorAttr = (Attr) ancestorAttrs.item(i);
if (XML_LANG_URI.equals(
currentAncestorAttr.getNamespaceURI())) {
// do we have an xml:* ?
if (!E.hasAttributeNS(
XML_LANG_URI,
currentAncestorAttr.getLocalName())) {
// the xml:* attr is not in E
if (!loa.containsKey(currentAncestorAttr.getName())) {
loa.put(currentAncestorAttr.getName(),
currentAncestorAttr);
}
}
}
}
}
}
result.addAll( loa.values());
}
/** /**
* Returns the Attr[]s to be outputted for the given element. * Returns the Attr[]s to be outputted for the given element.
* <br> * <br>
...@@ -192,7 +229,8 @@ public abstract class Canonicalizer20010315 extends CanonicalizerBase { ...@@ -192,7 +229,8 @@ public abstract class Canonicalizer20010315 extends CanonicalizerBase {
*/ */
Iterator handleAttributes(Element E, NameSpaceSymbTable ns ) throws CanonicalizationException { Iterator handleAttributes(Element E, NameSpaceSymbTable ns ) throws CanonicalizationException {
// result will contain the attrs which have to be outputted // result will contain the attrs which have to be outputted
boolean isRealVisible=isVisible(E); xmlattrStack.push(ns.getLevel());
boolean isRealVisible=isVisibleDO(E,ns.getLevel())==1;
NamedNodeMap attrs = null; NamedNodeMap attrs = null;
int attrsLength = 0; int attrsLength = 0;
if (E.hasAttributes()) { if (E.hasAttributes()) {
...@@ -204,16 +242,15 @@ public abstract class Canonicalizer20010315 extends CanonicalizerBase { ...@@ -204,16 +242,15 @@ public abstract class Canonicalizer20010315 extends CanonicalizerBase {
SortedSet result = this.result; SortedSet result = this.result;
result.clear(); result.clear();
for (int i = 0; i < attrsLength; i++) { for (int i = 0; i < attrsLength; i++) {
Attr N = (Attr) attrs.item(i); Attr N = (Attr) attrs.item(i);
String NName=N.getLocalName();
String NValue=N.getValue();
String NUri =N.getNamespaceURI(); String NUri =N.getNamespaceURI();
if (!XMLNS_URI.equals(NUri)) { if (XMLNS_URI!=NUri) {
//A non namespace definition node. //A non namespace definition node.
if (isRealVisible){ if (XML_LANG_URI==NUri) {
xmlattrStack.addXmlnsAttr(N);
} else if (isRealVisible){
//The node is visible add the attribute to the list of output attributes. //The node is visible add the attribute to the list of output attributes.
result.add(N); result.add(N);
} }
...@@ -221,7 +258,8 @@ public abstract class Canonicalizer20010315 extends CanonicalizerBase { ...@@ -221,7 +258,8 @@ public abstract class Canonicalizer20010315 extends CanonicalizerBase {
continue; continue;
} }
String NName=N.getLocalName();
String NValue=N.getValue();
if ("xml".equals(NName) if ("xml".equals(NName)
&& XML_LANG_URI.equals(NValue)) { && XML_LANG_URI.equals(NValue)) {
/* except omit namespace node with local name xml, which defines /* except omit namespace node with local name xml, which defines
...@@ -232,8 +270,12 @@ public abstract class Canonicalizer20010315 extends CanonicalizerBase { ...@@ -232,8 +270,12 @@ public abstract class Canonicalizer20010315 extends CanonicalizerBase {
//add the prefix binding to the ns symb table. //add the prefix binding to the ns symb table.
//ns.addInclusiveMapping(NName,NValue,N,isRealVisible); //ns.addInclusiveMapping(NName,NValue,N,isRealVisible);
if (isVisible(N)) { if (isVisible(N)) {
if (!isRealVisible && ns.removeMappingIfRender(NName)) {
continue;
}
//The xpath select this node output it if needed. //The xpath select this node output it if needed.
Node n=ns.addMappingAndRenderXNodeSet(NName,NValue,N,isRealVisible); //Node n=ns.addMappingAndRenderXNodeSet(NName,NValue,N,isRealVisible);
Node n=ns.addMappingAndRender(NName,NValue,N);
if (n!=null) { if (n!=null) {
result.add(n); result.add(n);
if (C14nHelper.namespaceIsRelative(N)) { if (C14nHelper.namespaceIsRelative(N)) {
...@@ -242,6 +284,12 @@ public abstract class Canonicalizer20010315 extends CanonicalizerBase { ...@@ -242,6 +284,12 @@ public abstract class Canonicalizer20010315 extends CanonicalizerBase {
"c14n.Canonicalizer.RelativeNamespace", exArgs); "c14n.Canonicalizer.RelativeNamespace", exArgs);
} }
} }
} else {
if (isRealVisible && NName!=XMLNS) {
ns.removeMapping(NName);
} else {
ns.addMapping(NName,NValue,N);
}
} }
} }
if (isRealVisible) { if (isRealVisible) {
...@@ -254,84 +302,21 @@ public abstract class Canonicalizer20010315 extends CanonicalizerBase { ...@@ -254,84 +302,21 @@ public abstract class Canonicalizer20010315 extends CanonicalizerBase {
} else if ( !isVisible(xmlns)) { } else if ( !isVisible(xmlns)) {
//There is a definition but the xmlns is not selected by the xpath. //There is a definition but the xmlns is not selected by the xpath.
//then xmlns="" //then xmlns=""
n=ns.addMappingAndRenderXNodeSet(XMLNS,"",nullNode,true); n=ns.addMappingAndRender(XMLNS,"",nullNode);
} }
//output the xmlns def if needed. //output the xmlns def if needed.
if (n!=null) { if (n!=null) {
result.add(n); result.add(n);
} }
//Float all xml:* attributes of the unselected parent elements to this one. //Float all xml:* attributes of the unselected parent elements to this one.
addXmlAttributes(E,result); //addXmlAttributes(E,result);
} xmlattrStack.getXmlnsAttr(result);
ns.getUnrenderedNodes(result);
return result.iterator();
}
/**
* Float the xml:* attributes of the unselected parent nodes to the ciurrent node.
* @param E
* @param result
*/
private void addXmlAttributes(Element E, SortedSet result) {
/* The processing of an element node E MUST be modified slightly when an
* XPath node-set is given as input and the element's parent is omitted
* from the node-set. The method for processing the attribute axis of an
* element E in the node-set is enhanced. All element nodes along E's
* ancestor axis are examined for nearest occurrences of attributes in
* the xml namespace, such as xml:lang and xml:space (whether or not they
* are in the node-set). From this list of attributes, remove any that are
* in E's attribute axis (whether or not they are in the node-set). Then,
* lexicographically merge this attribute list with the nodes of E's
* attribute axis that are in the node-set. The result of visiting the
* attribute axis is computed by processing the attribute nodes in this
* merged attribute list.
*/
// E is in the node-set
Node parent = E.getParentNode();
Map loa = new HashMap();
if ((parent != null) && (parent.getNodeType() == Node.ELEMENT_NODE)
&&!isVisible(parent)) {
// parent element is not in node set
for (Node ancestor = parent;
(ancestor != null)
&& (ancestor.getNodeType() == Node.ELEMENT_NODE);
ancestor = ancestor.getParentNode()) {
Element el=((Element) ancestor);
if (!el.hasAttributes()) {
continue;
} }
// for all ancestor elements
NamedNodeMap ancestorAttrs =el.getAttributes();
for (int i = 0; i < ancestorAttrs.getLength(); i++) {
// for all attributes in the ancestor element
Attr currentAncestorAttr = (Attr) ancestorAttrs.item(i);
if (XML_LANG_URI.equals(
currentAncestorAttr.getNamespaceURI())) {
// do we have an xml:* ?
if (!E.hasAttributeNS(
XML_LANG_URI,
currentAncestorAttr.getLocalName())) {
// the xml:* attr is not in E return result.iterator();
if (!loa.containsKey(currentAncestorAttr.getName())) {
loa.put(currentAncestorAttr.getName(),
currentAncestorAttr);
}
}
}
}
}
} }
result.addAll(loa.values());
}
/** /**
* Always throws a CanonicalizationException because this is inclusive c14n. * Always throws a CanonicalizationException because this is inclusive c14n.
* *
...@@ -363,4 +348,43 @@ public abstract class Canonicalizer20010315 extends CanonicalizerBase { ...@@ -363,4 +348,43 @@ public abstract class Canonicalizer20010315 extends CanonicalizerBase {
throw new CanonicalizationException( throw new CanonicalizationException(
"c14n.Canonicalizer.UnsupportedOperation"); "c14n.Canonicalizer.UnsupportedOperation");
} }
void circumventBugIfNeeded(XMLSignatureInput input) throws CanonicalizationException, ParserConfigurationException, IOException, SAXException {
if (!input.isNeedsToBeExpanded())
return;
Document doc = null;
if (input.getSubNode() != null) {
doc=XMLUtils.getOwnerDocument(input.getSubNode());
} else {
doc=XMLUtils.getOwnerDocument(input.getNodeSet());
}
XMLUtils.circumventBug2650(doc);
}
void handleParent(Element e, NameSpaceSymbTable ns) {
if (!e.hasAttributes()) {
return;
}
xmlattrStack.push(-1);
NamedNodeMap attrs = e.getAttributes();
int attrsLength = attrs.getLength();
for (int i = 0; i < attrsLength; i++) {
Attr N = (Attr) attrs.item(i);
if (Constants.NamespaceSpecNS!=N.getNamespaceURI()) {
//Not a namespace definition, ignore.
if (XML_LANG_URI==N.getNamespaceURI()) {
xmlattrStack.addXmlnsAttr(N);
}
continue;
}
String NName=N.getLocalName();
String NValue=N.getNodeValue();
if (XML.equals(NName)
&& Constants.XML_LANG_SPACE_SpecNS.equals(NValue)) {
continue;
}
ns.addMapping(NName,NValue,N);
}
}
} }
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
* reserved comment block * reserved comment block
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /*
* Copyright 1999-2004 The Apache Software Foundation. * Copyright 1999-2004 The Apache Software Foundation.
* *
...@@ -21,20 +20,26 @@ ...@@ -21,20 +20,26 @@
*/ */
package com.sun.org.apache.xml.internal.security.c14n.implementations; package com.sun.org.apache.xml.internal.security.c14n.implementations;
import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.TreeSet; import java.util.TreeSet;
import javax.xml.parsers.ParserConfigurationException;
import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException; import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException;
import com.sun.org.apache.xml.internal.security.c14n.helper.C14nHelper; import com.sun.org.apache.xml.internal.security.c14n.helper.C14nHelper;
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput; import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput;
import com.sun.org.apache.xml.internal.security.transforms.params.InclusiveNamespaces; import com.sun.org.apache.xml.internal.security.transforms.params.InclusiveNamespaces;
import com.sun.org.apache.xml.internal.security.utils.Constants; import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
import org.w3c.dom.Attr; import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap; import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.xml.sax.SAXException;
/** /**
* Implements &quot; <A * Implements &quot; <A
* HREF="http://www.w3.org/TR/2002/REC-xml-exc-c14n-20020718/">Exclusive XML * HREF="http://www.w3.org/TR/2002/REC-xml-exc-c14n-20020718/">Exclusive XML
...@@ -47,6 +52,7 @@ import org.w3c.dom.Node; ...@@ -47,6 +52,7 @@ import org.w3c.dom.Node;
* <i>THIS </i> implementation is a complete rewrite of the algorithm. * <i>THIS </i> implementation is a complete rewrite of the algorithm.
* *
* @author Christian Geuer-Pollmann <geuerp@apache.org> * @author Christian Geuer-Pollmann <geuerp@apache.org>
* @version $Revision: 1.5 $
* @see <a href="http://www.w3.org/TR/2002/REC-xml-exc-c14n-20020718/ Exclusive#"> * @see <a href="http://www.w3.org/TR/2002/REC-xml-exc-c14n-20020718/ Exclusive#">
* XML Canonicalization, Version 1.0</a> * XML Canonicalization, Version 1.0</a>
*/ */
...@@ -55,7 +61,7 @@ public abstract class Canonicalizer20010315Excl extends CanonicalizerBase { ...@@ -55,7 +61,7 @@ public abstract class Canonicalizer20010315Excl extends CanonicalizerBase {
* This Set contains the names (Strings like "xmlns" or "xmlns:foo") of * This Set contains the names (Strings like "xmlns" or "xmlns:foo") of
* the inclusive namespaces. * the inclusive namespaces.
*/ */
TreeSet _inclusiveNSSet = null; TreeSet _inclusiveNSSet = new TreeSet();
static final String XMLNS_URI=Constants.NamespaceSpecNS; static final String XMLNS_URI=Constants.NamespaceSpecNS;
final SortedSet result = new TreeSet(COMPARE); final SortedSet result = new TreeSet(COMPARE);
/** /**
...@@ -143,10 +149,8 @@ public abstract class Canonicalizer20010315Excl extends CanonicalizerBase { ...@@ -143,10 +149,8 @@ public abstract class Canonicalizer20010315Excl extends CanonicalizerBase {
for (int i = 0; i < attrsLength; i++) { for (int i = 0; i < attrsLength; i++) {
Attr N = (Attr) attrs.item(i); Attr N = (Attr) attrs.item(i);
String NName=N.getLocalName();
String NNodeValue=N.getNodeValue();
if (!XMLNS_URI.equals(N.getNamespaceURI())) { if (XMLNS_URI!=N.getNamespaceURI()) {
//Not a namespace definition. //Not a namespace definition.
//The Element is output element, add his prefix(if used) to visibyUtilized //The Element is output element, add his prefix(if used) to visibyUtilized
String prefix = N.getPrefix(); String prefix = N.getPrefix();
...@@ -157,6 +161,8 @@ public abstract class Canonicalizer20010315Excl extends CanonicalizerBase { ...@@ -157,6 +161,8 @@ public abstract class Canonicalizer20010315Excl extends CanonicalizerBase {
result.add(N); result.add(N);
continue; continue;
} }
String NName=N.getLocalName();
String NNodeValue=N.getNodeValue();
if (ns.addMapping(NName, NNodeValue,N)) { if (ns.addMapping(NName, NNodeValue,N)) {
//New definition check if it is relative. //New definition check if it is relative.
...@@ -168,17 +174,17 @@ public abstract class Canonicalizer20010315Excl extends CanonicalizerBase { ...@@ -168,17 +174,17 @@ public abstract class Canonicalizer20010315Excl extends CanonicalizerBase {
} }
} }
} }
String prefix;
if (E.getNamespaceURI() != null) { if (E.getNamespaceURI() != null) {
String prefix = E.getPrefix(); prefix = E.getPrefix();
if ((prefix == null) || (prefix.length() == 0)) { if ((prefix == null) || (prefix.length() == 0)) {
visiblyUtilized.add(XMLNS); prefix=XMLNS;
} else {
visiblyUtilized.add(prefix);
} }
} else { } else {
visiblyUtilized.add(XMLNS); prefix=XMLNS;
} }
visiblyUtilized.add(prefix);
//This can be optimezed by I don't have time //This can be optimezed by I don't have time
Iterator it=visiblyUtilized.iterator(); Iterator it=visiblyUtilized.iterator();
...@@ -211,12 +217,6 @@ public abstract class Canonicalizer20010315Excl extends CanonicalizerBase { ...@@ -211,12 +217,6 @@ public abstract class Canonicalizer20010315Excl extends CanonicalizerBase {
} }
/** @inheritDoc */
public byte[] engineCanonicalizeXPathNodeSet(Set xpathNodeSet
) throws CanonicalizationException {
return engineCanonicalizeXPathNodeSet(xpathNodeSet,"");
}
/** /**
* @inheritDoc * @inheritDoc
* @param E * @param E
...@@ -236,21 +236,20 @@ public abstract class Canonicalizer20010315Excl extends CanonicalizerBase { ...@@ -236,21 +236,20 @@ public abstract class Canonicalizer20010315Excl extends CanonicalizerBase {
//The prefix visibly utilized(in the attribute or in the name) in the element //The prefix visibly utilized(in the attribute or in the name) in the element
Set visiblyUtilized =null; Set visiblyUtilized =null;
//It's the output selected. //It's the output selected.
boolean isOutputElement = isVisible(E); boolean isOutputElement=isVisibleDO(E,ns.getLevel())==1;
if (isOutputElement) { if (isOutputElement) {
visiblyUtilized = (Set) this._inclusiveNSSet.clone(); visiblyUtilized = (Set) this._inclusiveNSSet.clone();
} }
for (int i = 0; i < attrsLength; i++) { for (int i = 0; i < attrsLength; i++) {
Attr N = (Attr) attrs.item(i); Attr N = (Attr) attrs.item(i);
String NName=N.getLocalName();
String NNodeValue=N.getNodeValue();
if (XMLNS_URI!=N.getNamespaceURI()) {
if ( !isVisible(N) ) { if ( !isVisible(N) ) {
//The node is not in the nodeset(if there is a nodeset) //The node is not in the nodeset(if there is a nodeset)
continue; continue;
} }
if (!XMLNS_URI.equals(N.getNamespaceURI())) {
//Not a namespace definition. //Not a namespace definition.
if (isOutputElement) { if (isOutputElement) {
//The Element is output element, add his prefix(if used) to visibyUtilized //The Element is output element, add his prefix(if used) to visibyUtilized
...@@ -263,6 +262,25 @@ public abstract class Canonicalizer20010315Excl extends CanonicalizerBase { ...@@ -263,6 +262,25 @@ public abstract class Canonicalizer20010315Excl extends CanonicalizerBase {
} }
continue; continue;
} }
String NName=N.getLocalName();
if (isOutputElement && !isVisible(N) && NName!=XMLNS) {
ns.removeMappingIfNotRender(NName);
continue;
}
String NNodeValue=N.getNodeValue();
if (!isOutputElement && isVisible(N) && _inclusiveNSSet.contains(NName) && !ns.removeMappingIfRender(NName)) {
Node n=ns.addMappingAndRender(NName,NNodeValue,N);
if (n!=null) {
result.add(n);
if (C14nHelper.namespaceIsRelative(N)) {
Object exArgs[] = { E.getTagName(), NName, N.getNodeValue() };
throw new CanonicalizationException(
"c14n.Canonicalizer.RelativeNamespace", exArgs);
}
}
}
if (ns.addMapping(NName, NNodeValue,N)) { if (ns.addMapping(NName, NNodeValue,N)) {
...@@ -306,18 +324,20 @@ public abstract class Canonicalizer20010315Excl extends CanonicalizerBase { ...@@ -306,18 +324,20 @@ public abstract class Canonicalizer20010315Excl extends CanonicalizerBase {
} }
result.add(key); result.add(key);
} }
} else /*if (_circunvented)*/ {
Iterator it=this._inclusiveNSSet.iterator();
while (it.hasNext()) {
String s=(String)it.next();
Attr key=ns.getMappingWithoutRendered(s);
if (key==null) {
continue;
} }
result.add(key);
return result.iterator();
} }
void circumventBugIfNeeded(XMLSignatureInput input) throws CanonicalizationException, ParserConfigurationException, IOException, SAXException {
if (!input.isNeedsToBeExpanded() || _inclusiveNSSet.isEmpty())
return;
Document doc = null;
if (input.getSubNode() != null) {
doc=XMLUtils.getOwnerDocument(input.getSubNode());
} else {
doc=XMLUtils.getOwnerDocument(input.getNodeSet());
} }
return result.iterator(); XMLUtils.circumventBug2650(doc);
} }
} }
...@@ -28,6 +28,7 @@ import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer; ...@@ -28,6 +28,7 @@ import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer;
/** /**
* Class Canonicalizer20010315ExclWithComments * Class Canonicalizer20010315ExclWithComments
* *
* @version $Revision: 1.5 $
*/ */
public class Canonicalizer20010315ExclWithComments public class Canonicalizer20010315ExclWithComments
extends Canonicalizer20010315Excl { extends Canonicalizer20010315Excl {
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
* reserved comment block * reserved comment block
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /*
* Copyright 1999-2004 The Apache Software Foundation. * Copyright 1999-2004 The Apache Software Foundation.
* *
......
...@@ -20,16 +20,10 @@ ...@@ -20,16 +20,10 @@
*/ */
package com.sun.org.apache.xml.internal.security.c14n.implementations; package com.sun.org.apache.xml.internal.security.c14n.implementations;
import java.lang.reflect.Array;
import java.util.AbstractList;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import org.w3c.dom.Attr; import org.w3c.dom.Attr;
...@@ -46,21 +40,26 @@ import org.w3c.dom.Node; ...@@ -46,21 +40,26 @@ import org.w3c.dom.Node;
public class NameSpaceSymbTable { public class NameSpaceSymbTable {
/**The map betwen prefix-> entry table. */ /**The map betwen prefix-> entry table. */
SymbMap symb = new SymbMap(); SymbMap symb;
/**The level of nameSpaces (for Inclusive visibility).*/ /**The level of nameSpaces (for Inclusive visibility).*/
int nameSpaces=0; int nameSpaces=0;
/**The stacks for removing the definitions when doing pop.*/ /**The stacks for removing the definitions when doing pop.*/
List level = new ArrayList(); List level;
boolean cloned=true; boolean cloned=true;
static final String XMLNS="xmlns"; static final String XMLNS="xmlns";
final static SymbMap initialMap=new SymbMap();
static {
NameSpaceSymbEntry ne=new NameSpaceSymbEntry("",null,true,XMLNS);
ne.lastrendered="";
initialMap.put(XMLNS,ne);
}
/** /**
* Default constractor * Default constractor
**/ **/
public NameSpaceSymbTable() { public NameSpaceSymbTable() {
level = new ArrayList(10);
//Insert the default binding for xmlns. //Insert the default binding for xmlns.
NameSpaceSymbEntry ne=new NameSpaceSymbEntry("",null,true); symb=(SymbMap) initialMap.clone();
ne.lastrendered="";
symb.put(XMLNS,ne);
} }
/** /**
...@@ -75,8 +74,14 @@ public class NameSpaceSymbTable { ...@@ -75,8 +74,14 @@ public class NameSpaceSymbTable {
NameSpaceSymbEntry n=(NameSpaceSymbEntry)(it.next()); NameSpaceSymbEntry n=(NameSpaceSymbEntry)(it.next());
//put them rendered? //put them rendered?
if ((!n.rendered) && (n.n!=null)) { if ((!n.rendered) && (n.n!=null)) {
result.add(n.n); n=(NameSpaceSymbEntry) n.clone();
needsClone();
symb.put(n.prefix,n);
n.lastrendered=n.uri;
n.rendered=true; n.rendered=true;
result.add(n.n);
} }
} }
} }
...@@ -104,10 +109,6 @@ public class NameSpaceSymbTable { ...@@ -104,10 +109,6 @@ public class NameSpaceSymbTable {
**/ **/
public void push() { public void push() {
//Put the number of namespace definitions in the stack. //Put the number of namespace definitions in the stack.
/**if (cloned) {
Object ob[]= {symb,cloned ? symb : null};
level.add(ob);
} **/
level.add(null); level.add(null);
cloned=false; cloned=false;
} }
...@@ -134,8 +135,7 @@ public class NameSpaceSymbTable { ...@@ -134,8 +135,7 @@ public class NameSpaceSymbTable {
final void needsClone() { final void needsClone() {
if (!cloned) { if (!cloned) {
level.remove(level.size()-1); level.set(level.size()-1,symb);
level.add(symb);
symb=(SymbMap) symb.clone(); symb=(SymbMap) symb.clone();
cloned=true; cloned=true;
} }
...@@ -200,7 +200,7 @@ public class NameSpaceSymbTable { ...@@ -200,7 +200,7 @@ public class NameSpaceSymbTable {
return false; return false;
} }
//Creates and entry in the table for this new definition. //Creates and entry in the table for this new definition.
NameSpaceSymbEntry ne=new NameSpaceSymbEntry(uri,n,false); NameSpaceSymbEntry ne=new NameSpaceSymbEntry(uri,n,false,prefix);
needsClone(); needsClone();
symb.put(prefix, ne); symb.put(prefix, ne);
if (ob != null) { if (ob != null) {
...@@ -238,7 +238,7 @@ public class NameSpaceSymbTable { ...@@ -238,7 +238,7 @@ public class NameSpaceSymbTable {
return null; return null;
} }
NameSpaceSymbEntry ne=new NameSpaceSymbEntry(uri,n,true); NameSpaceSymbEntry ne=new NameSpaceSymbEntry(uri,n,true,prefix);
ne.lastrendered=uri; ne.lastrendered=uri;
needsClone(); needsClone();
symb.put(prefix, ne); symb.put(prefix, ne);
...@@ -251,53 +251,38 @@ public class NameSpaceSymbTable { ...@@ -251,53 +251,38 @@ public class NameSpaceSymbTable {
} }
return ne.n; return ne.n;
} }
/**
* Adds & gets(if needed) the attribute node that defines the binding for the prefix. public int getLevel() {
* Take on account if the rules of rendering in the inclusive c14n. // TODO Auto-generated method stub
* For inclusive c14n. return level.size();
* @param prefix the prefix to obtain the attribute. }
* @param outputNode the container element is an output element.
* @param uri the Uri of the definition public void removeMapping(String prefix) {
* @param n the attribute that have the definition
* @return null if there is no need to render the prefix. Otherwise the node of
* definition.
**/
public Node addMappingAndRenderXNodeSet(String prefix, String uri,Attr n,boolean outputNode) {
NameSpaceSymbEntry ob = symb.get(prefix); NameSpaceSymbEntry ob = symb.get(prefix);
int visibleNameSpaces=nameSpaces;
if ((ob!=null) && uri.equals(ob.uri)) { if (ob!=null) {
if (!ob.rendered) {
ob=(NameSpaceSymbEntry)ob.clone();
needsClone(); needsClone();
symb.put(prefix,ob); symb.put(prefix,null);
ob.rendered=true; }
ob.level=visibleNameSpaces;
return ob.n;
} }
ob=(NameSpaceSymbEntry)ob.clone();
public void removeMappingIfNotRender(String prefix) {
NameSpaceSymbEntry ob = symb.get(prefix);
if (ob!=null && !ob.rendered) {
needsClone(); needsClone();
symb.put(prefix,ob); symb.put(prefix,null);
if (outputNode && (((visibleNameSpaces-ob.level)<2) || XMLNS.equals(prefix)) ) {
ob.level=visibleNameSpaces;
return null; //Already rendered, just return nulll
} }
ob.level=visibleNameSpaces;
return ob.n;
} }
NameSpaceSymbEntry ne=new NameSpaceSymbEntry(uri,n,true); public boolean removeMappingIfRender(String prefix) {
ne.level=nameSpaces; NameSpaceSymbEntry ob = symb.get(prefix);
ne.rendered=true;
needsClone();
symb.put(prefix, ne);
if (ob != null) {
ne.lastrendered=ob.lastrendered;
if ((ob.lastrendered!=null)&& (ob.lastrendered.equals(uri))) { if (ob!=null && ob.rendered) {
ne.rendered=true; needsClone();
} symb.put(prefix,null);
} }
return ne.n; return false;
} }
} }
...@@ -305,10 +290,11 @@ public class NameSpaceSymbTable { ...@@ -305,10 +290,11 @@ public class NameSpaceSymbTable {
* The internal structure of NameSpaceSymbTable. * The internal structure of NameSpaceSymbTable.
**/ **/
class NameSpaceSymbEntry implements Cloneable { class NameSpaceSymbEntry implements Cloneable {
NameSpaceSymbEntry(String name,Attr n,boolean rendered) { NameSpaceSymbEntry(String name,Attr n,boolean rendered,String prefix) {
this.uri=name; this.uri=name;
this.rendered=rendered; this.rendered=rendered;
this.n=n; this.n=n;
this.prefix=prefix;
} }
/** @inheritDoc */ /** @inheritDoc */
public Object clone() { public Object clone() {
...@@ -320,6 +306,7 @@ class NameSpaceSymbEntry implements Cloneable { ...@@ -320,6 +306,7 @@ class NameSpaceSymbEntry implements Cloneable {
} }
/** The level where the definition was rendered(Only for inclusive) */ /** The level where the definition was rendered(Only for inclusive) */
int level=0; int level=0;
String prefix;
/**The URI that the prefix defines */ /**The URI that the prefix defines */
String uri; String uri;
/**The last output in the URI for this prefix (This for speed reason).*/ /**The last output in the URI for this prefix (This for speed reason).*/
...@@ -330,11 +317,14 @@ class NameSpaceSymbEntry implements Cloneable { ...@@ -330,11 +317,14 @@ class NameSpaceSymbEntry implements Cloneable {
Attr n; Attr n;
}; };
class SymbMap implements Cloneable{ class SymbMap implements Cloneable {
int free=23; int free=23;
NameSpaceSymbEntry[] entries=new NameSpaceSymbEntry[free]; NameSpaceSymbEntry[] entries;
String[] keys=new String[free]; String[] keys;
SymbMap() {
entries=new NameSpaceSymbEntry[free];
keys=new String[free];
}
void put(String key, NameSpaceSymbEntry value) { void put(String key, NameSpaceSymbEntry value) {
int index = index(key); int index = index(key);
Object oldKey = keys[index]; Object oldKey = keys[index];
...@@ -352,14 +342,13 @@ class SymbMap implements Cloneable{ ...@@ -352,14 +342,13 @@ class SymbMap implements Cloneable{
List entrySet() { List entrySet() {
List a=new ArrayList(); List a=new ArrayList();
for (int i=0;i<entries.length;i++) { for (int i=0;i<entries.length;i++) {
if ((entries[i]!=null) && !("".equals(entries[i]))) { if ((entries[i]!=null) && !("".equals(entries[i].uri))) {
a.add(entries[i]); a.add(entries[i]);
} }
} }
return a; return a;
} }
protected int index(Object obj) { protected int index(Object obj) {
Object[] set = keys; Object[] set = keys;
int length = set.length; int length = set.length;
...@@ -370,12 +359,14 @@ class SymbMap implements Cloneable{ ...@@ -370,12 +359,14 @@ class SymbMap implements Cloneable{
if (cur == null || (cur.equals( obj))) { if (cur == null || (cur.equals( obj))) {
return index; return index;
} }
length=length-1;
do { do {
index=index==length? 0:++index; index=index==length? 0:++index;
cur = set[index]; cur = set[index];
} while (cur != null && (!cur.equals(obj))); } while (cur != null && (!cur.equals(obj)));
return index; return index;
} }
/** /**
* rehashes the map to the new capacity. * rehashes the map to the new capacity.
* *
...@@ -398,11 +389,12 @@ class SymbMap implements Cloneable{ ...@@ -398,11 +389,12 @@ class SymbMap implements Cloneable{
} }
} }
} }
NameSpaceSymbEntry get(String key) { NameSpaceSymbEntry get(String key) {
return entries[index(key)]; return entries[index(key)];
} }
protected Object clone() { protected Object clone() {
// TODO Auto-generated method stub
try { try {
SymbMap copy=(SymbMap) super.clone(); SymbMap copy=(SymbMap) super.clone();
copy.entries=new NameSpaceSymbEntry[entries.length]; copy.entries=new NameSpaceSymbEntry[entries.length];
......
package com.sun.org.apache.xml.internal.security.c14n.implementations;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Map;
public class UtfHelpper {
final static void writeByte(final String str,final OutputStream out,Map cache) throws IOException {
byte []result=(byte[]) cache.get(str);
if (result==null) {
result=getStringInUtf8(str);
cache.put(str,result);
}
out.write(result);
}
final static void writeCharToUtf8(final char c,final OutputStream out) throws IOException{
if (c < 0x80) {
out.write(c);
return;
}
if ((c >= 0xD800 && c <= 0xDBFF) || (c >= 0xDC00 && c <= 0xDFFF) ){
//No Surrogates in sun java
out.write(0x3f);
return;
}
int bias;
int write;
char ch;
if (c > 0x07FF) {
ch=(char)(c>>>12);
write=0xE0;
if (ch>0) {
write |= ( ch & 0x0F);
}
out.write(write);
write=0x80;
bias=0x3F;
} else {
write=0xC0;
bias=0x1F;
}
ch=(char)(c>>>6);
if (ch>0) {
write|= (ch & bias);
}
out.write(write);
out.write(0x80 | ((c) & 0x3F));
}
final static void writeStringToUtf8(final String str,final OutputStream out) throws IOException{
final int length=str.length();
int i=0;
char c;
while (i<length) {
c=str.charAt(i++);
if (c < 0x80) {
out.write(c);
continue;
}
if ((c >= 0xD800 && c <= 0xDBFF) || (c >= 0xDC00 && c <= 0xDFFF) ){
//No Surrogates in sun java
out.write(0x3f);
continue;
}
char ch;
int bias;
int write;
if (c > 0x07FF) {
ch=(char)(c>>>12);
write=0xE0;
if (ch>0) {
write |= ( ch & 0x0F);
}
out.write(write);
write=0x80;
bias=0x3F;
} else {
write=0xC0;
bias=0x1F;
}
ch=(char)(c>>>6);
if (ch>0) {
write|= (ch & bias);
}
out.write(write);
out.write(0x80 | ((c) & 0x3F));
}
}
public final static byte[] getStringInUtf8(final String str) {
final int length=str.length();
boolean expanded=false;
byte []result=new byte[length];
int i=0;
int out=0;
char c;
while (i<length) {
c=str.charAt(i++);
if ( c < 0x80 ) {
result[out++]=(byte)c;
continue;
}
if ((c >= 0xD800 && c <= 0xDBFF) || (c >= 0xDC00 && c <= 0xDFFF) ){
//No Surrogates in sun java
result[out++]=0x3f;
continue;
}
if (!expanded) {
byte newResult[]=new byte[3*length];
System.arraycopy(result, 0, newResult, 0, out);
result=newResult;
expanded=true;
}
char ch;
int bias;
byte write;
if (c > 0x07FF) {
ch=(char)(c>>>12);
write=(byte)0xE0;
if (ch>0) {
write |= ( ch & 0x0F);
}
result[out++]=write;
write=(byte)0x80;
bias=0x3F;
} else {
write=(byte)0xC0;
bias=0x1F;
}
ch=(char)(c>>>6);
if (ch>0) {
write|= (ch & bias);
}
result[out++]=write;
result[out++]=(byte)(0x80 | ((c) & 0x3F));/**/
}
if (expanded) {
byte newResult[]=new byte[out];
System.arraycopy(result, 0, newResult, 0, out);
result=newResult;
}
return result;
}
}
...@@ -113,14 +113,13 @@ public class XMLCipherInput { ...@@ -113,14 +113,13 @@ public class XMLCipherInput {
* @return the decripted bytes * @return the decripted bytes
* @throws XMLEncryptionException * @throws XMLEncryptionException
*/ */
private byte[] getDecryptBytes() throws XMLEncryptionException { private byte[] getDecryptBytes() throws XMLEncryptionException {
String base64EncodedEncryptedOctets = null; String base64EncodedEncryptedOctets = null;
if (_cipherData.getDataType() == CipherData.REFERENCE_TYPE) { if (_cipherData.getDataType() == CipherData.REFERENCE_TYPE) {
// Fun time! // Fun time!
if (logger.isLoggable(java.util.logging.Level.FINE)) logger.log(java.util.logging.Level.FINE, "Found a reference type CipherData"); logger.log(java.util.logging.Level.FINE, "Found a reference type CipherData");
CipherReference cr = _cipherData.getCipherReference(); CipherReference cr = _cipherData.getCipherReference();
// Need to wrap the uri in an Attribute node so that we can // Need to wrap the uri in an Attribute node so that we can
...@@ -138,16 +137,15 @@ public class XMLCipherInput { ...@@ -138,16 +137,15 @@ public class XMLCipherInput {
} }
if (input != null) { if (input != null) {
if (logger.isLoggable(java.util.logging.Level.FINE)) logger.log(java.util.logging.Level.FINE, "Managed to resolve URI \"" + cr.getURI() + "\""); logger.log(java.util.logging.Level.FINE, "Managed to resolve URI \"" + cr.getURI() + "\"");
} } else {
else { logger.log(java.util.logging.Level.FINE, "Failed to resolve URI \"" + cr.getURI() + "\"");
if (logger.isLoggable(java.util.logging.Level.FINE)) logger.log(java.util.logging.Level.FINE, "Failed to resolve URI \"" + cr.getURI() + "\"");
} }
// Lets see if there are any transforms // Lets see if there are any transforms
Transforms transforms = cr.getTransforms(); Transforms transforms = cr.getTransforms();
if (transforms != null) { if (transforms != null) {
if (logger.isLoggable(java.util.logging.Level.FINE)) logger.log(java.util.logging.Level.FINE, "Have transforms in cipher reference"); logger.log(java.util.logging.Level.FINE, "Have transforms in cipher reference");
try { try {
com.sun.org.apache.xml.internal.security.transforms.Transforms dsTransforms = com.sun.org.apache.xml.internal.security.transforms.Transforms dsTransforms =
transforms.getDSTransforms(); transforms.getDSTransforms();
...@@ -159,8 +157,7 @@ public class XMLCipherInput { ...@@ -159,8 +157,7 @@ public class XMLCipherInput {
try { try {
return input.getBytes(); return input.getBytes();
} } catch (IOException ex) {
catch (IOException ex) {
throw new XMLEncryptionException("empty", ex); throw new XMLEncryptionException("empty", ex);
} catch (CanonicalizationException ex) { } catch (CanonicalizationException ex) {
throw new XMLEncryptionException("empty", ex); throw new XMLEncryptionException("empty", ex);
...@@ -168,16 +165,15 @@ public class XMLCipherInput { ...@@ -168,16 +165,15 @@ public class XMLCipherInput {
// retrieve the cipher text // retrieve the cipher text
} else if (_cipherData.getDataType() == CipherData.VALUE_TYPE) { } else if (_cipherData.getDataType() == CipherData.VALUE_TYPE) {
CipherValue cv = _cipherData.getCipherValue(); base64EncodedEncryptedOctets =
base64EncodedEncryptedOctets = new String(cv.getValue()); _cipherData.getCipherValue().getValue();
} else { } else {
throw new XMLEncryptionException("CipherData.getDataType() returned unexpected value"); throw new XMLEncryptionException("CipherData.getDataType() returned unexpected value");
} }
if (logger.isLoggable(java.util.logging.Level.FINE)) logger.log(java.util.logging.Level.FINE, "Encrypted octets:\n" + base64EncodedEncryptedOctets); logger.log(java.util.logging.Level.FINE, "Encrypted octets:\n" + base64EncodedEncryptedOctets);
byte[] encryptedBytes = null; byte[] encryptedBytes = null;
try { try {
encryptedBytes = Base64.decode(base64EncodedEncryptedOctets); encryptedBytes = Base64.decode(base64EncodedEncryptedOctets);
} catch (Base64DecodingException bde) { } catch (Base64DecodingException bde) {
...@@ -185,7 +181,5 @@ public class XMLCipherInput { ...@@ -185,7 +181,5 @@ public class XMLCipherInput {
} }
return (encryptedBytes); return (encryptedBytes);
} }
} }
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
* reserved comment block * reserved comment block
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /*
* Copyright 1999-2004 The Apache Software Foundation. * Copyright 1999-2004 The Apache Software Foundation.
* *
...@@ -28,7 +27,7 @@ import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; ...@@ -28,7 +27,7 @@ import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
/** /**
* *
* @author $Author: raul $ * @author $Author: mullan $
*/ */
public class ContentHandlerAlreadyRegisteredException public class ContentHandlerAlreadyRegisteredException
extends XMLSecurityException { extends XMLSecurityException {
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
* reserved comment block * reserved comment block
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /*
* Copyright 1999-2004 The Apache Software Foundation. * Copyright 1999-2004 The Apache Software Foundation.
* *
...@@ -36,7 +35,7 @@ import com.sun.org.apache.xml.internal.security.keys.content.X509Data; ...@@ -36,7 +35,7 @@ import com.sun.org.apache.xml.internal.security.keys.content.X509Data;
/** /**
* Utility class for for <CODE>com.sun.org.apache.xml.internal.security.keys</CODE> package. * Utility class for for <CODE>com.sun.org.apache.xml.internal.security.keys</CODE> package.
* *
* @author $Author: raul $ * @author $Author: mullan $
*/ */
public class KeyUtils { public class KeyUtils {
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
* reserved comment block * reserved comment block
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /*
* Copyright 1999-2004 The Apache Software Foundation. * Copyright 1999-2004 The Apache Software Foundation.
* *
...@@ -28,7 +27,7 @@ package com.sun.org.apache.xml.internal.security.keys.content; ...@@ -28,7 +27,7 @@ package com.sun.org.apache.xml.internal.security.keys.content;
/** /**
* Empty interface just to identify Elements that can be cildren of ds:KeyInfo. * Empty interface just to identify Elements that can be cildren of ds:KeyInfo.
* *
* @author $Author: blautenb $ * @author $Author: mullan $
*/ */
public interface KeyInfoContent { public interface KeyInfoContent {
} }
...@@ -20,25 +20,18 @@ ...@@ -20,25 +20,18 @@
*/ */
package com.sun.org.apache.xml.internal.security.keys.content; package com.sun.org.apache.xml.internal.security.keys.content;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
import com.sun.org.apache.xml.internal.security.utils.Constants; import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy; import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
/** /**
* *
* @author $Author: raul $ * @author $Author: mullan $
*/ */
public class KeyName extends SignatureElementProxy implements KeyInfoContent { public class KeyName extends SignatureElementProxy implements KeyInfoContent {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(KeyName.class.getName());
/** /**
* Constructor KeyName * Constructor KeyName
* *
......
...@@ -20,11 +20,8 @@ ...@@ -20,11 +20,8 @@
*/ */
package com.sun.org.apache.xml.internal.security.keys.content; package com.sun.org.apache.xml.internal.security.keys.content;
import java.security.PublicKey; import java.security.PublicKey;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
import com.sun.org.apache.xml.internal.security.keys.content.keyvalues.DSAKeyValue; import com.sun.org.apache.xml.internal.security.keys.content.keyvalues.DSAKeyValue;
import com.sun.org.apache.xml.internal.security.keys.content.keyvalues.RSAKeyValue; import com.sun.org.apache.xml.internal.security.keys.content.keyvalues.RSAKeyValue;
...@@ -34,22 +31,18 @@ import com.sun.org.apache.xml.internal.security.utils.XMLUtils; ...@@ -34,22 +31,18 @@ import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
/** /**
* The KeyValue element contains a single public key that may be useful in * The KeyValue element contains a single public key that may be useful in
* validating the signature. Structured formats for defining DSA (REQUIRED) * validating the signature. Structured formats for defining DSA (REQUIRED)
* and RSA (RECOMMENDED) public keys are defined in Signature Algorithms * and RSA (RECOMMENDED) public keys are defined in Signature Algorithms
* (section 6.4). The KeyValue element may include externally defined public * (section 6.4). The KeyValue element may include externally defined public
* keys values represented as PCDATA or element types from an external namespace. * keys values represented as PCDATA or element types from an external
* namespace.
* *
* @author $Author: vishal $ * @author $Author: mullan $
*/ */
public class KeyValue extends SignatureElementProxy implements KeyInfoContent { public class KeyValue extends SignatureElementProxy implements KeyInfoContent {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(KeyValue.class.getName());
/** /**
* Constructor KeyValue * Constructor KeyValue
* *
...@@ -140,29 +133,24 @@ public class KeyValue extends SignatureElementProxy implements KeyInfoContent { ...@@ -140,29 +133,24 @@ public class KeyValue extends SignatureElementProxy implements KeyInfoContent {
*/ */
public PublicKey getPublicKey() throws XMLSecurityException { public PublicKey getPublicKey() throws XMLSecurityException {
Element rsa = XMLUtils.selectDsNode
Element rsa = XMLUtils.selectDsNode(this._constructionElement.getFirstChild(), (this._constructionElement.getFirstChild(),
Constants._TAG_RSAKEYVALUE,0); Constants._TAG_RSAKEYVALUE,0);
if (rsa != null) { if (rsa != null) {
RSAKeyValue kv = new RSAKeyValue(rsa, RSAKeyValue kv = new RSAKeyValue(rsa, this._baseURI);
this._baseURI);
return kv.getPublicKey(); return kv.getPublicKey();
} }
Element dsa = XMLUtils.selectDsNode(this._constructionElement, Element dsa = XMLUtils.selectDsNode
(this._constructionElement.getFirstChild(),
Constants._TAG_DSAKEYVALUE,0); Constants._TAG_DSAKEYVALUE,0);
if (dsa != null) { if (dsa != null) {
DSAKeyValue kv = new DSAKeyValue(dsa, DSAKeyValue kv = new DSAKeyValue(dsa, this._baseURI);
this._baseURI);
return kv.getPublicKey(); return kv.getPublicKey();
} }
return null; return null;
} }
......
...@@ -20,25 +20,18 @@ ...@@ -20,25 +20,18 @@
*/ */
package com.sun.org.apache.xml.internal.security.keys.content; package com.sun.org.apache.xml.internal.security.keys.content;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
import com.sun.org.apache.xml.internal.security.utils.Constants; import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy; import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
/** /**
* *
* @author $Author: raul $ * @author $Author: mullan $
*/ */
public class MgmtData extends SignatureElementProxy implements KeyInfoContent { public class MgmtData extends SignatureElementProxy implements KeyInfoContent {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(MgmtData.class.getName());
/** /**
* Constructor MgmtData * Constructor MgmtData
* *
......
...@@ -20,25 +20,18 @@ ...@@ -20,25 +20,18 @@
*/ */
package com.sun.org.apache.xml.internal.security.keys.content; package com.sun.org.apache.xml.internal.security.keys.content;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
import com.sun.org.apache.xml.internal.security.utils.Constants; import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy; import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;
import org.w3c.dom.Element; import org.w3c.dom.Element;
/** /**
* *
* @author $Author: raul $ * @author $Author: mullan $
* $todo$ Implement * $todo$ Implement
*/ */
public class PGPData extends SignatureElementProxy implements KeyInfoContent { public class PGPData extends SignatureElementProxy implements KeyInfoContent {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(PGPData.class.getName());
/** /**
* Constructor PGPData * Constructor PGPData
* *
......
...@@ -20,9 +20,6 @@ ...@@ -20,9 +20,6 @@
*/ */
package com.sun.org.apache.xml.internal.security.keys.content; package com.sun.org.apache.xml.internal.security.keys.content;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException; import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException;
import com.sun.org.apache.xml.internal.security.transforms.Transforms; import com.sun.org.apache.xml.internal.security.transforms.Transforms;
...@@ -33,17 +30,13 @@ import org.w3c.dom.Attr; ...@@ -33,17 +30,13 @@ import org.w3c.dom.Attr;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
/** /**
* *
* @author $Author: raul $ * @author $Author: mullan $
*/ */
public class RetrievalMethod extends SignatureElementProxy public class RetrievalMethod extends SignatureElementProxy
implements KeyInfoContent { implements KeyInfoContent {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(RetrievalMethod.class.getName());
//J- //J-
/** DSA retrieval */ /** DSA retrieval */
public static final String TYPE_DSA = Constants.SignatureSpecNS + "DSAKeyValue"; public static final String TYPE_DSA = Constants.SignatureSpecNS + "DSAKeyValue";
...@@ -133,7 +126,7 @@ public class RetrievalMethod extends SignatureElementProxy ...@@ -133,7 +126,7 @@ public class RetrievalMethod extends SignatureElementProxy
try { try {
Element transformsElem = Element transformsElem =
XMLUtils.selectDsNode(this._constructionElement, XMLUtils.selectDsNode(this._constructionElement.getFirstChild(),
Constants Constants
._TAG_TRANSFORMS, 0); ._TAG_TRANSFORMS, 0);
......
...@@ -20,25 +20,18 @@ ...@@ -20,25 +20,18 @@
*/ */
package com.sun.org.apache.xml.internal.security.keys.content; package com.sun.org.apache.xml.internal.security.keys.content;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
import com.sun.org.apache.xml.internal.security.utils.Constants; import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy; import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;
import org.w3c.dom.Element; import org.w3c.dom.Element;
/** /**
* *
* @author $Author: raul $ * @author $Author: mullan $
* $todo$ implement * $todo$ implement
*/ */
public class SPKIData extends SignatureElementProxy implements KeyInfoContent { public class SPKIData extends SignatureElementProxy implements KeyInfoContent {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(SPKIData.class.getName());
/** /**
* Constructor SPKIData * Constructor SPKIData
* *
......
...@@ -41,7 +41,7 @@ import org.w3c.dom.Node; ...@@ -41,7 +41,7 @@ import org.w3c.dom.Node;
/** /**
* *
* @author $Author: raul $ * @author $Author: mullan $
*/ */
public class X509Data extends SignatureElementProxy implements KeyInfoContent { public class X509Data extends SignatureElementProxy implements KeyInfoContent {
...@@ -72,62 +72,19 @@ public class X509Data extends SignatureElementProxy implements KeyInfoContent { ...@@ -72,62 +72,19 @@ public class X509Data extends SignatureElementProxy implements KeyInfoContent {
throws XMLSecurityException { throws XMLSecurityException {
super(element, BaseURI); super(element, BaseURI);
boolean noElements=true;
Node sibling=this._constructionElement.getFirstChild(); Node sibling=this._constructionElement.getFirstChild();
while (sibling!=null) { while (sibling!=null) {
if (sibling.getNodeType()!=Node.ELEMENT_NODE) { if (sibling.getNodeType()!=Node.ELEMENT_NODE) {
sibling=sibling.getNextSibling(); sibling=sibling.getNextSibling();
continue; continue;
} }
noElements=false; return;
Element currentElem = (Element) sibling;
sibling=sibling.getNextSibling();
String localname = currentElem.getLocalName();
if (currentElem.getNamespaceURI().equals(Constants.SignatureSpecNS)) {
if (localname.equals(Constants._TAG_X509ISSUERSERIAL)) {
XMLX509IssuerSerial is = new XMLX509IssuerSerial(currentElem,
BaseURI);
this.add(is);
} else if (localname.equals(Constants._TAG_X509SKI)) {
XMLX509SKI ski = new XMLX509SKI(currentElem, BaseURI);
this.add(ski);
} else if (localname.equals(Constants._TAG_X509SUBJECTNAME)) {
XMLX509SubjectName sn = new XMLX509SubjectName(currentElem,
BaseURI);
this.add(sn);
} else if (localname.equals(Constants._TAG_X509CERTIFICATE)) {
XMLX509Certificate cert = new XMLX509Certificate(currentElem,
BaseURI);
this.add(cert);
} else if (localname.equals(Constants._TAG_X509CRL)) {
XMLX509CRL crl = new XMLX509CRL(currentElem, BaseURI);
this.add(crl);
} else {
log.log(java.util.logging.Level.WARNING, "Found a " + currentElem.getTagName() + " element in "
+ Constants._TAG_X509DATA);
this.addUnknownElement(currentElem);
}
} else {
log.log(java.util.logging.Level.WARNING, "Found a " + currentElem.getTagName() + " element in "
+ Constants._TAG_X509DATA);
this.addUnknownElement(currentElem);
} }
} /* No Elements found */
if (noElements) {
Object exArgs[] = { "Elements", Constants._TAG_X509DATA }; Object exArgs[] = { "Elements", Constants._TAG_X509DATA };
throw new XMLSecurityException("xml.WrongContent", exArgs); throw new XMLSecurityException("xml.WrongContent", exArgs);
} }
}
/** /**
* Method addIssuerSerial * Method addIssuerSerial
* *
...@@ -169,12 +126,10 @@ public class X509Data extends SignatureElementProxy implements KeyInfoContent { ...@@ -169,12 +126,10 @@ public class X509Data extends SignatureElementProxy implements KeyInfoContent {
*/ */
public void add(XMLX509IssuerSerial xmlX509IssuerSerial) { public void add(XMLX509IssuerSerial xmlX509IssuerSerial) {
if (this._state == MODE_SIGN) {
this._constructionElement this._constructionElement
.appendChild(xmlX509IssuerSerial.getElement()); .appendChild(xmlX509IssuerSerial.getElement());
XMLUtils.addReturnToElement(this._constructionElement); XMLUtils.addReturnToElement(this._constructionElement);
} }
}
/** /**
* Method addSKI * Method addSKI
...@@ -202,12 +157,9 @@ public class X509Data extends SignatureElementProxy implements KeyInfoContent { ...@@ -202,12 +157,9 @@ public class X509Data extends SignatureElementProxy implements KeyInfoContent {
* @param xmlX509SKI * @param xmlX509SKI
*/ */
public void add(XMLX509SKI xmlX509SKI) { public void add(XMLX509SKI xmlX509SKI) {
if (this._state == MODE_SIGN) {
this._constructionElement.appendChild(xmlX509SKI.getElement()); this._constructionElement.appendChild(xmlX509SKI.getElement());
XMLUtils.addReturnToElement(this._constructionElement); XMLUtils.addReturnToElement(this._constructionElement);
} }
}
/** /**
* Method addSubjectName * Method addSubjectName
...@@ -233,12 +185,9 @@ public class X509Data extends SignatureElementProxy implements KeyInfoContent { ...@@ -233,12 +185,9 @@ public class X509Data extends SignatureElementProxy implements KeyInfoContent {
* @param xmlX509SubjectName * @param xmlX509SubjectName
*/ */
public void add(XMLX509SubjectName xmlX509SubjectName) { public void add(XMLX509SubjectName xmlX509SubjectName) {
if (this._state == MODE_SIGN) {
this._constructionElement.appendChild(xmlX509SubjectName.getElement()); this._constructionElement.appendChild(xmlX509SubjectName.getElement());
XMLUtils.addReturnToElement(this._constructionElement); XMLUtils.addReturnToElement(this._constructionElement);
} }
}
/** /**
* Method addCertificate * Method addCertificate
...@@ -266,12 +215,9 @@ public class X509Data extends SignatureElementProxy implements KeyInfoContent { ...@@ -266,12 +215,9 @@ public class X509Data extends SignatureElementProxy implements KeyInfoContent {
* @param xmlX509Certificate * @param xmlX509Certificate
*/ */
public void add(XMLX509Certificate xmlX509Certificate) { public void add(XMLX509Certificate xmlX509Certificate) {
if (this._state == MODE_SIGN) {
this._constructionElement.appendChild(xmlX509Certificate.getElement()); this._constructionElement.appendChild(xmlX509Certificate.getElement());
XMLUtils.addReturnToElement(this._constructionElement); XMLUtils.addReturnToElement(this._constructionElement);
} }
}
/** /**
* Method addCRL * Method addCRL
...@@ -288,12 +234,9 @@ public class X509Data extends SignatureElementProxy implements KeyInfoContent { ...@@ -288,12 +234,9 @@ public class X509Data extends SignatureElementProxy implements KeyInfoContent {
* @param xmlX509CRL * @param xmlX509CRL
*/ */
public void add(XMLX509CRL xmlX509CRL) { public void add(XMLX509CRL xmlX509CRL) {
if (this._state == MODE_SIGN) {
this._constructionElement.appendChild(xmlX509CRL.getElement()); this._constructionElement.appendChild(xmlX509CRL.getElement());
XMLUtils.addReturnToElement(this._constructionElement); XMLUtils.addReturnToElement(this._constructionElement);
} }
}
/** /**
* Method addUnknownElement * Method addUnknownElement
...@@ -301,12 +244,9 @@ public class X509Data extends SignatureElementProxy implements KeyInfoContent { ...@@ -301,12 +244,9 @@ public class X509Data extends SignatureElementProxy implements KeyInfoContent {
* @param element * @param element
*/ */
public void addUnknownElement(Element element) { public void addUnknownElement(Element element) {
if (this._state == MODE_SIGN) {
this._constructionElement.appendChild(element); this._constructionElement.appendChild(element);
XMLUtils.addReturnToElement(this._constructionElement); XMLUtils.addReturnToElement(this._constructionElement);
} }
}
/** /**
* Method lengthIssuerSerial * Method lengthIssuerSerial
...@@ -479,7 +419,7 @@ public class X509Data extends SignatureElementProxy implements KeyInfoContent { ...@@ -479,7 +419,7 @@ public class X509Data extends SignatureElementProxy implements KeyInfoContent {
* TODO implement * TODO implement
**/ **/
public Element itemUnknownElement(int i) { public Element itemUnknownElement(int i) {
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "itemUnknownElement not implemented:"+i); log.log(java.util.logging.Level.FINE, "itemUnknownElement not implemented:"+i);
return null; return null;
} }
......
...@@ -20,8 +20,6 @@ ...@@ -20,8 +20,6 @@
*/ */
package com.sun.org.apache.xml.internal.security.keys.content.keyvalues; package com.sun.org.apache.xml.internal.security.keys.content.keyvalues;
import java.math.BigInteger; import java.math.BigInteger;
import java.security.Key; import java.security.Key;
import java.security.KeyFactory; import java.security.KeyFactory;
...@@ -39,18 +37,13 @@ import com.sun.org.apache.xml.internal.security.utils.XMLUtils; ...@@ -39,18 +37,13 @@ import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
/** /**
* *
* @author $Author: raul $ * @author $Author: mullan $
*/ */
public class DSAKeyValue extends SignatureElementProxy public class DSAKeyValue extends SignatureElementProxy
implements KeyValueContent { implements KeyValueContent {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(DSAKeyValue.class.getName());
/** /**
* Constructor DSAKeyValue * Constructor DSAKeyValue
* *
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
* reserved comment block * reserved comment block
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /*
* Copyright 1999-2004 The Apache Software Foundation. * Copyright 1999-2004 The Apache Software Foundation.
* *
...@@ -32,7 +31,7 @@ import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; ...@@ -32,7 +31,7 @@ import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
* *
* *
* *
* @author $Author: raul $ * @author $Author: mullan $
* *
*/ */
public interface KeyValueContent { public interface KeyValueContent {
......
...@@ -20,8 +20,6 @@ ...@@ -20,8 +20,6 @@
*/ */
package com.sun.org.apache.xml.internal.security.keys.content.keyvalues; package com.sun.org.apache.xml.internal.security.keys.content.keyvalues;
import java.math.BigInteger; import java.math.BigInteger;
import java.security.Key; import java.security.Key;
import java.security.KeyFactory; import java.security.KeyFactory;
...@@ -39,19 +37,13 @@ import com.sun.org.apache.xml.internal.security.utils.XMLUtils; ...@@ -39,19 +37,13 @@ import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
/** /**
* *
* @author $Author: raul $ * @author $Author: mullan $
*/ */
public class RSAKeyValue extends SignatureElementProxy public class RSAKeyValue extends SignatureElementProxy
implements KeyValueContent { implements KeyValueContent {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(
RSAKeyValue.class.getName());
/** /**
* Constructor RSAKeyValue * Constructor RSAKeyValue
* *
......
...@@ -20,30 +20,20 @@ ...@@ -20,30 +20,20 @@
*/ */
package com.sun.org.apache.xml.internal.security.keys.content.x509; package com.sun.org.apache.xml.internal.security.keys.content.x509;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
import com.sun.org.apache.xml.internal.security.utils.Constants; import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy; import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
/** /**
* *
* * @author $Author: mullan $
*
*
* @author $Author: raul $
* *
*/ */
public class XMLX509CRL extends SignatureElementProxy public class XMLX509CRL extends SignatureElementProxy
implements XMLX509DataContent { implements XMLX509DataContent {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(XMLX509CRL.class.getName());
/** /**
* Constructor XMLX509CRL * Constructor XMLX509CRL
* *
......
...@@ -20,8 +20,6 @@ ...@@ -20,8 +20,6 @@
*/ */
package com.sun.org.apache.xml.internal.security.keys.content.x509; package com.sun.org.apache.xml.internal.security.keys.content.x509;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.security.PublicKey; import java.security.PublicKey;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
...@@ -34,18 +32,13 @@ import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy; ...@@ -34,18 +32,13 @@ import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
/** /**
* *
* @author $Author: raul $ * @author $Author: mullan $
*/ */
public class XMLX509Certificate extends SignatureElementProxy public class XMLX509Certificate extends SignatureElementProxy
implements XMLX509DataContent { implements XMLX509DataContent {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(XMLX509Certificate.class.getName());
/** Field JCA_CERT_ID */ /** Field JCA_CERT_ID */
public static final String JCA_CERT_ID = "X.509"; public static final String JCA_CERT_ID = "X.509";
...@@ -149,16 +142,18 @@ public class XMLX509Certificate extends SignatureElementProxy ...@@ -149,16 +142,18 @@ public class XMLX509Certificate extends SignatureElementProxy
/** @inheritDoc */ /** @inheritDoc */
public boolean equals(Object obj) { public boolean equals(Object obj) {
try { if (obj == null) {
if (!obj.getClass().getName().equals(this.getClass().getName())) { return false;
}
if (!this.getClass().getName().equals(obj.getClass().getName())) {
return false; return false;
} }
XMLX509Certificate other = (XMLX509Certificate) obj; XMLX509Certificate other = (XMLX509Certificate) obj;
try {
/** $todo$ or should be create X509Certificates and use the equals() from the Certs */ /** $todo$ or should be create X509Certificates and use the equals() from the Certs */
return java.security.MessageDigest.isEqual(other.getCertificateBytes(), return java.security.MessageDigest.isEqual
this.getCertificateBytes()); (other.getCertificateBytes(), this.getCertificateBytes());
} catch (XMLSecurityException ex) { } catch (XMLSecurityException ex) {
return false; return false;
} }
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
* reserved comment block * reserved comment block
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /*
* Copyright 1999-2004 The Apache Software Foundation. * Copyright 1999-2004 The Apache Software Foundation.
* *
...@@ -28,7 +27,7 @@ package com.sun.org.apache.xml.internal.security.keys.content.x509; ...@@ -28,7 +27,7 @@ package com.sun.org.apache.xml.internal.security.keys.content.x509;
/** /**
* Just used for tagging contents that are allowed inside a ds:X509Data Element. * Just used for tagging contents that are allowed inside a ds:X509Data Element.
* *
* @author $Author: blautenb $ * @author $Author: mullan $
*/ */
public interface XMLX509DataContent { public interface XMLX509DataContent {
} }
...@@ -20,8 +20,6 @@ ...@@ -20,8 +20,6 @@
*/ */
package com.sun.org.apache.xml.internal.security.keys.content.x509; package com.sun.org.apache.xml.internal.security.keys.content.x509;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
...@@ -33,15 +31,11 @@ import org.w3c.dom.Element; ...@@ -33,15 +31,11 @@ import org.w3c.dom.Element;
/** /**
* *
* @author $Author: raul $ * @author $Author: mullan $
*/ */
public class XMLX509SubjectName extends SignatureElementProxy public class XMLX509SubjectName extends SignatureElementProxy
implements XMLX509DataContent { implements XMLX509DataContent {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(XMLX509SubjectName.class.getName());
/** /**
* Constructor X509SubjectName * Constructor X509SubjectName
* *
...@@ -90,8 +84,11 @@ public class XMLX509SubjectName extends SignatureElementProxy ...@@ -90,8 +84,11 @@ public class XMLX509SubjectName extends SignatureElementProxy
/** @inheritDoc */ /** @inheritDoc */
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!obj.getClass().getName().equals(this.getClass().getName())) { if (!this.getClass().getName().equals(obj.getClass().getName())) {
return false; return false;
} }
...@@ -99,12 +96,7 @@ public class XMLX509SubjectName extends SignatureElementProxy ...@@ -99,12 +96,7 @@ public class XMLX509SubjectName extends SignatureElementProxy
String otherSubject = other.getSubjectName(); String otherSubject = other.getSubjectName();
String thisSubject = this.getSubjectName(); String thisSubject = this.getSubjectName();
if (otherSubject.equals(thisSubject)) { return thisSubject.equals(otherSubject);
return true;
}
return false;
} }
/** @inheritDoc */ /** @inheritDoc */
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
* reserved comment block * reserved comment block
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /*
* Copyright 1999-2004 The Apache Software Foundation. * Copyright 1999-2004 The Apache Software Foundation.
* *
...@@ -29,7 +28,7 @@ import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; ...@@ -29,7 +28,7 @@ import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
/** /**
* *
* *
* @author $Author: raul $ * @author $Author: mullan $
*/ */
public class InvalidKeyResolverException extends XMLSecurityException { public class InvalidKeyResolverException extends XMLSecurityException {
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
* reserved comment block * reserved comment block
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /*
* Copyright 1999-2004 The Apache Software Foundation. * Copyright 1999-2004 The Apache Software Foundation.
* *
...@@ -31,7 +30,7 @@ import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; ...@@ -31,7 +30,7 @@ import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
* *
* *
* *
* @author $Author: raul $ * @author $Author: mullan $
* *
*/ */
public class KeyResolverException extends XMLSecurityException { public class KeyResolverException extends XMLSecurityException {
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
* reserved comment block * reserved comment block
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /*
* Copyright 1999-2004 The Apache Software Foundation. * Copyright 1999-2004 The Apache Software Foundation.
* *
...@@ -28,7 +27,7 @@ import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; ...@@ -28,7 +27,7 @@ import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
/** /**
* *
* @author $Author: raul $ * @author $Author: mullan $
*/ */
public class StorageResolverException extends XMLSecurityException { public class StorageResolverException extends XMLSecurityException {
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
* reserved comment block * reserved comment block
* DO NOT REMOVE OR ALTER! * DO NOT REMOVE OR ALTER!
*/ */
/* /*
* Copyright 1999-2004 The Apache Software Foundation. * Copyright 1999-2004 The Apache Software Foundation.
* *
...@@ -28,7 +27,7 @@ import java.util.Iterator; ...@@ -28,7 +27,7 @@ import java.util.Iterator;
/** /**
* *
* @author $Author: raul $ * @author $Author: mullan $
*/ */
public abstract class StorageResolverSpi { public abstract class StorageResolverSpi {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
Joseph Reagle $last changed 20001215$ Joseph Reagle $last changed 20001215$
http://www.w3.org/2000/09/xmldsig# http://www.w3.org/2000/09/xmldsig#
$Revision: 1.1 $ on $Date: 2002/02/08 20:32:26 $ by $Author: reagle $ $Revision: 1.6 $ on $Date: 2008/07/24 16:15:03 $ by $Author: mullan $
Copyright 2001 The Internet Society and W3C (Massachusetts Institute Copyright 2001 The Internet Society and W3C (Massachusetts Institute
of Technology, Institut National de Recherche en Informatique et en of Technology, Institut National de Recherche en Informatique et en
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<!-- Schema for XML Signatures <!-- Schema for XML Signatures
http://www.w3.org/2000/09/xmldsig# http://www.w3.org/2000/09/xmldsig#
$Revision: 1.1 $ on $Date: 2002/02/08 20:32:26 $ by $Author: reagle $ $Revision: 1.6 $ on $Date: 2008/07/24 16:15:03 $ by $Author: mullan $
Copyright 2001 The Internet Society and W3C (Massachusetts Institute Copyright 2001 The Internet Society and W3C (Massachusetts Institute
of Technology, Institut National de Recherche en Informatique et en of Technology, Institut National de Recherche en Informatique et en
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册