waygate

package module
v0.0.0-...-01d9eb1 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: MIT Imports: 50 Imported by: 0

Documentation

Overview

Code in this file was adapted from https://github.com/crmejia/certmagic-sqlite3

Code in this file was adapted from https://github.com/crmejia/certmagic-sqlite3

Index

Constants

View Source
const (
	MessageTypeTunnelConfig = iota
	MessageTypeSuccess
	MessageTypeListen
	MessageTypeStream
	MessageTypeDial
	MessageTypeError
)
View Source
const ListenerDefaultKey = "default-listener"
View Source
const PROXY_PROTO_PP2_TYPE_MIN_CUSTOM = 0xe0
View Source
const PROXY_PROTO_SERVER_NAME_OFFSET = PROXY_PROTO_PP2_TYPE_MIN_CUSTOM + 0
View Source
const WebTransportCodeCancel = 0

Variables

View Source
var (
	DefaultToken   string = ""
	DefaultCertDir string = "./"
	DebugMode      bool   = false
)
View Source
var WaygateServerDomain string = "waygate.io"

Functions

func ConnectConns

func ConnectConns(downstreamConn connCloseWriter, upstreamConn connCloseWriter)

func DoDeviceFlow

func DoDeviceFlow() (string, error)

func NewKvStore

func NewKvStore(sqlDb *sql.DB) (*kvStore, error)

Types

type CertmagicSqliteStorage

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

func NewCertmagicSqliteStorage

func NewCertmagicSqliteStorage(sqlDb *sql.DB) (*CertmagicSqliteStorage, error)

func (*CertmagicSqliteStorage) Delete

func (s *CertmagicSqliteStorage) Delete(ctx context.Context, key string) error

func (*CertmagicSqliteStorage) Exists

func (s *CertmagicSqliteStorage) Exists(ctx context.Context, key string) bool

func (*CertmagicSqliteStorage) List

func (s *CertmagicSqliteStorage) List(ctx context.Context, prefix string, recursive bool) ([]string, error)

func (*CertmagicSqliteStorage) Load

func (s *CertmagicSqliteStorage) Load(ctx context.Context, key string) ([]byte, error)

func (*CertmagicSqliteStorage) Lock

func (s *CertmagicSqliteStorage) Lock(ctx context.Context, name string) error

func (*CertmagicSqliteStorage) Stat

func (*CertmagicSqliteStorage) Store

func (s *CertmagicSqliteStorage) Store(ctx context.Context, key string, value []byte) error

func (*CertmagicSqliteStorage) Unlock

func (s *CertmagicSqliteStorage) Unlock(ctx context.Context, name string) error

type Client

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

func NewClient

func NewClient(config *ClientConfig) *Client

func (*Client) AddUser

func (c *Client) AddUser(user obligator.User) error

func (*Client) GetUsers

func (c *Client) GetUsers() ([]*obligator.User, error)

func (*Client) ListenEvents

func (c *Client) ListenEvents(eventCh chan interface{})

func (*Client) Proxy

func (c *Client) Proxy(domain, addr string)

func (*Client) Run

func (c *Client) Run() error

func (*Client) SetForward

func (c *Client) SetForward(forward *Forward) error

type ClientConfig

type ClientConfig struct {
	Users        []string
	ServerDomain string
	Token        string
	Dir          string
	Public       bool
	NoBrowser    bool
	DNSProvider  string
	DNSUser      string
	DNSToken     string
}

type ClientDatabase

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

func NewClientDatabase

func NewClientDatabase(path string) (*ClientDatabase, error)

func (*ClientDatabase) DeleteForwardByDomain

func (d *ClientDatabase) DeleteForwardByDomain(domain string) error

func (*ClientDatabase) GetDomains

func (d *ClientDatabase) GetDomains() ([]string, error)

func (*ClientDatabase) GetForward

func (s *ClientDatabase) GetForward(domain string) (*Forward, error)

func (*ClientDatabase) GetForwards

func (d *ClientDatabase) GetForwards() ([]*Forward, error)

func (*ClientDatabase) GetServerUri

func (d *ClientDatabase) GetServerUri() (string, error)

func (*ClientDatabase) GetToken

func (d *ClientDatabase) GetToken() (string, error)

func (*ClientDatabase) SetDomain

func (d *ClientDatabase) SetDomain(domain string) error

func (*ClientDatabase) SetForward

func (d *ClientDatabase) SetForward(f *Forward) error

func (*ClientDatabase) SetServerUri

func (d *ClientDatabase) SetServerUri(serverUri string) error

func (*ClientDatabase) SetToken

func (d *ClientDatabase) SetToken(value string) error

type ClientMux

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

func NewClientMux

