certificates

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RootCertPath = "config/root_cert.pem"
	RootKeyPath  = "config/root_key.pem"
)

Certificate file path constants.

Variables

View Source
var (
	ErrCertFieldNotFound     = errors.New("cert field not found in secret")
	ErrKeyFieldNotFound      = errors.New("key field not found in secret")
	ErrStoreNotObjectStorage = errors.New("store does not support object storage")
	ErrDecodeCertificatePEM  = errors.New("failed to decode certificate PEM")
	ErrDecodePrivateKeyPEM   = errors.New("failed to decode private key PEM")
	ErrCertFilesNotFound     = errors.New("certificate files not found")
)

Sentinel errors for certificate operations.

Functions

func CheckAndLoadOrGenerateRootCertificate

func CheckAndLoadOrGenerateRootCertificate(addThumbPrintToName bool, commonName, country, organization string, strong bool) (*x509.Certificate, *rsa.PrivateKey, error)

CheckAndLoadOrGenerateRootCertificate checks if root certificate files exist, loads them if they do, or generates new ones if they don't.

func CheckAndLoadOrGenerateWebServerCertificate

func CheckAndLoadOrGenerateWebServerCertificate(rootCert CertAndKeyType, addThumbPrintToName bool, commonName, country, organization string, strong bool) (*x509.Certificate, *rsa.PrivateKey, error)

CheckAndLoadOrGenerateWebServerCertificate checks if web server certificate files exist, loads them if they do, or generates new ones if they don't.

func GenerateRootCertificate

func GenerateRootCertificate(addThumbPrintToName bool, commonName, country, organization string, strong bool) (*x509.Certificate, *rsa.PrivateKey, error)

func IssueWebServerCertificate

func IssueWebServerCertificate(rootCert CertAndKeyType, addThumbPrintToName bool, commonName, country, organization string, strong bool) (*x509.Certificate, *rsa.PrivateKey, error)

func LoadCertificateFromFile

func LoadCertificateFromFile(certPath, keyPath string) (*x509.Certificate, *rsa.PrivateKey, error)

LoadCertificateFromFile loads a certificate and private key from PEM files.

func LoadCertificateFromStore

func LoadCertificateFromStore(store security.Storager, name string) (*x509.Certificate, *rsa.PrivateKey, error)

LoadCertificateFromStore loads a certificate and private key from a security.Storager. If the store implements ObjectStorager, certificates are stored as {cert, key} fields. Path: certs/{name}.

func LoadOrGenerateRootCertificateWithVault

func LoadOrGenerateRootCertificateWithVault(store security.Storager, addThumbPrintToName bool, commonName, country, organization string, strong bool) (*x509.Certificate, *rsa.PrivateKey, error)

LoadOrGenerateRootCertificateWithVault attempts to load the root certificate from Vault first, falls back to local files, and generates new certificates if neither exists. When a new certificate is generated, it is stored in Vault (if available) and locally. Certificate is stored at: {basePath}/certs/root.

func LoadOrGenerateWebServerCertificateWithVault

func LoadOrGenerateWebServerCertificateWithVault(store security.Storager, rootCert CertAndKeyType, addThumbPrintToName bool, commonName, country, organization string, strong bool) (*x509.Certificate, *rsa.PrivateKey, error)

LoadOrGenerateWebServerCertificateWithVault attempts to load the web server certificate from Vault first, falls back to local files, and generates new certificates if neither exists. When a new certificate is generated, it is stored in Vault (if available) and locally. Certificate is stored at: {basePath}/certs/webserver-{commonName}.

func ParseCertificateFromPEM

func ParseCertificateFromPEM(certPEM, keyPEM string) (*x509.Certificate, *rsa.PrivateKey, error)

ParseCertificateFromPEM parses PEM-encoded certificate and key strings.

func SaveCertificateToStore

func SaveCertificateToStore(store security.Storager, name string, cert *x509.Certificate, key *rsa.PrivateKey) error

SaveCertificateToStore saves a certificate and private key to a security.Storager. If the store implements ObjectStorager, certificates are stored as {cert, key} fields. Path: certs/{name}.

Types

type CertAndKeyType

type CertAndKeyType struct {
	Cert *x509.Certificate
	Key  *rsa.PrivateKey
}

type ObjectStorager

type ObjectStorager interface {
	security.Storager
	GetObject(key string) (map[string]string, error)
	SetObject(key string, data map[string]string) error
}

ObjectStorager extends security.Storager with object storage capabilities.

Jump to

Keyboard shortcuts

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