certs

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package certs provides reusable validation.Check building blocks for inspecting X.509 certificates and PEM material: expiry, CA basic constraint, signature-algorithm and key-type strength, and key size. ValidatePEM and its file variants parse PEM data and run a set of checks against every certificate they contain, aggregating failures into a validation.Errors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidatePEM

func ValidatePEM(pemData []byte, checks ...Check) error

ValidatePEM parses all CERTIFICATE blocks from pemData and runs each check against every parsed certificate, collecting all failures into an validation.Errors value. Returns nil immediately when no checks are provided.

func ValidatePEMFile

func ValidatePEMFile(path string, checks ...Check) error

ValidatePEMFile reads path and forwards its contents to ValidatePEM. A read failure is returned wrapped so callers can distinguish IO problems from validation failures; the wrapped os.ReadFile error already includes the path.

func ValidatePEMKeyFile

func ValidatePEMKeyFile(path string) error

ValidatePEMKeyFile reads path and verifies it contains at least one PEM block whose type ends in "PRIVATE KEY" (covering "RSA PRIVATE KEY", "EC PRIVATE KEY", and "PRIVATE KEY" for PKCS#8). The block contents are not parsed; cryptographic validity and cert/key matching are exercised at runtime by crypto/tls.LoadX509KeyPair.

Types

type Check

type Check = validation.Check[*x509.Certificate]

Check inspects a single parsed certificate and returns a validation.Error describing any failure, or nil if the certificate is valid. It is an alias for the underlying validation.Check so callers can compose plain functions with the built-in checks in this package.

func IsCA

func IsCA() Check

IsCA returns a Check that rejects certificates that do not have the CA basic constraint set.

func NotExpired

func NotExpired() Check

NotExpired returns a Check that rejects certificates whose NotBefore is in the future or whose NotAfter is in the past.

func SecureAlgorithm

func SecureAlgorithm(allowedSuites ...uint16) Check

SecureAlgorithm returns a Check that rejects certificates signed with known-weak algorithms (SHA-1, MD5, MD2, DSA). When allowedSuites are provided it additionally rejects certificates whose public key type is incompatible with every suite in that list.

Self-issued certificates (RawIssuer == RawSubject) are exempt from the signature-algorithm check. This is a superset of self-signed: it also admits CA key-rollover certs, which are self-issued but signed by a different (older or newer) key than the one they certify. The exemption holds regardless: a self-issued cert's own signature is never consulted during chain verification — the cert is trusted (or not) based on its presence in the trust store, or on its role elsewhere in the chain, not on its self-attestation. Many still-valid public roots — used to sign SHA-256 chains today — carry legacy SHA-1 self-signatures; rejecting them would make the system CA bundle unusable as a trust anchor.

SecureAlgorithm is used both for trust-anchor validation and, via leafChecks, for certificates presented in a peer's chain. The exemption applies in both cases: a self-issued cert anywhere in a presented chain skips the weak-signature check, for the same reason. The key-type check still runs unconditionally.

func SufficientKeySize

func SufficientKeySize() Check

SufficientKeySize returns a Check that rejects certificates whose public key is below the recommended minimum size: RSA keys must be at least 2048 bits and ECDSA keys at least 256 bits. Key types other than RSA and ECDSA (e.g. Ed25519) are unsupported and rejected, since the supported cipher suites cover only RSA and ECDSA keys.

Jump to

Keyboard shortcuts

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