Search in sources :

Example 1 with KeyManagementException

use of java.security.KeyManagementException in project camel by apache.

the class ExceptionBuilderTest method createRouteBuilder.

protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @SuppressWarnings("unchecked")
        public void configure() throws Exception {
            errorHandler(deadLetterChannel("mock:error").redeliveryDelay(0).maximumRedeliveries(3));
            // START SNIPPET: exceptionBuilder1
            onException(NullPointerException.class).maximumRedeliveries(0).setHeader(MESSAGE_INFO, constant("Damm a NPE")).to(ERROR_QUEUE);
            onException(IOException.class).redeliveryDelay(100L).maximumRedeliveries(3).maximumRedeliveryDelay(30 * 1000L).backOffMultiplier(1.0).useExponentialBackOff().setHeader(MESSAGE_INFO, constant("Damm somekind of IO exception")).to(ERROR_QUEUE);
            onException(Exception.class).redeliveryDelay(100L).maximumRedeliveries(2).setHeader(MESSAGE_INFO, constant("Damm just exception")).to(ERROR_QUEUE);
            onException(MyBaseBusinessException.class).redeliveryDelay(100L).maximumRedeliveries(3).setHeader(MESSAGE_INFO, constant("Damm my business is not going to well")).to(BUSINESS_ERROR_QUEUE);
            onException(GeneralSecurityException.class, KeyException.class).maximumRedeliveries(1).setHeader(MESSAGE_INFO, constant("Damm some security error")).to(SECURITY_ERROR_QUEUE);
            onException(InstantiationException.class, IllegalAccessException.class, ClassNotFoundException.class).maximumRedeliveries(0).setHeader(MESSAGE_INFO, constant("Damm some access error")).to(ERROR_QUEUE);
            // END SNIPPET: exceptionBuilder1
            from("direct:a").process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    String s = exchange.getIn().getBody(String.class);
                    if ("Hello NPE".equals(s)) {
                        throw new NullPointerException();
                    } else if ("Hello IO".equals(s)) {
                        throw new ConnectException("Forced for testing - cannot connect to remote server");
                    } else if ("Hello Exception".equals(s)) {
                        throw new CamelExchangeException("Forced for testing", exchange);
                    } else if ("Hello business".equals(s)) {
                        throw new MyBusinessException();
                    } else if ("I am not allowed to do this".equals(s)) {
                        throw new KeyManagementException();
                    } else if ("I am not allowed to access this".equals(s)) {
                        throw new IllegalAccessException();
                    }
                    exchange.getOut().setBody("Hello World");
                }
            }).to("mock:result");
        }
    };
}
Also used : CamelExchangeException(org.apache.camel.CamelExchangeException) Processor(org.apache.camel.Processor) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) KeyException(java.security.KeyException) KeyManagementException(java.security.KeyManagementException) Exchange(org.apache.camel.Exchange) ConnectException(java.net.ConnectException)

Example 2 with KeyManagementException

use of java.security.KeyManagementException in project AndroidNetworkDemo by dodocat.

the class RequestManager method newRequestQueue.

private RequestQueue newRequestQueue(Context context) {
    RequestQueue requestQueue;
    try {
        String[] hosts = { "kyfw.12306.cn" };
        int[] certRes = { R.raw.kyfw };
        String[] certPass = { "asdfqaz" };
        socketFactoryMap = new Hashtable<>(hosts.length);
        for (int i = 0; i < certRes.length; i++) {
            int res = certRes[i];
            String password = certPass[i];
            SSLSocketFactory sslSocketFactory = createSSLSocketFactory(context, res, password);
            socketFactoryMap.put(hosts[i], sslSocketFactory);
        }
        HurlStack stack = new SelfSignSslOkHttpStack(socketFactoryMap);
        requestQueue = Volley.newRequestQueue(context, stack);
        requestQueue.start();
    } catch (KeyStoreException | CertificateException | NoSuchAlgorithmException | KeyManagementException | IOException e) {
        throw new RuntimeException(e);
    }
    return requestQueue;
}
Also used : HurlStack(com.android.volley.toolbox.HurlStack) CertificateException(java.security.cert.CertificateException) KeyStoreException(java.security.KeyStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) RequestQueue(com.android.volley.RequestQueue) SSLSocketFactory(javax.net.ssl.SSLSocketFactory)

