-
Notifications
You must be signed in to change notification settings - Fork 190
Use zeroize for secure secret cleanup #3411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7a6af09
c994b17
79ad325
03a8659
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,7 @@ use tee_call::TeeCall; | |
| use thiserror::Error; | ||
| use zerocopy::FromZeros; | ||
| use zerocopy::IntoBytes; | ||
| use zeroize::Zeroize; | ||
|
|
||
| /// An attestation error. | ||
| #[derive(Debug, Error)] | ||
|
|
@@ -180,7 +181,7 @@ fn derive_key( | |
| Ok(output.try_into().unwrap()) | ||
| } | ||
|
|
||
| #[derive(Debug)] | ||
| #[derive(Debug, zeroize::Zeroize, zeroize::ZeroizeOnDrop)] | ||
| struct Keys { | ||
| ingress: [u8; AES_GCM_KEY_LENGTH], | ||
| decrypt_egress: Option<[u8; AES_GCM_KEY_LENGTH]>, | ||
|
|
@@ -1337,8 +1338,11 @@ async fn persist_all_key_protectors( | |
| // Remove ingress KP & DEK, no longer applies to data store | ||
| key_protector.dek[key_protector.active_kp as usize % NUMBER_KP] | ||
| .dek_buffer | ||
| .fill(0); | ||
| .zeroize(); | ||
| key_protector.gsp[key_protector.active_kp as usize % NUMBER_KP].gsp_length = 0; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to do something more to clear the gsp than just setting length to 0? #Resolved
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch — setting Added |
||
| key_protector.gsp[key_protector.active_kp as usize % NUMBER_KP] | ||
| .gsp_buffer | ||
| .zeroize(); | ||
| key_protector.active_kp += 1; | ||
|
|
||
| vmgs::write_key_protector(key_protector, vmgs) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,8 @@ use vmgs_format::VmgsProvisioningReason; | |
| use zerocopy::FromBytes; | ||
| use zerocopy::FromZeros; | ||
| use zerocopy::IntoBytes; | ||
| #[cfg(feature = "encryption")] | ||
| use zeroize::Zeroize; | ||
|
|
||
| /// Operation types for provisioning telemetry. | ||
| #[derive(Debug)] | ||
|
|
@@ -1235,7 +1237,7 @@ impl Vmgs { | |
| let mut temp_state = self.temp_state(); | ||
|
|
||
| // Remove the corresponding datastore_key | ||
| temp_state.datastore_keys[key_index].fill(0); | ||
| temp_state.datastore_keys[key_index].zeroize(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we not want to add ZeroizeOnDrop to all VmgsDatastoreKeys?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Options for broader coverage would be either converting it to a newtype struct (touching |
||
|
|
||
| // Remove the corresponding metadata_key | ||
| temp_state.encrypted_metadata_keys[key_index] = VmgsEncryptionKey::new_zeroed(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we not want to add ZeroizeOnDrop to all DekKps? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DekKpalready has#[derive(Zeroize, ZeroizeOnDrop)]in this PR (see the changes inopenhcl/openhcl_attestation_protocol/src/vmgs.rs), so allDekKpinstances — including the ones insideKeyProtector.dek[]— will have theirdek_buffersecurely zeroized when dropped.This explicit
.zeroize()call is technically redundant now (theZeroizeOnDropon the parentKeyProtectorwill cascade to itsDekKpfields), but I kept it as a 1:1 replacement of the original.fill(0)for defense-in-depth — it ensures the buffer is cleared before the struct is written back to VMGS on line 1345, not just when the struct is eventually dropped. Happy to remove it if you'd prefer to rely solely on the drop behavior.