Example usage for java.security NoSuchAlgorithmException getMessage

List of usage examples for java.security NoSuchAlgorithmException getMessage

Introduction

In this page you can find the example usage for java.security NoSuchAlgorithmException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:es.tid.fiware.fiwareconnectors.cygnus.http.HttpClientFactory.java

/**
 * Gets a SchemeRegistry object accepting all the X509 certificates by default.
 * @return A SchemeRegistry object./*from www. j a  v  a  2 s  .c om*/
 */
private SchemeRegistry getSchemeRegistry() {
    // http://stackoverflow.com/questions/2703161/how-to-ignore-ssl-certificate-errors-in-apache-httpclient-4-0

    SSLContext sslContext = null;

    try {
        sslContext = SSLContext.getInstance("SSL");
    } catch (NoSuchAlgorithmException e) {
        logger.fatal("Fatal error (SSL cannot be used, no such algorithm. Details=" + e.getMessage() + ")");
        return null;
    } // try catch

    try {
        // set up a TrustManager that trusts everything
        sslContext.init(null, new TrustManager[] { new X509TrustManager() {
            @Override
            public X509Certificate[] getAcceptedIssuers() {
                return null;
            } // getAcceptedIssuers

            @Override
            public void checkClientTrusted(X509Certificate[] certs, String authType) {
            } // getAcceptedIssuers

            @Override
            public void checkServerTrusted(X509Certificate[] certs, String authType) {
            } // checkServerTrusted
        } }, new SecureRandom());
    } catch (KeyManagementException e) {
        logger.fatal("Fatal error (Cannot ignore SSL certificates. Details=" + e.getMessage() + ")");
        return null;
    } // try catch

    if (sslContext == null) {
        logger.fatal("Fatal error (Cannot ignore SSL certificates, SSL context is null)");
        return null;
    } // if

    SSLSocketFactory sf = new SSLSocketFactory(sslContext);
    Scheme httpsScheme = new Scheme("https", 443, sf);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(httpsScheme);
    return schemeRegistry;
}

From source file:org.apache.james.jdkim.tagvalue.PublicKeyRecordImpl.java

/**
 * @see org.apache.james.jdkim.api.PublicKeyRecord#getPublicKey()
 *//*ww  w . jav  a2  s .  com*/
public PublicKey getPublicKey() {
    try {
        String p = getValue("p").toString();
        byte[] key = Base64.decodeBase64(p.getBytes());
        KeyFactory keyFactory;
        keyFactory = KeyFactory.getInstance(getValue("k").toString());
        X509EncodedKeySpec pubSpec = new X509EncodedKeySpec(key);
        RSAPublicKey rsaKey;
        rsaKey = (RSAPublicKey) keyFactory.generatePublic(pubSpec);
        return rsaKey;
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalStateException("Unknown algorithm: " + e.getMessage());
    } catch (InvalidKeySpecException e) {
        throw new IllegalStateException("Invalid key spec: " + e.getMessage());
    }
}

From source file:com.thoughtworks.go.security.AuthSSLProtocolSocketFactory.java

private SSLContext createSSLContext(boolean certAuth) {
    try {//from   ww  w  . ja  v  a  2s.c  o  m
        SSLContext context = SSLContext.getInstance(
                systemEnvironment.get(SystemEnvironment.GO_SSL_TRANSPORT_PROTOCOL_TO_BE_USED_BY_AGENT));
        KeyManager[] keyManagers = keyManagerFactory == null ? null : keyManagerFactory.keyManagers();
        TrustManager[] trustManagers = trustManagerFactory == null ? null : trustManagerFactory.trustManagers();
        context.init(certAuth ? keyManagers : null, trustManagers, null);
        return context;
    } catch (NoSuchAlgorithmException e) {
        LOG.error(e.getMessage(), e);
        throw new AuthSSLInitializationError("Unsupported algorithm exception: " + e.getMessage());
    } catch (GeneralSecurityException e) {
        LOG.error(e.getMessage(), e);
        throw new AuthSSLInitializationError("Key management exception: " + e.getMessage());
    }
}

From source file:be.fedict.commons.eid.jca.BeIDSignature.java

@Override
protected void engineInitVerify(final PublicKey publicKey) throws InvalidKeyException {
    LOG.debug("engineInitVerify");
    if (null == this.verifySignature) {
        try {//  w  ww  .j a  v a 2  s . c  o m
            this.verifySignature = Signature.getInstance(this.signatureAlgorithm);
        } catch (final NoSuchAlgorithmException nsaex) {
            throw new InvalidKeyException("no such algo: " + nsaex.getMessage(), nsaex);
        }
    }
    this.verifySignature.initVerify(publicKey);
}

From source file:com.telefonica.iot.tidoop.apiext.http.HttpClientFactory.java

/**
 * Gets a SchemeRegistry object accepting all the X509 certificates by default.
 * @return A SchemeRegistry object.//from  ww w .j  a  va2 s .c  o  m
 */
