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

Implement getting verification cancellation info in Rust crypto #3947

Merged
merged 6 commits into from
Jan 25, 2024

Conversation

uhoreg
Copy link
Member

@uhoreg uhoreg commented Dec 8, 2023

Fixes element-hq/element-web#26652

Checklist

  • Tests written for new code (and old code if feasible)
  • Linter and other CI checks pass
  • Sign-off given on the changes (see CONTRIBUTING.md)

Here's what your changelog entry will look like:

🐛 Bug Fixes

@uhoreg uhoreg requested a review from a team as a code owner December 8, 2023 01:02
@uhoreg
Copy link
Member Author

uhoreg commented Dec 8, 2023

Don't know if I need tests for this

Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know if I need tests for this

Yes please. (I'm a bit surprised the coverage metrics are happy, but whatever).

There are already some tests in https://github.com/matrix-org/matrix-js-sdk/blob/c24f38fa1783862f361b2ee80e6c6698d7c7091c/spec/integ/crypto/verification.spec.ts which do cancellation. It should be pretty easy to add some calls to these getters to check that they give the right value.

@uhoreg
Copy link
Member Author

uhoreg commented Dec 11, 2023

I realized that cancelInfo.cancelCode() returns a matrix-rust-sdk-crypto-wasm verification.CancelCode, rather than a ruma::events::key::verification::cancel::CancelCode, which on the JavaScript side just becomes a mostly meaningless number. I think that the best way to fix this is to make cancelInfo.cancelCode() return a string, which is the .to_string()-ed ruma CancelCode (since the string is all that the JS side cares about), though that of course would require incompatible changes to the wasm bindings. I could get away without changing the wasm bindings by putting a map of numbers to the string equivalents in rust-crypto/verification.ts, but that seems kludgy.

and if we can get rid of the cancel_with_code function from the Rust binding, or make it take a String instead (it looks like nothing in the JS SDK calls that function), then we can get rid of the wasm version of CancelCode completely.

@richvdh
Copy link
Member

richvdh commented Dec 12, 2023

I realized that cancelInfo.cancelCode() returns a matrix-rust-sdk-crypto-wasm verification.CancelCode, rather than a ruma::events::key::verification::cancel::CancelCode, which on the JavaScript side just becomes a mostly meaningless number. I think that the best way to fix this is to make cancelInfo.cancelCode() return a string, which is the .to_string()-ed ruma CancelCode (since the string is all that the JS side cares about), though that of course would require incompatible changes to the wasm bindings. I could get away without changing the wasm bindings by putting a map of numbers to the string equivalents in rust-crypto/verification.ts, but that seems kludgy.

and if we can get rid of the cancel_with_code function from the Rust binding, or make it take a String instead (it looks like nothing in the JS SDK calls that function), then we can get rid of the wasm version of CancelCode completely.

Yes, all this sounds sensible to me. Don't worry about making breaking changes to the wasm bindings.

@uhoreg
Copy link
Member Author

uhoreg commented Dec 13, 2023

wasm PR is at matrix-org/matrix-rust-sdk-crypto-wasm#71

The tests on this PR won't pass until it gets merged, and this PR is updated to use the new code (which I assume means just waiting for a new release of the bindings and then bumping the required version number in package.json)

@uhoreg
Copy link
Member Author

uhoreg commented Jan 23, 2024

I merged in develop, which depends on the latest crypto wasm bindings. So the tests now pass.

Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

src/rust-crypto/verification.ts Outdated Show resolved Hide resolved
Comment on lines +746 to +747
expect(request.cancellationCode).toEqual("m.user");
expect(request.cancellingUserId).toEqual("@alice:localhost");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like there are quite a lot of codepaths here which we're not testing at all, but I won't insist for now :)

@uhoreg uhoreg added this pull request to the merge queue Jan 25, 2024
Merged via the queue into matrix-org:develop with commit 5e2acb5 Jan 25, 2024
20 checks passed
@uhoreg uhoreg deleted the cancellation_info_rust branch January 25, 2024 04:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants