* Note: Using {@link #setChainedProxyManager(ChainedProxyManager)} will supersede any value set by this method.
*
* @param chainedProxyAddress address of the upstream proxy
@@ -1181,7 +1208,6 @@ public void setChainedProxyManager(ChainedProxyManager chainedProxyManager) {
* Configures the Netty thread pool used by the LittleProxy back-end. See {@link ThreadPoolConfiguration} for details.
*
* @param threadPoolConfiguration thread pool configuration to use
- *
*/
public void setThreadPoolConfiguration(ThreadPoolConfiguration threadPoolConfiguration) {
if (isStarted()) {
@@ -1362,6 +1388,20 @@ public void setMitmDisabled(boolean mitmDisabled) throws IllegalStateException {
this.mitmDisabled = mitmDisabled;
}
+ @Override
+ public void setMitmManager(MitmManager mitmManager) {
+ this.mitmManager = mitmManager;
+ }
+
+ @Override
+ public void setTrustAllServers(boolean trustAllServers) {
+ if (isStarted()) {
+ throw new IllegalStateException("Cannot disable upstream server verification after the proxy has been started");
+ }
+
+ this.trustAllServers = trustAllServers;
+ }
+
public boolean isMitmDisabled() {
return this.mitmDisabled;
}
@@ -1501,4 +1541,5 @@ public HttpFilters filterRequest(HttpRequest originalRequest, ChannelHandlerCont
});
}
}
+
}
diff --git a/browsermob-core-littleproxy/src/main/java/net/lightbody/bmp/filters/ModifiedRequestAwareFilter.java b/browsermob-core-littleproxy/src/main/java/net/lightbody/bmp/filters/ModifiedRequestAwareFilter.java
index 1f21ac8a7..c117c0b56 100644
--- a/browsermob-core-littleproxy/src/main/java/net/lightbody/bmp/filters/ModifiedRequestAwareFilter.java
+++ b/browsermob-core-littleproxy/src/main/java/net/lightbody/bmp/filters/ModifiedRequestAwareFilter.java
@@ -1,12 +1,11 @@
package net.lightbody.bmp.filters;
-import io.netty.handler.codec.http.HttpObject;
import io.netty.handler.codec.http.HttpRequest;
/**
* Indicates that a filter wishes to capture the final HttpRequest that is sent to the server, reflecting all
- * modifications from request filters. {@link BrowserMobHttpFilterChain#clientToProxyRequest(HttpObject)} will invoke
- * the {@link #setModifiedHttpRequest(HttpRequest)} method after all filters have processed the initial
+ * modifications from request filters. {@link BrowserMobHttpFilterChain#clientToProxyRequest(io.netty.handler.codec.http.HttpObject)}
+ * will invoke the {@link #setModifiedHttpRequest(HttpRequest)} method after all filters have processed the initial
* {@link HttpRequest} object.
*/
public interface ModifiedRequestAwareFilter {
diff --git a/browsermob-core-littleproxy/src/main/java/net/lightbody/bmp/ssl/BrowserMobProxyMitmManager.java b/browsermob-core-littleproxy/src/main/java/net/lightbody/bmp/ssl/BrowserMobProxyMitmManager.java
deleted file mode 100644
index 99b31bf71..000000000
--- a/browsermob-core-littleproxy/src/main/java/net/lightbody/bmp/ssl/BrowserMobProxyMitmManager.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package net.lightbody.bmp.ssl;
-
-import org.littleshoot.proxy.MitmManager;
-
-import javax.net.ssl.SSLEngine;
-import javax.net.ssl.SSLSession;
-
-/**
- * This implementation mirrors the implementation of {@link org.littleshoot.proxy.extras.SelfSignedMitmManager}, but uses the
- * cybervillainsCA.jks keystore that the Jetty implementaion uses.
- */
-public class BrowserMobProxyMitmManager implements MitmManager {
- private final BrowserMobSslEngineSource bmpSslEngineSource =
- new BrowserMobSslEngineSource();
-
- @Override
- public SSLEngine serverSslEngine(String host, int port) {
- return bmpSslEngineSource.newSslEngine(host, port);
- }
-
- @Override
- public SSLEngine clientSslEngineFor(SSLSession serverSslSession) {
- return bmpSslEngineSource.newSslEngine();
- }
-}
-
diff --git a/browsermob-core-littleproxy/src/main/java/net/lightbody/bmp/ssl/BrowserMobSslEngineSource.java b/browsermob-core-littleproxy/src/main/java/net/lightbody/bmp/ssl/BrowserMobSslEngineSource.java
deleted file mode 100644
index 79a27c8b1..000000000
--- a/browsermob-core-littleproxy/src/main/java/net/lightbody/bmp/ssl/BrowserMobSslEngineSource.java
+++ /dev/null
@@ -1,102 +0,0 @@
-package net.lightbody.bmp.ssl;
-
-import org.littleshoot.proxy.SslEngineSource;
-
-import javax.net.ssl.KeyManager;
-import javax.net.ssl.KeyManagerFactory;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLEngine;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.TrustManagerFactory;
-import javax.net.ssl.X509TrustManager;
-import java.io.InputStream;
-import java.security.KeyStore;
-import java.security.Security;
-import java.security.cert.CertificateException;
-import java.security.cert.X509Certificate;
-
-/**
- * This implementation mirrors the implementation of {@link org.littleshoot.proxy.extras.SelfSignedSslEngineSource}, but uses the
- * cybervillainsCA.jks keystore that the Jetty implementaion uses.
- */
-public class BrowserMobSslEngineSource implements SslEngineSource {
- private static final String KEYSTORE_RESOURCE = "/sslSupport/cybervillainsCA.jks";
-
- private static final char[] KEYSTORE_PASSWORD = "password".toCharArray();
-
- private final SSLContext sslContext;
-
- public BrowserMobSslEngineSource() {
- this.sslContext = initializeSSLContext();
- }
-
- @Override
- public SSLEngine newSslEngine() {
- return sslContext.createSSLEngine();
- }
-
- @Override
- public SSLEngine newSslEngine(String host, int port) {
- return sslContext.createSSLEngine(host, port);
- }
-
- private SSLContext initializeSSLContext() {
- String algorithm = Security
- .getProperty("ssl.KeyManagerFactory.algorithm");
- if (algorithm == null) {
- algorithm = "SunX509";
- }
-
- InputStream keystoreStream = getClass().getResourceAsStream(KEYSTORE_RESOURCE);
- if (keystoreStream == null) {
- throw new RuntimeException("Unable to load keystore from classpath resource: " + KEYSTORE_RESOURCE);
- }
-
- try {
- final KeyStore ks = KeyStore.getInstance("JKS");
- // ks.load(new FileInputStream("keystore.jks"),
- // "changeit".toCharArray());
- ks.load(keystoreStream, KEYSTORE_PASSWORD);
-
- // Set up key manager factory to use our key store
- final KeyManagerFactory kmf =
- KeyManagerFactory.getInstance(algorithm);
- kmf.init(ks, KEYSTORE_PASSWORD);
-
- // Set up a trust manager factory to use our key store
- TrustManagerFactory tmf = TrustManagerFactory
- .getInstance(algorithm);
- tmf.init(ks);
-
- TrustManager[] trustManagers = new TrustManager[]{new X509TrustManager() {
- // TrustManager that trusts all servers
- @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;
- }
- }};
-
- KeyManager[] keyManagers = kmf.getKeyManagers();
-
- // Initialize the SSLContext to work with our key managers.
- SSLContext sslContext = SSLContext.getInstance("TLS");
- sslContext.init(keyManagers, trustManagers, null);
-
- return sslContext;
- } catch (Exception e) {
- throw new RuntimeException("Failed to initialize the server-side SSLContext", e);
- }
- }
-}
diff --git a/browsermob-core-littleproxy/src/test/groovy/net/lightbody/bmp/filters/RewriteUrlFilterTest.groovy b/browsermob-core-littleproxy/src/test/groovy/net/lightbody/bmp/filters/RewriteUrlFilterTest.groovy
index f9b4cead0..9d6350540 100644
--- a/browsermob-core-littleproxy/src/test/groovy/net/lightbody/bmp/filters/RewriteUrlFilterTest.groovy
+++ b/browsermob-core-littleproxy/src/test/groovy/net/lightbody/bmp/filters/RewriteUrlFilterTest.groovy
@@ -156,6 +156,7 @@ class RewriteUrlFilterTest extends MockServerTest {
.withBody("success"))
proxy = new BrowserMobProxyServer()
+ proxy.setTrustAllServers(true)
proxy.rewriteUrl('https://localhost:(\\d+)/badresource', 'https://localhost:$1/rewrittenresource')
proxy.start()
diff --git a/browsermob-core-littleproxy/src/test/groovy/net/lightbody/bmp/proxy/BlacklistTest.groovy b/browsermob-core-littleproxy/src/test/groovy/net/lightbody/bmp/proxy/BlacklistTest.groovy
index 23f97bd05..c6e86249c 100644
--- a/browsermob-core-littleproxy/src/test/groovy/net/lightbody/bmp/proxy/BlacklistTest.groovy
+++ b/browsermob-core-littleproxy/src/test/groovy/net/lightbody/bmp/proxy/BlacklistTest.groovy
@@ -56,6 +56,7 @@ class BlacklistTest extends MockServerTest {
.withBody("this URL should never be called"))
proxy = new BrowserMobProxyServer()
+ proxy.setTrustAllServers(true)
proxy.start()
int proxyPort = proxy.getPort()
@@ -128,6 +129,7 @@ class BlacklistTest extends MockServerTest {
.withBody("not blacklisted"))
proxy = new BrowserMobProxyServer()
+ proxy.setTrustAllServers(true)
proxy.start()
int proxyPort = proxy.getPort()
diff --git a/browsermob-core-littleproxy/src/test/groovy/net/lightbody/bmp/proxy/NewHarTest.groovy b/browsermob-core-littleproxy/src/test/groovy/net/lightbody/bmp/proxy/NewHarTest.groovy
index f466b5313..6d5ad4fd5 100644
--- a/browsermob-core-littleproxy/src/test/groovy/net/lightbody/bmp/proxy/NewHarTest.groovy
+++ b/browsermob-core-littleproxy/src/test/groovy/net/lightbody/bmp/proxy/NewHarTest.groovy
@@ -115,6 +115,7 @@ class NewHarTest extends MockServerTest {
proxy = new BrowserMobProxyServer();
proxy.setHarCaptureTypes([CaptureType.RESPONSE_COOKIES] as Set)
+ proxy.setTrustAllServers(true)
proxy.start()
proxy.newHar()
@@ -457,7 +458,8 @@ class NewHarTest extends MockServerTest {
.withStatusCode(200)
.withBody("success"))
- proxy = new BrowserMobProxyServer();
+ proxy = new BrowserMobProxyServer()
+ proxy.setTrustAllServers(true)
proxy.start()
proxy.newHar()
@@ -497,6 +499,7 @@ class NewHarTest extends MockServerTest {
proxy = new BrowserMobProxyServer();
proxy.rewriteUrl("https://localhost:${mockServerPort}/originalurl(.*)", "https://localhost:${mockServerPort}/httpsrewrittenurlcaptured\$1")
+ proxy.setTrustAllServers(true)
proxy.start()
proxy.newHar()
@@ -855,6 +858,7 @@ class NewHarTest extends MockServerTest {
.withBody("success"))
proxy = new BrowserMobProxyServer();
+ proxy.setTrustAllServers(true)
proxy.setIdleConnectionTimeout(3, TimeUnit.SECONDS)
proxy.start()
diff --git a/browsermob-core-littleproxy/src/test/groovy/net/lightbody/bmp/proxy/WhitelistTest.groovy b/browsermob-core-littleproxy/src/test/groovy/net/lightbody/bmp/proxy/WhitelistTest.groovy
index 0215d63a9..e5aac303d 100644
--- a/browsermob-core-littleproxy/src/test/groovy/net/lightbody/bmp/proxy/WhitelistTest.groovy
+++ b/browsermob-core-littleproxy/src/test/groovy/net/lightbody/bmp/proxy/WhitelistTest.groovy
@@ -77,6 +77,7 @@ class WhitelistTest extends MockServerTest {
.withBody("should never be returned"))
proxy = new BrowserMobProxyServer()
+ proxy.setTrustAllServers(true)
proxy.start()
int proxyPort = proxy.getPort()
@@ -127,6 +128,7 @@ class WhitelistTest extends MockServerTest {
.withBody("whitelisted"))
proxy = new BrowserMobProxyServer()
+ proxy.setTrustAllServers(true)
proxy.start()
int proxyPort = proxy.getPort()
@@ -199,6 +201,7 @@ class WhitelistTest extends MockServerTest {
.withBody("should never be returned"))
proxy = new BrowserMobProxyServer()
+ proxy.setTrustAllServers(true)
proxy.start()
int proxyPort = proxy.getPort()
diff --git a/browsermob-core-littleproxy/src/test/java/net/lightbody/bmp/proxy/InterceptorTest.java b/browsermob-core-littleproxy/src/test/java/net/lightbody/bmp/proxy/InterceptorTest.java
index 41179b977..9f8a2bae0 100644
--- a/browsermob-core-littleproxy/src/test/java/net/lightbody/bmp/proxy/InterceptorTest.java
+++ b/browsermob-core-littleproxy/src/test/java/net/lightbody/bmp/proxy/InterceptorTest.java
@@ -249,6 +249,7 @@ public void testRequestFilterCanModifyHttpsRequestBody() throws IOException {
.withBody("success"));
proxy = new BrowserMobProxyServer();
+ proxy.setTrustAllServers(true);
proxy.start();
proxy.addRequestFilter(new RequestFilter() {
@@ -367,6 +368,7 @@ public void testResponseFilterCanModifyHttpsTextContents() throws IOException {
.withBody(originalText));
proxy = new BrowserMobProxyServer();
+ proxy.setTrustAllServers(true);
proxy.start();
proxy.addResponseFilter(new ResponseFilter() {
@@ -839,6 +841,7 @@ public void testHttpsResponseFilterUrlReflectsModifications() throws IOException
.withBody("success"));
proxy = new BrowserMobProxyServer();
+ proxy.setTrustAllServers(true);
proxy.start();
final AtomicReference