private SchemeRegistry getSchemeRegistry() {
    // http://stackoverflow.com/questions/2703161/how-to-ignore-ssl-certificate-errors-in-apache-httpclient-4-0

    SSLContext sslContext = null;

    try {
        sslContext = SSLContext.getInstance("SSL");
    } catch (NoSuchAlgorithmException e) {
        logger.fatal("Fatal error (SSL cannot be used, no such algorithm. Details=" + e.getMessage() + ")");
        return null;
    } // try catch

    try {
        // set up a TrustManager that trusts everything
        sslContext.init(null, new TrustManager[] { new X509TrustManager() {
            @Override
            public X509Certificate[] getAcceptedIssuers() {
                return null;
            } // getAcceptedIssuers

            @Override
            public void checkClientTrusted(X509Certificate[] certs, String authType) {
            } // getAcceptedIssuers

            @Override
            public void checkServerTrusted(X509Certificate[] certs, String authType) {
            } // checkServerTrusted
        } }, new SecureRandom());
    } catch (KeyManagementException e) {
        logger.fatal("Fatal error (Cannot ignore SSL certificates. Details=" + e.getMessage() + ")");
        return null;
    } // try catch

    if (sslContext == null) {
        logger.fatal("Fatal error (Cannot ignore SSL certificates, SSL context is null)");
        return null;
    } // if

    SSLSocketFactory sf = new SSLSocketFactory(sslContext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    Scheme httpsScheme = new Scheme("https", 443, sf);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(httpsScheme);
    return schemeRegistry;
}

From source file:com.telefonica.iot.cosmos.hive.authprovider.HttpClientFactory.java

/**
 * Gets a SSL SchemeRegistry object accepting all the X509 certificates by default.
 * @return A SSL SchemeRegistry object./*from  w  ww. ja v  a  2  s. c  o  m*/
 */
private SchemeRegistry getSSLSchemeRegistry() {
    // http://stackoverflow.com/questions/2703161/how-to-ignore-ssl-certificate-errors-in-apache-httpclient-4-0

    SSLContext sslContext;

    try {
        sslContext = SSLContext.getInstance("SSL");
    } catch (NoSuchAlgorithmException e) {
        LOGGER.fatal("Fatal error (SSL cannot be used, no such algorithm. Details=" + e.getMessage() + ")");
        return null;
    } // try catch // try catch

    try {
        // set up a TrustManager that trusts everything
        sslContext.init(null, new TrustManager[] { new X509TrustManager() {
            @Override
            public X509Certificate[] getAcceptedIssuers() {
                return null;
            } // getAcceptedIssuers

            @Override
            public void checkClientTrusted(X509Certificate[] certs, String authType) {
            } // getAcceptedIssuers

            @Override
            public void checkServerTrusted(X509Certificate[] certs, String authType) {
            } // checkServerTrusted
        } }, new SecureRandom());
    } catch (KeyManagementException e) {
        LOGGER.fatal("Fatal error (Cannot ignore SSL certificates. Details=" + e.getMessage() + ")");
        return null;
    } // try catch // try catch

    if (sslContext == null) {
        LOGGER.fatal("Fatal error (Cannot ignore SSL certificates, SSL context is null)");
        return null;
    } // if

    SSLSocketFactory sf = new SSLSocketFactory(sslContext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    Scheme httpsScheme = new Scheme("https", 443, sf);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(httpsScheme);
    return schemeRegistry;
}

From source file:davmail.http.DavGatewaySSLProtocolSocketFactory.java

public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort) throws IOException {
    try {//from w w w  .j  a  v  a2s. c  o m
        return getSSLContext().getSocketFactory().createSocket(host, port, clientHost, clientPort);
    } catch (NoSuchAlgorithmException e) {
        throw new IOException(e + " " + e.getMessage());
    } catch (KeyManagementException e) {
        throw new IOException(e + " " + e.getMessage());
    } catch (KeyStoreException e) {
        throw new IOException(e + " " + e.getMessage());
    } catch (InvalidAlgorithmParameterException e) {
        throw new IOException(e + " " + e.getMessage());
    }
}

From source file:davmail.http.DavGatewaySSLProtocolSocketFactory.java

public Socket createSocket(String host, int port) throws IOException {
    try {/*  w  ww .  ja v a 2 s  .  c o  m*/
        return getSSLContext().getSocketFactory().createSocket(host, port);
    } catch (NoSuchAlgorithmException e) {
        throw new IOException(e + " " + e.getMessage());
    } catch (KeyManagementException e) {
        throw new IOException(e + " " + e.getMessage());
    } catch (KeyStoreException e) {
        throw new IOException(e + " " + e.getMessage());
    } catch (InvalidAlgorithmParameterException e) {
        throw new IOException(e + " " + e.getMessage());
    }
}

From source file:davmail.http.DavGatewaySSLProtocolSocketFactory.java

public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException {
    try {/*from   www.j  a v a 2s  . c  o  m*/
        return getSSLContext().getSocketFactory().createSocket(socket, host, port, autoClose);
    } catch (NoSuchAlgorithmException e) {
        throw new IOException(e + " " + e.getMessage());
    } catch (KeyManagementException e) {
        throw new IOException(e + " " + e.getMessage());
    } catch (KeyStoreException e) {
        throw new IOException(e + " " + e.getMessage());
    } catch (InvalidAlgorithmParameterException e) {
        throw new IOException(e + " " + e.getMessage());
    }
}

From source file:davmail.http.DavGatewaySSLProtocolSocketFactory.java

public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort,
        HttpConnectionParams params) throws IOException {
    try {/*  w ww .ja  v  a 2  s . c  o m*/
        return getSSLContext().getSocketFactory().createSocket(host, port, clientHost, clientPort);
    } catch (NoSuchAlgorithmException e) {
        throw new IOException(e + " " + e.getMessage());
    } catch (KeyManagementException e) {
        throw new IOException(e + " " + e.getMessage());
    } catch (KeyStoreException e) {
        throw new IOException(e + " " + e.getMessage());
    } catch (InvalidAlgorithmParameterException e) {
        throw new IOException(e + " " + e.getMessage());
    }
}