diff --git a/ts/background.ts b/ts/background.ts index 725275301..20a431c24 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -84,7 +84,6 @@ import type { SentEventData, StickerPackEvent, TypingEvent, - VerifiedEvent, ViewEvent, ViewOnceOpenSyncEvent, ViewSyncEvent, @@ -327,10 +326,6 @@ export async function startApp(): Promise { 'view', queuedEventListener(onViewReceipt) ); - messageReceiver.addEventListener( - 'verified', - queuedEventListener(onVerified) - ); messageReceiver.addEventListener( 'error', queuedEventListener(onError, false) @@ -3716,77 +3711,6 @@ export async function startApp(): Promise { return ViewSyncs.getSingleton().onSync(receipt); } - async function onVerified(ev: VerifiedEvent) { - const e164 = ev.verified.destination; - const uuid = ev.verified.destinationUuid; - const key = ev.verified.identityKey; - let state; - - if (ev.confirm) { - ev.confirm(); - } - - const c = new window.Whisper.Conversation({ - e164, - uuid, - type: 'private', - } as Partial as WhatIsThis); - const error = c.validate(); - if (error) { - log.error( - 'Invalid verified sync received:', - e164, - uuid, - Errors.toLogFormat(error) - ); - return; - } - - switch (ev.verified.state) { - case Proto.Verified.State.DEFAULT: - state = 'DEFAULT'; - break; - case Proto.Verified.State.VERIFIED: - state = 'VERIFIED'; - break; - case Proto.Verified.State.UNVERIFIED: - state = 'UNVERIFIED'; - break; - default: - log.error(`Got unexpected verified state: ${ev.verified.state}`); - } - - log.info( - 'got verified sync for', - e164, - uuid, - state, - ev.verified.viaContactSync ? 'via contact sync' : '' - ); - - const verifiedId = window.ConversationController.ensureContactIds({ - e164, - uuid, - highTrust: true, - reason: 'onVerified', - }); - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const contact = window.ConversationController.get(verifiedId)!; - const options = { - viaSyncMessage: true, - viaContactSync: ev.verified.viaContactSync, - key, - }; - - if (state === 'VERIFIED') { - await contact.setVerified(options); - } else if (state === 'DEFAULT') { - await contact.setVerifiedDefault(options); - } else { - await contact.setUnverified(options); - } - } - function onDeliveryReceipt(ev: DeliveryEvent) { const { deliveryReceipt } = ev; const { envelopeTimestamp, sourceUuid, source, sourceDevice, timestamp } = diff --git a/ts/model-types.d.ts b/ts/model-types.d.ts index c0e887460..e59ed4bd7 100644 --- a/ts/model-types.d.ts +++ b/ts/model-types.d.ts @@ -403,9 +403,7 @@ export type GroupV2PendingAdminApprovalType = { export type VerificationOptions = { key?: null | Uint8Array; - viaContactSync?: boolean; viaStorageServiceSync?: boolean; - viaSyncMessage?: boolean; }; export type ShallowChallengeError = CustomError & { diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index 3a3282faa..e3fd7cb99 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -2600,8 +2600,6 @@ export class ConversationModel extends window.Backbone const options = providedOptions || {}; window._.defaults(options, { viaStorageServiceSync: false, - viaSyncMessage: false, - viaContactSync: false, key: null, }); @@ -2618,7 +2616,7 @@ export class ConversationModel extends window.Backbone const uuid = this.getUuid(); const beginningVerified = this.get('verified'); let keyChange = false; - if (options.viaSyncMessage || options.viaStorageServiceSync) { + if (options.viaStorageServiceSync) { strictAssert( uuid, `Sync message didn't update uuid for conversation: ${this.id}` @@ -2655,27 +2653,26 @@ export class ConversationModel extends window.Backbone } const didSomethingChange = keyChange || beginningVerified !== verified; - const isExplicitUserAction = - !options.viaContactSync && !options.viaStorageServiceSync; - const shouldShowFromContactSync = - options.viaContactSync && verified !== UNVERIFIED; + const isExplicitUserAction = !options.viaStorageServiceSync; + const shouldShowFromStorageSync = + options.viaStorageServiceSync && verified !== UNVERIFIED; if ( // The message came from an explicit verification in a client (not a contact sync // or storage service sync) (didSomethingChange && isExplicitUserAction) || // The verification value received by the contact sync is different from what we // have on record (and it's not a transition to UNVERIFIED) - (didSomethingChange && shouldShowFromContactSync) || + (didSomethingChange && shouldShowFromStorageSync) || // Our local verification status is VERIFIED and it hasn't changed, but the key did // change (Key1/VERIFIED -> Key2/VERIFIED), but we don't want to show DEFAULT -> // DEFAULT or UNVERIFIED -> UNVERIFIED (keyChange && verified === VERIFIED) ) { await this.addVerifiedChange(this.id, verified === VERIFIED, { - local: !options.viaSyncMessage, + local: isExplicitUserAction, }); } - if (!options.viaSyncMessage && uuid) { + if (isExplicitUserAction && uuid) { await this.sendVerifySyncMessage(this.get('e164'), uuid, verified); } diff --git a/ts/textsecure/MessageReceiver.ts b/ts/textsecure/MessageReceiver.ts index c4fbdcc18..631a865d8 100644 --- a/ts/textsecure/MessageReceiver.ts +++ b/ts/textsecure/MessageReceiver.ts @@ -104,7 +104,6 @@ import { KeysEvent, PNIIdentityEvent, StickerPackEvent, - VerifiedEvent, ReadSyncEvent, ViewSyncEvent, ContactEvent, @@ -485,11 +484,6 @@ export default class MessageReceiver handler: (ev: StickerPackEvent) => void ): void; - public override addEventListener( - name: 'verified', - handler: (ev: VerifiedEvent) => void - ): void; - public override addEventListener( name: 'readSync', handler: (ev: ReadSyncEvent) => void @@ -2458,7 +2452,9 @@ export default class MessageReceiver return this.handleRead(envelope, syncMessage.read); } if (syncMessage.verified) { - return this.handleVerified(envelope, syncMessage.verified); + log.info('Got verified sync message, dropping'); + this.removeFromCache(envelope); + return undefined; } if (syncMessage.configuration) { return this.handleConfiguration(envelope, syncMessage.configuration); @@ -2655,27 +2651,6 @@ export default class MessageReceiver return this.dispatchAndWait(ev); } - private async handleVerified( - envelope: ProcessedEnvelope, - verified: Proto.IVerified - ): Promise { - const ev = new VerifiedEvent( - { - state: verified.state, - destination: dropNull(verified.destination), - destinationUuid: verified.destinationUuid - ? normalizeUuid( - verified.destinationUuid, - 'handleVerified.destinationUuid' - ) - : undefined, - identityKey: verified.identityKey ? verified.identityKey : undefined, - }, - this.removeFromCache.bind(this, envelope) - ); - return this.dispatchAndWait(ev); - } - private async handleRead( envelope: ProcessedEnvelope, read: Array diff --git a/ts/textsecure/messageReceiverEvents.ts b/ts/textsecure/messageReceiverEvents.ts index 889d0cc03..1fcc878ff 100644 --- a/ts/textsecure/messageReceiverEvents.ts +++ b/ts/textsecure/messageReceiverEvents.ts @@ -379,25 +379,6 @@ export class StickerPackEvent extends ConfirmableEvent { } } -export type VerifiedEventData = Readonly<{ - state: Proto.IVerified['state']; - destination?: string; - destinationUuid?: string; - identityKey?: Uint8Array; - - // Used in `ts/background.ts` - viaContactSync?: boolean; -}>; - -export class VerifiedEvent extends ConfirmableEvent { - constructor( - public readonly verified: VerifiedEventData, - confirm: ConfirmCallback - ) { - super('verified', confirm); - } -} - export type ReadSyncEventData = Readonly<{ timestamp?: number; envelopeTimestamp: number;