1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.jameleon.util;
20
21 import com.sun.net.ssl.HostnameVerifier;
22 import com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl;
23
24 import javax.net.ssl.SSLContext;
25 import javax.net.ssl.TrustManager;
26
27 import java.security.SecureRandom;
28 import java.security.NoSuchAlgorithmException;
29 import java.security.KeyManagementException;
30
31 /***
32 * Utility to override the JSSE settings for SSL certificate checking
33 * This can be used to disable the SSL certificate checking normally done by Java
34 */
35 public class JsseSettings {
36
37 /***
38 * don't instantiate this class
39 */
40 private JsseSettings(){
41 }
42
43 public static void disableSslCertificateChecking() {
44
45 TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustEverythingManager()};
46
47 HostnameVerifier doNotVerifyHost = new HostnameVerifier() {
48 public boolean verify(String hostname, String session) { return true; }
49 };
50
51 try {
52 SSLContext sc = SSLContext.getInstance("SSL");
53 sc.init(null, trustAllCerts, new SecureRandom());
54 HttpsURLConnectionOldImpl.setDefaultSSLSocketFactory(sc.getSocketFactory());
55 HttpsURLConnectionOldImpl.setDefaultHostnameVerifier(doNotVerifyHost);
56 } catch (NoSuchAlgorithmException e) {
57 e.printStackTrace();
58 } catch (KeyManagementException e) {
59 e.printStackTrace();
60 }
61 }
62
63 }