|
8 | 8 | import java.net.URL; |
9 | 9 | import java.nio.charset.StandardCharsets; |
10 | 10 | import java.nio.file.*; |
| 11 | +import java.security.KeyManagementException; |
11 | 12 | import java.security.MessageDigest; |
12 | 13 | import java.security.NoSuchAlgorithmException; |
| 14 | +import java.security.cert.X509Certificate; |
13 | 15 | import java.util.*; |
14 | 16 | import java.util.concurrent.Callable; |
15 | 17 | import java.util.jar.Attributes; |
|
18 | 20 | import java.util.stream.Collectors; |
19 | 21 | import java.util.stream.Stream; |
20 | 22 |
|
| 23 | +import javax.net.ssl.HostnameVerifier; |
| 24 | +import javax.net.ssl.HttpsURLConnection; |
| 25 | +import javax.net.ssl.SSLContext; |
| 26 | +import javax.net.ssl.SSLSession; |
| 27 | +import javax.net.ssl.TrustManager; |
| 28 | +import javax.net.ssl.X509TrustManager; |
| 29 | + |
21 | 30 | import org.apache.commons.text.StringEscapeUtils; |
22 | 31 |
|
23 | 32 | import com.sun.nio.file.SensitivityWatchEventModifier; |
@@ -83,6 +92,9 @@ boolean debug() { |
83 | 92 | @Option(names = { "-D" }, description = "set a system property") |
84 | 93 | Map<String, String> properties = new HashMap<>(); |
85 | 94 |
|
| 95 | + @Option(names = { "--naive" }, description = "Trust all SSL certificates.") |
| 96 | + boolean naive; |
| 97 | + |
86 | 98 | public int completion() throws IOException { |
87 | 99 | String script = AutoComplete.bash( |
88 | 100 | spec.name(), |
@@ -156,6 +168,41 @@ private Integer doCall() throws IOException { |
156 | 168 | return completion(); |
157 | 169 | } |
158 | 170 |
|
| 171 | + if (naive) { |
| 172 | + try { |
| 173 | + // Create a trust manager that does not validate certificate chains |
| 174 | + TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { |
| 175 | + public java.security.cert.X509Certificate[] getAcceptedIssuers() { |
| 176 | + return null; |
| 177 | + } |
| 178 | + |
| 179 | + public void checkClientTrusted(X509Certificate[] certs, String authType) { |
| 180 | + } |
| 181 | + |
| 182 | + public void checkServerTrusted(X509Certificate[] certs, String authType) { |
| 183 | + } |
| 184 | + } |
| 185 | + }; |
| 186 | + |
| 187 | + // Install the all-trusting trust manager |
| 188 | + SSLContext sc = SSLContext.getInstance("SSL"); |
| 189 | + sc.init(null, trustAllCerts, new java.security.SecureRandom()); |
| 190 | + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); |
| 191 | + |
| 192 | + // Create all-trusting host name verifier |
| 193 | + HostnameVerifier allHostsValid = new HostnameVerifier() { |
| 194 | + public boolean verify(String hostname, SSLSession session) { |
| 195 | + return true; |
| 196 | + } |
| 197 | + }; |
| 198 | + |
| 199 | + // Install the all-trusting host verifier |
| 200 | + HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); |
| 201 | + } catch (NoSuchAlgorithmException | KeyManagementException ex) { |
| 202 | + throw new RuntimeException(ex); |
| 203 | + } |
| 204 | + } |
| 205 | + |
159 | 206 | if (clearCache) { |
160 | 207 | info("Clearing cache at " + Settings.getCacheDir().toPath()); |
161 | 208 | // noinspection resource |
|
0 commit comments