From 2b648b79a4150835997ceccfb0c686bd854640af Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Mon, 1 Aug 2022 18:31:24 -0700 Subject: [PATCH] Upgrade to libsignal-client v0.19.2 --- package.json | 2 +- ts/SignalProtocolStore.ts | 30 ++++++++++---------- ts/test-electron/SignalProtocolStore_test.ts | 14 ++++----- ts/textsecure/AccountManager.ts | 4 +-- ts/textsecure/cds/CDSISocket.ts | 5 +--- yarn.lock | 8 +++--- 6 files changed, 29 insertions(+), 34 deletions(-) diff --git a/package.json b/package.json index 893955ffc..882bbe131 100644 --- a/package.json +++ b/package.json @@ -80,7 +80,7 @@ "@indutny/frameless-titlebar": "2.3.5", "@popperjs/core": "2.9.2", "@react-spring/web": "9.4.5", - "@signalapp/libsignal-client": "0.18.1", + "@signalapp/libsignal-client": "0.19.2", "@sindresorhus/is": "0.8.0", "@types/fabric": "4.5.3", "abort-controller": "3.0.0", diff --git a/ts/SignalProtocolStore.ts b/ts/SignalProtocolStore.ts index d2b892598..db6bfb8d0 100644 --- a/ts/SignalProtocolStore.ts +++ b/ts/SignalProtocolStore.ts @@ -7,7 +7,7 @@ import { z } from 'zod'; import { Direction, - // IdentityKeyPair, + IdentityKeyPair, PreKeyRecord, PrivateKey, PublicKey, @@ -32,7 +32,7 @@ import type { IdentityKeyIdType, KeyPairType, OuterSignedPrekeyType, - // PniKeyMaterialType, + PniKeyMaterialType, PreKeyIdType, PreKeyType, SenderKeyIdType, @@ -1978,34 +1978,35 @@ export class SignalProtocolStore extends EventsMixin { ]); } - async updateOurPniKeyMaterial(pni: UUID): /* { - identityKeyPair: identityBytes, - signedPreKey: signedPreKeyBytes, - registrationId, - }: PniKeyMaterialType - */ - Promise { - throw new Error( - `TODO: SignalProtocolStore.updateOurPniKeyMaterial(${pni}) is not implemented!` - ); - - /* + async updateOurPniKeyMaterial( + pni: UUID, + { + identityKeyPair: identityBytes, + signedPreKey: signedPreKeyBytes, + registrationId, + }: PniKeyMaterialType + ): Promise { log.info(`SignalProtocolStore.updateOurPniKeyMaterial(${pni})`); + const identityKeyPair = IdentityKeyPair.deserialize( Buffer.from(identityBytes) ); const signedPreKey = SignedPreKeyRecord.deserialize( Buffer.from(signedPreKeyBytes) ); + const { storage } = window; + const pniPublicKey = identityKeyPair.publicKey.serialize(); const pniPrivateKey = identityKeyPair.privateKey.serialize(); + // Update caches this.ourIdentityKeys.set(pni.toString(), { pubKey: pniPublicKey, privKey: pniPrivateKey, }); this.ourRegistrationIds.set(pni.toString(), registrationId); + // Update database await Promise.all([ storage.put('identityKeyMap', { @@ -2030,7 +2031,6 @@ export class SignalProtocolStore extends EventsMixin { signedPreKey.timestamp() ), ]); - */ } async removeAllData(): Promise { diff --git a/ts/test-electron/SignalProtocolStore_test.ts b/ts/test-electron/SignalProtocolStore_test.ts index d7a2b14cb..d1e3f7d84 100644 --- a/ts/test-electron/SignalProtocolStore_test.ts +++ b/ts/test-electron/SignalProtocolStore_test.ts @@ -7,12 +7,12 @@ import chai, { assert } from 'chai'; import chaiAsPromised from 'chai-as-promised'; import { Direction, - // IdentityKeyPair, - // PrivateKey, - // PublicKey, + IdentityKeyPair, + PrivateKey, + PublicKey, SenderKeyRecord, SessionRecord, - // SignedPreKeyRecord, + SignedPreKeyRecord, } from '@signalapp/libsignal-client'; import { signal } from '../protobuf/compiled'; @@ -20,12 +20,12 @@ import { sessionStructureToBytes } from '../util/sessionTranslation'; import * as durations from '../util/durations'; import { Zone } from '../util/Zone'; -// import * as Bytes from '../Bytes'; +import * as Bytes from '../Bytes'; import { getRandomBytes, constantTimeEqual } from '../Crypto'; import { clampPrivateKey, setPublicKeyTypeByte, - // generateSignedPreKey, + generateSignedPreKey, } from '../Curve'; import type { SignalProtocolStore } from '../SignalProtocolStore'; import { GLOBAL_ZONE } from '../SignalProtocolStore'; @@ -1774,7 +1774,6 @@ describe('SignalProtocolStore', () => { assert.strictEqual(items.length, 0); }); }); - /* describe('removeOurOldPni/updateOurPniKeyMaterial', () => { beforeEach(async () => { await store.storePreKey(ourUuid, 2, testKey); @@ -1851,5 +1850,4 @@ describe('SignalProtocolStore', () => { // Note: signature is ignored. }); }); - */ }); diff --git a/ts/textsecure/AccountManager.ts b/ts/textsecure/AccountManager.ts index 097e0002b..5128b5e08 100644 --- a/ts/textsecure/AccountManager.ts +++ b/ts/textsecure/AccountManager.ts @@ -862,8 +862,8 @@ export default class AccountManager extends EventTarget { if (keyMaterial) { await storage.protocol.updateOurPniKeyMaterial( - new UUID(pni) - // keyMaterial + new UUID(pni), + keyMaterial ); // Intentionally not awaiting since this is processed on encrypted queue diff --git a/ts/textsecure/cds/CDSISocket.ts b/ts/textsecure/cds/CDSISocket.ts index 44f63a7c9..49bc87b69 100644 --- a/ts/textsecure/cds/CDSISocket.ts +++ b/ts/textsecure/cds/CDSISocket.ts @@ -1,7 +1,7 @@ // Copyright 2022 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only -import type { Cds2Client } from '@signalapp/libsignal-client'; +import { Cds2Client } from '@signalapp/libsignal-client'; import { strictAssert } from '../../util/assert'; import { SignalService as Proto } from '../../protobuf'; @@ -23,8 +23,6 @@ export class CDSISocket extends CDSSocketBase { ); this.state = CDSSocketState.Handshake; - throw new Error('TODO: CDSISocket: Cds2Client is not available!'); - /* { const { done, value: attestationMessage } = await this.socketIterator.next(); @@ -42,7 +40,6 @@ export class CDSISocket extends CDSSocketBase { earliestValidTimestamp ); } - */ this.socket.sendBytes(this.cdsClient.initialRequest()); diff --git a/yarn.lock b/yarn.lock index 013d737e1..d4142c9b6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1745,10 +1745,10 @@ "@react-spring/shared" "~9.4.5" "@react-spring/types" "~9.4.5" -"@signalapp/libsignal-client@0.18.1": - version "0.18.1" - resolved "https://registry.yarnpkg.com/@signalapp/libsignal-client/-/libsignal-client-0.18.1.tgz#6b499cdcc952f1981c6367f68484cf3275be3b31" - integrity sha512-43NcTYpahImlWHBDaNFmn7QaeXZHkFkTtb4m+ZWgzU0mkS1M8V+orGen2XuDvNiu+9HQmW4Lg7FV1deXhWtIRA== +"@signalapp/libsignal-client@0.19.2": + version "0.19.2" + resolved "https://registry.yarnpkg.com/@signalapp/libsignal-client/-/libsignal-client-0.19.2.tgz#319da45eac91fe0809bd602528f841346050b7f4" + integrity sha512-tK2U9+NKeO246EmXmk0xraot6S+dKBnhCqQ7XBEUOsyMSJ5THUaGIridjWJiazJcBAFDPFHWArXMR3iEoNPXsg== dependencies: node-gyp-build "^4.2.3" uuid "^8.3.0"