chshare

package
v0.0.0-...-f49fb2b Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2021 License: MIT Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const DetermRandIter = 2048

DetermRandIter is the number of times a seed is hashed with SHA-512 to produce starting state of a pseudo-random stream

View Source
const ProtocolVersion = "sammck-wstunnel-v1"

ProtocolVersion of wstunnel. When backwards incompatible changes are made, this will be incremented to signify a protocol mismatch.

Variables

View Source
var BuildVersion = "1.0.0-src"

BuildVersion is the build version for this release

View Source
var LastSSHSessionID int32

LastSSHSessionID is the last allocated ID for SSH sessions, for logging purposes

View Source
var UserAllowAll = regexp.MustCompile("")

UserAllowAll is a regular expression used to match any address

Functions

func AllocSSHSessionID

func AllocSSHSessionID() int32

AllocSSHSessionID allocates a monotonically incresing session ID number (for debugging/logging only)

func FingerprintKey

func FingerprintKey(k ssh.PublicKey) string

FingerprintKey returns a standard fingerprint hash string for an SSH public key, which clients can use to authenticate the SSH server.

func GenerateKey

func GenerateKey(seed string) ([]byte, error)

GenerateKey generates a keypair to use for the SSH server end, using an optional seed that will produce the same keypair every time. If seed is "", a random key will be generated.

func GoStats

func GoStats()

GoStats prints statistics to stdout on SIGUSR2 (posix-only)

func HandleTCPStream

func HandleTCPStream(l Logger, connStats *ConnStats, src io.ReadWriteCloser, remote string)

HandleTCPStream handles a new ssh.Conn from a remote Stub that needs to Dial to a local network resource and pipe between them. Returns when the connection is complete. src will be closed before returning.

func NewDetermRand

func NewDetermRand(seed []byte) io.Reader

NewDetermRand creates an io.Reader that produces pseudo random bytes that are deterministic from a seed

func ParseAuth

func ParseAuth(auth string) (string, string)

ParseAuth parses a ":"-delimited authorization string pair. Returns two empty strings if the input does not contain ":"

func SleepSignal

func SleepSignal(d time.Duration)

SleepSignal sleeps for the given duration, or until a SIGHUP is received

Types

type Client

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

Client represents a client instance

func NewClient

func NewClient(config *Config) (*Client, error)

NewClient creates a new client instance

func (*Client) GetLoopServer

func (c *Client) GetLoopServer() *LoopServer

GetLoopServer returns the shared LoopServer if loop protocol is enabled; nil otherwise

func (*Client) GetSSHConn

func (c *Client) GetSSHConn() (ssh.Conn, error)

