security

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const BearerTokenLength = 32

Variables

This section is empty.

Functions

func ExtractRootCertificate added in v0.22.10

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

ExtractRootCertificate extracts the trust anchor from PEM-encoded certificate data. It identifies the self-signed certificate (where Issuer equals Subject) regardless of PEM ordering. For a single self-signed cert it returns that cert. For a chain it returns the root CA after verifying that the leaf cert chains to it through any intermediates present. Returns an error if no self-signed certificate is found or if the chain is invalid.

func MakeBearerToken

func MakeBearerToken() ([]byte, error)

func PEMEncodeBlock added in v0.22.10

func PEMEncodeBlock(blockType string, derBytes []byte) []byte

PEMEncodeBlock PEM-encodes a single block with the given type and DER bytes.

func PEMEncodeCertificates

func PEMEncodeCertificates(certs ...[]byte) []byte

PEMEncodeCertificates PEM-encodes a set of raw DER certificates into a common buffer.

func PEMEncodePrivateKey

func PEMEncodePrivateKey(pkcs1Bytes []byte) []byte

PEMEncodePrivateKey PEM-encodes PKCS#1 RSA private key bytes.

func ValidateCertificate added in v0.22.10

func ValidateCertificate(cert *x509.Certificate) (string, error)

ValidateCertificate validates that the given certificate is currently valid, authorized for server authentication, and covers a localhost address. Returns the server address to use based on what the certificate covers and the system's IP version preference.

Types

type ServerCertificateData

type ServerCertificateData struct {
	CACertPEM    []byte // Root CA certificate, PEM-encoded (for client trust / kubeconfig)
	CertChainPEM []byte // Server certificate chain (leaf + intermediates), PEM-encoded
	ServerKeyPEM []byte // Server private key, PEM-encoded
}

func GenerateServerCertificate

func GenerateServerCertificate(ip net.IP) (ServerCertificateData, error)

Generates a self-signed certificate authority, server certificate, and a server private key for securing network connections. Returned certificates are raw (not PEM-encoded).

func LookupCertificate added in v0.22.10

func LookupCertificate(thumbprint string) (*ServerCertificateData, string, error)

LookupCertificate looks up a certificate by its SHA-1 thumbprint in the system certificate store (CurrentUser\My on Windows) and returns the certificate data including the private key, along with the validated server address the certificate covers. This is only supported on Windows; on other platforms it returns an error.

Jump to

Keyboard shortcuts

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