util

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CertPool added in v0.13.0

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

CertPool is a set of certificates.

func NewCertPool added in v0.13.0

func NewCertPool(options ...Option) *CertPool

NewCertPool returns a new, empty CertPool. It will deduplicate certificates based on their SHA256 hash. Optionally, it can filter out expired certificates.

func (*CertPool) AddCertsFromPEM added in v0.13.0

func (cp *CertPool) AddCertsFromPEM(pemData []byte) error

AddCertsFromPEM strictly validates a given input PEM bundle to confirm it contains only valid CERTIFICATE PEM blocks. If successful, returns the validated PEM blocks with any comments or extra data stripped.

This validation is broadly similar to the standard library function crypto/x509.CertPool.AppendCertsFromPEM - that is, we decode each PEM block at a time and parse it as a certificate.

The difference here is that we want to ensure that the bundle _only_ contains certificates, and not just skip over things which aren't certificates.

If, for example, someone accidentally used a combined cert + private key as an input to a trust bundle, we wouldn't want to then distribute the private key in the target.

In addition, the standard library AppendCertsFromPEM also silently skips PEM blocks with non-empty Headers. We error on such PEM blocks, for the same reason as above; headers could contain (accidental) private information. They're also non-standard according to https://www.rfc-editor.org/rfc/rfc7468

Additionally, if the input PEM bundle contains no non-expired certificates, an error is returned. TODO: Reconsider what should happen if the input only contains expired certificates.

func (*CertPool) Certificates added in v0.13.0

func (certPool *CertPool) Certificates() []*x509.Certificate

Get the list of all x509 Certificates in the certificates pool

func (*CertPool) PEM added in v0.13.0

func (certPool *CertPool) PEM() string

func (*CertPool) PEMSplit added in v0.13.0

func (certPool *CertPool) PEMSplit() []string

func (*CertPool) Size added in v0.13.0

func (cp *CertPool) Size() int

Get certificates quantity in the certificates pool

type Option added in v0.13.0

type Option func(*CertPool)

func WithFilteredExpiredCerts added in v0.13.0

func WithFilteredExpiredCerts(filterExpired bool) Option

Jump to

Keyboard shortcuts

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