cert

package
v0.22.1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: Apache-2.0 Imports: 16 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")
	ErrCertificateMismatch            = errors.New("certificate did not match private key")
	ErrCertificateNotFound            = errors.New("no certificate found")
	ErrCertificateNotValid            = errors.New("certificate validity not ok")
	ErrKeyNotFound                    = errors.New("no key private key found")
	ErrNoAuthHandlerAvailable         = errors.New("no auth handler was available")
	ErrNotImplemented                 = errors.New("method not implemented")
	ErrSignerNotFound                 = errors.New("no signer found")
	ErrUnexpectedCertificateAuthority = errors.New("certificate was not issued by the CA")
	ErrUnexpectedResponse             = errors.New("unexpected response from CA")
)
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.

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 Storage

type Storage interface {
	AddToAgent() error
	Certificate() (*ssh.Certificate, error)
	CertificateBytes() ([]byte, error)
	GeneratePrivateKey() error
	HasCertificate() bool
	HasPrivateKey() bool
	PrivateKey() (crypto.PrivateKey, error)
	PrivateKeyBytes() ([]byte, error)
	PublicKey() (ssh.PublicKey, error)
	PublicKeyBytes() ([]byte, 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.

type Waiter

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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