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: req_new_epoch advance epoch number #14635

Merged
merged 2 commits into from
Feb 7, 2023
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 @@ -3,7 +3,7 @@
"@emotion/react": "11.10.5",
"@types/eslint": "^8.4.10",
"@wireapp/avs": "9.0.20",
"@wireapp/core": "38.9.1",
"@wireapp/core": "38.10.1",
"@wireapp/lru-cache": "3.8.1",
"@wireapp/react-ui-kit": "9.3.5",
"@wireapp/store-engine-dexie": "2.0.4",
Expand Down
32 changes: 19 additions & 13 deletions src/script/calling/mlsConference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
*/

import {SUBCONVERSATION_ID} from '@wireapp/api-client/lib/conversation/Subconversation';
import {QualifiedId} from '@wireapp/api-client/lib/user';
import {MLSService} from '@wireapp/core/lib/messagingProtocols/mls';
import {constructFullyQualifiedClientId} from '@wireapp/core/lib/util/fullyQualifiedClientIdUtils';
Expand Down Expand Up @@ -50,16 +51,26 @@ const generateSubconversationMembers = async (

export const getSubconversationEpochInfo = async (
{mlsService}: {mlsService: MLSService},
subconversationGroupId: string,
parentGroupId: string,
conversationId: QualifiedId,
shouldAdvanceEpoch = false,
): Promise<{
members: SubconversationEpochInfoMember[];
epoch: number;
secretKey: string;
keyLength: number;
}> => {
const subconversationGroupId = await mlsService.getGroupIdFromConversationId(
conversationId,
SUBCONVERSATION_ID.CONFERENCE,
);
const parentGroupId = await mlsService.getGroupIdFromConversationId(conversationId);

const members = await generateSubconversationMembers({mlsService}, subconversationGroupId, parentGroupId);

if (shouldAdvanceEpoch) {
await mlsService.renewKeyMaterial(subconversationGroupId);
}

const epoch = Number(await mlsService.getEpoch(subconversationGroupId));

const secretKey = await mlsService.exportSecretKey(subconversationGroupId, KEY_LENGTH);
Expand All @@ -77,27 +88,22 @@ export const subscribeToEpochUpdates = async (
keyLength: number;
}) => void,
): Promise<() => void> => {
const subconversation = await mlsService.joinConferenceSubconversation(conversationId);
const {epoch: initialEpoch, groupId: subconversationGroupId} = await mlsService.joinConferenceSubconversation(
conversationId,
);

const forwardNewEpoch = async ({groupId, epoch}: {groupId: string; epoch: number}) => {
if (groupId !== subconversation.group_id) {
if (groupId !== subconversationGroupId) {
return;
}

const subconversationGroupId = subconversation.group_id;
const parentConversationGroupId = await mlsService.getGroupIdFromConversationId(conversationId);

const {keyLength, secretKey, members} = await getSubconversationEpochInfo(
{mlsService},
subconversationGroupId,
parentConversationGroupId,
);
const {keyLength, secretKey, members} = await getSubconversationEpochInfo({mlsService}, conversationId);
onEpochUpdate({epoch: Number(epoch), keyLength, secretKey, members});
};

mlsService.on('newEpoch', forwardNewEpoch);

await forwardNewEpoch({groupId: subconversation.group_id, epoch: subconversation.epoch});
await forwardNewEpoch({groupId: subconversationGroupId, epoch: initialEpoch});

return () => mlsService.off('newEpoch', forwardNewEpoch);
};
19 changes: 10 additions & 9 deletions src/script/view_model/CallingViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
*/

import {SUBCONVERSATION_ID} from '@wireapp/api-client/lib/conversation/Subconversation';
import {QualifiedId} from '@wireapp/api-client/lib/user';
import ko from 'knockout';
import {container} from 'tsyringe';
Expand Down Expand Up @@ -207,27 +208,27 @@ export class CallingViewModel {
return !!this.callState.joinedCall();
};

const updateEpochInfo = async (conversationId: QualifiedId) => {
const updateEpochInfo = async (conversationId: QualifiedId, shouldAdvanceEpoch = false) => {
const conversation = this.getConversationById(conversationId);
if (!conversation?.isUsingMLSProtocol) {
return;
}

const subconversation = await this.mlsService.getConferenceSubconversation(conversationId);
const subconversationGroupId = await this.mlsService.getGroupIdFromConversationId(
conversationId,
SUBCONVERSATION_ID.CONFERENCE,
);

//we don't want to react to avs callbacks when conversation was not yet established
const isMLSConversationEstablished = await this.mlsService.conversationExists(subconversation.group_id);
const isMLSConversationEstablished = await this.mlsService.conversationExists(subconversationGroupId);
if (!isMLSConversationEstablished) {
return;
}

const parentGroupId = await this.mlsService.getGroupIdFromConversationId(conversationId);
const subconversationGroupId = subconversation.group_id;

const {epoch, keyLength, secretKey, members} = await getSubconversationEpochInfo(
{mlsService: this.mlsService},
subconversationGroupId,
parentGroupId,
conversationId,
shouldAdvanceEpoch,
);
this.callingRepository.setEpochInfo(conversationId, {epoch, keyLength, secretKey}, members);
};
Expand All @@ -243,7 +244,7 @@ export class CallingViewModel {
this.callingRepository.onRequestClientsCallback(updateEpochInfo);

//update epoch info when AVS requests new epoch
this.callingRepository.onRequestNewEpochCallback(updateEpochInfo);
this.callingRepository.onRequestNewEpochCallback(conversationId => updateEpochInfo(conversationId, true));

//once we leave a call, we unsubscribe from all the events we've subscribed to during this call
this.callingRepository.onLeaveCall(callingSubscriptions.removeCall);
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4383,9 +4383,9 @@ __metadata:
languageName: node
linkType: hard

"@wireapp/core@npm:38.9.1":
version: 38.9.1
resolution: "@wireapp/core@npm:38.9.1"
"@wireapp/core@npm:38.10.1":
version: 38.10.1
resolution: "@wireapp/core@npm:38.10.1"
dependencies:
"@wireapp/api-client": ^22.15.2
"@wireapp/commons": ^5.0.4
Expand All @@ -4403,7 +4403,7 @@ __metadata:
logdown: 3.3.1
long: ^5.2.0
uuidjs: 4.2.13
checksum: 70b8acbc8f885b630d98f7963c4951bc5fc2be5db193d192545710136a25f1f42dfb8076e366a3c23aae9fc90dcad47b43d7603a04c1a10db5280a303b8f7e43
checksum: 5ba0480421d26be42bedbd7d90e2c9aa70dc76e9fe40013899919c2c14dbfa9ac304f7e02c456b3783d3854c4012d9ced956a94f7a3e9ac114877756dbcf3350
languageName: node
linkType: hard

Expand Down Expand Up @@ -16712,7 +16712,7 @@ __metadata:
"@typescript-eslint/parser": ^5.50.0
"@wireapp/avs": 9.0.20
"@wireapp/copy-config": 2.0.7
"@wireapp/core": 38.9.1
"@wireapp/core": 38.10.1
"@wireapp/eslint-config": 2.1.1
"@wireapp/lru-cache": 3.8.1
"@wireapp/prettier-config": 0.5.2
Expand Down