From 86e92dda51c40cba0ba64898f981f93b92f2ccd3 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Tue, 20 Dec 2022 14:17:51 -0800 Subject: [PATCH] Share profile key: Cancel send in more situations --- ts/jobs/conversationJobQueue.ts | 15 +++++++++++ ts/jobs/helpers/sendProfileKey.ts | 43 +++++++++++++++++++++---------- 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/ts/jobs/conversationJobQueue.ts b/ts/jobs/conversationJobQueue.ts index 848136d0c4..0a36e89182 100644 --- a/ts/jobs/conversationJobQueue.ts +++ b/ts/jobs/conversationJobQueue.ts @@ -301,6 +301,13 @@ export class ConversationJobQueue extends JobQueue { verificationData.type === ConversationVerificationState.PendingVerification ) { + if (type === conversationQueueJobEnum.enum.ProfileKey) { + log.warn( + "Cancelling profile share, we don't want to wait for pending verification." + ); + return; + } + log.info( 'verification is pending for this conversation; waiting at most 5m...' ); @@ -426,9 +433,17 @@ export class ConversationJobQueue extends JobQueue { } if (untrustedUuids.length) { + if (type === jobSet.ProfileKey) { + log.warn( + `Cancelling profile share, since there were ${untrustedUuids.length} untrusted send targets.` + ); + return; + } + log.error( `Send failed because ${untrustedUuids.length} conversation(s) were untrusted. Adding to verification list.` ); + window.reduxActions.conversations.conversationStoppedByMissingVerification( { conversationId: conversation.id, diff --git a/ts/jobs/helpers/sendProfileKey.ts b/ts/jobs/helpers/sendProfileKey.ts index b9de587643..32f8b61680 100644 --- a/ts/jobs/helpers/sendProfileKey.ts +++ b/ts/jobs/helpers/sendProfileKey.ts @@ -32,6 +32,8 @@ import { SendMessageProtoError, UnregisteredUserError, } from '../../textsecure/Errors'; +import { getRecipients } from '../../util/getRecipients'; +import { getUntrustedConversationUuids } from './getUntrustedConversationUuids'; export function canAllErrorsBeIgnored( conversation: ConversationAttributesType, @@ -102,27 +104,34 @@ export async function sendProfileKey( // Note: flags and the profileKey itself are all that matter in the proto. - // Note: we don't check for untrusted conversations here; we attempt to send anyway + 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` + ); + return; + } if (isDirectConversation(conversation.attributes)) { - if (!isConversationAccepted(conversation.attributes)) { - log.info( - `conversation ${conversation.idForLogging()} is not accepted; refusing to send` - ); - return; - } if (isConversationUnregistered(conversation.attributes)) { log.info( `conversation ${conversation.idForLogging()} is unregistered; refusing to send` ); return; } - if (conversation.isBlocked()) { - log.info( - `conversation ${conversation.idForLogging()} is blocked; refusing to send` - ); - return; - } const proto = await messaging.getContentMessage({ flags: Proto.DataMessage.Flags.PROFILE_KEY_UPDATE, @@ -144,6 +153,14 @@ export async function sendProfileKey( log.error('No revision provided, but conversation is GroupV2'); } + const ourUuid = window.textsecure.storage.user.getCheckedUuid(); + if (!conversation.hasMember(ourUuid)) { + log.info( + `We are not part of group ${conversation.idForLogging()}; refusing to send` + ); + return; + } + const groupV2Info = conversation.getGroupV2Info(); if (groupV2Info && isNumber(revision)) { groupV2Info.revision = revision;