OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 67 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 67 Rev 174
Line 20... Line 20...
20
import java.net.InetAddress;
20
import java.net.InetAddress;
21
import java.net.NetworkInterface;
21
import java.net.NetworkInterface;
22
import java.net.ServerSocket;
22
import java.net.ServerSocket;
23
import java.net.SocketException;
23
import java.net.SocketException;
24
import java.net.URL;
24
import java.net.URL;
-
 
25
import java.security.KeyManagementException;
-
 
26
import java.security.NoSuchAlgorithmException;
-
 
27
import java.security.cert.X509Certificate;
25
import java.util.Enumeration;
28
import java.util.Enumeration;
26
 
29
 
27
import javax.net.ssl.HostnameVerifier;
30
import javax.net.ssl.HostnameVerifier;
28
import javax.net.ssl.HttpsURLConnection;
31
import javax.net.ssl.HttpsURLConnection;
-
 
32
import javax.net.ssl.SSLContext;
29
import javax.net.ssl.SSLSession;
33
import javax.net.ssl.SSLSession;
-
 
34
import javax.net.ssl.TrustManager;
-
 
35
import javax.net.ssl.X509TrustManager;
30
 
36
 
31
public class NetUtils {
37
public class NetUtils {
32
 
38
 
33
    public static int findFreePort(final int preferred) {
39
    public static int findFreePort(final int preferred) {
34
        return findFreePort(null, preferred);
40
        return findFreePort(null, preferred);
Line 123... Line 129...
123
        public boolean verify(String hostname, SSLSession session) {
129
        public boolean verify(String hostname, SSLSession session) {
124
            return true;
130
            return true;
125
        }
131
        }
126
    };
132
    };
127
 
133
 
-
 
134
    public static final String getHTTPContent(String address) {
-
 
135
        return getHTTPContent(address, false);
-
 
136
    }
-
 
137
 
128
    public static final String getHTTPContent(String address, final boolean dontVerify) {
138
    public static final String getHTTPContent(String address, final boolean dontVerify) {
129
        String content = "";
139
        String content = "";
130
        OutputStream out = null;
140
        OutputStream out = null;
131
        HttpsURLConnection conn = null;
141
        HttpsURLConnection conn = null;
132
        InputStream in = null;
142
        InputStream in = null;
Line 165... Line 175...
165
            }
175
            }
166
        }
176
        }
167
 
177
 
168
        return content;
178
        return content;
169
    }
179
    }
-
 
180
 
-
 
181
    // Create a trust manager that does not validate certificate chains
-
 
182
    static private final TrustManager[] TRUSTALL_MANAGERS = new TrustManager[] { new X509TrustManager() {
-
 
183
        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
-
 
184
            return null;
-
 
185
        }
-
 
186
 
-
 
187
        public void checkClientTrusted(X509Certificate[] certs, String authType) {
-
 
188
        }
-
 
189
 
-
 
190
        public void checkServerTrusted(X509Certificate[] certs, String authType) {
-
 
191
        }
-
 
192
    } };
-
 
193
 
-
 
194
    static public final SSLContext createTrustAllContext() throws KeyManagementException, NoSuchAlgorithmException {
-
 
195
        final SSLContext sc = SSLContext.getInstance("TLS");
-
 
196
        sc.init(null, TRUSTALL_MANAGERS, new java.security.SecureRandom());
-
 
197
        return sc;
-
 
198
    }
170
}
199
}