sidecar

package module
v0.0.0-...-aeec9b5 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: GPL-2.0 Imports: 32 Imported by: 0

README

Introduction

Sidecar is a https proxy server based on MITM.

Feature

  • HTTP proxy
  • HTTPS proxy
  • Work as a daemon
  • Support custom config
  • Support assistant log
  • Auto create certificate
  • Provide cmd tool
  • Support PAC
  • Support Custom DNS
  • Support HTTP2
  • Refactoring

Get Started

Here is User Manual.

License

GPL-2.0 license

Documentation

Overview

From JumpServer KoKo

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChangeResolver

func ChangeResolver(ipAddr string)

func CreateDirIfNotExist

func CreateDirIfNotExist(path string) (abspath string)

func CreateFileIfNotExist

func CreateFileIfNotExist(file string) (fd *os.File)

func Debug

func Debug(args ...interface{})

func DetectFile

func DetectFile(name string) (path string)

func DetectProcess

func DetectProcess(pid int) (alive bool)

func Error

func Error(args ...interface{})

func Fatal

func Fatal(args ...interface{})

func GenAndSavePriKey

func GenAndSavePriKey(fd *os.File) (pri *rsa.PrivateKey)

func GenAndSaveRootCert

func GenAndSaveRootCert(fd *os.File, pri *rsa.PrivateKey) (crt *x509.Certificate)

func GenTLSCert

func GenTLSCert(hostname string, crt *x509.Certificate, pri *rsa.PrivateKey) (tls_cert *tls.Certificate, err error)

func Info

func Info(args ...interface{})

func Initial

func Initial(LogLevel string, fd *os.File)

func MitMHandleHttp

func MitMHandleHttp(server string, subpath string, headers map[string]string, writer http.ResponseWriter, in_req *http.Request)

func MitMHandleWs

func MitMHandleWs(server string, subpath string, headers map[string]string, writer http.ResponseWriter, in_req *http.Request)

func OpenExistFile

func OpenExistFile(file string) (fd *os.File)

func Panic

func Panic(args ...interface{})

func ReadPriKey

func ReadPriKey(name string) (pri *rsa.PrivateKey)

func ReadRootCert

func ReadRootCert(name string) (crt *x509.Certificate)

func RenderTemplateByConfig

func RenderTemplateByConfig(config *Config)

func StartDaemonProcess

func StartDaemonProcess(configPath string, serviceType string)

run in backgroud

func StopDaemonProcess

func StopDaemonProcess(workDir string)

func Warn

func Warn(args ...interface{})

Types

type CertLRU

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

func NewCertLRU

func NewCertLRU(ca *x509.Certificate, pri *rsa.PrivateKey) *CertLRU

func (*CertLRU) GetCert

func (c *CertLRU) GetCert(sni string) (tls_cert *tls.Certificate, err error)

type Client

type Client struct {
	ProxyPort        int
	OnlyListenIPv4   bool
	RunAsDaemon      bool
	Mode             string
	WorkDir          string
	LogLevel         string
	GfwListUrl       string
	CustomProxyHosts []string
	PriKeyPath       string
	CertPath         string
	Resolver         string
	RemoteServers    []RemoteServerInfo
}

type Config

type Config struct {
	Client      Client
	Server      Server
	NginxConfig NginxConfig
}

func ReadClientConfig

func ReadClientConfig(path string) (cfg *Config)

func ReadNginxTplConfig

func ReadNginxTplConfig(path string) (cfg *Config)

func ReadServerConfig

func ReadServerConfig(path string) (cfg *Config)

type CustomHeaders

type CustomHeaders map[string]string

type Daemon

type Daemon struct {
	Pid          int
	WorkDir      string
	CertPath     string
	PriKeyPath   string
	LockFilePath string
	LogLevel     string
	Logger       *os.File
	PriKey       *rsa.PrivateKey
	Cert         *x509.Certificate
}

func (*Daemon) LoadCertAndPriKey

func (d *Daemon) LoadCertAndPriKey()

func (*Daemon) Perpare

func (d *Daemon) Perpare(backgroud bool)

