summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenny Root <kroot@google.com>2014-05-08 08:55:34 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-05-08 08:55:34 +0000
commit0d6d32920134aa84e55fab59b6bd3a71c7bcb38f (patch)
treea946968305f48216618f8e0c7332f64ee0709465
parent578741db192290a996a4a4f1fe6d7c28b64181c3 (diff)
parent6005b896b58659f8c2e0693bd9ead32706a05044 (diff)
downloadlibcore-0d6d32920134aa84e55fab59b6bd3a71c7bcb38f.zip
libcore-0d6d32920134aa84e55fab59b6bd3a71c7bcb38f.tar.gz
libcore-0d6d32920134aa84e55fab59b6bd3a71c7bcb38f.tar.bz2
am 6005b896: am 4abcf7ad: Merge changes Iaaafcbed,Ifbca5637
* commit '6005b896b58659f8c2e0693bd9ead32706a05044': KeyStoreTest: add more key types KeyManagerFactoryTest: add all the possible key types
-rw-r--r--luni/src/test/java/libcore/java/security/KeyStoreTest.java45
-rw-r--r--luni/src/test/java/libcore/javax/net/ssl/KeyManagerFactoryTest.java4
-rw-r--r--support/src/test/java/libcore/java/security/TestKeyStore.java21
3 files changed, 58 insertions, 12 deletions
diff --git a/luni/src/test/java/libcore/java/security/KeyStoreTest.java b/luni/src/test/java/libcore/java/security/KeyStoreTest.java
index 47aa72a..04fd7af 100644
--- a/luni/src/test/java/libcore/java/security/KeyStoreTest.java
+++ b/luni/src/test/java/libcore/java/security/KeyStoreTest.java
@@ -46,6 +46,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.Enumeration;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -55,7 +56,16 @@ import junit.framework.TestCase;
public class KeyStoreTest extends TestCase {
- private static PrivateKeyEntry PRIVATE_KEY;
+ private static HashMap<String, PrivateKeyEntry> sPrivateKeys
+ = new HashMap<String, PrivateKeyEntry>();
+
+ private static TestKeyStore TEST_KEY_STORE = new TestKeyStore.Builder()
+ .keyAlgorithms("RSA", "DH_RSA", "DSA", "EC")
+ .aliasPrefix("rsa-dsa-ec-dh")
+ .build();
+
+ private static final String[] KEY_TYPES = new String[] { "DH", "DSA", "RSA", "EC" };
+
private static PrivateKeyEntry PRIVATE_KEY_2;
private static SecretKey SECRET_KEY;
@@ -87,10 +97,26 @@ public class KeyStoreTest extends TestCase {
private static final ProtectionParameter PARAM_BAD = new PasswordProtection(PASSWORD_BAD);
private static PrivateKeyEntry getPrivateKey() {
- if (PRIVATE_KEY == null) {
- PRIVATE_KEY = TestKeyStore.getServer().getPrivateKey("RSA", "RSA");
+ return getPrivateKey("RSA");
+ }
+
+ private static PrivateKeyEntry getPrivateKey(String keyType) {
+ PrivateKeyEntry entry = sPrivateKeys.get(keyType);
+ if (entry == null) {
+ if ("RSA".equals(keyType)) {
+ entry = TEST_KEY_STORE.getPrivateKey("RSA", "RSA");
+ } else if ("DH".equals(keyType)) {
+ entry = TEST_KEY_STORE.getPrivateKey("DH", "RSA");
+ } else if ("DSA".equals(keyType)) {
+ entry = TEST_KEY_STORE.getPrivateKey("DSA", "DSA");
+ } else if ("EC".equals(keyType)) {
+ entry = TEST_KEY_STORE.getPrivateKey("EC", "EC");
+ } else {
+ throw new IllegalArgumentException("Unexpected key type " + keyType);
+ }
+ sPrivateKeys.put(keyType, entry);
}
- return PRIVATE_KEY;
+ return entry;
}
private static PrivateKeyEntry getPrivateKey2() {
@@ -341,10 +367,15 @@ public class KeyStoreTest extends TestCase {
ks.setCertificateEntry(alias, certificate);
}
+
public static void assertPrivateKey(Key actual)
throws Exception {
assertEquals(getPrivateKey().getPrivateKey(), actual);
}
+ public static void assertPrivateKey(String keyType, Key actual)
+ throws Exception {
+ assertEquals(getPrivateKey(keyType).getPrivateKey(), actual);
+ }
public static void assertPrivateKey2(Key actual)
throws Exception {
assertEquals(getPrivateKey2().getPrivateKey(), actual);
@@ -2183,8 +2214,10 @@ public class KeyStoreTest extends TestCase {
continue;
}
if (isNullPasswordAllowed(keyStore) || isKeyPasswordIgnored(keyStore)) {
- keyStore.setEntry(ALIAS_PRIVATE, getPrivateKey(), null);
- assertPrivateKey(keyStore.getKey(ALIAS_PRIVATE, null));
+ for (String keyType : KEY_TYPES) {
+ keyStore.setEntry(ALIAS_PRIVATE, getPrivateKey(keyType), null);
+ assertPrivateKey(keyType, keyStore.getKey(ALIAS_PRIVATE, null));
+ }
} else {
try {
keyStore.setEntry(ALIAS_PRIVATE, getPrivateKey(), null);
diff --git a/luni/src/test/java/libcore/javax/net/ssl/KeyManagerFactoryTest.java b/luni/src/test/java/libcore/javax/net/ssl/KeyManagerFactoryTest.java
index f2d36c8..0657f18 100644
--- a/luni/src/test/java/libcore/javax/net/ssl/KeyManagerFactoryTest.java
+++ b/luni/src/test/java/libcore/javax/net/ssl/KeyManagerFactoryTest.java
@@ -45,8 +45,8 @@ public class KeyManagerFactoryTest extends TestCase {
private static TestKeyStore getTestKeyStore() throws Exception {
if (TEST_KEY_STORE == null) {
TEST_KEY_STORE = new TestKeyStore.Builder()
- .keyAlgorithms("RSA", "DSA", "EC", "EC_RSA")
- .aliasPrefix("rsa-dsa-ec")
+ .keyAlgorithms("RSA", "DH_RSA", "DSA", "DH_DSA", "EC", "EC_RSA")
+ .aliasPrefix("rsa-dsa-ec-dh")
.build();
}
return TEST_KEY_STORE;
diff --git a/support/src/test/java/libcore/java/security/TestKeyStore.java b/support/src/test/java/libcore/java/security/TestKeyStore.java
index 86d6f4c..203c028 100644
--- a/support/src/test/java/libcore/java/security/TestKeyStore.java
+++ b/support/src/test/java/libcore/java/security/TestKeyStore.java
@@ -54,6 +54,7 @@ import java.security.cert.X509Certificate;
import java.security.interfaces.ECPrivateKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
@@ -371,10 +372,15 @@ public final class TestKeyStore extends Assert {
for (String keyAlgorithm : keyAlgorithms) {
String publicAlias = aliasPrefix + "-public-" + keyAlgorithm;
String privateAlias = aliasPrefix + "-private-" + keyAlgorithm;
- if (keyAlgorithm.equals("EC_RSA") && signer == null && rootCa == null) {
+ if ((keyAlgorithm.equals("EC_RSA") || keyAlgorithm.equals("DH_RSA"))
+ && signer == null && rootCa == null) {
createKeys(keyStore, keyAlgorithm, publicAlias, privateAlias,
privateKey(keyStore, keyPassword, "RSA", "RSA"));
continue;
+ } else if (keyAlgorithm.equals("DH_DSA") && signer == null && rootCa == null) {
+ createKeys(keyStore, keyAlgorithm, publicAlias, privateAlias,
+ privateKey(keyStore, keyPassword, "DSA", "DSA"));
+ continue;
}
createKeys(keyStore, keyAlgorithm, publicAlias, privateAlias, signer);
}
@@ -436,8 +442,14 @@ public final class TestKeyStore extends Assert {
if (keyAlgorithm.equals("RSA")) {
// 512 breaks SSL_RSA_EXPORT_* on RI and TLS_ECDHE_RSA_WITH_RC4_128_SHA for us
keySize = 1024;
+ } else if (keyAlgorithm.equals("DH_RSA")) {
+ keySize = 512;
+ keyAlgorithm = "DH";
} else if (keyAlgorithm.equals("DSA")) {
keySize = 512;
+ } else if (keyAlgorithm.equals("DH_DSA")) {
+ keySize = 512;
+ keyAlgorithm = "DH";
} else if (keyAlgorithm.equals("EC")) {
keySize = 256;
} else if (keyAlgorithm.equals("EC_RSA")) {
@@ -686,7 +698,7 @@ public final class TestKeyStore extends Assert {
continue;
}
if (found != null) {
- throw new IllegalStateException("KeyStore has more than one private key for "
+ throw new IllegalStateException("KeyStore has more than one private key for"
+ " keyAlgorithm: " + keyAlgorithm
+ " signatureAlgorithm: " + signatureAlgorithm
+ "\nfirst: " + found.getPrivateKey()
@@ -695,13 +707,14 @@ public final class TestKeyStore extends Assert {
found = privateKey;
}
if (found == null) {
- throw new IllegalStateException("KeyStore contained no private key for "
+ throw new IllegalStateException("KeyStore contained no private key for"
+ " keyAlgorithm: " + keyAlgorithm
+ " signatureAlgorithm: " + signatureAlgorithm);
}
return found;
} catch (Exception e) {
- throw new RuntimeException(e);
+ throw new RuntimeException("Problem getting key for " + keyAlgorithm
+ + " and signature " + signatureAlgorithm, e);
}
}