DineshAtPowel

Accessing HTTPS mapservices with Self signed certificate fails

Discussion created by DineshAtPowel on Mar 20, 2012
I wish to access HTTPS mapservices with self signed certificate. When I tried to do this it fails.
I tried to call the code below to be able to accept any certificate in andriod but this does not help.

private void trustEveryone() {
  try {
   HttpsURLConnection
     .setDefaultHostnameVerifier(new HostnameVerifier() {
      public boolean verify(String hostname,
        SSLSession session) {
       return true;
      }
     });
   SSLContext context = SSLContext.getInstance("TLS");
   context.init(null, new X509TrustManager[] { new X509TrustManager() {
    public void checkClientTrusted(X509Certificate[] chain,
      String authType) throws CertificateException {
    }

    public void checkServerTrusted(X509Certificate[] chain,
      String authType) throws CertificateException {
    }

    public X509Certificate[] getAcceptedIssuers() {
     return new X509Certificate[0];
    }
   } }, new SecureRandom());
   HttpsURLConnection.setDefaultSSLSocketFactory(context
     .getSocketFactory());
  } catch (Exception e) { // should never happen
   e.printStackTrace();
  }
}

If anyone has a solution to this please let me know.

Thanks in advance.

Dinesh Mathur

Outcomes