Skip to content

Commit b0a91ab

Browse files
sutes-workCQ Bot
authored andcommitted
[fxfs] Keep key structure versioning in Fxfs rather than fxfs-crypto
After this CL, the fxfs-crypto crate always has the latest versions of keey structures and Fxfs just has aliases to them. When these structures evolve, we will have to copy legacy versions into Fxfs. This differs from the approach suggested in the bug which had the downside that we would have had to have two copies of the structures. Fixed: 419723745 Change-Id: I62cff5fa7bf1e0ef56abf85afb185995b8c955f3 Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1357344 Reviewed-by: Aaron Drew <[email protected]> Fuchsia-Auto-Submit: Chris Suter <[email protected]> Commit-Queue: Chris Suter <[email protected]>
1 parent 69ff3ab commit b0a91ab

File tree

5 files changed

+21
-23
lines changed

5 files changed

+21
-23
lines changed

src/storage/fxfs/crypto/src/lib.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ impl std::ops::Deref for UnwrappedKey {
4444
}
4545

4646
/// A fixed length array of 48 bytes that holds an AES-256-GCM-SIV wrapped key.
47-
// TODO(b/419723745): Move this to Fxfs and keep fxfs-crypto free of versioned types.
48-
pub type WrappedKeyBytes = WrappedKeyBytesV32;
4947
#[repr(transparent)]
5048
#[derive(Clone, Debug, PartialEq)]
51-
pub struct WrappedKeyBytesV32(pub [u8; FXFS_WRAPPED_KEY_SIZE]);
49+
pub struct WrappedKeyBytes(pub [u8; FXFS_WRAPPED_KEY_SIZE]);
5250
impl Default for WrappedKeyBytes {
5351
fn default() -> Self {
5452
Self([0u8; FXFS_WRAPPED_KEY_SIZE])
@@ -131,13 +129,10 @@ impl<'de> Deserialize<'de> for WrappedKeyBytes {
131129
}
132130
}
133131

134-
// TODO(b/419723745): Move this to Fxfs and keep fxfs-crypto free of versioned types.
135-
pub type FxfsKey = FxfsKeyV40;
136-
137132
/// An Fxfs encryption key wrapped in AES-256-GCM-SIV and the associated wrapping key ID.
138133
/// This can be provided to Crypt::unwrap_key to obtain the unwrapped key.
139134
#[derive(Clone, Default, Debug, Serialize, Deserialize, TypeFingerprint, PartialEq)]
140-
pub struct FxfsKeyV40 {
135+
pub struct FxfsKey {
141136
/// The identifier of the wrapping key. The identifier has meaning to whatever is doing the
142137
/// unwrapping.
143138
pub wrapping_key_id: u128,
@@ -146,7 +141,7 @@ pub struct FxfsKeyV40 {
146141
/// https://csrc.nist.gov/CSRC/media/Projects/Block-Cipher-Techniques/documents/BCM/Comments/XTS/follow-up_XTS_comments-Ball.pdf)
147142
/// which is what we do here. Since the key is wrapped with AES-GCM-SIV, there are an
148143
/// additional 16 bytes paid per key (so the actual key material is 32 bytes once unwrapped).
149-
pub key: WrappedKeyBytesV32,
144+
pub key: WrappedKeyBytes,
150145
}
151146

152147
impl Into<fidl_fuchsia_fxfs::FxfsKey> for FxfsKey {
@@ -165,9 +160,6 @@ impl<'a> arbitrary::Arbitrary<'a> for FxfsKey {
165160
}
166161
}
167162

168-
#[derive(Serialize, Deserialize, TypeFingerprint)]
169-
pub struct WrappedKeysV40(pub Vec<(u64, FxfsKeyV40)>);
170-
171163
/// A thin wrapper around a ChaCha20 stream cipher. This will use a zero nonce. **NOTE**: Great
172164
/// care must be taken not to encrypt different plaintext with the same key and offset (even across
173165
/// multiple boots), so consider if this suits your purpose before using it.

src/storage/fxfs/src/object_store.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ use fidl_fuchsia_io as fio;
5959
use fprint::TypeFingerprint;
6060
use fuchsia_sync::Mutex;
6161
use fxfs_crypto::ff1::Ff1;
62-
use fxfs_crypto::{
63-
Cipher, Crypt, FxfsCipher, FxfsKey, FxfsKeyV40, KeyPurpose, StreamCipher, UnwrappedKey,
64-
};
62+
use fxfs_crypto::{Cipher, Crypt, FxfsCipher, KeyPurpose, StreamCipher, UnwrappedKey};
6563
use once_cell::sync::OnceCell;
6664
use scopeguard::ScopeGuard;
6765
use serde::{Deserialize, Serialize};
@@ -76,9 +74,9 @@ pub use extent_record::{
7674
FSVERITY_MERKLE_ATTRIBUTE_ID,
7775
};
7876
pub use object_record::{
79-
AttributeKey, EncryptionKey, EncryptionKeys, ExtendedAttributeValue, FsverityMetadata,
80-
ObjectAttributes, ObjectKey, ObjectKeyData, ObjectKind, ObjectValue, ProjectProperty,
81-
RootDigest,
77+
AttributeKey, EncryptionKey, EncryptionKeys, ExtendedAttributeValue, FsverityMetadata, FxfsKey,
78+
FxfsKeyV40, ObjectAttributes, ObjectKey, ObjectKeyData, ObjectKind, ObjectValue,
79+
ProjectProperty, RootDigest,
8280
};
8381
pub use transaction::Mutation;
8482

src/storage/fxfs/src/object_store/object_record.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ use crate::object_store::extent_record::{
1717
};
1818
use crate::serialized_types::{Migrate, Versioned, migrate_nodefault, migrate_to_version};
1919
use fprint::TypeFingerprint;
20-
use fxfs_crypto::{
21-
FscryptKeyIdentifier, FscryptKeyIdentifierAndNonce, FxfsKeyV40, WrappedKey, WrappedKeysV40,
22-
};
20+
use fxfs_crypto::{FscryptKeyIdentifier, FscryptKeyIdentifierAndNonce, WrappedKey};
2321
use fxfs_unicode::CasefoldString;
2422
use serde::{Deserialize, Serialize};
2523
use std::collections::BTreeMap;
@@ -573,6 +571,11 @@ pub type EncryptionKey = EncryptionKeyV47;
573571
#[cfg_attr(fuzz, derive(arbitrary::Arbitrary))]
574572
pub enum EncryptionKeyV47 {
575573
Fxfs(FxfsKeyV40),
574+
// NOTE: `key_identifier` can be thought of as the "name" of the key to use; it is not a
575+
// per-file or per-directory key. It is similar to Fxfs's wrapping key ID, although it
576+
// doesn't wrap anything. Files using the same `key_identifier` are encrypted using the
577+
// same underlying key, with just differences in the tweak used. Directories also use the
578+
// same underlying key, but some structures are further salted using the provided nonce.
576579
FscryptInoLblk32File { key_identifier: [u8; 16] },
577580
FscryptInoLblk32Dir { key_identifier: [u8; 16], nonce: [u8; 16] },
578581
}
@@ -817,6 +820,9 @@ impl<'a> From<ItemRef<'a, ObjectKey, ObjectValue>>
817820
}
818821
}
819822

823+
pub type FxfsKey = FxfsKeyV40;
824+
pub type FxfsKeyV40 = fxfs_crypto::FxfsKey;
825+
820826
#[cfg(test)]
821827
mod tests {
822828
use super::{ObjectKey, ObjectKeyV43};

src/storage/fxfs/src/object_store/object_record/legacy.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ impl From<EncryptionKeysV40> for EncryptionKeysV47 {
9696
}
9797
}
9898

99+
#[derive(Serialize, Deserialize, TypeFingerprint)]
100+
pub struct WrappedKeysV40(pub Vec<(u64, FxfsKeyV40)>);
101+
99102
#[derive(Migrate, Serialize, Deserialize, TypeFingerprint, Versioned)]
100103
#[migrate_to_version(ObjectValueV47)]
101104
pub enum ObjectValueV46 {

src/storage/fxfs/src/object_store/transaction.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use crate::object_store::AttributeKey;
1212
use crate::object_store::allocator::{AllocatorItem, Reservation};
1313
use crate::object_store::object_manager::{ObjectManager, reserved_space_from_journal_usage};
1414
use crate::object_store::object_record::{
15-
ObjectItem, ObjectItemV40, ObjectItemV41, ObjectItemV43, ObjectItemV46, ObjectItemV47,
16-
ObjectKey, ObjectKeyData, ObjectValue, ProjectProperty,
15+
FxfsKey, FxfsKeyV40, ObjectItem, ObjectItemV40, ObjectItemV41, ObjectItemV43, ObjectItemV46,
16+
ObjectItemV47, ObjectKey, ObjectKeyData, ObjectValue, ProjectProperty,
1717
};
1818
use crate::serialized_types::{Migrate, Versioned, migrate_nodefault, migrate_to_version};
1919
use anyhow::Error;
@@ -22,7 +22,6 @@ use fprint::TypeFingerprint;
2222
use fuchsia_sync::Mutex;
2323
use futures::future::poll_fn;
2424
use futures::pin_mut;
25-
use fxfs_crypto::{FxfsKey, FxfsKeyV40};
2625
use rustc_hash::FxHashMap as HashMap;
2726
use scopeguard::ScopeGuard;
2827
use serde::{Deserialize, Serialize};

0 commit comments

Comments
 (0)