Skip to content
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

feat(crypto): Support storing the dehydrated device pickle key #4383

Merged
merged 1 commit into from
Dec 13, 2024

Conversation

BillCarsonFr
Copy link
Member

Fixes #4186

No need for migration, the pickle key is stored in the generic Key/Value store.

  • Public API changes documented in changelogs (optional)

Signed-off-by:

Copy link

codecov bot commented Dec 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.30%. Comparing base (6dcefe4) to head (2b39476).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4383      +/-   ##
==========================================
+ Coverage   85.27%   85.30%   +0.02%     
==========================================
  Files         282      282              
  Lines       31207    31257      +50     
==========================================
+ Hits        26613    26663      +50     
  Misses       4594     4594              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@BillCarsonFr BillCarsonFr force-pushed the valere/cache_dehydration_pickle_key branch 2 times, most recently from 821df3d to 3162d33 Compare December 6, 2024 15:13
@BillCarsonFr BillCarsonFr marked this pull request as ready for review December 6, 2024 15:28
@BillCarsonFr BillCarsonFr requested review from a team as code owners December 6, 2024 15:28
@BillCarsonFr BillCarsonFr requested review from bnjbvr and poljar and removed request for a team December 6, 2024 15:28
@bnjbvr bnjbvr removed their request for review December 9, 2024 09:26
crates/matrix-sdk-crypto/src/machine/mod.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-crypto/src/machine/mod.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-crypto/src/machine/mod.rs Outdated Show resolved Hide resolved
@@ -846,6 +852,11 @@ impl CryptoStore for SqliteCryptoStore {
txn.set_kv("backup_version_v1", &serialized_backup_version)?;
}

if let Some(pickle_key) = &changes.dehydrated_device_pickle_key {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for the indexedDB implementation, docs and implementation don't match.

@BillCarsonFr BillCarsonFr requested a review from poljar December 11, 2024 11:54
Copy link
Contributor

@poljar poljar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, left a question and some nits about moving the public methods around.

crates/matrix-sdk-crypto/src/machine/mod.rs Outdated Show resolved Hide resolved
Comment on lines +500 to +504
async fn delete_dehydrated_device_pickle_key(&self) -> Result<()> {
let mut lock = self.dehydrated_device_pickle_key.write().await;
*lock = None;
Ok(())
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm missing something, but is this method used anywhere? It's part of the trait, but It's not exposed to users nor do we internally delete the key anywhere.

Would it make sense to delete it automagically when we create a new dehydrated device?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exposed now. Should be used by apps.
It could make sense if we changed a bit the API, currently create does not need the pickle key, it's upload_keys that use it. Not sure how it would work. Need to talk a bit with @uhoreg to see if can have a better integrated usage of pickle key handling

key.copy_from_slice(pickle_key);

// safe to unwrap because we checked the size
let raw_bytes: [u8; 32] = pickle_key.try_into().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would leave the copy from slice, try_into() moves self and moves are copies in Rust. Now here it's fine because you move a reference so we only copy the reference instead of the whole byte array.

But we always handle secret key material using copy_from_slice() and there it's obvious where the copy is made. The panic/unwrap is then also implicit and it's understood that you need a size check before.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BillCarsonFr BillCarsonFr force-pushed the valere/cache_dehydration_pickle_key branch from 604e379 to 2b39476 Compare December 13, 2024 12:05
@BillCarsonFr BillCarsonFr merged commit 789bd31 into main Dec 13, 2024
40 checks passed
@BillCarsonFr BillCarsonFr deleted the valere/cache_dehydration_pickle_key branch December 13, 2024 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Device Dehydration: Cache the dehydration key
2 participants