net.lightbody.bmp.util.HttpUtil Java Examples

The following examples show how to use net.lightbody.bmp.util.HttpUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImpersonatingMitmManager.java    From CapturePacket with MIT License 5 votes vote down vote up
@Override
public SSLEngine clientSslEngineFor(HttpRequest httpRequest, SSLSession sslSession) {
    String requestedHostname = HttpUtil.getHostFromRequest(httpRequest);

    try {
        SslContext ctx = getHostnameImpersonatingSslContext(requestedHostname, sslSession);

        return ctx.newEngine(ByteBufAllocator.DEFAULT);
    } catch (RuntimeException e) {
        throw new MitmException("Error creating SSLEngine for connection to client to impersonate upstream host: " + requestedHostname, e);
    }
}
 
Example #2
Source File: HttpsAwareFiltersAdapter.java    From CapturePacket with MIT License 5 votes vote down vote up
/**
 * Returns the full, absolute URL of the specified request for both HTTP and HTTPS URLs. The request may reflect
 * modifications from this or other filters. This filter instance must be currently handling the specified request;
 * otherwise the results are undefined.
 *
 * @param modifiedRequest a possibly-modified version of the request currently being processed
 * @return the full URL of the request, including scheme, host, port, path, and query parameters
 */
public String getFullUrl(HttpRequest modifiedRequest) {
    // special case: for HTTPS requests, the full URL is scheme (https://) + the URI of this request
    if (ProxyUtils.isCONNECT(modifiedRequest)) {
        // CONNECT requests contain the default port, even if it isn't specified on the request.
        String hostNoDefaultPort = BrowserMobHttpUtil.removeMatchingPort(modifiedRequest.getUri(), 443);
        return "https://" + hostNoDefaultPort;
    }

    // To get the full URL, we need to retrieve the Scheme, Host + Port, Path, and Query Params from the request.
    // If the request URI starts with http:// or https://, it is already a full URL and can be returned directly.
    if (HttpUtil.startsWithHttpOrHttps(modifiedRequest.getUri())) {
        return modifiedRequest.getUri();
    }

    // The URI did not include the scheme and host, so examine the request to obtain them:
    // Scheme: the scheme (HTTP/HTTPS) are based on the type of connection, obtained from isHttps()
    // Host and Port: available for HTTP and HTTPS requests using the getHostAndPort() helper method.
    // Path + Query Params: since the request URI doesn't start with the scheme, we can safely assume that the URI
    //    contains only the path and query params.
    String hostAndPort = getHostAndPort(modifiedRequest);
    String path = modifiedRequest.getUri();
    String url;
    if (isHttps()) {
        url = "https://" + hostAndPort + path;
    } else {
        url = "http://" + hostAndPort + path;
    }
    return url;
}
 
Example #3
Source File: HttpsAwareFiltersAdapter.java    From CapturePacket with MIT License 5 votes vote down vote up
/**
 * Returns the hostname (but not the port) the specified request for both HTTP and HTTPS requests.  The request may reflect
 * modifications from this or other filters. This filter instance must be currently handling the specified request;
 * otherwise the results are undefined.
 *
 * @param modifiedRequest a possibly-modified version of the request currently being processed
 * @return hostname of the specified request, without the port
 */
public String getHost(HttpRequest modifiedRequest) {
    String serverHost;
    if (isHttps()) {
        HostAndPort hostAndPort = HostAndPort.fromString(getHttpsRequestHostAndPort());
        serverHost = hostAndPort.getHost();
    } else {
        serverHost = HttpUtil.getHostFromRequest(modifiedRequest);
    }
    return serverHost;
}
 
Example #4
Source File: HttpsAwareFiltersAdapter.java    From CapturePacket with MIT License 5 votes vote down vote up
/**
 * Returns the host and port of the specified request for both HTTP and HTTPS requests.  The request may reflect
 * modifications from this or other filters. This filter instance must be currently handling the specified request;
 * otherwise the results are undefined.
 *
 * @param modifiedRequest a possibly-modified version of the request currently being processed
 * @return host and port of the specified request
 */
public String getHostAndPort(HttpRequest modifiedRequest) {
    // For HTTP requests, the host and port can be read from the request itself using the URI and/or
    //   Host header. for HTTPS requests, the host and port are not available in the request. by using the
    //   getHttpsRequestHostAndPort() helper method, we can retrieve the host and port for HTTPS requests.
    if (isHttps()) {
        return getHttpsRequestHostAndPort();
    } else {
        return HttpUtil.getHostAndPortFromRequest(modifiedRequest);
    }
}
 
