Documentation
¶
Overview ¶
Package certutil provides utilities to work with certificates.
A Bundler builds and verifies certificate chains. It trusts only the roots it is given, plus the platform trust store when WithSystemRoots(true) is set; without trust roots it defaults to Force, which checks signatures only. AIA downloads (WithAIA) are bounded by the WithHTTPClient timeout and the context given to BundleContext. One Bundler can be shared by goroutines; intermediates it learns over AIA are reused by later calls:
b, err := certutil.NewBundler(nil, intermediates,
certutil.WithSystemRoots(true),
certutil.WithAIA(true),
)
if err != nil {
return err
}
chain, err := b.BundleContext(ctx, []*x509.Certificate{leaf}, nil)
Index ¶
- Constants
- Variables
- func BuildBundle(c *Chain) (bundle *Bundle, status *BundleStatus, err error)
- func CreateOCSPRequest(crt, issuer *x509.Certificate, hash crypto.Hash) ([]byte, error)
- func CreateOCSPResponse(ctx context.Context, issuer, responderCert *x509.Certificate, ...) ([]byte, error)
- func CreatePoolFromPEM(pemBytes []byte) (*x509.CertPool, error)
- func Digest(hash crypto.Hash, data []byte) []byte
- func EncodePrivateKeyToPEM(priv crypto.PrivateKey) (key []byte, err error)
- func EncodePublicKeyToPEM(pubKey crypto.PublicKey) ([]byte, error)
- func EncodeToPEM(out io.Writer, withComments bool, certs ...*x509.Certificate) error
- func EncodeToPEMString(withComments bool, certs ...*x509.Certificate) (string, error)
- func ExpiryTime(chain []*x509.Certificate) (notAfter time.Time)
- func FindExtension(list []pkix.Extension, oid asn1.ObjectIdentifier) *pkix.Extension
- func FindExtensionValue(list []pkix.Extension, oid asn1.ObjectIdentifier) []byte
- func FindIssuer(crt *x509.Certificate, chain []*x509.Certificate, root *x509.Certificate) *x509.Certificate
- func GetAuthorityKeyID(c *x509.Certificate) string
- func GetIssuerID(c *x509.Certificate) string
- func GetKeyDERFromPEM(in []byte, password []byte) ([]byte, error)
- func GetSubjectID(c *x509.Certificate) string
- func GetSubjectKeyID(c *x509.Certificate) string
- func GetThumbprintStr(c *x509.Certificate) string
- func HasOCSPNoCheck(crt *x509.Certificate) bool
- func HashAlgoToStr(hash crypto.Hash) string
- func HashToBase64URL(hash crypto.Hash, data []byte) string
- func HashToHex(hash crypto.Hash, data []byte) string
- func IsOCSPSigner(crt *x509.Certificate) bool
- func IsPostQuantumCertificate(crt *x509.Certificate) bool
- func IsPostQuantumKey(key any) bool
- func IsPostQuantumSignatureAlgorithm(algo x509.SignatureAlgorithm) bool
- func JoinPEM(p1, p2 []byte) []byte
- func LoadAndVerifyBundleFromPEM(certFile, intCAFile, rootFile string, opt ...Option) (*Bundle, *BundleStatus, error)
- func LoadChainFromPEM(certFile string) ([]*x509.Certificate, error)
- func LoadFromPEM(certFile string) (*x509.Certificate, error)
- func LoadPEMFiles(files ...string) ([]byte, error)
- func NameToString(name *pkix.Name) string
- func NewHash(algo string) (hash.Hash, error)
- func ParseChainFromPEM(certificateChainPem []byte) ([]*x509.Certificate, error)
- func ParseFromPEM(bytes []byte) (*x509.Certificate, error)
- func ParseHexDigestWithPrefix(digest string) (hash.Hash, []byte, error)
- func ParseOCSPResponse(der []byte, issuer *x509.Certificate) (*ocsp.Response, error)
- func ParseOCSPResponseForCert(der []byte, cert, issuer *x509.Certificate) (*ocsp.Response, error)
- func ParsePrivateKeyDER(keyDER []byte) (key crypto.Signer, err error)
- func ParsePrivateKeyPEM(keyPEM []byte) (key crypto.Signer, err error)
- func ParsePrivateKeyPEMWithPassword(keyPEM []byte, password []byte) (key crypto.Signer, err error)
- func ParsePublicKeyFromPEM(key []byte) (crypto.PublicKey, error)
- func ParseRSAPublicKeyFromPEM(key []byte) (*rsa.PublicKey, error)
- func Random(byteLength int) []byte
- func RandomString(length int) string
- func SHA1(data []byte) []byte
- func SHA1Base64(data []byte) string
- func SHA1Hex(data []byte) string
- func SHA256(data []byte) []byte
- func SHA256Base64(data []byte) string
- func SHA256Hex(data []byte) string
- func StrToHashAlgo(algo string) crypto.Hash
- func VerifyBundleFromPEM(certPEM, intCAPEM, rootPEM []byte, opt ...Option) (bundle *Bundle, status *BundleStatus, err error)
- func VerifyOCSPResponder(res *ocsp.Response, issuer *x509.Certificate) error
- type Bundle
- type BundleFlavor
- type BundleStatus
- type Bundler
- func (b *Bundler) Bundle(certs []*x509.Certificate, key crypto.Signer) (*Chain, error)
- func (b *Bundler) BundleContext(ctx context.Context, certs []*x509.Certificate, key crypto.Signer) (*Chain, error)
- func (b *Bundler) ChainFromFile(bundleFile, keyFile string, password string) (*Chain, error)
- func (b *Bundler) ChainFromPEM(certsRaw, keyPEM []byte, password string) (*Chain, error)
- func (b *Bundler) ChainFromPEMContext(ctx context.Context, certsRaw, keyPEM []byte, password string) (*Chain, error)
- func (b *Bundler) IntermediatePool() *x509.CertPool
- func (b *Bundler) IsKnownIssuer(cert *x509.Certificate) bool
- func (b *Bundler) RootPool() *x509.CertPool
- func (b *Bundler) VerifyOptions() x509.VerifyOptions
- type Chain
- type KeyInfo
- type Option
Constants ¶
const ( BundleExpiringBit int = 1 << iota // 0x01 BundleNotUbiquitousBit // 0x02 )
Warning code for a success
const ( // KeyTypeRSA is the KeyInfo.Type of an RSA key. KeyTypeRSA = "RSA" // KeyTypeECDSA is the KeyInfo.Type of an ECDSA key. KeyTypeECDSA = "ECDSA" // KeyTypeMLDSA is the KeyInfo.Type of an ML-DSA (FIPS 204) key. KeyTypeMLDSA = "ML-DSA" )
Key type names reported by KeyInfo.Type, as crypto/x509 prints the public key algorithm.
Variables ¶
var ErrNoCertificates = errors.New("no certificates")
ErrNoCertificates is returned, wrapped, when a Bundler or BuildBundle is given no certificate to bundle.
var IntermediateStash string
IntermediateStash contains the path to the directory where downloaded intermediates should be saved. When unspecified, downloaded intermediates are not saved.
var RandReader randSource = rand.Reader
RandReader is used so that it can be replaced in tests that require deterministic output
Functions ¶
func BuildBundle ¶
func BuildBundle(c *Chain) (bundle *Bundle, status *BundleStatus, err error)
BuildBundle returns the Bundle and BundleStatus of a Chain built by a Bundler. A nil c or c.Cert returns an error; a nil c.Status is treated as an empty status, and a nil c.Root (a Force chain) leaves RootCert and RootCertPEM empty (XPKI-042).
func CreateOCSPRequest ¶
CreateOCSPRequest returns the DER encoded OCSP request for crt issued by issuer, hashing the issuer name and key with hash. A nil crt or issuer or an unavailable hash returns an error before any work (XPKI-103), and so does an issuer whose subject is not crt's issuer name or whose key did not sign crt (XPKI-121). The signature check accepts SHA-1 and applies no CA policy. The request is the one ocsp.CreateRequest builds, issuerNameHash included, which was empty up to v2.0.324 (XPKI-131).
func CreateOCSPResponse ¶
func CreateOCSPResponse(ctx context.Context, issuer, responderCert *x509.Certificate, template ocsp.Response, signer crypto.Signer) ([]byte, error)
CreateOCSPResponse returns a DER encoded OCSP response signed by signer, the key of responderCert, as ocsp.CreateResponse does: template gives the content, and template.Certificate, when set, is embedded. Unlike ocsp.CreateResponse it also signs with an ML-DSA key, from any provider: the response is encoded by golang.org/x/crypto/ocsp, and the signature over its tbsResponseData (RFC 6960 §4.2.1) is pure ML-DSA with an empty context and the id-ml-dsa-* algorithm without parameters (RFC 9881). template.SignatureAlgorithm is ignored for an ML-DSA key, whose parameter set fixes the algorithm. A nil issuer, responderCert or signer, or an uninitialized ML-DSA key, is an error.
An ML-DSA response can be read by ParseOCSPResponse and by OpenSSL 3.5, but golang.org/x/crypto/ocsp cannot verify it.
ctx bounds the signature: a cryptoprov.ContextSigner signs with it (SignContext), any other signer is called once ctx is checked.
func CreatePoolFromPEM ¶
CreatePoolFromPEM returns CertPool from PEM encoded certs
func EncodePrivateKeyToPEM ¶
func EncodePrivateKeyToPEM(priv crypto.PrivateKey) (key []byte, err error)
EncodePrivateKeyToPEM returns the PEM encoded private key: PKCS#1 ("RSA PRIVATE KEY") for RSA, SEC1 ("EC PRIVATE KEY") for ECDSA and PKCS#8 ("PRIVATE KEY", seed form) for ML-DSA. Other key types are an error.
func EncodePublicKeyToPEM ¶
EncodePublicKeyToPEM returns PEM encoded public key
func EncodeToPEM ¶
EncodeToPEM converts certificates to PEM format, with optional comments
func EncodeToPEMString ¶
func EncodeToPEMString(withComments bool, certs ...*x509.Certificate) (string, error)
EncodeToPEMString converts certificates to PEM format, with optional comments
func ExpiryTime ¶
func ExpiryTime(chain []*x509.Certificate) (notAfter time.Time)
ExpiryTime returns the time when the certificate chain is expired.
func FindExtension ¶
FindExtension returns extension, or nil
func FindExtensionValue ¶
func FindExtensionValue(list []pkix.Extension, oid asn1.ObjectIdentifier) []byte
FindExtensionValue returns extension value, or nil
func FindIssuer ¶
func FindIssuer(crt *x509.Certificate, chain []*x509.Certificate, root *x509.Certificate) *x509.Certificate
FindIssuer returns an issuer cert
func GetAuthorityKeyID ¶
func GetAuthorityKeyID(c *x509.Certificate) string
GetAuthorityKeyID returns Authority Key Identifier
func GetIssuerID ¶
func GetIssuerID(c *x509.Certificate) string
GetIssuerID returns ID of the issuer. If present, it uses Authority Key Identifier, otherwise SHA1 of the Issuer name
func GetKeyDERFromPEM ¶
GetKeyDERFromPEM parses a PEM-encoded private key and returns DER-format key bytes, decrypting it with password when it is encrypted. Encrypted PKCS#8 keys are supported only with PBES2, PBKDF2 (HMAC-SHA1, -SHA224, -SHA256, -SHA384 or -SHA512, at most 10,000,000 iterations) and AES-128/192/256-CBC, which OpenSSL 3 writes by default. Other PKCS#8 schemes (PBES1, PKCS#12 PBE, scrypt, DES) return an "unsupported PKCS#8 encryption" error (XPKI-043). The decrypted bytes are returned only when they are a PKCS#8 PrivateKeyInfo; otherwise, as for bad padding, the error matches x509.IncorrectPasswordError (XPKI-115).
func GetSubjectID ¶
func GetSubjectID(c *x509.Certificate) string
GetSubjectID returns ID of the cert. If present, it uses Subject Key Identifier, otherwise SHA1 of the Subject name
func GetSubjectKeyID ¶
func GetSubjectKeyID(c *x509.Certificate) string
GetSubjectKeyID returns Subject Key Identifier
func GetThumbprintStr ¶
func GetThumbprintStr(c *x509.Certificate) string
GetThumbprintStr returns hex-encoded SHA1 of the certificate
func HasOCSPNoCheck ¶
func HasOCSPNoCheck(crt *x509.Certificate) bool
HasOCSPNoCheck returns true if certificate has ocsp-no-check. Both Extensions (populated on a parsed certificate) and ExtraExtensions (populated on a template before signing) are inspected.
func HashAlgoToStr ¶
HashAlgoToStr converts hash algorithm to string
func HashToBase64URL ¶
HashToBase64URL returns Base64URL encoded digest
func IsOCSPSigner ¶
func IsOCSPSigner(crt *x509.Certificate) bool
IsOCSPSigner returns true for OCSP key usage
func IsPostQuantumCertificate ¶
func IsPostQuantumCertificate(crt *x509.Certificate) bool
IsPostQuantumCertificate reports whether crt carries a post-quantum public key or is signed with a post-quantum signature algorithm, so a chain that mixes classical and ML-DSA keys is detected at either end. A nil certificate is not post-quantum.
func IsPostQuantumKey ¶
IsPostQuantumKey reports whether key is a post-quantum (ML-DSA) key: an *mldsa.PublicKey or *mldsa.PrivateKey, or a crypto.Signer or crypto.Decrypter, such as an HSM or KMS key, whose Public() is one. A nil key is not post-quantum.
func IsPostQuantumSignatureAlgorithm ¶
func IsPostQuantumSignatureAlgorithm(algo x509.SignatureAlgorithm) bool
IsPostQuantumSignatureAlgorithm reports whether algo is a post-quantum X.509 signature algorithm: ML-DSA-44, ML-DSA-65 or ML-DSA-87.
func LoadAndVerifyBundleFromPEM ¶
func LoadAndVerifyBundleFromPEM(certFile, intCAFile, rootFile string, opt ...Option) (*Bundle, *BundleStatus, error)
LoadAndVerifyBundleFromPEM constructs and verifies the cert chain
func LoadChainFromPEM ¶
func LoadChainFromPEM(certFile string) ([]*x509.Certificate, error)
LoadChainFromPEM returns Certificates loaded from the file
func LoadFromPEM ¶
func LoadFromPEM(certFile string) (*x509.Certificate, error)
LoadFromPEM returns Certificate loaded from the file
func LoadPEMFiles ¶
LoadPEMFiles loads and concatenates PEM files into one slice
func NameToString ¶
NameToString converts Name to string, compatible with openssl output
func ParseChainFromPEM ¶
func ParseChainFromPEM(certificateChainPem []byte) ([]*x509.Certificate, error)
ParseChainFromPEM returns Certificates parsed from PEM
func ParseFromPEM ¶
func ParseFromPEM(bytes []byte) (*x509.Certificate, error)
ParseFromPEM returns Certificate parsed from PEM
func ParseHexDigestWithPrefix ¶
ParseHexDigestWithPrefix parses encoded digest in {alg}:{hex} format
func ParseOCSPResponse ¶
ParseOCSPResponse parses and verifies a DER encoded OCSP response that holds one status, as ParseOCSPResponseForCert with no certificate.
func ParseOCSPResponseForCert ¶
ParseOCSPResponseForCert parses a DER encoded OCSP response and returns the status of cert, as ocsp.ParseResponseForCert does, and also verifies a response signed with ML-DSA, which that function cannot. A response with an embedded certificate is verified with that certificate's key and, when issuer is set, the certificate with the issuer's key; without one, the response is verified with the issuer's key when issuer is set. With no embedded certificate and no issuer the signature is not checked. A status other than successful is an ocsp.ResponseError in the error chain, and a signature that does not verify an ocsp.ParseError, for ML-DSA too. Response.SignatureAlgorithm is x509.MLDSA44, MLDSA65 or MLDSA87 for an ML-DSA response, so Response.CheckSignatureFrom works on it.
Like golang.org/x/crypto/ocsp, it does not check that an embedded certificate is authorized to answer for the issuer (the OCSP signing EKU of RFC 6960 §4.2.2.2) or is within its validity, or that the CertID names the issuer: any certificate the issuer signed can sign an accepted response. A caller that relies on the status checks that with VerifyOCSPResponder.
func ParsePrivateKeyDER ¶
ParsePrivateKeyDER parses a PKCS #1, PKCS #8, ECDSA, Ed25519 or ML-DSA DER-encoded private key. The key must not be in PEM format. An ML-DSA key must be in the PKCS #8 seed form (RFC 9881), which x509.MarshalPKCS8PrivateKey and "openssl genpkey -provparam ml-dsa.output_formats=seed-only" write; the form holding both the seed and the expanded key is rejected.
func ParsePrivateKeyPEM ¶
ParsePrivateKeyPEM parses and returns a PEM-encoded private key. The private key may be either an unencrypted PKCS#8, PKCS#1, or elliptic private key.
func ParsePrivateKeyPEMWithPassword ¶
ParsePrivateKeyPEMWithPassword parses and returns a PEM-encoded private key. The private key may be an unencrypted PKCS#8, PKCS#1, or SEC1 key, a legacy PEM block encrypted per RFC 1423 (Proc-Type: 4,ENCRYPTED), or an encrypted PKCS#8 key (ENCRYPTED PRIVATE KEY) as described by GetKeyDERFromPEM. The key may be RSA, ECDSA, Ed25519 or ML-DSA (the last two PKCS#8 only). A nil password fails for an encrypted key; a wrong password returns an error that matches x509.IncorrectPasswordError.
func ParsePublicKeyFromPEM ¶
ParsePublicKeyFromPEM parses a PEM encoded public key in the SubjectPublicKeyInfo form (RFC 5280), or a PKCS#1 RSA public key. It returns what x509.ParsePKIXPublicKey does, so any type that function supports, including *ecdh.PublicKey and *dsa.PublicKey, which cannot verify a modern signature: a caller that needs a signature key checks the type.
func ParseRSAPublicKeyFromPEM ¶
ParseRSAPublicKeyFromPEM parses PEM encoded RSA public key
func RandomString ¶
RandomString returns a random string of the given length over [0-9A-Za-z]. It panics if the random source fails.
func SHA256Base64 ¶
SHA256Base64 returns Base64URL encoded SHA256
func StrToHashAlgo ¶
StrToHashAlgo converts string to hash algorithm
func VerifyBundleFromPEM ¶
func VerifyBundleFromPEM(certPEM, intCAPEM, rootPEM []byte, opt ...Option) (bundle *Bundle, status *BundleStatus, err error)
VerifyBundleFromPEM constructs and verifies the cert chain
func VerifyOCSPResponder ¶ added in v2.0.328
func VerifyOCSPResponder(res *ocsp.Response, issuer *x509.Certificate) error
VerifyOCSPResponder checks that res, a response read by ParseOCSPResponse, ParseOCSPResponseForCert or golang.org/x/crypto/ocsp, answers for a certificate of issuer and was signed by a responder that RFC 6960 §4.2.2.2 authorizes to answer for it. The parsers check only signatures, so without this check any certificate the issuer signed, a client certificate for example, can sign a good status for any serial number of the issuer. The rules, for classical and ML-DSA responses alike:
- with no embedded certificate, or one with the issuer's key, the issuer's key must verify the response;
- any other embedded certificate (the first, the one the parsers use) is a delegated responder: its issuer name and signature are the issuer's, it has the OCSP signing extended key usage (anyExtendedKeyUsage does not count), it is valid now, and its key must verify the response;
- the CertID of the status res reports, the first response for res.SerialNumber, carries the hashes of the issuer's name and key.
The signatures are verified again, so res read without an issuer is checked too. A responder is checked against the current time rather than ThisUpdate, so the key of an expired responder cannot sign a response dated within its validity. The caller still checks the issuer itself (its chain, validity and revocation), the revocation of a delegated responder that lacks id-pkix-ocsp-nocheck, the freshness of ThisUpdate and NextUpdate, and a responder it trusts locally (the first case of §4.2.2.2), which this function rejects unless it is the issuer.
Types ¶
type Bundle ¶
type Bundle struct {
// Chain does not include the root anchor
Chain []*x509.Certificate
Cert *x509.Certificate
IssuerCert *x509.Certificate
RootCert *x509.Certificate
Issuer *pkix.Name
Subject *pkix.Name
IssuerID string
SubjectID string
Expires time.Time
Hostnames []string
CertPEM string
CACertsPEM string
RootCertPEM string
}
A Bundle contains a certificate and its trust chain. It is intended to store the most widely applicable chain, with shortness an explicit goal.
func SortBundlesByExpiration ¶
SortBundlesByExpiration returns a new slice of bundles sorted by Expires in descending order. The sort is stable, so bundles with the same Expires keep their input order, and nil bundles go last. The caller's slice is not reordered; the bundles themselves are shared (XPKI-038).
func (*Bundle) ExpiresInHours ¶
ExpiresInHours returns the time until Expires truncated toward zero to whole hours: 90 minutes is 1h, and an expiry 90 minutes ago is -1h (XPKI-045).
type BundleFlavor ¶
type BundleFlavor string
BundleFlavor is named optimization strategy on certificate chain selection when bundling.
const ( // Optimal means the shortest chain with newest intermediates and // the most advanced crypto. Optimal BundleFlavor = "optimal" // Force means the bundler only verifies the input as a valid bundle, not optimization is done. Force BundleFlavor = "force" )
type BundleStatus ¶
type BundleStatus struct {
// A list of SKIs of expiring certificates
ExpiringSKIs []string `json:"expiring_SKIs"`
// A list of untrusted root store names
Untrusted []string `json:"untrusted_root_stores"`
// A list of human readable warning messages based on the bundle status.
Messages []string `json:"messages"`
Code int `json:"code"`
}
BundleStatus is designated for various status reporting.
func (*BundleStatus) IsExpiring ¶
func (b *BundleStatus) IsExpiring() bool
IsExpiring returns true if bundle is expiring in less than 30 days
func (*BundleStatus) IsUntrusted ¶
func (b *BundleStatus) IsUntrusted() bool
IsUntrusted returns true if the cert's issuers are not trusted
type Bundler ¶
type Bundler struct {
// contains filtered or unexported fields
}
A Bundler contains the certificate pools for producing certificate bundles. It contains any intermediates and root certificates that should be used.
A Bundler is safe for concurrent use. Intermediates learned over AIA are shared by later calls: they are published by replacing the intermediate pool and the known issuers with updated copies, so a pool or map once read is never modified (XPKI-035). RootPool, IntermediatePool, IsKnownIssuer and VerifyOptions read the current ones.
func LoadBundler ¶
LoadBundler creates a new Bundler from the files passed in; these files should contain a list of valid root certificates and a list of valid intermediate certificates, respectively.
func NewBundler ¶
func NewBundler(roots, intermediates []*x509.Certificate, opt ...Option) (*Bundler, error)
NewBundler returns a Bundler that trusts roots, plus the system roots with WithSystemRoots, and uses intermediates to build chains. The flavor defaults to Optimal with trust roots and to Force without them; Optimal without trust roots is an error, so a Bundler never trusts system roots implicitly. The root pool is nil only when there are no trust roots.
func NewBundlerFromPEM ¶
NewBundlerFromPEM creates a new Bundler from PEM-encoded root certificates and intermediate certificates. Without root certificates the default flavor is Force; see NewBundler.
func (*Bundler) Bundle ¶
Bundle takes an X509 certificate (already in the Certificate structure), a private key as crypto.Signer in one of the appropriate formats (i.e. *rsa.PrivateKey, *ecdsa.PrivateKey or *mldsa.PrivateKey, or even an opaque key), using them to build a certificate bundle. certs[0] is the leaf (a reversed chain is detected); its key must be RSA, ECDSA or ML-DSA. A nil or empty certs returns an error matching ErrNoCertificates, and a nil entry returns an error (XPKI-036).
func (*Bundler) BundleContext ¶
func (b *Bundler) BundleContext(ctx context.Context, certs []*x509.Certificate, key crypto.Signer) (*Chain, error)
BundleContext is Bundle with a context that bounds and cancels AIA downloads. When ctx is done during an AIA download, the returned error matches ctx.Err() with errors.Is. An Optimal Bundler without trust roots fails instead of verifying against the system roots.
func (*Bundler) ChainFromFile ¶
ChainFromFile takes a set of files containing the PEM-encoded leaf certificate (optionally along with some intermediate certs), the PEM-encoded private key and returns the bundle built from that key and the certificate(s).
func (*Bundler) ChainFromPEM ¶
ChainFromPEM builds a certificate chain from the set of byte slices containing the PEM or DER-encoded certificate(s), private key.
func (*Bundler) ChainFromPEMContext ¶
func (b *Bundler) ChainFromPEMContext(ctx context.Context, certsRaw, keyPEM []byte, password string) (*Chain, error)
ChainFromPEMContext is ChainFromPEM with a context that bounds and cancels AIA downloads; see BundleContext.
func (*Bundler) IntermediatePool ¶
IntermediatePool returns a copy of the intermediates known now: those the Bundler was created with and those it has learned over AIA since.
func (*Bundler) IsKnownIssuer ¶
func (b *Bundler) IsKnownIssuer(cert *x509.Certificate) bool
IsKnownIssuer reports whether cert is one of the roots or intermediates the Bundler knows now.
func (*Bundler) RootPool ¶
RootPool returns a copy of the trust roots, which is empty when the Bundler has none.
func (*Bundler) VerifyOptions ¶
func (b *Bundler) VerifyOptions() x509.VerifyOptions
VerifyOptions returns the x509.VerifyOptions used by Optimal bundling. Roots is never nil: without trust roots it is an empty pool, so the options never fall back to the system roots. It is a snapshot: intermediates learned later are not added to it.
type Chain ¶
type Chain struct {
Chain []*x509.Certificate
Cert *x509.Certificate
Root *x509.Certificate
Key any
Issuer *pkix.Name
Subject *pkix.Name
Expires time.Time
LeafExpires time.Time
Hostnames []string
Status *BundleStatus
}
Chain contains a certificate and its trust chain. It is intended to store the most widely applicable chain, with shortness an explicit goal.
type KeyInfo ¶
KeyInfo provides information about the key: Type is KeyTypeRSA, KeyTypeECDSA or KeyTypeMLDSA; KeySize is the RSA modulus or ECDSA curve size in bits, or the ML-DSA parameter set number (44, 65 or 87); Hash is the digest a hash-then-sign caller uses with the key, and zero for an ML-DSA key, which signs the message itself.
func NewKeyInfo ¶
NewKeyInfo returns the KeyInfo of k: an RSA, ECDSA or ML-DSA private key, public key, crypto.Signer or crypto.Decrypter (an HSM or KMS key, whose Public() is inspected) or a JWK holding one of them. IsPrivate is set only for an in-memory private key.
type Option ¶
type Option func(*options)
An Option sets options such as allowed key usages, etc.
func WithBundleFlavor ¶
func WithBundleFlavor(flavor BundleFlavor) Option
WithBundleFlavor selects Optimal or Force chain building. Without this option the flavor is Optimal when the Bundler has trust roots (explicit roots or WithSystemRoots) and Force otherwise. NewBundler rejects Optimal without trust roots and any other flavor value; the last option wins.
func WithHTTPClient ¶
WithHTTPClient sets the client for AIA downloads. Each request is bounded by the client's Timeout, or 3s when it is zero, and by the context given to BundleContext. Only a 200 response of at most 1 MiB is parsed. Without this option a client with a 3s timeout is used.
func WithKeyUsages ¶
func WithKeyUsages(usages ...x509.ExtKeyUsage) Option
WithKeyUsages lets you set which Extended Key Usage values are acceptable. By default x509.ExtKeyUsageAny will be used.
func WithSystemRoots ¶
WithSystemRoots adds the platform trust store (x509.SystemCertPool) to the explicit roots. It is the only way a Bundler trusts system roots: without it, Optimal verification uses the explicit roots alone (XPKI-041).