88import javax .net .ssl .TrustManager ;
99import javax .net .ssl .X509TrustManager ;
1010import java .io .IOException ;
11- import java .io .InputStream ;
11+ import java .net .URLConnection ;
12+ import java .security .KeyManagementException ;
13+ import java .security .NoSuchAlgorithmException ;
1214import java .security .cert .X509Certificate ;
1315
1416/**
@@ -22,20 +24,22 @@ public InsecureHTTPURLConfigurationLocation(@NotNull final Project project,
2224 super (id , ConfigurationType .INSECURE_HTTP_URL , project );
2325 }
2426
25- @ NotNull
2627 @ Override
27- protected InputStream resolveFile (@ NotNull final ClassLoader checkstyleClassLoader ) throws IOException {
28- TrustManager [] trustAllCerts = new TrustManager []{new AllTrustingTrustManager ()};
29-
30- try {
31- final SSLContext sc = SSLContext .getInstance ("TLSv1.3" );
32- sc .init (null , trustAllCerts , new java .security .SecureRandom ());
33- HttpsURLConnection .setDefaultSSLSocketFactory (sc .getSocketFactory ());
34- } catch (Exception ignored ) {
35- // we care not for security
28+ @ NotNull URLConnection connectionTo (final String location ) throws IOException {
29+ final URLConnection urlConnection = super .connectionTo (location );
30+
31+ if (urlConnection instanceof HttpsURLConnection httpsURLConnection ) {
32+ try {
33+ final TrustManager [] trustAllCerts = new TrustManager []{new AllTrustingTrustManager ()};
34+ final SSLContext sc = SSLContext .getInstance ("TLSv1.3" );
35+ sc .init (null , trustAllCerts , new java .security .SecureRandom ());
36+ httpsURLConnection .setSSLSocketFactory (sc .getSocketFactory ());
37+ } catch (NoSuchAlgorithmException | KeyManagementException e ) {
38+ throw new IOException ("Failed to set an insecure SSL socket factory" , e );
39+ }
3640 }
3741
38- return super . resolveFile ( checkstyleClassLoader ) ;
42+ return urlConnection ;
3943 }
4044
4145 private static final class AllTrustingTrustManager implements X509TrustManager {
0 commit comments