Documentation
¶
Overview ¶
Package martian provides an HTTP/1.1 proxy with an API for configurable request and response modifiers.
Index ¶
- Variables
- func Debugf(format string, args ...interface{})
- func Errorf(format string, args ...interface{})
- func Infof(format string, args ...interface{})
- func NewTemplate(org, host string, start, end time.Time, pub interface{}) (*x509.Certificate, error)
- type Auth
- type Context
- type MITM
- type Proxy
- func (p *Proxy) ModifyRequest(ctx *Context, req *http.Request) error
- func (p *Proxy) ModifyResponse(ctx *Context, res *http.Response) error
- func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (p *Proxy) SetConnectRequestModifier(creqmod RequestModifier)
- func (p *Proxy) SetConnectResponseModifier(cresmod ResponseModifier)
- func (p *Proxy) SetRequestModifier(reqmod RequestModifier)
- func (p *Proxy) SetResponseModifier(resmod ResponseModifier)
- type RequestModifier
- type RequestModifierFunc
- type RequestResponseModifier
- type ResponseModifier
- type ResponseModifierFunc
- type RoundTripFunc
Constants ¶
This section is empty.
Variables ¶
var ErrAuthRequired = errors.New("authentication is required")
ErrAuthRequired is the error returned by modifiers when ctx.Auth.ID is required, but empty.
MaxSerialNumber is the upper boundary that is used to create unique serial numbers for the certificate. This can be any unsigned integer up to 20 bytes (2^(8*20)-1).
Functions ¶
func Debugf ¶
func Debugf(format string, args ...interface{})
Debugf logs a debug message with caller information.
func Errorf ¶
func Errorf(format string, args ...interface{})
Errorf logs an error message with caller information.
func Infof ¶
func Infof(format string, args ...interface{})
Infof logs an info message with caller information.
func NewTemplate ¶
func NewTemplate(org, host string, start, end time.Time, pub interface{}) (*x509.Certificate, error)
NewTemplate returns a new base *x509.Certificate.
Types ¶
type Auth ¶
type Auth struct { // ID is the identifier for a user. ID string // Error is used to signal that ID is required, but is either // blank or invalid per the semantics of the modifier. Error error }
Auth contains per session authentication information.
type Context ¶
type Context struct { // Auth is the session authentication information. Auth *Auth // SkipRoundTrip signals to the proxy that it should not send the request over the wire. SkipRoundTrip bool }
Context contains information for a proxy session.
type MITM ¶
type MITM struct { // Authority is the CA certificate used to sign MITM certificates. Authority *x509.Certificate // PublicKey used to create MITM certificates. PublicKey interface{} // PrivateKey of the CA used to sign MITM certificates. PrivateKey interface{} // Validity is the window of time around time.Now() that the // certificate will be valid. Validity time.Duration // Organization that is displayed as the owner of the // certificate. Organization string }
MITM is the configuration for using the Proxy as a MITM.
type Proxy ¶
type Proxy struct { // RoundTripper used to make the request from the proxy to the target server. RoundTripper http.RoundTripper // Timeout is the length of time the connection will be kept open while idle. Timeout time.Duration // contains filtered or unexported fields }
Proxy implements an HTTP proxy with CONNECT and TLS MITM support.
func (*Proxy) ModifyRequest ¶
ModifyRequest modifies the request.
func (*Proxy) ModifyResponse ¶
ModifyResponse modifies the response.
func (*Proxy) ServeHTTP ¶
func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handles requests from a connection and writes responses.
If a MITM config was provided and a CONNECT request is received, the proxy will generate a fake TLS certificate using the given authority certificate and perform the TLS handshake. The request will then be decrypted and modifiers will be run, followed by the request being re-encrypted and sent to the destination server.
If no MITM config was provided and a CONNECT request is received, the proxy will open a connection to the destination server and copy the encrypted bytes directly, as per normal CONNECT semantics.
func (*Proxy) SetConnectRequestModifier ¶
func (p *Proxy) SetConnectRequestModifier(creqmod RequestModifier)
SetConnectRequestModifier sets the request modifier for the CONNECT request.
func (*Proxy) SetConnectResponseModifier ¶
func (p *Proxy) SetConnectResponseModifier(cresmod ResponseModifier)
SetConnectResponseModifier sets the response modifier for the CONNECT response.
func (*Proxy) SetRequestModifier ¶
func (p *Proxy) SetRequestModifier(reqmod RequestModifier)
SetRequestModifier sets the request modifier for the decrypted request.
func (*Proxy) SetResponseModifier ¶
func (p *Proxy) SetResponseModifier(resmod ResponseModifier)
SetResponseModifier sets the response modifier for the decrypted response.
type RequestModifier ¶
type RequestModifier interface { // ModifyRequest modifies the request. // // Modifying the request body is possible, though the req.Body must be // replaced with a new io.ReadCloser since rewinding the body is // unsupported. ModifyRequest(ctx *Context, req *http.Request) error }
RequestModifier is an interface that defines a request modifier that can be used by a proxy.
type RequestModifierFunc ¶
RequestModifierFunc is an adapter for using a function with the given signature as a RequestModifier.
func (RequestModifierFunc) ModifyRequest ¶
func (f RequestModifierFunc) ModifyRequest(ctx *Context, req *http.Request) error
ModifyRequest modifies the request using the given function.
type RequestResponseModifier ¶
type RequestResponseModifier interface { RequestModifier ResponseModifier }
RequestResponseModifier is an interface that is both a ResponseModifier and a RequestModifier.
type ResponseModifier ¶
type ResponseModifier interface { // ModifyResponse modifies the response. // // Modifying the response body is possible, though the res.Body must be // replaced with a new io.ReadCloser since rewinding the body is // unsupported. ModifyResponse(ctx *Context, res *http.Response) error }
ResponseModifier is an interface that defines a response modifier that can be used by a proxy.
type ResponseModifierFunc ¶
ResponseModifierFunc is an adapter for using a function with the given signature as a ResponseModifier.
func (ResponseModifierFunc) ModifyResponse ¶
func (f ResponseModifierFunc) ModifyResponse(ctx *Context, res *http.Response) error
ModifyResponse modifies the response using the given function.
type RoundTripFunc ¶
RoundTripFunc is an adapter for using a function with the given signature as an http.RoundTripper.
Directories
¶
Path | Synopsis |
---|---|
Package auth provides filtering support for a martian.Proxy based on ctx.Auth.ID.
|
Package auth provides filtering support for a martian.Proxy based on ctx.Auth.ID. |
Package body allows for the replacement of message body on responses.
|
Package body allows for the replacement of message body on responses. |
Package cookie allows for the modification of cookies on http requests and responses.
|
Package cookie allows for the modification of cookies on http requests and responses. |
Package cors provides CORS support for http.Handlers.
|
Package cors provides CORS support for http.Handlers. |
proxy is a martian.Proxy configurable via HTTP.
|
proxy is a martian.Proxy configurable via HTTP. |
Package header provides utilities for modifying, filtering, and verifying headers in martian.Proxy.
|
Package header provides utilities for modifying, filtering, and verifying headers in martian.Proxy. |
Package ipauth provides a martian.Modifier that sets auth based on IP.
|
Package ipauth provides a martian.Modifier that sets auth based on IP. |
Package martianhttp provides HTTP handlers for managing the state of a martian.Proxy.
|
Package martianhttp provides HTTP handlers for managing the state of a martian.Proxy. |
Package martianurl provides utilities for modifying, filtering, and verifying URLs in martian.Proxy.
|
Package martianurl provides utilities for modifying, filtering, and verifying URLs in martian.Proxy. |
Package method provides utilities for verifying method type in martian.Proxy.
|
Package method provides utilities for verifying method type in martian.Proxy. |
Package parse constructs martian modifiers from JSON messages.
|
Package parse constructs martian modifiers from JSON messages. |
Package pingback provides verification that specific URLs have been seen by the proxy.
|
Package pingback provides verification that specific URLs have been seen by the proxy. |
Package priority allows grouping modifiers and applying them in priority order.
|
Package priority allows grouping modifiers and applying them in priority order. |
Package proxyauth provides authentication support via the Proxy-Authorization header.
|
Package proxyauth provides authentication support via the Proxy-Authorization header. |
Package proxyutil provides functionality for building proxies.
|
Package proxyutil provides functionality for building proxies. |
Package querystring contains a modifier to rewrite query strings in a request.
|
Package querystring contains a modifier to rewrite query strings in a request. |
Package status contains a modifier to rewrite the status code on a response.
|
Package status contains a modifier to rewrite the status code on a response. |
Package verify provides support for using martian modifiers for request and response verifications.
|
Package verify provides support for using martian modifiers for request and response verifications. |