there are legit reasons not to have valid certificate path :( Drew was affected by this

This commit is contained in:
rusefi 2020-06-23 20:06:29 -04:00
parent d0979e8e4b
commit e6cc2b99e3
4 changed files with 32 additions and 9 deletions

View File

@ -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);
}
}

View File

@ -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;
}
}
}

View File

@ -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());

View File

@ -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);
}