common

package
v0.0.0-...-31bae31 Latest Latest
Warning

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

Go to latest
Published: May 17, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BearerString is the string used to designate an auth token
	BearerString = "Bearer "
	// MaxTokenSize is the maximum number of characters for a bearer token
	MaxTokenSize = 48
	// MinTokenSize is the minimum number of characters for a bearer token
	MinTokenSize = 32
)
View Source
const (
	EndpointCtrlDisconnect = iota
	EndpointCtrlAddRTunnel
	EndpointCtrlAddTunnel
	EndpointCtrlSocksProxy
	EndpointCtrlSocksProxyAck
	EndpointCtrlSocksKill
	EndpointCtrlDeleteTunnel
)
View Source
const (
	TunnelDirectionForward = iota
	TunnelDirectionReverse
)
View Source
const (
	TunnelCtrlConnect = iota
	TunnelCtrlAck
	TunnelCtrlDisconnect
)
View Source
const (
	ConnectionStatusCreated = iota
	ConnectionStatusConnected
	ConnectionStatusClosed
)
View Source
const ClientIDSize = 8

ClientIDSize is the constant used for the string size of a generated client ID

View Source
const TunnelIDSize = 8

TunnelIDSize is the constant used for the string size of a generated tunnel ID

Variables

This section is empty.

Functions

func GenerateString

func GenerateString(length int) string

GenerateString will generate a random string of length Credit to: https://www.calhoun.io/creating-random-strings-in-go/

func GenerateToken

func GenerateToken() (string, error)

GenerateToken will generate a random string to be used as a client authorization.

func Int32ToIP

func Int32ToIP(i uint32) net.IP

Int32ToIP converts a uint32 to a net.IP

func IpToInt32

func IpToInt32(ip net.IP) uint32

IpToInt32 converts a net.IP to a uint32 Credit to https://gist.github.com/ammario/ipint.go

Types

type ByteStream

type ByteStream interface {
	Send(*cs.BytesMessage) error
	Recv() (*cs.BytesMessage, error)
}

type Connection

type Connection struct {
	ID        string
	TCPConn   net.TCPConn
	Kill      chan bool
	Status    int32
	Connected chan bool
	// contains filtered or unexported fields
}

A structure to handle the TCP connection and map them to the gRPC byte stream.

func NewConnection

func NewConnection(tcpConn net.TCPConn) *Connection

NewConnection is a constructor function for Connection.

func (*Connection) Close

func (c *Connection) Close()

Close will close a TCP connection and close the Kill channel.

func (*Connection) GetStream

func (c *Connection) GetStream() ByteStream

GetStream will return the byteStream for a connection

func (*Connection) SendCloseMessage

func (c *Connection) SendCloseMessage()

SendCloseMessage will send a zero sized message to the remote endpoint, indicating that a TCP connection has been closed locally.

func (*Connection) SetStream

func (c *Connection) SetStream(s ByteStream)

SetStream will set the byteStream for a connection

func (*Connection) Start

func (c *Connection) Start()

Start will start two goroutines for handling the TCP socket and the gRPC stream.

type ConnectionStreamHandler

type ConnectionStreamHandler interface {
	GetByteStream(tunnel *Tunnel, ctrlMessage *cs.TunnelControlMessage) ByteStream
	CloseStream(tunnel *Tunnel, connID string)
	Acknowledge(tunnel *Tunnel, ctrlMessage *cs.TunnelControlMessage) ByteStream
}

type Endpoint

type Endpoint struct {
	Id string
	// contains filtered or unexported fields
}

func NewEndpoint

func NewEndpoint() *Endpoint

NewEndpoint is a constructor for the endpoint class. It takes an endpoint ID string as an argument.

func (*Endpoint) AddTunnel

func (e *Endpoint) AddTunnel(id string, t *Tunnel)

AddTunnel adds a tunnel instance to the list of tunnels maintained by the endpoint

func (*Endpoint) GetTunnel

func (e *Endpoint) GetTunnel(tunID string) (*Tunnel, bool)

GetTunnel will take in a tunnel ID string as an argument and return a Tunnel pointer of the corresponding ID.

func (*Endpoint) GetTunnels

func (e *Endpoint) GetTunnels() map[string]*Tunnel

GetTunnels returns all of the active tunnels maintained by the endpoint

func (*Endpoint) SetID

func (e *Endpoint) SetID(id string)

SetID takes in a string and will set the Id to that string

