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

crypto: fix BackedUpRoomKey de/serialization #3246

Merged
merged 1 commit into from
Mar 19, 2024

Conversation

BillCarsonFr
Copy link
Member

@BillCarsonFr BillCarsonFr commented Mar 19, 2024

Fixes #3247

A source of #3197

When downloading keys if the forwarding_curve25519_key_chain contains items the deserialisation would fail with error: Json(Error("invalid type: string \"EQCtWSJclhxEU9mGlF4erDHxIacpUQz70yjYVRPODTg\", expected an array of length 32", line: 1, column: 255))

As a consequence the key import fails silently with:
Successfully imported room keys total_count=0 imported_count=0 room_keys={}
That would cause unable to decrypt errors for history.

A serde attribute deserialize_curve_key_vec was missing.

  • Public API changes documented in changelogs (optional)

Signed-off-by:

@BillCarsonFr BillCarsonFr requested a review from a team as a code owner March 19, 2024 15:07
@BillCarsonFr BillCarsonFr requested review from bnjbvr and removed request for a team March 19, 2024 15:07
@poljar poljar requested review from poljar and removed request for bnjbvr March 19, 2024 15:11
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 some small suggestions.

crates/matrix-sdk-crypto/src/olm/group_sessions/mod.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-crypto/src/olm/group_sessions/mod.rs Outdated Show resolved Hide resolved
Copy link

codecov bot commented Mar 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.62%. Comparing base (1e35188) to head (4b201a9).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3246      +/-   ##
==========================================
- Coverage   83.62%   83.62%   -0.01%     
==========================================
  Files         236      236              
  Lines       24451    24451              
==========================================
- Hits        20447    20446       -1     
- Misses       4004     4005       +1     

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

@BillCarsonFr BillCarsonFr force-pushed the valere/fix_backup_deserialize_forwarding_curve branch from c8e737b to 4b201a9 Compare March 19, 2024 15:26
@poljar poljar merged commit 3ac123d into main Mar 19, 2024
35 checks passed
@poljar poljar deleted the valere/fix_backup_deserialize_forwarding_curve branch March 19, 2024 16:10
@richvdh richvdh changed the title crypto: fix BackedUpRoomKey Serialization crypto: fix BackedUpRoomKey deserialization Apr 29, 2024
@richvdh
Copy link
Member

richvdh commented Apr 29, 2024

AFAICT this is a fix to deserialization, not serialization. I have updated the PR title accordingly.

@poljar
Copy link
Contributor

poljar commented Apr 29, 2024

AFAICT this is a fix to _de_serialization, not serialization. I have updated the PR title accordingly.

It's for both:

image

@richvdh
Copy link
Member

richvdh commented Apr 29, 2024

Hrm ok. Serialisation doesn't appear to be tested; and the bug it clams to fix (#3247), and the description of the PR, only mention deserialisation. Hence my confusion.

Any idea what the effect of this issue would have been on serialization? Presumably the forwarding_curve25519_key_chain property would have been serialised as an array of individual bytes, or something? But maybe that didn't really matter in practice because we so rarely use room keys with forwarding_curve25519_key_chain?

@poljar
Copy link
Contributor

poljar commented Apr 29, 2024

Any idea what the effect of this issue would have been on serialization? Presumably the forwarding_curve25519_key_chain property would have been serialised as an array of individual bytes, or something? But maybe that didn't really matter in practice because we so rarely use room keys with forwarding_curve25519_key_chain?

Yes, all of that is correct. It would not base64 encode the keys, it would instead create a 32 byte long array. I'm not completely sure, but I think it didn't matter as the SDK doesn't really use the forwarding chain, I would need to look at the codepaths where we receive room keys.

@richvdh richvdh changed the title crypto: fix BackedUpRoomKey deserialization crypto: fix BackedUpRoomKey de/serialization Apr 29, 2024
@richvdh
Copy link
Member

richvdh commented Apr 29, 2024

As a consequence the key import fails silently with:

For links: the fact that deserialization errors were swallowed was a separate problem, seemingly fixed in #3149.

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.

Import from backup fails if the key SessionData contains curve keys in forwarding_curve25519_key_chain
3 participants