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

runfix: Correctly check if user has mls device before performing mls operations #17344

Merged
merged 2 commits into from
Apr 30, 2024
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@lexical/react": "0.12.5",
"@wireapp/avs": "9.6.12",
"@wireapp/commons": "5.2.7",
"@wireapp/core": "46.0.4",
"@wireapp/core": "46.0.5",
"@wireapp/react-ui-kit": "9.16.4",
"@wireapp/store-engine-dexie": "2.1.8",
"@wireapp/webapp-events": "0.20.1",
Expand Down
3 changes: 3 additions & 0 deletions src/__mocks__/@wireapp/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export class Account extends EventEmitter {
cancelTask: jest.fn(),
};

get hasMLSDevice() {
return true;
}
configureMLSCallbacks = jest.fn();
enrollE2EI = jest.fn();
service = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {ConversationVerificationState} from '../../ConversationVerificationState

describe('MLSConversationVerificationStateHandler', () => {
const conversationState = new ConversationState();
let core = new Core();
let core: Core;
const groupId = 'AAEAAKA0LuGtiU7NjqqlZIE2dQUAZWxuYS53aXJlLmxpbms=';
const conversation = new Conversation(createUuid(), '', ConversationProtocol.MLS);
conversationState.conversations.push(conversation);
Expand Down Expand Up @@ -73,6 +73,20 @@ describe('MLSConversationVerificationStateHandler', () => {
expect(core.service?.mls?.on).not.toHaveBeenCalled();
});

it('should do nothing if the user does not have an mls device', () => {
jest.spyOn(core, 'hasMLSDevice', 'get').mockReturnValue(false);

new MLSConversationVerificationStateHandler(
'domain',
() => {},
async () => {},
conversationState,
core,
);

expect(core.service?.mls?.on).not.toHaveBeenCalled();
});

describe('checkConversationVerificationState', () => {
it('should reset to unverified if mls group does not exist anymore', async () => {
let triggerEpochChange: Function = () => {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ export class MLSConversationVerificationStateHandler {
private readonly core: Core,
) {
this.logger = getLogger('MLSConversationVerificationStateHandler');
// We need to check if the core service is available and if the e2eIdentity is available
if (!this.core.service?.mls || !this.core.service?.e2eIdentity) {
// We need to check if the core account has a valid MLS device and that e2ei is enabled
if (!this.core.hasMLSDevice || !this.core.service?.e2eIdentity) {
return;
}

// We hook into the newEpoch event of the MLS service to check if the conversation needs to be verified or degraded
this.core.service.mls.on('newEpoch', this.onEpochChanged);
this.core.service?.mls?.on('newEpoch', this.onEpochChanged);
this.core.service.e2eIdentity.on('crlChanged', ({domain}) => this.handleNewRevocationList(domain));
}

Expand Down
6 changes: 3 additions & 3 deletions src/script/main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {getLogger, Logger} from 'Util/Logger';
import {includesString} from 'Util/StringUtil';
import {TIME_IN_MILLIS} from 'Util/TimeUtil';
import {appendParameter} from 'Util/UrlUtil';
import {checkIndexedDb, supportsMLS} from 'Util/util';
import {checkIndexedDb} from 'Util/util';

import '../../style/default.less';
import {AssetRepository} from '../assets/AssetRepository';
Expand Down Expand Up @@ -443,7 +443,7 @@ export class App {
// We load all the users the self user is connected with
await userRepository.loadUsers(selfUser, connections, conversations, teamMembers);

if (supportsMLS()) {
if (this.core.hasMLSDevice) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if we have a MLS device it means that:

  • the env supportsMLS (previous check)
  • the team has MLS enabled
  • the user has a valid mls device

(it a more exhaustive check than the previous supportsMLS check)

//if mls is supported, we need to initialize the callbacks (they are used when decrypting messages)
conversationRepository.initMLSConversationRecoveredListener();
conversationRepository.registerMLSConversationVerificationStateHandler(
Expand Down Expand Up @@ -472,7 +472,7 @@ export class App {

await conversationRepository.init1To1Conversations(connections, conversations);

if (supportsMLS()) {
if (this.core.hasMLSDevice) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this one is the fix to automation correct?
Seems like the change in MLSConversationVerificationStateHandler isn't necessarry? (that's the one breaking unit tests)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

exactly, I'm working on the fix right now :)

//add the potential `self` and `team` conversations
await initialiseSelfAndTeamConversations(conversations, selfUser, clientEntity.id, this.core);

Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4763,9 +4763,9 @@ __metadata:
languageName: node
linkType: hard

"@wireapp/core@npm:46.0.4":
version: 46.0.4
resolution: "@wireapp/core@npm:46.0.4"
"@wireapp/core@npm:46.0.5":
version: 46.0.5
resolution: "@wireapp/core@npm:46.0.5"
dependencies:
"@wireapp/api-client": ^27.0.1
"@wireapp/commons": ^5.2.7
Expand All @@ -4785,7 +4785,7 @@ __metadata:
long: ^5.2.0
uuidjs: 4.2.13
zod: 3.23.4
checksum: 15a9d8a9a7ddbdc220dba21a22a80fc20f93793717947c1a2a802266659d6adfe27c3904064dc592aac88858e4a8a9abe6e3ba90e4cdd714db3074cc9fb25c56
checksum: f78001b45cdac85c4a3918a60f9d4c06b82e9f750f64b60789c1f196830d27fb9eca37ede190ca8bcd9ee96c5a019cdf3b5f2a9f3c0700726efd19cbd18e3f60
languageName: node
linkType: hard

Expand Down Expand Up @@ -17457,7 +17457,7 @@ __metadata:
"@wireapp/avs": 9.6.12
"@wireapp/commons": 5.2.7
"@wireapp/copy-config": 2.1.14
"@wireapp/core": 46.0.4
"@wireapp/core": 46.0.5
"@wireapp/eslint-config": 3.0.5
"@wireapp/prettier-config": 0.6.3
"@wireapp/react-ui-kit": 9.16.4
Expand Down
Loading