8006855: PKCS12 test failures due to unsupported algorithm
authorvinnie
Thu, 24 Jan 2013 16:44:15 +0000
changeset 15301 215128369cab
parent 15300 ffec14ad2f94
child 15302 0580250d24d1
8006855: PKCS12 test failures due to unsupported algorithm Reviewed-by: mullan
jdk/src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java
jdk/test/java/security/KeyStore/PBETest.java
jdk/test/sun/security/pkcs12/StoreSecretKeyTest.java
--- a/jdk/src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java	Thu Jan 24 09:47:09 2013 +0000
+++ b/jdk/src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java	Thu Jan 24 16:44:15 2013 +0000
@@ -887,13 +887,13 @@
     /*
      * Map a PBE algorithm name onto its object identifier
      */
-    private ObjectIdentifier mapPBEAlgorithmToOID(String algorithm) {
+    private ObjectIdentifier mapPBEAlgorithmToOID(String algorithm)
+        throws NoSuchAlgorithmException {
         // Check for PBES2 algorithms
         if (algorithm.toLowerCase().startsWith("pbewithhmacsha")) {
             return pbes2_OID;
         }
-
-        return null;
+        return AlgorithmId.get(algorithm).getOID();
     }
 
     /**
--- a/jdk/test/java/security/KeyStore/PBETest.java	Thu Jan 24 09:47:09 2013 +0000
+++ b/jdk/test/java/security/KeyStore/PBETest.java	Thu Jan 24 16:44:15 2013 +0000
@@ -36,7 +36,8 @@
 
 public class PBETest {
     private final static String DIR = System.getProperty("test.src", ".");
-    private static final String PBE_ALGO = "PBEWithHmacSHA1AndAES_128";
+    //private static final String PBE_ALGO = "PBEWithHmacSHA1AndAES_128";
+    private static final String PBE_ALGO = "PBEWithSHA1AndDESede";
     private static final char[] PASSWORD = "passphrase".toCharArray();
     private static final String KEYSTORE_TYPE = "JKS";
     private static final String KEYSTORE = DIR + "/keystore.jks";
--- a/jdk/test/sun/security/pkcs12/StoreSecretKeyTest.java	Thu Jan 24 09:47:09 2013 +0000
+++ b/jdk/test/sun/security/pkcs12/StoreSecretKeyTest.java	Thu Jan 24 16:44:15 2013 +0000
@@ -43,6 +43,14 @@
 
     public static void main(String[] args) throws Exception {
 
+        // Skip test if AES is unavailable
+        try {
+            SecretKeyFactory.getInstance("AES");
+        } catch (NoSuchAlgorithmException nsae) {
+            System.out.println("AES is unavailable. Skipping test...");
+            return;
+        }
+
         new File(KEYSTORE).delete();
 
         try {
@@ -79,6 +87,17 @@
 
     private static SecretKey generateSecretKey(String algorithm, int size)
         throws NoSuchAlgorithmException {
+
+        // Failover to DES if the requested secret key factory is unavailable
+        SecretKeyFactory keyFactory;
+        try {
+            keyFactory = SecretKeyFactory.getInstance(algorithm);
+        } catch (NoSuchAlgorithmException nsae) {
+            keyFactory = SecretKeyFactory.getInstance("DES");
+            algorithm = "DES";
+            size = 56;
+        }
+
         KeyGenerator generator = KeyGenerator.getInstance(algorithm);
         generator.init(size);
         return generator.generateKey();