diff options
author | Antony Riley <antony@cyberiantiger.org> | 2014-12-08 01:41:20 +0200 |
---|---|---|
committer | Antony Riley <antony@cyberiantiger.org> | 2014-12-08 01:41:20 +0200 |
commit | c4677b211a863f809dfb2053598ee0e48c6bae25 (patch) | |
tree | f737a6df12a2706a635fd7ca20df91d7f193b5f2 /src | |
parent | 8c3c4ef42ee1b5617373022df6de8b9fa6da9a9c (diff) | |
download | buildtools-c4677b211a863f809dfb2053598ee0e48c6bae25.tar buildtools-c4677b211a863f809dfb2053598ee0e48c6bae25.tar.gz buildtools-c4677b211a863f809dfb2053598ee0e48c6bae25.tar.lz buildtools-c4677b211a863f809dfb2053598ee0e48c6bae25.tar.xz buildtools-c4677b211a863f809dfb2053598ee0e48c6bae25.zip |
Add command line option to disable https certificate checking.
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/spigotmc/builder/Builder.java | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/main/java/org/spigotmc/builder/Builder.java b/src/main/java/org/spigotmc/builder/Builder.java index 45971b5..07eaedb 100644 --- a/src/main/java/org/spigotmc/builder/Builder.java +++ b/src/main/java/org/spigotmc/builder/Builder.java @@ -22,12 +22,21 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintStream; import java.net.URL; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.X509Certificate; import java.util.Arrays; import java.util.Date; import java.util.Enumeration; import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; import lombok.RequiredArgsConstructor; import org.apache.commons.io.FileUtils; import org.eclipse.jgit.api.Git; @@ -46,6 +55,11 @@ public class Builder public static void main(String[] args) throws Exception { + for (String s : args) { + if ("--disable-certificate-check".equals(s)) { + disableHttpsCertificateCheck(); + } + } if ( IS_MAC ) { System.out.println( "Sorry, but Macintosh is not currently a supported platform for compilation at this time." ); @@ -431,4 +445,40 @@ public class Builder return target; } + + public static void disableHttpsCertificateCheck() { + // This globally disables certificate checking + // http://stackoverflow.com/questions/19723415/java-overriding-function-to-disable-ssl-certificate-check + try + { + TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() { + public java.security.cert.X509Certificate[] getAcceptedIssuers() { + return null; + } + public void checkClientTrusted(X509Certificate[] certs, String authType) { + } + public void checkServerTrusted(X509Certificate[] certs, String authType) { + } + } + }; + SSLContext sc = SSLContext.getInstance("SSL"); + sc.init(null, trustAllCerts, new java.security.SecureRandom()); + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + + HostnameVerifier allHostsValid = new HostnameVerifier() { + public boolean verify(String hostname, SSLSession session) { + return true; + } + }; + HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); + } catch ( NoSuchAlgorithmException ex ) + { + System.out.println("Failed to disable https certificate check"); + ex.printStackTrace(System.out); + } catch ( KeyManagementException ex ) + { + System.out.println("Failed to disable https certificate check"); + ex.printStackTrace(System.out); + } + } } |