certpool

package
v0.5.12 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: MIT Imports: 23 Imported by: 1

Documentation

Overview

Package certpool provides a x509 Certificates store from ground up

Index

Constants

View Source
const (
	// HashSize is the number of bytes of HashCert's output
	HashSize = 32
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bundler

type Bundler struct {
	Roots x509utils.CertPooler
	Inter x509utils.CertPooler
}

Bundler uses two CertPoolers to bundler keys and certificates

func (*Bundler) Bundle

func (b *Bundler) Bundle(cert *x509.Certificate, key x509utils.PrivateKey) (
	*tls.Certificate, error)

Bundle bundles a key and a certificate into a *tls.Certificate

type CertPool

type CertPool struct {
	// contains filtered or unexported fields
}

CertPool represents a collection of CA Certificates

func SystemCertPool

func SystemCertPool() (*CertPool, error)

SystemCertPool returns a Pool populated with the system's valid CA certificates

func (*CertPool) AddCert

func (s *CertPool) AddCert(cert *x509.Certificate) bool

AddCert adds parsed CA certificates to the CertPool

func (*CertPool) AppendCertsFromPEM

func (s *CertPool) AppendCertsFromPEM(b []byte) bool

AppendCertsFromPEM adds certificates to the Pool from a PEM encoded blob, and returns true if a new Certificate was effectivelt added

func (*CertPool) Bundle

func (pool *CertPool) Bundle(cert *x509.Certificate, key x509utils.PrivateKey,
	roots x509utils.CertPooler) (*tls.Certificate, error)

Bundle verifies a leaf x509.Certificate and return a tls.Certificate

func (*CertPool) Certs

func (s *CertPool) Certs() []*x509.Certificate

Certs returns an array of all certificates in the CertPool

func (*CertPool) Clone

func (s *CertPool) Clone() x509utils.CertPooler

Clone creates a copy of the CertPool

func (*CertPool) Copy added in v0.5.6

func (s *CertPool) Copy(out *CertPool) *CertPool

Copy replicate itself into a given CertPool

func (*CertPool) Count

func (s *CertPool) Count() int

Count tells how many certificates are stored in the CertPool

func (*CertPool) Delete

func (s *CertPool) Delete(_ context.Context, name string) error

Delete removes a certificate by name

func (*CertPool) DeleteCert

func (s *CertPool) DeleteCert(_ context.Context, cert *x509.Certificate) error

DeleteCert removes a given certificate

func (*CertPool) Equal

func (s *CertPool) Equal(x x509utils.CertPooler) bool

Equal checks if another CertPooler is equal to this one

func (*CertPool) Export

func (s *CertPool) Export() *x509.CertPool

Export produces a standard *x509.CertPool containing the same CA certificates

func (*CertPool) ForEach

func (s *CertPool) ForEach(ctx context.Context, fn x509utils.StoreIterFunc) error

ForEach iterates over all certificates

func (*CertPool) Get

func (s *CertPool) Get(_ context.Context, name string) (*x509.Certificate, error)

Get find a certificate by name

func (*CertPool) IsCA added in v0.5.2

func (s *CertPool) IsCA() bool

IsCA tells if all certificates in the store are CAs

func (*CertPool) Minus

Minus produces a new CertPool without any certificate on the given Pool

func (*CertPool) Plus

Plus produces a new CertPool with all certificate on the given Pool

func (*CertPool) Put

func (s *CertPool) Put(_ context.Context, name string, cert *x509.Certificate) error

Put adds a certificate by name

func (*CertPool) Reset

func (s *CertPool) Reset()

Reset removes all certificates from the Pool

type Hash

type Hash [HashSize]byte

Hash is a blake3.Sum256 representation of a DER encoded certificate

func HashCert

func HashCert(cert *x509.Certificate) Hash

HashCert produces a blake3 unkeyed digest of the DER representation of a Certificate

type PoolBuffer

type PoolBuffer struct {
	// contains filtered or unexported fields
}

PoolBuffer is a CertPool in the making

func (*PoolBuffer) Add

func (pb *PoolBuffer) Add(data ...string) error

Add loads private keys and certificates from PEM files, directories, and direct text

func (*PoolBuffer) AddCert

func (pb *PoolBuffer) AddCert(fn string, cert *x509.Certificate) error

AddCert adds a Certificate to the PoolBuffer

func (*PoolBuffer) AddKey

func (pb *PoolBuffer) AddKey(fn string, pk x509utils.PrivateKey) error

AddKey adds a PrivateKey to the PoolBuffer

func (*PoolBuffer) Bundle

Bundle verifies a leaf x509.Certificate and return a tls.Certificate

func (*PoolBuffer) Certificates

func (pb *PoolBuffer) Certificates(base x509utils.CertPooler) ([]*tls.Certificate, error)

Certificates exports all the Certificates it contains bundled considering a given base

func (*PoolBuffer) CopyPool added in v0.5.6

func (pb *PoolBuffer) CopyPool(out *CertPool) *CertPool

CopyPool copies the CA certificates into the given CertPool

func (*PoolBuffer) Count

func (pb *PoolBuffer) Count() int

Count returns how many certificates are in the buffer

func (*PoolBuffer) Export

func (pb *PoolBuffer) Export() *x509.CertPool

Export returns a new x509.CertPool with the CA certificates

func (*PoolBuffer) Keys added in v0.5.2

func (pb *PoolBuffer) Keys() []x509utils.PrivateKey

Keys returns an array of all stored Private Keys

func (*PoolBuffer) NewBundler

func (pb *PoolBuffer) NewBundler(roots x509utils.CertPooler) (*Bundler, error)

NewBundler creates a Bundler using the known CAs and provided roots. If no base is given, system certs will be used instead.

func (*PoolBuffer) Pool

func (pb *PoolBuffer) Pool() *CertPool

Pool returns a new CertPool with the CA certificates

func (*PoolBuffer) Reset

func (pb *PoolBuffer) Reset()

Reset makes the PoolBuffer go back to its initial state, empty

func (*PoolBuffer) SetLogger

func (pb *PoolBuffer) SetLogger(logger slog.Logger)

SetLogger binds a slog.Logger to the buffer

Jump to

Keyboard shortcuts

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