cert

package
v0.27.4 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 17 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

Index

Constants

View Source
const DefaultHostCertificateLifetime = (time.Hour * 24) * 30
View Source
const DefaultUserCertificateLifetime = time.Hour * 24

Variables

View Source
var (
	ErrAddingToAgent                  = errors.New("could not add to agent")
	ErrAlreadyRevoked                 = errors.New("certificate was already revoked")
	ErrCertificateMismatch            = errors.New("certificate did not match private key")
	ErrCertificateNotFound            = errors.New("no certificate found")
	ErrCertificateNotValid            = errors.New("certificate validity not ok")
	ErrDeletingCertificate            = errors.New("could not delete certificate")
	ErrKeyNotFound                    = errors.New("no key private key found")
	ErrNoAuthHandlerAvailable         = errors.New("no auth handler was available")
	ErrNotImplemented                 = errors.New("method not implemented")
	ErrRemovingFromAgent              = errors.New("could not remove from agent")
	ErrSignerNotFound                 = errors.New("no signer found")
	ErrUnexpectedCertificateAuthority = errors.New("certificate was not issued by the CA")
	ErrUnexpectedResponse             = errors.New("unexpected response from CA")
	ErrUnknownCertificate             = errors.New("certificate not found at CA for this key")
)
View Source
var (
	ErrInitialRequestFailed = errors.New("initial certificate request failed")
	ErrNotRunning           = errors.New("renewal ticker not running")
)
View Source
var (
	ErrEmptyPrincipalsList = errors.New("principals list was empty")
)

Functions

func CertificateValid

func CertificateValid(ca ssh.PublicKey, pub ssh.PublicKey, cert *ssh.Certificate) error

Helper function to validate a certificate. This checks that the certificate is not expired, was issued by the expected CA and that the certificate is for the public key of the private key it will be used with.

func RenewalDue

func RenewalDue(c *ssh.Certificate, at float64, now time.Time) bool

RenewalDue reports whether the fraction at (between 0 and 1) of the certificate's validity period, from ValidAfter to ValidBefore, has passed at now. Expired certificates are always due and certificates that never expire are never due.

Types

type BaseCertificate

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

func (*BaseCertificate) Store

func (base *BaseCertificate) Store() Storage

type Certificate

type Certificate interface {
	Store() Storage
}

type HostCertificate

type HostCertificate struct {
	*BaseCertificate

	AuthHandler auth.Handler
	Lifetime    time.Duration
	Principals  []string
}

func NewHostCertificate

func NewHostCertificate(server string, store Storage, opts ...Option) (*HostCertificate, error)

func (*HostCertificate) Renew

func (h *HostCertificate) Renew() error

Renew renews the existing host certificate. See HostCertificate.RenewContext.

func (*HostCertificate) RenewContext

func (h *HostCertificate) RenewContext(ctx context.Context) error

RenewContext renews the existing host certificate using proof of possession of the private key, saving the renewed certificate to the store. Cancelling ctx aborts the request to the CA.

func (*HostCertificate) Request

func (h *HostCertificate) Request() error

Request requests a new host certificate. See HostCertificate.RequestContext.

func (*HostCertificate) RequestContext

func (h *HostCertificate) RequestContext(ctx context.Context) error

RequestContext authenticates using the AuthHandler and requests a new host certificate for Principals from the CA, saving it to the store. Cancelling ctx stops waiting for authentication and aborts the request to the CA.

func (*HostCertificate) Revoke added in v0.24.0

func (h *HostCertificate) Revoke() (time.Time, error)

Revoke revokes the current host certificate. See HostCertificate.RevokeContext.

func (*HostCertificate) RevokeContext added in v0.24.0

func (h *HostCertificate) RevokeContext(ctx context.Context) (time.Time, error)

RevokeContext revokes the current host certificate at the CA using proof of possession of the private key, which needs no authentication. Once revoked the certificate is deleted from the store. Host certificates are not held in an SSH agent, so unlike UserCertificate.RevokeContext no agent is contacted. The time of revocation is returned. Cancelling ctx aborts the request to the CA.

If the certificate was already revoked the error wraps ErrAlreadyRevoked, although the certificate is still removed.

func (*HostCertificate) RevokeSerialContext added in v0.24.0

