aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--luni/src/test/java/tests/targets/security/KeyStorePkcs7FormatTest.java170
-rw-r--r--luni/src/test/resources/keystore/README.md68
-rw-r--r--luni/src/test/resources/keystore/certificate.pem13
-rwxr-xr-xluni/src/test/resources/keystore/mkstores.sh27
-rw-r--r--luni/src/test/resources/keystore/pberc2.p12bin0 -> 1533 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-128-aes-128-sha1.p12bin0 -> 1651 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-128-aes-128-sha224.p12bin0 -> 1663 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-128-aes-128-sha256.p12bin0 -> 1667 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-128-aes-128-sha384.p12bin0 -> 1683 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-128-aes-128-sha512.p12bin0 -> 1699 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-128-aes-192-sha1.p12bin0 -> 1651 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-128-aes-192-sha224.p12bin0 -> 1663 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-128-aes-192-sha256.p12bin0 -> 1667 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-128-aes-192-sha384.p12bin0 -> 1683 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-128-aes-192-sha512.p12bin0 -> 1699 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-128-aes-256-sha1.p12bin0 -> 1651 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-128-aes-256-sha224.p12bin0 -> 1663 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-128-aes-256-sha256.p12bin0 -> 1667 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-128-aes-256-sha384.p12bin0 -> 1683 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-128-aes-256-sha512.p12bin0 -> 1699 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-192-aes-128-sha1.p12bin0 -> 1651 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-192-aes-128-sha224.p12bin0 -> 1663 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-192-aes-128-sha256.p12bin0 -> 1667 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-192-aes-128-sha384.p12bin0 -> 1683 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-192-aes-128-sha512.p12bin0 -> 1699 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-192-aes-192-sha1.p12bin0 -> 1651 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-192-aes-192-sha224.p12bin0 -> 1663 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-192-aes-192-sha256.p12bin0 -> 1667 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-192-aes-192-sha384.p12bin0 -> 1683 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-192-aes-192-sha512.p12bin0 -> 1699 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-192-aes-256-sha1.p12bin0 -> 1651 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-192-aes-256-sha224.p12bin0 -> 1663 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-192-aes-256-sha256.p12bin0 -> 1667 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-192-aes-256-sha384.p12bin0 -> 1683 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-192-aes-256-sha512.p12bin0 -> 1699 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-256-aes-128-sha1.p12bin0 -> 1651 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-256-aes-128-sha224.p12bin0 -> 1663 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-256-aes-128-sha256.p12bin0 -> 1667 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-256-aes-128-sha384.p12bin0 -> 1683 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-256-aes-128-sha512.p12bin0 -> 1699 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-256-aes-192-sha1.p12bin0 -> 1651 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-256-aes-192-sha224.p12bin0 -> 1663 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-256-aes-192-sha256.p12bin0 -> 1667 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-256-aes-192-sha384.p12bin0 -> 1683 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-256-aes-192-sha512.p12bin0 -> 1699 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-256-aes-256-sha1.p12bin0 -> 1651 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-256-aes-256-sha224.p12bin0 -> 1663 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-256-aes-256-sha256.p12bin0 -> 1667 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-256-aes-256-sha384.p12bin0 -> 1683 bytes
-rw-r--r--luni/src/test/resources/keystore/pbes2-aes-256-aes-256-sha512.p12bin0 -> 1699 bytes
-rw-r--r--luni/src/test/resources/keystore/privkey.pem16
-rw-r--r--luni/src/test/resources/keystore/sha3.p12bin0 -> 1667 bytes
52 files changed, 294 insertions, 0 deletions
diff --git a/luni/src/test/java/tests/targets/security/KeyStorePkcs7FormatTest.java b/luni/src/test/java/tests/targets/security/KeyStorePkcs7FormatTest.java
new file mode 100644
index 00000000000..43c84696c63
--- /dev/null
+++ b/luni/src/test/java/tests/targets/security/KeyStorePkcs7FormatTest.java
@@ -0,0 +1,170 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests.targets.security;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.KeyStore;
+import java.security.KeyStore.PrivateKeyEntry;
+import java.security.cert.X509Certificate;
+import java.security.interfaces.RSAPrivateKey;
+import java.security.interfaces.RSAPublicKey;
+import java.util.Arrays;
+import java.util.Enumeration;
+import javax.crypto.Cipher;
+import org.junit.Test;
+import org.junit.experimental.runners.Enclosed;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * Tests the ability of PKCS#12 KeyStores to read PKCS#7 private key entries
+ * shrouded with different encryption schemes.
+ *
+ * KeyStores to test and instructions for regenerating them are in
+ * libcore/luni/src/test/resources/keystore.
+ *
+ * Each KeyStore to be tested contains the same certificate and private key
+ * pair and has the password "password".
+ */
+@RunWith(Enclosed.class)
+public class KeyStorePkcs7FormatTest {
+ private static final char[] PASSWORD = "password".toCharArray();
+ private static final String UNKNOWN_HASH = "/keystore/sha3.p12";
+
+ @RunWith(Parameterized.class)
+ public static class ParameterizedTests {
+ @Parameters(name = "{0}")
+ public static Iterable<?> data() {
+ return Arrays.asList(
+ "/keystore/pberc2.p12",
+ "/keystore/pbes2-aes-128-aes-128-sha1.p12",
+ "/keystore/pbes2-aes-128-aes-128-sha224.p12",
+ "/keystore/pbes2-aes-128-aes-128-sha256.p12",
+ "/keystore/pbes2-aes-128-aes-128-sha384.p12",
+ "/keystore/pbes2-aes-128-aes-128-sha512.p12",
+ "/keystore/pbes2-aes-128-aes-192-sha1.p12",
+ "/keystore/pbes2-aes-128-aes-192-sha224.p12",
+ "/keystore/pbes2-aes-128-aes-192-sha256.p12",
+ "/keystore/pbes2-aes-128-aes-192-sha384.p12",
+ "/keystore/pbes2-aes-128-aes-192-sha512.p12",
+ "/keystore/pbes2-aes-128-aes-256-sha1.p12",
+ "/keystore/pbes2-aes-128-aes-256-sha224.p12",
+ "/keystore/pbes2-aes-128-aes-256-sha256.p12",
+ "/keystore/pbes2-aes-128-aes-256-sha384.p12",
+ "/keystore/pbes2-aes-128-aes-256-sha512.p12",
+ "/keystore/pbes2-aes-192-aes-128-sha1.p12",
+ "/keystore/pbes2-aes-192-aes-128-sha224.p12",
+ "/keystore/pbes2-aes-192-aes-128-sha256.p12",
+ "/keystore/pbes2-aes-192-aes-128-sha384.p12",
+ "/keystore/pbes2-aes-192-aes-128-sha512.p12",
+ "/keystore/pbes2-aes-192-aes-192-sha1.p12",
+ "/keystore/pbes2-aes-192-aes-192-sha224.p12",
+ "/keystore/pbes2-aes-192-aes-192-sha256.p12",
+ "/keystore/pbes2-aes-192-aes-192-sha384.p12",
+ "/keystore/pbes2-aes-192-aes-192-sha512.p12",
+ "/keystore/pbes2-aes-192-aes-256-sha1.p12",
+ "/keystore/pbes2-aes-192-aes-256-sha224.p12",
+ "/keystore/pbes2-aes-192-aes-256-sha256.p12",
+ "/keystore/pbes2-aes-192-aes-256-sha384.p12",
+ "/keystore/pbes2-aes-192-aes-256-sha512.p12",
+ "/keystore/pbes2-aes-256-aes-128-sha1.p12",
+ "/keystore/pbes2-aes-256-aes-128-sha224.p12",
+ "/keystore/pbes2-aes-256-aes-128-sha256.p12",
+ "/keystore/pbes2-aes-256-aes-128-sha384.p12",
+ "/keystore/pbes2-aes-256-aes-128-sha512.p12",
+ "/keystore/pbes2-aes-256-aes-192-sha1.p12",
+ "/keystore/pbes2-aes-256-aes-192-sha224.p12",
+ "/keystore/pbes2-aes-256-aes-192-sha256.p12",
+ "/keystore/pbes2-aes-256-aes-192-sha384.p12",
+ "/keystore/pbes2-aes-256-aes-192-sha512.p12",
+ "/keystore/pbes2-aes-256-aes-256-sha1.p12",
+ "/keystore/pbes2-aes-256-aes-256-sha224.p12",
+ "/keystore/pbes2-aes-256-aes-256-sha256.p12",
+ "/keystore/pbes2-aes-256-aes-256-sha384.p12",
+ "/keystore/pbes2-aes-256-aes-256-sha512.p12"
+ );
+ }
+
+ @Parameter
+ public String keystoreFile;
+
+ @Test
+ public void keystoreIsReadableAndConsistent() throws Exception {
+ KeyStore keystore = KeyStore.getInstance("PKCS12");
+ InputStream inputStream = getClass().getResourceAsStream(keystoreFile);
+ assertNotNull("Resource not found: " + keystoreFile, inputStream);
+ keystore.load(inputStream, PASSWORD);
+
+ Enumeration<String> aliases = keystore.aliases();
+ assertTrue("Empty KeyStore", aliases.hasMoreElements());
+
+ while (aliases.hasMoreElements()) {
+ String alias = aliases.nextElement();
+
+ if (!keystore.isKeyEntry(alias)) {
+ fail("Test KeyStore should only contain private key entries");
+ }
+
+ PrivateKeyEntry keyEntry = (PrivateKeyEntry) keystore.getEntry(alias, null);
+ X509Certificate certificate = (X509Certificate) keyEntry.getCertificate();
+ assertEquals("CN=Test", certificate.getSubjectX500Principal().getName());
+
+ // Check the keys actually work with each other.
+ RSAPublicKey publicKey = (RSAPublicKey) certificate.getPublicKey();
+ RSAPrivateKey privateKey = (RSAPrivateKey) keyEntry.getPrivateKey();
+ byte[] original = "Some random input text".getBytes();
+
+ Cipher cipher = Cipher.getInstance("RSA");
+ cipher.init(Cipher.ENCRYPT_MODE, privateKey);
+ byte[] encrypted = cipher.doFinal(original);
+
+ cipher.init(Cipher.DECRYPT_MODE, publicKey);
+ byte[] decrypted = cipher.doFinal(encrypted);
+
+ assertArrayEquals(original, decrypted);
+ }
+ }
+ }
+
+ @RunWith(JUnit4.class)
+ public static class OtherTests {
+ @Test
+ public void unknownHashThrowsCorrectException() throws Exception {
+ KeyStore keystore = KeyStore.getInstance("PKCS12");
+ InputStream inputStream = getClass().getResourceAsStream(UNKNOWN_HASH);
+ assertNotNull("Resource not found: " + UNKNOWN_HASH, inputStream);
+
+ try {
+ keystore.load(inputStream, PASSWORD);
+ fail();
+ } catch (IOException expected) {
+ assertFalse("Internal BCPrivate exception thrown",
+ expected.getMessage().contains("BCPrivate"));
+ }
+ }
+ }
+}
diff --git a/luni/src/test/resources/keystore/README.md b/luni/src/test/resources/keystore/README.md
new file mode 100644
index 00000000000..876735e6913
--- /dev/null
+++ b/luni/src/test/resources/keystore/README.md
@@ -0,0 +1,68 @@
+## Test KeyStore data
+
+This directory contains the same certificate and private key stored in multiple
+PKCS#12 KeyStore files, each using a different PKCS#7 encryption scheme for the
+private key, for use in `KeyStorePkcs7FormatTest`.
+
+To generate the certificate and private key:
+
+```
+openssl req -x509 -nodes -days 36500 -subj "/CN=Test" -newkey rsa:1024 \
+ -out certificate.pem -keyout privkey.pem
+```
+
+### Tested formats
+
+All KeyStores have the password "password".
+
+#### Openssl version notes
+
+In the following commands `openssl1` refers to version 1.x of the
+`openssl` binary and `openssl3` refers to version 3.x.
+
+On most Linux installations openssl1 is still the default and you may need
+to build openssl3 from source.
+
+
+#### RC2 / 3DES
+
+Very old format, but still the default generated by openssl 1.x.
+
+* PKCS12 MAC: SHA-1
+* PKCS7 Encrypted data: pbeWithSHA1And40BitRC2-CBC, Iteration 2048
+* Shrouded Keybag: pbeWithSHA1And3-KeyTripleDES-CBC, Iteration 2048
+
+(The "Encrypted data" scheme is for the outer layer encryption for the
+whole KeyStore and the "Shrouded Keybag" is the scheme used to encrypt
+the private key)
+
+```
+openssl1 pkcs12 -export -out pberc2.p12 -in certificate.pem -inkey privkey.pem \
+ -passout pass:password
+```
+
+Can also be generated using:
+
+```
+openssl3 pkcs12 -legacy -export -out pberc2.p12 -in certificate.pem -inkey privkey.pem \
+ -passout pass:password
+```
+
+which generates identical ASN.1 data.
+
+#### PBES2
+
+All the pbes2-* files are generated with the mkstores.sh script which uses
+openssl3 to generate all supported variations of private key and certificate
+encryption (from the AES family) and overall MAC algorithm from the SHA-1 and
+SHA-2 family.
+
+#### SHA-3
+
+A file using SHA3-256 as its MAC algorithm. Used to trigger exceptions
+for testing. Created with:
+
+```
+openssl3 pkcs12 -export -out sha3.p12 -in certificate.pem -inkey privkey.pem \
+ -passout pass:password -macalg SHA3-256
+```
diff --git a/luni/src/test/resources/keystore/certificate.pem b/luni/src/test/resources/keystore/certificate.pem
new file mode 100644
index 00000000000..8364e47ff15
--- /dev/null
+++ b/luni/src/test/resources/keystore/certificate.pem
@@ -0,0 +1,13 @@
+-----BEGIN CERTIFICATE-----
+MIIB/DCCAWWgAwIBAgIUIcImGa1nvbzmXV2KuHXM7MpC5UkwDQYJKoZIhvcNAQEL
+BQAwDzENMAsGA1UEAwwEVGVzdDAgFw0yMjA1MTcxMzMwMzlaGA8yMTIyMDQyMzEz
+MzAzOVowDzENMAsGA1UEAwwEVGVzdDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkC
+gYEAoXKYUP8oSM5eW3aSuDz6+vd/STgFL7YVf777oVOfcgk0t6UKCr4sTx2GJYJB
+KwgQBjcSWkpoS3kVDBN+PYaNOoWxp0+pvDaa6S5P5Gg2h6Qr3ag4bS6vjxx5JbTs
+Kw5wuPl+yINhAjGSzcArLJauEz0FACDSxQy9FQdjSPVIviMCAwEAAaNTMFEwHQYD
+VR0OBBYEFHyc1WuHSglRut4pgGgcQMX7BHTuMB8GA1UdIwQYMBaAFHyc1WuHSglR
+ut4pgGgcQMX7BHTuMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADgYEA
+RvExqBRNmh+2h2OoHSH9GwVbWjN+YZCujX1p33kNQ+a+TogdBIoNET77IvvWlIqu
+kW1VPZdFksYpoOvbtW0z7qXpwMe9vfXaF17MS4tNhCaoE/3V/Qs3v4x1cK8S9fDa
+t/5O1U4ph488Esa7q7WcALq703nV3Q+cDXTX5d9gSQY=
+-----END CERTIFICATE-----
diff --git a/luni/src/test/resources/keystore/mkstores.sh b/luni/src/test/resources/keystore/mkstores.sh
new file mode 100755
index 00000000000..19d13bafd89
--- /dev/null
+++ b/luni/src/test/resources/keystore/mkstores.sh
@@ -0,0 +1,27 @@
+#! /bin/sh
+#
+# Creates keystores from privkey.prm and certificate.pem with algorithm variations
+
+mkstore() {
+ local KEYALG="$1"
+ local CERTALG="$2"
+ local MACALG="$3"
+
+ local OUTFILE="pbes2-${KEYALG}-${CERTALG}-${MACALG}.p12"
+
+ openssl3 pkcs12 -export -out "$OUTFILE" -in certificate.pem \
+ -inkey privkey.pem -passout pass:password \
+ -macalg "$MACALG" -keypbe "${KEYALG}-cbc" -certpbe "${CERTALG}-cbc"
+}
+
+
+KEYALGS="aes-128 aes-192 aes-256"
+MACALGS="sha1 sha224 sha256 sha384 sha512"
+
+for keyalg in $KEYALGS; do
+ for certalg in $KEYALGS; do
+ for macalg in $MACALGS; do
+ mkstore "$keyalg" "$certalg" "$macalg"
+ done
+ done
+done
diff --git a/luni/src/test/resources/keystore/pberc2.p12 b/luni/src/test/resources/keystore/pberc2.p12
new file mode 100644
index 00000000000..05d35376591
--- /dev/null
+++ b/luni/src/test/resources/keystore/pberc2.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-128-aes-128-sha1.p12 b/luni/src/test/resources/keystore/pbes2-aes-128-aes-128-sha1.p12
new file mode 100644
index 00000000000..faf0fa09003
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-128-aes-128-sha1.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-128-aes-128-sha224.p12 b/luni/src/test/resources/keystore/pbes2-aes-128-aes-128-sha224.p12
new file mode 100644
index 00000000000..6f3a20d8b31
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-128-aes-128-sha224.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-128-aes-128-sha256.p12 b/luni/src/test/resources/keystore/pbes2-aes-128-aes-128-sha256.p12
new file mode 100644
index 00000000000..b3207e2db30
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-128-aes-128-sha256.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-128-aes-128-sha384.p12 b/luni/src/test/resources/keystore/pbes2-aes-128-aes-128-sha384.p12
new file mode 100644
index 00000000000..3cd5906af42
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-128-aes-128-sha384.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-128-aes-128-sha512.p12 b/luni/src/test/resources/keystore/pbes2-aes-128-aes-128-sha512.p12
new file mode 100644
index 00000000000..f499da1fa0e
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-128-aes-128-sha512.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-128-aes-192-sha1.p12 b/luni/src/test/resources/keystore/pbes2-aes-128-aes-192-sha1.p12
new file mode 100644
index 00000000000..d69e3aa5b41
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-128-aes-192-sha1.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-128-aes-192-sha224.p12 b/luni/src/test/resources/keystore/pbes2-aes-128-aes-192-sha224.p12
new file mode 100644
index 00000000000..67b3380e324
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-128-aes-192-sha224.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-128-aes-192-sha256.p12 b/luni/src/test/resources/keystore/pbes2-aes-128-aes-192-sha256.p12
new file mode 100644
index 00000000000..1fc3f548abf
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-128-aes-192-sha256.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-128-aes-192-sha384.p12 b/luni/src/test/resources/keystore/pbes2-aes-128-aes-192-sha384.p12
new file mode 100644
index 00000000000..195c0ca7581
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-128-aes-192-sha384.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-128-aes-192-sha512.p12 b/luni/src/test/resources/keystore/pbes2-aes-128-aes-192-sha512.p12
new file mode 100644
index 00000000000..4b49cd4cfad
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-128-aes-192-sha512.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-128-aes-256-sha1.p12 b/luni/src/test/resources/keystore/pbes2-aes-128-aes-256-sha1.p12
new file mode 100644
index 00000000000..f728c43c2f3
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-128-aes-256-sha1.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-128-aes-256-sha224.p12 b/luni/src/test/resources/keystore/pbes2-aes-128-aes-256-sha224.p12
new file mode 100644
index 00000000000..e2bac979838
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-128-aes-256-sha224.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-128-aes-256-sha256.p12 b/luni/src/test/resources/keystore/pbes2-aes-128-aes-256-sha256.p12
new file mode 100644
index 00000000000..3b864848b5b
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-128-aes-256-sha256.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-128-aes-256-sha384.p12 b/luni/src/test/resources/keystore/pbes2-aes-128-aes-256-sha384.p12
new file mode 100644
index 00000000000..e08afacb584
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-128-aes-256-sha384.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-128-aes-256-sha512.p12 b/luni/src/test/resources/keystore/pbes2-aes-128-aes-256-sha512.p12
new file mode 100644
index 00000000000..dfaf763ab98
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-128-aes-256-sha512.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-192-aes-128-sha1.p12 b/luni/src/test/resources/keystore/pbes2-aes-192-aes-128-sha1.p12
new file mode 100644
index 00000000000..049ac78ac4d
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-192-aes-128-sha1.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-192-aes-128-sha224.p12 b/luni/src/test/resources/keystore/pbes2-aes-192-aes-128-sha224.p12
new file mode 100644
index 00000000000..25f0d269e85
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-192-aes-128-sha224.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-192-aes-128-sha256.p12 b/luni/src/test/resources/keystore/pbes2-aes-192-aes-128-sha256.p12
new file mode 100644
index 00000000000..ab96aa649f9
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-192-aes-128-sha256.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-192-aes-128-sha384.p12 b/luni/src/test/resources/keystore/pbes2-aes-192-aes-128-sha384.p12
new file mode 100644
index 00000000000..85b5e40faad
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-192-aes-128-sha384.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-192-aes-128-sha512.p12 b/luni/src/test/resources/keystore/pbes2-aes-192-aes-128-sha512.p12
new file mode 100644
index 00000000000..81bc86edee6
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-192-aes-128-sha512.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-192-aes-192-sha1.p12 b/luni/src/test/resources/keystore/pbes2-aes-192-aes-192-sha1.p12
new file mode 100644
index 00000000000..df180109012
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-192-aes-192-sha1.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-192-aes-192-sha224.p12 b/luni/src/test/resources/keystore/pbes2-aes-192-aes-192-sha224.p12
new file mode 100644
index 00000000000..c4e3c8f9c89
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-192-aes-192-sha224.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-192-aes-192-sha256.p12 b/luni/src/test/resources/keystore/pbes2-aes-192-aes-192-sha256.p12
new file mode 100644
index 00000000000..35937648c6f
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-192-aes-192-sha256.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-192-aes-192-sha384.p12 b/luni/src/test/resources/keystore/pbes2-aes-192-aes-192-sha384.p12
new file mode 100644
index 00000000000..2d978044269
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-192-aes-192-sha384.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-192-aes-192-sha512.p12 b/luni/src/test/resources/keystore/pbes2-aes-192-aes-192-sha512.p12
new file mode 100644
index 00000000000..36ce440b768
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-192-aes-192-sha512.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-192-aes-256-sha1.p12 b/luni/src/test/resources/keystore/pbes2-aes-192-aes-256-sha1.p12
new file mode 100644
index 00000000000..feeb995fc57
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-192-aes-256-sha1.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-192-aes-256-sha224.p12 b/luni/src/test/resources/keystore/pbes2-aes-192-aes-256-sha224.p12
new file mode 100644
index 00000000000..1ac50be806f
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-192-aes-256-sha224.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-192-aes-256-sha256.p12 b/luni/src/test/resources/keystore/pbes2-aes-192-aes-256-sha256.p12
new file mode 100644
index 00000000000..46975cd2fd4
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-192-aes-256-sha256.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-192-aes-256-sha384.p12 b/luni/src/test/resources/keystore/pbes2-aes-192-aes-256-sha384.p12
new file mode 100644
index 00000000000..08a76694dde
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-192-aes-256-sha384.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-192-aes-256-sha512.p12 b/luni/src/test/resources/keystore/pbes2-aes-192-aes-256-sha512.p12
new file mode 100644
index 00000000000..e557c94a2d8
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-192-aes-256-sha512.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-256-aes-128-sha1.p12 b/luni/src/test/resources/keystore/pbes2-aes-256-aes-128-sha1.p12
new file mode 100644
index 00000000000..3218d657949
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-256-aes-128-sha1.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-256-aes-128-sha224.p12 b/luni/src/test/resources/keystore/pbes2-aes-256-aes-128-sha224.p12
new file mode 100644
index 00000000000..a20a1bcf612
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-256-aes-128-sha224.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-256-aes-128-sha256.p12 b/luni/src/test/resources/keystore/pbes2-aes-256-aes-128-sha256.p12
new file mode 100644
index 00000000000..1a3e11137e5
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-256-aes-128-sha256.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-256-aes-128-sha384.p12 b/luni/src/test/resources/keystore/pbes2-aes-256-aes-128-sha384.p12
new file mode 100644
index 00000000000..ab59494753e
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-256-aes-128-sha384.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-256-aes-128-sha512.p12 b/luni/src/test/resources/keystore/pbes2-aes-256-aes-128-sha512.p12
new file mode 100644
index 00000000000..82c3a21bbaf
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-256-aes-128-sha512.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-256-aes-192-sha1.p12 b/luni/src/test/resources/keystore/pbes2-aes-256-aes-192-sha1.p12
new file mode 100644
index 00000000000..4f0e33615ac
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-256-aes-192-sha1.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-256-aes-192-sha224.p12 b/luni/src/test/resources/keystore/pbes2-aes-256-aes-192-sha224.p12
new file mode 100644
index 00000000000..fa059032598
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-256-aes-192-sha224.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-256-aes-192-sha256.p12 b/luni/src/test/resources/keystore/pbes2-aes-256-aes-192-sha256.p12
new file mode 100644
index 00000000000..83fb514c69b
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-256-aes-192-sha256.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-256-aes-192-sha384.p12 b/luni/src/test/resources/keystore/pbes2-aes-256-aes-192-sha384.p12
new file mode 100644
index 00000000000..943b6c25f79
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-256-aes-192-sha384.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-256-aes-192-sha512.p12 b/luni/src/test/resources/keystore/pbes2-aes-256-aes-192-sha512.p12
new file mode 100644
index 00000000000..4bb85f5d6c5
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-256-aes-192-sha512.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-256-aes-256-sha1.p12 b/luni/src/test/resources/keystore/pbes2-aes-256-aes-256-sha1.p12
new file mode 100644
index 00000000000..194c6267bed
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-256-aes-256-sha1.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-256-aes-256-sha224.p12 b/luni/src/test/resources/keystore/pbes2-aes-256-aes-256-sha224.p12
new file mode 100644
index 00000000000..a5cdbaa0e31
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-256-aes-256-sha224.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-256-aes-256-sha256.p12 b/luni/src/test/resources/keystore/pbes2-aes-256-aes-256-sha256.p12
new file mode 100644
index 00000000000..0f8c39115bf
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-256-aes-256-sha256.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-256-aes-256-sha384.p12 b/luni/src/test/resources/keystore/pbes2-aes-256-aes-256-sha384.p12
new file mode 100644
index 00000000000..65f940a150c
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-256-aes-256-sha384.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/pbes2-aes-256-aes-256-sha512.p12 b/luni/src/test/resources/keystore/pbes2-aes-256-aes-256-sha512.p12
new file mode 100644
index 00000000000..ac32f8fbc44
--- /dev/null
+++ b/luni/src/test/resources/keystore/pbes2-aes-256-aes-256-sha512.p12
Binary files differ
diff --git a/luni/src/test/resources/keystore/privkey.pem b/luni/src/test/resources/keystore/privkey.pem
new file mode 100644
index 00000000000..60dc0f052c8
--- /dev/null
+++ b/luni/src/test/resources/keystore/privkey.pem
@@ -0,0 +1,16 @@
+-----BEGIN PRIVATE KEY-----
+MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAKFymFD/KEjOXlt2
+krg8+vr3f0k4BS+2FX+++6FTn3IJNLelCgq+LE8dhiWCQSsIEAY3ElpKaEt5FQwT
+fj2GjTqFsadPqbw2mukuT+RoNoekK92oOG0ur48ceSW07CsOcLj5fsiDYQIxks3A
+KyyWrhM9BQAg0sUMvRUHY0j1SL4jAgMBAAECgYEAmrox4kZ3/DbT1YJxIONIgiea
+tLhcuBogxpppnHaBNBBAltQ0KJGT84rPGrmX7T6/5MT48NGo3NRBaJ5x+VMvm2X2
+Z1OCePuc1ZMmgnHzsbQLuzH5aajD1wLwyYCTmQl1cUOH+Qw38axkFMkKfDgveSax
+LW2H7VMrbFYiie3KeSkCQQDOb7hOSQHodxsyo02m00LyrwOu7g/o6RfC4YNLm5js
+rO9egrRBRFB99wTLcB+iSZ+HQvWzch8S6xbl/kWg7TatAkEAyDW2ifbldcD39dhq
+AC8N1VyOugbZcle2zb4bzx7x4rWe+ekFrZvKsomfTevevGIhp4HpLHCNim6z9LQS
+bd/yDwJAMT4jF8GAjARFX5nmvwGr+ZnX5hVxhBx+B4WlvRZbrzE9VC0XdG4oSTPw
+V9riIOMxA6HsXCa/1NJxPuGdmFqdbQJBAIajoJtNX2h+GgLJxBdVjX8D3LP7sTX1
+COl5xKfYTqDAtSWpcHkdAQZqCKjVS5fygmFsuwt4sab75adVheNALD8CQBDzw8HR
+YhwauMYGxvWZmSTmNDVW93ouBFnO+uweVZhqMqztRu2bUkXUbwJJchddOWL2Jx1S
+vguQtWRnq9yfNgQ=
+-----END PRIVATE KEY-----
diff --git a/luni/src/test/resources/keystore/sha3.p12 b/luni/src/test/resources/keystore/sha3.p12
new file mode 100644
index 00000000000..f1e32dfe4e9
--- /dev/null
+++ b/luni/src/test/resources/keystore/sha3.p12
Binary files differ