Skip to content

Commit

Permalink
feat: Un-encrypted messages not allowed in E2EE rooms (#32040)
Browse files Browse the repository at this point in the history
Co-authored-by: gabriellsh <40830821+gabriellsh@users.noreply.github.com>
Co-authored-by: Hugo Costa <20212776+hugocostadev@users.noreply.github.com>
  • Loading branch information
3 people authored May 24, 2024
1 parent a565999 commit 4fd9c4c
Show file tree
Hide file tree
Showing 22 changed files with 700 additions and 106 deletions.
8 changes: 8 additions & 0 deletions .changeset/slow-cars-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@rocket.chat/i18n': minor
'@rocket.chat/meteor': minor
---

Introduced a new setting which doesn't allow users to access encrypted rooms until E2EE is configured and also doesn't allow users to send un-encrypted messages in encrypted rooms.

New room setup for E2EE feature which helps users to setup their E2EE keys and introduced states to E2EE feature.
9 changes: 9 additions & 0 deletions apps/meteor/app/e2e/client/E2EEState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export enum E2EEState {
NOT_STARTED = 'NOT_STARTED',
DISABLED = 'DISABLED',
LOADING_KEYS = 'LOADING_KEYS',
READY = 'READY',
SAVE_PASSWORD = 'SAVE_PASSWORD',
ENTER_PASSWORD = 'ENTER_PASSWORD',
ERROR = 'ERROR',
}
15 changes: 15 additions & 0 deletions apps/meteor/app/e2e/client/rocketchat.e2e.room.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const permitedMutations = {
E2ERoomState.ERROR,
E2ERoomState.DISABLED,
E2ERoomState.WAITING_KEYS,
E2ERoomState.CREATING_KEYS,
],
};

Expand Down Expand Up @@ -92,6 +93,10 @@ export class E2ERoom extends Emitter {
logError(`E2E ROOM { state: ${this.state}, rid: ${this.roomId} }`, ...msg);
}

getState() {
return this.state;
}

setState(requestedState) {
const currentState = this.state;
const nextState = filterMutation(currentState, requestedState);
Expand Down Expand Up @@ -208,6 +213,10 @@ export class E2ERoom extends Emitter {

// Initiates E2E Encryption
async handshake() {
if (!e2e.isReady()) {
return;
}

if (this.state !== E2ERoomState.KEYS_RECEIVED && this.state !== E2ERoomState.NOT_STARTED) {
return;
}
Expand Down Expand Up @@ -459,5 +468,11 @@ export class E2ERoom extends Emitter {
}

this.encryptKeyForOtherParticipants();
this.setState(E2ERoomState.READY);
}

onStateChange(cb) {
this.on('STATE_CHANGED', cb);
return () => this.off('STATE_CHANGED', cb);
}
}
Loading

0 comments on commit 4fd9c4c

Please sign in to comment.