func (h *HostCertificate) RevokeSerialContext(ctx context.Context, serial uint64) (time.Time, error)

RevokeSerialContext revokes the host certificate with serial at the CA, which must have been issued for the private key in the store. If serial is the current certificate it is removed as for HostCertificate.RevokeContext. If the CA has no certificate with serial for the key the error wraps ErrUnknownCertificate.

type Option

type Option func(*BaseCertificate)

func WithHTTPClient

func WithHTTPClient(h *http.Client) Option

func WithStore

func WithStore(store Storage) Option

type Renewable

type Renewable interface {
	Requestable
	Renew() error
	RenewContext(ctx context.Context) error
}

type RenewableWaiter

type RenewableWaiter interface {
	Renewable
	Waiter
}

type Requestable

type Requestable interface {
	Certificate
	Request() error
	RequestContext(ctx context.Context) error
}

type RequestableWaiter

type RequestableWaiter interface {
	Requestable
	Waiter
}

type Revocable added in v0.24.0

type Revocable interface {
	Certificate
	Revoke() (time.Time, error)
	RevokeContext(ctx context.Context) (time.Time, error)
	RevokeSerialContext(ctx context.Context, serial uint64) (time.Time, error)
}

Revocable is a certificate that can be revoked at the CA using proof of possession of its private key

type Storage

type Storage interface {
	AddToAgent() error
	Certificate() (*ssh.Certificate, error)
	CertificateBytes() ([]byte, error)
	DeleteCertificate() error
	GeneratePrivateKey() error
	HasCertificate() bool
	HasPrivateKey() bool
	PrivateKey() (crypto.PrivateKey, error)
	PrivateKeyBytes() ([]byte, error)
	PublicKey() (ssh.PublicKey, error)
	PublicKeyBytes() ([]byte, error)
	RemoveFromAgent() error
	RemoveStaleFromAgent() ([]*ssh.Certificate, error)
	SaveCertificate(*ssh.Certificate) error
	Signer() (ssh.Signer, error)
}

type UserCertificate

type UserCertificate struct {
	*BaseCertificate

	AuthHandler auth.Handler
	Lifetime    time.Duration
}

func NewUserCertificate

func NewUserCertificate(server string, store Storage, opts ...Option) (*UserCertificate, error)

func (*UserCertificate) Request

func (u *UserCertificate) Request() error

Request requests a new user certificate. See UserCertificate.RequestContext.

func (*UserCertificate) RequestContext

func (u *UserCertificate) RequestContext(ctx context.Context) error

RequestContext authenticates using the AuthHandler and requests a new user certificate from the CA, saving it to the store. Cancelling ctx stops waiting for authentication and aborts the request to the CA.

func (*UserCertificate) Revoke added in v0.24.0

func (u *UserCertificate) Revoke() (time.Time, error)

Revoke revokes the current user certificate. See UserCertificate.RevokeContext.

func (*UserCertificate) RevokeContext added in v0.24.0

func (u *UserCertificate) RevokeContext(ctx context.Context) (time.Time, error)

RevokeContext revokes the current user certificate at the CA using proof of possession of the private key, which needs no authentication. Once revoked the certificate is removed from the SSH agent and deleted from the store. The time of revocation is returned. Cancelling ctx aborts the request to the CA.

If the certificate was already revoked the error wraps ErrAlreadyRevoked, although the certificate is still removed. If the certificate was revoked but could not be removed from the SSH agent the error wraps ErrRemovingFromAgent.

func (*UserCertificate) RevokeSerialContext added in v0.24.0

func (u *UserCertificate) RevokeSerialContext(ctx context.Context, serial uint64) (time.Time, error)

RevokeSerialContext revokes the user certificate with serial at the CA, which must have been issued for the private key in the store. If serial is the current certificate it is removed as for UserCertificate.RevokeContext. If the CA has no certificate with serial for the key the error wraps ErrUnknownCertificate.

type Waiter

type Waiter interface {
	Wait() error
	Stop()
}

Directories

Path Synopsis
Package store provides the certificate store: a private key and its certificate, kept in a Backend such as a file or the system keyring.
Package store provides the certificate store: a private key and its certificate, kept in a Backend such as a file or the system keyring.

Jump to

Keyboard shortcuts

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