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

Support https self signed certificates #68

Closed
GoogleCodeExporter opened this issue Mar 18, 2015 · 5 comments
Closed

Support https self signed certificates #68

GoogleCodeExporter opened this issue Mar 18, 2015 · 5 comments

Comments

@GoogleCodeExporter
Copy link

Hi

currently the plugin doesn't support https (or at least to skip self signed 
certificate).


Would be great to add it.

What I did to support it:
1) add in Confluence:

if (endpoint.startsWith("https")) {
  try {
      YesConfiguration.configureJVm();
  }
  catch (final Exception e) {
      throw new IllegalStateException(e);
  }
}

2) YesConfiguration is:

import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

public class YesConfiguration {
    public static SSLSocketFactory newInstance() throws Exception {
        final SSLContext ctx = SSLContext.getInstance("TLS");
        ctx.init(null, new TrustManager[] { new YesTrustManager() }, null);
        return ctx.getSocketFactory();
    }

    public static void configureJVm() throws Exception {
        HttpsURLConnection.setDefaultSSLSocketFactory(newInstance());
        HttpsURLConnection.setDefaultHostnameVerifier(new YesHostnameVerifier());
    }

    public static class YesHostnameVerifier implements HostnameVerifier {
        @Override
        public boolean verify(final String s, final SSLSession sslSession) {
            return true;
        }
    }

    public static class YesTrustManager implements X509TrustManager {
        @Override
        public void checkClientTrusted(final X509Certificate[] x509Certificates, final String s) throws CertificateException {
            // no-op
        }

        @Override
        public void checkServerTrusted(final X509Certificate[] x509Certificates, final String s) throws CertificateException {
            // no-op
        }

        @Override
        public X509Certificate[] getAcceptedIssuers() {
            return null;
        }
    }
}




Side note : a more advanced version could support HostnameVerifier and 
X509TrustManager qualified names

Original issue reported on code.google.com by rmannibucau@gmail.com on 7 Jul 2014 at 4:02

@GoogleCodeExporter
Copy link
Author

Hi

Thanks for feedback

I'll apply your suggestion soon

Original comment by bartolom...@gmail.com on 7 Jul 2014 at 6:35

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

Original comment by bartolom...@gmail.com on 7 Jul 2014 at 6:36

  • Added labels: Type-Enhancement, Milestone-Release4.1.0
  • Removed labels: Type-Defect

@GoogleCodeExporter
Copy link
Author

FYI I pushed a PR on v4 branch (should apply on master I guess) on github

Original comment by rmannibucau@gmail.com on 7 Jul 2014 at 6:43

@GoogleCodeExporter
Copy link
Author

fix deployed in version 4.1.0

Original comment by bartolom...@gmail.com on 9 Jul 2014 at 12:47

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

Thank you!

Original comment by rmannibucau@gmail.com on 9 Jul 2014 at 3:31

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

No branches or pull requests

1 participant