sshd

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2022 License: MIT Imports: 13 Imported by: 3

README

sshd

ssh server

Build Go Report Card GoDoc GitHub license gocover.io

This project is to add protocol support for the sshproxy, or it can be used alone

Usage

API Documentation

Example

  • Support for the Direct TCP IP command
  • Support for the TCP IP Forward command
  • Support for the Direct Stream Local command
  • Support for the Stream Local Forward command
  • Support for the Session command
    • env
    • exec
    • shell

License

Licensed under the MIT License. See LICENSE for the full license text.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiscardRequests added in v0.1.1

func DiscardRequests(logger Logger, in <-chan *ssh.Request)

DiscardRequests consumes and rejects all requests from the passed-in channel.

func FormatPublicKey added in v0.2.0

func FormatPublicKey(pk ssh.PublicKey) string

func GetHostkey added in v0.0.2

func GetHostkey(key string) (ssh.Signer, error)

func IsClosedConnError added in v0.1.1

func IsClosedConnError(err error) bool

IsClosedConnError reports whether err is an error from use of a closed network connection.

func ParseHostkey added in v0.0.2

func ParseHostkey(keyData []byte) (ssh.Signer, error)

func RandomHostkey added in v0.0.2

func RandomHostkey() (ssh.Signer, error)

func RegistryHandleChannel added in v0.1.1

func RegistryHandleChannel(name string, fun HandleChannelFunc)

func RegistryHandleRequest added in v0.1.1

func RegistryHandleRequest(name string, fun HandleRequestFunc)

func Tunnel added in v0.1.1

func Tunnel(ctx context.Context, c1, c2 io.ReadWriteCloser, buf1, buf2 []byte) error

Tunnel create tunnels for two io.ReadWriteCloser

Types

type Authorized added in v0.2.0

type Authorized struct {
	Data map[string]map[string]string
}

func GetAuthorizedFile

func GetAuthorizedFile(authorized string) (*Authorized, error)

func ParseAuthorized

func ParseAuthorized(r io.Reader) (*Authorized, error)

func (*Authorized) Allow added in v0.2.0

func (a *Authorized) Allow(pk ssh.PublicKey) (bool, string)

type BytesPool

type BytesPool interface {
	Get() []byte
	Put([]byte)
}

BytesPool is an interface for getting and returning temporary bytes for use by io.CopyBuffer.

type ChannelOpenDirectMsg

type ChannelOpenDirectMsg struct {
	RAddr string
	RPort uint32
	LAddr string
	LPort uint32
}

ChannelOpenDirectMsg copy from golang.org/x/crypto/ssh.channelOpenDirectMsg

type ExecMsg

type ExecMsg struct {
	Command string
}

ExecMsg copy from golang.org/x/crypto/ssh.execMsg

type ExitStatusMsg

type ExitStatusMsg struct {
	Status uint32
}

ExitStatusMsg copy from golang.org/x/crypto/ssh.exitStatusMsg

type ForwardMsg added in v0.1.1

type ForwardMsg struct {
	LAddr string
	LPort uint32
}

ForwardMsg copy from golang.org/x/crypto/ssh.channelForwardMsg

type ForwardResponseMsg added in v0.1.1

type ForwardResponseMsg struct {
	Port uint32
}

type ForwardedStreamLocalPayload added in v0.1.5

type ForwardedStreamLocalPayload struct {
	SocketPath string
	Reserved0  string
}

ForwardedStreamLocalPayload copy from golang.org/x/crypto/ssh.forwardedStreamLocalPayload

type ForwardedTCPPayload added in v0.1.1

type ForwardedTCPPayload struct {
	Addr       string
	Port       uint32
	OriginAddr string
	OriginPort uint32
}

ForwardedTCPPayload copy from golang.org/x/crypto/ssh.forwardedTCPPayload

type HandleChannelFunc added in v0.1.1

type HandleChannelFunc func(ctx context.Context, newChan ssh.NewChannel, serverConn *ServerConn)

