Randomize nitro websocket port

This commit is contained in:
UnfamiliarLegacy 2022-12-07 03:20:40 +01:00
parent 1e33b3be1a
commit fbb60cf9e3
4 changed files with 14 additions and 4 deletions

View File

@ -5,7 +5,6 @@ public final class NitroConstants {
public static final int HTTP_PORT = 9090;
public static final int HTTP_BUFFER_SIZE = 1024 * 1024 * 10;
public static final int WEBSOCKET_PORT = 2096;
public static final int WEBSOCKET_BUFFER_SIZE = 1024 * 1024 * 10;
public static final String WEBSOCKET_REVISION = "PRODUCTION-201611291003-338511768";
public static final String WEBSOCKET_CLIENT_IDENTIFIER = "HTML5";

View File

@ -24,6 +24,7 @@ public class NitroProxyProvider implements ProxyProvider, NitroHttpProxyServerCa
private final NitroWebsocketProxy nitroWebsocketProxy;
private final AtomicBoolean abortLock;
private int websocketPort;
private String originalWebsocketUrl;
private String originalCookies;
@ -63,6 +64,8 @@ public class NitroProxyProvider implements ProxyProvider, NitroHttpProxyServerCa
return;
}
websocketPort = nitroWebsocketProxy.getPort();
stateSetter.setState(HState.WAITING_FOR_CLIENT);
}
@ -101,7 +104,7 @@ public class NitroProxyProvider implements ProxyProvider, NitroHttpProxyServerCa
public String replaceWebsocketServer(String configUrl, String websocketUrl) {
originalWebsocketUrl = websocketUrl;
return String.format("ws://127.0.0.1:%d", NitroConstants.WEBSOCKET_PORT);
return String.format("ws://127.0.0.1:%d", websocketPort);
}
@Override

View File

@ -106,6 +106,7 @@ public class NitroHttpProxy {
.withPort(NitroConstants.HTTP_PORT)
.withManInTheMiddle(new NitroCertificateSniffingManager(authority))
.withFiltersSource(new NitroHttpProxyFilterSource(serverCallback))
.withTransparent(true)
.start();
if (!initializeCertificate()) {

View File

@ -3,10 +3,11 @@ package gearth.protocol.connection.proxy.nitro.websocket;
import gearth.protocol.HConnection;
import gearth.protocol.connection.HProxySetter;
import gearth.protocol.connection.HStateSetter;
import gearth.protocol.connection.proxy.nitro.NitroConstants;
import gearth.protocol.connection.proxy.nitro.NitroProxyProvider;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer;
@ -28,7 +29,7 @@ public class NitroWebsocketProxy {
this.stateSetter = stateSetter;
this.connection = connection;
this.proxyProvider = proxyProvider;
this.server = new Server(NitroConstants.WEBSOCKET_PORT);
this.server = new Server(0);
}
public boolean start() {
@ -56,6 +57,12 @@ public class NitroWebsocketProxy {
return false;
}
public int getPort() {
final ServerConnector serverConnector = (ServerConnector) server.getConnectors()[0];
return serverConnector.getLocalPort();
}
public void stop() {
try {
server.stop();