-
Notifications
You must be signed in to change notification settings - Fork 329
Refactor/improve performance sqlite db #5472
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?
Refactor/improve performance sqlite db #5472
Conversation
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.
Not quite there yet I'm afraid.
CodSpeed Performance ReportMerging #5472 will not alter performanceComparing Summary
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #5472 +/- ##
==========================================
- Coverage 88.63% 88.61% -0.02%
==========================================
Files 341 341
Lines 95138 95191 +53
Branches 95138 95191 +53
==========================================
+ Hits 84322 84354 +32
- Misses 6628 6650 +22
+ Partials 4188 4187 -1 ☔ View full report in Codecov by Sentry. |
Hey I'm unsure about the |
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.
Hey I'm unsure about the get_or_create_store_cipher could you point me in the right direction?
What about get_or_create_store_cipher()
looks reasonable except that the secrets are copied and not zeroized.
You need to either not copy them or you need to zeroize them using the zeroize crate.
…f encrypted store
…nstead of a only a key to encrypt a store
…f an insecure export function
065ec6e
to
9718b79
Compare
@poljar Hey I think I managed the implementation, could you provide me with feedback please? |
…g the opening with a key
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.
Sorry for the late reply, I was unavailable the past two weeks. This seems almost good to go.
Though we have a tricky problem with hidden copies of the secret key material.
@@ -6,6 +6,14 @@ All notable changes to this project will be documented in this file. | |||
|
|||
## [Unreleased] - ReleaseDate | |||
|
|||
### Features | |||
- Implement a new constructrot that allow to open SqliteCryptoStore with a Key |
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.
- Implement a new constructrot that allow to open SqliteCryptoStore with a Key | |
- Implement a new constructor that allows to open the SqliteCryptoStore with a cryptographic key. |
#[zeroize] | ||
Key([u8; 32]), | ||
#[zeroize] | ||
PassPhrase(String), |
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.
The enum variants need to be documented.
@@ -43,13 +44,21 @@ pub use self::state_store::{SqliteStateStore, DATABASE_NAME as STATE_STORE_DATAB | |||
#[cfg(test)] | |||
matrix_sdk_test_utils::init_tracing_for_tests!(); | |||
|
|||
#[derive(Clone, Debug, Eq, PartialEq, Zeroize)] |
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.
I think we should derive ZeroizeOnDrop
here so we don't need the manual zeroize()
calls.
#[derive(Clone, Debug, Eq, PartialEq, Zeroize)] | ||
pub enum Secret { | ||
#[zeroize] | ||
Key([u8; 32]), |
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.
This should be inside a Box
or inside a Zeroizing
struct so we avoid unintended copies due to moves being a memcpy
call in Rust land. More info here: https://benma.github.io/2020/10/16/rust-zeroize-move.html.
In short, every time you pass the Secret
to a function a memcpy
call will copy the contents of the array.
If a Box
is used, the pointer is instead copied.
#[zeroize] | ||
Key([u8; 32]), | ||
#[zeroize] | ||
PassPhrase(String), |
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.
Same here, this will produce unintended copies, Zeroizing<String>
would make sense.
Signed-off-by: multi [email protected]
Fixes #3697