ssh

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

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

Go to latest
Published: Jul 9, 2020 License: MIT Imports: 21 Imported by: 0

README

go-ssh

Hello! This is a passionate rewrite of gilderlabs/ssh.

I'm terrible about writing documentation, so please, please help me 🙏.

Documentation

Index

Constants

View Source
const (
	SIGABRT = Signal(ssh.SIGABRT)
	SIGALRM = Signal(ssh.SIGALRM)
	SIGFPE  = Signal(ssh.SIGFPE)
	SIGHUP  = Signal(ssh.SIGHUP)
	SIGILL  = Signal(ssh.SIGILL)
	SIGKILL = Signal(ssh.SIGKILL)
	SIGPIPE = Signal(ssh.SIGPIPE)
	SIGQUIT = Signal(ssh.SIGQUIT)
	SIGSEGV = Signal(ssh.SIGSEGV)
	SIGTERM = Signal(ssh.SIGTERM)
	SIGUSR1 = Signal(ssh.SIGUSR1)
	SIGUSR2 = Signal(ssh.SIGUSR2)
)

Variables

View Source
var (
	ContextKeySessionID     = &contextKey{"session-id"}
	ContextKeyClientVersion = &contextKey{"client-version"}
	ContextKeyServerVersion = &contextKey{"server-version"}
	ContextKeyUser          = &contextKey{"user"}
	ContextKeyLocalAddr     = &contextKey{"local-addr"}
	ContextKeyRemoteAddr    = &contextKey{"remote-addr"}
	ContextKeyPermissions   = &contextKey{"permissions"}
	ContextKeyLogger        = &contextKey{"logger"}

	ContextKeyServer    = &contextKey{"ssh-server"}
	ContextKeyConn      = &contextKey{"ssh-conn"}
	ContextKeyPublicKey = &contextKey{"public-key"}
)
View Source
var (
	ErrServerClosed     = errors.New("server closed")
	ErrPermissionDenied = errors.New("permission denied")
)

Functions

func AgentRequested

func AgentRequested(sess Session) bool

func ForwardAgentConnections

func ForwardAgentConnections(l net.Listener, s Session)

func Handle

func Handle(handler Handler)

func KeysEqual

func KeysEqual(ak, bk PublicKey) bool

func ListenAndServe

func ListenAndServe(addr string, handler Handler, options ...Option) error

func NewAgentListener

func NewAgentListener() (net.Listener, error)

func Serve

func Serve(l net.Listener, handler Handler, options ...Option) error

func SetAgentRequested

func SetAgentRequested(ctx Context)

Types

type ChannelHandler

type ChannelHandler interface {
	HandleChannel(ctx Context, srv *Server, conn *ssh.ServerConn, newChan ssh.NewChannel)
}

type ConnCallback

type ConnCallback func(conn net.Conn) net.Conn

type Context

type Context interface {
	context.Context
	sync.Locker

	SetValue(key, value interface{})
	SessionID() string
	ClientVersion() string
	ServerVersion() string
	User() string
	LocalAddr() net.Addr
	RemoteAddr() net.Addr
	Permissions() *Permissions
	Logger() Logger
}

type DefaultServerConfigCallback

type DefaultServerConfigCallback func(ctx Context) *ssh.ServerConfig

type DirectTcpIpHandler

type DirectTcpIpHandler struct {
	net.Dialer
}

func (*DirectTcpIpHandler) HandleChannel

func (h *DirectTcpIpHandler) HandleChannel(ctx Context, srv *Server, conn *ssh.ServerConn, newChan ssh.NewChannel)

type Handler

type Handler func(Session)
var DefaultHandler Handler

type KeyboardInteractiveHandler

type KeyboardInteractiveHandler func(ctx Context, challenger ssh.KeyboardInteractiveChallenge) bool

type LocalPortForwardingCallback

type LocalPortForwardingCallback func(ctx Context, destinationHost string, destinationPort uint32) bool

type Logger

type Logger interface {
	logrus.Ext1FieldLogger
}

type Option

type Option func(*Server) error

func HostKeyFile

func HostKeyFile(filepath string) Option

func HostKeyPEM

func HostKeyPEM(bytes []byte) Option

func NoPty

func NoPty() Option

func PasswordAuth

func PasswordAuth(fn PasswordHandler) Option

func PublicKeyAuth

func PublicKeyAuth(fn PublicKeyHandler) Option

func WrapConn

func WrapConn(fn ConnCallback) Option

type PasswordHandler

type PasswordHandler func(ctx Context, password string) bool

type Permissions

type Permissions struct {
	*ssh.Permissions
}

type Pty

type Pty struct {
	Term   string
	Window Window
	Modes  []byte
}

type PtyCallback

type PtyCallback func(ctx Context, pty Pty) bool

type PublicKey

type PublicKey interface {
	ssh.PublicKey
}

func ParseAuthorizedKey

func ParseAuthorizedKey(in []byte) (out PublicKey, comment string, options []string, rest []byte, err error)

func ParsePublicKey

func ParsePublicKey(in []byte) (out PublicKey, err error)

type PublicKeyHandler

type PublicKeyHandler func(ctx Context, key PublicKey) bool

type RequestHandler

type RequestHandler interface {
	HandleRequest(ctx Context, srv *Server, req *ssh.Request) (ok bool, payload []byte)
}

type ReversePortForwardingCallback

type ReversePortForwardingCallback func(ctx Context, bindHost string, bindPort uint32) bool

