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

Replace uses of checkDeviceTrust with getDeviceVerificationStatus #10663

Merged
merged 12 commits into from
Apr 24, 2023

Conversation

richvdh
Copy link
Member

@richvdh richvdh commented Apr 19, 2023

matrix-org/matrix-js-sdk#3287 and matrix-org/matrix-js-sdk#3303 added a new API called getDeviceVerificationStatus. Let's use it.

Hopefully this makes sense to review commit-by-commit.

The quality gate isn't quite met but there are cypress tests covering the places where coverage is lacking.

Fixes element-hq/element-web#25092 and element-hq/element-web#25093


This change is marked as an internal change (Task), so will not be included in the changelog.

@richvdh richvdh added the T-Task Refactoring, enabling or disabling functionality, other engineering tasks label Apr 19, 2023
@richvdh richvdh force-pushed the rav/element-r/01_device_verification_status branch from e16cba5 to 60f6e20 Compare April 19, 2023 13:52
@richvdh richvdh force-pushed the rav/element-r/01_device_verification_status branch from 60f6e20 to 2545dc6 Compare April 19, 2023 14:00
@richvdh richvdh force-pushed the rav/element-r/01_device_verification_status branch from 2545dc6 to d9c3e33 Compare April 19, 2023 15:26
@richvdh richvdh force-pushed the rav/element-r/01_device_verification_status branch from d9c3e33 to e487a07 Compare April 19, 2023 22:08
@richvdh richvdh force-pushed the rav/element-r/01_device_verification_status branch from e487a07 to 1d88f27 Compare April 20, 2023 06:18
@richvdh richvdh force-pushed the rav/element-r/01_device_verification_status branch from 1d88f27 to 3fc5044 Compare April 20, 2023 11:09
@richvdh richvdh force-pushed the rav/element-r/01_device_verification_status branch 2 times, most recently from 36f9494 to b2284c3 Compare April 20, 2023 12:54
@richvdh richvdh force-pushed the rav/element-r/01_device_verification_status branch from b2284c3 to f1adf65 Compare April 21, 2023 10:44
We have a method called `fetchDevicesWithVerification` which is currently used
in the new Session manager. Let's use it for the (old) Devices Panel too,
because it allows us to check the device verification upfront, rather than on
the fly, which is going to be handy when that operation becomes async
these are in an async method, but currently use `some`. We need to invent an
`asyncSome` (we already have an `asyncEvery`) and use that
This is ok except we need an "unmounted" guard because it's an old-style
componment
@richvdh richvdh force-pushed the rav/element-r/01_device_verification_status branch from 639cc2b to 1cc6e40 Compare April 21, 2023 15:18
src/DeviceListener.ts Outdated Show resolved Hide resolved
Comment on lines +327 to +335
/**
* Async version of Array.some.
*/
export async function asyncSome<T>(values: T[], predicate: (value: T) => Promise<boolean>): Promise<boolean> {
for (const value of values) {
if (await predicate(value)) return true;
}
return false;
}
Copy link
Member

Choose a reason for hiding this comment

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

Might this be worth doing with Promise.race or similar as one slow or never resolving promise might wedge things up here

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe. I'm somewhat keen to keep it symmetrical with asyncEvery, and the semantics are much easier to reason about if the promises happen serially.

Copy link
Member

Choose a reason for hiding this comment

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

That's fair, didn't see asyncEvery

src/components/views/right_panel/UserInfo.tsx Outdated Show resolved Hide resolved
@@ -258,7 +270,7 @@ function DevicesSection({
// cross-signing so that other users can then safely trust you.
// For other people's devices, the more general verified check that
// includes locally verified devices can be used.
const isVerified = isMe ? deviceTrust.isCrossSigningVerified() : deviceTrust.isVerified();
const isVerified = deviceTrust && (isMe ? deviceTrust.crossSigningVerified : deviceTrust.isVerified());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const isVerified = deviceTrust && (isMe ? deviceTrust.crossSigningVerified : deviceTrust.isVerified());
const isVerified = isMe ? deviceTrust?.crossSigningVerified : deviceTrust?.isVerified());

To match L177 in the same file

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem here is avoiding the implicit cast to boolean if deviceTrust is nullish. We could do something like isVerified = !!(isMe ? deviceTrust?.crossSigningVerified : deviceTrust?.isVerified())) but I'm far from convinced that's clearer.

At L177, we have an explicit check on deviceTrust, so I'd say my variant of this is closer to L177 than yours.

Comment on lines 327 to 328
.getCrypto()
?.getDeviceVerificationStatus(cli.getUserId()!, device.deviceId!);
!.getDeviceVerificationStatus(cli.getUserId()!, device.deviceId!);
Copy link
Member

Choose a reason for hiding this comment

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

The ! needs to be on .getCrypto()!

Copy link
Member Author

Choose a reason for hiding this comment

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

bah

@richvdh richvdh merged commit d7bb804 into develop Apr 24, 2023
@richvdh richvdh deleted the rav/element-r/01_device_verification_status branch April 24, 2023 13:19
richvdh added a commit that referenced this pull request Apr 26, 2023
richvdh added a commit that referenced this pull request May 3, 2023
* Fix remaing use of `checkDeviceTrust`

Followup to #10663

* fix strict type-checking error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-Task Refactoring, enabling or disabling functionality, other engineering tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Element-R: Replace CryptoBackend.checkDeviceTrust
2 participants