Skip to content

Commit

Permalink
Sender Key: Proper 409-handling, save new members earlier
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Nonnenberg <scott@signal.org>
  • Loading branch information
automated-signal and scottnonnenberg-signal committed Aug 3, 2021
1 parent 12b10af commit 6df1cf4
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions ts/util/sendToGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,18 @@ export async function sendToGroupViaSenderKey(options: {
{ messageIds: [], sendType: 'senderKeyDistributionMessage' }
);

// Update memberDevices with new devices
const updatedMemberDevices = [...memberDevices, ...newToMemberDevices];

conversation.set({
senderKeyInfo: {
createdAtDate,
distributionId,
memberDevices: updatedMemberDevices,
},
});
await window.Signal.Data.updateConversation(conversation.attributes);

// Restart here because we might have discovered new or dropped devices as part of
// distributing our sender key.
return sendToGroupViaSenderKey({
Expand All @@ -389,15 +401,14 @@ export async function sendToGroupViaSenderKey(options: {
});
}

// 9. Update memberDevices with both adds and the removals which didn't require a reset.
if (removedFromMemberDevices.length > 0 || newToMemberDevices.length > 0) {
// 9. Update memberDevices with removals which didn't require a reset.
if (removedFromMemberDevices.length > 0) {
const updatedMemberDevices = [
...differenceWith<DeviceType, DeviceType>(
memberDevices,
removedFromMemberDevices,
deviceComparator
),
...newToMemberDevices,
];

conversation.set({
Expand Down Expand Up @@ -651,7 +662,7 @@ async function handle409Response(logId: string, error: Error) {
const { uuid, devices } = item;
// Start new sessions with devices we didn't know about before
if (devices.missingDevices && devices.missingDevices.length > 0) {
await fetchKeysForIdentifier(uuid, devices.extraDevices);
await fetchKeysForIdentifier(uuid, devices.missingDevices);
}

// Archive sessions with devices that have been removed
Expand Down Expand Up @@ -859,16 +870,10 @@ function isValidSenderKeyRecipient(

const capabilities = memberConversation.get('capabilities');
if (!capabilities?.senderKey) {
window.log.info(
`isValidSenderKeyRecipient: Missing senderKey capability for member ${uuid}`
);
return false;
}

if (!getAccessKey(memberConversation.attributes)) {
window.log.warn(
`isValidSenderKeyRecipient: Missing accessKey for member ${uuid}`
);
return false;
}

Expand Down

0 comments on commit 6df1cf4

Please sign in to comment.