sshh

package
v0.0.0-...-49e565d Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2015 License: Apache-2.0, Apache-2.0 Imports: 8 Imported by: 0

README

sshh Build Status Coverage Status

An SSH Handler library which makes it easy to implement SSH servers

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	sync.Mutex

	// Deadline is the maximum time the listener will block
	// between connections. As a consequence, this duration
	// also sets the max length of time the SSH server will
	// be unresponsive before shutting down.
	Deadline time.Duration

	// Handlers is a map of SSHHandlers which process incoming connections. The map
	// consists of channel names as keys and SSHHandlers as the values. If a
	// client connects and creates a channel with a defined SSHHandler, the handler
	// will process all requests on that channel. If a channel is accepted without a
	// defined handler, the channel is closed as well as the connection.
	Handlers map[string]SSHHandler

	// Logger logs errors and debug output for the SSH server.
	Logger log.Logger

	// Bind specifies the Bind address the SSH server will listen on.
	Bind string

	// PrivateKey is added to the SSH config as a host key.
	PrivateKey ssh.Signer

	// AuthLogCallback, if non-nil, is called to log all authentication
	// attempts.
	AuthLogCallback func(conn ssh.ConnMetadata, method string, err error)

	// PasswordCallback, if non-nil, is called when a user
	// attempts to authenticate using a password.
	PasswordCallback func(conn ssh.ConnMetadata, password []byte) (*ssh.Permissions, error)

	// PublicKeyCallback, if non-nil, is called when a client attempts public
	// key authentication. It must return true if the given public key is
	// valid for the given user. For example, see CertChecker.Authenticate.
	PublicKeyCallback func(ssh.ConnMetadata, ssh.PublicKey) (*ssh.Permissions, error)
	// contains filtered or unexported fields
}

Config is used to setup the SSHServer, including the server config and the SSHHandlers.

func (*Config) Handler

func (c *Config) Handler(channel string) (handler SSHHandler, ok bool)

Handler is a helper method for determining if a channel handler has been defined.

func (*Config) SSHConfig

func (c *Config) SSHConfig() *ssh.ServerConfig

SSHConfig returns an SSH server configuration. If the AuthLogCallback is nil at the time this method is called, the default function will be used.

type SSHHandler

type SSHHandler interface {

	// Handle processes SSH connections. The requests chan can be disregarded if it is not needed.
	Handle(t tomb.Tomb, conn *ssh.ServerConn, channel ssh.Channel, requests <-chan *ssh.Request) error
}

A SSHHandler is registered with an SSH server to process incoming connections on a particular channel.

type SSHServer

type SSHServer struct {
	Addr *net.TCPAddr
	// contains filtered or unexported fields
}

SSHServer handles all the incoming connections as well as handler dispatch.

func NewSSHServer

func NewSSHServer(cfg *Config) (server SSHServer, err error)

NewSSHServer creates a new server with the given config. The server will call `cfg.SSHConfig()` to setup the server. If an error occurs it will be returned. If the Bind address is empty or invalid an error will be returned. If there is an error starting the TCP server, the error will be returned.

func (*SSHServer) Start

func (s *SSHServer) Start()

Start starts accepting client connections. This method is non-blocking.

func (*SSHServer) Stop

func (s *SSHServer) Stop() error

Stop stops the server and kills all goroutines. This method is blocking.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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