Skip to content

Commit 27d2867

Browse files
committed
Make sure that SSL can be re-enabled
1 parent 3830e0d commit 27d2867

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

src/main/java/io/cryptolens/internal/HelperMethods.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -66,30 +66,6 @@ public static <T extends BasicResult> T SendRequestToWebAPI(String method, Reque
6666
RequestHandler requestHandler = new HttpsURLConnectionRequestHandler();
6767

6868
try {
69-
if(!HelperMethods.SSLVerifyEnabled) {
70-
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
71-
public boolean verify(String hostname, SSLSession session) {
72-
return true;
73-
}
74-
});
75-
SSLContext context = SSLContext.getInstance("TLS");
76-
context.init(null, new X509TrustManager[]{new X509TrustManager() {
77-
public void checkClientTrusted(X509Certificate[] chain,
78-
String authType) throws CertificateException {
79-
}
80-
81-
public void checkServerTrusted(X509Certificate[] chain,
82-
String authType) throws CertificateException {
83-
}
84-
85-
public X509Certificate[] getAcceptedIssuers() {
86-
return new X509Certificate[0];
87-
}
88-
}}, new SecureRandom());
89-
HttpsURLConnection.setDefaultSSLSocketFactory(
90-
context.getSocketFactory());
91-
}
92-
9369
String response = requestHandler.makePostRequest(licenseServerUrl + "/api/" + method, params);
9470

9571
Gson gson = new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new JsonDeserializer<LocalDateTime>() {

src/main/java/io/cryptolens/legacy/HttpsURLConnectionRequestHandler.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
package io.cryptolens.legacy;
22

3+
import io.cryptolens.internal.HelperMethods;
4+
import sun.net.util.URLUtil;
5+
36
import java.io.*;
47
import java.net.*;
8+
import java.security.SecureRandom;
9+
import java.security.cert.CertificateException;
10+
import java.security.cert.X509Certificate;
511
import java.util.*;
612

713
import javax.net.ssl.*;
@@ -12,6 +18,33 @@ public String makePostRequest(String url, Map<String,String> params) throws Exce
1218

1319
// HttpsURLConnection extends HttpURLConnection
1420
HttpURLConnection connection = (HttpURLConnection)url_.openConnection();
21+
22+
if(!HelperMethods.SSLVerifyEnabled && "https".equals(url_.getProtocol())){
23+
24+
SSLContext context = SSLContext.getInstance("TLS");
25+
context.init(null, new X509TrustManager[]{new X509TrustManager() {
26+
public void checkClientTrusted(X509Certificate[] chain,
27+
String authType) throws CertificateException {
28+
}
29+
30+
public void checkServerTrusted(X509Certificate[] chain,
31+
String authType) throws CertificateException {
32+
}
33+
34+
public X509Certificate[] getAcceptedIssuers() {
35+
return new X509Certificate[0];
36+
}
37+
}}, new SecureRandom());
38+
39+
((HttpsURLConnection)connection).setHostnameVerifier(new HostnameVerifier() {
40+
public boolean verify(String hostname, SSLSession session) {
41+
return true;
42+
}
43+
});
44+
45+
((HttpsURLConnection)connection).setSSLSocketFactory(context.getSocketFactory());
46+
}
47+
1548
connection.setRequestMethod("POST");
1649

1750
connection.setDoOutput(true);

0 commit comments

Comments
 (0)