diff --git a/java_console/autoupdate/src/com/rusefi/autoupdate/Autoupdate.java b/java_console/autoupdate/src/com/rusefi/autoupdate/Autoupdate.java index 212a54d543..dd5427883b 100644 --- a/java_console/autoupdate/src/com/rusefi/autoupdate/Autoupdate.java +++ b/java_console/autoupdate/src/com/rusefi/autoupdate/Autoupdate.java @@ -82,7 +82,6 @@ public class Autoupdate { } // todo: user could have waited hours to respond to question above, we probably need to re-establish connection - HttpURLConnection httpConnection = connectionAndMeta.getHttpConnection(); long completeFileSize = connectionAndMeta.getCompleteFileSize(); long lastModified = connectionAndMeta.getLastModified(); @@ -95,7 +94,7 @@ public class Autoupdate { System.out.println("Downloaded " + file.length() + " bytes"); unzip(zipFileName, ".."); - } catch (IOException e) { + } catch (Exception e) { System.err.println(e); } } diff --git a/java_console/autoupdate/src/com/rusefi/autoupdate/AutoupdateUtil.java b/java_console/autoupdate/src/com/rusefi/autoupdate/AutoupdateUtil.java index 4e92abcc79..9f198a81ce 100644 --- a/java_console/autoupdate/src/com/rusefi/autoupdate/AutoupdateUtil.java +++ b/java_console/autoupdate/src/com/rusefi/autoupdate/AutoupdateUtil.java @@ -3,6 +3,7 @@ package com.rusefi.autoupdate; import com.rusefi.ui.util.FrameHelper; import org.jetbrains.annotations.NotNull; +import javax.net.ssl.*; import javax.swing.*; import java.awt.*; import java.io.*; @@ -10,6 +11,11 @@ import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; import java.util.Date; import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; @@ -119,7 +125,7 @@ public class AutoupdateUtil { public static class ConnectionAndMeta { private String zipFileName; - private HttpURLConnection httpConnection; + private HttpsURLConnection httpConnection; private long completeFileSize; private long lastModified; @@ -139,12 +145,31 @@ public class AutoupdateUtil { return lastModified; } - public ConnectionAndMeta invoke() throws IOException { + public ConnectionAndMeta invoke() throws IOException, NoSuchAlgorithmException, KeyManagementException { + // user can have java with expired certificates or funny proxy, we shall accept any certificate :( + SSLContext ctx = SSLContext.getInstance("TLS"); + ctx.init(new KeyManager[0], new TrustManager[] {new AcceptAnyCertificateTrustManager()}, new SecureRandom()); + URL url = new URL("https://rusefi.com/build_server/autoupdate/" + zipFileName); - httpConnection = (HttpURLConnection) url.openConnection(); + httpConnection = (HttpsURLConnection) url.openConnection(); + httpConnection.setSSLSocketFactory(ctx.getSocketFactory()); completeFileSize = httpConnection.getContentLength(); lastModified = httpConnection.getLastModified(); return this; } } + + private static class AcceptAnyCertificateTrustManager implements X509TrustManager { + + @Override + public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {} + + @Override + public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {} + + @Override + public X509Certificate[] getAcceptedIssuers() { + return null; + } + } } diff --git a/java_tools/ts_plugin_launcher/src/com/rusefi/ts_plugin/TsPluginLauncher.java b/java_tools/ts_plugin_launcher/src/com/rusefi/ts_plugin/TsPluginLauncher.java index cab286eacd..7e63f1a8c3 100644 --- a/java_tools/ts_plugin_launcher/src/com/rusefi/ts_plugin/TsPluginLauncher.java +++ b/java_tools/ts_plugin_launcher/src/com/rusefi/ts_plugin/TsPluginLauncher.java @@ -10,7 +10,7 @@ import javax.swing.*; * by the way TS installs stuff into %user%\.efianalytics\TunerStudio\plugins folder */ public class TsPluginLauncher implements ApplicationPlugin { - static final String VERSION = "alpha2020"; + static final String VERSION = "alpha2_2020"; private static final String HELP_URL = "https://github.com/rusefi/rusefi/wiki/TS-Plugin"; private final JPanel content = new JPanel(new VerticalFlowLayout()); diff --git a/java_tools/ts_plugin_launcher/src/com/rusefi/ts_plugin/Updater.java b/java_tools/ts_plugin_launcher/src/com/rusefi/ts_plugin/Updater.java index a96934397a..bad2664911 100644 --- a/java_tools/ts_plugin_launcher/src/com/rusefi/ts_plugin/Updater.java +++ b/java_tools/ts_plugin_launcher/src/com/rusefi/ts_plugin/Updater.java @@ -9,7 +9,6 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; -import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.MalformedURLException; @@ -86,7 +85,7 @@ public class Updater { AutoupdateUtil.ConnectionAndMeta connectionAndMeta; try { connectionAndMeta = new AutoupdateUtil.ConnectionAndMeta(PLUGIN_BODY_JAR).invoke(); - } catch (IOException e) { + } catch (Exception e) { e.printStackTrace(); return; } @@ -146,7 +145,7 @@ public class Updater { startPlugin(); - } catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException e) { + } catch (Exception e) { e.printStackTrace(); download.setEnabled(true); }