Skip to content

Commit f4bc0f4

Browse files
v4 with jetty 11
1 parent 373c4a1 commit f4bc0f4

File tree

13 files changed

+850
-531
lines changed

13 files changed

+850
-531
lines changed

.github/workflows/release.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v2
15+
16+
- name: Set up JDK 11
17+
uses: actions/setup-java@v2
18+
with:
19+
java-version: '11'
20+
distribution: 'adoptopenjdk'
21+
22+
- name: Cache Maven dependencies
23+
uses: actions/cache@v2
24+
with:
25+
path: ~/.m2/repository
26+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
27+
restore-keys: |
28+
${{ runner.os }}-maven-
29+
30+
# Run Maven to package the project
31+
- name: Build with Maven
32+
run: mvn clean package -DskipTests
33+
34+
# Upload the JAR as a release asset
35+
- name: Upload JAR to GitHub Releases
36+
uses: softprops/action-gh-release@v1
37+
with:
38+
files: target/*.jar
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

pom.xml

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>com.testingbot</groupId>
55
<artifactId>TestingBotTunnel</artifactId>
6-
<version>3.6-SNAPSHOT</version>
6+
<version>4.0-SNAPSHOT</version>
77
<packaging>jar</packaging>
88

99
<properties>
@@ -120,22 +120,22 @@
120120
<dependency>
121121
<groupId>org.eclipse.jetty</groupId>
122122
<artifactId>jetty-server</artifactId>
123-
<version>9.4.43.v20210629</version>
123+
<version>11.0.24</version>
124124
</dependency>
125125
<dependency>
126126
<groupId>org.eclipse.jetty</groupId>
127127
<artifactId>jetty-servlet</artifactId>
128-
<version>9.4.43.v20210629</version>
128+
<version>11.0.24</version>
129129
</dependency>
130130
<dependency>
131131
<groupId>org.eclipse.jetty</groupId>
132132
<artifactId>jetty-proxy</artifactId>
133-
<version>9.4.43.v20210629</version>
133+
<version>11.0.24</version>
134134
</dependency>
135135
<dependency>
136136
<groupId>org.eclipse.jetty</groupId>
137137
<artifactId>jetty-servlets</artifactId>
138-
<version>9.4.43.v20210629</version>
138+
<version>11.0.24</version>
139139
<type>jar</type>
140140
</dependency>
141141
<dependency>
@@ -153,11 +153,27 @@
153153
<artifactId>commons-cli</artifactId>
154154
<version>1.4</version>
155155
</dependency>
156-
<dependency>
157-
<groupId>net.sf.json-lib</groupId>
158-
<artifactId>json-lib</artifactId>
159-
<version>2.4</version>
160-
<classifier>jdk15</classifier>
161-
</dependency>
156+
<dependency>
157+
<groupId>net.sf.json-lib</groupId>
158+
<artifactId>json-lib</artifactId>
159+
<version>2.4</version>
160+
<classifier>jdk15</classifier>
161+
</dependency>
162+
<dependency>
163+
<groupId>org.slf4j</groupId>
164+
<artifactId>slf4j-api</artifactId>
165+
<version>1.7.32</version>
166+
</dependency>
167+
<dependency>
168+
<groupId>ch.qos.logback</groupId>
169+
<artifactId>logback-classic</artifactId>
170+
<version>1.2.6</version>
171+
</dependency>
172+
173+
<dependency>
174+
<groupId>ch.qos.logback</groupId>
175+
<artifactId>logback-core</artifactId>
176+
<version>1.2.6</version>
177+
</dependency>
162178
</dependencies>
163179
</project>

src/main/java/com/testingbot/tunnel/Api.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public JSONObject createTunnel() throws Exception {
5555
if (app.isBypassingSquid()) {
5656
nameValuePairs.add(new BasicNameValuePair("no_cache", String.valueOf(app.isBypassingSquid())));
5757
}
58+
if (app.isNoBump()) {
59+
nameValuePairs.add(new BasicNameValuePair("no_bump", String.valueOf(app.isNoBump())));
60+
}
5861
return this._post("https://" + apiHost + "/v1/tunnel/create", nameValuePairs);
5962
}
6063
catch (Exception e) {

src/main/java/com/testingbot/tunnel/App.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,15 @@
1717
import java.util.logging.ConsoleHandler;
1818
import java.util.logging.FileHandler;
1919
import java.util.logging.Handler;
20-
import java.util.logging.LogManager;
2120
import java.util.logging.Level;
2221
import java.util.logging.Logger;
2322
import net.sf.json.JSONObject;
2423
import org.apache.commons.cli.*;
2524
import ssh.SSHTunnel;
2625
import ssh.TunnelPoller;
27-
import org.eclipse.jetty.util.log.Log;
28-
import org.eclipse.jetty.util.log.JavaUtilLog;
2926

3027
public class App {
31-
public static final Float VERSION = 3.5f;
28+
public static final Float VERSION = 4.0f;
3229
private Api api;
3330
private String clientKey;
3431
private String clientSecret;
@@ -44,6 +41,7 @@ public class App {
4441
private int jettyPort = 0;
4542
private boolean noProxy = false;
4643
private boolean bypassSquid = false;
44+
private boolean noBump = false;
4745
private boolean debugMode = false;
4846
private HttpProxy httpProxy;
4947
private String proxy;
@@ -118,13 +116,11 @@ public static void main(String... args) throws Exception {
118116

119117
options.addOption("x", "noproxy", false, "Do not start a local proxy (requires user provided proxy server on port 8087)");
120118
options.addOption("q", "nocache", false, "Bypass our Caching Proxy running on our tunnel VM.");
119+
options.addOption("b", "nobump", false, "Do not perform SSL bumping.");
121120
options.addOption("j", "localproxy", true, "The port to launch the local proxy on (default 8087)");
122121
options.addOption(null, "doctor", false, "Perform checks to detect possible misconfiguration or problems.");
123122
options.addOption("v", "version", false, "Displays the current version of this program");
124123

125-
Log.setLog(new TestingBotLogHandler());
126-
System.setProperty("org.eclipse.jetty.LEVEL", "OFF");
127-
128124
Statistics.setStartTime(System.currentTimeMillis());
129125

130126
CommandLine commandLine;
@@ -149,17 +145,12 @@ public static void main(String... args) throws Exception {
149145

150146
App app = new App();
151147
if (commandLine.hasOption("debug")) {
152-
Log.setLog(new JavaUtilLog());
153-
Logger.getLogger(App.class.getName()).log(Level.INFO, "Running in debug-mode");
154-
Logger.getLogger(App.class.getName()).setLevel(Level.ALL);
148+
System.setProperty("org.eclipse.jetty.LEVEL", "DEBUG");
149+
logger.log(Level.INFO, "Running in debug-mode");
150+
logger.setLevel(Level.ALL);
155151
app.setDebugMode(true);
156-
Logger rootLogger = LogManager.getLogManager().getLogger("");
157-
rootLogger.setLevel(Level.ALL);
158-
for (Handler h : rootLogger.getHandlers()) {
159-
h.setLevel(Level.ALL);
160-
}
161152
} else {
162-
Logger.getLogger(App.class.getName()).setLevel(Level.INFO);
153+
logger.setLevel(Level.INFO);
163154
}
164155

165156
if (commandLine.hasOption("logfile")) {
@@ -280,6 +271,11 @@ public static void main(String... args) throws Exception {
280271
app.bypassSquid = true;
281272
}
282273

274+
if (commandLine.hasOption("nobump")) {
275+
Logger.getLogger(App.class.getName()).log(Level.INFO, "Disable SSL bumping. SSL certificates will not be rewritten.");
276+
app.noBump = true;
277+
}
278+
283279
if (commandLine.hasOption("hubport")) {
284280
app.hubPort = Integer.parseInt(commandLine.getOptionValue("hubport"));
285281
if ((app.hubPort != 80) && (app.hubPort != 4444)) {
@@ -586,6 +582,10 @@ public boolean isBypassingSquid() {
586582
return bypassSquid;
587583
}
588584

585+
public boolean isNoBump() {
586+
return noBump;
587+
}
588+
589589
/**
590590
* @return the debugMode
591591
*/

