diff --git a/src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java b/src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java index 5d0c0533a1b2ce1f3188686f1789970851fadffb..f84fe27f20a125c4716c3edf96b5ab3265cef365 100644 --- a/src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java +++ b/src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java @@ -887,13 +887,13 @@ public final class PKCS12KeyStore extends KeyStoreSpi { /* * 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(); } /** diff --git a/test/java/security/KeyStore/PBETest.java b/test/java/security/KeyStore/PBETest.java index bc12102f230e4a8713a5e299c1fb1a08221735e9..be437d03bbd2a918ff840e8200ce9fee4f6ef918 100644 --- a/test/java/security/KeyStore/PBETest.java +++ b/test/java/security/KeyStore/PBETest.java @@ -36,7 +36,8 @@ import javax.crypto.spec.*; 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"; diff --git a/test/sun/security/pkcs12/StoreSecretKeyTest.java b/test/sun/security/pkcs12/StoreSecretKeyTest.java index 9a91148a41b19e06b2d2ef2c63826f04e93cdbfe..f002ef7506aa543eaa6890ce073a02aec885d0f9 100644 --- a/test/sun/security/pkcs12/StoreSecretKeyTest.java +++ b/test/sun/security/pkcs12/StoreSecretKeyTest.java @@ -43,6 +43,14 @@ public class StoreSecretKeyTest { 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 @@ public class StoreSecretKeyTest { 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();