initca

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: BSD-2-Clause Imports: 22 Imported by: 244 modules, 493 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package initca contains code to initialise a certificate authority, generating a new root key and certificate.

Index

Constants

This section is empty.

Variables

View Source
var CAPolicy = func() *config.Signing {
	return &config.Signing{
		Default: &config.SigningProfile{
			Usage:        []string{"cert sign", "crl sign"},
			ExpiryString: "43800h",
			Expiry:       5 * helpers.OneYear,
			CAConstraint: config.CAConstraint{IsCA: true},
		},
	}
}

CAPolicy contains the CA issuing policy as default policy.

Functions

func New

func New(req *csr.CertificateRequest) (cert, csrPEM, key []byte, err error)

New creates a new root certificate from the certificate request.

func NewFromPEM

func NewFromPEM(req *csr.CertificateRequest, keyFile string) (cert, csrPEM []byte, err error)

NewFromPEM creates a new root certificate from the key file passed in.

func NewFromSigner

func NewFromSigner(req *csr.CertificateRequest, priv crypto.Signer) (cert, csrPEM []byte, err error)

NewFromSigner creates a new root certificate from a crypto.Signer.

func NewUnsigned added in v1.7.2

func NewUnsigned(req *csr.CertificateRequest) (cert, key []byte, err error)

NewUnsigned is New followed by Unsign. req.RawSubject must be set; the returned certificate is an RFC 9925 unsigned root whose subject and issuer are req.RawSubject. req.Hosts is ignored, so the root has no SANs.

func NewUnsignedFromSigner added in v1.7.2

func NewUnsignedFromSigner(req *csr.CertificateRequest, priv crypto.Signer) (cert []byte, err error)

NewUnsignedFromSigner returns an RFC 9925 unsigned root for the public key of priv, with the same request rules as NewUnsigned. req.KeyRequest is ignored.

Most signers that do not hold the key they report fail earlier, when the CSR or the certificate is signed. After priv signs the certificate, the signature is checked under the certificate's own public key, which fails with a KeyMismatch error for a signer whose Public result changes between operations.

func RenewFromPEM

func RenewFromPEM(caFile, keyFile string) ([]byte, error)

RenewFromPEM re-creates a root certificate from the CA cert and key files. The resulting root certificate will have the input CA certificate as the template and have the same expiry length. E.g. the existing CA is valid for a year from Jan 01 2015 to Jan 01 2016, the renewed certificate will be valid from now and expire in one year as well.

func RenewFromSigner

func RenewFromSigner(ca *x509.Certificate, priv crypto.Signer) ([]byte, error)

RenewFromSigner re-creates a root certificate from the CA cert and crypto.Signer. The resulting root certificate will have ca certificate as the template and have the same expiry length. E.g. the existing CA is valid for a year from Jan 01 2015 to Jan 01 2016, the renewed certificate will be valid from now and expire in one year as well. An RFC 9925 unsigned certificate is rejected, because renewal would produce a signed certificate.

func Unsign added in v1.7.2

func Unsign(certPEM []byte) ([]byte, error)

Unsign converts a PEM-encoded certificate into an RFC 9925 unsigned certificate: TBSCertificate.signature and signatureAlgorithm become id-alg-unsigned with absent parameters and signatureValue becomes an empty BIT STRING. The authority key identifier and issuer alternative name extensions are removed, as RFC 9925, Section 3.3 says senders should omit them. All other fields, including the issuer, are preserved byte for byte.

The input can be a root, an intermediate or an end-entity certificate. The input signature is not verified, so the caller is responsible for deciding that the certificate is trusted, for example because it is about to be installed directly as a trust anchor. The input must parse as an X.509 version 3 certificate. A certificate whose issuer has no attributes is rejected, because X.509 and RFC 5280 forbid an empty issuer (RFC 9925, Section 3.2). A certificate with an issuerUniqueID is rejected, because RFC 9925, Section 3.2 requires senders to omit it.

func Update

func Update(ca *x509.Certificate, priv crypto.Signer) (cert []byte, err error)

Update copies the CA certificate, updates the NotBefore and NotAfter fields, and then re-signs the certificate.

Types

This section is empty.

Jump to

Keyboard shortcuts

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