Documentation
¶
Overview ¶
This file contains some code copied from the Go standard library under the following license: https://github.com/golang/go/blob/c95fe91d0715dc0a8d55ac80a80f383c3635548b/LICENSE
Index ¶
- Constants
- Variables
- func BuildKeyUsagesKube(usages []certificatesv1.KeyUsage) (x509.KeyUsage, []x509.ExtKeyUsage, error)
- func CertificateTemplateFromCSR(csr *x509.CertificateRequest, ...) (*x509.Certificate, error)
- func CertificateTemplateFromCSRPEM(csrPEM []byte, validatorMutators ...CertificateTemplateValidatorMutator) (*x509.Certificate, error)
- func CertificateTemplateFromCertificate(crt *v1.Certificate) (*x509.Certificate, error)
- func CertificateTemplateFromCertificateRequest(cr *v1.CertificateRequest) (*x509.Certificate, error)
- func CertificateTemplateFromCertificateSigningRequest(csr *certificatesv1.CertificateSigningRequest) (*x509.Certificate, error)
- func DecodePrivateKeyBytes(keyBytes []byte) (crypto.Signer, error)
- func DecodeX509CertificateBytes(certBytes []byte) (*x509.Certificate, error)
- func DecodeX509CertificateChainBytes(certBytes []byte) ([]*x509.Certificate, error)
- func DecodeX509CertificateRequestBytes(csrBytes []byte) (*x509.CertificateRequest, error)
- func DecodeX509CertificateSetBytes(certBytes []byte) ([]*x509.Certificate, error)
- func DurationFromCertificateSigningRequest(csr *certificatesv1.CertificateSigningRequest) (time.Duration, error)
- func EncodeCSR(template *x509.CertificateRequest, key crypto.Signer) ([]byte, error)
- func EncodeECPrivateKey(pk *ecdsa.PrivateKey) ([]byte, error)
- func EncodePKCS1PrivateKey(pk *rsa.PrivateKey) []byte
- func EncodePKCS8PrivateKey(pk interface{}) ([]byte, error)
- func EncodePrivateKey(pk crypto.PrivateKey, keyEncoding v1.PrivateKeyEncoding) ([]byte, error)
- func EncodeX509(cert *x509.Certificate) ([]byte, error)
- func EncodeX509Chain(certs []*x509.Certificate) ([]byte, error)
- func ExtKeyUsageFromOID(oid asn1.ObjectIdentifier) (eku x509.ExtKeyUsage, ok bool)
- func ExtractCommonNameFromRDNSequence(rdns pkix.RDNSequence) string
- func FuzzyX509AltNamesMatchSpec(x509cert *x509.Certificate, spec cmapi.CertificateSpec) []stringdeprecated
- func GenerateCSR(crt *v1.Certificate, optFuncs ...GenerateCSROption) (*x509.CertificateRequest, error)
- func GenerateECPrivateKey(keySize int) (*ecdsa.PrivateKey, error)
- func GenerateEd25519PrivateKey() (ed25519.PrivateKey, error)
- func GenerateLocallySignedTemporaryCertificate(crt *cmapi.Certificate, pkData []byte) ([]byte, error)
- func GeneratePrivateKeyForCertificate(crt *v1.Certificate) (crypto.Signer, error)
- func GenerateRSAPrivateKey(keySize int) (*rsa.PrivateKey, error)
- func IPAddressesFromStrings(ipStrings []string) ([]net.IP, error)
- func IPAddressesToString(ipAddresses []net.IP) []string
- func IsASN1SubjectEmpty(asn1Subject []byte) bool
- func KeyUsagesForCertificateOrCertificateRequest(usages []v1.KeyUsage, isCA bool) (ku x509.KeyUsage, eku []x509.ExtKeyUsage, err error)
- func MarshalBasicConstraints(isCA bool, maxPathLen *int) (pkix.Extension, error)
- func MarshalExtKeyUsage(extUsages []x509.ExtKeyUsage, unknownUsages []asn1.ObjectIdentifier) (pkix.Extension, error)
- func MarshalKeyUsage(usage x509.KeyUsage) (pkix.Extension, error)
- func MarshalNameConstraints(nameConstraints *NameConstraints, critical bool) (pkix.Extension, error)
- func MarshalRDNSequenceToRawDERBytes(rdnSequence pkix.RDNSequence) ([]byte, error)
- func MarshalSANs(gns GeneralNames, hasSubject bool) (pkix.Extension, error)
- func MarshalUniversalValue(uv UniversalValue) ([]byte, error)
- func OIDFromExtKeyUsage(eku x509.ExtKeyUsage) (oid asn1.ObjectIdentifier, ok bool)
- func ParseObjectIdentifier(oidString string) (oid asn1.ObjectIdentifier, err error)
- func PrivateKeyMatchesSpec(pk crypto.PrivateKey, spec cmapi.CertificateSpec) []string
- func PublicKeyForPrivateKey(pk crypto.PrivateKey) (crypto.PublicKey, error)
- func PublicKeyMatchesCSR(check crypto.PublicKey, csr *x509.CertificateRequest) (bool, error)
- func PublicKeyMatchesCertificate(check crypto.PublicKey, crt *x509.Certificate) (bool, error)
- func PublicKeysEqual(a, b crypto.PublicKey) (bool, error)
- func RenewBefore(actualDuration time.Duration, renewBefore *metav1.Duration, ...) time.Duration
- func RenewalTime(notBefore, notAfter time.Time, renewBefore *metav1.Duration, ...) *metav1.Time
- func RequestMatchesSpec(req *cmapi.CertificateRequest, spec cmapi.CertificateSpec) ([]string, error)
- func SignCertificate(template *x509.Certificate, issuerCert *x509.Certificate, ...) ([]byte, *x509.Certificate, error)
- func SignatureAlgorithm(crt *v1.Certificate) (x509.PublicKeyAlgorithm, x509.SignatureAlgorithm, error)
- func SubjectForCertificate(crt *v1.Certificate) v1.X509Subject
- func URLsToString(uris []*url.URL) []string
- func UnmarshalBasicConstraints(value []byte) (isCA bool, maxPathLen *int, err error)
- func UnmarshalExtKeyUsage(value []byte) (extUsages []x509.ExtKeyUsage, unknownUsages []asn1.ObjectIdentifier, err error)
- func UnmarshalKeyUsage(value []byte) (usage x509.KeyUsage, err error)
- func UnmarshalRawDerBytesToRDNSequence(der []byte) (rdnSequence pkix.RDNSequence, err error)
- func UnmarshalSubjectStringToRDNSequence(subject string) (pkix.RDNSequence, error)
- type CertificateTemplateValidatorMutator
- func CertificateTemplateOverrideDuration(duration time.Duration) CertificateTemplateValidatorMutator
- func CertificateTemplateValidateAndOverrideBasicConstraints(isCA bool, maxPathLen *int) CertificateTemplateValidatorMutator
- func CertificateTemplateValidateAndOverrideKeyUsages(keyUsage x509.KeyUsage, extKeyUsage []x509.ExtKeyUsage) CertificateTemplateValidatorMutator
- type EDIPartyName
- type GeneralNames
- type GenerateCSROption
- type NameConstraints
- type OtherName
- type PEMBundle
- type RenewalTimeFunc
- type UniversalValue
- type UniversalValueType
Constants ¶
const ( // MinRSAKeySize is the minimum RSA keysize allowed to be generated by the // generator functions in this package. MinRSAKeySize = 2048 // MaxRSAKeySize is the maximum RSA keysize allowed to be generated by the // generator functions in this package. MaxRSAKeySize = 8192 // ECCurve256 represents a secp256r1 / prime256v1 / NIST P-256 ECDSA key. ECCurve256 = 256 // ECCurve384 represents a secp384r1 / NIST P-384 ECDSA key. ECCurve384 = 384 // ECCurve521 represents a secp521r1 / NIST P-521 ECDSA key. ECCurve521 = 521 )
Variables ¶
var ( OIDExtensionKeyUsage = []int{2, 5, 29, 15} OIDExtensionExtendedKeyUsage = []int{2, 5, 29, 37} )
Copied from x509.go
var OIDConstants = struct { Country []int Organization []int OrganizationalUnit []int CommonName []int SerialNumber []int Locality []int Province []int StreetAddress []int DomainComponent []int UniqueIdentifier []int }{ Country: []int{2, 5, 4, 6}, Organization: []int{2, 5, 4, 10}, OrganizationalUnit: []int{2, 5, 4, 11}, CommonName: []int{2, 5, 4, 3}, SerialNumber: []int{2, 5, 4, 5}, Locality: []int{2, 5, 4, 7}, Province: []int{2, 5, 4, 8}, StreetAddress: []int{2, 5, 4, 9}, DomainComponent: []int{0, 9, 2342, 19200300, 100, 1, 25}, UniqueIdentifier: []int{0, 9, 2342, 19200300, 100, 1, 1}, }
var (
OIDExtensionBasicConstraints = []int{2, 5, 29, 19}
)
Copied from x509.go
var (
OIDExtensionNameConstraints = []int{2, 5, 29, 30}
)
Copied from x509.go
Functions ¶
func BuildKeyUsagesKube ¶ added in v1.8.0
func BuildKeyUsagesKube(usages []certificatesv1.KeyUsage) (x509.KeyUsage, []x509.ExtKeyUsage, error)
BuildKeyUsagesKube returns a key usage and extended key usage of the x509 certificate
func CertificateTemplateFromCSR ¶ added in v1.13.0
func CertificateTemplateFromCSR(csr *x509.CertificateRequest, validatorMutators ...CertificateTemplateValidatorMutator) (*x509.Certificate, error)
CertificateTemplateFromCSR will create a x509.Certificate for the given *x509.CertificateRequest.
func CertificateTemplateFromCSRPEM ¶ added in v1.13.0
func CertificateTemplateFromCSRPEM(csrPEM []byte, validatorMutators ...CertificateTemplateValidatorMutator) (*x509.Certificate, error)
CertificateTemplateFromCSRPEM will create a x509.Certificate for the given csrPEM.
func CertificateTemplateFromCertificate ¶ added in v1.13.0
func CertificateTemplateFromCertificate(crt *v1.Certificate) (*x509.Certificate, error)
CertificateTemplateFromCertificate will create a x509.Certificate for the given Certificate resource
func CertificateTemplateFromCertificateRequest ¶ added in v1.13.0
func CertificateTemplateFromCertificateRequest(cr *v1.CertificateRequest) (*x509.Certificate, error)
CertificateTemplateFromCertificateRequest will create a x509.Certificate for the given CertificateRequest resource
func CertificateTemplateFromCertificateSigningRequest ¶ added in v1.13.0
func CertificateTemplateFromCertificateSigningRequest(csr *certificatesv1.CertificateSigningRequest) (*x509.Certificate, error)
CertificateTemplateFromCertificateSigningRequest will create a x509.Certificate for the given CertificateSigningRequest resource
func DecodePrivateKeyBytes ¶
DecodePrivateKeyBytes will decode a PEM encoded private key into a crypto.Signer. It supports ECDSA, RSA and EdDSA private keys only. All other types will return err.
func DecodeX509CertificateBytes ¶
func DecodeX509CertificateBytes(certBytes []byte) (*x509.Certificate, error)
DecodeX509CertificateBytes will decode a PEM encoded x509 Certificate.
func DecodeX509CertificateChainBytes ¶ added in v0.6.0
func DecodeX509CertificateChainBytes(certBytes []byte) ([]*x509.Certificate, error)
DecodeX509CertificateChainBytes will decode a PEM encoded x509 Certificate chain.
func DecodeX509CertificateRequestBytes ¶ added in v1.8.0
func DecodeX509CertificateRequestBytes(csrBytes []byte) (*x509.CertificateRequest, error)
DecodeX509CertificateRequestBytes will decode a PEM encoded x509 Certificate Request.
func DecodeX509CertificateSetBytes ¶ added in v1.12.9
func DecodeX509CertificateSetBytes(certBytes []byte) ([]*x509.Certificate, error)
DecodeX509CertificateSetBytes will decode a concatenated set of PEM encoded x509 Certificates.
func DurationFromCertificateSigningRequest ¶ added in v1.8.0
func DurationFromCertificateSigningRequest(csr *certificatesv1.CertificateSigningRequest) (time.Duration, error)
DurationFromCertificateSigningRequest returns the duration that the user may have requested using the annotation "experimental.cert-manager.io/request-duration" or via the CSR spec.expirationSeconds field (the annotation is preferred since it predates the field which is only available in Kubernetes v1.22+). Returns the cert-manager default certificate duration when the user hasn't provided the annotation or spec.expirationSeconds.
func EncodeCSR ¶
EncodeCSR calls x509.CreateCertificateRequest to sign the given CSR template. It returns a DER encoded signed CSR.
func EncodeECPrivateKey ¶
func EncodeECPrivateKey(pk *ecdsa.PrivateKey) ([]byte, error)
EncodeECPrivateKey will marshal an ECDSA private key into x509 PEM format.
func EncodePKCS1PrivateKey ¶
func EncodePKCS1PrivateKey(pk *rsa.PrivateKey) []byte
EncodePKCS1PrivateKey will marshal a RSA private key into x509 PEM format.
func EncodePKCS8PrivateKey ¶ added in v0.7.0
EncodePKCS8PrivateKey will marshal a private key into x509 PEM format.
func EncodePrivateKey ¶
func EncodePrivateKey(pk crypto.PrivateKey, keyEncoding v1.PrivateKeyEncoding) ([]byte, error)
EncodePrivateKey will encode a given crypto.PrivateKey by first inspecting the type of key encoding and then inspecting the type of key provided. It only supports encoding RSA or ECDSA keys.
func EncodeX509 ¶
func EncodeX509(cert *x509.Certificate) ([]byte, error)
EncodeX509 will encode a single *x509.Certificate into PEM format.
func EncodeX509Chain ¶ added in v0.6.0
func EncodeX509Chain(certs []*x509.Certificate) ([]byte, error)
EncodeX509Chain will encode a list of *x509.Certificates into a PEM format chain. Self-signed certificates are not included as per https://datatracker.ietf.org/doc/html/rfc5246#section-7.4.2 Certificates are output in the order they're given; if the input is not ordered as specified in RFC5246 section 7.4.2, the resulting chain might not be valid for use in TLS.
func ExtKeyUsageFromOID ¶ added in v1.8.0
func ExtKeyUsageFromOID(oid asn1.ObjectIdentifier) (eku x509.ExtKeyUsage, ok bool)
func ExtractCommonNameFromRDNSequence ¶ added in v1.14.0
func ExtractCommonNameFromRDNSequence(rdns pkix.RDNSequence) string
func FuzzyX509AltNamesMatchSpec
deprecated
added in
v1.16.0
func FuzzyX509AltNamesMatchSpec(x509cert *x509.Certificate, spec cmapi.CertificateSpec) []string
FuzzyX509AltNamesMatchSpec will compare a X509 Certificate to a CertificateSpec and return a list of 'violations' for any fields that do not match their counterparts.
This is a purposely less comprehensive check than RequestMatchesSpec as some issuers override/force certain fields.
Deprecated: This function is very fuzzy and makes too many assumptions about how the issuer maps a CSR to a certificate. We only keep it for backward compatibility reasons, but use other comparison functions when possible.
func GenerateCSR ¶
func GenerateCSR(crt *v1.Certificate, optFuncs ...GenerateCSROption) (*x509.CertificateRequest, error)
GenerateCSR will generate a new *x509.CertificateRequest template to be used by issuers that utilise CSRs to obtain Certificates. The CSR will not be signed, and should be passed to either EncodeCSR or to the x509.CreateCertificateRequest function.
func GenerateECPrivateKey ¶
func GenerateECPrivateKey(keySize int) (*ecdsa.PrivateKey, error)
GenerateECPrivateKey will generate an ECDSA private key of the given size. It can be used to generate 256, 384 and 521 sized keys.
func GenerateEd25519PrivateKey ¶ added in v1.8.0
func GenerateEd25519PrivateKey() (ed25519.PrivateKey, error)
GenerateEd25519PrivateKey will generate an Ed25519 private key
func GenerateLocallySignedTemporaryCertificate ¶ added in v1.12.0
func GenerateLocallySignedTemporaryCertificate(crt *cmapi.Certificate, pkData []byte) ([]byte, error)
GenerateLocallySignedTemporaryCertificate signs a temporary certificate for the given certificate resource using a one-use temporary CA that is then discarded afterwards. This is to mitigate a potential attack against x509 certificates that use a predictable serial number and weak MD5 hashing algorithms. In practice, this shouldn't really be a concern anyway.
func GeneratePrivateKeyForCertificate ¶
func GeneratePrivateKeyForCertificate(crt *v1.Certificate) (crypto.Signer, error)
GeneratePrivateKeyForCertificate will generate a private key suitable for the provided cert-manager Certificate resource, taking into account the parameters on the provided resource. The returned key will either be RSA or ECDSA.
func GenerateRSAPrivateKey ¶
func GenerateRSAPrivateKey(keySize int) (*rsa.PrivateKey, error)
GenerateRSAPrivateKey will generate a RSA private key of the given size. It places restrictions on the minimum and maximum RSA keysize.
func IPAddressesFromStrings ¶ added in v1.14.0
func IPAddressesToString ¶ added in v0.7.0
IPAddressesToString converts a slice of IP addresses to strings, which can be useful for printing a list of addresses but MUST NOT be used for comparing two slices of IP addresses.
func IsASN1SubjectEmpty ¶ added in v1.14.2
func KeyUsagesForCertificateOrCertificateRequest ¶ added in v1.12.0
func MarshalBasicConstraints ¶ added in v1.12.0
Adapted from x509.go
func MarshalExtKeyUsage ¶ added in v1.12.0
func MarshalExtKeyUsage(extUsages []x509.ExtKeyUsage, unknownUsages []asn1.ObjectIdentifier) (pkix.Extension, error)
Adapted from x509.go
func MarshalKeyUsage ¶ added in v1.12.0
Adapted from x509.go
func MarshalNameConstraints ¶ added in v1.14.0
func MarshalNameConstraints(nameConstraints *NameConstraints, critical bool) (pkix.Extension, error)
Adapted from x509.go
func MarshalRDNSequenceToRawDERBytes ¶ added in v1.12.0
func MarshalRDNSequenceToRawDERBytes(rdnSequence pkix.RDNSequence) ([]byte, error)
func MarshalSANs ¶ added in v1.14.0
func MarshalSANs(gns GeneralNames, hasSubject bool) (pkix.Extension, error)
adapted from https://cs.opensource.google/go/go/+/master:src/crypto/x509/x509.go;l=1059-1103;drc=e2d9574b14b3db044331da0c6fadeb62315c644a MarshalSANs marshals a list of addresses into the contents of an X.509 SubjectAlternativeName extension.
func MarshalUniversalValue ¶ added in v1.14.0
func MarshalUniversalValue(uv UniversalValue) ([]byte, error)
func OIDFromExtKeyUsage ¶ added in v1.8.0
func OIDFromExtKeyUsage(eku x509.ExtKeyUsage) (oid asn1.ObjectIdentifier, ok bool)
OIDFromExtKeyUsage returns the ASN1 Identifier for a x509.ExtKeyUsage
func ParseObjectIdentifier ¶ added in v1.14.0
func ParseObjectIdentifier(oidString string) (oid asn1.ObjectIdentifier, err error)
ParseObjectIdentifier parses an object identifier from its string representation.
func PrivateKeyMatchesSpec ¶ added in v1.12.0
func PrivateKeyMatchesSpec(pk crypto.PrivateKey, spec cmapi.CertificateSpec) []string
PrivateKeyMatchesSpec returns a list of violations for the provided private key against the provided CertificateSpec. It will return an empty list/ nil if there are no violations found. RSA, Ed25519 and ECDSA private keys are supported. The function panics if the CertificateSpec contains an unknown key algorithm, since this should have been caught by the CertificateSpec validation already.
func PublicKeyForPrivateKey ¶
func PublicKeyForPrivateKey(pk crypto.PrivateKey) (crypto.PublicKey, error)
PublicKeyForPrivateKey will return the crypto.PublicKey for the given crypto.PrivateKey. It only supports RSA and ECDSA keys.
func PublicKeyMatchesCSR ¶
PublicKeyMatchesCSR can be used to verify the given public key matches the public key in the given x509.CertificateRequest. Returns false and no error if the given public key is *not* the same as the CSR's key Returns true and no error if the given public key *is* the same as the CSR's key Returns an error if the CSR's key type cannot be determined (i.e. non RSA/ECDSA keys)
func PublicKeyMatchesCertificate ¶
PublicKeyMatchesCertificate checks whether the given public key matches the public key in the given x509.Certificate. Returns false and no error if the public key is *not* the same as the certificate's key Returns true and no error if the public key *is* the same as the certificate's key Returns an error if the certificate's key type cannot be determined (i.e. non RSA/ECDSA keys)
func PublicKeysEqual ¶ added in v1.8.0
PublicKeysEqual compares two given public keys for equality. The definition of "equality" depends on the type of the public keys. Returns true if the keys are the same, false if they differ or an error if the key type of `a` cannot be determined.
func RenewBefore ¶ added in v1.16.0
func RenewBefore(actualDuration time.Duration, renewBefore *metav1.Duration, renewBeforePercentage *int32) time.Duration
RenewBefore calculates how far before expiry a certificate should be renewed. If renewBefore is non-nil and less than the certificate's lifetime, renewal time will be the computed renewBefore period before expiry. If renewBeforePercentage is non-nil and in the range (0,100), renewal time will be the computed period before expiry based on the renewBeforePercentage and actualDuration values. Default is 2/3 through certificate's lifetime.
func RenewalTime ¶ added in v1.12.0
func RenewalTime(notBefore, notAfter time.Time, renewBefore *metav1.Duration, renewBeforePercentage *int32) *metav1.Time
RenewalTime calculates renewal time for a certificate. If renewBefore is non-nil and less than the certificate's lifetime, renewal time will be the computed renewBefore period before expiry. If renewBeforePercentage is non-nil and in the range (0,100), renewal time will be the computed period before expiry based on the renewBeforePercentage value and certificate lifetime. Default renewal time is 2/3 through certificate's lifetime.
func RequestMatchesSpec ¶ added in v1.12.0
func RequestMatchesSpec(req *cmapi.CertificateRequest, spec cmapi.CertificateSpec) ([]string, error)
RequestMatchesSpec compares a CertificateRequest with a CertificateSpec and returns a list of field names on the Certificate that do not match their counterpart fields on the CertificateRequest. If decoding the x509 certificate request fails, an error will be returned.
func SignCertificate ¶
func SignCertificate(template *x509.Certificate, issuerCert *x509.Certificate, publicKey crypto.PublicKey, signerKey interface{}) ([]byte, *x509.Certificate, error)
SignCertificate returns a signed *x509.Certificate given a template *x509.Certificate crt and an issuer. publicKey is the public key of the signee, and signerKey is the private key of the signer. It returns a PEM encoded copy of the Certificate as well as a *x509.Certificate which can be used for reading the encoded values.
func SignatureAlgorithm ¶
func SignatureAlgorithm(crt *v1.Certificate) (x509.PublicKeyAlgorithm, x509.SignatureAlgorithm, error)
SignatureAlgorithm will determine the appropriate signature algorithm for the given certificate. Adapted from https://github.com/cloudflare/cfssl/blob/master/csr/csr.go#L102
func SubjectForCertificate ¶ added in v1.8.0
func SubjectForCertificate(crt *v1.Certificate) v1.X509Subject
SubjectForCertificate will return the Subject from the Certificate resource or an empty one if it is not set
func URLsToString ¶ added in v1.8.0
func UnmarshalBasicConstraints ¶ added in v1.13.0
Adapted from x509.go
func UnmarshalExtKeyUsage ¶ added in v1.13.0
func UnmarshalExtKeyUsage(value []byte) (extUsages []x509.ExtKeyUsage, unknownUsages []asn1.ObjectIdentifier, err error)
func UnmarshalKeyUsage ¶ added in v1.13.0
func UnmarshalRawDerBytesToRDNSequence ¶ added in v1.12.0
func UnmarshalRawDerBytesToRDNSequence(der []byte) (rdnSequence pkix.RDNSequence, err error)
func UnmarshalSubjectStringToRDNSequence ¶ added in v1.12.0
func UnmarshalSubjectStringToRDNSequence(subject string) (pkix.RDNSequence, error)
Types ¶
type CertificateTemplateValidatorMutator ¶ added in v1.13.0
type CertificateTemplateValidatorMutator func(*x509.CertificateRequest, *x509.Certificate) error
func CertificateTemplateOverrideDuration ¶ added in v1.13.0
func CertificateTemplateOverrideDuration(duration time.Duration) CertificateTemplateValidatorMutator
CertificateTemplateOverrideDuration returns a CertificateTemplateValidatorMutator that overrides the certificate duration.
func CertificateTemplateValidateAndOverrideBasicConstraints ¶ added in v1.13.0
func CertificateTemplateValidateAndOverrideBasicConstraints(isCA bool, maxPathLen *int) CertificateTemplateValidatorMutator
CertificateTemplateValidateAndOverrideBasicConstraints returns a CertificateTemplateValidatorMutator that overrides the certificate basic constraints.
func CertificateTemplateValidateAndOverrideKeyUsages ¶ added in v1.13.0
func CertificateTemplateValidateAndOverrideKeyUsages(keyUsage x509.KeyUsage, extKeyUsage []x509.ExtKeyUsage) CertificateTemplateValidatorMutator
CertificateTemplateValidateAndOverrideKeyUsages returns a CertificateTemplateValidatorMutator that overrides the certificate key usages.
type EDIPartyName ¶ added in v1.14.0
type EDIPartyName struct { NameAssigner string `asn1:"tag:0,optional"` PartyName string `asn1:"tag:1"` }
Based on RFC 5280, section 4.2.1.6 see https://datatracker.ietf.org/doc/html/rfc5280#section-4.2.1.6
EDIPartyName ::= SEQUENCE { nameAssigner [0] DirectoryString OPTIONAL, partyName [1] DirectoryString }
type GeneralNames ¶ added in v1.14.0
type GeneralNames struct { OtherNames []OtherName RFC822Names []string DNSNames []string X400Addresses []asn1.RawValue DirectoryNames []pkix.RDNSequence EDIPartyNames []EDIPartyName UniformResourceIdentifiers []string IPAddresses []net.IP RegisteredIDs []asn1.ObjectIdentifier }
func UnmarshalSANs ¶ added in v1.14.0
func UnmarshalSANs(value []byte) (GeneralNames, error)
func (GeneralNames) Empty ¶ added in v1.14.0
func (gns GeneralNames) Empty() bool
type GenerateCSROption ¶ added in v1.13.0
type GenerateCSROption func(*generateCSROptions)
func WithEncodeBasicConstraintsInRequest ¶ added in v1.13.0
func WithEncodeBasicConstraintsInRequest(encode bool) GenerateCSROption
WithEncodeBasicConstraintsInRequest determines whether the BasicConstraints extension should be encoded in the CSR. NOTE: this is a temporary option that will be removed in a future release.
func WithNameConstraints ¶ added in v1.14.0
func WithNameConstraints(enabled bool) GenerateCSROption
func WithOtherNames ¶ added in v1.14.0
func WithOtherNames(enabled bool) GenerateCSROption
func WithUseLiteralSubject ¶ added in v1.13.0
func WithUseLiteralSubject(useLiteralSubject bool) GenerateCSROption
type NameConstraints ¶ added in v1.14.0
type NameConstraints struct { PermittedDNSDomains []string ExcludedDNSDomains []string PermittedIPRanges []*net.IPNet ExcludedIPRanges []*net.IPNet PermittedEmailAddresses []string ExcludedEmailAddresses []string PermittedURIDomains []string ExcludedURIDomains []string }
NameConstraints represents the NameConstraints extension.
func UnmarshalNameConstraints ¶ added in v1.14.0
func UnmarshalNameConstraints(value []byte) (*NameConstraints, error)
Adapted from crypto/x509/parser.go
func (NameConstraints) IsEmpty ¶ added in v1.14.0
func (nc NameConstraints) IsEmpty() bool
type OtherName ¶ added in v1.14.0
type OtherName struct { TypeID asn1.ObjectIdentifier Value asn1.RawValue `asn1:"tag:0,explicit"` }
Based on RFC 5280, section 4.2.1.6 see https://datatracker.ietf.org/doc/html/rfc5280#section-4.2.1.6
OtherName ::= SEQUENCE { type-id OBJECT IDENTIFIER, value [0] EXPLICIT ANY DEFINED BY type-id }
type PEMBundle ¶ added in v1.8.0
PEMBundle includes the PEM encoded X.509 certificate chain and CA. CAPEM contains either 1 CA certificate, or is empty if only a single certificate exists in the chain.
func ParseSingleCertificateChain ¶ added in v1.8.0
func ParseSingleCertificateChain(certs []*x509.Certificate) (PEMBundle, error)
ParseSingleCertificateChain returns the PEM-encoded chain of certificates as well as the PEM-encoded CA certificate.
The CA (CAPEM) may not be a true root, but the highest intermediate certificate. The certificate is chosen as follows:
- If the chain has a self-signed root, the root certificate.
- If the chain has no self-signed root and has > 1 certificates, the highest certificate in the chain.
- If the chain has no self-signed root and has == 1 certificate, nil.
The certificate chain (ChainPEM) starts with the leaf certificate and ends with the highest certificate in the chain which is not self-signed. Self-signed certificates are not included in the chain because we are certain they are known and trusted by the client already.
This function removes duplicate certificate entries as well as comments and unnecessary white space.
An error is returned if the passed bundle is not a valid single chain, the bundle is malformed, or the chain is broken.
func ParseSingleCertificateChainPEM ¶ added in v1.8.0
ParseSingleCertificateChainPEM decodes a PEM encoded certificate chain before calling ParseSingleCertificateChainPEM
func SignCSRTemplate ¶ added in v1.8.0
func SignCSRTemplate(caCerts []*x509.Certificate, caKey crypto.Signer, template *x509.Certificate) (PEMBundle, error)
SignCSRTemplate signs a certificate template usually based upon a CSR. This function expects all fields to be present in the certificate template, including its public key. It returns the PEM bundle containing certificate data and the CA data, encoded in PEM format.
type RenewalTimeFunc ¶ added in v1.12.0
RenewalTimeFunc is a custom function type for calculating renewal time of a certificate.
type UniversalValue ¶ added in v1.14.0
type UniversalValue struct { Bytes []byte IA5String string UTF8String string PrintableString string }
func UnmarshalUniversalValue ¶ added in v1.14.0
func UnmarshalUniversalValue(rawValue asn1.RawValue) (UniversalValue, error)
func (UniversalValue) Type ¶ added in v1.14.0
func (uv UniversalValue) Type() UniversalValueType
type UniversalValueType ¶ added in v1.14.0
type UniversalValueType int
const ( UniversalValueTypeBytes UniversalValueType = iota UniversalValueTypeIA5String UniversalValueTypeUTF8String UniversalValueTypePrintableString )