Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to accept self-signed certificates #3

Open
kevinphippsstfc opened this issue Aug 5, 2016 · 0 comments
Open

Add option to accept self-signed certificates #3

kevinphippsstfc opened this issue Aug 5, 2016 · 0 comments

Comments

@kevinphippsstfc
Copy link

Having to add self-signed certificates to the cacerts file in your Java installation is a pain and currently I believe the IcatManager fails silently and you have to look in the log file to find out why your connection failed. It would be convenient if you could set an option (tickbox?) in the IcatManager to accept self signed certificates. Accepting certificates can be done by calling the method below:

public static void installTrustManager() {
    // Create a trust manager that does not validate certificate chains
    // Equivalent to --no-certificate-check in wget
    TrustManager[] trustAllCerts = new TrustManager[]{
            new X509TrustManager() {
                public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                    return null;
                }
                public void checkClientTrusted(
                        java.security.cert.X509Certificate[] certs, String authType) {
                }
                public void checkServerTrusted(
                        java.security.cert.X509Certificate[] certs, String authType) {
                }
            }
    };

    // Install the all-trusting trust manager
    try {
        SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    } catch (Exception e) {
        LOGGER.severe("Exception setting trust manager. " + e);
    }
    // log message
    LOGGER.info("Trust manager set up successfully");

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant