Skip to content

Commit bd19d3d

Browse files
committed
feat!: replace dead key-rotation machinery with keyring decrypt helper (LAB-683)
Deletes the rotation dead code the LAB-275 audit flagged as a trust bug and implements the cachekit-core half of the keyring decision (protocol/decisions/key-rotation.md, merged via protocol#34): - Remove ZeroKnowledgeEncryptor::rotate_key() NotImplemented stub and the EncryptionError::NotImplemented variant - Delete src/encryption/key_rotation.rs whole (KeyRotationState, RotationAwareHeader) and the EncryptionHeader alias + re-exports - Add encryption::keyring::Keyring: one current master key + at most 3 decrypt-only keys; sequential decrypt current-first with identical AAD per attempt; per-entry HKDF-derived encryption-key fingerprints for fingerprint-based selection; cap and forward-only self-collision rejected at construction; all key material zeroized on drop BREAKING CHANGE: public items EncryptionHeader, KeyRotationState, RotationAwareHeader, and ZeroKnowledgeEncryptor::rotate_key() are removed (EncryptionError::NotImplemented variant included). Use Keyring for master-key rotation.
1 parent daf3459 commit bd19d3d

7 files changed

Lines changed: 425 additions & 359 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ gcc -o example example.c -L target/release -lcachekit_core -I include
215215
│ Each tenant key provides: │
216216
│ • Cryptographic isolation (compromise one ≠ compromise all) │
217217
│ • Domain separation (cache vs auth vs sessions) │
218-
│ • Forward secrecy with key rotation │
218+
│ • Master-key rotation via decrypt-only keyring (grace window) │
219219
│ │
220220
└─────────────────────────────────────────────────────────────────┘
221221
```
@@ -263,7 +263,7 @@ cachekit-core/
263263
│ │ ├── mod.rs # Module exports
264264
│ │ ├── core.rs # AES-256-GCM implementation
265265
│ │ ├── key_derivation.rs # HKDF-SHA256 + tenant isolation
266-
│ │ └── key_rotation.rs # Graceful key rotation support
266+
│ │ └── keyring.rs # Multi-key decrypt keyring (master-key rotation)
267267
│ │
268268
│ └── ffi/ # (feature = "ffi")
269269
│ ├── mod.rs # FFI exports

‎src/encryption/core.rs‎

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,19 @@ pub enum EncryptionError {
154154
#[error("Nonce counter exhausted - key rotation required")]
155155
NonceCounterExhausted,
156156

157-
#[error("Key rotation not yet implemented")]
158-
NotImplemented(String),
157+
#[error("Invalid master key length: expected at least 16 bytes, got {0}")]
158+
InvalidMasterKeyLength(usize),
159+
160+
#[error(
161+
"Keyring cap exceeded: at most {max} decrypt-only keys allowed, got {0}",
162+
max = super::keyring::MAX_DECRYPT_ONLY_KEYS
163+
)]
164+
KeyringCapExceeded(usize),
165+
166+
#[error(
167+
"Current key must not appear in the decrypt-only list (forward-only rotation invariant)"
168+
)]
169+
CurrentKeyInDecryptOnlyList,
159170
}
160171

161172
/// Zero-knowledge encryptor using AES-256-GCM with hardware acceleration detection
@@ -480,22 +491,6 @@ impl ZeroKnowledgeEncryptor {
480491
.unwrap_or_else(|_| OperationMetrics::new())
481492
}
482493

483-
/// Key rotation API (stub for future implementation)
484-
///
485-
/// This method will support gradual key migration to allow rotating encryption keys
486-
/// without downtime. Future implementation will:
487-
/// - Support dual-key mode (read from both old and new key, write with new key only)
488-
/// - Add version byte to ciphertext header indicating which key was used
489-
/// - Implement gradual migration strategy
490-
///
491-
/// Currently returns NotImplemented error.
492-
pub fn rotate_key(&mut self, _new_master_key: &[u8]) -> Result<(), EncryptionError> {
493-
Err(EncryptionError::NotImplemented(
494-
"Key rotation will be implemented in a future release with gradual migration support"
495-
.into(),
496-
))
497-
}
498-
499494
/// Encrypt data using AES-256-GCM with authenticated additional data (wasm32)
500495
///
501496
/// Uses RustCrypto's `aes-gcm` crate (pure Rust, compiles on wasm32-unknown-unknown).

‎src/encryption/key_rotation.rs‎

Lines changed: 0 additions & 305 deletions
This file was deleted.

0 commit comments

Comments
 (0)