-
Notifications
You must be signed in to change notification settings - Fork 32
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
Add support for new dehydrated device format #199
base: main
Are you sure you want to change the base?
Conversation
4fbc6c6
to
d867b21
Compare
97c798f
to
fbf8e39
Compare
Gonna close and reopen this to see if the codecov thing kicks in. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #199 +/- ##
==========================================
- Coverage 90.28% 90.24% -0.05%
==========================================
Files 34 34
Lines 1905 1989 +84
==========================================
+ Hits 1720 1795 +75
- Misses 185 194 +9 ☔ View full report in Codecov by Sentry. |
so that if new keys get generated, the existing keys don't get overwritten
@poljar can I get a review on this PR? Thanks |
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.
Hi, sorry for the late reply, we miscommunicated on who would do the first review.
A good start but needs a bit more polish.
src/utilities/mod.rs
Outdated
@@ -22,6 +21,8 @@ use base64::{ | |||
engine::{general_purpose, GeneralPurpose}, | |||
Engine, | |||
}; | |||
#[cfg(not(feature = "libolm-compat"))] | |||
pub(crate) use libolm_compat::{pickle_libolm, unpickle_libolm}; |
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.
You can just import this unconditionally and remove the imports from the line bellow.
src/olm/account/mod.rs
Outdated
@@ -439,6 +439,45 @@ impl Account { | |||
|
|||
pickle.try_into() | |||
} | |||
|
|||
/// Create a dehydrated device pickle. |
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 is pretty terse, perhaps we should explain a bit what a dehydrated device is and add an example how this can be used.
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 also has the IV reuse problem, right? Mentioned here and in the MSC. I wonder if we should fix this properly now and just include a random IV or Nonce in the pickle.
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.
Yup, I had considered fixing the IV problem, but also wasn't sure if I wanted to introduce a new encryption scheme into the code. I'll think about it some more.
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 now have a dep on Chacha20
in vodozemac due to the QR Login work, and it's likely going to be needed for the PQ support.
So using a new scheme isn't as problematic anymore.
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.
Added more to the comment, and switch encryption to using Chacha20poly1305
src/olm/account/mod.rs
Outdated
pub(super) struct Pickle { | ||
version: u32, | ||
private_curve25519_key: Box<[u8; 32]>, | ||
private_ed25519_key: Box<[u8; 64]>, | ||
one_time_keys: Vec<OneTimeKey>, | ||
opt_fallback_key: OptFallbackKey, | ||
} |
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.
Since this format will come from the homeserver, we should add a fuzz target for it and fuzz it for a bit to ensure that we're not introducing a vulnerability. We already have a fuzz target for all the other formats we receive over the network and have to decode.
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.
Forgot to respond to this earlier.
I've written the basic code:
use afl::fuzz;
use arbitrary::Arbitrary;
use vodozemac::olm::Account;
#[derive(Arbitrary)]
struct Data {
ciphertext: String,
nonce: String,
key: [u8; 32],
}
fn main() {
fuzz!(|data: Data| {
let _ = Account::from_dehydrated_device(&data.ciphertext, &data.nonce, &data.key);
});
}
It looks like the afl documentation is suggesting to provide some example input? Or can I just let it provide random input?
To use it, do I just run cargo afl fuzz
? When I do that, I get a permission error -- which may be because my home directory is mounted noexec
, so I need to figure out how to get it to run. But I was wondering if there was something else I need to add to the command line.
} | ||
} | ||
|
||
impl From<chacha20poly1305::aead::Error> for DehydratedDeviceError { |
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 using Decryption(#[from] chacha20poly1305::aead::Error)
, but it was complaining about some missing traits. So I had to do this instead. I'm not sure if there's a better way.
src/olm/account/mod.rs
Outdated
pub fn to_dehydrated_device( | ||
&self, | ||
key: &[u8; 32], | ||
) -> Result<(String, String), crate::DehydratedDeviceError> { |
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.
Should I create a new struct instead of returning (String, 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.
Yeah that sounds good, and it might implement Serialize
The clippy failure seems to be in code that I did not change. I'm guessing that I should create a new PR to fix that, rather than adding the fixes to this PR. |
as documented in the current version of MSC3814
Fixes #196