func NewClientMux(authServer *obligator.Server, fileServer *gemdrive.Server, db *ClientDatabase) *ClientMux

func (*ClientMux) Handle

func (s *ClientMux) Handle(p string, h http.Handler)

func (*ClientMux) HandleFunc

func (s *ClientMux) HandleFunc(p string, f func(w http.ResponseWriter, r *http.Request))

func (*ClientMux) ServeHTTP

func (m *ClientMux) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ClientSession

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

func NewClientSession

func NewClientSession(token string, db *ClientDatabase) (*ClientSession, error)

func (*ClientSession) DialUDP

func (s *ClientSession) DialUDP(network string, dstAddr *net.UDPAddr) (*UDPConn, error)

func (*ClientSession) GetTunnelConfig

func (s *ClientSession) GetTunnelConfig() TunnelConfig

func (*ClientSession) Listen

func (s *ClientSession) Listen(network, address string) (*Listener, error)

func (*ClientSession) ListenUDP

func (s *ClientSession) ListenUDP(network string, udpAddr *net.UDPAddr) (*UDPConn, error)

type Database

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

func NewDatabase

func NewDatabase(path string) (*Database, error)

func (*Database) GetJWKS

func (d *Database) GetJWKS() (string, error)

func (*Database) SetJWKS

func (d *Database) SetJWKS(jwks string) error

type DialRequest

type DialRequest struct {
	Network string `json:"network"`
	Address string `json:"address"`
}

type DialResponse

type DialResponse struct {
	Success bool   `json:"success"`
	Message string `json:"message"`
	Address string `json:"address"`
}

type Forward

type Forward struct {
	Domain        string `db:"domain"`
	Protected     bool   `db:"protected"`
	TargetAddress string `db:"target_address"`
}

type ListenOptions

type ListenOptions struct {
	Token string
	Db    *ClientDatabase
}

type ListenRequest

type ListenRequest struct {
	Network string `json:"network"`
	Address string `json:"address"`
}

type ListenResponse

type ListenResponse struct {
	Success bool   `json:"success"`
	Message string `json:"message"`
}

type Listener

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

func Listen

func Listen(network, address string, opts ...ListenOptions) (*Listener, error)

func ListenWithOpts

func ListenWithOpts(network, address, token string, db *ClientDatabase) (*Listener, error)

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) GetTunnelConfig

func (l *Listener) GetTunnelConfig() TunnelConfig

type MessageType

type MessageType uint8

func (MessageType) String

func (t MessageType) String() string

type MuxadoTunnel

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

func NewTlsMuxadoClientTunnel

func NewTlsMuxadoClientTunnel(tunnelReq TunnelRequest) (*MuxadoTunnel, error)

func NewTlsMuxadoServerTunnel

func NewTlsMuxadoServerTunnel(tlsConn *tls.Conn, jose *josencillo.JOSE, public bool) (*MuxadoTunnel, error)

func NewWebSocketMuxadoClientTunnel

func NewWebSocketMuxadoClientTunnel(tunReq TunnelRequest) (*MuxadoTunnel, error)

func NewWebSocketMuxadoServerTunnel

func NewWebSocketMuxadoServerTunnel(
	w http.ResponseWriter,
	r *http.Request,
	jose *josencillo.JOSE,
	public bool,
	tunnelDomains []string,
	gauge prometheus.Gauge,
) (*MuxadoTunnel, error)

func (*MuxadoTunnel) AcceptStream

func (t *MuxadoTunnel) AcceptStream() (connCloseWriter, error)

func (*MuxadoTunnel) AcceptStreamType

func (t *MuxadoTunnel) AcceptStreamType() (connCloseWriter, MessageType, error)

func (*MuxadoTunnel) GetConfig

func (t *MuxadoTunnel) GetConfig() TunnelConfig

func (*MuxadoTunnel) HandleRequests

func (t *MuxadoTunnel) HandleRequests(callback func(interface{}) interface{}) error

func (*MuxadoTunnel) OpenStream

func (t *MuxadoTunnel) OpenStream() (connCloseWriter, error)

func (*MuxadoTunnel) OpenStreamType

func (t *MuxadoTunnel) OpenStreamType(msgType MessageType) (connCloseWriter, error)

func (*MuxadoTunnel) ReceiveDatagram

func (t *MuxadoTunnel) ReceiveDatagram() ([]byte, net.Addr, net.Addr, error)

func (*MuxadoTunnel) Request

func (t *MuxadoTunnel) Request(req interface{}) (interface{}, error)

func (*MuxadoTunnel) SendDatagram

func (t *MuxadoTunnel) SendDatagram(msg []byte, srcAddr, dstAddr net.Addr) error