Example #5
Source File: ImpersonatingMitmManager.java    From Dream-Catcher with MIT License 5 votes vote down vote up
@Override
public SSLEngine clientSslEngineFor(HttpRequest httpRequest, SSLSession sslSession) {
    String requestedHostname = HttpUtil.getHostFromRequest(httpRequest);

    try {
        SslContext ctx = getHostnameImpersonatingSslContext(requestedHostname, sslSession);

        return ctx.newEngine(ByteBufAllocator.DEFAULT);
    } catch (RuntimeException e) {
        throw new MitmException("Error creating SSLEngine for connection to client to impersonate upstream host: " + requestedHostname, e);
    }
}
 
Example #6
Source File: HttpsAwareFiltersAdapter.java    From Dream-Catcher with MIT License 5 votes vote down vote up
/**
 * Returns the full, absolute URL of the specified request for both HTTP and HTTPS URLs. The request may reflect
 * modifications from this or other filters. This filter instance must be currently handling the specified request;
 * otherwise the results are undefined.
 *
 * @param modifiedRequest a possibly-modified version of the request currently being processed
 * @return the full URL of the request, including scheme, host, port, path, and query parameters
 */
public String getFullUrl(HttpRequest modifiedRequest) {
    // special case: for HTTPS requests, the full URL is scheme (https://) + the URI of this request
    if (ProxyUtils.isCONNECT(modifiedRequest)) {
        // CONNECT requests contain the default port, even if it isn't specified on the request.
        String hostNoDefaultPort = BrowserMobHttpUtil.removeMatchingPort(modifiedRequest.getUri(), 443);
        return "https://" + hostNoDefaultPort;
    }

    // To get the full URL, we need to retrieve the Scheme, Host + Port, Path, and Query Params from the request.
    // If the request URI starts with http:// or https://, it is already a full URL and can be returned directly.
    if (HttpUtil.startsWithHttpOrHttps(modifiedRequest.getUri())) {
        return modifiedRequest.getUri();
    }

    // The URI did not include the scheme and host, so examine the request to obtain them:
    // Scheme: the scheme (HTTP/HTTPS) are based on the type of connection, obtained from isHttps()
    // Host and Port: available for HTTP and HTTPS requests using the getHostAndPort() helper method.
    // Path + Query Params: since the request URI doesn't start with the scheme, we can safely assume that the URI
    //    contains only the path and query params.
    String hostAndPort = getHostAndPort(modifiedRequest);
    String path = modifiedRequest.getUri();
    String url;
    if (isHttps()) {
        url = "https://" + hostAndPort + path;
    } else {
        url = "http://" + hostAndPort + path;
    }
    return url;
}
 
Example #7
Source File: HttpsAwareFiltersAdapter.java    From Dream-Catcher with MIT License 5 votes vote down vote up
/**
 * Returns the hostname (but not the port) the specified request for both HTTP and HTTPS requests.  The request may reflect
 * modifications from this or other filters. This filter instance must be currently handling the specified request;
 * otherwise the results are undefined.
 *
 * @param modifiedRequest a possibly-modified version of the request currently being processed
 * @return hostname of the specified request, without the port
 */
public String getHost(HttpRequest modifiedRequest) {
    String serverHost;
    if (isHttps()) {
        HostAndPort hostAndPort = HostAndPort.fromString(getHttpsRequestHostAndPort());
        serverHost = hostAndPort.getHostText();
    } else {
        serverHost = HttpUtil.getHostFromRequest(modifiedRequest);
    }
    return serverHost;
}
 
Example #8
Source File: HttpsAwareFiltersAdapter.java    From Dream-Catcher with MIT License 5 votes vote down vote up
/**
 * Returns the host and port of the specified request for both HTTP and HTTPS requests.  The request may reflect
 * modifications from this or other filters. This filter instance must be currently handling the specified request;
 * otherwise the results are undefined.
 *
 * @param modifiedRequest a possibly-modified version of the request currently being processed
 * @return host and port of the specified request
 */
public String getHostAndPort(HttpRequest modifiedRequest) {
    // For HTTP requests, the host and port can be read from the request itself using the URI and/or
    //   Host header. for HTTPS requests, the host and port are not available in the request. by using the
    //   getHttpsRequestHostAndPort() helper method, we can retrieve the host and port for HTTPS requests.
    if (isHttps()) {
        return getHttpsRequestHostAndPort();
    } else {
        return HttpUtil.getHostAndPortFromRequest(modifiedRequest);
    }
}
 
