Cancel receipt send when encountering safety number change

This commit is contained in:
Jamie Kyle 2023-02-13 10:02:40 -08:00 committed by GitHub
parent a0b6459307
commit 5626cea9c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 22 deletions

View file

@ -455,6 +455,13 @@ export class ConversationJobQueue extends JobQueue<ConversationQueueJobData> {
return;
}
if (type === jobSet.Receipts) {
log.warn(
`Cancelling receipt send, since there were ${untrustedUuids.length} untrusted send targets.`
);
return;
}
log.error(
`Send failed because ${untrustedUuids.length} conversation(s) were untrusted. Adding to verification list.`
);

View file

@ -23,7 +23,6 @@ import type {
ProfileKeyJobData,
} from '../conversationJobQueue';
import type { CallbackResultType } from '../../textsecure/Types.d';
import { isConversationAccepted } from '../../util/isConversationAccepted';
import { isConversationUnregistered } from '../../util/isConversationUnregistered';
import type { ConversationAttributesType } from '../../model-types.d';
import {
@ -32,8 +31,7 @@ import {
SendMessageProtoError,
UnregisteredUserError,
} from '../../textsecure/Errors';
import { getRecipients } from '../../util/getRecipients';
import { getUntrustedConversationUuids } from './getUntrustedConversationUuids';
import { shouldSendToConversation } from './shouldSendToConversation';
export function canAllErrorsBeIgnored(
conversation: ConversationAttributesType,
@ -104,24 +102,7 @@ export async function sendProfileKey(
// Note: flags and the profileKey itself are all that matter in the proto.
const recipients = getRecipients(conversation.attributes);
const untrustedUuids = getUntrustedConversationUuids(recipients);
if (untrustedUuids.length) {
log.info(
`conversation ${conversation.idForLogging()} has untrusted recipients; refusing to send`
);
}
if (!isConversationAccepted(conversation.attributes)) {
log.info(
`conversation ${conversation.idForLogging()} is not accepted; refusing to send`
);
return;
}
if (conversation.isBlocked()) {
log.info(
`conversation ${conversation.idForLogging()} is blocked; refusing to send`
);
if (!shouldSendToConversation(conversation, log)) {
return;
}

View file

@ -7,12 +7,16 @@ import type {
ConversationQueueJobBundle,
ReceiptsJobData,
} from '../conversationJobQueue';
import { shouldSendToConversation } from './shouldSendToConversation';
export async function sendReceipts(
_conversation: ConversationModel,
conversation: ConversationModel,
{ log }: ConversationQueueJobBundle,
data: ReceiptsJobData
): Promise<void> {
if (!shouldSendToConversation(conversation, log)) {
return;
}
await sendReceiptsTask({
log,
receipts: data.receipts,

View file

@ -0,0 +1,39 @@
// Copyright 2023 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { ConversationModel } from '../../models/conversations';
import type { LoggerType } from '../../types/Logging';
import { getRecipients } from '../../util/getRecipients';
import { isConversationAccepted } from '../../util/isConversationAccepted';
import { getUntrustedConversationUuids } from './getUntrustedConversationUuids';
export function shouldSendToConversation(
conversation: ConversationModel,
log: LoggerType
): boolean {
const recipients = getRecipients(conversation.attributes);
const untrustedUuids = getUntrustedConversationUuids(recipients);
if (untrustedUuids.length) {
log.info(
`conversation ${conversation.idForLogging()} has untrusted recipients; refusing to send`
);
return false;
}
if (!isConversationAccepted(conversation.attributes)) {
log.info(
`conversation ${conversation.idForLogging()} is not accepted; refusing to send`
);
return false;
}
if (conversation.isBlocked()) {
log.info(
`conversation ${conversation.idForLogging()} is blocked; refusing to send`
);
return false;
}
return true;
}