11package io .cryptolens .legacy ;
22
3+ import io .cryptolens .internal .HelperMethods ;
4+ import sun .net .util .URLUtil ;
5+
36import java .io .*;
47import java .net .*;
8+ import java .security .SecureRandom ;
9+ import java .security .cert .CertificateException ;
10+ import java .security .cert .X509Certificate ;
511import java .util .*;
612
713import 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