easyssh

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

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

Go to latest
Published: Aug 21, 2016 License: MIT Imports: 11 Imported by: 0

README

EasySSH

Easier ssh server wrapper, net/http-style.

Work-in-progress

Disclaimer

I make no guarantees this is secure, or that your usage of it will be secure. Use at your own risk.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ServerContextKey is a context key. It can be used in handlers with
	// context.WithValue to access the server that started the handler. The
	// associated value will be of type *Server.
	ServerContextKey = &contextKey{"http-server"}

	// LocalAddrContextKey is a context key. It can be used in handlers with
	// context.WithValue to access the address the local address the connection
	// arrived on. The associated value will be of type net.Addr.
	LocalAddrContextKey = &contextKey{"local-addr"}

	// ErrServerHasNoHostKeys is returned when you try to start a server without adding any host keys
	ErrServerHasNoHostKeys = errors.New("server has no host keys")
)
View Source
var DefaultHandler = HandlerFunc(func(p *Permissions, c Channel, r <-chan *Request) {
	ssh.DiscardRequests(unwrapRequests(r))
})

Functions

func PublicConfig

func PublicConfig() *ssh.ServerConfig

Types

type Channel

type Channel struct {
	ssh.Channel
	// contains filtered or unexported fields
}

type ConnState

type ConnState int

A ConnState represents the state of a client connection to a server. It's used by the optional Server.ConnState hook.

const (
	// StateNew represents a new connection that has newly connected. Connections
	// begin at this state and then transition to either StateActive or
	// StateClosed.
	StateNew ConnState = iota

	// StateHandshake represents a connection that is currently performing the
	// handshake.
	StateHandshake

	// StateActive represents a connection that has read 1 or more
	// bytes of a request.
	StateActive

	// StateClosed represents a closed connection.
	// This is a terminal state.
	StateClosed
)

func (ConnState) String

func (s ConnState) String() string

type Handler

type Handler interface {
	ServeSSH(*Permissions, Channel, <-chan *Request) // TODO: Finish filling this in
}

Handler handles ssh connections

type HandlerFunc

type HandlerFunc func(*Permissions, Channel, <-chan *Request)

The HandlerFunc type is an adapter to allow the use of ordinary functions as handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler that calls f.

func (HandlerFunc) ServeSSH

func (f HandlerFunc) ServeSSH(p *Permissions, c Channel, r <-chan *Request)

ServeSSH calls f(p, c, r).

type Permissions

type Permissions struct {
	ssh.Permissions
}

type Request

type Request struct {
	ssh.Request
}

type Server

type Server struct {
	Addr    string  // TCP address to listen on, ":ssh" if empty
	Handler Handler // handler to invoke, DefaultHandler if nil

	// ConnState specifies an optional callback function that is
	// called when a client connection changes state. See the
	// ConnState type and associated constants for details.
	ConnState func(net.Conn, ConnState)

	// ErrorLog specifies an optional logger for errors accepting
	// connections and unexpected behavior from handlers.
	// If nil, logging goes to os.Stderr via the log package's
	// standard logger.
	ErrorLog *log.Logger

	// HostKey count to track the number of added host keys.
	//
	// This sucks a bit, but there's no way to get the number of host keys from
	// the ServerConfig directly.
	HostKeyCount int
	*ssh.ServerConfig
}

Server is an SSH server

func (*Server) AddHostKey

func (srv *Server) AddHostKey(r io.Reader) error

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe() error

ListenAndServe listens on the TCP network address srv.Addr and then calls Serve to handle requests on incoming connections. Accepted connections are configured to enable TCP keep-alives. If srv.Addr is blank, ":ssh" is used. ListenAndServe always returns a non-nil error.

func (*Server) Serve

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

Serve accepts incoming connections on the Listener l, creating a new service goroutine for each. The service goroutines read requests and then call srv.Handler to reply to them.

Serve always returns a non-nil error.

Directories

Path Synopsis
A simple public chat server, over ssh.
A simple public chat server, over ssh.

Jump to

Keyboard shortcuts

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