Documentation
¶
Overview ¶
Package crypto provides cryptographic utilities for certificate management.
Index ¶
- Variables
- func CAFingerprintFromPEM(certPEM []byte) (string, error)
- func GenerateCSR(hostname string) (csrPEM, keyPEM []byte, err error)
- func GenerateCSRFromKey(hostname string, keyPEM []byte) (csrPEM []byte, err error)
- func OpenWithAAD(key, ciphertext, aad []byte) ([]byte, error)
- func SealWithAAD(key, plaintext, aad []byte) ([]byte, error)
- func VerifyCAContinuity(oldCAPEM, newCAPEM []byte) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidKey is returned when the key is not exactly 32 bytes (AES-256). ErrInvalidKey = errors.New("crypto: key must be 32 bytes (AES-256)") // ErrAADRequired is returned when the AAD is empty. Domain-separation AAD is // MANDATORY: a naked AEAD call (nil/empty AAD) is refused by construction, so // two different ciphertext domains can never be confused or cross-decrypted, // and "forgot the AAD" is impossible to do silently. ErrAADRequired = errors.New("crypto: AAD is required (domain separation; no naked AEAD calls)") // ErrMalformedCiphertext is returned when a ciphertext is too short to carry // its prepended nonce. ErrMalformedCiphertext = errors.New("crypto: ciphertext too short") )
var ErrUnsupportedKeyType = errors.New("crypto: device identity key must be Ed25519")
ErrUnsupportedKeyType is returned when a stored device key is not Ed25519. The Control Server's CA refuses any other identity key type, so a renewal CSR built from one could never be signed.
Functions ¶
func CAFingerprintFromPEM ¶
CAFingerprintFromPEM returns the lowercase-hex SHA-256 of the certificate's decoded DER bytes.
func GenerateCSR ¶
GenerateCSR creates a new Ed25519 key pair and returns the CSR (PEM) and private key (PKCS#8 PEM).
The CSR carries no SANs (no DNSNames, IPAddresses, EmailAddresses, or URIs). Agent certificates are client certs — identified by the deviceID that the Control Server writes into the issued cert's Subject.SerialNumber, not by anything the agent puts in the CSR. The Control Server's CA rejects any CSR with SANs:
internal/ca/ca.go: "CSR must not request subject alternative names"
so including a DNS SAN here fails registration immediately. The hostname is still put in the CSR's CN for operator debuggability (the CA discards the CN and replaces it with the device ID), but the DNS SAN is omitted.
func GenerateCSRFromKey ¶
GenerateCSRFromKey creates a CSR using an existing PKCS#8 PEM-encoded Ed25519 private key. This is used for certificate renewal where the key pair is reused: the CA's renewal proof-of-possession requires the CSR's public key to equal the held certificate's.
func OpenWithAAD ¶
OpenWithAAD reverses SealWithAAD: it splits the prepended nonce, then authenticates and decrypts under key with the SAME aad. Any authentication failure — a wrong key, a wrong-domain aad, or a tampered ciphertext — returns an error and NO plaintext. A 32-byte key and a non-empty aad are required.
func SealWithAAD ¶
SealWithAAD encrypts plaintext with AES-256-GCM under key, binding aad as additional authenticated data, and returns nonce||ciphertext||tag.
A fresh random 96-bit nonce is generated PER CALL and prepended to the output. The nonce is generated here, never taken from the caller, so nonce reuse under the same key (catastrophic for GCM) cannot be introduced by a caller mistake; a crypto/rand failure fails closed rather than emitting a predictable nonce.
Both a 32-byte key and a NON-EMPTY aad are required: an empty aad is rejected (ErrAADRequired) so every ciphertext is domain-separated. The AEAD tag covers the plaintext AND the aad, so a wrong key, a wrong-domain aad, or any tamper fails authentication in OpenWithAAD.
func VerifyCAContinuity ¶
VerifyCAContinuity reports whether newCAPEM is an acceptable rotation of oldCAPEM: it must be byte-identical to the enrolled CA, OR be a CA that is cross-signed by (chains to) the enrolled CA. An unrelated CA is refused — that is the trust-anchor swap an attacker (or a compromised/MITM'd control origin) would attempt at certificate renewal. A hard CA swap (a new self-signed root not cross-signed by the old one) is intentionally refused too: it requires re-enrollment, not silent adoption over the renewal channel.
Types ¶
This section is empty.