Skip to content

Commit 6187aee

Browse files
committed
fix(security): replace deprecated Nonce::from_slice with Nonce::from in DEK encryption
Update encrypt_dek and decrypt_dek to use the non-deprecated Nonce::from constructor. The decrypt path now performs an explicit TryInto conversion to a [u8; 12] array before constructing the nonce, surfacing a proper error if the slice length is wrong.
1 parent 3f66bd2 commit 6187aee

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

nodedb/src/control/security/encryption.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,11 @@ impl VolumeEncryption {
185185
let cipher = Aes256Gcm::new_from_slice(master).map_err(|e| crate::Error::Encryption {
186186
detail: format!("AES-GCM key init failed: {e}"),
187187
})?;
188-
let nonce = Nonce::from_slice(&nonce_bytes);
188+
let nonce = Nonce::from(nonce_bytes);
189189

190190
let ciphertext =
191191
cipher
192-
.encrypt(nonce, dek.as_ref())
192+
.encrypt(&nonce, dek.as_ref())
193193
.map_err(|e| crate::Error::Encryption {
194194
detail: format!("DEK encryption failed: {e}"),
195195
})?;
@@ -230,11 +230,16 @@ impl VolumeEncryption {
230230
let cipher = Aes256Gcm::new_from_slice(master).map_err(|e| crate::Error::Encryption {
231231
detail: format!("AES-GCM key init failed: {e}"),
232232
})?;
233-
let nonce = Nonce::from_slice(nonce_bytes);
233+
let nonce_arr: [u8; 12] = nonce_bytes
234+
.try_into()
235+
.map_err(|_| crate::Error::Encryption {
236+
detail: "nonce slice is not 12 bytes".into(),
237+
})?;
238+
let nonce = Nonce::from(nonce_arr);
234239

235240
let plaintext =
236241
cipher
237-
.decrypt(nonce, ciphertext)
242+
.decrypt(&nonce, ciphertext)
238243
.map_err(|_| crate::Error::Encryption {
239244
detail: "DEK decryption failed: authentication tag mismatch".into(),
240245
})?;

0 commit comments

Comments
 (0)