|
7 | 7 | import io.cryptolens.models.ErrorType; |
8 | 8 | import io.cryptolens.models.RequestModel; |
9 | 9 |
|
| 10 | +import javax.net.ssl.*; |
10 | 11 | import java.lang.reflect.Field; |
11 | 12 | import java.lang.reflect.Type; |
| 13 | +import java.security.SecureRandom; |
| 14 | +import java.security.cert.CertificateException; |
| 15 | +import java.security.cert.X509Certificate; |
12 | 16 | import java.time.Instant; |
13 | 17 | import java.time.LocalDateTime; |
14 | 18 | import java.time.ZoneId; |
|
17 | 21 |
|
18 | 22 | public class HelperMethods { |
19 | 23 |
|
| 24 | + /** |
| 25 | + * This field can be used to bypass SSL verification when calling app.cryptolens.io. Set this to 'false' |
| 26 | + * before calling any of the API methods. Once an API method is called, it will no longer be possible |
| 27 | + * to re-enable SSL verification by setting this variable to false. |
| 28 | + */ |
| 29 | + public static boolean SSLEnabled = true; |
| 30 | + |
20 | 31 | public static <T extends BasicResult> T SendRequestToWebAPI(String method, RequestModel model, Map<String,String> extraParams, Class<T> clazz) { |
21 | 32 | return SendRequestToWebAPI(method, model, extraParams, clazz, null); |
22 | 33 | } |
@@ -55,6 +66,29 @@ public static <T extends BasicResult> T SendRequestToWebAPI(String method, Reque |
55 | 66 | RequestHandler requestHandler = new HttpsURLConnectionRequestHandler(); |
56 | 67 |
|
57 | 68 | try { |
| 69 | + if(!HelperMethods.SSLEnabled) { |
| 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 | + } |
58 | 92 |
|
59 | 93 | String response = requestHandler.makePostRequest(licenseServerUrl + "/api/" + method, params); |
60 | 94 |
|
|
0 commit comments