src/main/java/com/testingbot/tunnel/HttpProxy.java

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,28 @@
1111
import java.util.List;
1212
import java.util.logging.Level;
1313
import java.util.logging.Logger;
14-
import javax.servlet.http.HttpServletRequest;
15-
import javax.servlet.http.HttpServletResponse;
14+
15+
import com.testingbot.tunnel.proxy.WebsocketHandler;
16+
import jakarta.servlet.http.HttpServletRequest;
17+
import jakarta.servlet.http.HttpServletResponse;
1618
import org.apache.http.HttpResponse;
1719
import org.apache.http.NameValuePair;
1820
import org.apache.http.client.HttpClient;
1921
import org.apache.http.client.entity.UrlEncodedFormEntity;
2022
import org.apache.http.client.methods.HttpPost;
2123
import org.apache.http.impl.client.HttpClientBuilder;
2224
import org.apache.http.message.BasicNameValuePair;
23-
import org.eclipse.jetty.server.Connector;
25+
import org.eclipse.jetty.proxy.ConnectHandler;
2426
import org.eclipse.jetty.server.HttpConfiguration;
2527
import org.eclipse.jetty.server.HttpConnectionFactory;
2628
import org.eclipse.jetty.server.Request;
2729
import org.eclipse.jetty.server.Server;
2830
import org.eclipse.jetty.server.ServerConnector;
2931
import org.eclipse.jetty.server.handler.AbstractHandler;
32+
import org.eclipse.jetty.server.handler.HandlerList;
3033
import org.eclipse.jetty.servlet.ServletHolder;
31-
32-
import org.eclipse.jetty.server.handler.HandlerCollection;
3334
import org.eclipse.jetty.servlet.ServletContextHandler;
35+
3436
/**
3537
*
3638
* @author TestingBot
@@ -45,17 +47,27 @@ public HttpProxy(App app) {
4547
this.app = app;
4648

4749
this.httpProxy = new Server();
48-
HttpConfiguration http_config = new HttpConfiguration();
49-
ServerConnector connector = new ServerConnector(httpProxy,
50+
51+
HttpConfiguration http_config = new HttpConfiguration();
52+
53+
ServerConnector proxyConnector = new ServerConnector(httpProxy,
5054
new HttpConnectionFactory(http_config));
51-
connector.setPort(app.getJettyPort());
52-
connector.setIdleTimeout(400000);
53-
httpProxy.setConnectors(new Connector[] { connector });
55+
56+
proxyConnector.setPort(app.getJettyPort());
57+
proxyConnector.setIdleTimeout(400000);
58+
httpProxy.addConnector(proxyConnector);
5459
httpProxy.setStopAtShutdown(true);
5560

56-
ServletHolder servletHolder = new ServletHolder(TunnelProxyServlet.class);
57-
servletHolder.setInitParameter("idleTimeout", "120000");
58-
servletHolder.setInitParameter("timeout", "120000");
61+
ConnectHandler connectHandler = new CustomConnectHandler(app);
62+
WebsocketHandler websocketHandler = new WebsocketHandler();
63+
64+
ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
65+
contextHandler.setContextPath("/"); // Root path for all requests
66+
67+
// AsyncProxyServlet for proxying HTTP requests
68+
ServletHolder proxyServlet = new ServletHolder(new TunnelProxyServlet());
69+
proxyServlet.setInitParameter("idleTimeout", "120000");
70+
proxyServlet.setInitParameter("timeout", "120000");
5971

6072
if (app.getFastFail() != null && app.getFastFail().length > 0) {
6173
StringBuilder sb = new StringBuilder();
@@ -65,44 +77,35 @@ public HttpProxy(App app) {
6577
}
6678
sb.append(domain).append(",");
6779
}
68-
servletHolder.setInitParameter("blackList", sb.toString());
80+
proxyServlet.setInitParameter("blackList", sb.toString());
6981
}
7082

7183
if (app.isDebugMode()) {
72-
servletHolder.setInitParameter("tb_debug", "true");
84+
proxyServlet.setInitParameter("tb_debug", "true");
7385
}
7486

7587
if (app.getProxy() != null) {
76-
servletHolder.setInitParameter("proxy", app.getProxy());
88+
proxyServlet.setInitParameter("proxy", app.getProxy());
7789
}
7890

7991
if (app.getProxyAuth() != null) {
80-
servletHolder.setInitParameter("proxyAuth", app.getProxyAuth());
92+
proxyServlet.setInitParameter("proxyAuth", app.getProxyAuth());
8193
}
8294

8395
if (app.getBasicAuth() != null) {
84-
servletHolder.setInitParameter("basicAuth", String.join(",", app.getBasicAuth()));
96+
proxyServlet.setInitParameter("basicAuth", String.join(",", app.getBasicAuth()));
8597
}
8698

87-
servletHolder.setInitParameter("jetty", String.valueOf(app.getJettyPort()));
99+
proxyServlet.setInitParameter("jetty", String.valueOf(app.getJettyPort()));
88100

89-
HandlerCollection handlers = new HandlerCollection();
90-
httpProxy.setHandler(handlers);
101+
contextHandler.addServlet(proxyServlet, "/*"); // Proxy all HTTP requests
91102

92-
ServletContextHandler context = new ServletContextHandler(handlers, "/", ServletContextHandler.SESSIONS);
93-
context.addServlet(servletHolder, "/*");
94-
context.setAttribute("extra_headers", app.getCustomHeaders());
95-
CustomConnectHandler proxy = new CustomConnectHandler(app);
96-
proxy.setDebugMode(app.isDebugMode());
97-
if (app.getFastFail() != null && app.getFastFail().length > 0) {
98-
for (String domain : app.getFastFail()) {
99-
if (!domain.contains(":")) {
100-
domain = domain + ":443"; // default port 443 (SSL)
101-
}
102-
proxy.getBlackListHosts().add(domain);
103-
}
104-
}
105-
handlers.addHandler(proxy);
103+
// Add the context handler to the server
104+
HandlerList handlers = new HandlerList();
105+
handlers.addHandler(websocketHandler); // For handling WS requests
106+
handlers.addHandler(connectHandler); // For handling HTTPS requests (if needed)
107+
handlers.addHandler(contextHandler); // For handling HTTP requests through proxy servlet
108+
httpProxy.setHandler(handlers);
106109

107110
start();
108111

@@ -206,11 +209,9 @@ public boolean testProxy() {
206209
private class TestHandler extends AbstractHandler {
207210
@Override
208211
public void handle(String target,
209-
Request baseRequest,
210-
HttpServletRequest request,
211-
HttpServletResponse response)
212-
throws IOException
213-
{
212+
Request baseRequest,
213+
HttpServletRequest request,
214+
HttpServletResponse response) throws IOException {
214215
response.setContentType("text/html;charset=utf-8");
215216
response.setStatus(HttpServletResponse.SC_OK);
216217
baseRequest.setHandled(true);

0 commit comments

Comments
 (0)