PREF: Disable SSL cert validation
authordonghyuk.yang <donghyuk.yang@samsung.com>
Sun, 19 Jan 2014 06:05:53 +0000 (15:05 +0900)
committerdonghyuk.yang <donghyuk.yang@samsung.com>
Sun, 19 Jan 2014 06:05:53 +0000 (15:05 +0900)
The following exception is occurred when connecting https site:
 com.sun.jersey.api.client.ClientHandlerException:
  javax.net.ssl.SSLHandshakeException:
   sun.security.validator.ValidatorException:
    PKIX path building failed:
     sun.security.provider.certpath.SunCertPathBuilderException:
      unable to find valid certification path to requested target
This solution is temporary and can be changed.

Signed-off-by: donghyuk.yang <donghyuk.yang@samsung.com>
Change-Id: I5210afa2a74c41872c2be376675c3a724204db7e

org.tizen.nativeplatform/src/org/tizen/nativeplatform/preferences/PreferencesManager.java

index c4a3724..a518dcd 100644 (file)
@@ -31,16 +31,25 @@ import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Writer;
+import java.net.HttpURLConnection;
 import java.net.InetSocketAddress;
 import java.net.Proxy;
 import java.net.URL;
 import java.net.URLConnection;
+import java.security.SecureRandom;
+import java.security.cert.X509Certificate;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+
 import org.eclipse.core.net.proxy.IProxyData;
 import org.eclipse.core.net.proxy.IProxyService;
 import org.eclipse.core.resources.ResourcesPlugin;
@@ -273,8 +282,7 @@ public class PreferencesManager {
             Bundle bundle = FrameworkUtil.getBundle(PreferencesManager.class);
             if (bundle != null) {
                 proxyTracker = new ServiceTracker<IProxyService, IProxyService>(
-                        bundle.getBundleContext(),
-                        IProxyService.class.getName(), null);
+                        bundle.getBundleContext(), IProxyService.class.getName(), null);
             }
             if (proxyTracker == null) {
                 return null;
@@ -475,6 +483,38 @@ public class PreferencesManager {
         String name = loadSiteConfigName().get(idx);
         String path = loadGitListLocation().get(idx);
 
+        /*
+         * Disable SSL cert validation because of following exception:
+         *  com.sun.jersey.api.client.ClientHandlerException: 
+         *  javax.net.ssl.SSLHandshakeException: 
+         *  sun.security.validator.ValidatorException: 
+         *  PKIX path building failed: 
+         *  sun.security.provider.certpath.SunCertPathBuilderException: 
+         *  unable to find valid certification path to requested target
+         * This solution is temporary and can be changed.
+         */
+        // Create a trust manager that does not validate certificate chains
+        TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
+            public X509Certificate[] getAcceptedIssuers() {
+                return null;
+            }
+
+            public void checkClientTrusted(X509Certificate[] certs, String authType) {
+            }
+
+            public void checkServerTrusted(X509Certificate[] certs, String authType) {
+            }
+        } };
+
+        // Install the all-trusting trust manager
+        try {
+            SSLContext sc = SSLContext.getInstance("TLS");
+            sc.init(null, trustAllCerts, new SecureRandom());
+            HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
+        } catch (Exception e) {
+            ;
+        }
+
         Writer out = null;
         try {
             URL u = new URL(path);