sshd

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2020 License: MIT Imports: 16 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSessionChannel = errors.New("no session channel")

ErrNoSessionChannel is returned when there is no session channel.

View Source
var ErrNotSessionChannel = errors.New("terminal requires session channel")

ErrNotSessionChannel is returned when a channel is not a session channel.

Functions

func ConnectShell

func ConnectShell(host string, name string, handler func(r io.Reader, w io.WriteCloser) error) error

ConnectShell makes a barebones SSH client session, used for testing.

func Fingerprint

func Fingerprint(k ssh.PublicKey) string

Fingerprint performs a SHA256 BASE64 fingerprint of the PublicKey, similar to OpenSSH. See: https://anongit.mindrot.org/openssh.git/commit/?id=56d1c83cdd1ac

func MakeAuth

func MakeAuth(auth Auth) *ssh.ServerConfig

MakeAuth makes an ssh.ServerConfig which performs authentication against an Auth implementation. TODO: Switch to using ssh.AuthMethod instead?

func MakeNoAuth

func MakeNoAuth() *ssh.ServerConfig

MakeNoAuth makes a simple ssh.ServerConfig which allows all connections. Primarily used for testing.

func NewClientConfig

func NewClientConfig(name string) *ssh.ClientConfig

NewClientConfig creates a barebones ssh.ClientConfig to be used with ssh.Dial.

func NewInputLimiter

func NewInputLimiter() rateio.Limiter

NewInputLimiter returns a rateio.Limiter with sensible defaults for differentiating between humans typing and bots spamming.

func NewRandomSigner

func NewRandomSigner(bits int) (ssh.Signer, error)

NewRandomSigner generates a random key of a desired bit length.

func ReadLimitConn

func ReadLimitConn(conn net.Conn, limiter rateio.Limiter) net.Conn

ReadLimitConn returns a net.Conn whose io.Reader interface is rate-limited by limiter.

func SetLogger

func SetLogger(w io.Writer)

SetLogger sets the package logging output to use w.

Types

type Auth

type Auth interface {
	// Whether to allow connections without a public key.
	AllowAnonymous() bool
	// Given address and public key and client agent string, returns nil if the connection should be allowed.
	Check(net.Addr, ssh.PublicKey, string) error
}

Auth is used to authenticate connections based on public keys.

type Connection

type Connection interface {
	PublicKey() ssh.PublicKey
	RemoteAddr() net.Addr
	Name() string
	ClientVersion() []byte
	Close() error
}

Connection is an interface with fields necessary to operate an sshd host.

type Env added in v1.10.1

type Env []EnvVar

Env is a wrapper type around []EnvVar with some helper methods

func (Env) Get added in v1.10.1

func (e Env) Get(key string) string

Get returns the latest value for a given key, or empty string if not found

type EnvVar added in v1.10.1

type EnvVar struct {
	Key   string
	Value string
}

EnvVar is an environment variable key-value pair

func (EnvVar) String added in v1.10.1

func (v EnvVar) String() string

type SSHListener

type SSHListener struct {
	net.Listener

	RateLimit   func() rateio.Limiter
	HandlerFunc func(term *Terminal)
	// contains filtered or unexported fields
}

SSHListener is the container for the connection and ssh-related configuration

func ListenSSH

func ListenSSH(laddr string, config *ssh.ServerConfig) (*SSHListener, error)

ListenSSH makes an SSH listener socket

func (*SSHListener) Serve

func (l *SSHListener) Serve()

Serve Accepts incoming connections as terminal requests and yield them

type Terminal

type Terminal struct {
	terminal.Terminal
	Conn    Connection
	Channel ssh.Channel
	// contains filtered or unexported fields
}

Terminal extends ssh/terminal to include a close method

func NewSession

func NewSession(conn *ssh.ServerConn, channels <-chan ssh.NewChannel) (*Terminal, error)

NewSession Finds a session channel and make a Terminal from it

func NewTerminal

func NewTerminal(conn *ssh.ServerConn, ch ssh.NewChannel) (*Terminal, error)

Make new terminal from a session channel TODO: For v2, make a separate `Serve(ctx context.Context) error` method to activate the Terminal

func (*Terminal) Close

func (t *Terminal) Close() error

Close terminal and ssh connection

func (*Terminal) Env added in v1.10.1

func (t *Terminal) Env() Env

Env returns a list of environment key-values that have been set. They are returned in the order that they have been set, there is no deduplication or other pre-processing applied.

func (*Terminal) Term added in v1.10.1

func (t *Terminal) Term() string

Term returns the terminal string value as set by the pty. If there was no pty request, it falls back to the TERM value passed in as an Env variable.

Directories

Path Synopsis
Package terminal provides support functions for dealing with terminals, as commonly found on UNIX systems.
Package terminal provides support functions for dealing with terminals, as commonly found on UNIX systems.

Jump to

Keyboard shortcuts

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