Example 3 with KeyManagementException

use of java.security.KeyManagementException in project android_frameworks_base by ParanoidAndroid.

the class SSLCertificateSocketFactory method makeSocketFactory.

private SSLSocketFactory makeSocketFactory(KeyManager[] keyManagers, TrustManager[] trustManagers) {
    try {
        OpenSSLContextImpl sslContext = new OpenSSLContextImpl();
        sslContext.engineInit(keyManagers, trustManagers, null);
        sslContext.engineGetClientSessionContext().setPersistentCache(mSessionCache);
        return sslContext.engineGetSocketFactory();
    } catch (KeyManagementException e) {
        Log.wtf(TAG, e);
        // Fallback
        return (SSLSocketFactory) SSLSocketFactory.getDefault();
    }
}
Also used : OpenSSLContextImpl(org.apache.harmony.xnet.provider.jsse.OpenSSLContextImpl) KeyManagementException(java.security.KeyManagementException)

Example 4 with KeyManagementException

use of java.security.KeyManagementException in project sonarqube by SonarSource.

the class HttpsTrustTest method failOnError.

@Test
public void failOnError() throws Exception {
    HttpsTrust.Ssl context = mock(HttpsTrust.Ssl.class);
    KeyManagementException cause = new KeyManagementException("foo");
    when(context.newFactory(any(TrustManager.class))).thenThrow(cause);
    try {
        new HttpsTrust(context);
        fail();
    } catch (IllegalStateException e) {
        assertThat(e.getMessage()).isEqualTo("Fail to build SSL factory");
        assertThat(e.getCause()).isSameAs(cause);
    }
}
Also used : KeyManagementException(java.security.KeyManagementException) TrustManager(javax.net.ssl.TrustManager) Test(org.junit.Test)

Example 5 with KeyManagementException

use of java.security.KeyManagementException in project OpenAttestation by OpenAttestation.

the class Pkcs12 method setRsaCredentialX509.

/**
     * Replaces an existing keypair with the same alias or adds a new keypair
     * if one did not already exist.
     * 
     * The chain is optional and if provided it must be the certificates that
     * signed the credential's public key, in order, with the Root CA being LAST.
     * 
     * @param key
     * @param chain
     * @param alias 
     * @param keyPassword
     */
public void setRsaCredentialX509(RsaCredentialX509 key, X509Certificate[] chain, String alias, String keyPassword) throws KeyManagementException {
    try {
        List<String> aliases = Collections.list(keystore.aliases());
        if (aliases.contains(alias)) {
            keystore.deleteEntry(alias);
        }
        X509Certificate[] chain1;
        if (chain != null) {
            chain1 = new X509Certificate[chain.length + 1];
            chain1[0] = key.getCertificate();
            System.arraycopy(chain, 0, chain1, 1, chain.length);
        } else {
            chain1 = new X509Certificate[] { key.getCertificate() };
        }
        keystore.setKeyEntry(alias, key.getPrivateKey(), keyPassword.toCharArray(), chain1);
    } catch (KeyStoreException e) {
        throw new KeyManagementException("Cannot add credential", e);
    }
}
Also used : KeyStoreException(java.security.KeyStoreException) X509Certificate(java.security.cert.X509Certificate) KeyManagementException(java.security.KeyManagementException)

Aggregations

KeyManagementException (java.security.KeyManagementException)132 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)86 SSLContext (javax.net.ssl.SSLContext)65 KeyStoreException (java.security.KeyStoreException)43 TrustManager (javax.net.ssl.TrustManager)39 IOException (java.io.IOException)38 CertificateException (java.security.cert.CertificateException)23 X509TrustManager (javax.net.ssl.X509TrustManager)22 SecureRandom (java.security.SecureRandom)21 X509Certificate (java.security.cert.X509Certificate)19 UnrecoverableKeyException (java.security.UnrecoverableKeyException)18 KeyManager (javax.net.ssl.KeyManager)18 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)16 KeyStore (java.security.KeyStore)13 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)13 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)10 HostnameVerifier (javax.net.ssl.HostnameVerifier)9 NoSuchProviderException (java.security.NoSuchProviderException)7 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)7 SSLSocket (javax.net.ssl.SSLSocket)7