Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
crypto: Authenticated backup #2659
crypto: Authenticated backup #2659
Changes from 10 commits
e58bd7e
b234be3
2454306
c091a0b
c3be55c
1438753
6cd5665
0a66718
f697aa2
8eceee6
15ca4fa
3217845
dd191a5
04fdce3
a454bcd
7ed633e
0268eeb
22f4474
cdc025e
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 really a fan of this function signature, wasn't a fan before this PR either.
I added a different one here:
matrix-rust-sdk/crates/matrix-sdk-crypto/src/backups/keys/decryption.rs
Lines 225 to 242 in 2f41fe1
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.
We usually use
Box<[u8; 32]>
for this. And add deriveZeroize
andZeroizeOnDrop
on the container type.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.
If I do that, and pass the
Box[<u8; 32]>
as a function argument, as inMegolmV1BackupKey::new
, then it will automagically do the right thing when it becomes part of the struct?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.
If by right thing you mean that it will zeroize the
Box<[u8; 32]>
when the whole struct gets dropped, then yes.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 tried deriving
Zeroize
andZeroizeOnDrop
on the container type, which isInnerBackupKey
but that gives me errors:
Should I do something else, or is there a way to fix this?
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 error complains that not all the types in the fields of the struct implement
Zeroize
. But this is completely fine since only one field contains private key material which should be zeroized.You can make the compiler happy by implementing
Zeroize
manually, or use the#[zeroize(skip)
attribute on the fields which don't need to be zeroized, more info about this macro can be found in thezeroize
crate docs: https://docs.rs/zeroize/latest/zeroize/index.html#custom-derive-supportThere 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 did
but I get
So it seems like zeroize doesn't like
Option
. One solution that I can think of is to makemac_key: HmacSha256Key
, so it always has some sort of key stored, but add a boolean flag that indicates whether the key is actually used. But that doesn't seem very Rust-y to me. Are there any better solutions?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.
It's not the
Option<T>
per se, it's theOption<Box<T>>
, not quite sure why that would be sincezeroizing
implementsZeroize
for bothOption<T>
andBox<T>
. Alright, let's stick to theZeroizing
thing since this seems to be too annoying.