type HandleRequestFunc added in v0.1.1

type HandleRequestFunc func(ctx context.Context, req *ssh.Request, serverConn *ServerConn)

type Logger

type Logger interface {
	Println(v ...interface{})
}

type Permissions added in v0.2.0

type Permissions interface {
	Allow(req string, args string) bool
}

Permissions specifies the permissions that the user has

type PtyRequestMsg

type PtyRequestMsg struct {
	Term     string
	Columns  uint32
	Rows     uint32
	Width    uint32
	Height   uint32
	Modelist string
}

PtyRequestMsg copy from golang.org/x/crypto/ssh.ptyRequestMsg

type PtyWindowChangeMsg

type PtyWindowChangeMsg struct {
	Columns uint32
	Rows    uint32
	Width   uint32
	Height  uint32
}

PtyWindowChangeMsg copy from golang.org/x/crypto/ssh.ptyWindowChangeMsg

type Server

type Server struct {
	// Context is default context
	Context context.Context
	// ServerConfig SSH Server config
	ServerConfig ssh.ServerConfig
	// Logger error log
	Logger Logger
	// ProxyDial specifies the optional proxyDial function for
	// establishing the transport connection.
	ProxyDial func(context.Context, string, string) (net.Conn, error)
	// ProxyListen specifies the optional proxyListen function for
	// establishing the transport connection.
	ProxyListen func(context.Context, string, string) (net.Listener, error)
	// UserPermissions are based on the user getting all their permissions
	// If nil, then allow all
	UserPermissions func(user string) Permissions
	// BytesPool getting and returning temporary bytes for use by io.CopyBuffer
	BytesPool BytesPool
	// Default environment
	Environ []string
	// Default workdir
	Dir string
}

Server is accepting connections and handling the details of the SSH protocol

func NewServer

func NewServer() *Server

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(network, addr string) error

ListenAndServe is used to create a listener and serve on it

func (*Server) Serve

func (s *Server) Serve(l net.Listener) error

Serve is used to serve connections from a listener

func (*Server) ServeConn

func (s *Server) ServeConn(conn net.Conn)

ServeConn is used to serve a single connection.

type ServerConn

type ServerConn struct {
	*ssh.ServerConn
	// BytesPool getting and returning temporary bytes for use by io.CopyBuffer
	BytesPool BytesPool
	// Logger error log
	Logger Logger
	// Newly Request
	Requests <-chan *ssh.Request
	// Newly channel
	Channels <-chan ssh.NewChannel
	// ProxyDial specifies the optional proxyDial function for
	// establishing the transport connection.
	ProxyDial func(context.Context, string, string) (net.Conn, error)
	// ProxyListen specifies the optional proxyListen function for
	// establishing the transport connection.
	ProxyListen func(context.Context, string, string) (net.Listener, error)
	// Default environment
	Environ []string
	// Default workdir
	Dir string
	// Permissions specify the permissions that the user has
	// If nil, then allow all
	Permissions Permissions
}

ServerConn Handling for a single incoming connection

func NewServerConn

func NewServerConn(conn net.Conn, config *ssh.ServerConfig) (*ServerConn, error)

func (*ServerConn) Handle

func (s *ServerConn) Handle(ctx context.Context)

Handle a single established connection

type SetenvRequest

type SetenvRequest struct {
	Name  string
	Value string
}

SetenvRequest copy from golang.org/x/crypto/ssh.setenvRequest

type StreamLocalChannelForwardMsg added in v0.1.5

type StreamLocalChannelForwardMsg struct {
	SocketPath string
}

StreamLocalChannelForwardMsg copy from golang.org/x/crypto/ssh.streamLocalChannelForwardMsg

type StreamLocalChannelOpenDirectMsg added in v0.1.5

type StreamLocalChannelOpenDirectMsg struct {
	SocketPath string
	Reserved0  string
	Reserved1  uint32
}

StreamLocalChannelOpenDirectMsg copy from golang.org/x/crypto/ssh.streamLocalChannelOpenDirectMsg

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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