[java-opensaml COMMIT] in /trunk/opensaml-xmlsec-api/src: main/java/org/opensaml/xmlsec/ApacheXMLSecurityConstants.ja...

noreply at shibboleth.net noreply at shibboleth.net
Fri Apr 4 22:11:45 EDT 2014


Author: putmanb
Date: Fri Apr  4 22:11:42 2014
New Revision: 3766

URL: http://svn.shibboleth.net/view/java-opensaml?rev=3766&view=rev
Log:
Update AlgorithmSupport to eliminate use of Santuario JCEMapper, in favor of our new AlgorithmRegistry. 

Modified:
    trunk/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/ApacheXMLSecurityConstants.java
    trunk/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/algorithm/AlgorithmSupport.java
    trunk/opensaml-xmlsec-api/src/test/java/org/opensaml/xmlsec/algorithm/AlgorithmSupportTest.java

Modified: trunk/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/algorithm/AlgorithmSupport.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/algorithm/AlgorithmSupport.java?rev=3766&r1=3765&r2=3766&view=diff
==============================================================================
--- trunk/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/algorithm/AlgorithmSupport.java (original)
+++ trunk/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/algorithm/AlgorithmSupport.java Fri Apr  4 22:11:42 2014
@@ -22,25 +22,16 @@
 import java.security.NoSuchAlgorithmException;
 import java.security.NoSuchProviderException;
 import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
 
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import javax.crypto.KeyGenerator;
 import javax.crypto.SecretKey;
 
-import net.shibboleth.utilities.java.support.collection.LazySet;
-import net.shibboleth.utilities.java.support.primitive.StringSupport;
-
-import org.apache.xml.security.Init;
-import org.apache.xml.security.algorithms.JCEMapper;
 import org.opensaml.core.config.ConfigurationService;
 import org.opensaml.security.credential.BasicCredential;
 import org.opensaml.security.credential.Credential;
 import org.opensaml.security.crypto.KeySupport;
-import org.opensaml.xmlsec.ApacheXMLSecurityConstants;
-import org.opensaml.xmlsec.signature.support.SignatureConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -54,15 +45,6 @@
     /** Logger. */
     private static final Logger LOG = LoggerFactory.getLogger(AlgorithmSupport.class);
     
-    /** Additional algorithm URI's which imply RSA keys. */
-    private static Set<String> rsaAlgorithmURIs;
-
-    /** Additional algorithm URI's which imply DSA keys. */
-    private static Set<String> dsaAlgorithmURIs;
-
-    /** Additional algorithm URI's which imply ECDSA keys. */
-    private static Set<String> ecdsaAlgorithmURIs;
-    
     /** Constructor. */
     private AlgorithmSupport() {
         
@@ -84,7 +66,14 @@
      * @return the Java algorithm identifier, or null if the mapping is unavailable or indeterminable from the URI
      */
     @Nullable public static String getAlgorithmID(@Nonnull final String algorithmURI) {
-        return StringSupport.trimOrNull(JCEMapper.translateURItoJCEID(algorithmURI));
+        AlgorithmRegistry registry = getGlobalAlgorithmRegistry();
+        if (registry != null){
+            AlgorithmDescriptor descriptor = registry.get(algorithmURI);
+            if (descriptor != null) {
+                return descriptor.getJCAAlgorithmID();
+            }
+        }
+        return null;
     }
 
     /**
@@ -94,8 +83,14 @@
      * @return true if URI indicates HMAC, false otherwise
      */
     public static boolean isHMAC(@Nonnull final String signatureAlgorithm) {
-        String algoClass = StringSupport.trimOrNull(JCEMapper.getAlgorithmClassFromURI(signatureAlgorithm));
-        return ApacheXMLSecurityConstants.ALGO_CLASS_MAC.equals(algoClass);
+        AlgorithmRegistry registry = getGlobalAlgorithmRegistry();
+        if (registry != null){
+            AlgorithmDescriptor descriptor = registry.get(signatureAlgorithm);
+            if (descriptor != null) {
+                return descriptor.getType().equals(AlgorithmDescriptor.AlgorithmType.Mac);
+            }
+        }
+        return false;
     }
     
     /**
@@ -105,27 +100,13 @@
      * @return the Java key algorithm specifier, or null if the mapping is unavailable or indeterminable from the URI
      */
     @Nullable public static String getKeyAlgorithm(@Nonnull final String algorithmURI) {
-        // The default Apache config file currently only includes the key algorithm for
-        // the block ciphers and key wrap URI's. Note: could use a custom config file which contains others.
-        String apacheValue = StringSupport.trimOrNull(JCEMapper.getJCEKeyAlgorithmFromURI(algorithmURI));
-        if (apacheValue != null) {
-            return apacheValue;
-        }
-      
-        // HMAC uses any symmetric key, so there is no implied specific key algorithm
-        if (isHMAC(algorithmURI)) {
-            return null;
-        }
-    
-        // As a last ditch fallback, check some known common and supported ones.
-        if (rsaAlgorithmURIs.contains(algorithmURI)) {
-            return "RSA";
-        } else if (dsaAlgorithmURIs.contains(algorithmURI)) {
-            return "DSA";

[... 103 lines stripped ...]


More information about the commits mailing list