Skip to content

Commit

Permalink
minor enhancement of DNS record handlings
Browse files Browse the repository at this point in the history
  • Loading branch information
tkohegyi committed Dec 14, 2023
1 parent 2e6b288 commit 89f7761
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ext.myBuildNumber='SNAPSHOT'
if ( hasProperty('buildNumber') ) {
myBuildNumber = "${project.ext.buildNumber}"
}
version = "$wilmaVersion" + ".27." + "${project.ext.myBuildNumber}"
version = "$wilmaVersion" + ".28." + "${project.ext.myBuildNumber}"
mainClassName = "website.magyar.mitm.standalone.StandaloneProxy"

def isSnapshot = project.version.contains('SNAPSHOT')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ private static void reportError(final Exception e, final URL url, final HttpResp
String shortDesc = "PROXY: Bad Gateway";
String longDesc = "The server was acting as a gateway or proxy and received an invalid response from the upstream server.";
if (e instanceof UnknownHostException) {
status = HttpServletResponse.SC_NOT_FOUND;
shortDesc = "PROXY: Not Found";
status = HttpServletResponse.SC_BAD_REQUEST;
shortDesc = "PROXY: Unknown Host Exception";
longDesc = "The requested resource could not be found but may be available again in the future. Subsequent requests by the client are permissible.";
} else if (e instanceof ConnectException) {
status = HttpServletResponse.SC_SERVICE_UNAVAILABLE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,15 +445,7 @@ public void handleConnect(String pathInContext, String pathParams, HttpRequest r

try {
log.debug("CONNECT: {}", uri);
InetAddrPort addrPort;
// When logging, we'll attempt to send messages to hosts that don't exist
if (uri.toString().endsWith(".selenium.doesnotexist:443")) {
// so we have to do set the host to be localhost (you can't new up an IAP with a non-existent hostname)
addrPort = new InetAddrPort(443);
} else {
addrPort = new InetAddrPort(uri.toString());
}

InetAddrPort addrPort = new InetAddrPort(uri.toString());
if (isForbidden(HttpMessage.__SSL_SCHEME, addrPort.getHost(), addrPort.getPort(), false)) {
sendForbid(request, response, uri);
} else {
Expand Down Expand Up @@ -497,6 +489,9 @@ public void handleConnect(String pathInContext, String pathParams, HttpRequest r
}
request.setHandled(true);
}
} catch (UnknownHostException e) {
log.debug("error during handleConnect - UnknownHostException", e);
response.sendError(HttpResponse.__400_Bad_Request, e.toString());
} catch (Exception e) {
log.debug("error during handleConnect", e);
response.sendError(HttpResponse.__500_Internal_Server_Error, e.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ protected void tearDown() throws Exception {
}

@Test
public void testGoogleViaProxy() throws Exception {
HttpHost host = new HttpHost("www.google.com", 443, "https");
public void testAppleViaProxy() throws Exception {
HttpHost host = new HttpHost("www.apple.com", 443, "https");
HttpGet request = new HttpGet(GET_REQUEST);
try (CloseableHttpClient httpClient = getHttpClient()) {
HttpResponse response = httpClient.execute(host, request); //request is here
Expand Down Expand Up @@ -68,6 +68,36 @@ public void testGitHubViaProxy() throws Exception {
}
}

@Test
public void testNoDnsHttpViaProxyGET() throws Exception {
HttpHost host = new HttpHost("no.dns.record.here", 80, "http");
HttpGet request = new HttpGet(GET_REQUEST + "tkohegyi/mitmJavaProxy/master/LICENSE.txt");
try (CloseableHttpClient httpClient = getHttpClient()) {
HttpResponse response = httpClient.execute(host, request); //request is here
int statusCode = response.getStatusLine().getStatusCode();
String body = EntityUtils.toString(response.getEntity());
EntityUtils.consume(response.getEntity());
Assertions.assertEquals( 400, statusCode, "HTTP Response Status code is:" + statusCode);
logger.debug("Body length: {}, first few data:{}...", body.length(), body.substring(0,30));
Assertions.assertNull(getLastException());
}
}

@Test
public void testNoDnsHttpSViaProxyGET() throws Exception {
HttpHost host = new HttpHost("no.dns.record.here", 443, "https");
HttpGet request = new HttpGet(GET_REQUEST + "tkohegyi/mitmJavaProxy/master/LICENSE.txt");
try (CloseableHttpClient httpClient = getHttpClient()) {
HttpResponse response = httpClient.execute(host, request); //request is here
int statusCode = response.getStatusLine().getStatusCode();
String body = EntityUtils.toString(response.getEntity());
EntityUtils.consume(response.getEntity());
Assertions.assertEquals( 400, statusCode, "HTTP Response Status code is:" + statusCode);
logger.debug("Body length: {}, first few data:{}...", body.length(), body.substring(0,30));
Assertions.assertNull(getLastException());
}
}

class TestRequestInterceptor implements RequestInterceptor {

@Override
Expand Down

0 comments on commit 89f7761

Please sign in to comment.