From b26f60d2fc44613be587335aeae9048b98f02fd0 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Sat, 19 Nov 2022 00:31:31 -0800 Subject: [PATCH] Better handling of calling messages --- ts/services/calling.ts | 36 +++++++++++++++++++++++++++++++- ts/textsecure/MessageReceiver.ts | 12 +++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/ts/services/calling.ts b/ts/services/calling.ts index 4da98c764..34ca0a118 100644 --- a/ts/services/calling.ts +++ b/ts/services/calling.ts @@ -66,7 +66,7 @@ import { findBestMatchingCameraId, } from '../calling/findBestMatchingDevice'; import type { LocalizerType } from '../types/Util'; -import { UUID } from '../types/UUID'; +import { UUID, UUIDKind } from '../types/UUID'; import type { ConversationModel } from '../models/conversations'; import * as Bytes from '../Bytes'; import { uuidToBytes, bytesToUuid } from '../Crypto'; @@ -1720,6 +1720,33 @@ export class CallingClass { log.error('handleGroupCallRingUpdate(): could not find conversation'); return; } + + const logId = `handleGroupCallRingUpdate(${conversation.idForLogging()})`; + if (conversation.isBlocked()) { + log.warn(`${logId}: is blocked`); + return; + } + + const ourACI = window.textsecure.storage.user.getCheckedUuid(UUIDKind.ACI); + + if (conversation.get('left') || !conversation.hasMember(ourACI)) { + log.warn(`${logId}: we left the group`); + return; + } + + if (!conversation.hasMember(new UUID(ringerUuid))) { + log.warn(`${logId}: they left the group`); + return; + } + + if ( + conversation.get('announcementsOnly') && + !conversation.isAdmin(new UUID(ringerUuid)) + ) { + log.warn(`${logId}: non-admin update to announcement-only group`); + return; + } + const conversationId = conversation.id; let shouldRing = false; @@ -1812,6 +1839,13 @@ export class CallingClass { return null; } + if (conversation.isBlocked()) { + log.warn( + `handleIncomingCall(): ${conversation.idForLogging()} is blocked` + ); + return null; + } + try { // The peer must be 'trusted' before accepting a call from them. // This is mostly the safety number check, unverified meaning that they were diff --git a/ts/textsecure/MessageReceiver.ts b/ts/textsecure/MessageReceiver.ts index ee2ea69bf..99e082ce0 100644 --- a/ts/textsecure/MessageReceiver.ts +++ b/ts/textsecure/MessageReceiver.ts @@ -2529,6 +2529,18 @@ export default class MessageReceiver logUnexpectedUrgentValue(envelope, 'callingMessage'); this.removeFromCache(envelope); + + if ( + (envelope.source && this.isBlocked(envelope.source)) || + (envelope.sourceUuid && this.isUuidBlocked(envelope.sourceUuid)) + ) { + const logId = getEnvelopeId(envelope); + + log.info(`${logId}: Dropping calling message from blocked sender`); + this.removeFromCache(envelope); + return; + } + await window.Signal.Services.calling.handleCallingMessage( envelope, callingMessage