use of java.security.KeyStoreSpi in project robovm by robovm.
the class MyCertificate method test_KeyStoreSpi.
@SuppressWarnings("cast")
public void test_KeyStoreSpi() {
try {
MyKeyStoreSpi ksSpi = new MyKeyStoreSpi();
assertNotNull(ksSpi);
assertTrue(ksSpi instanceof KeyStoreSpi);
} catch (Exception ex) {
fail("Unexpected exception");
}
}
use of java.security.KeyStoreSpi in project robovm by robovm.
the class MyCertificate method testKeyStoreSpi02.
/**
* Test for <code>KeyStoreSpi()</code> constructor and abstract engine
* methods. Assertion: creates new KeyStoreSpi object.
*/
public void testKeyStoreSpi02() throws NoSuchAlgorithmException, UnrecoverableKeyException, CertificateException {
KeyStoreSpi ksSpi = new MyKeyStoreSpi();
assertNull("engineGetKey(..) must return null", ksSpi.engineGetKey("", new char[0]));
assertNull("engineGetCertificateChain(..) must return null", ksSpi.engineGetCertificateChain(""));
assertNull("engineGetCertificate(..) must return null", ksSpi.engineGetCertificate(""));
assertEquals("engineGetCreationDate(..) must return Date(0)", new Date(0), ksSpi.engineGetCreationDate(""));
try {
ksSpi.engineSetKeyEntry("", null, new char[0], new Certificate[0]);
fail("KeyStoreException must be thrown from engineSetKeyEntry(..)");
} catch (KeyStoreException expected) {
}
try {
ksSpi.engineSetKeyEntry("", new byte[0], new Certificate[0]);
fail("KeyStoreException must be thrown from engineSetKeyEntry(..)");
} catch (KeyStoreException expected) {
}
try {
ksSpi.engineSetCertificateEntry("", null);
fail("KeyStoreException must be thrown " + "from engineSetCertificateEntry(..)");
} catch (KeyStoreException expected) {
}
try {
ksSpi.engineDeleteEntry("");
fail("KeyStoreException must be thrown from engineDeleteEntry(..)");
} catch (KeyStoreException expected) {
}
assertNull("engineAliases() must return null", ksSpi.engineAliases());
assertFalse("engineContainsAlias(..) must return false", ksSpi.engineContainsAlias(""));
assertEquals("engineSize() must return 0", 0, ksSpi.engineSize());
try {
ksSpi.engineStore(null, null);
fail("IOException must be thrown");
} catch (IOException expected) {
}
}
use of java.security.KeyStoreSpi in project robovm by robovm.
the class MyCertificate method testKeyStoreSpi01.
public void testKeyStoreSpi01() throws IOException, NoSuchAlgorithmException, CertificateException, UnrecoverableEntryException, KeyStoreException {
final boolean[] keyEntryWasSet = new boolean[1];
KeyStoreSpi ksSpi = new MyKeyStoreSpi() {
@Override
public void engineSetKeyEntry(String alias, Key key, char[] password, Certificate[] chain) throws KeyStoreException {
keyEntryWasSet[0] = true;
}
};
BadKeyStoreEntry badEntry = new BadKeyStoreEntry();
BadKeyStoreProtectionParameter badParameter = new BadKeyStoreProtectionParameter();
KeyStore.SecretKeyEntry dummyEntry = new KeyStore.SecretKeyEntry(new SecretKey() {
@Override
public String getAlgorithm() {
return null;
}
@Override
public String getFormat() {
return null;
}
@Override
public byte[] getEncoded() {
return null;
}
});
try {
ksSpi.engineStore(null);
} catch (UnsupportedOperationException expected) {
}
assertNull("Not null entry", ksSpi.engineGetEntry("aaa", null));
assertNull("Not null entry", ksSpi.engineGetEntry(null, badParameter));
assertNull("Not null entry", ksSpi.engineGetEntry("aaa", badParameter));
try {
ksSpi.engineSetEntry("", null, null);
fail("KeyStoreException or NullPointerException must be thrown");
} catch (KeyStoreException expected) {
} catch (NullPointerException expected) {
}
try {
ksSpi.engineSetEntry("", new KeyStore.TrustedCertificateEntry(new MyCertificate("type", new byte[0])), null);
fail("KeyStoreException must be thrown");
} catch (KeyStoreException expected) {
}
try {
ksSpi.engineSetEntry("aaa", badEntry, null);
fail("KeyStoreException must be thrown");
} catch (KeyStoreException expected) {
}
ksSpi.engineSetEntry("aaa", dummyEntry, null);
assertTrue(keyEntryWasSet[0]);
}
use of java.security.KeyStoreSpi in project robovm by robovm.
the class MyCertificate method test_engineEntryInstanceOf.
/*
* java.security.KeyStore.engineEntryInstanceOf(String, Class<?
* extends Entry>)
*/
public void test_engineEntryInstanceOf() throws Exception {
KeyStoreSpi ksSpi = new MyKeyStoreSpi();
assertTrue(ksSpi.engineEntryInstanceOf("test_engineEntryInstanceOf_Alias1", KeyStore.PrivateKeyEntry.class));
assertFalse(ksSpi.engineEntryInstanceOf("test_engineEntryInstanceOf_Alias2", KeyStore.SecretKeyEntry.class));
assertFalse(ksSpi.engineEntryInstanceOf("test_engineEntryInstanceOf_Alias3", KeyStore.TrustedCertificateEntry.class));
try {
assertFalse(ksSpi.engineEntryInstanceOf(null, KeyStore.TrustedCertificateEntry.class));
} catch (NullPointerException expected) {
}
try {
assertFalse(ksSpi.engineEntryInstanceOf("test_engineEntryInstanceOf_Alias1", null));
} catch (NullPointerException expected) {
}
}
use of java.security.KeyStoreSpi in project robovm by robovm.
the class MyCertificate method test_engineLoadLjava_security_KeyStore_LoadStoreParameter.
/**
* java.security.KeyStoreSpi#engineLoad(KeyStore.LoadStoreParameter)
*/
public void test_engineLoadLjava_security_KeyStore_LoadStoreParameter() throws Exception {
final String msg = "error";
KeyStoreSpi ksSpi = new MyKeyStoreSpi() {
public void engineLoad(InputStream stream, char[] password) {
assertNull(stream);
assertNull(password);
throw new RuntimeException(msg);
}
};
try {
ksSpi.engineLoad(null);
fail("Should throw exception");
} catch (RuntimeException expected) {
assertSame(msg, expected.getMessage());
}
// test: protection parameter is null
try {
ksSpi.engineLoad(new MyLoadStoreParams(null));
fail("No expected UnsupportedOperationException");
} catch (UnsupportedOperationException expected) {
}
// PasswordProtection or CallbackHandlerProtection
try {
ksSpi.engineLoad(new MyLoadStoreParams(new BadKeyStoreProtectionParameter()));
fail("No expected UnsupportedOperationException");
} catch (UnsupportedOperationException expected) {
}
}
Aggregations