summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormd_5 <me@md-5.net>2014-12-10 03:50:41 +0100
committermd_5 <me@md-5.net>2014-12-10 03:50:41 +0100
commit42001db64a13ebe7a13aec121c7638cbfb43db72 (patch)
treed0fd9c241fc00f1e1d01fb42594577fe7c0b9be1
parentf09c6388754c2ea1150099ba0c74333d00e249fe (diff)
parentc4677b211a863f809dfb2053598ee0e48c6bae25 (diff)
downloadbuildtools-42001db64a13ebe7a13aec121c7638cbfb43db72.tar
buildtools-42001db64a13ebe7a13aec121c7638cbfb43db72.tar.gz
buildtools-42001db64a13ebe7a13aec121c7638cbfb43db72.tar.lz
buildtools-42001db64a13ebe7a13aec121c7638cbfb43db72.tar.xz
buildtools-42001db64a13ebe7a13aec121c7638cbfb43db72.zip
Merge pull request #8 in SPIGOT/buildtools from ~CYBERTIGER/buildtools:disable-certificate-check to master
* commit 'c4677b211a863f809dfb2053598ee0e48c6bae25': Add command line option to disable https certificate checking.
-rw-r--r--src/main/java/org/spigotmc/builder/Builder.java50
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 ba9ff81..117a14e 100644
--- a/src/main/java/org/spigotmc/builder/Builder.java
+++ b/src/main/java/org/spigotmc/builder/Builder.java
@@ -23,12 +23,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;
@@ -47,6 +56,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." );
@@ -455,4 +469,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);
+ }
+ }
}