tinyca

package
v1.21.8 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package tinyca implements a small and flexible Certificate Authority. The CA issues client certificates signed by a root certificate and private key.

tinyca exposes a simple HTTP API to issue certificates. tinyca is primarily meant to issue client certificates for mTLS authentication.

The CA also provides an interface to customize the certificate template. This allows applications to add application-specific data to issued certificates, along with the standard bifrost fields.

Index

Constants

View Source
const GauntletTimeout = 100 * time.Millisecond

GauntletTimeout is the maximum time the CA Gauntlet function is allowed to run.

View Source
const MaxIssueValidity = 30 * 24 * time.Hour

MaxIssueValidity is the maximum validity period for issued certificates.

Variables

This section is empty.

Functions

func CACertTemplate added in v1.16.8

func CACertTemplate(ns, id uuid.UUID) (*x509.Certificate, error)

CACertTemplate returns a new x509.Certificate template for a CA certificate.

func ParseValidity added in v1.16.8

func ParseValidity(notBefore string, notAfter string) (time.Time, time.Time, error)

ParseValidity parses notBefore and notAfter into time.Time values. notBefore and notAfter can either be in RFC3339 format or a duration offset from the current time. Offset durations are parsed using time.ParseDuration. If notBefore is empty or set to "now", it defaults to the current time. If notAfter is empty, it behaves as if it is set to "+1h". Negative validity periods are not allowed.

func TLSClientCertTemplate added in v1.16.8

func TLSClientCertTemplate() *x509.Certificate

TLSClientCertTemplate returns a new x509.Certificate template for a client certificate.

Types

type CA

type CA struct {
	io.Closer
	// contains filtered or unexported fields
}

CA is a simple Certificate Authority. The CA issues client certificates signed by a root certificate and private key. The CA provides an HTTP handler to issue certificates. The CA also provides a Gauntlet function to customize the certificate template. Call Close to release resources when done.

func New

func New(
	cert *bifrost.Certificate,
	key *bifrost.PrivateKey,
	gauntlet Gauntlet,
) (*CA, error)

New returns a new Certificate Authority. CA signs client certificates with the provided root certificate and private key. CA uses the provided gauntlet func to customise issued certificates.

func (*CA) AddRoutes added in v1.21.0

func (ca *CA) AddRoutes(mux *http.ServeMux, metrics bool)

AddRoutes adds the CA's HTTP handlers to the provided ServeMux. The CA's HTTP handlers are: - GET /namespace: returns the namespace of the CA. - POST /issue: issues a certificate.

func (*CA) Close added in v1.20.0

func (ca *CA) Close() error

Close releases resources held by the CA. Multiple calls to Close are safe.

func (*CA) IssueCertificate

func (ca *CA) IssueCertificate(asn1CSR []byte, notBefore, notAfter time.Time) ([]byte, error)

IssueCertificate issues a client certificate for a valid certificate request parsed from asn1CSR.

func (*CA) ServeHTTP

func (ca *CA) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP issues a certificate if a valid certificate request is read from the request.

Requests carrying a content-type of "text/plain" should have a PEM encoded certificate request. Requests carrying a content-type of "application/octet-stream" should submit the ASN.1 DER encoded form instead.

type Gauntlet added in v1.19.0

type Gauntlet func(ctx context.Context, csr *bifrost.CertificateRequest) (tmpl *x509.Certificate, err error)

Gauntlet is the signature for a function that validates a certificate request. If the second return value is non-nil, then the certificate request is denied. If the first return value is nil, the default template TLSClientCertTemplate will be used. If the function exceeds GauntletTimeout, ctx will be cancelled and the request will be denied with an error. The template will be used to issue a client certificate. Consult the x509 package for the full list of fields that can be set. tinyca will overwrite the following template fields:

  • NotBefore
  • NotAfter
  • SignatureAlgorithm
  • Issuer
  • Subject.Organization
  • Subject.CommonName

If SerialNumber is nil, a random value will be generated.

Jump to

Keyboard shortcuts

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