keys

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: AGPL-3.0 Imports: 25 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 keys reads the private keys a credential can hold: OpenSSH and PEM keys, and PuTTY's .ppk (versions 2 and 3, encrypted or not), which it converts to OpenSSH. It also makes new ed25519 keys. What it returns is the OpenSSH key to keep in the keychain, with its public half.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotACert is data that is no OpenSSH certificate.
	ErrNotACert = errors.New("keys: not an OpenSSH certificate")
	// ErrHostCert is a host certificate given where a user one is wanted.
	ErrHostCert = errors.New("keys: a host certificate, not a user certificate")
	// ErrCertMismatch is a certificate of another key than the private key.
	ErrCertMismatch = errors.New("keys: the certificate is not for this private key")
)
View Source
var (
	// ErrPassphraseNeeded is an encrypted key read without a passphrase.
	ErrPassphraseNeeded = errors.New("keys: the key is encrypted; a passphrase is needed")
	// ErrPassphraseWrong is a passphrase that does not open the key.
	ErrPassphraseWrong = errors.New("keys: wrong passphrase")
	// ErrNotAKey is data that is no private key this package reads.
	ErrNotAKey = errors.New("keys: not a private key")
	// ErrPublicKey is a public key given where a private one is wanted.
	ErrPublicKey = errors.New("keys: this is a public key; a private key is needed")
	// ErrCorrupt is a PuTTY key whose checksum does not match.
	ErrCorrupt = errors.New("keys: the key file is damaged")
)

Functions

func IsCert added in v0.0.9

func IsCert(data []byte) bool

IsCert reports whether data looks like an OpenSSH certificate.

func IsPPK

func IsPPK(data []byte) bool

IsPPK reports whether data looks like a PuTTY key file.

Types

type Cert added in v0.0.9

type Cert struct {
	*ssh.Certificate
	// Line is the certificate as one authorized_keys line, as kept.
	Line string
}

Cert is an OpenSSH user certificate (a key-cert.pub file): a public key signed by a certificate authority, offered with its private key.

func ParseCert added in v0.0.9

func ParseCert(data []byte) (Cert, error)

ParseCert reads a user certificate, as written by ssh-keygen -s.

func (Cert) After added in v0.0.9

func (c Cert) After() time.Time

After and Before bound when the certificate is valid.

func (Cert) Before added in v0.0.9

func (c Cert) Before() time.Time

func (Cert) CAFingerprint added in v0.0.9

func (c Cert) CAFingerprint() string

CAFingerprint is the SHA256 fingerprint of the authority that signed it.

func (Cert) Early added in v0.0.9

func (c Cert) Early(now time.Time) bool

Early reports a certificate not valid yet at now.

func (Cert) Expired added in v0.0.9

func (c Cert) Expired(now time.Time) bool

Expired reports a certificate no longer valid at now.

func (Cert) Forever added in v0.0.9

func (c Cert) Forever() bool

Forever reports a certificate valid without a time limit.

func (Cert) KeyFingerprint added in v0.0.9

func (c Cert) KeyFingerprint() string

KeyFingerprint is the SHA256 fingerprint of the certified key, the one its private key must have.

func (Cert) Matches added in v0.0.9

func (c Cert) Matches(fingerprint string) bool

Matches reports whether the certificate is for the key with this fingerprint; an unknown fingerprint ("") matches.

type Key

type Key struct {
	// PEM is the OpenSSH (or PEM) private key, encrypted with its
	// passphrase when it has one.
	PEM []byte
	// Public is the key's public half; for an encrypted legacy PEM key
	// read without its passphrase it is nil.
	Public ssh.PublicKey
	// Encrypted reports that PEM needs a passphrase.
	Encrypted bool
	Comment   string
}

Key is a private key ready to keep.

func Encode

func Encode(priv any, comment string, passphrase []byte) (Key, error)

Encode turns a crypto private key into a Key in OpenSSH form.

func Generate

func Generate(comment string, passphrase []byte) (Key, error)

Generate makes a new ed25519 key, encrypted with passphrase unless it is empty.

func Import

func Import(data, passphrase []byte) (Key, error)

Import reads a private key, OpenSSH, PEM or PuTTY .ppk. passphrase opens an encrypted one. An encrypted key read without it is ErrPassphraseNeeded; for an OpenSSH key the Key returned with it still has its public half, so it can be kept and opened later. A PuTTY key is converted to OpenSSH, encrypted with the same passphrase.

func (Key) AuthorizedLine

func (k Key) AuthorizedLine() string

AuthorizedLine is the key as a line of authorized_keys, without the newline: "type base64 comment".

func (Key) Fingerprint

func (k Key) Fingerprint() string

Fingerprint is the public key's SHA256 fingerprint, "" when unknown.

func (Key) Type

func (k Key) Type() string

Type is the key's algorithm, as ssh-ed25519.

type UnsupportedError

type UnsupportedError struct{ What string }

UnsupportedError is a key of a kind this package does not read, such as a DSA key or a PuTTY key derived with Argon2d.

func (*UnsupportedError) Error

func (e *UnsupportedError) Error() string

Jump to

Keyboard shortcuts

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