// Package conn owns SSH connections: dialing with a bounded handshake, // host-key verification, authentication, keepalive, reconnect, remote exec // and a reference-counted pool. Nothing outside the Pool closes a // connection. package conn import ( "context" "crypto/sha256" "encoding/base64" "golang.org/x/crypto/ssh" "vcom/internal/ssh/sshconfig" ) // Endpoint is the resolved host to dial. type Endpoint = sshconfig.Endpoint // HostIdentity identifies a server host key. type HostIdentity struct { KeyType string // e.g. "ssh-ed25519" FingerprintSHA256 string // "SHA256:..." as printed by ssh-keygen -l } // IdentityOf returns the identity of a public key. func IdentityOf(k ssh.PublicKey) HostIdentity { sum := sha256.Sum256(k.Marshal()) return HostIdentity{ KeyType: k.Type(), FingerprintSHA256: "SHA256:" + base64.RawStdEncoding.EncodeToString(sum[:]), } } // HostKeyDecision is the answer to an unknown or changed host key. type HostKeyDecision uint8 const ( Reject HostKeyDecision = iota // refuse to connect AcceptOnce // trust for this process only AcceptAndSave // trust and append to known_hosts ) // Prompter asks the user. The UI implements it via jobs.Ask; every method // must return promptly when ctx is cancelled. A nil Prompter rejects unknown // host keys and offers no interactive authentication. type Prompter interface { // HostKey is called for a key that is not in known_hosts. changed is // true when known_hosts has a different key of the same type (possible // MITM); known lists the keys known_hosts has for the host. HostKey(ctx context.Context, ep Endpoint, id HostIdentity, known []HostIdentity, changed bool) (HostKeyDecision, error) Password(ctx context.Context, ep Endpoint) (string, error) KeyboardInteractive(ctx context.Context, ep Endpoint, instruction string, questions []string, echo []bool) ([]string, error) Passphrase(ctx context.Context, keyPath string) ([]byte, error) }