proxy

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2022 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

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.

func RequestIDFromContext added in v0.7.0

func RequestIDFromContext(ctx context.Context) (ulid.ULID, bool)

func WithRequestID added in v0.7.0

func WithRequestID(ctx context.Context, id ulid.ULID) context.Context

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 Config added in v0.6.0

type Config struct {
	CACert *x509.Certificate
	CAKey  crypto.PrivateKey
	Logger log.Logger
}

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(cfg Config) (*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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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