add a way to share currently distributing keypair to added members

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

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

Loading…
Cancel
Save