From 7c1f186c05ca1456565d195de50f7545ea6ebf55 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Fri, 20 Jan 2023 16:50:34 -0800 Subject: [PATCH] sendToGroup: Don't fail send if we get 401 from multi_recipient/ request --- ts/test-electron/util/sendToGroup_test.ts | 12 ++++++++++++ ts/textsecure/Errors.ts | 2 ++ ts/util/sendToGroup.ts | 10 +++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/ts/test-electron/util/sendToGroup_test.ts b/ts/test-electron/util/sendToGroup_test.ts index 83dbd1a10..4cca28172 100644 --- a/ts/test-electron/util/sendToGroup_test.ts +++ b/ts/test-electron/util/sendToGroup_test.ts @@ -15,12 +15,14 @@ import type { DeviceType } from '../../textsecure/Types.d'; import { ConnectTimeoutError, HTTPError, + IncorrectSenderKeyAuthError, MessageError, OutgoingIdentityKeyError, OutgoingMessageError, SendMessageChallengeError, SendMessageNetworkError, SendMessageProtoError, + UnknownRecipientError, UnregisteredUserError, } from '../../textsecure/Errors'; @@ -219,6 +221,16 @@ describe('sendToGroup', () => { assert.isFalse(_shouldFailSend(error, 'testing generic 204')); }); + it('returns false for specific errors', () => { + const unknownRecipient = new UnknownRecipientError(); + assert.isFalse( + _shouldFailSend(unknownRecipient, 'testing unknown recipient') + ); + + const incorrectAuth = new IncorrectSenderKeyAuthError(); + assert.isFalse(_shouldFailSend(incorrectAuth, 'testing incorrect auth')); + }); + it('returns true for a specified error codes', () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any const error: any = new Error('generic'); diff --git a/ts/textsecure/Errors.ts b/ts/textsecure/Errors.ts index 6dfd832b6..06e306555 100644 --- a/ts/textsecure/Errors.ts +++ b/ts/textsecure/Errors.ts @@ -305,4 +305,6 @@ export class ConnectTimeoutError extends Error {} export class UnknownRecipientError extends Error {} +export class IncorrectSenderKeyAuthError extends Error {} + export class WarnOnlyError extends Error {} diff --git a/ts/util/sendToGroup.ts b/ts/util/sendToGroup.ts index 634f0e70e..5c1945f4f 100644 --- a/ts/util/sendToGroup.ts +++ b/ts/util/sendToGroup.ts @@ -34,6 +34,7 @@ import type { } from '../textsecure/SendMessage'; import { ConnectTimeoutError, + IncorrectSenderKeyAuthError, OutgoingIdentityKeyError, SendMessageProtoError, UnknownRecipientError, @@ -65,6 +66,7 @@ import { GLOBAL_ZONE } from '../SignalProtocolStore'; import { waitForAll } from './waitForAll'; const UNKNOWN_RECIPIENT = 404; +const INCORRECT_AUTH_KEY = 401; const ERROR_EXPIRED_OR_MISSING_DEVICES = 409; const ERROR_STALE_DEVICES = 410; @@ -569,6 +571,9 @@ export async function sendToGroupViaSenderKey(options: { if (error.code === UNKNOWN_RECIPIENT) { throw new UnknownRecipientError(); } + if (error.code === INCORRECT_AUTH_KEY) { + throw new IncorrectSenderKeyAuthError(); + } if (error.code === ERROR_EXPIRED_OR_MISSING_DEVICES) { await handle409Response(logId, error); @@ -764,10 +769,13 @@ export function _shouldFailSend(error: unknown, logId: string): boolean { log.error(`_shouldFailSend/${logId}: ${message}`); }; - // We need to fail over to a normal send if multi_recipient/ endpoint returns 404 + // We need to fail over to a normal send if multi_recipient/ endpoint returns 404 or 401 if (error instanceof UnknownRecipientError) { return false; } + if (error instanceof IncorrectSenderKeyAuthError) { + return false; + } if ( error instanceof LibSignalErrorBase &&