use of java.security.InvalidAlgorithmParameterException in project robovm by robovm.
the class PKIXBuilderParametersTest method testPKIXBuilderParametersKeyStoreCertSelector03.
/**
* Test #3 for <code>PKIXBuilderParameters(KeyStore, CertSelector)</code>
* constructor<br>
* Assertion: <code>InvalidAlgorithmParameterException</code> - if the
* <code>keystore</code> does not contain at least one trusted certificate
* entry
*/
public final void testPKIXBuilderParametersKeyStoreCertSelector03() throws Exception {
KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
keyTest.load(null, null);
try {
new PKIXBuilderParameters(keyTest, new X509CertSelector());
fail("InvalidAlgorithmParameterException expected");
} catch (InvalidAlgorithmParameterException e) {
// expected
}
}
use of java.security.InvalidAlgorithmParameterException in project robovm by robovm.
the class PKIXParametersTest method testKeyStoreConstructor.
public void testKeyStoreConstructor() throws Exception {
TestKeyStore server = TestKeyStore.getServer();
KeyStore.PrivateKeyEntry pke = server.getPrivateKey("RSA", "RSA");
char[] password = "password".toCharArray();
// contains CA and server certificates
assertEquals(2, new PKIXParameters(server.keyStore).getTrustAnchors().size());
// just copy server certificates
KeyStore ks = TestKeyStore.createKeyStore();
ks.setKeyEntry("key", pke.getPrivateKey(), password, pke.getCertificateChain());
ks.setCertificateEntry("cert", pke.getCertificateChain()[0]);
assertEquals(1, new PKIXParameters(ks).getTrustAnchors().size());
// should fail with just key, even though cert is present in key entry
try {
KeyStore keyOnly = TestKeyStore.createKeyStore();
keyOnly.setKeyEntry("key", pke.getPrivateKey(), password, pke.getCertificateChain());
new PKIXParameters(keyOnly);
fail();
} catch (InvalidAlgorithmParameterException expected) {
}
// should fail with empty KeyStore
try {
new PKIXParameters(TestKeyStore.createKeyStore());
fail();
} catch (InvalidAlgorithmParameterException expected) {
}
}
use of java.security.InvalidAlgorithmParameterException in project robovm by robovm.
the class KeyManagerFactoryTest method test_KeyManagerFactory.
private void test_KeyManagerFactory(KeyManagerFactory kmf) throws Exception {
assertNotNull(kmf);
assertNotNull(kmf.getAlgorithm());
assertNotNull(kmf.getProvider());
// before init
try {
kmf.getKeyManagers();
fail();
} catch (IllegalStateException expected) {
}
// init with null ManagerFactoryParameters
try {
kmf.init(null);
fail();
} catch (InvalidAlgorithmParameterException expected) {
}
// init with useless ManagerFactoryParameters
try {
kmf.init(new UselessManagerFactoryParameters());
fail();
} catch (InvalidAlgorithmParameterException expected) {
}
// init with KeyStoreBuilderParameters ManagerFactoryParameters
PasswordProtection pp = new PasswordProtection(getTestKeyStore().storePassword);
Builder builder = Builder.newInstance(getTestKeyStore().keyStore, pp);
KeyStoreBuilderParameters ksbp = new KeyStoreBuilderParameters(builder);
if (supportsManagerFactoryParameters(kmf.getAlgorithm())) {
kmf.init(ksbp);
test_KeyManagerFactory_getKeyManagers(kmf, false);
} else {
try {
kmf.init(ksbp);
fail();
} catch (InvalidAlgorithmParameterException expected) {
}
}
// init with null for default behavior
kmf.init(null, null);
test_KeyManagerFactory_getKeyManagers(kmf, true);
// init with specific key store and password
kmf.init(getTestKeyStore().keyStore, getTestKeyStore().storePassword);
test_KeyManagerFactory_getKeyManagers(kmf, false);
}
use of java.security.InvalidAlgorithmParameterException in project robovm by robovm.
the class ECDHKeyAgreementTest method testInit_withUnsupportedAlgorithmParameterSpec.
void testInit_withUnsupportedAlgorithmParameterSpec(Provider provider) throws Exception {
try {
getKeyAgreement(provider).init(KAT_PRIVATE_KEY1, new ECGenParameterSpec("prime256v1"));
fail();
} catch (InvalidAlgorithmParameterException expected) {
}
}
use of java.security.InvalidAlgorithmParameterException in project robovm by robovm.
the class CipherTest method test_initWithKeyAlgorithmParameters.
public void test_initWithKeyAlgorithmParameters() throws Exception {
AlgorithmParameterSpec ap = new IvParameterSpec(IV);
Cipher c = Cipher.getInstance("DES/CBC/PKCS5Padding");
c.init(Cipher.DECRYPT_MODE, CIPHER_KEY_DES, ap);
assertNotNull(c.getParameters());
try {
c.init(Cipher.DECRYPT_MODE, CIPHER_KEY_3DES, ap);
fail();
} catch (InvalidKeyException expected) {
}
try {
c.init(Cipher.DECRYPT_MODE, CIPHER_KEY_DES, (AlgorithmParameters) null);
fail();
} catch (InvalidAlgorithmParameterException expected) {
}
}
Aggregations