add a way to share currently distributing keypair to added members

pull/1501/head
Audric Ackermann 4 years ago
parent 78e7255cb8
commit 0c1343cad5
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -33,6 +33,11 @@ import { MessageController } from '../session/messages';
import { ClosedGroupEncryptionPairReplyMessage } from '../session/messages/outgoing/content/data/group';
import { queueAllCachedFromSource } from './receiver';
export const distributingClosedGroupEncryptionKeyPairs = new Map<
string,
ECKeyPair
>();
export async function handleClosedGroupControlMessage(
envelope: EnvelopePlus,
groupUpdate: SignalService.DataMessage.ClosedGroupControlMessage
@ -456,6 +461,9 @@ async function handleClosedGroupEncryptionKeyPair(
);
if (isKeyPairAlreadyHere) {
const existingKeyPairs = await getAllEncryptionKeyPairsForGroup(
groupPublicKey
);
window.log.info('Dropping already saved keypair for group', groupPublicKey);
await removeFromCache(envelope);
return;
@ -764,11 +772,17 @@ async function sendLatestKeyPairToUsers(
groupPubKey: string,
targetUsers: Array<string>
) {
// use the inMemory keypair if found
const inMemoryKeyPair = distributingClosedGroupEncryptionKeyPairs.get(
groupPubKey
);
// Get the latest encryption key pair
const latestKeyPair = await getLatestClosedGroupEncryptionKeyPair(
groupPubKey
);
if (!latestKeyPair) {
if (!inMemoryKeyPair && !latestKeyPair) {
window.log.info(
'We do not have the keypair ourself, so dropping this message.'
);
@ -789,7 +803,7 @@ async function sendLatestKeyPairToUsers(
const wrappers = await ClosedGroup.buildEncryptionKeyPairWrappers(
[member],
ECKeyPair.fromHexKeyPair(latestKeyPair)
inMemoryKeyPair || ECKeyPair.fromHexKeyPair(latestKeyPair)
);
const keypairsMessage = new ClosedGroupEncryptionPairReplyMessage({

@ -35,6 +35,7 @@ import {
ClosedGroupUpdateMessage,
} from '../messages/outgoing/content/data/group';
import { MessageController } from '../messages';
import { distributingClosedGroupEncryptionKeyPairs } from '../../receiver/closedGroups';
export interface GroupInfo {
id: string;
@ -572,11 +573,15 @@ export async function generateAndSendNewEncryptionKeyPair(
expireTimer,
});
distributingClosedGroupEncryptionKeyPairs.set(toHex(groupId), newKeyPair);
const messageSentCallback = async () => {
window.log.info(
`KeyPairMessage for ClosedGroup ${groupPublicKey} is sent. Saving the new encryptionKeyPair.`
);
distributingClosedGroupEncryptionKeyPairs.delete(toHex(groupId));
await addClosedGroupEncryptionKeyPair(
toHex(groupId),
newKeyPair.toHexKeyPair()

Loading…
Cancel
Save