From 4eb49ff30462c4f452f76519e8a582336bc843b1 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Fri, 15 Jan 2021 08:57:09 -0800 Subject: [PATCH] Fix a few issues with linking a new Desktop instance --- js/signal_protocol_store.js | 9 ++++++-- libtextsecure/storage/user.js | 2 +- ts/textsecure/AccountManager.ts | 35 ++++++++++++++--------------- ts/textsecure/ProvisioningCipher.ts | 6 +++++ ts/util/lint/exceptions.json | 2 +- 5 files changed, 32 insertions(+), 22 deletions(-) diff --git a/js/signal_protocol_store.js b/js/signal_protocol_store.js index d4ff816c0c30..b5f7e45a31ff 100644 --- a/js/signal_protocol_store.js +++ b/js/signal_protocol_store.js @@ -544,8 +544,13 @@ const identityRecord = this.getIdentityRecord(identifier); if (isOurIdentifier) { - const existing = identityRecord ? identityRecord.publicKey : null; - return equalArrayBuffers(existing, publicKey); + if (identityRecord && identityRecord.publicKey) { + return equalArrayBuffers(identityRecord.publicKey, publicKey); + } + window.log.warn( + 'isTrustedIdentity: No local record for our own identifier. Returning true.' + ); + return true; } switch (direction) { diff --git a/libtextsecure/storage/user.js b/libtextsecure/storage/user.js index 3a6aa7f3e98e..6a1ea686da0b 100644 --- a/libtextsecure/storage/user.js +++ b/libtextsecure/storage/user.js @@ -32,7 +32,7 @@ getUuid() { const uuid = textsecure.storage.get('uuid_id'); if (uuid === undefined) return undefined; - return textsecure.utils.unencodeNumber(uuid)[0]; + return textsecure.utils.unencodeNumber(uuid.toLowerCase())[0]; }, getDeviceId() { diff --git a/ts/textsecure/AccountManager.ts b/ts/textsecure/AccountManager.ts index bc14928b8531..5bc3739170e8 100644 --- a/ts/textsecure/AccountManager.ts +++ b/ts/textsecure/AccountManager.ts @@ -166,7 +166,7 @@ export default class AccountManager extends EventTarget { .then(async (keys: GeneratedKeysType) => registerKeys(keys).then(async () => confirmKeys(keys)) ) - .then(async () => registrationDone({ number })); + .then(async () => registrationDone()); } ) ); @@ -274,9 +274,7 @@ export default class AccountManager extends EventTarget { confirmKeys(keys) ) ) - .then(async () => - registrationDone(provisionMessage) - ); + .then(registrationDone); } ) ) @@ -582,10 +580,23 @@ export default class AccountManager extends EventTarget { ); } + // This needs to be done very early, because it changes how things are saved in the + // database. Your identity, for example, in the saveIdentityWithAttributes call + // below. + const conversationId = window.ConversationController.ensureContactIds({ + e164: number, + uuid, + highTrust: true, + }); + + if (!conversationId) { + throw new Error('registrationDone: no conversationId!'); + } + // update our own identity key, which may have changed // if we're relinking after a reinstall on the master device await window.textsecure.storage.protocol.saveIdentityWithAttributes( - number, + uuid || number, { publicKey: identityKeyPair.pubKey, firstUse: true, @@ -714,20 +725,8 @@ export default class AccountManager extends EventTarget { }); } - async registrationDone({ uuid, number }: { uuid?: string; number?: string }) { + async registrationDone() { window.log.info('registration done'); - - const conversationId = window.ConversationController.ensureContactIds({ - e164: number, - uuid, - highTrust: true, - }); - if (!conversationId) { - throw new Error('registrationDone: no conversationId!'); - } - - window.log.info('dispatching registration event'); - this.dispatchEvent(new Event('registration')); } } diff --git a/ts/textsecure/ProvisioningCipher.ts b/ts/textsecure/ProvisioningCipher.ts index 299525f9a238..c72c85fb9c90 100644 --- a/ts/textsecure/ProvisioningCipher.ts +++ b/ts/textsecure/ProvisioningCipher.ts @@ -63,6 +63,12 @@ class ProvisioningCipherInner { return window.libsignal.Curve.async .createKeyPair(privKey) .then(keyPair => { + window.normalizeUuids( + provisionMessage, + ['uuid'], + 'ProvisioningCipher.decrypt' + ); + const ret: ProvisionDecryptResult = { identityKeyPair: keyPair, number: provisionMessage.number, diff --git a/ts/util/lint/exceptions.json b/ts/util/lint/exceptions.json index 747bd4bc649e..f268cdc762b2 100644 --- a/ts/util/lint/exceptions.json +++ b/ts/util/lint/exceptions.json @@ -326,7 +326,7 @@ "rule": "jQuery-load(", "path": "js/signal_protocol_store.js", "line": " await ConversationController.load();", - "lineNumber": 1019, + "lineNumber": 1024, "reasonCategory": "falseMatch", "updated": "2020-06-12T14:20:09.936Z" },