Commits

md_5 authored 42001db64a1 Merge
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.
No tags

src/main/java/org/spigotmc/builder/Builder.java

Modified
16 16 import java.io.File;
17 17 import java.io.FileOutputStream;
18 18 import java.io.FileWriter;
19 19 import java.io.FilenameFilter;
20 20 import java.io.IOException;
21 21 import java.io.InputStream;
22 22 import java.io.InputStreamReader;
23 23 import java.io.OutputStream;
24 24 import java.io.PrintStream;
25 25 import java.net.URL;
26 +import java.security.KeyManagementException;
27 +import java.security.NoSuchAlgorithmException;
28 +import java.security.cert.X509Certificate;
26 29 import java.util.Arrays;
27 30 import java.util.Date;
28 31 import java.util.Enumeration;
29 32 import java.util.List;
30 33 import java.util.zip.ZipEntry;
31 34 import java.util.zip.ZipFile;
35 +import javax.net.ssl.HostnameVerifier;
36 +import javax.net.ssl.HttpsURLConnection;
37 +import javax.net.ssl.SSLContext;
38 +import javax.net.ssl.SSLSession;
39 +import javax.net.ssl.TrustManager;
40 +import javax.net.ssl.X509TrustManager;
32 41 import lombok.RequiredArgsConstructor;
33 42 import org.apache.commons.io.FileUtils;
34 43 import org.eclipse.jgit.api.Git;
35 44 import org.eclipse.jgit.api.ResetCommand;
36 45 import org.eclipse.jgit.api.errors.GitAPIException;
37 46 import org.eclipse.jgit.revwalk.RevCommit;
38 47
39 48 public class Builder
40 49 {
41 50
42 51 public static final boolean IS_WINDOWS = System.getProperty( "os.name" ).startsWith( "Windows" );
43 52 public static final boolean IS_MAC = System.getProperty( "os.name" ).startsWith( "Mac" );
44 53 public static final File CWD = new File( "." );
45 54 public static final String MC_VERSION = "1.8";
46 55 private static final File jacobeDir = new File( "jacobe" );
47 56
48 57 public static void main(String[] args) throws Exception
49 58 {
59 + for (String s : args) {
60 + if ("--disable-certificate-check".equals(s)) {
61 + disableHttpsCertificateCheck();
62 + }
63 + }
50 64 if ( IS_MAC )
51 65 {
52 66 System.out.println( "Sorry, but Macintosh is not currently a supported platform for compilation at this time." );
53 67 System.out.println( "Please run this script on a Windows or Linux PC and then copy the jars to this computer." );
54 68 System.exit( 1 );
55 69 }
56 70
57 71 try
58 72 {
59 73 runProcess( CWD, "bash", "-c", "exit" );
448 462 System.out.println( "Starting download of " + url );
449 463
450 464 byte[] bytes = Resources.toByteArray( new URL( url ) );
451 465
452 466 System.out.println( "Downloaded file: " + target + " with md5: " + Hashing.md5().hashBytes( bytes ).toString() );
453 467
454 468 Files.write( bytes, target );
455 469
456 470 return target;
457 471 }
472 +
473 + public static void disableHttpsCertificateCheck() {
474 + // This globally disables certificate checking
475 + // http://stackoverflow.com/questions/19723415/java-overriding-function-to-disable-ssl-certificate-check
476 + try
477 + {
478 + TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
479 + public java.security.cert.X509Certificate[] getAcceptedIssuers() {
480 + return null;
481 + }
482 + public void checkClientTrusted(X509Certificate[] certs, String authType) {
483 + }
484 + public void checkServerTrusted(X509Certificate[] certs, String authType) {
485 + }
486 + }
487 + };
488 + SSLContext sc = SSLContext.getInstance("SSL");
489 + sc.init(null, trustAllCerts, new java.security.SecureRandom());
490 + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
491 +
492 + HostnameVerifier allHostsValid = new HostnameVerifier() {
493 + public boolean verify(String hostname, SSLSession session) {
494 + return true;
495 + }
496 + };
497 + HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
498 + } catch ( NoSuchAlgorithmException ex )
499 + {
500 + System.out.println("Failed to disable https certificate check");
501 + ex.printStackTrace(System.out);
502 + } catch ( KeyManagementException ex )
503 + {
504 + System.out.println("Failed to disable https certificate check");
505 + ex.printStackTrace(System.out);
506 + }
507 + }
458 508 }

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut