41 KiB
ca
import "github.com/effective-security/trustyca/internal/ca"
Package ca is the core of the Certification Authority: it resolves the issuer and the profile that serve a tenant request, builds authority issuers from the issuer rows and their keys, creates and imports issuers, and mirrors the platform ca-config into the CA tables.
The Registry is the entry point of the signing services. Every lookup names its tenant scope and the built issuers are cached by row ID, so the labels of different orgs and projects never collide (DESIGN.md sections 5 and 6):
keys := ca.NewKeys(cryptoProviders, dataProtection)
registry := ca.NewRegistry(caDb, keys, ca.Options{TTL: 5 * time.Minute})
res, err := registry.Resolve(ctx, &ca.ResolveRequest{
OrgID: orgID,
ProjectID: projectID,
Profile: "server",
})
if err != nil {
// errors.Is(err, ca.ErrProfileNotFound), ca.ErrIssuerNotFound, ...
}
crt, pem, err := res.Issuer.Sign(csr.SignRequest{
Request: csrPEM,
Profile: res.ProfileName,
})
Keys generates the key of a new issuer in a crypto provider, or wraps a software key with the data protection provider, and loads the key of a row; NewRootIssuer, NewSignedIssuer, NewPendingIssuer, ImportIssuer and ActivatedIssuer build the rows the service registers. Registry.Bootstrap registers the platform issuers, roots and profiles of an authority.Config at startup and loads the enabled issuers, so that one that does not load fails the start.
Index
- Constants
- Variables
- func AuthorityProfile(p *model.CertificateProfile) (*authority.CertProfile, error)
- func CrlDue(current *model.Crl, renewal time.Duration, now time.Time) bool
- func IsKeyURI(key string) bool
- func IsSelfSigned(crt *x509.Certificate) bool
- func KeyLabel(orgID, projectID xdb.ID, label string) string
- func KeySpec(spec *pb.KeySpec) (string, int, error)
- func LoadBootstrapConfig(path string) (*authority.Config, error)
- func PublicKeysEqual(a, b crypto.PublicKey) bool
- func SubjectKeyID(pub crypto.PublicKey) (string, error)
- type BootstrapResult
- type CrlCounts
- type CrlPublisher
- type ImportRequest
- type IssuerRequest
- type KeyRef
- type Keys
- func NewKeys(crypto *cryptoprov.Crypto, dp dataprotection.Provider) *Keys
- func (k *Keys) ActivatedIssuer(ctx context.Context, row *model.Issuer, certPEM, intermediates, rootPEM string) (*model.Issuer, error)
- func (k *Keys) Crypto() *cryptoprov.Crypto
- func (k *Keys) Destroy(_ context.Context, m *model.Issuer) error
- func (k *Keys) DisableSoftwareKeys()
- func (k *Keys) Generate(ctx context.Context, prov cryptoprov.Provider, keyLabel string, spec *pb.KeySpec, req *csr.CertificateRequest) ([]byte, crypto.Signer, *KeyRef, error)
- func (k *Keys) ImportIssuer(ctx context.Context, req *ImportRequest) (*model.Issuer, error)
- func (k *Keys) ImportKey(ctx context.Context, keyURI string, keyPEM []byte, keyLabel string, pub crypto.PublicKey) (crypto.Signer, *KeyRef, error)
- func (k *Keys) KeyRefFromExport(ctx context.Context, prov cryptoprov.Provider, keyLabel string, exported []byte) (*KeyRef, error)
- func (k *Keys) NewPendingIssuer(ctx context.Context, req *IssuerRequest) (*model.Issuer, error)
- func (k *Keys) NewRootIssuer(ctx context.Context, req *IssuerRequest, profileName string, profile *authority.CertProfile) (*model.Issuer, error)
- func (k *Keys) NewSignedIssuer(ctx context.Context, req *IssuerRequest, parent *Resolution) (*model.Issuer, error)
- func (k *Keys) ProtectKey(ctx context.Context, keyPEM []byte) (string, error)
- func (k *Keys) Provider(name string) (cryptoprov.Provider, error)
- func (k *Keys) Signer(ctx context.Context, m *model.Issuer) (crypto.Signer, error)
- type Options
- type PublishCrlsRequest
- type PublishCrlsResult
- type Registry
- func NewRegistry(caDb db.CaReadonlyDb, keys *Keys, opts Options) *Registry
- func (r *Registry) Bootstrap(ctx context.Context, caDb db.CaDb, cfg *authority.Config) (*BootstrapResult, error)
- func (r *Registry) FindIssuer(ctx context.Context, orgID, projectID xdb.ID, label string) (*model.Issuer, error)
- func (r *Registry) FindProfile(ctx context.Context, orgID, projectID xdb.ID, label string) (*model.CertificateProfile, error)
- func (r *Registry) InvalidateIssuer(row *model.Issuer)
- func (r *Registry) InvalidateProfile(orgID, projectID xdb.ID, label string)
- func (r *Registry) Issuer(ctx context.Context, row *model.Issuer) (*authority.Issuer, error)
- func (r *Registry) IssuerByKeyHash(ctx context.Context, alg crypto.Hash, hash []byte) (*authority.Issuer, *model.Issuer, error)
- func (r *Registry) IssuerByNameHash(_ context.Context, alg crypto.Hash, hash []byte) (*authority.Issuer, *model.Issuer, error)
- func (r *Registry) IssuerBySKID(ctx context.Context, skid string) (*authority.Issuer, *model.Issuer, error)
- func (r *Registry) Keys() *Keys
- func (r *Registry) Len() int
- func (r *Registry) Purge()
- func (r *Registry) Resolve(ctx context.Context, req *ResolveRequest) (*Resolution, error)
- type Resolution
- type ResolveRequest
Constants
const (
// SoftwareKeyProvider names the provider of a key that no crypto
// provider holds: the key material is kept wrapped by the data
// protection provider in key_protected. It is the name of the xpki
// in-memory provider, which generates such keys and is for tests and
// development only.
SoftwareKeyProvider = "inmem"
// DefaultKeyAlgo is the algorithm of a generated key when the request
// names none
DefaultKeyAlgo = "ECDSA"
// DefaultKeySize is the curve of a generated key when the request names
// none
DefaultKeySize = 256
)
const (
// DefaultCacheTTL bounds the staleness of the cached issuers and
// profiles when the configuration sets none: a change made by another
// instance is visible within five minutes (DESIGN.md section 5.1)
DefaultCacheTTL = 5 * time.Minute
// DefaultCacheSize is the number of issuers kept in memory when the
// configuration sets none
DefaultCacheSize = 1000
)
const (
// CrlPEMType is the PEM block type of a CRL
CrlPEMType = "X509 CRL"
)
Variables
Errors of the issuer and profile resolution. They are returned wrapped with a stack, so compare them with errors.Is; the service maps them to its status codes.
var (
// ErrProfileNotFound is returned when the scope has no active profile
// with the label, in the project or in the org
ErrProfileNotFound = errors.New("profile not found")
// ErrIssuerNotFound is returned when the scope has no issuer with the
// label, in the project or in the org
ErrIssuerNotFound = errors.New("issuer not found")
// ErrIssuerNotActive is returned when the issuer exists but does not
// sign: it is Pending, Archived or Destroyed
ErrIssuerNotActive = errors.New("issuer is not active")
// ErrIssuerLabelRequired is returned when the profile binds to any
// issuer and the request names none
ErrIssuerLabelRequired = errors.New("issuer label is required")
// ErrIssuerMismatch is returned when the request names an issuer other
// than the one the profile binds to
ErrIssuerMismatch = errors.New("issuer does not match the profile")
// ErrProfileNotAllowed is returned when a profile bound to any issuer is
// not listed in the AllowedProfiles of the issuer
ErrProfileNotAllowed = errors.New("issuer does not allow the profile")
// ErrIssuerExpired is returned when the certificate of the issuer is no
// longer valid, so it signs no CRL
ErrIssuerExpired = errors.New("issuer certificate has expired")
// ErrSoftwareKeysDisabled is returned by Keys when a key that no crypto
// provider holds (a key the inmem provider generates, a PEM key of an
// import or of a bootstrap key file) is refused: the configuration
// allows keys of the crypto providers only (ca.allow_software_keys)
ErrSoftwareKeysDisabled = errors.New("software keys are not allowed: use a key of a crypto provider")
)
CrlStatuses are the lifecycle statuses of the issuers that publish CRLs: an Archived issuer signs no certificate but keeps answering for the ones it issued (DESIGN.md section 4.2)
var CrlStatuses = []pb.IssuerStatus_Enum{
pb.IssuerStatus_Active,
pb.IssuerStatus_Archived,
}
func AuthorityProfile
func AuthorityProfile(p *model.CertificateProfile) (*authority.CertProfile, error)
AuthorityProfile converts a profile row to the profile the authority signs with. It reads the row only: a row the registry returned is shared with other requests, and its IDs must not be formatted (model.Definition).
func CrlDue
func CrlDue(current *model.Crl, renewal time.Duration, now time.Time) bool
CrlDue reports whether a CRL must be published at the time: the issuer has none, or the next update of the current one is within the renewal period
func IsKeyURI
func IsKeyURI(key string) bool
IsKeyURI returns true when the key is a reference to a key in a crypto provider rather than key material
func IsSelfSigned
func IsSelfSigned(crt *x509.Certificate) bool
IsSelfSigned reports whether the certificate is its own issuer
func KeyLabel
func KeyLabel(orgID, projectID xdb.ID, label string) string
KeyLabel returns the label of the key of an issuer in its crypto provider: trustyca/{org}/{project}/{label}, with 0 for the platform and the org scope
func KeySpec
func KeySpec(spec *pb.KeySpec) (string, int, error)
KeySpec returns the algorithm and size of the key to generate for a request; a nil or empty specification takes the defaults, and a size the algorithm does not accept is an error
func LoadBootstrapConfig
func LoadBootstrapConfig(path string) (*authority.Config, error)
LoadBootstrapConfig loads the ca-config of the platform bootstrap with authority.LoadConfig, which expands `$VAR` and `${VAR}` as environment variables in every value: a `${ISSUER_ID}` in the AIA, CRL or OCSP URL template of an issuer would become an empty string, and every certificate the issuer signs would name the URL without the issuer. A file whose templates name the issuer that way is refused before it is loaded; file issuers use pbconv.IssuerIDPlaceholder (`:ISSUER_ID`).
func PublicKeysEqual
func PublicKeysEqual(a, b crypto.PublicKey) bool
PublicKeysEqual reports whether the two public keys are the same key
func SubjectKeyID
func SubjectKeyID(pub crypto.PublicKey) (string, error)
SubjectKeyID returns the key identifier of a public key: the SHA-1 of its subjectPublicKey bits (RFC 5280 section 4.2.1.2 method 1). It is the identifier the CA puts in the certificates it issues, the IKID of the certificates the key signs and the issuer key hash of their OCSP requests, so a Pending issuer is identified by it before it has a certificate.
type BootstrapResult
BootstrapResult counts the rows a bootstrap registered or updated
type BootstrapResult struct {
// Issuers is the number of issuers registered
Issuers int
// Updated is the number of issuers whose runtime settings changed, or
// that the configuration enabled again
Updated int
// Archived is the number of issuers the configuration disabled
Archived int
// Roots is the number of trust anchors registered or refreshed
Roots int
// Profiles is the number of profiles registered or replaced
Profiles int
}
type CrlCounts
CrlCounts reports the issuers that publish CRLs, the Active and Archived issuers whose certificate is valid, by the state of their current CRL at a time: Issuers is Current, Due, Overdue and Missing together
type CrlCounts struct {
// Issuers is the number of issuers that publish CRLs
Issuers int
// Current is the number of CRLs whose next update is later than the
// renewal period of their issuer
Current int
// Due is the number of CRLs whose next update is within the renewal
// period of their issuer
Due int
// Overdue is the number of CRLs whose next update has passed
Overdue int
// Missing is the number of issuers that have published no CRL
Missing int
}
func CountCrls
func CountCrls(states []*model.CrlState, now time.Time) (*CrlCounts, error)
CountCrls classifies the CRL states of the issuers that publish CRLs (db.CaReadonlyDb.ListCrlStates for CrlStatuses, read with the other counts of the summary at one snapshot) at the time: an issuer without a CRL is Missing, a CRL whose next update is not after the time is Overdue, one within the renewal period of its issuer (as CrlDue judges it) is Due, any other is Current. An issuer whose certificate has expired publishes no CRL and is not counted. The renewal period comes from the settings of the issuer, so an issuer whose config does not parse fails the count, as the lists fail on it; a Missing or Overdue CRL needs no settings.
type CrlPublisher
CrlPublisher signs and stores the CRLs of the issuers (DESIGN.md section 8). The PublishCrls method of the CA service and the crl_renewal task share it: a CRL is published when the issuer has none, when the current one is within the renewal period of its next update, or on demand. The CRL number is the issuer's current number plus one, and db.PublishCrl stores the CRL and the number in one transaction, refusing a number that is not greater than the issuer's: when another instance publishes first, the CRL is signed again with the next number.
A CrlPublisher is safe for concurrent use.
type CrlPublisher struct {
// contains filtered or unexported fields
}
func NewCrlPublisher
func NewCrlPublisher(caDb db.CaDb, registry *Registry) *CrlPublisher
NewCrlPublisher returns a publisher over the CA tables and the registry that loads the issuers
func (*CrlPublisher) PublishCrl
func (p *CrlPublisher) PublishCrl(ctx context.Context, row *model.Issuer, force bool) (*model.Crl, bool, error)
PublishCrl signs and stores the CRL of the issuer row when it is due (CrlDue with the renewal period of the issuer settings), or when forced, and returns the CRL and true. When the current CRL (db.GetCrl) is not due it is returned with false. The row must be an Active or Archived issuer whose certificate is valid; its CRL number is the current one, so the row comes from the DB, not from a cache.
func (*CrlPublisher) PublishCrls
func (p *CrlPublisher) PublishCrls(ctx context.Context, req *PublishCrlsRequest) (*PublishCrlsResult, error)
PublishCrls publishes the due CRLs of the Active and Archived issuers of the scope, every CRL when forced. The current CRLs of a page of issuers are read in one query (db.GetCrls), and an issuer whose CRL is not due is skipped from the settings of its row, before its signer is loaded. An issuer that fails does not stop the run: the failure is logged and counted. The error is a failure to list the issuers or to read their CRLs; the CRLs published before it are in the result.
type ImportRequest
ImportRequest describes an issuer imported with an existing certificate and key: bring your own CA
type ImportRequest struct {
// OrgID is the owning org; zero is the platform
OrgID xdb.ID
// ProjectID is the owning project; zero is the org scope
ProjectID xdb.ID
// Label of the issuer, unique in its scope
Label string
// Type of the authority
Type pb.AuthorityType_Enum
// Certificate is the PEM encoded issuer certificate
Certificate string
// Intermediates are the PEM encoded intermediate CA certificates
Intermediates string
// Root is the PEM encoded root; empty for a self-signed certificate
Root string
// KeyURI references the key in a crypto provider
KeyURI string
// KeyPEM is the PEM encoded key, stored wrapped
KeyPEM string
// Config provides the runtime settings of the issuer
Config *pb.IssuerConfig
}
type IssuerRequest
IssuerRequest describes an issuer to create: its scope and identity, the key to generate and its runtime settings (DESIGN.md section 5.2). The certificate request is built from Subject, SAN and Extensions.
type IssuerRequest struct {
// OrgID is the owning org; zero is the platform
OrgID xdb.ID
// ProjectID is the owning project; zero is the org scope
ProjectID xdb.ID
// Label of the issuer, unique in its scope
Label string
// Type of the authority
Type pb.AuthorityType_Enum
// Subject of the issuer certificate; a common name or names are required
Subject *csr.X509Subject
// SAN of the issuer certificate
SAN []string
// Extensions of the issuer certificate
Extensions []csr.X509Extension
// KeySpec of the key to generate; nil takes the defaults
KeySpec *pb.KeySpec
// Provider generates and holds the key
Provider cryptoprov.Provider
// Config provides the runtime settings of the issuer
Config *pb.IssuerConfig
}
type KeyRef
KeyRef locates the private key of an issuer; it is stored in the key columns of the issuer row and never carries plain key material
type KeyRef struct {
// Provider is the manufacturer of the crypto provider that holds the
// key, or SoftwareKeyProvider
Provider string
// KeyID is the URI of the key in its provider, or the key label of a
// software key
KeyID string
// Protected is the wrapped PEM of a software key; empty for a key a
// provider holds
Protected string
}
func (*KeyRef) Apply
func (r *KeyRef) Apply(m *model.Issuer)
Apply sets the key columns of the issuer row
type Keys
Keys generates, loads and protects the private keys of the issuers. A key generated in a KMS or HSM provider is referenced by its URI and never leaves the provider; a software key is wrapped by the data protection provider before it is stored.
type Keys struct {
// contains filtered or unexported fields
}
func NewKeys
func NewKeys(crypto *cryptoprov.Crypto, dp dataprotection.Provider) *Keys
NewKeys returns the key management over the crypto providers and the data protection provider; either may be nil when the deployment has none, and the operations that need it fail. Software keys are allowed until DisableSoftwareKeys.
func (*Keys) ActivatedIssuer
func (k *Keys) ActivatedIssuer(ctx context.Context, row *model.Issuer, certPEM, intermediates, rootPEM string) (*model.Issuer, error)
ActivatedIssuer returns the copy of a Pending row with the certificate signed outside the CA, after verifying that the certificate is for the key of the issuer and that its chain verifies; the DB activates the row
func (*Keys) Crypto
func (k *Keys) Crypto() *cryptoprov.Crypto
Crypto returns the crypto providers
func (*Keys) Destroy
func (k *Keys) Destroy(_ context.Context, m *model.Issuer) error
Destroy removes the key of an issuer from its crypto provider, when the provider manages keys. A software key has no provider copy: it is destroyed when the row clears key_protected.
func (*Keys) DisableSoftwareKeys
func (k *Keys) DisableSoftwareKeys()
DisableSoftwareKeys refuses, with ErrSoftwareKeysDisabled, every key that no crypto provider holds: a key the inmem provider generates, the PEM key of an import and the key file of a bootstrap issuer, which would be stored wrapped in key_protected. A production configuration disables them (ca.allow_software_keys), so that every issuer key lives in a KMS or an HSM; the wrapped keys of existing rows still load.
func (*Keys) Generate
func (k *Keys) Generate(ctx context.Context, prov cryptoprov.Provider, keyLabel string, spec *pb.KeySpec, req *csr.CertificateRequest) ([]byte, crypto.Signer, *KeyRef, error)
Generate generates the key of an issuer in the provider, with the label and specification, and signs the certificate request with it. It returns the PEM encoded CSR, the signer and the reference to store on the row.
func (*Keys) ImportIssuer
func (k *Keys) ImportIssuer(ctx context.Context, req *ImportRequest) (*model.Issuer, error)
ImportIssuer verifies the certificate chain and the key of an imported issuer and returns its Active row; the chain and root columns hold the verified chain
func (*Keys) ImportKey
func (k *Keys) ImportKey(ctx context.Context, keyURI string, keyPEM []byte, keyLabel string, pub crypto.PublicKey) (crypto.Signer, *KeyRef, error)
ImportKey returns the signer and the reference of an existing key: by its URI in a crypto provider, or as PEM, which is wrapped. The key must be the private key of the public key.
func (*Keys) KeyRefFromExport
func (k *Keys) KeyRefFromExport(ctx context.Context, prov cryptoprov.Provider, keyLabel string, exported []byte) (*KeyRef, error)
KeyRefFromExport returns the reference of a key its provider exported (cryptoprov.KeyGenerator.ExportKey, or the key authority.NewRoot returns): a key URI references the key in the provider, key material is wrapped and the reference carries the key label
func (*Keys) NewPendingIssuer
func (k *Keys) NewPendingIssuer(ctx context.Context, req *IssuerRequest) (*model.Issuer, error)
NewPendingIssuer generates the key of an issuer in the provider and its certificate request. The row is Pending with the CSR until ActivatedIssuer sets the certificate signed outside the CA.
func (*Keys) NewRootIssuer
func (k *Keys) NewRootIssuer(ctx context.Context, req *IssuerRequest, profileName string, profile *authority.CertProfile) (*model.Issuer, error)
NewRootIssuer generates the key of a self-signed root in the provider and signs its certificate with the CA profile, registered under profileName. The row is Active and its own trust anchor; the caller registers the root certificate.
func (*Keys) NewSignedIssuer
func (k *Keys) NewSignedIssuer(ctx context.Context, req *IssuerRequest, parent *Resolution) (*model.Issuer, error)
NewSignedIssuer generates the key of an issuer in the provider and has the parent sign its certificate with the CA profile the parent resolved. The row is Active, with the parent as its parent, the parent and its chain as its chain and the parent's root as its root. A Root is refused: it is self-signed by NewRootIssuer. The chain of the parent must allow a subordinate CA with the path length of the profile (checkPathLength), or the certificates the subordinate issues would never verify.
func (*Keys) ProtectKey
func (k *Keys) ProtectKey(ctx context.Context, keyPEM []byte) (string, error)
ProtectKey wraps the PEM of a software key with the data protection provider; the result is what key_protected stores
func (*Keys) Provider
func (k *Keys) Provider(name string) (cryptoprov.Provider, error)
Provider returns the crypto provider with the name, `manufacturer` or `manufacturer/model`; an empty name is the default provider
func (*Keys) Signer
func (k *Keys) Signer(ctx context.Context, m *model.Issuer) (crypto.Signer, error)
Signer returns the signer of an issuer row: the wrapped software key, or the key its URI references in a crypto provider
type Options
Options configure a Registry
type Options struct {
// TTL bounds the staleness of the cached issuers and profiles; a change
// made by another instance is visible after it. Zero is DefaultCacheTTL.
TTL time.Duration
// Size is the number of issuers kept in memory; the least recently used
// is evicted first. Zero is DefaultCacheSize.
Size int
}
type PublishCrlsRequest
PublishCrlsRequest selects the issuers whose due CRLs are published: the Active and Archived issuers of the scope, as query.ListIssuersRequest names it
type PublishCrlsRequest struct {
// OrgID limits the issuers to the org
OrgID xdb.ID
// AllOrgs selects the issuers of every org and the platform when OrgID
// is zero, for the renewal task
AllOrgs bool
// ProjectID limits the issuers to the project
ProjectID xdb.ID
// ProjectIDs limits the issuers to the org-wide ones and those of the
// projects; nil applies no project filter
ProjectIDs []uint64
// Force publishes the CRLs that are not due
Force bool
}
type PublishCrlsResult
PublishCrlsResult is the outcome of a run over the issuers of a scope
type PublishCrlsResult struct {
// Crls are the CRLs the run published
Crls []*model.Crl
// Skipped is the number of issuers whose CRL was not due, and of the
// issuers whose certificate has expired
Skipped int
// Failed is the number of issuers whose CRL could not be published;
// every failure is logged
Failed int
}
type Registry
Registry resolves the issuer and the profile that serve a tenant request and keeps the built authority issuers in memory.
Every lookup names its tenant scope: a label resolves in the project, then in the org, never in the platform or in another org (DESIGN.md section 6), and the DB finds rows by exact scope. The built issuers are cached by row ID, which is unique across orgs, so equal labels of different orgs or projects never collide; the resolutions of a scope and label are cached under the requested scope. Both caches are bounded by size and TTL, and a mutation made through this instance invalidates its entries at once (InvalidateIssuer, InvalidateProfile); a mutation made by another instance is visible after the TTL. Resolutions that fail are not cached.
A Registry is safe for concurrent use.
type Registry struct {
// contains filtered or unexported fields
}
func NewRegistry
func NewRegistry(caDb db.CaReadonlyDb, keys *Keys, opts Options) *Registry
NewRegistry returns a registry over the CA tables and the key management
func (*Registry) Bootstrap
func (r *Registry) Bootstrap(ctx context.Context, caDb db.CaDb, cfg *authority.Config) (*BootstrapResult, error)
Bootstrap mirrors the issuers, trust anchors and profiles of a ca-config into the platform rows (org_id IS NULL), so that the platform issuers sign tenant CA certificates and CIS serves their chains from the same tables (DESIGN.md section 5.1), then loads every enabled issuer, so that a key that does not load or a delegated OCSP profile that does not bind fails the start instead of the first request.
It is idempotent: a registered issuer with the same certificate only has its runtime settings refreshed, roots are registered by thumbprint and profiles are replaced by label. It is also safe when several instances start against one fresh DB at once: an issuer insert that loses the race to another instance continues with the row that instance registered. The key of an issuer is a key URI, stored as the reference, or key material, stored wrapped; both are checked against the certificate. An issuer whose certificate is for a new key is an error: renewal keeps the label unique, so the old issuer must be archived under another label first. A certificate renewed for the registered key is an error too: renewal means a new key, so two certificates never share a SKID (DESIGN.md section 5.4). A disabled issuer is archived, so that it stops signing on every instance, and enabled again when the configuration enables it; a destroyed one has no key and is an error. The anchor of a root issuer is written in the transaction of the issuer insert, and registered again on every start from the stored certificate, which restores an anchor that was deleted or that a version without the transaction failed to write.
func (*Registry) FindIssuer
func (r *Registry) FindIssuer(ctx context.Context, orgID, projectID xdb.ID, label string) (*model.Issuer, error)
FindIssuer returns the issuer with the label of the project, or of the org when the project has none, in any lifecycle status
func (*Registry) FindProfile
func (r *Registry) FindProfile(ctx context.Context, orgID, projectID xdb.ID, label string) (*model.CertificateProfile, error)
FindProfile returns the active profile with the label of the project, or of the org when the project has none; an inactive profile is not found and does not fall back to the org
func (*Registry) InvalidateIssuer
func (r *Registry) InvalidateIssuer(row *model.Issuer)
InvalidateIssuer drops the issuer and the resolutions of its label from memory, after a mutation of its row is committed
func (*Registry) InvalidateProfile
func (r *Registry) InvalidateProfile(orgID, projectID xdb.ID, label string)
InvalidateProfile drops the resolutions of the profile label of the scope from memory, after a mutation of the profile is committed: a project profile from its project, an org profile from every project of the org
func (*Registry) Issuer
func (r *Registry) Issuer(ctx context.Context, row *model.Issuer) (*authority.Issuer, error)
Issuer returns the authority issuer of the row, built from its certificate, chain and key on the first use and kept until the TTL, an eviction or an invalidation
func (*Registry) IssuerByKeyHash
func (r *Registry) IssuerByKeyHash(ctx context.Context, alg crypto.Hash, hash []byte) (*authority.Issuer, *model.Issuer, error)
IssuerByKeyHash returns the issuer whose public key has the hash, as an OCSP request identifies it. The issuers in memory are matched for any algorithm; a SHA-1 hash is also the Subject Key Identifier of a CA certificate this CA issued (RFC 5280 method 1), so it is looked up in the DB. A certificate of an issuer that is not in memory and whose key identifier is not its SHA-1 key hash is not found.
func (*Registry) IssuerByNameHash
func (r *Registry) IssuerByNameHash(_ context.Context, alg crypto.Hash, hash []byte) (*authority.Issuer, *model.Issuer, error)
IssuerByNameHash returns the issuer whose subject name has the hash, as an OCSP request may identify it; only the issuers in memory are matched
func (*Registry) IssuerBySKID
func (r *Registry) IssuerBySKID(ctx context.Context, skid string) (*authority.Issuer, *model.Issuer, error)
IssuerBySKID returns the issuer whose Subject Key Identifier is the IKID of the certificates it issued, for revocation status: an Active or Archived issuer, since an Archived one still answers for its certificates
func (*Registry) Keys
func (r *Registry) Keys() *Keys
Keys returns the key management of the registry
func (*Registry) Len
func (r *Registry) Len() int
Len returns the number of issuers in memory
func (*Registry) Purge
func (r *Registry) Purge()
Purge drops every cached issuer and resolution
func (*Registry) Resolve
func (r *Registry) Resolve(ctx context.Context, req *ResolveRequest) (*Resolution, error)
Resolve returns the issuer and the profile of a sign request: the profile of the scope, the issuer it binds to (or the requested one, when the profile binds to any issuer that allows it), which must be Active, with the profile registered on the issuer.
type Resolution
Resolution is the issuer and the profile that sign a request
type Resolution struct {
// Issuer signs with the key of Row
Issuer *authority.Issuer
// Row is the issuer row
Row *model.Issuer
// ProfileRow is the profile row the request resolved to
ProfileRow *model.CertificateProfile
// Profile is the authority profile of ProfileRow
Profile *authority.CertProfile
// ProfileName is the name Profile is registered under in Issuer; a
// csr.SignRequest names it in Profile
ProfileName string
}
type ResolveRequest
ResolveRequest names the issuer and the profile of a sign request
type ResolveRequest struct {
// OrgID is the org of the request; required
OrgID xdb.ID
// ProjectID is the project of the request; zero is the org scope
ProjectID xdb.ID
// Profile is the label of the profile; required
Profile string
// IssuerLabel selects the issuer when the profile binds to any issuer;
// otherwise it must be empty or the profile's issuer
IssuerLabel string
}
Generated by gomarkdoc