Skip to content

Commit 2631b90

Browse files
authored
Update the display of decryption failures due to failed trust requirement (#28300)
* update the display of decryption failures due to failed trust requirement * add test for not showing shield
1 parent 502cc91 commit 2631b90

File tree

8 files changed

+63
-33
lines changed

8 files changed

+63
-33
lines changed

playwright/e2e/crypto/invisible-crypto.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ test.describe("Invisible cryptography", () => {
5151
/* should show an error for a message from a previously verified device */
5252
await bobSecondDevice.sendMessage(testRoomId, "test encrypted from user that was previously verified");
5353
const lastTile = page.locator(".mx_EventTile_last");
54-
await expect(lastTile).toContainText("Verified identity has changed");
54+
await expect(lastTile).toContainText("Sender's verified identity has changed");
5555
});
5656
});

res/css/views/messages/_DecryptionFailureBody.pcss

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,11 @@ Please see LICENSE files in the repository root for full details.
1111
font-style: italic;
1212
}
1313

14-
/* Formatting for the "Verified identity has changed" error */
15-
.mx_DecryptionFailureVerifiedIdentityChanged > span {
16-
/* Show it in red */
17-
color: var(--cpd-color-text-critical-primary);
18-
background-color: var(--cpd-color-bg-critical-subtle);
19-
20-
/* With a red border */
21-
border: 1px solid var(--cpd-color-border-critical-subtle);
22-
border-radius: $font-16px;
23-
24-
/* Some space inside the border */
25-
padding: var(--cpd-space-1x) var(--cpd-space-3x) var(--cpd-space-1x) var(--cpd-space-2x);
26-
27-
/* some space between the (!) icon and text */
14+
/* Formatting for errors due to sender trust requirement failures */
15+
.mx_DecryptionFailureSenderTrustRequirement > span {
16+
/* some space between the (/) icon and text */
2817
display: inline-flex;
29-
gap: var(--cpd-space-2x);
18+
gap: var(--cpd-space-1x);
3019

3120
/* Center vertically */
3221
align-items: center;

src/components/views/messages/DecryptionFailureBody.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import classNames from "classnames";
1010
import React, { forwardRef, ForwardRefExoticComponent, useContext } from "react";
1111
import { MatrixEvent } from "matrix-js-sdk/src/matrix";
1212
import { DecryptionFailureCode } from "matrix-js-sdk/src/crypto-api";
13-
import { WarningIcon } from "@vector-im/compound-design-tokens/assets/web/icons";
13+
import { BlockIcon } from "@vector-im/compound-design-tokens/assets/web/icons";
1414

1515
import { _t } from "../../../languageHandler";
1616
import { IBodyProps } from "./IBodyProps";
@@ -41,15 +41,20 @@ function getErrorMessage(mxEvent: MatrixEvent, isVerified: boolean | undefined):
4141
case DecryptionFailureCode.SENDER_IDENTITY_PREVIOUSLY_VERIFIED:
4242
return (
4343
<span>
44-
<WarningIcon className="mx_Icon mx_Icon_16" />
44+
<BlockIcon className="mx_Icon mx_Icon_16" />
4545
{_t("timeline|decryption_failure|sender_identity_previously_verified")}
4646
</span>
4747
);
4848

4949
case DecryptionFailureCode.UNSIGNED_SENDER_DEVICE:
5050
// TODO: event should be hidden instead of showing this error.
5151
// To be revisited as part of https://github.com/element-hq/element-meta/issues/2449
52-
return _t("timeline|decryption_failure|sender_unsigned_device");
52+
return (
53+
<span>
54+
<BlockIcon className="mx_Icon mx_Icon_16" />
55+
{_t("timeline|decryption_failure|sender_unsigned_device")}
56+
</span>
57+
);
5358
}
5459
return _t("timeline|decryption_failure|unable_to_decrypt");
5560
}
@@ -58,7 +63,8 @@ function getErrorMessage(mxEvent: MatrixEvent, isVerified: boolean | undefined):
5863
function errorClassName(mxEvent: MatrixEvent): string | null {
5964
switch (mxEvent.decryptionFailureReason) {
6065
case DecryptionFailureCode.SENDER_IDENTITY_PREVIOUSLY_VERIFIED:
61-
return "mx_DecryptionFailureVerifiedIdentityChanged";
66+
case DecryptionFailureCode.UNSIGNED_SENDER_DEVICE:
67+
return "mx_DecryptionFailureSenderTrustRequirement";
6268

6369
default:
6470
return null;

src/components/views/rooms/EventTile.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { logger } from "matrix-js-sdk/src/logger";
2828
import { CallErrorCode } from "matrix-js-sdk/src/webrtc/call";
2929
import {
3030
CryptoEvent,
31+
DecryptionFailureCode,
3132
EventShieldColour,
3233
EventShieldReason,
3334
UserVerificationStatus,
@@ -719,7 +720,14 @@ export class UnwrappedEventTile extends React.Component<EventTileProps, IState>
719720

720721
// event could not be decrypted
721722
if (ev.isDecryptionFailure()) {
722-
return <E2ePadlockDecryptionFailure />;
723+
switch (ev.decryptionFailureReason) {
724+
// These two errors get icons from DecryptionFailureBody, so we hide the padlock icon
725+
case DecryptionFailureCode.SENDER_IDENTITY_PREVIOUSLY_VERIFIED:
726+
case DecryptionFailureCode.UNSIGNED_SENDER_DEVICE:
727+
return null;
728+
default:
729+
return <E2ePadlockDecryptionFailure />;
730+
}
723731
}
724732

725733
if (this.state.shieldColour !== EventShieldColour.NONE) {

src/i18n/strings/en_EN.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3266,8 +3266,8 @@
32663266
"historical_event_no_key_backup": "Historical messages are not available on this device",
32673267
"historical_event_unverified_device": "You need to verify this device for access to historical messages",
32683268
"historical_event_user_not_joined": "You don't have access to this message",
3269-
"sender_identity_previously_verified": "Verified identity has changed",
3270-
"sender_unsigned_device": "Encrypted by a device not verified by its owner.",
3269+
"sender_identity_previously_verified": "Sender's verified identity has changed",
3270+
"sender_unsigned_device": "Sent from an insecure device.",
32713271
"unable_to_decrypt": "Unable to decrypt message"
32723272
},
32733273
"disambiguated_profile": "%(displayName)s (%(matrixId)s)",

test/unit-tests/components/views/messages/DecryptionFailureBody-test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,6 @@ describe("DecryptionFailureBody", () => {
129129
const { container } = customRender(event);
130130

131131
// Then
132-
expect(container).toHaveTextContent("Encrypted by a device not verified by its owner");
132+
expect(container).toHaveTextContent("Sent from an insecure device");
133133
});
134134
});

test/unit-tests/components/views/messages/__snapshots__/DecryptionFailureBody-test.tsx.snap

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ exports[`DecryptionFailureBody Should display "Unable to decrypt message" 1`] =
2323
exports[`DecryptionFailureBody should handle messages from users who change identities after verification 1`] = `
2424
<div>
2525
<div
26-
class="mx_DecryptionFailureBody mx_EventTile_content mx_DecryptionFailureVerifiedIdentityChanged"
26+
class="mx_DecryptionFailureBody mx_EventTile_content mx_DecryptionFailureSenderTrustRequirement"
2727
>
2828
<span>
2929
<svg
@@ -35,15 +35,10 @@ exports[`DecryptionFailureBody should handle messages from users who change iden
3535
xmlns="http://www.w3.org/2000/svg"
3636
>
3737
<path
38-
d="M12.713 17.713A.968.968 0 0 1 12 18a.968.968 0 0 1-.713-.287A.967.967 0 0 1 11 17a.97.97 0 0 1 .287-.712A.968.968 0 0 1 12 16a.97.97 0 0 1 .713.288A.968.968 0 0 1 13 17a.97.97 0 0 1-.287.713Zm0-4A.968.968 0 0 1 12 14a.968.968 0 0 1-.713-.287A.967.967 0 0 1 11 13V9a.97.97 0 0 1 .287-.712A.968.968 0 0 1 12 8a.97.97 0 0 1 .713.288A.968.968 0 0 1 13 9v4a.97.97 0 0 1-.287.713Z"
39-
/>
40-
<path
41-
clip-rule="evenodd"
42-
d="M10.264 3.039c.767-1.344 2.705-1.344 3.472 0l8.554 14.969c.762 1.333-.2 2.992-1.736 2.992H3.446c-1.535 0-2.498-1.659-1.736-2.992l8.553-14.969ZM3.446 19 12 4.031l8.554 14.97H3.446Z"
43-
fill-rule="evenodd"
38+
d="M12 22a9.738 9.738 0 0 1-3.9-.788 10.099 10.099 0 0 1-3.175-2.137c-.9-.9-1.612-1.958-2.137-3.175A9.738 9.738 0 0 1 2 12a9.74 9.74 0 0 1 .788-3.9 10.099 10.099 0 0 1 2.137-3.175c.9-.9 1.958-1.612 3.175-2.137A9.738 9.738 0 0 1 12 2a9.74 9.74 0 0 1 3.9.788 10.098 10.098 0 0 1 3.175 2.137c.9.9 1.613 1.958 2.137 3.175A9.738 9.738 0 0 1 22 12a9.738 9.738 0 0 1-.788 3.9 10.098 10.098 0 0 1-2.137 3.175c-.9.9-1.958 1.613-3.175 2.137A9.738 9.738 0 0 1 12 22Zm0-2c2.233 0 4.125-.775 5.675-2.325C19.225 16.125 20 14.233 20 12c0-.9-.146-1.767-.438-2.6A7.951 7.951 0 0 0 18.3 7.1L7.1 18.3c.7.55 1.467.97 2.3 1.262.833.292 1.7.438 2.6.438Zm-6.3-3.1L16.9 5.7a7.95 7.95 0 0 0-2.3-1.263A7.813 7.813 0 0 0 12 4c-2.233 0-4.125.775-5.675 2.325C4.775 7.875 4 9.767 4 12c0 .9.146 1.767.438 2.6A7.95 7.95 0 0 0 5.7 16.9Z"
4439
/>
4540
</svg>
46-
Verified identity has changed
41+
Sender's verified identity has changed
4742
</span>
4843
</div>
4944
</div>

test/unit-tests/components/views/rooms/EventTile-test.tsx

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ import {
1919
Room,
2020
TweakName,
2121
} from "matrix-js-sdk/src/matrix";
22-
import { CryptoApi, EventEncryptionInfo, EventShieldColour, EventShieldReason } from "matrix-js-sdk/src/crypto-api";
22+
import {
23+
CryptoApi,
24+
DecryptionFailureCode,
25+
EventEncryptionInfo,
26+
EventShieldColour,
27+
EventShieldReason,
28+
} from "matrix-js-sdk/src/crypto-api";
2329
import { mkEncryptedMatrixEvent } from "matrix-js-sdk/src/testing";
2430

2531
import EventTile, { EventTileProps } from "../../../../../src/components/views/rooms/EventTile";
@@ -350,6 +356,32 @@ describe("EventTile", () => {
350356
"mx_EventTile_e2eIcon_decryption_failure",
351357
);
352358
});
359+
360+
it("should not show a shield for previously-verified users", async () => {
361+
mxEvent = mkEvent({
362+
type: "m.room.encrypted",
363+
room: room.roomId,
364+
user: "@alice:example.org",
365+
event: true,
366+
content: {},
367+
});
368+
369+
const mockCrypto = {
370+
decryptEvent: async (_ev): Promise<IEventDecryptionResult> => {
371+
throw new Error("can't decrypt");
372+
},
373+
} as Parameters<MatrixEvent["attemptDecryption"]>[0];
374+
await mxEvent.attemptDecryption(mockCrypto);
375+
mxEvent["_decryptionFailureReason"] = DecryptionFailureCode.SENDER_IDENTITY_PREVIOUSLY_VERIFIED;
376+
377+
const { container } = getComponent();
378+
await act(flushPromises);
379+
380+
const eventTiles = container.getElementsByClassName("mx_EventTile");
381+
expect(eventTiles).toHaveLength(1);
382+
383+
expect(container.getElementsByClassName("mx_EventTile_e2eIcon")).toHaveLength(0);
384+
});
353385
});
354386

355387
it("should update the warning when the event is edited", async () => {

0 commit comments

Comments
 (0)