|
9 | 9 | import org.slf4j.Logger; |
10 | 10 | import org.slf4j.LoggerFactory; |
11 | 11 |
|
| 12 | +import javax.net.ssl.HttpsURLConnection; |
| 13 | +import javax.net.ssl.SSLContext; |
| 14 | +import javax.net.ssl.TrustManager; |
| 15 | +import javax.net.ssl.X509TrustManager; |
12 | 16 | import java.io.IOException; |
13 | 17 | import java.net.ConnectException; |
14 | 18 | import java.net.Socket; |
15 | 19 | import java.net.URI; |
16 | 20 | import java.net.http.HttpClient; |
17 | 21 | import java.net.http.HttpRequest; |
18 | 22 | import java.net.http.HttpResponse; |
| 23 | +import java.security.KeyManagementException; |
| 24 | +import java.security.NoSuchAlgorithmException; |
19 | 25 | import java.time.Duration; |
20 | 26 | import java.time.ZoneOffset; |
21 | 27 | import java.time.ZonedDateTime; |
@@ -306,7 +312,7 @@ private void registerInvalidUrl(URI mentionedAt, String url, String reason) { |
306 | 312 | invalidUrls.get(url).add(mentionedAt); |
307 | 313 | } |
308 | 314 |
|
309 | | - public static void main(String[] rawArgs) throws InterruptedException, IOException { |
| 315 | + public static void main(String[] rawArgs) throws InterruptedException, IOException, KeyManagementException, NoSuchAlgorithmException { |
310 | 316 | Map<String, Set<String>> opts = new HashMap<>(); |
311 | 317 | Set<String> flags = new HashSet<>(); |
312 | 318 | List<String> args = new LinkedList<>(); |
@@ -339,6 +345,28 @@ public static void main(String[] rawArgs) throws InterruptedException, IOExcepti |
339 | 345 | String redisHost = opts.getOrDefault("redis-host", Collections.emptySet()).stream().findFirst().orElse(System.getProperty("redis.host", "localhost")); |
340 | 346 | String redisPort = opts.getOrDefault("redis-port", Collections.emptySet()).stream().findFirst().orElse(System.getProperty("redis.port", "6379")); |
341 | 347 |
|
| 348 | + if (flags.contains("ignore-ssl-errors")) { |
| 349 | + // Create a trust manager that does not validate certificate chains |
| 350 | + TrustManager[] trustAllCerts = new TrustManager[]{ |
| 351 | + new X509TrustManager() { |
| 352 | + public java.security.cert.X509Certificate[] getAcceptedIssuers() { |
| 353 | + return null; |
| 354 | + } |
| 355 | + public void checkClientTrusted( |
| 356 | + java.security.cert.X509Certificate[] certs, String authType) { |
| 357 | + } |
| 358 | + public void checkServerTrusted( |
| 359 | + java.security.cert.X509Certificate[] certs, String authType) { |
| 360 | + } |
| 361 | + } |
| 362 | + }; |
| 363 | + |
| 364 | + // Install the all-trusting trust manager |
| 365 | + SSLContext sc = SSLContext.getInstance("SSL"); |
| 366 | + sc.init(null, trustAllCerts, null); |
| 367 | + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); |
| 368 | + } |
| 369 | + |
342 | 370 | try (Socket socket = new Socket(redisHost, Integer.valueOf(redisPort))) { |
343 | 371 | Redis redis = new Redis(socket); |
344 | 372 | Set<URI> urls = new SerializedSet<>(redis, LinkChecker.class.getCanonicalName() + ".urls"); |
|
0 commit comments