提交 4eed2940 编写于 作者: V vinnie

8006855: PKCS12 test failures due to unsupported algorithm

Reviewed-by: mullan
上级 9eb93842
...@@ -887,13 +887,13 @@ public final class PKCS12KeyStore extends KeyStoreSpi { ...@@ -887,13 +887,13 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
/* /*
* Map a PBE algorithm name onto its object identifier * 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 // Check for PBES2 algorithms
if (algorithm.toLowerCase().startsWith("pbewithhmacsha")) { if (algorithm.toLowerCase().startsWith("pbewithhmacsha")) {
return pbes2_OID; return pbes2_OID;
} }
return AlgorithmId.get(algorithm).getOID();
return null;
} }
/** /**
......
...@@ -36,7 +36,8 @@ import javax.crypto.spec.*; ...@@ -36,7 +36,8 @@ import javax.crypto.spec.*;
public class PBETest { public class PBETest {
private final static String DIR = System.getProperty("test.src", "."); 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 char[] PASSWORD = "passphrase".toCharArray();
private static final String KEYSTORE_TYPE = "JKS"; private static final String KEYSTORE_TYPE = "JKS";
private static final String KEYSTORE = DIR + "/keystore.jks"; private static final String KEYSTORE = DIR + "/keystore.jks";
......
...@@ -43,6 +43,14 @@ public class StoreSecretKeyTest { ...@@ -43,6 +43,14 @@ public class StoreSecretKeyTest {
public static void main(String[] args) throws Exception { 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(); new File(KEYSTORE).delete();
try { try {
...@@ -79,6 +87,17 @@ public class StoreSecretKeyTest { ...@@ -79,6 +87,17 @@ public class StoreSecretKeyTest {
private static SecretKey generateSecretKey(String algorithm, int size) private static SecretKey generateSecretKey(String algorithm, int size)
throws NoSuchAlgorithmException { 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); KeyGenerator generator = KeyGenerator.getInstance(algorithm);
generator.init(size); generator.init(size);
return generator.generateKey(); return generator.generateKey();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册