use of java.security.KeyStore.TrustedCertificateEntry in project platform_frameworks_base by android.
the class AndroidKeyStoreTest method testKeyStore_SetEntry_CAEntry_Overwrites_CAEntry_Encrypted_Success.
public void testKeyStore_SetEntry_CAEntry_Overwrites_CAEntry_Encrypted_Success() throws Exception {
setupPassword();
mKeyStore.load(null, null);
final CertificateFactory f = CertificateFactory.getInstance("X.509");
// Insert TrustedCertificateEntry
{
final Certificate caCert = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_CA_1));
TrustedCertificateEntry expectedCertEntry = new TrustedCertificateEntry(caCert);
mKeyStore.setEntry(TEST_ALIAS_1, expectedCertEntry, null);
Entry actualEntry = mKeyStore.getEntry(TEST_ALIAS_1, null);
assertNotNull("Retrieved entry should exist", actualEntry);
assertTrue("Retrieved entry should be of type TrustedCertificateEntry", actualEntry instanceof TrustedCertificateEntry);
TrustedCertificateEntry actualCertEntry = (TrustedCertificateEntry) actualEntry;
assertEquals("Stored and retrieved certificates should be the same", expectedCertEntry.getTrustedCertificate(), actualCertEntry.getTrustedCertificate());
}
// Replace with TrustedCertificateEntry of USER
{
final Certificate userCert = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_USER_1));
TrustedCertificateEntry expectedUserEntry = new TrustedCertificateEntry(userCert);
mKeyStore.setEntry(TEST_ALIAS_1, expectedUserEntry, null);
Entry actualEntry = mKeyStore.getEntry(TEST_ALIAS_1, null);
assertNotNull("Retrieved entry should exist", actualEntry);
assertTrue("Retrieved entry should be of type TrustedCertificateEntry", actualEntry instanceof TrustedCertificateEntry);
TrustedCertificateEntry actualUserEntry = (TrustedCertificateEntry) actualEntry;
assertEquals("Stored and retrieved certificates should be the same", expectedUserEntry.getTrustedCertificate(), actualUserEntry.getTrustedCertificate());
}
}
use of java.security.KeyStore.TrustedCertificateEntry in project android_frameworks_base by AOSPA.
the class AndroidKeyStoreTest method testKeyStore_SetEntry_CAEntry_Overwrites_CAEntry_Encrypted_Success.
public void testKeyStore_SetEntry_CAEntry_Overwrites_CAEntry_Encrypted_Success() throws Exception {
setupPassword();
mKeyStore.load(null, null);
final CertificateFactory f = CertificateFactory.getInstance("X.509");
// Insert TrustedCertificateEntry
{
final Certificate caCert = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_CA_1));
TrustedCertificateEntry expectedCertEntry = new TrustedCertificateEntry(caCert);
mKeyStore.setEntry(TEST_ALIAS_1, expectedCertEntry, null);
Entry actualEntry = mKeyStore.getEntry(TEST_ALIAS_1, null);
assertNotNull("Retrieved entry should exist", actualEntry);
assertTrue("Retrieved entry should be of type TrustedCertificateEntry", actualEntry instanceof TrustedCertificateEntry);
TrustedCertificateEntry actualCertEntry = (TrustedCertificateEntry) actualEntry;
assertEquals("Stored and retrieved certificates should be the same", expectedCertEntry.getTrustedCertificate(), actualCertEntry.getTrustedCertificate());
}
// Replace with TrustedCertificateEntry of USER
{
final Certificate userCert = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_USER_1));
TrustedCertificateEntry expectedUserEntry = new TrustedCertificateEntry(userCert);
mKeyStore.setEntry(TEST_ALIAS_1, expectedUserEntry, null);
Entry actualEntry = mKeyStore.getEntry(TEST_ALIAS_1, null);
assertNotNull("Retrieved entry should exist", actualEntry);
assertTrue("Retrieved entry should be of type TrustedCertificateEntry", actualEntry instanceof TrustedCertificateEntry);
TrustedCertificateEntry actualUserEntry = (TrustedCertificateEntry) actualEntry;
assertEquals("Stored and retrieved certificates should be the same", expectedUserEntry.getTrustedCertificate(), actualUserEntry.getTrustedCertificate());
}
}
use of java.security.KeyStore.TrustedCertificateEntry in project android_frameworks_base by DirtyUnicorns.
the class AndroidKeyStoreTest method testKeyStore_SetEntry_CAEntry_Overwrites_CAEntry_Encrypted_Success.
public void testKeyStore_SetEntry_CAEntry_Overwrites_CAEntry_Encrypted_Success() throws Exception {
setupPassword();
mKeyStore.load(null, null);
final CertificateFactory f = CertificateFactory.getInstance("X.509");
// Insert TrustedCertificateEntry
{
final Certificate caCert = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_CA_1));
TrustedCertificateEntry expectedCertEntry = new TrustedCertificateEntry(caCert);
mKeyStore.setEntry(TEST_ALIAS_1, expectedCertEntry, null);
Entry actualEntry = mKeyStore.getEntry(TEST_ALIAS_1, null);
assertNotNull("Retrieved entry should exist", actualEntry);
assertTrue("Retrieved entry should be of type TrustedCertificateEntry", actualEntry instanceof TrustedCertificateEntry);
TrustedCertificateEntry actualCertEntry = (TrustedCertificateEntry) actualEntry;
assertEquals("Stored and retrieved certificates should be the same", expectedCertEntry.getTrustedCertificate(), actualCertEntry.getTrustedCertificate());
}
// Replace with TrustedCertificateEntry of USER
{
final Certificate userCert = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_USER_1));
TrustedCertificateEntry expectedUserEntry = new TrustedCertificateEntry(userCert);
mKeyStore.setEntry(TEST_ALIAS_1, expectedUserEntry, null);
Entry actualEntry = mKeyStore.getEntry(TEST_ALIAS_1, null);
assertNotNull("Retrieved entry should exist", actualEntry);
assertTrue("Retrieved entry should be of type TrustedCertificateEntry", actualEntry instanceof TrustedCertificateEntry);
TrustedCertificateEntry actualUserEntry = (TrustedCertificateEntry) actualEntry;
assertEquals("Stored and retrieved certificates should be the same", expectedUserEntry.getTrustedCertificate(), actualUserEntry.getTrustedCertificate());
}
}
use of java.security.KeyStore.TrustedCertificateEntry in project android_frameworks_base by DirtyUnicorns.
the class AndroidKeyStoreTest method testKeyStore_SetEntry_CAEntry_Overwrites_PrivateKeyEntry_Encrypted_Success.
public void testKeyStore_SetEntry_CAEntry_Overwrites_PrivateKeyEntry_Encrypted_Success() throws Exception {
setupPassword();
mKeyStore.load(null, null);
final CertificateFactory f = CertificateFactory.getInstance("X.509");
// Start with TrustedCertificateEntry
{
final Certificate caCert = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_CA_1));
TrustedCertificateEntry expectedCertEntry = new TrustedCertificateEntry(caCert);
mKeyStore.setEntry(TEST_ALIAS_1, expectedCertEntry, null);
Entry actualEntry = mKeyStore.getEntry(TEST_ALIAS_1, null);
assertNotNull("Retrieved entry should exist", actualEntry);
assertTrue("Retrieved entry should be of type TrustedCertificateEntry", actualEntry instanceof TrustedCertificateEntry);
TrustedCertificateEntry actualCertEntry = (TrustedCertificateEntry) actualEntry;
assertEquals("Stored and retrieved certificates should be the same", expectedCertEntry.getTrustedCertificate(), actualCertEntry.getTrustedCertificate());
}
// Replace with PrivateKeyEntry
{
KeyFactory keyFact = KeyFactory.getInstance("RSA");
PrivateKey expectedKey = keyFact.generatePrivate(new PKCS8EncodedKeySpec(FAKE_RSA_KEY_1));
final Certificate[] expectedChain = new Certificate[2];
expectedChain[0] = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_USER_1));
expectedChain[1] = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_CA_1));
PrivateKeyEntry expectedPrivEntry = new PrivateKeyEntry(expectedKey, expectedChain);
mKeyStore.setEntry(TEST_ALIAS_1, expectedPrivEntry, null);
Entry actualEntry = mKeyStore.getEntry(TEST_ALIAS_1, null);
assertNotNull("Retrieved entry should exist", actualEntry);
assertTrue("Retrieved entry should be of type PrivateKeyEntry", actualEntry instanceof PrivateKeyEntry);
PrivateKeyEntry actualPrivEntry = (PrivateKeyEntry) actualEntry;
assertPrivateKeyEntryEquals(actualPrivEntry, "RSA", FAKE_RSA_KEY_1, FAKE_RSA_USER_1, FAKE_RSA_CA_1);
}
}
use of java.security.KeyStore.TrustedCertificateEntry in project android_frameworks_base by ResurrectionRemix.
the class AndroidKeyStoreTest method testKeyStore_SetEntry_CAEntry_Overwrites_CAEntry_Encrypted_Success.
public void testKeyStore_SetEntry_CAEntry_Overwrites_CAEntry_Encrypted_Success() throws Exception {
setupPassword();
mKeyStore.load(null, null);
final CertificateFactory f = CertificateFactory.getInstance("X.509");
// Insert TrustedCertificateEntry
{
final Certificate caCert = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_CA_1));
TrustedCertificateEntry expectedCertEntry = new TrustedCertificateEntry(caCert);
mKeyStore.setEntry(TEST_ALIAS_1, expectedCertEntry, null);
Entry actualEntry = mKeyStore.getEntry(TEST_ALIAS_1, null);
assertNotNull("Retrieved entry should exist", actualEntry);
assertTrue("Retrieved entry should be of type TrustedCertificateEntry", actualEntry instanceof TrustedCertificateEntry);
TrustedCertificateEntry actualCertEntry = (TrustedCertificateEntry) actualEntry;
assertEquals("Stored and retrieved certificates should be the same", expectedCertEntry.getTrustedCertificate(), actualCertEntry.getTrustedCertificate());
}
// Replace with TrustedCertificateEntry of USER
{
final Certificate userCert = f.generateCertificate(new ByteArrayInputStream(FAKE_RSA_USER_1));
TrustedCertificateEntry expectedUserEntry = new TrustedCertificateEntry(userCert);
mKeyStore.setEntry(TEST_ALIAS_1, expectedUserEntry, null);
Entry actualEntry = mKeyStore.getEntry(TEST_ALIAS_1, null);
assertNotNull("Retrieved entry should exist", actualEntry);
assertTrue("Retrieved entry should be of type TrustedCertificateEntry", actualEntry instanceof TrustedCertificateEntry);
TrustedCertificateEntry actualUserEntry = (TrustedCertificateEntry) actualEntry;
assertEquals("Stored and retrieved certificates should be the same", expectedUserEntry.getTrustedCertificate(), actualUserEntry.getTrustedCertificate());
}
}
Aggregations