From 22fb69bbb72a54b9bec6aefd11a846eb50363aed Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Thu, 8 Jun 2023 18:08:24 -0700 Subject: [PATCH] Call refreshPreKeys on same cadence as rotateSignedPreKey --- ts/textsecure/AccountManager.ts | 11 +++++++++-- ts/textsecure/RotateSignedPreKeyListener.ts | 7 +++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ts/textsecure/AccountManager.ts b/ts/textsecure/AccountManager.ts index 0c0ada0bd..a6461f55c 100644 --- a/ts/textsecure/AccountManager.ts +++ b/ts/textsecure/AccountManager.ts @@ -326,13 +326,20 @@ export default class AccountManager extends EventTarget { async refreshPreKeys(uuidKind: UUIDKind): Promise { return this.queueTask(async () => { const preKeyCount = await this.server.getMyKeys(uuidKind); - log.info(`prekey count ${preKeyCount}`); + log.info( + `refreshPreKeys(${uuidKind}): Server prekey count is ${preKeyCount}` + ); if (preKeyCount >= 10) { return; } + const keys = await this.generateKeys(SIGNED_KEY_GEN_BATCH_SIZE, uuidKind); await this.server.registerKeys(keys, uuidKind); - await this.confirmKeys(keys, uuidKind); + + const updatedCount = await this.server.getMyKeys(uuidKind); + log.info( + `refreshPreKeys(${uuidKind}): Successfully updated; server count is now ${updatedCount}` + ); }); } diff --git a/ts/textsecure/RotateSignedPreKeyListener.ts b/ts/textsecure/RotateSignedPreKeyListener.ts index fb2a871dc..c74339f6c 100644 --- a/ts/textsecure/RotateSignedPreKeyListener.ts +++ b/ts/textsecure/RotateSignedPreKeyListener.ts @@ -58,6 +58,13 @@ export class RotateSignedPreKeyListener { accountManager.rotateSignedPreKey(UUIDKind.ACI), accountManager.rotateSignedPreKey(UUIDKind.PNI), ]); + + // We try to update this whenever we remove a preKey; this is a fail-safe to ensure + // we're always in good shape + await Promise.all([ + accountManager.refreshPreKeys(UUIDKind.ACI), + accountManager.refreshPreKeys(UUIDKind.PNI), + ]); this.scheduleNextRotation(); this.setTimeoutForNextRun(); } catch (error) {