From bebdab211e36a613bc25d98aa8b86534be4c813d Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Thu, 24 Apr 2025 11:24:52 -0700 Subject: [PATCH] Simplify service id checks in MessageReceiver --- ts/textsecure/MessageReceiver.ts | 13 +++---------- ts/util/checkOurPniIdentityKey.ts | 10 +++++++++- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/ts/textsecure/MessageReceiver.ts b/ts/textsecure/MessageReceiver.ts index a7a10c623d..2612477f15 100644 --- a/ts/textsecure/MessageReceiver.ts +++ b/ts/textsecure/MessageReceiver.ts @@ -1248,16 +1248,9 @@ export default class MessageReceiver const task = async (): Promise => { const { destinationServiceId } = envelope; - const serviceIdKind = - this.#storage.user.getOurServiceIdKind(destinationServiceId); - if (serviceIdKind === ServiceIdKind.Unknown) { - log.warn( - 'MessageReceiver.decryptAndCacheBatch: ' + - `Rejecting envelope ${getEnvelopeId(envelope)}, ` + - `unknown serviceId: ${destinationServiceId}` - ); - return { plaintext: undefined, envelope: undefined }; - } + const serviceIdKind = isPniString(destinationServiceId) + ? ServiceIdKind.PNI + : ServiceIdKind.ACI; const unsealedEnvelope = await this.#unsealEnvelope( stores, diff --git a/ts/util/checkOurPniIdentityKey.ts b/ts/util/checkOurPniIdentityKey.ts index 2b4a0605ca..f1f765ed58 100644 --- a/ts/util/checkOurPniIdentityKey.ts +++ b/ts/util/checkOurPniIdentityKey.ts @@ -10,6 +10,15 @@ export async function checkOurPniIdentityKey(): Promise { strictAssert(server, 'WebAPI not ready'); const ourPni = window.storage.user.getCheckedPni(); + const { pni: remotePni } = await server.whoami(); + if (remotePni !== ourPni) { + log.warn( + `checkOurPniIdentityKey: remote pni mismatch, ${remotePni} != ${ourPni}` + ); + window.Whisper.events.trigger('unlinkAndDisconnect'); + return; + } + const localKeyPair = await window.storage.protocol.getIdentityKeyPair(ourPni); if (!localKeyPair) { log.warn( @@ -20,7 +29,6 @@ export async function checkOurPniIdentityKey(): Promise { } const { identityKey: remoteKey } = await server.getKeysForServiceId(ourPni); - if (!constantTimeEqual(localKeyPair.publicKey.serialize(), remoteKey)) { log.warn( `checkOurPniIdentityKey: local/remote key mismatch for ${ourPni}, unlinking`