intercept

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 29 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package intercept implements a native man-in-the-middle HTTP(S) proxy: it generates its own certificate authority, signs per-host leaf certificates on the fly, and records the request/response exchanges that flow through it — so antares can inspect, and (via rules) mock or rewrite, a target's traffic. For authorized debugging and testing of properties you control.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fingerprint

func Fingerprint(c *x509.Certificate) string

Fingerprint returns the hex SHA-1 of the whole CA cert — the value trust stores and dialogs show so an operator can confirm they trusted the right one.

func SubjectHashOld

func SubjectHashOld(c *x509.Certificate) string

SubjectHashOld returns the OpenSSL "subject_hash_old" (8 hex chars) of the CA subject — the filename Android and some Linux/NSS flows expect for a trusted root (e.g. "<hash>.0"). It is the first 4 bytes of MD5(RawSubject), read little-endian. RawSubject is used directly to match OpenSSL's canonical form.

Types

type ActivateOpts

type ActivateOpts struct {
	ProxyAddr       string         // host:port the proxy listens on
	CACertPath      string         // on-disk CA PEM path
	SPKIFingerprint string         // base64 SPKI hash for Chromium CT-bypass
	Extra           map[string]any // interceptor-specific (url, container id, …)
}

ActivateOpts carries everything an interceptor needs to hook a client to the running proxy. The tool layer fills these from the shared Proxy + CA.

type BreakpointResume

type BreakpointResume struct {
	Method  string            `json:"method"`
	URL     string            `json:"url"`
	Headers map[string]string `json:"headers"`
	Body    string            `json:"body"`
}

BreakpointResume carries operator edits to release a paused request.

type CA

type CA struct {
	// contains filtered or unexported fields
}

CA is the proxy's certificate authority: a long-lived root that signs the short-lived leaf certificates presented for each intercepted host.

func LoadOrCreateCA

func LoadOrCreateCA(dir string) (*CA, error)

LoadOrCreateCA loads the CA from dir, creating and persisting it on first use.

func (*CA) Cert

func (c *CA) Cert() *x509.Certificate

Cert returns the parsed CA certificate.

func (*CA) CertDER

func (c *CA) CertDER() []byte

CertDER returns the raw DER bytes of the CA certificate.

func (*CA) CertPEM

func (c *CA) CertPEM() []byte

CertPEM returns the CA certificate in PEM form, for the user to trust.

func (*CA) LeafFor

func (c *CA) LeafFor(host string) (*tls.Certificate, error)

LeafFor returns (and caches) a leaf certificate for host, signed by the CA.

func (*CA) SPKIFingerprint

func (c *CA) SPKIFingerprint() string

SPKIFingerprint returns base64(SHA-256(SubjectPublicKeyInfo)) of the CA cert. This is the fingerprint Chromium-family browsers accept via --ignore-certificate-errors-spki-list, which makes them trust every leaf the proxy signs WITHOUT installing anything into a trust store — the key trick that lets a launched browser be intercepted with zero cert setup.

type Exchange

type Exchange struct {
	ID          int64       `json:"id"`
	Time        time.Time   `json:"time"`
	Method      string      `json:"method"`
	URL         string      `json:"url"`
	Host        string      `json:"host"`
	Secure      bool        `json:"secure"`
	ReqHeaders  http.Header `json:"req_headers"`
	ReqBody     string      `json:"req_body"`
	Status      int         `json:"status"`
	RespHeaders http.Header `json:"resp_headers"`
	RespBody    string      `json:"resp_body"`
	DurationMS  int64       `json:"duration_ms"`
	Mocked      bool        `json:"mocked"`
	Blocked     bool        `json:"blocked"`
}

Exchange is one captured request/response pair.

type InstallTarget

type InstallTarget struct {
	Label     string `json:"label"`
	Command   string `json:"command"`
	Tool      string `json:"tool"`
	Available bool   `json:"available"`
	Note      string `json:"note,omitempty"`
}

InstallTarget is one way to trust the CA on this machine: a human label, the exact shell command, and whether the tool it needs is actually present.

func InstallLocations

func InstallLocations(certPath string, subjectHash string) []InstallTarget

InstallLocations returns the trust-install options for the current OS, each flagged with whether its tool is on PATH so the UI can show a ready command or an "install this first" hint. certPath is the on-disk CA PEM.

type Interceptor

type Interceptor interface {
	// ID is the stable identifier, e.g. "fresh-chrome", "terminal", "android".
	ID() string
	// Label is a short human name for the picker.
	Label() string
	// Category groups interceptors in the UI: browser, terminal, mobile, etc.
	Category() string
	// Available reports whether this interceptor can run here right now. It
	// never errors hard: ok=false with a reason (a copy-pasteable install hint)
	// is the normal "dependency missing" path.
	Available(ctx context.Context) (ok bool, reason string)
	// Activate starts interception and returns a Session to stop it.
	Activate(ctx context.Context, opts ActivateOpts) (Session, error)
}