Example #9
Source File: ImpersonatingMitmManager.java    From AndroidHttpCapture with MIT License 5 votes vote down vote up
@Override
public SSLEngine clientSslEngineFor(HttpRequest httpRequest, SSLSession sslSession) {
    String requestedHostname = HttpUtil.getHostFromRequest(httpRequest);

    try {
        SslContext ctx = getHostnameImpersonatingSslContext(requestedHostname, sslSession);

        return ctx.newEngine(ByteBufAllocator.DEFAULT);
    } catch (RuntimeException e) {
        throw new MitmException("Error creating SSLEngine for connection to client to impersonate upstream host: " + requestedHostname, e);
    }
}
 
Example #10
Source File: HttpsAwareFiltersAdapter.java    From AndroidHttpCapture with MIT License 5 votes vote down vote up
/**
 * Returns the full, absolute URL of the specified request for both HTTP and HTTPS URLs. The request may reflect
 * modifications from this or other filters. This filter instance must be currently handling the specified request;
 * otherwise the results are undefined.
 *
 * @param modifiedRequest a possibly-modified version of the request currently being processed
 * @return the full URL of the request, including scheme, host, port, path, and query parameters
 */
public String getFullUrl(HttpRequest modifiedRequest) {
    // special case: for HTTPS requests, the full URL is scheme (https://) + the URI of this request
    if (ProxyUtils.isCONNECT(modifiedRequest)) {
        // CONNECT requests contain the default port, even if it isn't specified on the request.
        String hostNoDefaultPort = BrowserMobHttpUtil.removeMatchingPort(modifiedRequest.getUri(), 443);
        return "https://" + hostNoDefaultPort;
    }

    // To get the full URL, we need to retrieve the Scheme, Host + Port, Path, and Query Params from the request.
    // If the request URI starts with http:// or https://, it is already a full URL and can be returned directly.
    if (HttpUtil.startsWithHttpOrHttps(modifiedRequest.getUri())) {
        return modifiedRequest.getUri();
    }

    // The URI did not include the scheme and host, so examine the request to obtain them:
    // Scheme: the scheme (HTTP/HTTPS) are based on the type of connection, obtained from isHttps()
    // Host and Port: available for HTTP and HTTPS requests using the getHostAndPort() helper method.
    // Path + Query Params: since the request URI doesn't start with the scheme, we can safely assume that the URI
    //    contains only the path and query params.
    String hostAndPort = getHostAndPort(modifiedRequest);
    String path = modifiedRequest.getUri();
    String url;
    if (isHttps()) {
        url = "https://" + hostAndPort + path;
    } else {
        url = "http://" + hostAndPort + path;
    }
    return url;
}
 
Example #11
Source File: HttpsAwareFiltersAdapter.java    From AndroidHttpCapture with MIT License 5 votes vote down vote up
/**
 * Returns the hostname (but not the port) the specified request for both HTTP and HTTPS requests.  The request may reflect
 * modifications from this or other filters. This filter instance must be currently handling the specified request;
 * otherwise the results are undefined.
 *
 * @param modifiedRequest a possibly-modified version of the request currently being processed
 * @return hostname of the specified request, without the port
 */
public String getHost(HttpRequest modifiedRequest) {
    String serverHost;
    if (isHttps()) {
        HostAndPort hostAndPort = HostAndPort.fromString(getHttpsRequestHostAndPort());
        serverHost = hostAndPort.getHost();
    } else {
        serverHost = HttpUtil.getHostFromRequest(modifiedRequest);
    }
    return serverHost;
}
 
Example #12
Source File: HttpsAwareFiltersAdapter.java    From AndroidHttpCapture with MIT License 5 votes vote down vote up
/**
 * Returns the host and port of the specified request for both HTTP and HTTPS requests.  The request may reflect
 * modifications from this or other filters. This filter instance must be currently handling the specified request;
 * otherwise the results are undefined.
 *
 * @param modifiedRequest a possibly-modified version of the request currently being processed
 * @return host and port of the specified request
 */
public String getHostAndPort(HttpRequest modifiedRequest) {
    // For HTTP requests, the host and port can be read from the request itself using the URI and/or
    //   Host header. for HTTPS requests, the host and port are not available in the request. by using the
    //   getHttpsRequestHostAndPort() helper method, we can retrieve the host and port for HTTPS requests.
    if (isHttps()) {
        return getHttpsRequestHostAndPort();
    } else {
        return HttpUtil.getHostAndPortFromRequest(modifiedRequest);
    }
}