Documentation
¶
Overview ¶
Package sshtest is an SSH server in process, for SSHYard's tests and its development server (cmd/devsshd): password and public-key auth (one key, or an authorized_keys file checked as OpenSSH's StrictModes does), a PTY shell (a toy line shell, or a real one through Shell), keepalive replies, the sftp subsystem of github.com/pkg/sftp, exec requests, and TCP forwarding both ways (direct-tcpip channels, tcpip-forward requests).
Index ¶
- func LineShell(ch ssh.Channel, pty PTY, resize <-chan PTY) int
- func NewHostKey() ssh.Signer
- func ShellExec(dir string) func(ch ssh.Channel, cmd string) int
- type FakeEntry
- type FakeFS
- func (f *FakeFS) Conn(rw io.ReadWriteCloser) io.ReadWriteCloser
- func (f *FakeFS) File(p string) []byte
- func (f *FakeFS) Filecmd(r *sftp.Request) error
- func (f *FakeFS) Filelist(r *sftp.Request) (sftp.ListerAt, error)
- func (f *FakeFS) Fileread(r *sftp.Request) (io.ReaderAt, error)
- func (f *FakeFS) Filewrite(r *sftp.Request) (io.WriterAt, error)
- func (f *FakeFS) Handlers() sftp.Handlers
- func (f *FakeFS) Listed() int
- func (f *FakeFS) Names() []string
- func (f *FakeFS) RealPath(p string) (string, error)
- func (f *FakeFS) Resume()
- func (f *FakeFS) Seen() []string
- func (f *FakeFS) Stop()
- type PTY
- type Server
- type Shell
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type FakeFS ¶
type FakeFS struct {
Dirs map[string][]FakeEntry
Files map[string][]byte
Writes map[string][]byte
// List, when set, lists the folders Dirs does not have.
List func(p string) ([]FakeEntry, bool)
// Real, when set, answers realpath requests.
Real func(p string) string
// Lists counts listing requests.
Lists int
// Listing, when set, is told of each folder whose names are about to
// be sent, each time (after the folder was opened).
Listing func(p string)
// Many, when set, gives folders of n files ("f0000000" on) the others
// do not have, made as they are listed.
Many func(p string) (n int, ok bool)
// Served counts the entries listings have sent.
Served atomic.Int64
// contains filtered or unexported fields
}
FakeFS is an sftp server (Server.SFTPHandlers) that lists what it is told to, names included, as a hostile or broken server may: Dirs maps a folder's path to its listing, Files a file's path to what reading it gives. Writes keep what was written, by path.
func (*FakeFS) Conn ¶
func (f *FakeFS) Conn(rw io.ReadWriteCloser) io.ReadWriteCloser
Conn is the server's side of a session (Server.SFTPConn): while the server is stopped, no reply goes out, whatever the request.
func (*FakeFS) Resume ¶
func (f *FakeFS) Resume()
Resume answers again, the requests that waited first.
type Server ¶
type Server struct {
Addr string
User string
Password string
// AuthorizedKey, when set, may log in too.
AuthorizedKey ssh.PublicKey
// AuthorizedKeysFile, when set, is read at each public-key attempt;
// any key in it may log in. As with OpenSSH's StrictModes, it is
// ignored when it or its directory is writable by group or others.
AuthorizedKeysFile string
// TrustedCA, when set, signs the user certificates that may log in,
// as OpenSSH's TrustedUserCAKeys: valid now, naming User.
TrustedCA ssh.PublicKey
// DirectTCPIP lets clients open direct-tcpip channels (ssh -L, -D,
// jump hosts); TCPIPForward lets them ask for remote listeners
// (ssh -R).
DirectTCPIP, TCPIPForward bool
// Exec runs "exec" requests; nil refuses them.
Exec func(ch ssh.Channel, cmd string) int
// RefuseEnv refuses "env" requests, as a server whose AcceptEnv does
// not name the variable.
RefuseEnv bool
// IgnoreEnv leaves "env" requests unanswered, as warpgate does;
// IgnoreShell leaves "shell" requests unanswered, as a server that
// never starts the shell.
IgnoreEnv, IgnoreShell bool
// ExecPTY runs "exec" requests on a channel that asked for a PTY
// first (ssh -t host cmd); nil leaves them to Exec.
ExecPTY func(ch ssh.Channel, cmd string, pty PTY, resize <-chan PTY) int
HostKey ssh.Signer
// SFTPRoot is the working directory of the sftp subsystem.
SFTPRoot string
// NoSFTP refuses the sftp subsystem, as a server without one.
NoSFTP bool
// SFTPExit, when set, takes the sftp subsystem and ends it at once
// with that status, as a server whose sftp-server is missing (127).
SFTPExit int
// SFTPHandlers, when set, serves the sftp subsystem instead, with
// handlers it makes for each session (a fake or hostile server).
SFTPHandlers func() sftp.Handlers
// SFTPConn, when set, stands between SFTPHandlers' server and its
// channel (FakeFS.Conn: a server that stops answering).
SFTPConn func(io.ReadWriteCloser) io.ReadWriteCloser
// Shell runs sessions; nil is the toy line shell.
Shell Shell
// Mute stops replies to keepalives, as a server that hangs does.
Mute atomic.Bool
// contains filtered or unexported fields
}
Server is an SSH server on a loopback port.
func StartWithKey ¶
StartWithKey is Start with a given host key.
func (*Server) Drop ¶
func (s *Server) Drop()
Drop cuts every connection, as a network failure does.
func (*Server) SetKeyboardInteractive ¶ added in v1.1.0
func (s *Server) SetKeyboardInteractive(fn func(m ssh.ConnMetadata, client ssh.KeyboardInteractiveChallenge) (*ssh.Permissions, error))
SetKeyboardInteractive logs in by keyboard-interactive questions with fn, as a server asking a one-time password does.