An Interceptor is a way to route some client (a browser, a terminal, an Android device, a container…) through the proxy and make it trust the CA. This unifies HTTP Toolkit's per-interceptor patterns into one contract so the tool/API/dashboard drive them all the same way, and so anything that needs an external tool (adb, certutil, java, docker) degrades to a clear "install X" message via Available() instead of failing hard.

func Browsers

func Browsers() []Interceptor

Browsers returns an interceptor per known Chromium-family variant.

func OtherInterceptors

func OtherInterceptors() []Interceptor

OtherInterceptors returns the non-Chromium interceptors: the terminal env-override (works everywhere), and dependency-gated ones (firefox, electron, android, docker, jvm) that report a clear "install X" reason via Available() until their runtime is present. This is the "ship gated stubs first" path from docs/intercept-port.md — the real per-runtime work lands behind these.

type PausedExchange

type PausedExchange struct {
	ID      int64             `json:"id"`
	Method  string            `json:"method"`
	URL     string            `json:"url"`
	Headers map[string]string `json:"headers"`
	Body    string            `json:"body"`
	// contains filtered or unexported fields
}

PausedExchange is a request held at a breakpoint, waiting for the operator to resume (optionally with edits) or abort it. It carries a resolve channel the waiting proxy goroutine blocks on.

type Proxy

type Proxy struct {
	// contains filtered or unexported fields
}

Proxy is a MITM HTTP(S) proxy that captures every exchange.

func New

func New(ca *CA) *Proxy

New builds a proxy backed by the given CA.

func (*Proxy) Abort

func (p *Proxy) Abort(id int64)

Abort releases a paused request by refusing it (the client gets a 4xx).

func (*Proxy) AddRule

func (p *Proxy) AddRule(r Rule) Rule

AddRule registers a rule and returns it with an assigned id.

func (*Proxy) CA

func (p *Proxy) CA() *CA

CA returns the proxy's certificate authority.

func (*Proxy) CACertPEM

func (p *Proxy) CACertPEM() []byte

CACertPEM exposes the CA cert for the user to trust.

func (*Proxy) Clear

func (p *Proxy) Clear()

Clear empties the capture log.

func (*Proxy) DeleteRule

func (p *Proxy) DeleteRule(id int64)

DeleteRule removes a rule by id.

func (*Proxy) Exchanges

func (p *Proxy) Exchanges() []*Exchange

Exchanges returns a snapshot of the captured log (newest first).

func (*Proxy) ListPaused

func (p *Proxy) ListPaused() []*PausedExchange

ListPaused returns the requests currently held at breakpoints.

func (*Proxy) Resume

func (p *Proxy) Resume(id int64, edit BreakpointResume)

Resume releases a paused request with the operator's edits and lets the proxy forward it. Unknown ids are a no-op.

func (*Proxy) Rules

func (p *Proxy) Rules() []Rule

Rules returns the active rules.

func (*Proxy) SPKIFingerprint

func (p *Proxy) SPKIFingerprint() string

SPKIFingerprint is the CA's SubjectPublicKeyInfo fingerprint, for launching Chromium-family browsers that trust the proxy without a cert install.

func (*Proxy) Start

func (p *Proxy) Start(addr string) error

Start begins listening on addr (e.g. "127.0.0.1:8899").

func (*Proxy) Status

func (p *Proxy) Status() (bool, string)

Status reports whether the proxy is running and where.

func (*Proxy) Stop

func (p *Proxy) Stop()

Stop shuts the proxy down.

func (*Proxy) SubscribeBreakpoints

func (p *Proxy) SubscribeBreakpoints() (<-chan struct{}, func())

SubscribeBreakpoints returns a channel that fires whenever a request is paused or resolved, so the dashboard can refresh without polling.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry holds the process's interceptors, keyed by id.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns an empty registry.

func (*Registry) Get

func (r *Registry) Get(id string) (Interceptor, bool)

Get looks up an interceptor by id.

func (*Registry) List

func (r *Registry) List() []Interceptor

List returns every interceptor, sorted by category then id.

func (*Registry) PutSession

func (r *Registry) PutSession(s Session)

PutSession records a live session so it can be listed and stopped later.

func (*Registry) Register

func (r *Registry) Register(i Interceptor)

Register adds an interceptor.

func (*Registry) Sessions

func (r *Registry) Sessions() []Session

Sessions returns the live sessions.

func (*Registry) StopSession

func (r *Registry) StopSession(id string) error

StopSession stops and forgets one session.

type Rule

type Rule struct {
	ID         int64  `json:"id"`
	Match      string `json:"match"` // substring of the URL
	Block      bool   `json:"block"`
	MockStatus int    `json:"mock_status"`
	MockBody   string `json:"mock_body"`
	// Breakpoint pauses a matching request before it is forwarded, so the
	// operator can edit it (or the response) and then resume or abort it.
	Breakpoint bool `json:"breakpoint"`
}

Rule matches a request by URL substring and either blocks it, returns a mock response, or pauses it at a breakpoint for the operator to edit — letting them shape a target's traffic during testing.

type Session

type Session interface {
	ID() string
	Interceptor() string
	Info() map[string]any
	Stop() error
}

Session is a live interception a caller can inspect and stop.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL