From 22e1ff9b5023c45cb1c2b55034203d1b738acdaf Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Wed, 10 May 2023 10:02:32 -0700 Subject: [PATCH] Drop support of PniIdentity sync message --- protos/SignalService.proto | 7 +--- ts/background.ts | 11 ----- ts/textsecure/AccountManager.ts | 71 -------------------------------- ts/textsecure/MessageReceiver.ts | 28 ------------- ts/textsecure/SendMessage.ts | 24 ----------- 5 files changed, 1 insertion(+), 140 deletions(-) diff --git a/protos/SignalService.proto b/protos/SignalService.proto index 2691b7678f3a..d762d155a5f1 100644 --- a/protos/SignalService.proto +++ b/protos/SignalService.proto @@ -512,11 +512,6 @@ message SyncMessage { optional bytes storageService = 1; } - message PniIdentity { - optional bytes publicKey = 1; - optional bytes privateKey = 2; - } - message Read { optional string sender = 1; optional string senderUuid = 3; @@ -630,7 +625,7 @@ message SyncMessage { optional MessageRequestResponse messageRequestResponse = 14; reserved 15; // not yet added repeated Viewed viewed = 16; - optional PniIdentity pniIdentity = 17; + reserved 17; // pniIdentity optional PniChangeNumber pniChangeNumber = 18; optional CallEvent callEvent = 19; } diff --git a/ts/background.ts b/ts/background.ts index bb619d213a50..1788be8dcdeb 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -2640,17 +2640,6 @@ export async function startApp(): Promise { void routineProfileRefresher.start(); } - - // Make sure we have the PNI identity - - const pni = storage.user.getCheckedUuid(UUIDKind.PNI); - const pniIdentity = await storage.protocol.getIdentityKeyPair(pni); - if (!pniIdentity) { - log.info('Requesting PNI identity sync'); - await singleProtoJobQueue.add( - MessageSender.getRequestPniIdentitySyncMessage() - ); - } } let initialStartupCount = 0; diff --git a/ts/textsecure/AccountManager.ts b/ts/textsecure/AccountManager.ts index 9bb6efa4722f..0c0ada0bdbf9 100644 --- a/ts/textsecure/AccountManager.ts +++ b/ts/textsecure/AccountManager.ts @@ -695,77 +695,6 @@ export default class AccountManager extends EventTarget { ]); } - async updatePNIIdentity(identityKeyPair: KeyPairType): Promise { - const { storage } = window.textsecure; - - log.info('AccountManager.updatePNIIdentity: generating new keys'); - - await this.queueTask(async () => { - // Server has accepted our keys which means we have the latest PNI identity - // now that doesn't conflict the PNI identity of the primary device. - log.info( - 'AccountManager.updatePNIIdentity: updating identity key ' + - 'and registration id' - ); - - const pni = storage.user.getCheckedUuid(UUIDKind.PNI); - const identityKeyMap = { - ...(storage.get('identityKeyMap') || {}), - [pni.toString()]: identityKeyPair, - }; - - await storage.put('identityKeyMap', identityKeyMap); - await storage.protocol.hydrateCaches(); - }); - - // Intentionally not awaiting because `updatePNIIdentity` runs on an - // Encrypted queue of MessageReceiver and we don't want to await remote - // endpoints and block message processing. - void this.queueTask(async () => { - try { - const keys = await this.generateKeys( - SIGNED_KEY_GEN_BATCH_SIZE, - UUIDKind.PNI, - identityKeyPair - ); - await this.server.registerKeys(keys, UUIDKind.PNI); - await this.confirmKeys(keys, UUIDKind.PNI); - - const pni = storage.user.getCheckedUuid(UUIDKind.PNI); - - // Repair registration id - const deviceId = storage.user.getDeviceId(); - const { devices } = await this.server.getKeysForIdentifier( - pni.toString(), - deviceId - ); - const us = devices.find( - remoteDevice => remoteDevice.deviceId === deviceId - ); - if (us) { - const oldRegistrationIdMap = storage.get('registrationIdMap') || {}; - const oldRegistrationId = oldRegistrationIdMap[pni.toString()]; - if (oldRegistrationId !== us.registrationId) { - log.warn( - 'updatePNIIdentity: repairing PNI registration id from ' + - `${oldRegistrationId} to ${us.registrationId}` - ); - } - const registrationIdMap = { - ...oldRegistrationIdMap, - [pni.toString()]: us.registrationId, - }; - await storage.put('registrationIdMap', registrationIdMap); - } - } catch (error) { - log.error( - 'updatePNIIdentity: Failed to upload PNI prekeys. Moving on', - Errors.toLogFormat(error) - ); - } - }); - } - // Takes the same object returned by generateKeys async confirmKeys( keys: GeneratedKeysType, diff --git a/ts/textsecure/MessageReceiver.ts b/ts/textsecure/MessageReceiver.ts index e29bd64a02b1..05273e0dda58 100644 --- a/ts/textsecure/MessageReceiver.ts +++ b/ts/textsecure/MessageReceiver.ts @@ -1533,13 +1533,6 @@ export default class MessageReceiver // Some sync messages have to be fully processed in the middle of // decryption queue since subsequent envelopes use their key material. const { syncMessage } = content; - if (syncMessage?.pniIdentity) { - inProgressMessageType = 'pni identity'; - await this.handlePNIIdentity(envelope, syncMessage.pniIdentity); - this.removeFromCache(envelope); - return { plaintext: undefined, envelope }; - } - if (syncMessage?.pniChangeNumber) { inProgressMessageType = 'pni change number'; await this.handlePNIChangeNumber(envelope, syncMessage.pniChangeNumber); @@ -2888,9 +2881,6 @@ export default class MessageReceiver if (envelope.sourceDevice == ourDeviceId) { throw new Error('Received sync message from our own device'); } - if (syncMessage.pniIdentity) { - return; - } if (syncMessage.sent) { const sentMessage = syncMessage.sent; @@ -3200,24 +3190,6 @@ export default class MessageReceiver return this.dispatchAndWait(logId, ev); } - // Runs on TaskType.Encrypted queue - private async handlePNIIdentity( - envelope: ProcessedEnvelope, - { publicKey, privateKey }: Proto.SyncMessage.IPniIdentity - ): Promise { - log.info('MessageReceiver: got pni identity sync message'); - - logUnexpectedUrgentValue(envelope, 'pniIdentitySync'); - - if (!publicKey || !privateKey) { - log.warn('MessageReceiver: empty pni identity sync message'); - return; - } - - const manager = window.getAccountManager(); - await manager.updatePNIIdentity({ privKey: privateKey, pubKey: publicKey }); - } - // Runs on TaskType.Encrypted queue private async handlePNIChangeNumber( envelope: ProcessedEnvelope, diff --git a/ts/textsecure/SendMessage.ts b/ts/textsecure/SendMessage.ts index 994130973c8f..cb0b598d66c4 100644 --- a/ts/textsecure/SendMessage.ts +++ b/ts/textsecure/SendMessage.ts @@ -1384,30 +1384,6 @@ export default class MessageSender { }; } - static getRequestPniIdentitySyncMessage(): SingleProtoJobData { - const myUuid = window.textsecure.storage.user.getCheckedUuid(); - - const request = new Proto.SyncMessage.Request(); - request.type = Proto.SyncMessage.Request.Type.PNI_IDENTITY; - const syncMessage = this.createSyncMessage(); - syncMessage.request = request; - const contentMessage = new Proto.Content(); - contentMessage.syncMessage = syncMessage; - - const { ContentHint } = Proto.UnidentifiedSenderMessage.Message; - - return { - contentHint: ContentHint.RESENDABLE, - identifier: myUuid.toString(), - isSyncMessage: true, - protoBase64: Bytes.toBase64( - Proto.Content.encode(contentMessage).finish() - ), - type: 'pniIdentitySyncRequest', - urgent: true, - }; - } - static getFetchManifestSyncMessage(): SingleProtoJobData { const myUuid = window.textsecure.storage.user.getCheckedUuid();