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 ¶
- Variables
- func CreateCSR(key crypto.Signer, commonName string) ([]byte, error)
- func EncodeCertificatePEM(der []byte) []byte
- func Fingerprint(cert *x509.Certificate) string
- func GenerateKey() (*ecdsa.PrivateKey, error)
- func MTLSConfig(roots *x509.CertPool, serverName string, getCert func() *tls.Certificate) *tls.Config
- func MarshalPrivateKeyPEM(key crypto.Signer) ([]byte, error)
- func NeedsRenewal(cert *x509.Certificate, now time.Time) bool
- func NormalizePin(pin string) (string, error)
- func ParseCertificatePEM(data []byte) (*x509.Certificate, error)
- func ParseCertificatesPEM(data []byte) ([]*x509.Certificate, error)
- func ParsePrivateKeyPEM(data []byte) (crypto.Signer, error)
- func PinnedTLSConfig(pin, serverName string) *tls.Config
- func SamePublicKey(cert *x509.Certificate, key crypto.Signer) bool
- func VerifyNodeCertificate(cert, ca *x509.Certificate, key crypto.Signer, now time.Time) error
- func VerifyPinnedChain(chain []*x509.Certificate, pin, serverName string, now time.Time) error
Constants ¶
This section is empty.
Variables ¶
var ErrPinMismatch = errors.New("CA pin mismatch")
ErrPinMismatch is returned when no certificate presented by the server matches the pinned CA fingerprint.
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
ParsePrivateKeyPEM decodes a PKCS#8 (or SEC 1 "EC PRIVATE KEY") PEM key.
func PinnedTLSConfig ¶
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 ¶
VerifyNodeCertificate checks that cert was issued by ca for client authentication and certifies key's public key.
func VerifyPinnedChain ¶
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:
- some certificate in the presented chain must have a DER SHA-256 equal to pin (the console sends leaf + CA);
- the leaf must verify against that certificate as the only root, be valid for serverName and allow server authentication.
Types ¶
This section is empty.