Class ApiCaptureProxyServer

java.lang.Object
com.shaft.capture.proxy.ApiCaptureProxyServer
All Implemented Interfaces:
AutoCloseable

public final class ApiCaptureProxyServer extends Object implements AutoCloseable
Embedded, loopback-only MITM HTTP(S) proxy for recording native mobile API traffic. Every request/response pair that passes through is delivered to sink as a raw ProxyTransaction; safe, non-sensitive operational issues (a transaction that could not be captured, a host with a pinned/unimpersonable certificate) are delivered to warn.

Binds to 127.0.0.1 only -- this proxy is meant to be reached either directly (an emulator on the same machine) or via adb reverse/port-forwarding from a device, never by exposing it on a LAN-routable address.

  • Constructor Details

    • ApiCaptureProxyServer

      public ApiCaptureProxyServer(CaptureCertificateAuthority certificateAuthority, int requestedPort, Consumer<ProxyTransaction> sink, Consumer<String> warn)
      Starts the proxy on a loopback port.
      Parameters:
      certificateAuthority - CA used to impersonate HTTPS hosts
      requestedPort - port to bind, or 0 to let the OS choose a free port
      sink - destination for each captured transaction
      warn - destination for safe operational warnings
  • Method Details

    • pinnedHosts

      public Set<String> pinnedHosts()
      Known-pinned hostnames tunneled without MITM interception (Tier-3, see CapturingHttpFilters) rather than having capture attempted and failing. Returns an immutable snapshot -- use addPinnedHost(String)/removePinnedHost(String) to mutate the underlying set rather than exposing it directly.
      Returns:
      immutable snapshot of currently pinned hostnames
    • addPinnedHost

      public void addPinnedHost(String host)
      Adds a hostname to the pinned set so its traffic is tunneled without MITM interception.
      Parameters:
      host - hostname, without port
    • removePinnedHost

      public void removePinnedHost(String host)
      Removes a hostname from the pinned set, resuming MITM interception for it.
      Parameters:
      host - hostname, without port
    • port

      public int port()
      Returns the loopback port this proxy is actually listening on (resolved even when requestedPort was 0).
      Returns:
      bound port
    • stop

      public void stop()
      Stops the proxy, closing all active connections.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable