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 ¶
- func Fingerprint(c *x509.Certificate) string
- func SubjectHashOld(c *x509.Certificate) string
- type ActivateOpts
- type BreakpointResume
- type CA
- type Exchange
- type InstallTarget
- type Interceptor
- type PausedExchange
- type Proxy
- func (p *Proxy) Abort(id int64)
- func (p *Proxy) AddRule(r Rule) Rule
- func (p *Proxy) CA() *CA
- func (p *Proxy) CACertPEM() []byte
- func (p *Proxy) Clear()
- func (p *Proxy) DeleteRule(id int64)
- func (p *Proxy) Exchanges() []*Exchange
- func (p *Proxy) ListPaused() []*PausedExchange
- func (p *Proxy) Resume(id int64, edit BreakpointResume)
- func (p *Proxy) Rules() []Rule
- func (p *Proxy) SPKIFingerprint() string
- func (p *Proxy) Start(addr string) error
- func (p *Proxy) Status() (bool, string)
- func (p *Proxy) Stop()
- func (p *Proxy) SubscribeBreakpoints() (<-chan struct{}, func())
- type Registry
- type Rule
- type Session
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 ¶
LoadOrCreateCA loads the CA from dir, creating and persisting it on first use.
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 ¶
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 (*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) SPKIFingerprint ¶
SPKIFingerprint is the CA's SubjectPublicKeyInfo fingerprint, for launching Chromium-family browsers that trust the proxy without a cert install.
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 (*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 ¶
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) StopSession ¶
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.