func (*Endpoint) Stop

func (e *Endpoint) Stop()

Stop will close all tunnels and the associated TCP connections with each tunnel.

func (*Endpoint) StopAndDeleteTunnel

func (e *Endpoint) StopAndDeleteTunnel(tunID string) bool

StopAndDeleteTunnel takes in a tunnelID as an argument and removes the tunnel from the endpoint. Returns true if successful and false otherwise.

type SocksServer

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

SocksServer is a structure that handles starting and stopping a socks v5 proxy on the gClient.

func NewSocksServer

func NewSocksServer(port uint32) *SocksServer

NewSocksServer is a constructor for the SocksServer struct. It takes in a port as an argument, wich will be the port on which the socks server listens.

func (*SocksServer) Start

func (s *SocksServer) Start() bool

Start will start the socks server. Simple enough.

func (*SocksServer) Stop

func (s *SocksServer) Stop()

Stop - You'll never guess what this does.

type TokenAuth

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

TokenAuth is a structure repesenting a bearer token for client auth

func NewToken

func NewToken(token string) *TokenAuth

NewToken will generate a new TokenAuth structure with the provided string set to the token member.

func (*TokenAuth) GetRequestMetadata

func (t *TokenAuth) GetRequestMetadata(ctx context.Context, in ...string) (
	map[string]string, error)

GetRequestMetadata will return the bearer token as an authorization header

func (*TokenAuth) RequireTransportSecurity

func (t *TokenAuth) RequireTransportSecurity() bool

RequireTransportSecurity always returns true

type Tunnel

type Tunnel struct {
	Kill chan bool

	ConnectionHandler ConnectionStreamHandler
	// contains filtered or unexported fields
}

func NewTunnel

func NewTunnel(id string,
	direction uint32,
	listenIP net.IP,
	listenPort uint32,
	destinationIP net.IP,
	destinationPort uint32) *Tunnel

NewTunnel is a constructor for the tunnel struct. It takes in id, direction, listenIP, lisetnPort, destinationIP, and destinationPort as parameters.

func (*Tunnel) AddConnection

func (t *Tunnel) AddConnection(c *Connection)

Addconnection will generate an ID for the connection and add it to the map.

func (*Tunnel) AddListener

func (t *Tunnel) AddListener(clientID string) bool

AddListener will start a tcp listener on a specific port and forward all accepted TCP connections to the associated tunnel.

func (*Tunnel) GetConnection

func (t *Tunnel) GetConnection(connID string) *Connection

GetConnection will return a Connection object with the given connection id

func (*Tunnel) GetConnections

func (t *Tunnel) GetConnections() map[string]*Connection

GetConnections will return the connection map

func (*Tunnel) GetControlStream

func (t *Tunnel) GetControlStream() TunnelControlStream

GetControlStream will return the control stream for the associated tunnel

func (*Tunnel) GetDestinationIP

func (t *Tunnel) GetDestinationIP() net.IP

GetDestinationIP gets the destination IP of the tunnel.

func (*Tunnel) GetDestinationPort

func (t *Tunnel) GetDestinationPort() uint32

GetDestinationPort gets the destination port of the tunnel.

func (*Tunnel) GetDirection

func (t *Tunnel) GetDirection() uint32

GetDirection gets the direction of the tunnel (forward or reverse)

func (*Tunnel) GetListenIP

func (t *Tunnel) GetListenIP() net.IP

GetListenIP gets the ip address that the tunnel is listening on.

func (*Tunnel) GetListenPort

func (t *Tunnel) GetListenPort() uint32

GetListenPort gets the port that the tunnel is listening on.

func (*Tunnel) RemoveConnection

func (t *Tunnel) RemoveConnection(connID string)

RemoveConnection will remove the Connection object from the connections map.

func (*Tunnel) SetControlStream

func (t *Tunnel) SetControlStream(s TunnelControlStream)

SetControlStream will set the provided control stream for the associated tunnel

func (*Tunnel) Start

func (t *Tunnel) Start()

Start receiving control messages for the tunnel

func (*Tunnel) Stop

func (t *Tunnel) Stop()

Stop will stop all associated goroutines for the tunnel and disconnect any associated TCP connections

type TunnelControlStream

type TunnelControlStream interface {
	Send(*cs.TunnelControlMessage) error
	Recv() (*cs.TunnelControlMessage, error)
}

Jump to

Keyboard shortcuts

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