Skip to content

Commit 704c697

Browse files
committed
add flag for ignoring ssl errors
1 parent 092d746 commit 704c697

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ java -cp 'lib/*:bin/*.jar' nl.melp.linkchecker.LinkChecker
4242
| `--recheck-only-errors` | Only recheck links that had an internal error state, i.e. all urls that (which usually are out of your control anyway |
4343
| `--no-recheck` | Don't do recheck, even if url's are marked as "processing". This happens if a linkchecker process was interrupted without finishing cleanly. |
4444
| `--reset` | Start with a clean slate |
45-
| `--resume` | Resume a previously stopped session. Without a properly configured Redis instance, this has no effect. |
45+
| `--resume` | Resume a previously stopped session. |
4646
| `--report` | When done, write a report to stdout and to reporting keys in Redis. |
4747
| `--report-all` | Also report working links. By default, only error statuses are reported |
4848

src/nl/melp/linkchecker/LinkChecker.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@
99
import org.slf4j.Logger;
1010
import org.slf4j.LoggerFactory;
1111

12+
import javax.net.ssl.HttpsURLConnection;
13+
import javax.net.ssl.SSLContext;
14+
import javax.net.ssl.TrustManager;
15+
import javax.net.ssl.X509TrustManager;
1216
import java.io.IOException;
1317
import java.net.ConnectException;
1418
import java.net.Socket;
1519
import java.net.URI;
1620
import java.net.http.HttpClient;
1721
import java.net.http.HttpRequest;
1822
import java.net.http.HttpResponse;
23+
import java.security.KeyManagementException;
24+
import java.security.NoSuchAlgorithmException;
1925
import java.time.Duration;
2026
import java.time.ZoneOffset;
2127
import java.time.ZonedDateTime;
@@ -306,7 +312,7 @@ private void registerInvalidUrl(URI mentionedAt, String url, String reason) {
306312
invalidUrls.get(url).add(mentionedAt);
307313
}
308314

309-
public static void main(String[] rawArgs) throws InterruptedException, IOException {
315+
public static void main(String[] rawArgs) throws InterruptedException, IOException, KeyManagementException, NoSuchAlgorithmException {
310316
Map<String, Set<String>> opts = new HashMap<>();
311317
Set<String> flags = new HashSet<>();
312318
List<String> args = new LinkedList<>();
@@ -339,6 +345,28 @@ public static void main(String[] rawArgs) throws InterruptedException, IOExcepti
339345
String redisHost = opts.getOrDefault("redis-host", Collections.emptySet()).stream().findFirst().orElse(System.getProperty("redis.host", "localhost"));
340346
String redisPort = opts.getOrDefault("redis-port", Collections.emptySet()).stream().findFirst().orElse(System.getProperty("redis.port", "6379"));
341347

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+
342370
try (Socket socket = new Socket(redisHost, Integer.valueOf(redisPort))) {
343371
Redis redis = new Redis(socket);
344372
Set<URI> urls = new SerializedSet<>(redis, LinkChecker.class.getCanonicalName() + ".urls");

0 commit comments

Comments
 (0)