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

feat!: Allow E2EE rooms to reset its room key #33328

Merged
merged 66 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
fbeea3e
TEMPORARY Revert "chore!: Removed Mongo 4.4. support and added 7.0 (#…
ggazzo Sep 16, 2024
c2524ba
chore!: Improve permissions check on teams endpoints (#32351)
matheusbsilva137 May 9, 2024
2a93e45
new type for subs
KevLehman Sep 12, 2024
900b9f6
add keyid to message
KevLehman Sep 12, 2024
a4247f5
create reset room key endpoint
KevLehman Sep 13, 2024
3fd6b92
remove old keys when user resets their own key
KevLehman Sep 13, 2024
c47ec7c
wip
KevLehman Sep 16, 2024
f9715ab
lint
KevLehman Sep 19, 2024
434db60
keys
KevLehman Sep 20, 2024
ad76a26
keyID is already present on messages
KevLehman Sep 24, 2024
f4b49cb
accept old room keys on suggestion of group key
KevLehman Sep 24, 2024
39a1674
ts
KevLehman Sep 24, 2024
75e9697
ts
KevLehman Sep 24, 2024
a399b5f
ts
KevLehman Sep 25, 2024
0abe59f
Update apps/meteor/server/models/raw/Rooms.ts
KevLehman Sep 25, 2024
db34761
revert randomization here
KevLehman Sep 25, 2024
db6a9b3
decrypt oldkeys when received instead of every message
KevLehman Sep 25, 2024
71ee71a
share old room keys
KevLehman Sep 26, 2024
cf53864
Discard changes to .changeset/fair-seahorses-laugh.md
KevLehman Sep 27, 2024
f856705
Discard changes to .changeset/fluffy-knives-count.md
KevLehman Sep 27, 2024
42c42a7
Discard changes to .github/workflows/ci-test-e2e.yml
KevLehman Sep 27, 2024
90c022e
Discard changes to .github/workflows/ci.yml
KevLehman Sep 27, 2024
56eb7c2
Discard changes to apps/meteor/tests/end-to-end/api/teams.ts
KevLehman Sep 27, 2024
7d61ecc
Discard changes to docker-compose-local.yml
KevLehman Sep 27, 2024
0ec8056
allow user to provide suggested old keys to users along with keys
KevLehman Sep 30, 2024
dc1a81d
provide right keys
KevLehman Sep 30, 2024
61dc75c
Revert "fix: Async E2EE key exchange not working on develop (#33378)"
KevLehman Sep 30, 2024
4043f77
Reset room key full cycle
KevLehman Sep 30, 2024
255e46a
lint
KevLehman Sep 30, 2024
a0df56e
lint
KevLehman Oct 1, 2024
c066c93
Discard changes to apps/meteor/server/startup/serverRunning.js
KevLehman Oct 2, 2024
3974d53
fix for multikey
KevLehman Oct 2, 2024
c8425d4
refactor code
KevLehman Oct 2, 2024
ad9d81c
unify sha256 functions into helper
KevLehman Oct 2, 2024
86a1bf4
lint
KevLehman Oct 2, 2024
5dfa387
id appreciate if you reported all issues at once
KevLehman Oct 2, 2024
ecaaf60
change key for now
KevLehman Oct 2, 2024
ebefd24
Proper messages and fix for old room key check
KevLehman Oct 3, 2024
674eeef
old room keys exchange working
KevLehman Oct 3, 2024
d9157ab
Apply suggestions from code review
KevLehman Oct 3, 2024
62baee3
Update apps/meteor/app/e2e/client/rocketchat.e2e.room.js
KevLehman Oct 7, 2024
abab2d8
provided key ts was saved as string
KevLehman Oct 7, 2024
cfa6312
use always latest room key id
KevLehman Oct 7, 2024
d049b9e
put room into waiting keys when a sub is encrypted without keyID
KevLehman Oct 7, 2024
3bc4cea
dont need format date
KevLehman Oct 7, 2024
1aba2ad
not move state when already on state
KevLehman Oct 7, 2024
1b7626a
not re-create but reassign
KevLehman Oct 7, 2024
138cc1e
revert waiting key logic
KevLehman Oct 8, 2024
90ad101
fix
KevLehman Oct 8, 2024
66f46dc
fix
KevLehman Oct 8, 2024
71d7cb0
better error when publickey is missing
KevLehman Oct 8, 2024
a2c01ce
dont call reset room key when room has no keyID yet
KevLehman Oct 8, 2024
eac1374
temporal fix for testing hook
KevLehman Oct 8, 2024
df90e1d
lint
KevLehman Oct 8, 2024
76df7f8
reset should not happen before room has keyID set
KevLehman Oct 9, 2024
e883a30
reapply reverted commit
KevLehman Oct 9, 2024
45a2fda
more fixes
KevLehman Oct 9, 2024
8450d46
add perm check
KevLehman Oct 9, 2024
3aa1b41
Discard changes to apps/meteor/client/ui.ts
KevLehman Oct 10, 2024
b3759dd
remove testing changes
KevLehman Oct 10, 2024
45cc62f
cr
KevLehman Oct 10, 2024
1b1ae7c
auto set key (#33516)
KevLehman Oct 11, 2024
19ba48b
cr
KevLehman Oct 11, 2024
1d0d6d0
filter more
KevLehman Oct 11, 2024
a0e985d
Create smooth-horses-draw.md
KevLehman Oct 11, 2024
9fac813
Apply suggestions from code review
KevLehman Oct 14, 2024
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
11 changes: 11 additions & 0 deletions .changeset/smooth-horses-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@rocket.chat/meteor": major
"@rocket.chat/core-services": patch
"@rocket.chat/core-typings": patch
"@rocket.chat/ddp-client": patch
"@rocket.chat/i18n": patch
"@rocket.chat/model-typings": patch
"@rocket.chat/rest-typings": patch
---

Allows authorized users to reset the encryption key for end-to-end encrypted rooms. This aims to prevent situations where all users of a room have lost the encryption key, and as such, the access to the room.
42 changes: 42 additions & 0 deletions apps/meteor/app/api/server/v1/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,23 @@ import {
ise2eUpdateGroupKeyParamsPOST,
isE2EProvideUsersGroupKeyProps,
isE2EFetchUsersWaitingForGroupKeyProps,
isE2EResetRoomKeyProps,
} from '@rocket.chat/rest-typings';
import ExpiryMap from 'expiry-map';
import { Meteor } from 'meteor/meteor';

import { canAccessRoomIdAsync } from '../../../authorization/server/functions/canAccessRoom';
import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
import { handleSuggestedGroupKey } from '../../../e2e/server/functions/handleSuggestedGroupKey';
import { provideUsersSuggestedGroupKeys } from '../../../e2e/server/functions/provideUsersSuggestedGroupKeys';
import { resetRoomKey } from '../../../e2e/server/functions/resetRoomKey';
import { settings } from '../../../settings/server';
import { API } from '../api';

// After 10s the room lock will expire, meaning that if for some reason the process never completed
// The next reset will be available 10s after
const LockMap = new ExpiryMap<string, boolean>(10000);

API.v1.addRoute(
'e2e.fetchMyKeys',
{
Expand Down Expand Up @@ -284,3 +293,36 @@ API.v1.addRoute(
},
},
);

// This should have permissions
API.v1.addRoute(
'e2e.resetRoomKey',
{ authRequired: true, validateParams: isE2EResetRoomKeyProps },
{
async post() {
const { rid, e2eKey, e2eKeyId } = this.bodyParams;
if (!(await hasPermissionAsync(this.userId, 'toggle-room-e2e-encryption', rid))) {
return API.v1.unauthorized();
}
if (LockMap.has(rid)) {
throw new Error('error-e2e-key-reset-in-progress');
}

LockMap.set(rid, true);

if (!(await canAccessRoomIdAsync(rid, this.userId))) {
throw new Error('error-not-allowed');
}

try {
await resetRoomKey(rid, this.userId, e2eKey, e2eKeyId);
return API.v1.success();
} catch (e) {
console.error(e);
KevLehman marked this conversation as resolved.
Show resolved Hide resolved
return API.v1.failure('error-e2e-key-reset-failed');
} finally {
LockMap.delete(rid);
}
},
},
);
7 changes: 6 additions & 1 deletion apps/meteor/app/e2e/client/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,14 @@ export async function generateMnemonicPhrase(n, sep = ' ') {
return result.join(sep);
}

export async function createSha256Hash(data) {
export async function createSha256HashFromText(data) {
const hash = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(data));
return Array.from(new Uint8Array(hash))
.map((b) => b.toString(16).padStart(2, '0'))
.join('');
}

export async function sha256HashFromArrayBuffer(arrayBuffer) {
const hashArray = Array.from(new Uint8Array(await crypto.subtle.digest('SHA-256', arrayBuffer)));
return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
}
Loading
Loading