From 3f58a9b76291eb414d8ffd371c405deddea99b61 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Wed, 9 Dec 2020 14:26:37 -0800 Subject: [PATCH] Clean up UUID-handling to prepare for future --- js/modules/refresh_sender_certificate.js | 64 ++++++++++++++++-------- ts/background.ts | 5 +- ts/models/conversations.ts | 2 - ts/sql/Client.ts | 1 + ts/textsecure/WebAPI.ts | 9 +++- ts/util/lint/exceptions.json | 4 +- ts/views/conversation_view.ts | 1 - 7 files changed, 55 insertions(+), 31 deletions(-) diff --git a/js/modules/refresh_sender_certificate.js b/js/modules/refresh_sender_certificate.js index e2bf1c471..c34f61e01 100644 --- a/js/modules/refresh_sender_certificate.js +++ b/js/modules/refresh_sender_certificate.js @@ -65,6 +65,32 @@ function initialize({ events, storage, navigator, logger }) { // Keeping this entrypoint around so more inialize() calls just kick the timing scheduleNext = scheduleNextRotation; + async function saveCert({ certificate, key }) { + const arrayBuffer = window.Signal.Crypto.base64ToArrayBuffer(certificate); + const decodedContainer = textsecure.protobuf.SenderCertificate.decode( + arrayBuffer + ); + const decodedCert = textsecure.protobuf.SenderCertificate.Certificate.decode( + decodedContainer.certificate + ); + + // We don't want to send a protobuf-generated object across IPC, so we make + // our own object. + const toSave = { + expires: decodedCert.expires.toNumber(), + serialized: arrayBuffer, + }; + await storage.put(key, toSave); + } + + async function removeOldKey() { + const oldCertKey = 'senderCertificateWithUuid'; + const oldUuidCert = storage.get(oldCertKey); + if (oldUuidCert) { + await storage.remove(oldCertKey); + } + } + async function run() { logger.info('refreshSenderCertificate: Getting new certificate...'); try { @@ -76,29 +102,23 @@ function initialize({ events, storage, navigator, logger }) { password: PASSWORD, }); - const { certificate } = await server.getSenderCertificate(); - const arrayBuffer = window.Signal.Crypto.base64ToArrayBuffer(certificate); - const decodedContainer = textsecure.protobuf.SenderCertificate.decode( - arrayBuffer - ); - const decodedCert = textsecure.protobuf.SenderCertificate.Certificate.decode( - decodedContainer.certificate - ); + const omitE164 = true; + const [ + { certificate }, + { certificate: certificateWithNoE164 }, + ] = await Promise.all([ + server.getSenderCertificate(), + server.getSenderCertificate(omitE164), + ]); - // We don't want to send a protobuf-generated object across IPC, so we make - // our own object. - const toSave = { - expires: decodedCert.expires.toNumber(), - serialized: arrayBuffer, - }; - - storage.put('senderCertificate', toSave); - - const oldCertKey = 'senderCertificateWithUuid'; - const oldUuidCert = storage.get(oldCertKey); - if (oldUuidCert) { - await storage.remove(oldCertKey); - } + await Promise.all([ + saveCert({ certificate, key: 'senderCertificate' }), + saveCert({ + certificate: certificateWithNoE164, + key: 'senderCertificateNoE164', + }), + removeOldKey(), + ]); scheduledTime = null; scheduleNextRotation(); diff --git a/ts/background.ts b/ts/background.ts index 498f7e4f8..f833a4c23 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -1810,11 +1810,12 @@ type WhatIsThis = import('./window.d').WhatIsThis; !c.isEverUnregistered() ) ) - .map(c => c.get('e164')); + .map(c => c.get('e164')) + .filter(Boolean) as Array; if (lonelyE164s.length > 0) { const lookup = await window.textsecure.messaging.getUuidsForE164s( - lonelyE164s as WhatIsThis + lonelyE164s ); const e164s = Object.keys(lookup); e164s.forEach(e164 => { diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index 86df5e0a7..525a2535b 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -2428,7 +2428,6 @@ export class ConversationModel extends window.Backbone.Model< : ''; return { - author: contact.get('e164'), authorUuid: contact.get('uuid'), bodyRanges: quotedMessage.get('bodyRanges'), id: quotedMessage.get('sent_at'), @@ -2594,7 +2593,6 @@ export class ConversationModel extends window.Backbone.Model< async sendReactionMessage( reaction: { emoji: string; remove: boolean }, target: { - targetAuthorE164: string; targetAuthorUuid: string; targetTimestamp: number; } diff --git a/ts/sql/Client.ts b/ts/sql/Client.ts index ccba561aa..a9bf69d48 100644 --- a/ts/sql/Client.ts +++ b/ts/sql/Client.ts @@ -628,6 +628,7 @@ async function removeAllSignedPreKeys() { const ITEM_KEYS: { [key: string]: Array | undefined } = { identityKey: ['value.pubKey', 'value.privKey'], senderCertificate: ['value.serialized'], + senderCertificateNoE164: ['value.serialized'], signaling_key: ['value'], profileKey: ['value'], }; diff --git a/ts/textsecure/WebAPI.ts b/ts/textsecure/WebAPI.ts index 3fb0418ba..d83fa1662 100644 --- a/ts/textsecure/WebAPI.ts +++ b/ts/textsecure/WebAPI.ts @@ -1083,13 +1083,18 @@ export function initialize({ ); } - async function getSenderCertificate() { + async function getSenderCertificate(omitE164?: boolean) { + const baseParameters = '?includeUuid=true'; + const urlParameters = `${baseParameters}${ + omitE164 ? '&includeE164=false' : '' + }`; + return _ajax({ call: 'deliveryCert', httpType: 'GET', responseType: 'json', validateResponse: { certificate: 'string' }, - urlParameters: '?includeUuid=true', + urlParameters, }); } diff --git a/ts/util/lint/exceptions.json b/ts/util/lint/exceptions.json index 054d32d2e..6244744a4 100644 --- a/ts/util/lint/exceptions.json +++ b/ts/util/lint/exceptions.json @@ -15173,7 +15173,7 @@ "rule": "jQuery-wrap(", "path": "ts/textsecure/WebAPI.js", "line": " const byteBuffer = window.dcodeIO.ByteBuffer.wrap(quote, 'binary', window.dcodeIO.ByteBuffer.LITTLE_ENDIAN);", - "lineNumber": 1263, + "lineNumber": 1265, "reasonCategory": "falseMatch", "updated": "2020-09-08T23:07:22.682Z" }, @@ -15181,7 +15181,7 @@ "rule": "jQuery-wrap(", "path": "ts/textsecure/WebAPI.ts", "line": " const byteBuffer = window.dcodeIO.ByteBuffer.wrap(", - "lineNumber": 2172, + "lineNumber": 2177, "reasonCategory": "falseMatch", "updated": "2020-09-08T23:07:22.682Z" } diff --git a/ts/views/conversation_view.ts b/ts/views/conversation_view.ts index 0c6409176..b2a720311 100644 --- a/ts/views/conversation_view.ts +++ b/ts/views/conversation_view.ts @@ -2931,7 +2931,6 @@ Whisper.ConversationView = Whisper.View.extend({ try { await this.model.sendReactionMessage(reaction, { - targetAuthorE164: messageModel.getSource(), targetAuthorUuid: messageModel.getSourceUuid(), targetTimestamp: messageModel.get('sent_at'), });