Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/maven/G-Earth/ch.qos.logback-lo…
Browse files Browse the repository at this point in the history
…gback-core-1.3.12
  • Loading branch information
sirjonasxx authored Jun 20, 2024
2 parents fd9f2c3 + 1a4543b commit 186141c
Show file tree
Hide file tree
Showing 13 changed files with 217 additions and 49 deletions.
4 changes: 2 additions & 2 deletions G-Earth/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<properties>
<javafx.version>1.8</javafx.version>
<jettyVersion>9.4.51.v20230217</jettyVersion>
<jettyVersion>9.4.53.v20231009</jettyVersion>
<logback.version>1.3.12</logback.version>
</properties>

Expand Down Expand Up @@ -209,7 +209,7 @@
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20230227</version>
<version>20231013</version>
</dependency>
<dependency>
<groupId>org.fxmisc.richtext</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class HOffer {
private int priceInCredits;
private int priceInActivityPoints;
private int activityPointType;
private int priceInSilver;
private boolean giftable;
private List<HProduct> products = new ArrayList<>();
private int clubLevel;
Expand All @@ -28,6 +29,7 @@ protected HOffer(HPacket packet) {
this.priceInCredits = packet.readInteger();
this.priceInActivityPoints = packet.readInteger();
this.activityPointType = packet.readInteger();
this.priceInSilver = packet.readInteger();
this.giftable = packet.readBoolean();

int productCount = packet.readInteger();
Expand Down Expand Up @@ -65,6 +67,10 @@ public int getActivityPointType() {
return activityPointType;
}

public int getPriceInSilver() {
return priceInSilver;
}

public boolean isGiftable() {
return giftable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ProxyProviderFactory {
autoDetectHosts.add("game-it.habbo.com:30000");
autoDetectHosts.add("game-nl.habbo.com:30000");
autoDetectHosts.add("game-tr.habbo.com:30000");
autoDetectHosts.add("game-us.habbo.com:38101");
autoDetectHosts.add("game-us.habbo.com:30000");
autoDetectHosts.add("game-s2.habbo.com:30000");

List<Object> additionalCachedHotels = Cacher.getList(HOTELS_CACHE_KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
import gearth.protocol.connection.HState;
import gearth.protocol.connection.HStateSetter;
import gearth.protocol.connection.proxy.ProxyProvider;
import gearth.protocol.connection.proxy.nitro.http.NitroAuthority;
import gearth.protocol.connection.proxy.nitro.http.NitroCertificateSniffingManager;
import gearth.protocol.connection.proxy.nitro.http.NitroHttpProxy;
import gearth.protocol.connection.proxy.nitro.http.NitroHttpProxyServerCallback;
import gearth.protocol.connection.proxy.nitro.websocket.NitroWebsocketProxy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.ServerSocket;
import java.util.concurrent.atomic.AtomicBoolean;

public class NitroProxyProvider implements ProxyProvider, NitroHttpProxyServerCallback, StateChangeListener {
Expand All @@ -32,11 +33,14 @@ public class NitroProxyProvider implements ProxyProvider, NitroHttpProxyServerCa
private String originalCookies;

public NitroProxyProvider(HProxySetter proxySetter, HStateSetter stateSetter, HConnection connection) {
final NitroAuthority authority = new NitroAuthority();
final NitroCertificateSniffingManager certificateManager = new NitroCertificateSniffingManager(authority);

this.proxySetter = proxySetter;
this.stateSetter = stateSetter;
this.connection = connection;
this.nitroHttpProxy = new NitroHttpProxy(this);
this.nitroWebsocketProxy = new NitroWebsocketProxy(proxySetter, stateSetter, connection, this);
this.nitroHttpProxy = new NitroHttpProxy(this, certificateManager);
this.nitroWebsocketProxy = new NitroWebsocketProxy(proxySetter, stateSetter, connection, this, certificateManager);
this.abortLock = new AtomicBoolean();
}

Expand Down Expand Up @@ -122,7 +126,7 @@ public void abort() {
public String replaceWebsocketServer(String configUrl, String websocketUrl) {
originalWebsocketUrl = websocketUrl;

return String.format("ws://127.0.0.1:%d", websocketPort);
return String.format("wss://127.0.0.1:%d", websocketPort);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,31 @@ public class NitroCertificateSniffingManager implements MitmManager {
private static final boolean DEBUG = false;

private final BouncyCastleSslEngineSource sslEngineSource;
private final Authority authority;

public NitroCertificateSniffingManager(Authority authority) throws RootCertificateException {
public NitroCertificateSniffingManager(Authority authority) {
this.authority = authority;
try {
sslEngineSource = new BouncyCastleSslEngineSource(authority, true, true, null);
} catch (final Exception e) {
throw new RootCertificateException("Errors during assembling root CA.", e);
throw new RuntimeException(new RootCertificateException("Errors during assembling root CA.", e));
}
}

public Authority getAuthority() {
return authority;
}

public SSLEngine websocketSslEngine(String commonName) {
final SubjectAlternativeNameHolder san = new SubjectAlternativeNameHolder();

san.addDomainName("localhost");
san.addIpAddress("127.0.0.1");

try {
return sslEngineSource.createCertForHost(commonName, san);
} catch (Exception e) {
throw new FakeCertificateException("Failed to create WebSocket certificate", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import javafx.scene.control.Label;
import org.littleshoot.proxy.HttpProxyServer;
import org.littleshoot.proxy.impl.DefaultHttpProxyServer;
import org.littleshoot.proxy.mitm.Authority;
import org.littleshoot.proxy.mitm.RootCertificateException;

import java.io.File;
import java.io.IOException;
Expand All @@ -25,20 +23,20 @@ public class NitroHttpProxy {
private static final String ADMIN_WARNING_KEY = "admin_warning_dialog";
private static final AtomicBoolean SHUTDOWN_HOOK = new AtomicBoolean();

private final Authority authority;
private final NitroOsFunctions osFunctions;
private final NitroHttpProxyServerCallback serverCallback;
private final NitroCertificateSniffingManager certificateManager;

private HttpProxyServer proxyServer = null;

public NitroHttpProxy(NitroHttpProxyServerCallback serverCallback) {
public NitroHttpProxy(NitroHttpProxyServerCallback serverCallback, NitroCertificateSniffingManager certificateManager) {
this.serverCallback = serverCallback;
this.authority = new NitroAuthority();
this.certificateManager = certificateManager;
this.osFunctions = NitroOsFunctionsFactory.create();
}

private boolean initializeCertificate() {
final File certificate = this.authority.aliasFile(".pem");
final File certificate = this.certificateManager.getAuthority().aliasFile(".pem");

// All good if certificate is already trusted.
if (this.osFunctions.isRootCertificateTrusted(certificate)) {
Expand Down Expand Up @@ -80,7 +78,7 @@ private boolean initializeCertificate() {
return false;
}

return this.osFunctions.installRootCertificate(this.authority.aliasFile(".pem"));
return this.osFunctions.installRootCertificate(this.certificateManager.getAuthority().aliasFile(".pem"));
}

/**
Expand All @@ -100,33 +98,28 @@ private boolean unregisterProxy() {
public boolean start() {
setupShutdownHook();

try {
proxyServer = DefaultHttpProxyServer.bootstrap()
.withPort(NitroConstants.HTTP_PORT)
.withManInTheMiddle(new NitroCertificateSniffingManager(authority))
.withFiltersSource(new NitroHttpProxyFilterSource(serverCallback))
.withTransparent(true)
.start();

if (!initializeCertificate()) {
proxyServer.stop();

System.out.println("Failed to initialize certificate");
return false;
}
proxyServer = DefaultHttpProxyServer.bootstrap()
.withPort(NitroConstants.HTTP_PORT)
.withManInTheMiddle(this.certificateManager)
.withFiltersSource(new NitroHttpProxyFilterSource(serverCallback))
.withTransparent(true)
.start();

if (!registerProxy()) {
proxyServer.stop();
if (!initializeCertificate()) {
proxyServer.stop();

System.out.println("Failed to register certificate");
return false;
}
System.out.println("Failed to initialize certificate");
return false;
}

return true;
} catch (RootCertificateException e) {
e.printStackTrace();
if (!registerProxy()) {
proxyServer.stop();

System.out.println("Failed to register certificate");
return false;
}

return true;
}

public void pause() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,24 @@

public class NitroHttpProxyFilter extends HttpFiltersAdapter {

private static final String NitroConfigSearch = "\"socket.url\"";
private static final String NitroConfigSearch = "socket.url";
private static final String NitroClientSearch = "configurationUrls:";
private static final Pattern NitroConfigPattern = Pattern.compile("\"socket\\.url\":.?\"(wss?://.*?)\"", Pattern.MULTILINE);
private static final Pattern NitroConfigPattern = Pattern.compile("[\"']socket\\.url[\"']:(\\s+)?[\"'](wss?:.*?)[\"']", Pattern.MULTILINE);

// https://developers.cloudflare.com/fundamentals/get-started/reference/cloudflare-cookies/
private static final HashSet<String> CloudflareCookies = new HashSet<>(Arrays.asList(
"__cflb",
"__cf_bm",
"__cfseq",
"cf_ob_info",
"cf_use_ob",
"__cfwaitingroom",
"__cfruid",
"cf_clearance"
"_cfuvid",
"cf_clearance",
"cf_chl_rc_i",
"cf_chl_rc_ni",
"cf_chl_rc_m"
));

private static final String HeaderAcceptEncoding = "Accept-Encoding";
Expand Down Expand Up @@ -95,11 +100,11 @@ public HttpObject serverToProxyResponse(HttpObject httpObject) {
final Matcher matcher = NitroConfigPattern.matcher(responseBody);

if (matcher.find()) {
final String originalWebsocket = matcher.group(1);
final String originalWebsocket = matcher.group(2).replace("\\/", "/");
final String replacementWebsocket = callback.replaceWebsocketServer(this.url, originalWebsocket);

if (replacementWebsocket != null) {
responseBody = responseBody.replace(originalWebsocket, replacementWebsocket);
responseBody = responseBody.replace(matcher.group(2), replacementWebsocket);
responseModified = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package gearth.protocol.connection.proxy.nitro.http;

import org.eclipse.jetty.util.ssl.SslContextFactory;

import javax.net.ssl.SSLEngine;

public class NitroSslContextFactory extends SslContextFactory.Server {

private final NitroCertificateSniffingManager certificateManager;

public NitroSslContextFactory(NitroCertificateSniffingManager certificateManager) {
this.certificateManager = certificateManager;
}

@Override
public SSLEngine newSSLEngine(String host, int port) {
System.out.printf("[NitroSslContextFactory] Creating SSLEngine for %s:%d%n", host, port);
return certificateManager.websocketSslEngine(host);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gearth.protocol.connection.proxy.nitro.os;

import gearth.misc.OSValidator;
import gearth.protocol.connection.proxy.nitro.os.macos.NitroMacOS;
import gearth.protocol.connection.proxy.nitro.os.windows.NitroWindows;
import org.apache.commons.lang3.NotImplementedException;

Expand All @@ -15,7 +16,10 @@ public static NitroOsFunctions create() {
throw new NotImplementedException("unix nitro is not implemented yet");
}

throw new NotImplementedException("macOS nitro is not implemented yet");
}
if (OSValidator.isMac()) {
return new NitroMacOS();
}

throw new NotImplementedException("unsupported operating system");
}
}
Loading

1 comment on commit 186141c

@KendryS1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ciao dovrei potrei scriverti sono un tuo fans di youtube

Please sign in to comment.