proxy

package
v0.0.0-...-ef6b61c Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2022 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const ForwardRuleExample = `forwardRules:
- name: example
  matchPath: example.com/app
  targetPath: http://localhost/app
`

Variables

View Source
var (
	DefaultRootCaPem = []byte(`
-----BEGIN CERTIFICATE-----
MIICBTCCAaqgAwIBAgIBATAKBggqhkjOPQQDAjBaMQ4wDAYDVQQGEwVDaGluYTEO
MAwGA1UECBMFSHViZWkxDjAMBgNVBAcTBVd1aGFuMRAwDgYDVQQKEwdGb3J3YXJk
MRYwFAYDVQQDDA1odHRwc19mb3J3YXJkMB4XDTIxMDYyNDA4MDAwOVoXDTQyMDYy
NDA4MDAwOVowWjEOMAwGA1UEBhMFQ2hpbmExDjAMBgNVBAgTBUh1YmVpMQ4wDAYD
VQQHEwVXdWhhbjEQMA4GA1UEChMHRm9yd2FyZDEWMBQGA1UEAwwNaHR0cHNfZm9y
d2FyZDBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABPFLTsXmrzLUSG4/B+Q2KXjt
2mfsoFO6j0b/QHzNTgZVpUUbmaWOAme4H/04IFJNBF2m7DDu3i/DYNUnTKq8Kkqj
YTBfMA4GA1UdDwEB/wQEAwIBBjAdBgNVHSUEFjAUBggrBgEFBQcDAgYIKwYBBQUH
AwEwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUYydnnTxNzOTfHCrYBXIbLNtu
L9AwCgYIKoZIzj0EAwIDSQAwRgIhAKERFge+CagR612vwYqhve56ygcu7lQ70IVU
QRLFAIZvAiEAvEyNzS8TQsH/uHFBL8rKc4Aa0gzWfR+AdjeupJKpXNo=
-----END CERTIFICATE-----
`)

	DefaultRootKeyPem = []byte(`
-----BEGIN EC PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg7cPbPqTj7OtURNYe
m74YVgMh4hqNeO6lXTeQIInKeAyhRANCAATxS07F5q8y1EhuPwfkNil47dpn7KBT
uo9G/0B8zU4GVaVFG5mljgJnuB/9OCBSTQRdpuww7t4vw2DVJ0yqvCpK
-----END EC PRIVATE KEY-----
`)
)
View Source
var TunnelEstablishedResponseLine = []byte("HTTP/1.1 200 Connection established\r\n\r\n")

Functions

func GenerateCert

func GenerateCert(tmpl *x509.Certificate, rootCA *x509.Certificate, rootKey *MyRootKey) (*tls.Certificate, error)

func GenerateCertBlock

func GenerateCertBlock() (*pem.Block, *pem.Block, error)

func GenerateTemplate

func GenerateTemplate(host string, expireDays int) (*x509.Certificate, error)

generate certificate template

func NewDefaultProxyServer

func NewDefaultProxyServer(addr string, proxy IProxy) (*http.Server, error)

func OutPutRuleExample

func OutPutRuleExample(path string) error

func OutputDefaultCertAndPrivKey

func OutputDefaultCertAndPrivKey(path string) error

Types

type DefaultCertManagement

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

func NewDefaultCertManagement

func NewDefaultCertManagement(modifyOpts ...Option) (*DefaultCertManagement, error)

func NewDefaultCertManagementFromFile

func NewDefaultCertManagementFromFile(ca, key string) (*DefaultCertManagement, error)

func (*DefaultCertManagement) AddCert

func (c *DefaultCertManagement) AddCert(host string, cert *tls.Certificate) error

func (*DefaultCertManagement) GetCert

func (c *DefaultCertManagement) GetCert(host string) (*tls.Certificate, error)

type DefaultHttpsProxy

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

func NewDefaultHttpsProxy

func NewDefaultHttpsProxy(rules []IRule) (*DefaultHttpsProxy, error)

func (*DefaultHttpsProxy) ServeHTTP

func (p *DefaultHttpsProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request)

type ForwardRule

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

func NewForwardRule

func NewForwardRule(certManagement ICertManagement, rules ...ForwardRuleConfig) (*ForwardRule, error)

func NewForwardRuleFromConf

func NewForwardRuleFromConf(certManagement ICertManagement, fileName string) (*ForwardRule, error)

func (*ForwardRule) Handle

func (r *ForwardRule) Handle(rw http.ResponseWriter, req *http.Request) error

func (*ForwardRule) Match

func (r *ForwardRule) Match(req *http.Request) (bool, error)

type ForwardRuleConfig

type ForwardRuleConfig struct {
	Name       string `yaml:"name"`
	MatchPath  string `yaml:"matchPath"`
	TargetPath string `yaml:"targetPath"`
}

type ICertManagement

type ICertManagement interface {
	GetCert(string) (*tls.Certificate, error)
	AddCert(string, *tls.Certificate) error
}

type IProxy

type IProxy interface {
	ServeHTTP(http.ResponseWriter, *http.Request)
}

type IRule

type IRule interface {
	Match(*http.Request) (bool, error)
	Handle(http.ResponseWriter, *http.Request) error
}

type MyRootCa

type MyRootCa struct {
	Ca    *x509.Certificate
	Bytes *[]byte
}

type MyRootKey

type MyRootKey struct {
	Key   crypto.Signer
	Bytes *[]byte
}

type Option

type Option func(opt *options)

func WithRootCa

func WithRootCa(rootCa *[]byte) Option

func WithRootKey

func WithRootKey(rootKey *[]byte) Option

type RuleConfig

type RuleConfig struct {
	ForwardRules []ForwardRuleConfig `yaml:"forwardRules"`
}

Jump to

Keyboard shortcuts

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