Class BrowserProfile

java.lang.Object
org.microproxy.tls.BrowserProfile

public final class BrowserProfile extends Object
What one browser looks like to a server, as one thing to give the proxy: its TLS ClientHello, its HTTP/2 connection preface and request framing, its QUIC and HTTP/3 connections (Http3Options.Builder.upstreamProfile), and its request headers.

 BrowserProfile chrome = BrowserProfile.chrome156();
 HttpProxyServer proxy = MicroProxy.bootstrap()
         .withManInTheMiddle(new CertificateAuthorityMitmManager(ca, chrome.sslContext(null)))
         .withFiltersSource(chrome.filtersSource(true))
         .start();
 

The context's sockets carry the HTTP/2 profile (FingerprintSslContext.Builder.attach(java.lang.Object)), so HTTP/2 connections over them open as the browser's do without Http2Options.Builder.upstreamProfile; different servers can get different browsers by returning different contexts from a MitmManager.

  • Method Details

    • chrome156

      public static BrowserProfile chrome156()
      Chrome 156 on macOS, as captured from 156.0.8078.48: BrowserProfiles.chrome156(), Http2ClientProfile.chrome156(), and the headers of a navigation, in Chrome's order. The capture was of headless Chrome, whose User-Agent says HeadlessChrome; the profile's says Chrome, as a browser window's does.
      Returns:
      the profile
    • firefox159

      public static BrowserProfile firefox159()
      Firefox 159 on macOS, as captured from 159.0: BrowserProfiles.firefox159(), Http2ClientProfile.firefox159(), its QUIC and HTTP/3 connections (QuicClientProfile.firefox159(), Http3ClientProfile.firefox159()), and the headers of a navigation, in Firefox's order.
      Returns:
      the profile
    • name

      public String name()
      Returns the profile's name, such as chrome-156.
      Returns:
      the profile's name, such as chrome-156
    • tlsProfile

      public ClientHelloProfile tlsProfile()
      Returns the TLS ClientHello profile.
      Returns:
      the TLS ClientHello profile
    • http2Profile

      public Http2ClientProfile http2Profile()
      Returns the HTTP/2 profile.
      Returns:
      the HTTP/2 profile
    • quicProfile

      public QuicClientProfile quicProfile()
      Returns the QUIC client profile: its QUIC hello, transport parameters and Initial packets; null if it has none.
      Returns:
      the QUIC client profile: its QUIC hello, transport parameters and Initial packets; null if it has none
    • http3Profile

      public Http3ClientProfile http3Profile()
      Returns the HTTP/3 profile, or null if it has none.
      Returns:
      the HTTP/3 profile, or null if it has none
    • requestHeaders

      public List<Map.Entry<String,String>> requestHeaders()
      Returns the browser's request headers, in its order.
      Returns:
      the browser's request headers, in its order
    • sslContext

      public SSLContext sslContext(X509TrustManager trustManager)
      A client context with the browser's TLS fingerprint, whose sockets carry its HTTP/2 profile, that decompresses certificates with Brotli, zlib and (when the zstd-decoder module is on the class path) zstd.
      Parameters:
      trustManager - the servers to trust, or null for the JDK's default trust store
      Returns:
      the context
    • sslContext

      public SSLContext sslContext(X509TrustManager trustManager, EchConfigProvider ech)
      sslContext(X509TrustManager), encrypting the ClientHello (RFC 9849) to servers whose ECHConfigList ech gives; to the others, and with ech null, the browser's GREASE ECH alone, as a browser sends when it has no ECHConfig. No DNS lookups are made here: ech decides where configs come from (such as the server's DNS HTTPS record, from the resolver the deployment trusts).
      Parameters:
      trustManager - the servers to trust, or null for the JDK's default trust store
      ech - the source of servers' ECHConfigLists, or null for none
      Returns:
      the context
    • certificateDecompressor

      public static CertificateDecompressor certificateDecompressor()
      Decompresses certificate chains (RFC 8879) with Brotli, zlib and, when the zstd-decoder module is on the class path, zstd; each bounded to 1 MiB of output.
      Returns:
      the decompressor
    • applyHeaders

      public void applyHeaders(HttpHeaders headers, boolean replaceUserAgent)
      Gives a request the browser's headers, in the browser's order:
      • the browser's user-agent in place of the client's when replaceUserAgent is set, or when the client sent none;
      • the browser's headers the client did not send, except accept-encoding, since a client that did not ask for an encoding could not read a body in it;
      • no via, which says a proxy is there.
      The headers the browser sends come first, in its order; the client's others follow in theirs.
      Parameters:
      headers - the request's headers, changed in place
      replaceUserAgent - whether the browser's User-Agent replaces the client's
    • filtersSource

      public HttpFiltersSource filtersSource(boolean replaceUserAgent)
      Filters that apply the browser's headers to every request on its way to the server.
      Parameters:
      replaceUserAgent - whether the browser's User-Agent replaces the client's
      Returns:
      the filters' source
    • toString

      public String toString()
      Overrides:
      toString in class Object