Documentation
¶
Overview ¶
Package kek defines Key Encryption Key (KEK) abstractions for wrapping, unwrapping, and rewrapping Data Encryption Keys (DEKs).
Implementations may execute locally in memory (e.g., kek/local) or delegate cryptographic operations to remote cloud KMS / HSM services (e.g., kek/awskms, kek/gcpkms) where the KEK material never leaves the remote boundary.
Index ¶
- type CacheConfig
- type CachingKeyring
- func (c *CachingKeyring) ActiveKeyID() string
- func (c *CachingKeyring) Close()
- func (c *CachingKeyring) Invalidate()
- func (c *CachingKeyring) Rewrap(ctx context.Context, fromKEKID, toKEKID string, ...) ([]byte, error)
- func (c *CachingKeyring) Unwrap(ctx context.Context, kekID string, encryptedDEK, aad []byte) ([]byte, error)
- func (c *CachingKeyring) Wrap(ctx context.Context, dek, aad []byte) (kekID string, encryptedDEK []byte, err error)
- type Keyring
- type Rewrapper
- type Wrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheConfig ¶
type CacheConfig struct {
// TTL is the maximum duration a decrypted DEK remains valid in the cache.
// Must be positive.
TTL time.Duration
// MaxEntries is the maximum number of decrypted DEKs held in memory at once.
// When exceeded, the least-recently-used entry is evicted and zeroed.
// Must be positive.
MaxEntries int
}
CacheConfig configures a CachingKeyring.
type CachingKeyring ¶
type CachingKeyring struct {
// contains filtered or unexported fields
}
CachingKeyring decorates a Keyring with a bounded, TTL-expiring LRU cache of unwrapped DEKs to minimize remote KMS RPC latency, costs, and rate limits.
All cached DEK slices are defensive copies and are scrubbed from memory via encryption.ZeroBytes upon TTL expiration, LRU eviction, Invalidate, or Close.
func NewCachingKeyring ¶
func NewCachingKeyring(inner Keyring, cfg CacheConfig) (*CachingKeyring, error)
NewCachingKeyring wraps inner with an in-memory LRU DEK cache.
func (*CachingKeyring) ActiveKeyID ¶
func (c *CachingKeyring) ActiveKeyID() string
ActiveKeyID returns the active KEK identifier from the underlying keyring.
func (*CachingKeyring) Close ¶
func (c *CachingKeyring) Close()
Close scrubs all cached DEKs from memory and marks the CachingKeyring as closed.
func (*CachingKeyring) Invalidate ¶
func (c *CachingKeyring) Invalidate()
Invalidate scrubs and removes all currently cached DEKs from memory.
func (*CachingKeyring) Rewrap ¶
func (c *CachingKeyring) Rewrap(ctx context.Context, fromKEKID, toKEKID string, encryptedDEK, sourceAAD, targetAAD []byte) ([]byte, error)
Rewrap delegates DEK rewrapping to the underlying keyring.
type Keyring ¶
type Keyring interface {
// ActiveKeyID returns the ID of the KEK used for new Wrap operations.
ActiveKeyID() string
// Wrap encrypts a DEK using the active KEK, binding it to aad.
Wrap(ctx context.Context, dek, aad []byte) (kekID string, encryptedDEK []byte, err error)
// Unwrap decrypts an encrypted DEK using the KEK identified by kekID and verifies aad.
// Callers must scrub the returned slice with encryption.ZeroBytes when done.
Unwrap(ctx context.Context, kekID string, encryptedDEK, aad []byte) (dek []byte, err error)
// Rewrap re-encrypts an encrypted DEK from fromKEKID to toKEKID, verifying
// sourceAAD and binding targetAAD.
Rewrap(ctx context.Context, fromKEKID, toKEKID string, encryptedDEK, sourceAAD, targetAAD []byte) ([]byte, error)
}
Keyring coordinates an active KEK Wrapper for new DEK wrapping and a set of historical KEK Wrappers for unwrapping and rewrapping existing DEKs.
type Rewrapper ¶
type Rewrapper interface {
Rewrap(ctx context.Context, target Wrapper, encryptedDEK, sourceAAD, targetAAD []byte) ([]byte, error)
}
Rewrapper is an optional interface implemented by KEK wrappers that support native server-side re-encryption (e.g., AWS KMS ReEncrypt) without exposing the plaintext DEK to application memory.
If a Rewrapper cannot natively re-encrypt to the given target Wrapper (for example, when migrating across different KMS providers), it should return errors.ErrUnsupported so Keyring.Rewrap automatically falls back to Unwrap + Wrap.
type Wrapper ¶
type Wrapper interface {
// ID returns the unique KEK identifier persisted alongside wrapped DEKs.
ID() string
// Wrap encrypts a plaintext DEK, cryptographically binding it to aad.
Wrap(ctx context.Context, dek, aad []byte) (encryptedDEK []byte, err error)
// Unwrap decrypts an encrypted DEK and verifies aad.
// Callers must scrub the returned slice with encryption.ZeroBytes when done.
Unwrap(ctx context.Context, encryptedDEK, aad []byte) (dek []byte, err error)
}
Wrapper encrypts and decrypts Data Encryption Keys (DEKs) using a single KEK. Implementations must be safe for concurrent use.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package local implements an in-process symmetric kek.Wrapper using a cipher.Cipher (AES-256-GCM by default) and provides in-memory and file-based KEK loaders.
|
Package local implements an in-process symmetric kek.Wrapper using a cipher.Cipher (AES-256-GCM by default) and provides in-memory and file-based KEK loaders. |