sshagent

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT, MIT Imports: 27 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sshagent is lys-secrets' SSH agent: it serves the agent protocol for the keys in ~/.ssh that have a .pub beside them and for those added with ssh-add. An encrypted key's passphrase is asked through the desktop's dialog on its first signature, and may be remembered in the login collection, so that signing needs no prompt while it is unlocked. Decrypted keys live in locked memory and are dropped when the login collection locks.

Index

Constants

View Source
const Schema = "dev.stubbe.lys.SshKey"

Schema is the xdg:schema of a remembered passphrase's item in the login collection; its other attributes are the key's fingerprint and path.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

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

Agent is the agent's keys.

func New

func New(dir string, prompter Prompter, passphrases Passphrases) *Agent

New is an agent for the keys in dir (~/.ssh), asking prompter and remembering passphrases in passphrases.

func (*Agent) Add

func (a *Agent) Add(key agent.AddedKey) error

Add holds a key ssh-add sent, in memory only.

func (*Agent) Close

func (a *Agent) Close()

Close drops every key.

func (*Agent) Extension

func (a *Agent) Extension(string, []byte) ([]byte, error)

Extension answers no extension.

func (*Agent) Forget

func (a *Agent) Forget()

Forget drops every decrypted key of ~/.ssh, as the login collection locking does; the next signature asks again or reads the remembered passphrase.

func (*Agent) List

func (a *Agent) List() ([]*agent.Key, error)

List is the keys of ~/.ssh, then those added with ssh-add; none while the agent is locked.

func (*Agent) Lock

func (a *Agent) Lock(passphrase []byte) error

Lock locks the agent with passphrase, as ssh-add -x does.

func (*Agent) Remove

func (a *Agent) Remove(key ssh.PublicKey) error

Remove drops an added key; a key of ~/.ssh stays listed, its decrypted copy dropped.

func (*Agent) RemoveAll

func (a *Agent) RemoveAll() error

RemoveAll drops every added key and every decrypted key of ~/.ssh.

func (*Agent) Serve

func (a *Agent) Serve(ctx context.Context, ln *usersock.Listener)

Serve answers agent requests on ln until ctx ends.

func (*Agent) Sign

func (a *Agent) Sign(key ssh.PublicKey, data []byte) (*ssh.Signature, error)

Sign signs data with key.

func (*Agent) SignWithFlags

func (a *Agent) SignWithFlags(key ssh.PublicKey, data []byte, flags agent.SignatureFlags) (*ssh.Signature, error)

SignWithFlags signs data with key, an RSA key with the SHA-2 algorithm flags ask for.

func (*Agent) Signers

func (a *Agent) Signers() ([]ssh.Signer, error)

Signers is not offered: the agent signs only over its socket.

func (*Agent) Unlock

func (a *Agent) Unlock(passphrase []byte) error

Unlock undoes Lock given the same passphrase.

type Key

type Key struct {
	// Path is the private key's file, "" for a key added with ssh-add.
	Path        string
	Fingerprint string
	Comment     string
}

Key is a key as the dialogs name it.

type Passphrases

type Passphrases interface {
	Lookup(attrs map[string]string) (passphrase []byte, found bool, err error)
	Remember(label string, attrs map[string]string, passphrase []byte) error
}

Passphrases keeps remembered passphrases in the login collection. A locked login collection is an error.

type Prompter

type Prompter interface {
	// KeyPassphrase asks for an encrypted key's passphrase and whether to
	// remember it; ok is false when they dismissed the dialog. retry says
	// the previous attempt was wrong.
	KeyPassphrase(ctx context.Context, k Key, retry bool) (passphrase []byte, remember, ok bool, err error)
	// ConfirmUse asks whether a key added with ssh-add -c may sign.
	ConfirmUse(ctx context.Context, k Key) (bool, error)
}

Prompter asks the user about keys.

Jump to

Keyboard shortcuts

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