Search in sources :

Example 1 with UnrecoverableEntryException

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");
}
Also used : X509TrustManager(javax.net.ssl.X509TrustManager) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) UnrecoverableEntryException(java.security.UnrecoverableEntryException) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) KeyStoreException(java.security.KeyStoreException) KeyManagementException(java.security.KeyManagementException) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager)

Example 2 with UnrecoverableEntryException

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");
}
Also used : X509TrustManager(javax.net.ssl.X509TrustManager) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) UnrecoverableEntryException(java.security.UnrecoverableEntryException) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) KeyStoreException(java.security.KeyStoreException) KeyManagementException(java.security.KeyManagementException) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager)

Example 3 with UnrecoverableEntryException

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");
}
Also used : X509TrustManager(javax.net.ssl.X509TrustManager) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) UnrecoverableEntryException(java.security.UnrecoverableEntryException) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) KeyStoreException(java.security.KeyStoreException) KeyManagementException(java.security.KeyManagementException) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager)

Example 4 with UnrecoverableEntryException

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");
    }
}
Also used : UnrecoverableEntryException(java.security.UnrecoverableEntryException) UnrecoverableEntryException(java.security.UnrecoverableEntryException)

Example 5 with UnrecoverableEntryException

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
    }
}
Also used : Entry(java.security.KeyStore.Entry) UnrecoverableEntryException(java.security.UnrecoverableEntryException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStoreException(java.security.KeyStoreException) KeyStore(java.security.KeyStore) ProtectionParameter(java.security.KeyStore.ProtectionParameter)

Aggregations

UnrecoverableEntryException (java.security.UnrecoverableEntryException)18 KeyStoreException (java.security.KeyStoreException)16 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)16 IOException (java.io.IOException)10 CertificateException (java.security.cert.CertificateException)10 KeyStore (java.security.KeyStore)8 KeyManagementException (java.security.KeyManagementException)5 TrustManager (javax.net.ssl.TrustManager)4 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)4 X509TrustManager (javax.net.ssl.X509TrustManager)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 PasswordProtection (java.security.KeyStore.PasswordProtection)3 PrivateKeyEntry (java.security.KeyStore.PrivateKeyEntry)3 Certificate (java.security.cert.Certificate)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 KeyPair (java.security.KeyPair)2 KeyPairGenerator (java.security.KeyPairGenerator)2 Entry (java.security.KeyStore.Entry)2 ProtectionParameter (java.security.KeyStore.ProtectionParameter)2