-
Notifications
You must be signed in to change notification settings - Fork 291
feat(crypto): Add EncryptionInfo
to Decrypted
to-device variant
#5074
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?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5074 +/- ##
==========================================
+ Coverage 85.80% 85.82% +0.01%
==========================================
Files 332 332
Lines 36149 36171 +22
==========================================
+ Hits 31017 31042 +25
+ Misses 5132 5129 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
223f499
to
f14ecc9
Compare
@@ -127,6 +130,7 @@ pub(crate) struct DecryptionResult { | |||
pub event: Box<AnyDecryptedOlmEvent>, | |||
pub raw_event: Raw<AnyToDeviceEvent>, | |||
pub sender_key: Curve25519PublicKey, |
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.
Maybe we can now remove this sender_key
field? given that it is now in the encryption info.
It is a bit less convenient because it is now in the AlgorithmInfo
that could be olm or megolm.
Maybe I could had a function sender_key()
that would use a as_variant!(self, Self::OlmV1Curve25519AesSha2)
?
/// The info if the event was encrypted using m.olm.v1.curve25519-aes-sha2 | ||
OlmV1Curve25519AesSha2 { | ||
// The sender device key, base64 encoded | ||
curve25519_public_key_base64: 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.
Why the stringly typing? Curve25519Publickey
is a Copy
type so it's cheaper to copy it around, provides stronger typing and has a to_base64()
method if you do need a string.
I feel like we've been here already once.
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 tried to keep it consistent with the other variant.
I suppose I have then to use serde(deserialize_with = "deserialize_curve_key", .. "serialize_curve_key"
?
I'll do it too for MegolmV1AesSha2
to stay consistant
{ | ||
assert_eq!(session_id, expected_session_id); | ||
} else { | ||
panic!("Expected MegolmV1AesSha2"); | ||
} |
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.
There's assert_let!()
and assert_matches!()
for this kind of code snippet.
#[serde(deserialize_with = "deserialize_decrypted_variant")] | ||
Decrypted { | ||
/// The raw decrypted event | ||
raw: Raw<AnyToDeviceEvent>, |
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 doesn't need to be accessible?
raw: Raw<AnyToDeviceEvent>, | |
pub raw: Raw<AnyToDeviceEvent>, |
/// The raw decrypted event | ||
raw: Raw<AnyToDeviceEvent>, | ||
/// The olm encryption info | ||
encryption_info: EncryptionInfo, |
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.
Likewise:
encryption_info: EncryptionInfo, | |
pub encryption_info: EncryptionInfo, |
if json.get("raw").is_some() && json.get("encryption_info").is_some() { | ||
// If the "raw" field is present, it's a NewFormat | ||
#[derive(Deserialize)] | ||
struct NewFormat { | ||
raw: Raw<AnyToDeviceEvent>, | ||
encryption_info: EncryptionInfo, | ||
} |
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.
What happens if someone puts a raw
and encryption_info
field into the JSON of the event?
It seems to me that the sender of the event, perhaps in collusion with the homeserver, might insert an encryption_info
on their own.
Come to think of, why does this need to support Serialize
and Deserialize
? Because the widgets API will transfer this verbatim to the widget using JSON?
In any case, I think it's safer to not have a migration here since we don't seem to need it.
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.
Come to think of, why does this need to support Serialize and Deserialize?
I'll check but I think it mostly to export them to bindings?
But I agree that those should not be persisted, but we previously said that if we put something as serializable we should provide migration. I wish we had another trait for things that can be persisted
The
ProcessedToDeviceEvent::Decrypted
variant now also have anEncryptionInfo
field.Format changed from
Decrypted(Raw<AnyToDeviceEvent>)
toDecrypted { raw: Raw<AnyToDeviceEvent>, encryption_info: EncryptionInfo) }
It is needed for future work on widget in order to support encrypted to device properly via
add_event_handler
This is a follow-up on
crypto: Add variants for plain text and encrypted to-device events #4935
refactor(crypto): Move
session_id
fromEncryptionInfo
toAlgorithmInfo
as it is megolm specific #4981Public API changes documented in changelogs (optional)
Signed-off-by: