use of java.security.UnrecoverableEntryException in project OpenAttestation by OpenAttestation.
the class SslUtil method createX509TrustManagerWithCertificates.
public static X509TrustManager createX509TrustManagerWithCertificates(X509Certificate[] certificates) throws KeyManagementException {
try {
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(createTrustedSslKeystore(certificates));
TrustManager[] tms = tmf.getTrustManagers();
for (TrustManager tm : tms) {
if (tm instanceof X509TrustManager) {
return (X509TrustManager) tm;
}
}
} catch (NoSuchAlgorithmException e) {
throw new KeyManagementException("Cannot create X509TrustManager", e);
} catch (IOException e) {
throw new KeyManagementException("Cannot create X509TrustManager", e);
} catch (CertificateException e) {
throw new KeyManagementException("Cannot create X509TrustManager", e);
} catch (UnrecoverableEntryException e) {
throw new KeyManagementException("Cannot create X509TrustManager", e);
} catch (KeyStoreException e) {
throw new KeyManagementException("Cannot create X509TrustManager", e);
}
throw new IllegalArgumentException("TrustManagerFactory did not return an X509TrustManager instance");
}
use of java.security.UnrecoverableEntryException in project OpenAttestation by OpenAttestation.
the class X509Util method createX509TrustManagerWithKeystore.
/**
* @deprecated use TlsPolicy instead
* @param keystore
* @return
* @throws KeyManagementException
*/
public static X509TrustManager createX509TrustManagerWithKeystore(SimpleKeystore keystore) throws KeyManagementException {
try {
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(KeyStoreUtil.createTrustedSslKeystore(keystore));
TrustManager[] tms = tmf.getTrustManagers();
for (TrustManager tm : tms) {
if (tm instanceof X509TrustManager) {
return (X509TrustManager) tm;
}
}
} catch (NoSuchAlgorithmException | IOException | CertificateException | UnrecoverableEntryException | KeyStoreException e) {
throw new KeyManagementException("Cannot create X509TrustManager", e);
}
throw new IllegalArgumentException("TrustManagerFactory did not return an X509TrustManager instance");
}
use of java.security.UnrecoverableEntryException in project OpenAttestation by OpenAttestation.
the class X509Util method createX509TrustManagerWithCertificates.
/**
*
* @deprecated use TlsPolicy instead
* @param certificates
* @return
* @throws KeyManagementException
*/
public static X509TrustManager createX509TrustManagerWithCertificates(X509Certificate[] certificates) throws KeyManagementException {
try {
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(KeyStoreUtil.createTrustedSslKeystore(certificates));
TrustManager[] tms = tmf.getTrustManagers();
for (TrustManager tm : tms) {
if (tm instanceof X509TrustManager) {
return (X509TrustManager) tm;
}
}
} catch (NoSuchAlgorithmException | IOException | CertificateException | UnrecoverableEntryException | KeyStoreException e) {
throw new KeyManagementException("Cannot create X509TrustManager", e);
}
throw new IllegalArgumentException("TrustManagerFactory did not return an X509TrustManager instance");
}
use of java.security.UnrecoverableEntryException in project robovm by robovm.
the class UnrecoverableEntryExceptionTest method testUnrecoverableEntryExceptionString.
/*
* Class under test for void UnrecoverableEntryException(String)
*/
public void testUnrecoverableEntryExceptionString() {
UnrecoverableEntryException tE;
for (int i = 0; i < msgs.length; i++) {
tE = new UnrecoverableEntryException(msgs[i]);
assertEquals("getMessage() must return: ".concat(msgs[i]), tE.getMessage(), msgs[i]);
assertNull("getCause() must return null", tE.getCause());
}
try {
tE = new UnrecoverableEntryException(null);
} catch (Exception e) {
fail("Exception " + e + " was thrown for NULL parameter");
}
}
use of java.security.UnrecoverableEntryException in project robovm by robovm.
the class KeyStore4Test method testGetEntry.
public void testGetEntry() {
try {
Entry entry = keyStore.getEntry("certalias", null);
assertNotNull("entry is null", entry);
assertTrue("entry is not cert entry", entry instanceof KeyStore.TrustedCertificateEntry);
} catch (NoSuchAlgorithmException e) {
fail("unexpected exception: " + e);
} catch (UnrecoverableEntryException e) {
fail("unexpected exception: " + e);
} catch (KeyStoreException e) {
fail("unexpected exception: " + e);
}
try {
Entry entry = keyStore.getEntry("certalias", new KeyStore.ProtectionParameter() {
});
assertNotNull(entry);
} catch (NoSuchAlgorithmException e) {
fail("unexpected exception: " + e);
} catch (UnrecoverableEntryException e) {
fail("unexpected exception: " + e);
} catch (KeyStoreException e) {
fail("unexpected exception: " + e);
} catch (UnsupportedOperationException e) {
// ok
}
try {
Entry entry = keyStore.getEntry("keyalias", new KeyStore.PasswordProtection(new char[] {}));
assertNotNull(entry);
assertTrue(entry instanceof KeyStore.SecretKeyEntry);
} catch (NoSuchAlgorithmException e) {
fail("unexpected exception: " + e);
} catch (UnrecoverableEntryException e) {
fail("unexpected exception: " + e);
} catch (KeyStoreException e) {
fail("unexpected exception: " + e);
}
try {
keyStore.getEntry("unknownalias", new KeyStore.PasswordProtection(new char[] {}));
fail("expected NoSuchAlgorithmException");
} catch (NoSuchAlgorithmException e) {
// ok
} catch (UnrecoverableEntryException e) {
fail("unexpected exception: " + e);
} catch (KeyStoreException e) {
fail("unexpected exception: " + e);
} catch (UnsupportedOperationException e) {
// also ok
}
try {
keyStore.getEntry(null, new KeyStore.ProtectionParameter() {
});
fail("expected NullPointerException");
} catch (NoSuchAlgorithmException e) {
fail("unexpected exception: " + e);
} catch (UnrecoverableEntryException e) {
fail("unexpected exception: " + e);
} catch (KeyStoreException e) {
fail("unexpected exception: " + e);
} catch (NullPointerException e) {
// ok
}
}
Aggregations