type OAuth2AuthUriEvent

type OAuth2AuthUriEvent struct {
	Uri string
}

type OAuth2Handler

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

func NewOAuth2Handler

func NewOAuth2Handler(db *Database, serverUri, prefix string, jose *josencillo.JOSE) *OAuth2Handler

func (*OAuth2Handler) ServeHTTP

func (h *OAuth2Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type OmnistreamsTunnel

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

func NewOmnistreamsClientTunnel

func NewOmnistreamsClientTunnel(tunReq TunnelRequest) (*OmnistreamsTunnel, error)

func NewOmnistreamsServerTunnel

func NewOmnistreamsServerTunnel(
	w http.ResponseWriter,
	r *http.Request,
	jose *josencillo.JOSE,
	public bool,
	tunnelDomains []string,
	numStreamsGauge prometheus.Gauge,
	dash *dashtui.DashTUI,
) (*OmnistreamsTunnel, error)

func (*OmnistreamsTunnel) AcceptStream

func (t *OmnistreamsTunnel) AcceptStream() (connCloseWriter, error)

func (*OmnistreamsTunnel) AcceptStreamType

func (t *OmnistreamsTunnel) AcceptStreamType() (connCloseWriter, MessageType, error)

func (*OmnistreamsTunnel) GetConfig

func (t *OmnistreamsTunnel) GetConfig() TunnelConfig

func (*OmnistreamsTunnel) HandleRequests

func (t *OmnistreamsTunnel) HandleRequests(callback func(interface{}) interface{}) error

func (*OmnistreamsTunnel) OpenStream

func (t *OmnistreamsTunnel) OpenStream() (connCloseWriter, error)

func (*OmnistreamsTunnel) OpenStreamType

func (t *OmnistreamsTunnel) OpenStreamType(msgType MessageType) (connCloseWriter, error)

func (*OmnistreamsTunnel) ReceiveDatagram

func (t *OmnistreamsTunnel) ReceiveDatagram() ([]byte, net.Addr, net.Addr, error)

func (*OmnistreamsTunnel) Request

func (t *OmnistreamsTunnel) Request(req interface{}) (interface{}, error)

func (*OmnistreamsTunnel) SendDatagram

func (t *OmnistreamsTunnel) SendDatagram(msg []byte, srcAddr, dstAddr net.Addr) error

func (*OmnistreamsTunnel) SendMessage

func (t *OmnistreamsTunnel) SendMessage(msg interface{}) (interface{}, error)

type PassthroughListener

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

func NewPassthroughListener

func NewPassthroughListener() *PassthroughListener

func (*PassthroughListener) Accept

func (f *PassthroughListener) Accept() (net.Conn, error)

func (*PassthroughListener) Addr

func (f *PassthroughListener) Addr() net.Addr

func (*PassthroughListener) Close

func (f *PassthroughListener) Close() error

func (*PassthroughListener) PassConn

func (f *PassthroughListener) PassConn(conn net.Conn)

type ProxyConn

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

This type creates a new net.Conn that's the same as an old one, except a new reader is provided. So it proxies every method except Read. This is necessary because by calling peekClientHello, part of the reader is read, so we need to create a new reader with the already read data inserted back in the front. I'm sure there's a cleaner way to do this...

func NewProxyConn

func NewProxyConn(conn net.Conn, reader io.Reader) *ProxyConn

func (ProxyConn) Close

func (c ProxyConn) Close() error

TODO: is this safe? Will it actually close properly, or does it need to be connected to the reader somehow?

func (ProxyConn) CloseWrite

func (c ProxyConn) CloseWrite() error

func (ProxyConn) LocalAddr

func (c ProxyConn) LocalAddr() net.Addr

func (ProxyConn) Read

func (c ProxyConn) Read(p []byte) (int, error)

func (ProxyConn) RemoteAddr

func (c ProxyConn) RemoteAddr() net.Addr

func (ProxyConn) SetDeadline

func (c ProxyConn) SetDeadline(t time.Time) error

func (ProxyConn) SetReadDeadline

func (c ProxyConn) SetReadDeadline(t time.Time) error

func (ProxyConn) SetWriteDeadline

func (c ProxyConn) SetWriteDeadline(t time.Time) error

func (ProxyConn) Write

func (c ProxyConn) Write(p []byte) (int, error)

type Server

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

func NewServer

func NewServer(config *ServerConfig) *Server

func (*Server) Run

func (s *Server) Run()

type ServerConfig

type ServerConfig struct {
	AdminDomain      string
	Port             int
	Public           bool
	DnsProvider      string
	DnsToken         string
	DnsUser          string
	TunnelDomains    []string
	DisableTUI       bool
	TUIDisplayPeriod time.Duration
	Users            []string
}

type ServerMux

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

func NewServerMux

func NewServerMux(authServer *obligator.Server, adminDomain string) *ServerMux

func (*ServerMux) Handle

func (s *ServerMux) Handle(p string, h http.Handler)

func (*ServerMux) HandleFunc

func (s *ServerMux) HandleFunc(p string, f func(w http.ResponseWriter, r *http.Request))

func (*ServerMux) ServeHTTP

func (m *ServerMux) ServeHTTP(w http.ResponseWriter, r *http.Request)

type TokenFlow

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

func NewTokenFlow

func NewTokenFlow() (*TokenFlow, error)

func (*TokenFlow) GetAuthUri

func (f *TokenFlow) GetAuthUri() string

func (*TokenFlow) GetToken

func (f *TokenFlow) GetToken() (string, error)

func (*TokenFlow) GetTokenWithRedirect

func (f *TokenFlow) GetTokenWithRedirect(redirUriCh chan string) (string, error)

type Tunnel

type Tunnel interface {
	OpenStream() (connCloseWriter, error)
	OpenStreamType(MessageType) (connCloseWriter, error)
	AcceptStream() (connCloseWriter, error)
	AcceptStreamType() (connCloseWriter, MessageType, error)
	GetConfig() TunnelConfig
	Request(req interface{}) (interface{}, error)
	HandleRequests(callback func(interface{}) interface{}) error
	SendDatagram(msg []byte, srcAddr, dstAddr net.Addr) error
	ReceiveDatagram() ([]byte, net.Addr, net.Addr, error)
}

type TunnelConfig

type TunnelConfig struct {
	Domain           string `json:"domain"`
	TerminationType  string `json:"termination_type"`
	UseProxyProtocol bool   `json:"use_proxy_protocol"`
}

type TunnelConnectedEvent

type TunnelConnectedEvent struct {
	TunnelConfig TunnelConfig
}

type TunnelRequest

type TunnelRequest struct {
	Token            string `json:"token"`
	TerminationType  string `json:"termination_type"`
	UseProxyProtocol bool   `json:"use_proxy_protocol"`
}

type UDPConn

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

func DialUDP

func DialUDP(network string, udpAddr *net.UDPAddr) (*UDPConn, error)

func ListenUDP

func ListenUDP(network string, udpAddr *net.UDPAddr) (*UDPConn, error)

func (*UDPConn) ReadFromUDP

func (c *UDPConn) ReadFromUDP(buf []byte) (int, *net.UDPAddr, error)

func (*UDPConn) WriteToUDP

func (c *UDPConn) WriteToUDP(p []byte, addr *net.UDPAddr) (int, error)

type UsersUpdatedEvent

type UsersUpdatedEvent struct {
	Users []*obligator.User
}

type WebTransportTunnel

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

func NewWebTransportClientTunnel

func NewWebTransportClientTunnel(tunnelReq TunnelRequest) (*WebTransportTunnel, error)

func NewWebTransportServerTunnel

func NewWebTransportServerTunnel(
	w http.ResponseWriter,
	r *http.Request,
	wtServer webtransport.Server,
	jose *josencillo.JOSE,
	public bool,
	tunnelDomains []string,
) (*WebTransportTunnel, error)

func (*WebTransportTunnel) AcceptStream

func (t *WebTransportTunnel) AcceptStream() (connCloseWriter, error)

func (*WebTransportTunnel) AcceptStreamType

func (t *WebTransportTunnel) AcceptStreamType() (connCloseWriter, MessageType, error)

func (*WebTransportTunnel) GetConfig

func (t *WebTransportTunnel) GetConfig() TunnelConfig

func (*WebTransportTunnel) HandleRequests

func (t *WebTransportTunnel) HandleRequests(callback func(interface{}) interface{}) error

func (*WebTransportTunnel) OpenStream

func (t *WebTransportTunnel) OpenStream() (connCloseWriter, error)

func (*WebTransportTunnel) OpenStreamType

func (t *WebTransportTunnel) OpenStreamType(msgType MessageType) (connCloseWriter, error)

func (*WebTransportTunnel) ReceiveDatagram

func (t *WebTransportTunnel) ReceiveDatagram() ([]byte, net.Addr, net.Addr, error)

func (*WebTransportTunnel) Request

func (t *WebTransportTunnel) Request(req interface{}) (interface{}, error)

func (*WebTransportTunnel) SendDatagram

func (t *WebTransportTunnel) SendDatagram(msg []byte, srcAddr, dstAdd net.Addr) error

Directories

Path Synopsis
cmd
examples

Jump to

Keyboard shortcuts

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