sshserver

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandHandler added in v0.2.8

type CommandHandler func(ctx context.Context, sess ssh.Session, args []string) int

CommandHandler runs one session in-process instead of spawning a process. args are the argv the client sent after the command name, and the returned code is the session's exit status. sess carries the channel's stdio, and its context is canceled when the client goes away — a handler that blocks must select on it or on a read returning EOF.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server wraps an internal SSH server.

func New

func New() *Server

New creates an internal SSH server that communicates in-process via net.Pipe (no TCP port).

func (*Server) BuiltinForTest added in v0.2.8

func (s *Server) BuiltinForTest(name string) CommandHandler

BuiltinForTest exposes builtin to package-external tests, which need to assert what a registration did (or did not) install. It has no production caller.

func (*Server) Dial added in v0.1.0

func (s *Server) Dial() (net.Conn, error)

Dial creates a new in-memory connection to this server. The returned net.Conn is the client side of a net.Pipe(); the server side is handed to the SSH server goroutine for handshake and session handling.

func (*Server) MintClientConfig added in v0.0.4

func (s *Server) MintClientConfig() (*sshstd.ClientConfig, error)

MintClientConfig registers a new one-time username/password and returns a dial config. The entry is removed on the first successful SSH password authentication (single use). Call only after Start().

func (*Server) RegisterCommand added in v0.2.8

func (s *Server) RegisterCommand(name string, h CommandHandler)

RegisterCommand teaches the server a command it serves in-process: a session whose first argv word is name is handed to h instead of being exec'd. It is how the extension layer carries an HTTP MCP server over the in-memory channel without starting a second process, and it is deliberately an explicit registration rather than a name the server knows on its own — the sshserver stays a transport, and the thing being carried stays in the package that owns it.

func (*Server) RevokeClientConfig added in v0.2.0

func (s *Server) RevokeClientConfig(user string)

RevokeClientConfig drops a pending one-time credential minted by MintClientConfig. Call it when the returned config will never complete a successful authentication (dial refused, handshake error), otherwise the entry would stay in the pending map for the lifetime of the process — a memory leak on every failed session start. Revoking a credential that was already consumed is a no-op.

func (*Server) Start

func (s *Server) Start() error

Start begins serving SSH connections on the in-memory listener.

func (*Server) Stop

func (s *Server) Stop() error

Stop shuts down the SSH server.

This does not wait for in-flight session handlers: Close() tears down the connections, which cancels each session's context, and handleSession uses that to kill the child it started. Nothing here needs to join the handlers — the goroutine count comes back down on its own — and a WaitGroup on this path would add an Add/Wait race (a panic, not an error) to satisfy a wait nobody needs.

Jump to

Keyboard shortcuts

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