type Server

type Server struct {
	Addr        string
	Handler     Handler
	HostSigners []Signer
	Version     string
	Logger      Logger

	KeyboardInteractiveHandler    KeyboardInteractiveHandler
	PasswordHandler               PasswordHandler
	PublicKeyHandler              PublicKeyHandler
	PtyCallback                   PtyCallback
	ConnCallback                  ConnCallback
	LocalPortForwardingCallback   LocalPortForwardingCallback
	ReversePortForwardingCallback ReversePortForwardingCallback
	DefaultServerConfigCallback   DefaultServerConfigCallback
	SessionRequestCallback        SessionRequestCallback
	IdleTimeout                   time.Duration
	MaxTimeout                    time.Duration
	ChannelHandlers               map[string]ChannelHandler
	RequestHandlers               map[string]RequestHandler
	// contains filtered or unexported fields
}

func (*Server) AddHostKey

func (srv *Server) AddHostKey(key Signer)

func (*Server) Close

func (srv *Server) Close() error

func (*Server) Debug

func (srv *Server) Debug(args ...interface{})

func (*Server) Debugf

func (srv *Server) Debugf(format string, args ...interface{})

func (*Server) Debugln

func (srv *Server) Debugln(args ...interface{})

func (*Server) Error

func (srv *Server) Error(args ...interface{})

func (*Server) Errorf

func (srv *Server) Errorf(format string, args ...interface{})

func (*Server) Errorln

func (srv *Server) Errorln(args ...interface{})

func (*Server) Fatal

func (srv *Server) Fatal(args ...interface{})

func (*Server) Fatalf

func (srv *Server) Fatalf(format string, args ...interface{})

func (*Server) Fatalln

func (srv *Server) Fatalln(args ...interface{})

func (*Server) Handle

func (srv *Server) Handle(fn Handler)

func (*Server) Info

func (srv *Server) Info(args ...interface{})

func (*Server) Infof

func (srv *Server) Infof(format string, args ...interface{})

func (*Server) Infoln

func (srv *Server) Infoln(args ...interface{})

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe() error

func (*Server) Panic

func (srv *Server) Panic(args ...interface{})

func (*Server) Panicf

func (srv *Server) Panicf(format string, args ...interface{})

func (*Server) Panicln

func (srv *Server) Panicln(args ...interface{})

func (*Server) Print

func (srv *Server) Print(args ...interface{})

func (*Server) Printf

func (srv *Server) Printf(format string, args ...interface{})

func (*Server) Println

func (srv *Server) Println(args ...interface{})

func (*Server) Serve

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

func (*Server) SetOption

func (srv *Server) SetOption(option Option) error

func (*Server) Shutdown

func (srv *Server) Shutdown(ctx context.Context) error

func (*Server) Trace

func (srv *Server) Trace(args ...interface{})

func (*Server) Tracef

func (srv *Server) Tracef(format string, args ...interface{})

func (*Server) Traceln

func (srv *Server) Traceln(args ...interface{})

func (*Server) Warn

func (srv *Server) Warn(args ...interface{})

func (*Server) Warnf

func (srv *Server) Warnf(format string, args ...interface{})

func (*Server) Warning

func (srv *Server) Warning(args ...interface{})

func (*Server) Warningf

func (srv *Server) Warningf(format string, args ...interface{})

func (*Server) Warningln

func (srv *Server) Warningln(args ...interface{})

func (*Server) Warnln

func (srv *Server) Warnln(args ...interface{})

func (*Server) WithError

func (srv *Server) WithError(err error) *logrus.Entry

func (*Server) WithField

func (srv *Server) WithField(key string, value interface{}) *logrus.Entry

func (*Server) WithFields

func (srv *Server) WithFields(fields logrus.Fields) *logrus.Entry

type Session

type Session interface {
	ssh.Channel

	Logger() Logger
	User() string
	RemoteAddr() net.Addr
	LocalAddr() net.Addr
	Environ() []string
	Exit(code int) error
	ExitSignal(signal os.Signal, coreDumped bool, message, languageTag string) error
	Command() []string
	PublicKey() PublicKey
	Context() context.Context
	Permissions() Permissions
	Pty() (Pty, <-chan Window, bool)

	Notify(c chan<- Signal, sig ...Signal)
	Reset(sig ...Signal)
	Stop(c chan<- Signal)
}

type SessionHandler

type SessionHandler struct{}

func (SessionHandler) HandleChannel

func (SessionHandler) HandleChannel(ctx Context, srv *Server, conn *ssh.ServerConn, newChan ssh.NewChannel)

type SessionRequestCallback

type SessionRequestCallback func(sess Session, requestType string) bool

type Signal

type Signal ssh.Signal

func NewSignal

func NewSignal(sig os.Signal) Signal

func (Signal) OSSignal

func (s Signal) OSSignal() os.Signal

type Signer

type Signer interface {
	ssh.Signer
}

func NewSignerFromKey

func NewSignerFromKey(key interface{}) (Signer, error)

func NewSignerFromSigner

func NewSignerFromSigner(signer crypto.Signer) (Signer, error)

type Window

type Window struct {
	Cols   uint32
	Rows   uint32
	Width  uint32
	Height uint32
}

Directories

Path Synopsis
cmd
Code generated by counterfeiter.
Code generated by counterfeiter.
net_fakes
Code generated by counterfeiter.
Code generated by counterfeiter.
ssh_fakes
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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