-
Notifications
You must be signed in to change notification settings - Fork 291
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: MLSStateHandler updates clientEntities directly #16008
Changes from 3 commits
6446b2a
ac7dac3
afd9a56
9ca69fa
3f9be0c
4345b18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,8 +19,10 @@ | |
|
||
import {X509Certificate} from '@peculiar/x509'; | ||
import {QualifiedId} from '@wireapp/api-client/lib/user'; | ||
import {WireIdentity} from '@wireapp/core/lib/messagingProtocols/mls'; | ||
import {container} from 'tsyringe'; | ||
|
||
import {ClientEntity} from 'src/script/client'; | ||
import {Conversation} from 'src/script/entity/Conversation'; | ||
import {VerificationMessageType} from 'src/script/message/VerificationMessageType'; | ||
import {Core} from 'src/script/service/CoreSingleton'; | ||
|
@@ -95,31 +97,41 @@ export class MLSConversationVerificationStateHandler { | |
* This function returns the WireIdentity of all userDeviceEntities in a conversation, as long as they have a certificate. | ||
* If the conversation has userDeviceEntities without a certificate, it will not be included in the returned array | ||
* | ||
* It also updates the isMLSVerified observable of all the devices in the conversation | ||
*/ | ||
private getAllUserEntitiesInConversation = async (conversation: Conversation) => { | ||
if (!conversation.groupId) { | ||
this.logger.error('Conversation has no groupId', conversation.name); | ||
throw new Error('Conversation has no groupId'); | ||
} | ||
|
||
private updateUserDevices = async (conversation: Conversation) => { | ||
const userEntities = conversation.getAllUserEntities(); | ||
|
||
const deviceUserPairs = userEntities | ||
.flatMap(userEntity => { | ||
return userEntity.devices().map(device => ({[device.id]: userEntity.qualifiedId})); | ||
}) | ||
.reduce((acc, current) => { | ||
return {...acc, ...current}; | ||
}, {}); | ||
|
||
const identities = await this.core.service!.e2eIdentity!.getUserDeviceEntities( | ||
conversation.groupId, | ||
deviceUserPairs, | ||
); | ||
const allClients: ClientEntity[] = []; | ||
const allIdentities: WireIdentity[] = []; | ||
userEntities.forEach(async userEntity => { | ||
const devices = userEntity.devices(); | ||
const deviceUserPairs = devices | ||
.map(device => ({ | ||
[device.id]: userEntity.qualifiedId, | ||
})) | ||
.reduce((acc, current) => { | ||
return {...acc, ...current}; | ||
}, {}); | ||
const identities = await this.core.service!.e2eIdentity!.getUserDeviceEntities( | ||
conversation.groupId!, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there is a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. have a look at the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point. Changed the types and added the guard |
||
deviceUserPairs, | ||
); | ||
identities.forEach(identity => { | ||
if (identity.certificate) { | ||
const device = devices.find(device => device.id === identity.clientId); | ||
/** | ||
* ToDo: Change the current implementation of isMLSVerified to be stored in Zustand instead of ko.observable | ||
*/ | ||
device?.meta.isMLSVerified?.(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This meta is saved to the DB, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it should. I added all the entries for that. |
||
} | ||
}); | ||
allIdentities.push(...identities); | ||
allClients.push(...devices); | ||
}); | ||
|
||
return { | ||
identities, | ||
isResultComplete: Object.keys(deviceUserPairs).length === identities.length, | ||
identities: allIdentities, | ||
isResultComplete: allClients.length === allIdentities.length, | ||
qualifiedIds: userEntities.map(userEntity => userEntity.qualifiedId), | ||
}; | ||
}; | ||
|
@@ -140,8 +152,7 @@ export class MLSConversationVerificationStateHandler { | |
return; | ||
} | ||
|
||
const {isResultComplete, identities, qualifiedIds} = | ||
await this.getAllUserEntitiesInConversation(conversationEntity); | ||
const {isResultComplete, identities, qualifiedIds} = await this.updateUserDevices(conversationEntity); | ||
|
||
// If the number of userDevicePairs is not equal to the number of identities, our Conversation is not secure | ||
if (!isResultComplete) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I needed to fix yarn.lock issues.
Did that by clearing the locks and rebuilding them freshly. Thats why some packages got updates