client

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package client is the public Go API for embedding opskat capabilities into other binaries (mobile clients via gomobile, future SDK consumers, etc.).

Anything mobile-specific (gomobile bind targets, Dart-bridge debug helpers) belongs in the opskat-mobile repository, not here.

Index

Constants

This section is empty.

Variables

View Source
var ErrHostKeyMismatch = errors.New("client: host key mismatch")

ErrHostKeyMismatch is returned when a stored host key does not match the key offered by the server. This is a hard failure — the connection MUST be aborted.

View Source
var ErrHostKeyNotFound = errors.New("client: host key not in known_hosts")

ErrHostKeyNotFound is returned by KnownHosts.Lookup when the host has not been seen before. Callers MUST treat this as "ask the user" (TOFU prompt), not as "connect anyway".

Functions

func Version

func Version() string

Version returns the opskat build's version string.

Types

type HostKeyDecision

type HostKeyDecision int

HostKeyDecision tells Dial what to do when KnownHosts has no record for the target host. Returning Accept saves the key (TOFU) and continues; Reject aborts the dial.

const (
	HostKeyReject HostKeyDecision = iota
	HostKeyAccept
)

type HostKeyPrompt

type HostKeyPrompt func(host string, port int, fingerprint string) HostKeyDecision

HostKeyPrompt is invoked exactly once per Dial when the remote presents a key not in KnownHosts. Implementations are expected to surface the fingerprint to the human operator (TOFU prompt) and return their decision.

fingerprint is the SHA-256 fingerprint string ("SHA256:..."), suitable for display alongside what the user would see from `ssh -o VisualHostKey=no`.

type KnownHosts

type KnownHosts interface {
	// Lookup returns the stored key for the given host:port, or
	// ErrHostKeyNotFound if no entry exists. The returned slice is the raw
	// SSH wire-format public key (ssh.PublicKey.Marshal()), not the base64
	// authorized_keys form.
	Lookup(host string, port int) ([]byte, error)

	// Save records the host key as accepted. Overwrites any existing entry
	// for the same host:port — callers should only call this after the user
	// has explicitly approved the fingerprint.
	Save(host string, port int, publicKey []byte) error
}

KnownHosts persists previously-accepted SSH host public keys for trust-on- first-use (TOFU) verification. Implementations are caller-supplied: the desktop uses an on-disk known_hosts file, the mobile client stores entries in SQLite. Implementations MUST be safe for concurrent use.

func NewInMemoryKnownHosts

func NewInMemoryKnownHosts() KnownHosts

NewInMemoryKnownHosts returns an in-memory KnownHosts. Suitable for tests and for the mobile bridge's first iteration before SQLite is wired up. Entries are lost on process restart.

type SSHConfig

type SSHConfig struct {
	Host string
	Port int
	User string

	Password             string
	PrivateKey           []byte // PEM-encoded; empty when using password auth
	PrivateKeyPassphrase []byte // optional, only used with PrivateKey

	// DialTimeout caps the TCP dial + SSH handshake. Zero uses 15s.
	DialTimeout time.Duration
}

SSHConfig is the connection input. Exactly one of Password or PrivateKey must be non-empty; supplying both is an error to prevent accidental fallbacks that hide credential mistakes.

type Session

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

Session is an established SSH connection. It is not safe for concurrent Run calls — the typical use is one session per logical "shell" the user opened.

func Dial

func Dial(ctx context.Context, cfg SSHConfig, hostKeys KnownHosts, prompt HostKeyPrompt) (*Session, error)

Dial opens an SSH connection. If the server's host key is unknown to hostKeys, prompt is invoked; if prompt approves, the key is persisted via hostKeys.Save before authentication proceeds.

hostKeys and prompt are both required: nil hostKeys would silently disable MITM protection, nil prompt would deadlock TOFU.

func (*Session) Close

func (s *Session) Close() error

Close shuts down the SSH client. Subsequent Run calls will fail.

func (*Session) Run

func (s *Session) Run(ctx context.Context, cmd string, stdout, stderr io.Writer) (int, error)

Run executes cmd remotely, streaming stdout/stderr to the supplied writers. Returns the remote exit code (0 on success, non-zero from *ssh.ExitError, or -1 for transport-level errors).

Jump to

Keyboard shortcuts

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