pki

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pki implements the node side of the console's internal PKI: key and CSR generation, PEM handling, CA pinning during enrollment and the TLS configurations used for the node channel.

The node private key is generated locally and never leaves the node; only the CSR (public key + subject) is sent to the console.

Index

Constants

This section is empty.

Variables

View Source
var ErrPinMismatch = errors.New("CA pin mismatch")

ErrPinMismatch is returned when no certificate presented by the server matches the pinned CA fingerprint.

View Source
var ErrServerCertificate = errors.New("verify server certificate against pinned CA")

ErrServerCertificate is returned when the server's certificate does not verify against the pinned CA (wrong name, expired, not for servers).

Functions

func CreateCSR

func CreateCSR(key crypto.Signer, commonName string) ([]byte, error)

CreateCSR returns a PEM-encoded PKCS#10 certificate signing request for key with the given subject common name. The console overrides the CN with the node id when it signs the certificate.

func EncodeCertificatePEM

func EncodeCertificatePEM(der []byte) []byte

EncodeCertificatePEM encodes a DER certificate as PEM.

func Fingerprint

func Fingerprint(cert *x509.Certificate) string

Fingerprint returns the lowercase hex SHA-256 of the certificate DER. This is the format of the --ca-sha256 pin in the install command.

func GenerateKey

func GenerateKey() (*ecdsa.PrivateKey, error)

GenerateKey creates a new ECDSA P-256 private key.

func MTLSConfig

func MTLSConfig(roots *x509.CertPool, serverName string, getCert func() *tls.Certificate) *tls.Config

MTLSConfig returns the client TLS configuration used after enrollment: the server must present a certificate issued by the internal CA for serverName, and the node authenticates with the certificate returned by getCert (read on every handshake so renewals take effect without a restart).

func MarshalPrivateKeyPEM

func MarshalPrivateKeyPEM(key crypto.Signer) ([]byte, error)

MarshalPrivateKeyPEM encodes a private key as PKCS#8 PEM.

func NeedsRenewal

func NeedsRenewal(cert *x509.Certificate, now time.Time) bool

NeedsRenewal reports whether less than a third of the certificate's lifetime is left.

func NormalizePin

func NormalizePin(pin string) (string, error)

NormalizePin validates a CA pin and returns it as 64 lowercase hex characters. It accepts an optional "sha256:" prefix (kubeadm style) and colon-separated bytes (openssl style).

func ParseCertificatePEM

func ParseCertificatePEM(data []byte) (*x509.Certificate, error)

ParseCertificatePEM decodes the first certificate in data.

func ParseCertificatesPEM

func ParseCertificatesPEM(data []byte) ([]*x509.Certificate, error)

ParseCertificatesPEM decodes every CERTIFICATE block in data.

func ParsePrivateKeyPEM

func ParsePrivateKeyPEM(data []byte) (crypto.Signer, error)

ParsePrivateKeyPEM decodes a PKCS#8 (or SEC 1 "EC PRIVATE KEY") PEM key.

func PinnedTLSConfig

func PinnedTLSConfig(pin, serverName string) *tls.Config

PinnedTLSConfig returns a client TLS configuration that trusts exactly the CA whose certificate DER hashes to pin. Standard verification is disabled because the CA is not known yet; VerifyConnection performs the complete verification (pin, chain, host name, EKU) instead.

func SamePublicKey

func SamePublicKey(cert *x509.Certificate, key crypto.Signer) bool

SamePublicKey reports whether cert certifies the public half of key.

func VerifyNodeCertificate

func VerifyNodeCertificate(cert, ca *x509.Certificate, key crypto.Signer, now time.Time) error

VerifyNodeCertificate checks that cert was issued by ca for client authentication and certifies key's public key.

func VerifyPinnedChain

func VerifyPinnedChain(chain []*x509.Certificate, pin, serverName string, now time.Time) error

VerifyPinnedChain verifies a server certificate chain against a pinned CA (kubeadm-style discovery). It is used during enrollment, when the node does not yet have the internal CA certificate:

  1. some certificate in the presented chain must have a DER SHA-256 equal to pin (the console sends leaf + CA);
  2. the leaf must verify against that certificate as the only root, be valid for serverName and allow server authentication.

Types

This section is empty.

Directories

Path Synopsis
Package pkitest provides a throwaway certificate authority that mimics the console's internal CA.
Package pkitest provides a throwaway certificate authority that mimics the console's internal CA.

Jump to

Keyboard shortcuts

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