Documentation
¶
Index ¶
- Constants
- Variables
- func CertificateValid(ca ssh.PublicKey, pub ssh.PublicKey, cert *ssh.Certificate) error
- func RenewalDue(c *ssh.Certificate, at float64, now time.Time) bool
- type BaseCertificate
- type Certificate
- type HostCertificate
- func (h *HostCertificate) Renew() error
- func (h *HostCertificate) RenewContext(ctx context.Context) error
- func (h *HostCertificate) Request() error
- func (h *HostCertificate) RequestContext(ctx context.Context) error
- func (h *HostCertificate) Revoke() (time.Time, error)
- func (h *HostCertificate) RevokeContext(ctx context.Context) (time.Time, error)
- func (h *HostCertificate) RevokeSerialContext(ctx context.Context, serial uint64) (time.Time, error)
- type Option
- type Renewable
- type RenewableWaiter
- type Requestable
- type RequestableWaiter
- type Revocable
- type Storage
- type UserCertificate
- func (u *UserCertificate) Request() error
- func (u *UserCertificate) RequestContext(ctx context.Context) error
- func (u *UserCertificate) Revoke() (time.Time, error)
- func (u *UserCertificate) RevokeContext(ctx context.Context) (time.Time, error)
- func (u *UserCertificate) RevokeSerialContext(ctx context.Context, serial uint64) (time.Time, error)
- type Waiter
Constants ¶
const DefaultHostCertificateLifetime = (time.Hour * 24) * 30
const DefaultUserCertificateLifetime = time.Hour * 24
Variables ¶
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") )
var ( ErrInitialRequestFailed = errors.New("initial certificate request failed") ErrNotRunning = errors.New("renewal ticker not running") )
var (
ErrEmptyPrincipalsList = errors.New("principals list was empty")
)
Functions ¶
func CertificateValid ¶
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 ¶
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
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 Renewable ¶
type Renewable interface {
Requestable
Renew() error
RenewContext(ctx context.Context) error
}
type RenewableWaiter ¶
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
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.
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. |