signerx

package
v0.17.3 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package signerx is the apic abstraction over hardware- and KMS-backed crypto.Signer providers (PKCS#11 HSMs, AWS KMS, Azure Key Vault, etc.). It exists so the rest of the runtime (TLS, JWT, OIDC client assertions) never holds raw private key bytes -- everything goes through a Backend.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownBackend     = errors.New("signerx: unknown backend")
	ErrKeyNotFound        = errors.New("signerx: key not found")
	ErrFIPSForbidsBackend = errors.New("signerx: backend forbidden in FIPS mode")
)

Sentinel errors.

Functions

func CatalogNames added in v0.14.3

func CatalogNames() []string

CatalogNames returns the sorted static backend catalog (see KnownBackend).

func Deregister

func Deregister(name string)

Deregister removes name. Tests use this for cleanup.

func GetCertificateForServer

func GetCertificateForServer(b Backend, ref KeyRef) func(*tls.ClientHelloInfo) (*tls.Certificate, error)

GetCertificateForServer returns a tls.Config.GetCertificate callback that fetches a fresh handle from b on first call and caches it for the lifetime of the listener. Backends that perform expensive Open (PKCS#11 login, KMS GetPublicKey) pay the cost once.

A nil Backend or a Backend.Open error is surfaced lazily — the returned callback returns the error to crypto/tls on the first handshake. Callers that need eager failure should call b.Open themselves before passing the result here.

func KnownBackend added in v0.14.3

func KnownBackend(name string) bool

KnownBackend reports whether name is a backend this repository ships a factory for (see catalogNames), regardless of the current process's build tags. Generate-time config validation (cmd/apic) uses this instead of Names() because the generator never imports a backend subpackage.

func Names

func Names() []string

Names returns the registered backend names sorted.

func Register

func Register(name string, f Factory)

Register installs f under name. Each build-tagged backend file registers itself in an init().

func SignJWT

func SignJWT(_ context.Context, signer crypto.Signer, alg jwa.SignatureAlgorithm, claims jwt.Token) ([]byte, error)

SignJWT signs claims using signer under alg. signer can be any crypto.Signer including those returned by Backend.Open (PKCS#11, KMS, softfile). The returned bytes are a compact-serialized JWS.

FIPS deployments select RS256 / ES256 / PS256 to satisfy SC-13 + IA-7 (FIPS-validated cryptographic authentication).

Types

type Backend

type Backend interface {
	// Name returns the provider name ("softfile", "pkcs11", etc.)
	Name() string
	// Open returns a SignerHandle for the key identified by ref.
	Open(ctx context.Context, ref KeyRef) (SignerHandle, error)
	// Close releases backend resources.
	Close() error
}

Backend is implemented by every signer provider.

func Resolve

func Resolve(name string, cfg BackendConfig) (Backend, error)

Resolve looks up name and invokes the factory with cfg.

type BackendConfig

type BackendConfig map[string]any

BackendConfig is the raw JSON-like config passed to a Backend factory.

type Factory

type Factory func(BackendConfig) (Backend, error)

Factory constructs a Backend from raw config.

type KeyRef

type KeyRef struct {
	ID  string
	PIN string // activation PIN for PKCS#11 backends; ignored elsewhere
}

KeyRef identifies a key within a Backend. The ID is opaque to signerx and interpreted per backend (PKCS#11: CKA_LABEL or hex CKA_ID; AWS KMS: key ARN; Azure: vault key ID URL; softfile: filesystem path).

type SignerHandle

type SignerHandle struct {
	Signer crypto.Signer
	Public crypto.PublicKey
	// Cert, when non-nil, is the X.509 leaf associated with the key in
	// the backend (PKCS#11 CKO_CERTIFICATE or KMS GetPublicKey+lookup).
	Cert []byte
}

SignerHandle binds an opened key to its crypto.Signer and PublicKey.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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