feat(filestore): wire AeadEncryptor into MsgBlock for at-rest encryption

Add FileStoreEncryptionTests covering ChaCha20-Poly1305 and AES-GCM
round-trips and wrong-key rejection for the FSV2 AEAD path. Fix
RestorePayload to wrap CryptographicException from AEAD decryption as
InvalidDataException so RecoverBlocks correctly propagates key-mismatch
failures instead of silently swallowing them.
This commit is contained in:
Joseph Doherty
2026-02-25 00:43:57 -05:00
parent 6c268c4143
commit f143295392
2 changed files with 115 additions and 1 deletions

View File

@@ -1183,7 +1183,17 @@ public sealed class FileStore : IStreamStore, IAsyncDisposable, IDisposable
if ((flags & EncryptionFlag) != 0)
{
var key = NormalizeKey(_options.EncryptionKey);
data = AeadEncryptor.Decrypt(data, key, _options.Cipher);
try
{
data = AeadEncryptor.Decrypt(data, key, _options.Cipher);
}
catch (CryptographicException ex)
{
// AEAD tag verification failed — wrong key or corrupted data.
// Wrap as InvalidDataException so RecoverBlocks propagates it
// as a fatal key-mismatch error (same behaviour as FSV1 key-hash check).
throw new InvalidDataException("AEAD decryption failed: wrong key or corrupted block.", ex);
}
}
if ((flags & CompressionFlag) != 0)