sshd

package
v0.0.0-...-8103da3 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2017 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSessionChannel = errors.New("no session channel")
View Source
var ErrNotSessionChannel = errors.New("terminal requires 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.

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)

Types

type Auth

type Auth interface {
	// Whether to allow connections without a public key.
	AllowAnonymous() bool
	// Given address and public key, return if the connection should be permitted.
	Check(net.Addr, ssh.PublicKey) (bool, 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 SSHListener

type SSHListener struct {
	net.Listener

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

Container for the connection and ssh-related configuration

func ListenSSH

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

Make an SSH listener socket

func (*SSHListener) Serve

func (l *SSHListener) Serve()

Accept 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
}

Extending ssh/terminal to include a closer interface

func NewSession

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

Find 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

func (*Terminal) Close

func (t *Terminal) Close() error

Close terminal and ssh connection

Jump to

Keyboard shortcuts

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