func (*Daemon) WatchSignal

func (d *Daemon) WatchSignal()

type Formatter

type Formatter struct {
	// Timestamp format
	TimestampFormat string
	// Available standard keys: time, msg, lvl
	// Also can include custom fields but limited to strings.
	// All of fields need to be wrapped inside %% i.e %time% %msg%
	LogFormat string

	// Disables the truncation of the level text to 4 characters.
	DisableLevelTruncation bool
}

Formatter implements logrus.Formatter interface.

func (*Formatter) Format

func (f *Formatter) Format(entry *logrus.Entry) ([]byte, error)

Format building log message.

type Listener

type Listener struct {
	Chan chan net.Conn
	// contains filtered or unexported fields
}

func (*Listener) Accept

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

func (*Listener) Addr

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

func (*Listener) Close

func (l *Listener) Close() error

func (*Listener) Dest

func (l *Listener) Dest() string

func (*Listener) SetDest

func (l *Listener) SetDest(host string)

type MitMServer

type MitMServer struct {
	Listener *Listener
	// contains filtered or unexported fields
}

func NewMitMServer

func NewMitMServer(
	l *Listener, cache *CertLRU, fd *os.File,
	destination string, complex_path string, headers map[string]string,
) *MitMServer

func (*MitMServer) Run

func (p *MitMServer) Run()

type NginxConfig

type NginxConfig struct {
	ServerName           string
	ServerPort           int
	OnlyListenIPv4       bool
	Location             string
	Resolver             string
	SSLCertificate       string
	SSLPrivateKey        string
	WorkDir              string
	EnableListenHTTP2    bool
	EnableWebSocketProxy bool
	EnableModernTLSOnly  bool
	NginxCustomHeader    CustomHeaders
}

type Pac

type Pac struct {
	Matcher *adblock.RuleMatcher
}

func NewPac

func NewPac(server RemoteServerInfo, gfwUrl string, customHosts []string) *Pac

func (*Pac) Compare

func (p *Pac) Compare(req *http.Request) bool

func (*Pac) ExpandHosts

func (p *Pac) ExpandHosts(list []string)

type ProxyViaHttps

type ProxyViaHttps struct {
	Listener *Listener
	// contains filtered or unexported fields
}

func NewProxyViaHttps

func NewProxyViaHttps(fd *os.File, pac *Pac, onlyListenIPv4 bool, port int) *ProxyViaHttps

func (*ProxyViaHttps) Run

func (p *ProxyViaHttps) Run()

type ProxyViaWss

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

func NewProxyViaWss

func NewProxyViaWss(fd *os.File, pac *Pac,
	onlyListenIPv4 bool, port int, destination string, complex_path string, headers map[string]string,
) *ProxyViaWss

func (*ProxyViaWss) Run

func (i *ProxyViaWss) Run()

type RemoteServerHttps

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

func NewRemoteServerHttps

func NewRemoteServerHttps(
	fd *os.File, port int, only_listen_ipv4 bool, cert_path string, prikey_path string,
	complex_path string, headers map[string]string,
) *RemoteServerHttps

func (*RemoteServerHttps) Run

func (r *RemoteServerHttps) Run()

type RemoteServerInfo

type RemoteServerInfo struct {
	Host          string
	ComplexPath   string
	CustomHeaders CustomHeaders
}

type RemoteServerWss

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

func NewRemoteServerWss

func NewRemoteServerWss(
	fd *os.File, port int, only_listen_ipv4 bool, cert_path string, prikey_path string,
	complex_path string, headers map[string]string,
) *RemoteServerWss

func (*RemoteServerWss) Run

func (ws *RemoteServerWss) Run()

type Server

type Server struct {
	ServerPort     int
	OnlyListenIPv4 bool
	RunAsDaemon    bool
	Mode           string
	WorkDir        string
	Resolver       string
	LogLevel       string
	PriKeyPath     string
	CertPath       string
	ComplexPath    string
	CustomHeaders  CustomHeaders
}

Directories

Path Synopsis
cmd
examples

Jump to

Keyboard shortcuts

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