keystore

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 8 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 keystore generates and fingerprints SSH keys by shelling out to ssh-keygen. Generation is non-destructive by default (an existing private key is never clobbered) and perms are set on create.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GenResult

type GenResult struct {
	Path        string
	Fingerprint string
	Created     bool
	// Type and Comment are what ssh-keygen was actually run with, set when
	// Created. They differ from the request only for a hardware *-sk type that
	// fell back to software (Fallback), so callers record the key that exists
	// rather than the one asked for.
	Type     string
	Comment  string
	Fallback bool
}

GenResult is the outcome of Generate. Created is false when the key already existed (an idempotent re-run).

type KeyStore

type KeyStore struct{}

KeyStore mints and inspects keys.

func New

func New() *KeyStore

New returns a KeyStore.

func (*KeyStore) Fingerprint

func (k *KeyStore) Fingerprint(path string) (string, error)

Fingerprint returns the SHA256:... fingerprint of a public or private key.

func (*KeyStore) Generate

func (k *KeyStore) Generate(privPath, keyType, comment, passphrase string, overwrite bool) (GenResult, error)

Generate mints a keypair at privPath. Idempotent and non-destructive by default (an existing key is kept and its fingerprint returned); with overwrite the old pair is replaced (callers MUST have snapshotted ~/.ssh). A hardware *-sk type falls back to its software equivalent when no FIDO2 device is present.

func (*KeyStore) PublicFromPrivate

func (k *KeyStore) PublicFromPrivate(privPath string) (pub string, encrypted bool, err error)

PublicFromPrivate derives the public key from the private key material (ssh-keygen -y) - the only way to prove a keypair matches. It returns the public line (empty if it could not be derived) and whether the key is encrypted: empty + encrypted=true means a valid passphrase-protected key, empty + encrypted=false means an invalid/unreadable private key. err is non-nil only if ssh-keygen is absent.

Jump to

Keyboard shortcuts

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