Skip to content

Commit 3490f2a

Browse files
committed
Zeroize VssStore's data_encryption_key on Drop
.. to make sure it doesn't linger in memory.
1 parent 59651e8 commit 3490f2a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/io/vss_store.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ type CustomRetryPolicy = FilteredRetryPolicy<
3838
Box<dyn Fn(&VssError) -> bool + 'static + Send + Sync>,
3939
>;
4040

41+
const KEY_LENGTH: usize = 32;
42+
4143
/// A [`KVStore`] implementation that writes to and reads from a [VSS](https://github.com/lightningdevkit/vss-server/blob/main/README.md) backend.
4244
pub struct VssStore {
4345
client: VssClient<CustomRetryPolicy>,
4446
store_id: String,
4547
runtime: Arc<Runtime>,
46-
data_encryption_key: [u8; 32],
48+
data_encryption_key: [u8; KEY_LENGTH],
4749
key_obfuscator: KeyObfuscator,
4850
}
4951

@@ -237,6 +239,12 @@ impl KVStore for VssStore {
237239
}
238240
}
239241

242+
impl Drop for VssStore {
243+
fn drop(&mut self) {
244+
self.data_encryption_key.copy_from_slice(&[0u8; KEY_LENGTH]);
245+
}
246+
}
247+
240248
fn derive_data_encryption_and_obfuscation_keys(vss_seed: &[u8; 32]) -> ([u8; 32], [u8; 32]) {
241249
let hkdf = |initial_key_material: &[u8], salt: &[u8]| -> [u8; 32] {
242250
let mut engine = HmacEngine::<sha256::Hash>::new(salt);

0 commit comments

Comments
 (0)