now with some SSL

This commit is contained in:
rusefi 2020-07-17 21:49:15 -04:00
parent 1bcd038ea6
commit 7bedd0e799
3 changed files with 19 additions and 5 deletions

View File

@ -115,7 +115,7 @@ public class ServerTest {
assertTrue(applicationServerCreated.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS));
// start authenticator
IoStream authenticatorToProxyStream = TestHelper.connectToLocalhost(serverPortForRemoteUsers, logger);
IoStream authenticatorToProxyStream = TestHelper.secureConnectToLocalhost(serverPortForRemoteUsers, logger);
new HelloCommand(logger, "hello").handle(authenticatorToProxyStream);
assertTrue(disconnectedCountDownLatch.await(30, TimeUnit.SECONDS));
@ -147,7 +147,7 @@ public class ServerTest {
ApplicationRequest applicationRequest = new ApplicationRequest(sessionDetails, 123);
// start authenticator
IoStream authenticatorToProxyStream = TestHelper.connectToLocalhost(serverPortForRemoteUsers, logger);
IoStream authenticatorToProxyStream = TestHelper.secureConnectToLocalhost(serverPortForRemoteUsers, logger);
LocalApplicationProxy localApplicationProxy = new LocalApplicationProxy(logger, applicationRequest);
localApplicationProxy.run(authenticatorToProxyStream);
@ -208,7 +208,7 @@ public class ServerTest {
// start authenticator
int authenticatorPort = 7004; // local port on which authenticator accepts connections from Tuner Studio
IoStream authenticatorToProxyStream = TestHelper.connectToLocalhost(serverPortForRemoteUsers, logger);
IoStream authenticatorToProxyStream = TestHelper.secureConnectToLocalhost(serverPortForRemoteUsers, logger);
LocalApplicationProxy.startAndRun(logger, applicationRequest, authenticatorPort, authenticatorToProxyStream);

View File

@ -15,6 +15,7 @@ import com.rusefi.tools.online.ProxyClient;
import com.rusefi.tune.xml.Constant;
import org.jetbrains.annotations.NotNull;
import javax.net.ssl.SSLSocketFactory;
import java.io.IOException;
import java.net.Socket;
@ -45,6 +46,17 @@ public class TestHelper {
return server;
}
@NotNull
public static IoStream secureConnectToLocalhost(int controllerPort, Logger logger) {
IoStream targetEcuSocket;
try {
targetEcuSocket = new TcpIoStream(logger, SSLSocketFactory.getDefault().createSocket(ProxyClient.LOCALHOST, controllerPort));
} catch (IOException e) {
throw new IllegalStateException("Failed to connect to controller " + ProxyClient.LOCALHOST + ":" + controllerPort);
}
return targetEcuSocket;
}
@NotNull
public static IoStream connectToLocalhost(int controllerPort, Logger logger) {
IoStream targetEcuSocket;

View File

@ -72,7 +72,9 @@ public class Backend {
public void runApplicationConnector(int serverPortForApplications, Listener serverSocketCreationCallback) {
BinaryProtocolServer.tcpServerSocket(serverPortForApplications, "ApplicationServer", new Function<Socket, Runnable>() {
// connection from authenticator app which proxies for Tuner Studio
// authenticator pushed hello packet on connect
BinaryProtocolServer.tcpServerSocket(logger, new Function<Socket, Runnable>() {
@Override
public Runnable apply(Socket applicationSocket) {
return new Runnable() {
@ -114,7 +116,7 @@ public class Backend {
}
};
}
}, logger, serverSocketCreationCallback);
}, serverPortForApplications, "ApplicationServer", serverSocketCreationCallback, BinaryProtocolServer.SECURE_SOCKET_FACTORY);
}
protected void onDisconnectApplication() {