GetSSHConn waits for and returns the main ssh.Conn that this proxy is using to communicate with the remote proxy. It is possible that goroutines servicing local stub sockets will ask for this before it is available (if for example a listener on the client accepts a connection before the server has ackknowledged configuration.

func (*Client) GetSocksServer

func (c *Client) GetSocksServer() *socks5.Server

GetSocksServer returns the shared socks5 server if socks protocol is enabled; nil otherwise

func (*Client) HandleOnceShutdown

func (c *Client) HandleOnceShutdown(completionErr error) error

HandleOnceShutdown will be called exactly once, in its own goroutine. It should take completionError as an advisory completion value, actually shut down, then return the real completion value.

func (*Client) IsServer

func (c *Client) IsServer() bool

IsServer returns true if this is a proxy server; false if it is a cliet

func (*Client) Run

func (c *Client) Run(ctx context.Context) error

Run starts client and blocks while connected

func (*Client) Start

func (c *Client) Start(ctx context.Context) error

Start client and does not block

type Config

type Config struct {
	Debug            bool
	Fingerprint      string
	Auth             string
	KeepAlive        time.Duration
	MaxRetryCount    int
	MaxRetryInterval time.Duration
	Server           string
	HTTPProxy        string
	ChdStrings       []string
	HostHeader       string
	// contains filtered or unexported fields
}

Config represents a client configuration

type ConnStats

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

ConnStats keep track of both currently open and total connection counts for an entity

func (*ConnStats) Close

func (c *ConnStats) Close()

Close subtracts one from the current open connection count in a ConnStats

func (*ConnStats) New

func (c *ConnStats) New() int32

New adds one to the total connection count in a ConnStats

func (*ConnStats) Open

func (c *ConnStats) Open()

Open adds one to the current open connection count in a ConnStats

func (*ConnStats) String

func (c *ConnStats) String() string

type DetermRand

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

DetermRand keeps running state for a pseudorandom byte stream

func (*DetermRand) Read

func (d *DetermRand) Read(b []byte) (int, error)

type GetSSHConn

type GetSSHConn func() ssh.Conn

GetSSHConn is a callback that is used to defer fetching of the ssh.Conn until after it is established

type HTTPServer

type HTTPServer struct {
	ShutdownHelper
	*http.Server
	// contains filtered or unexported fields
}

HTTPServer extends net/http Server and adds graceful shutdowns

func NewHTTPServer

func NewHTTPServer(logger Logger) *HTTPServer

NewHTTPServer creates a new HTTPServer

func (*HTTPServer) Close

func (h *HTTPServer) Close() error

Close completely shuts down the server, then returns the final completion code

func (*HTTPServer) HandleOnceShutdown

func (h *HTTPServer) HandleOnceShutdown(completionErr error) error

HandleOnceShutdown will be called exactly once, in its own goroutine. It should take completionError as an advisory completion value, actually shut down, then return the real completion value.

func (*HTTPServer) ListenAndServe

func (h *HTTPServer) ListenAndServe(ctx context.Context, addr string, handler http.Handler) error

ListenAndServe Runs the HTTP server on the given bind address, invoking the provided handler for each request. It returns after the server has shutdown. The server can be shutdown either by cancelling the context or by calling Shutdown().

func (*HTTPServer) Shutdown

func (h *HTTPServer) Shutdown(completionError error) error

Shutdown completely shuts down the server, then returns the final completion code

type ProxyServerConfig

type ProxyServerConfig struct {
	KeySeed  string
	AuthFile string
	Auth     string
	Proxy    string
	Socks5   bool
	NoLoop   bool
	Reverse  bool
	Debug    bool
}

ProxyServerConfig is the configuration for the wstunnel service

type SSHSession

type SSHSession struct {
	ShutdownHelper
	// contains filtered or unexported fields
}

SSHSession wraps a primary SSH connection to the remote proxy

func (*SSHSession) HandleOnceShutdown

func (s *SSHSession) HandleOnceShutdown(completionErr error) error

HandleOnceShutdown will be called exactly once, in its own goroutine. It should take completionError as an advisory completion value, actually shut down, then return the real completion value.

func (*SSHSession) InitSSHSession

func (s *SSHSession) InitSSHSession(logger Logger, localChannelEnv LocalChannelEnv)

InitSSHSession initializes a new SSHSession

func (*SSHSession) String

func (s *SSHSession) String() string

type Server

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

Server respresent a wstunnel service

func NewServer

func NewServer(config *ProxyServerConfig) (*Server, error)

NewServer creates and returns a new wstunnel server

func (*Server) AddUser

func (s *Server) AddUser(user, pass string, addrs ...string) error

AddUser adds a new user into the server user index

func (*Server) DeleteUser

func (s *Server) DeleteUser(user string)

DeleteUser removes a user from the server user index

func (*Server) GetFingerprint

func (s *Server) GetFingerprint() string

GetFingerprint is used to access the server fingerprint

func (*Server) HandleOnceShutdown

func (s *Server) HandleOnceShutdown(completionErr error) error

HandleOnceShutdown will be called exactly once, in its own goroutine. It should take completionError as an advisory completion value, actually shut down, then return the real completion value.

func (*Server) Run

func (s *Server) Run(ctx context.Context, host, port string) error

Run is responsible for starting the wstunnel service

type ServerSSHSession

type ServerSSHSession struct {
	SSHSession
	// contains filtered or unexported fields
}

ServerSSHSession wraps a primary SSH connection with a single client proxy

func NewServerSSHSession

func NewServerSSHSession(server *Server) (*ServerSSHSession, error)

NewServerSSHSession creates a server-side proxy session object

func (*ServerSSHSession) GetLoopServer

func (s *ServerSSHSession) GetLoopServer() *LoopServer

GetLoopServer returns the shared LoopServer if loop protocol is enabled; nil otherwise

func (*ServerSSHSession) GetSSHConn

func (s *ServerSSHSession) GetSSHConn() (ssh.Conn, error)

GetSSHConn waits for and returns the main ssh.Conn that this proxy is using to communicate with the remote proxy. It is possible that goroutines servicing local stub sockets will ask for this before it is available (if for example a listener on the client accepts a connection before the server has ackknowledged configuration. An error response indicates that the SSH connection failed to initialize.

func (*ServerSSHSession) GetSocksServer

func (s *ServerSSHSession) GetSocksServer() *socks5.Server

GetSocksServer returns the shared socks5 server if socks protocol is enabled; nil otherwise

func (*ServerSSHSession) IsServer

func (s *ServerSSHSession) IsServer() bool

IsServer returns true if this is a proxy server; false if it is a cliet

func (*ServerSSHSession) Run

func (s *ServerSSHSession) Run(ctx context.Context, conn net.Conn) error

Run runs an SSH server session to completion from an incoming just-connected client socket (which has already been wrapped on a websocket)

type SessionConfigRequest

type SessionConfigRequest struct {
	Version            string
	ChannelDescriptors []*ChannelDescriptor
}

SessionConfigRequest describes a wstunnel proxy/client session configuration. It is sent from the client to the server during initialization

func PbToSessionConfigRequest

func PbToSessionConfigRequest(pb *interproxy.PbSessionConfigRequest) *SessionConfigRequest

PbToSessionConfigRequest returns a SessionConfigRequest from its protobuf value

func (*SessionConfigRequest) FromPb

FromPb initializes a SessionConfigRequest from its protobuf value

func (*SessionConfigRequest) Marshal

func (c *SessionConfigRequest) Marshal() ([]byte, error)

Marshal serializes a SessionConfigRequest to protobuf bytes

func (*SessionConfigRequest) ToPb

ToPb converts a SessionConfigRequest to its protobuf value

func (*SessionConfigRequest) Unmarshal

func (c *SessionConfigRequest) Unmarshal(b []byte) error

Unmarshal unserializes a SessionConfigRequest from protobuf bytes

type TCPProxy

type TCPProxy struct {
	ShutdownHelper
	// contains filtered or unexported fields
}

TCPProxy proxies a single channel between a local stub endpoint and a remote skeleton endpoint

func NewTCPProxy

func NewTCPProxy(logger Logger, localChannelEnv LocalChannelEnv, index int, chd *ChannelDescriptor) *TCPProxy

NewTCPProxy creates a new TCPProxy

func (*TCPProxy) HandleOnceShutdown

func (p *TCPProxy) HandleOnceShutdown(completionErr error) error

HandleOnceShutdown will be called exactly once, in its own goroutine. It should take completionError as an advisory completion value, actually shut down, then return the real completion value.

func (*TCPProxy) Start

func (p *TCPProxy) Start(ctx context.Context) error

Start starts a listener for the local stub endpoint in the backgroud

func (*TCPProxy) String

func (p *TCPProxy) String() string

type User

type User struct {
	Name  string
	Pass  string
	Addrs []*regexp.Regexp
}

User describes a single user's authorization info, including name, password, and a list of channel endpoint regular expressions that are allowed

func (*User) HasAccess

func (u *User) HasAccess(addr string) bool

HasAccess returns True if a given address matches the allowed address patterns for the user

type UserIndex

type UserIndex struct {
	Logger
	*Users
	// contains filtered or unexported fields
}

UserIndex is a reloadable user source

func NewUserIndex

func NewUserIndex(logger Logger) *UserIndex

NewUserIndex creates a source for users

func (*UserIndex) LoadUsers

func (u *UserIndex) LoadUsers(configFile string) error

LoadUsers is responsible for loading users from a file

type Users

type Users struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Users manages a list of users with authorization info for each

func NewUsers

func NewUsers() *Users

NewUsers creates a new Users object to manage user authorization information

func (*Users) AddUser

func (u *Users) AddUser(user *User)

AddUser adds a users to the list

func (*Users) Del

func (u *Users) Del(key string)

Del deletes a user from the list

func (*Users) Get

func (u *Users) Get(key string) (*User, bool)

Get user from the index by key

func (*Users) Len

func (u *Users) Len() int

Len returns the numbers of users

func (*Users) Set

func (u *Users) Set(key string, user *User)

Set a users into the list by specific key

Jump to

Keyboard shortcuts

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