Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4303 from matrix-org/jryans/id-change-red
Browse files Browse the repository at this point in the history
Show red shield for users that become unverified
  • Loading branch information
jryans authored Mar 31, 2020
2 parents c094afb + 520b4c3 commit 2455c5a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/components/views/right_panel/UserInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ export const getE2EStatus = (cli, userId, devices) => {
return hasUnverifiedDevice ? "warning" : "verified";
}
const isMe = userId === cli.getUserId();
const userVerified = cli.checkUserTrust(userId).isCrossSigningVerified();
if (!userVerified) return "normal";
const userTrust = cli.checkUserTrust(userId);
if (!userTrust.isCrossSigningVerified()) {
return userTrust.wasCrossSigningVerified() ? "warning" : "normal";
}

const anyDeviceUnverified = devices.some(device => {
const { deviceId } = device;
Expand Down
6 changes: 3 additions & 3 deletions src/components/views/rooms/MemberTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ export default createReactClass({
const cli = MatrixClientPeg.get();
const { userId } = this.props.member;
const isMe = userId === cli.getUserId();
const userVerified = cli.checkUserTrust(userId).isCrossSigningVerified();
if (!userVerified) {
const userTrust = cli.checkUserTrust(userId);
if (!userTrust.isCrossSigningVerified()) {
this.setState({
e2eStatus: "normal",
e2eStatus: userTrust.wasCrossSigningVerified() ? "warning" : "normal",
});
return;
}
Expand Down
8 changes: 8 additions & 0 deletions src/utils/ShieldUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ interface Client {
getUserId: () => string;
checkUserTrust: (userId: string) => {
isCrossSigningVerified: () => boolean
wasCrossSigningVerified: () => boolean
};
getStoredDevicesForUser: (userId: string) => Promise<[{ deviceId: string }]>;
checkDeviceTrust: (userId: string, deviceId: string) => {
Expand All @@ -29,6 +30,13 @@ export async function shieldStatusForRoom(client: Client, room: Room): Promise<s
verified : unverified).push(userId);
});

/* Alarm if any unverified users were verified before. */
for (const userId of unverified) {
if (client.checkUserTrust(userId).wasCrossSigningVerified()) {
return "warning";
}
}

/* Check all verified user devices. */
/* Don't alarm if no other users are verified */
const includeUser = (verified.length > 0) && // Don't alarm for self in rooms where nobody else is verified
Expand Down
17 changes: 15 additions & 2 deletions test/utils/ShieldUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function mkClient(selfTrust) {
getUserId: () => "@self:localhost",
checkUserTrust: (userId) => ({
isCrossSigningVerified: () => userId[1] == "T",
wasCrossSigningVerified: () => userId[1] == "T" || userId[1] == "W",
}),
checkDeviceTrust: (userId, deviceId) => ({
isVerified: () => userId === "@self:localhost" ? selfTrust : userId[2] == "T",
Expand Down Expand Up @@ -150,7 +151,7 @@ describe("shieldStatusForMembership other-trust behaviour", function() {
const client = mkClient(true);
const room = {
roomId: dm ? "DM" : "other",
getEncryptionTargetMembers: () => ["@self:localhost", "@TF:h", "@TT: h"].map((userId) => ({userId})),
getEncryptionTargetMembers: () => ["@self:localhost", "@TF:h", "@TT:h"].map((userId) => ({userId})),
};
const status = await shieldStatusForRoom(client, room);
expect(status).toEqual(result);
Expand All @@ -162,7 +163,19 @@ describe("shieldStatusForMembership other-trust behaviour", function() {
const client = mkClient(true);
const room = {
roomId: dm ? "DM" : "other",
getEncryptionTargetMembers: () => ["@self:localhost", "@FF:h", "@FT: h"].map((userId) => ({userId})),
getEncryptionTargetMembers: () => ["@self:localhost", "@FF:h", "@FT:h"].map((userId) => ({userId})),
};
const status = await shieldStatusForRoom(client, room);
expect(status).toEqual(result);
});

it.each(
[["warning", true], ["warning", false]],
)("2 was verified: returns '%s', DM = %s", async (result, dm) => {
const client = mkClient(true);
const room = {
roomId: dm ? "DM" : "other",
getEncryptionTargetMembers: () => ["@self:localhost", "@WF:h", "@FT:h"].map((userId) => ({userId})),
};
const status = await shieldStatusForRoom(client, room);
expect(status).toEqual(result);
Expand Down

0 comments on commit 2455c5a

Please sign in to comment.