use of java.security.NoSuchProviderException in project robovm by robovm.
the class X509CertificateTest method testVerifyPublicKey.
/**
* @throws SignatureException
* @throws NoSuchProviderException
* @throws NoSuchAlgorithmException
* @throws InvalidKeyException
* @throws CertificateException
* {@link Certificate#verify(PublicKey)}
*/
@SideEffect("Destroys MD5 provider, hurts succeeding tests")
public void testVerifyPublicKey() throws InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException, SignatureException, CertificateException {
// Preconditions
assertNotNull(javaxCert.getPublicKey());
assertNotNull(javaxSSCert.getPublicKey());
// here not self signed:
try {
javaxCert.verify(javaxCert.getPublicKey());
} catch (SignatureException e) {
// ok
}
PublicKey k = javaxCert.getPublicKey();
MyModifiablePublicKey changedEncoding = new MyModifiablePublicKey(k);
changedEncoding.setEncoding(new byte[javaxCert.getEncoded().length - 1]);
try {
javaxCert.verify(tbt_cert.getPublicKey());
} catch (InvalidKeyException e) {
// ok
}
try {
javaxCert.verify(null);
} catch (Exception e) {
// ok
}
try {
javaxCert.verify(changedEncoding);
fail("Exception expected");
} catch (Exception e) {
// ok
}
// following test doesn't work because the algorithm is derived from
// somewhere else.
// MyModifiablePublicKey changedAlgo = new MyModifiablePublicKey(k);
// changedAlgo.setAlgorithm("MD5withBla");
// try {
// javaxCert.verify(changedAlgo);
// fail("Exception expected");
// } catch (SignatureException e) {
// // ok
// }
// Security.removeProvider(mySSProvider.getName());
// try {
// javaxSSCert.verify(javaxSSCert.getPublicKey());
// } catch (NoSuchProviderException e) {
// // ok
// }
// Security.addProvider(mySSProvider);
// must always evaluate true for self signed
// javaxSSCert.verify(javaxSSCert.getPublicKey());
}
use of java.security.NoSuchProviderException in project robovm by robovm.
the class TrustManagerFactory2Test method test_getInstanceLjava_lang_StringLjava_lang_String.
/**
* Test for <code>getInstance(String algorithm, String provider)</code>
* method
* Assertions:
* throws NullPointerException when algorithm is null;
* throws NoSuchAlgorithmException when algorithm is not correct;
* throws IllegalArgumentException when provider is null or empty;
* throws NoSuchProviderException when provider is available;
* returns TrustManagerFactory object
*/
public void test_getInstanceLjava_lang_StringLjava_lang_String() throws Exception {
try {
TrustManagerFactory.getInstance(null, mProv.getName());
fail("NoSuchAlgorithmException or NullPointerException should be thrown (algorithm is null");
} catch (NoSuchAlgorithmException e) {
} catch (NullPointerException e) {
}
for (int i = 0; i < invalidValues.length; i++) {
try {
TrustManagerFactory.getInstance(invalidValues[i], mProv.getName());
fail("NoSuchAlgorithmException must be thrown (algorithm: ".concat(invalidValues[i]).concat(")"));
} catch (NoSuchAlgorithmException e) {
}
}
String prov = null;
for (int i = 0; i < validValues.length; i++) {
try {
TrustManagerFactory.getInstance(validValues[i], prov);
fail("IllegalArgumentException must be thrown when provider is null (algorithm: ".concat(invalidValues[i]).concat(")"));
} catch (IllegalArgumentException e) {
}
try {
TrustManagerFactory.getInstance(validValues[i], "");
fail("IllegalArgumentException must be thrown when provider is empty (algorithm: ".concat(invalidValues[i]).concat(")"));
} catch (IllegalArgumentException e) {
}
}
for (int i = 0; i < validValues.length; i++) {
for (int j = 1; j < invalidValues.length; j++) {
try {
TrustManagerFactory.getInstance(validValues[i], invalidValues[j]);
fail("NoSuchProviderException must be thrown (algorithm: ".concat(invalidValues[i]).concat(" provider: ").concat(invalidValues[j]).concat(")"));
} catch (NoSuchProviderException e) {
}
}
}
TrustManagerFactory tmf;
for (int i = 0; i < validValues.length; i++) {
tmf = TrustManagerFactory.getInstance(validValues[i], mProv.getName());
assertTrue("Not instanceof TrustManagerFactory object", tmf instanceof TrustManagerFactory);
assertEquals("Incorrect algorithm", tmf.getAlgorithm(), validValues[i]);
assertEquals("Incorrect provider", tmf.getProvider().getName(), mProv.getName());
checkResult(tmf);
}
}
use of java.security.NoSuchProviderException in project robovm by robovm.
the class KeyFactoryTest method testGetInstanceStringString.
@SuppressWarnings("unchecked")
public void testGetInstanceStringString() {
try {
KeyFactory factory = KeyFactory.getInstance(TEST_KEYFACTORY_NAME, TEST_PROVIDER_NAME);
assertNotNull(factory);
} catch (NoSuchAlgorithmException e) {
fail("unexpected exception: " + e);
} catch (NoSuchProviderException e) {
fail("unexpected exception: " + e);
}
String[][] combinations = { { "UnknownKeyFactory", TEST_PROVIDER_NAME }, { TEST_KEYFACTORY_NAME, "UnknownProvider" }, { TEST_KEYFACTORY_NAME, existingProvider.getName() }, { null, TEST_PROVIDER_NAME }, { TEST_KEYFACTORY_NAME, null }, { null, null } };
Class[] exceptions = { NoSuchAlgorithmException.class, NoSuchProviderException.class, NoSuchAlgorithmException.class, NullPointerException.class, IllegalArgumentException.class, IllegalArgumentException.class };
for (int i = 0; i < combinations.length; i++) {
String[] combination = combinations[i];
String message = "getInstance(\"" + combination[0] + "\", \"" + combination[1] + "\")";
exceptionThrown = false;
try {
KeyFactory.getInstance(combination[0], combination[1]);
} catch (Exception e) {
checkException(message, e, exceptions[i]);
} finally {
checkException(message, null, exceptions[i]);
}
}
}
use of java.security.NoSuchProviderException in project robovm by robovm.
the class CertPathBuilder2Test method testGetInstance02.
/**
* Test for <code>getInstance(String algorithm, String provider)</code> method
* Assertions:
* throws NullPointerException when algorithm is null
* throws NoSuchAlgorithmException when algorithm is not correct
* throws IllegalArgumentException when provider is null or empty;
* throws NoSuchProviderException when provider is available;
* returns CertPathBuilder object
*/
public void testGetInstance02() throws NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException, InvalidAlgorithmParameterException, CertPathBuilderException {
try {
CertPathBuilder.getInstance(null, mProv.getName());
fail("NullPointerException or NoSuchAlgorithmException must be thrown when algorithm is null");
} catch (NullPointerException e) {
} catch (NoSuchAlgorithmException e) {
}
for (int i = 0; i < invalidValues.length; i++) {
try {
CertPathBuilder.getInstance(invalidValues[i], mProv.getName());
fail("NoSuchAlgorithmException must be thrown (type: ".concat(invalidValues[i]).concat(")"));
} catch (NoSuchAlgorithmException e) {
}
}
String prov = null;
for (int i = 0; i < validValues.length; i++) {
try {
CertPathBuilder.getInstance(validValues[i], prov);
fail("IllegalArgumentException must be thrown when provider is null (type: ".concat(validValues[i]).concat(")"));
} catch (IllegalArgumentException e) {
}
try {
CertPathBuilder.getInstance(validValues[i], "");
fail("IllegalArgumentException must be thrown when provider is empty (type: ".concat(validValues[i]).concat(")"));
} catch (IllegalArgumentException e) {
}
}
for (int i = 0; i < validValues.length; i++) {
for (int j = 1; j < invalidValues.length; j++) {
try {
CertPathBuilder.getInstance(validValues[i], invalidValues[j]);
fail("NoSuchProviderException must be thrown (type: ".concat(validValues[i]).concat(" provider: ").concat(invalidValues[j]).concat(")"));
} catch (NoSuchProviderException e) {
}
}
}
CertPathBuilder cerPB;
for (int i = 0; i < validValues.length; i++) {
cerPB = CertPathBuilder.getInstance(validValues[i], mProv.getName());
assertEquals("Incorrect type", cerPB.getAlgorithm(), validValues[i]);
assertEquals("Incorrect provider", cerPB.getProvider().getName(), mProv.getName());
checkResult(cerPB);
}
}
use of java.security.NoSuchProviderException in project robovm by robovm.
the class KeyStore4Test method testGetInstanceStringString.
public void testGetInstanceStringString() {
try {
KeyStore ks = KeyStore.getInstance("TestKeyStore", provider.getName());
assertNotNull("keystore is null", ks);
assertEquals("KeyStore is not of expected type", "TestKeyStore", ks.getType());
} catch (KeyStoreException e) {
fail("unexpected exception: " + e);
} catch (NoSuchProviderException e) {
fail("unexpected exception: " + e);
}
try {
KeyStore.getInstance("UnknownKeyStore", provider.getName());
fail("expected KeyStoreException");
} catch (KeyStoreException e) {
// ok
} catch (NoSuchProviderException e) {
fail("unexpected exception: " + e);
}
try {
KeyStore.getInstance("TestKeyStore", (String) null);
fail("expected IllegalArgumentException");
} catch (KeyStoreException e) {
fail("unexpected exception: " + e);
} catch (NoSuchProviderException e) {
fail("unexpected exception: " + e);
} catch (IllegalArgumentException e) {
// ok
}
try {
KeyStore.getInstance("TestKeyStore", "");
fail("expected IllegalArgumentException");
} catch (KeyStoreException e) {
fail("unexpected exception: " + e);
} catch (NoSuchProviderException e) {
fail("unexpected exception: " + e);
} catch (IllegalArgumentException e) {
// ok
}
try {
KeyStore.getInstance(null, provider.getName());
fail("expected KeyStoreException");
} catch (KeyStoreException e) {
// ok
} catch (NoSuchProviderException e) {
fail("unexpected exception: " + e);
} catch (NullPointerException e) {
// also ok
}
try {
KeyStore.getInstance("TestKeyStore", "UnknownProvider");
fail("expected NoSuchProviderException");
} catch (NoSuchProviderException e) {
// ok
} catch (KeyStoreException e) {
fail("unexpected exception: " + e);
}
}
Aggregations