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

Fix the warning for messages from unsigned devices #3743

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spec/unit/crypto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ describe("Crypto", function () {
const event = await buildEncryptedEvent();
expect(await client.getCrypto()!.getEncryptionInfoForEvent(event)).toEqual({
shieldColour: EventShieldColour.RED,
shieldReason: EventShieldReason.UNVERIFIED_IDENTITY,
shieldReason: EventShieldReason.UNSIGNED_DEVICE,
});
});

Expand Down
10 changes: 9 additions & 1 deletion src/crypto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2738,6 +2738,8 @@ export class Crypto extends TypedEventEmitter<CryptoEvent, CryptoEventHandlerMap
const senderId = event.getSender();
if (!senderId || encryptionInfo.mismatchedSender) {
// something definitely wrong is going on here

// previously: E2EState.Warning -> E2ePadlockUnverified -> Red/"Encrypted by an unverified session"
Copy link
Member Author

Choose a reason for hiding this comment

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

these "previously" comments relate to the old logic in EventTile (https://github.com/matrix-org/matrix-react-sdk/blob/v3.80.1/src/components/views/rooms/EventTile.tsx#L579-L637). I found them useful for double-checking the logic.

return {
shieldColour: EventShieldColour.RED,
shieldReason: EventShieldReason.MISMATCHED_SENDER_KEY,
Expand All @@ -2750,11 +2752,13 @@ export class Crypto extends TypedEventEmitter<CryptoEvent, CryptoEventHandlerMap
// shield, otherwise if the user isn't cross-signed then
// nothing's needed
if (!encryptionInfo.authenticated) {
// previously: E2EState.Unauthenticated -> E2ePadlockUnauthenticated -> Grey/"The authenticity of this encrypted message can't be guaranteed on this device."
return {
shieldColour: EventShieldColour.GREY,
shieldReason: EventShieldReason.AUTHENTICITY_NOT_GUARANTEED,
};
} else {
// previously: E2EState.Normal -> no icon
return { shieldColour: EventShieldColour.NONE, shieldReason: null };
}
}
Expand All @@ -2765,26 +2769,30 @@ export class Crypto extends TypedEventEmitter<CryptoEvent, CryptoEventHandlerMap
(await this.getDeviceVerificationStatus(senderId, encryptionInfo.sender.deviceId));

if (!eventSenderTrust) {
// previously: E2EState.Unknown -> E2ePadlockUnknown -> Grey/"Encrypted by a deleted session"
return {
shieldColour: EventShieldColour.GREY,
shieldReason: EventShieldReason.UNKNOWN_DEVICE,
};
}

if (!eventSenderTrust.isVerified()) {
// previously: E2EState.Warning -> E2ePadlockUnverified -> Red/"Encrypted by an unverified session"
return {
shieldColour: EventShieldColour.RED,
shieldReason: EventShieldReason.UNVERIFIED_IDENTITY,
shieldReason: EventShieldReason.UNSIGNED_DEVICE,
};
}

if (!encryptionInfo.authenticated) {
// previously: E2EState.Unauthenticated -> E2ePadlockUnauthenticated -> Grey/"The authenticity of this encrypted message can't be guaranteed on this device."
return {
shieldColour: EventShieldColour.GREY,
shieldReason: EventShieldReason.AUTHENTICITY_NOT_GUARANTEED,
};
}

// previously: E2EState.Verified -> no icon
return { shieldColour: EventShieldColour.NONE, shieldReason: null };
}

Expand Down
1 change: 1 addition & 0 deletions src/rust-crypto/rust-crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1649,6 +1649,7 @@ function rustEncryptionInfoToJsEncryptionInfo(
if (shieldState.message === null) {
shieldReason = null;
} else if (shieldState.message === "Encrypted by an unverified user.") {
// this case isn't actually used with lax shield semantics.
Copy link
Member Author

Choose a reason for hiding this comment

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

this is unrelated, but something I came across while I was figuring out what happened and it doesn't feel like worth making a separate PR for

shieldReason = EventShieldReason.UNVERIFIED_IDENTITY;
} else if (shieldState.message === "Encrypted by a device not verified by its owner.") {
shieldReason = EventShieldReason.UNSIGNED_DEVICE;
Expand Down
Loading