proxy

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2022 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const ReqLogIDKey contextKey = 0

Variables

View Source
var ErrAlreadyAccepted = errors.New("listener already accepted")
View Source
var MaxSerialNumber = big.NewInt(0).SetBytes(bytes.Repeat([]byte{255}, 20))

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 LoadOrCreateCA

func LoadOrCreateCA(caKeyFile, caCertFile string) (*x509.Certificate, *rsa.PrivateKey, error)

LoadOrCreateCA loads an existing CA key pair from disk, or creates a new keypair and saves to disk if certificate or key files don't exist.

func NewCA

func NewCA(name, organization string, validity time.Duration) (*x509.Certificate, *rsa.PrivateKey, error)

NewCA creates a new CA certificate and associated private key.

Types

type CertConfig

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

CertConfig is a set of configuration values that are used to build TLS configs capable of MITM.

func NewCertConfig

func NewCertConfig(ca *x509.Certificate, caPrivKey crypto.PrivateKey) (*CertConfig, error)

NewCertConfig creates a MITM config using the CA certificate and private key to generate on-the-fly certificates.

func (*CertConfig) TLSConfig

func (c *CertConfig) TLSConfig() *tls.Config

TLSConfig returns a *tls.Config that will generate certificates on-the-fly using the SNI extension in the TLS ClientHello.

type ConnNotify

type ConnNotify struct {
	net.Conn
	// contains filtered or unexported fields
}

ConnNotify embeds net.Conn and adds a channel field for notifying that the connection was closed.

func (*ConnNotify) Close

func (c *ConnNotify) Close()

type OnceAcceptListener

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

OnceListener implements net.Listener.

Accepts a connection once and returns an error on subsequent attempts.

func (*OnceAcceptListener) Accept

func (l *OnceAcceptListener) Accept() (net.Conn, error)

func (*OnceAcceptListener) Addr

func (l *OnceAcceptListener) Addr() net.Addr

func (*OnceAcceptListener) Close

func (l *OnceAcceptListener) Close() error

type Proxy

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

Proxy implements http.Handler and offers MITM behaviour for modifying HTTP requests and responses.

func NewProxy

func NewProxy(ca *x509.Certificate, key crypto.PrivateKey) (*Proxy, error)

NewProxy returns a new Proxy.

func (*Proxy) ServeHTTP

func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Proxy) UseRequestModifier

func (p *Proxy) UseRequestModifier(fn ...RequestModifyMiddleware)

func (*Proxy) UseResponseModifier

func (p *Proxy) UseResponseModifier(fn ...ResponseModifyMiddleware)

type RequestModifyFunc

type RequestModifyFunc func(req *http.Request)

RequestModifyFunc defines a type for a function that can modify a HTTP request before it's proxied.

type RequestModifyMiddleware

type RequestModifyMiddleware func(next RequestModifyFunc) RequestModifyFunc

RequestModifyMiddleware defines a type for chaining request modifier middleware.

type ResponseModifyFunc

type ResponseModifyFunc func(res *http.Response) error

ResponseModifyFunc defines a type for a function that can modify a HTTP response before it's written back to the client.

type ResponseModifyMiddleware

type ResponseModifyMiddleware func(ResponseModifyFunc) ResponseModifyFunc

ResponseModifyMiddleware defines a type for chaining response modifier middleware.

Jump to

Keyboard shortcuts

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