diff --git a/keyserver/addons/rust-node-addon/rust-binding-types.js b/keyserver/addons/rust-node-addon/rust-binding-types.js --- a/keyserver/addons/rust-node-addon/rust-binding-types.js +++ b/keyserver/addons/rust-node-addon/rust-binding-types.js @@ -14,8 +14,6 @@ contentPrekeySignature: string, notifPrekey: string, notifPrekeySignature: string, - contentOneTimeKeys: $ReadOnlyArray, - notifOneTimeKeys: $ReadOnlyArray, force: ?boolean, ) => Promise, +registerUser: ( diff --git a/keyserver/addons/rust-node-addon/src/identity_client/login.rs b/keyserver/addons/rust-node-addon/src/identity_client/login.rs --- a/keyserver/addons/rust-node-addon/src/identity_client/login.rs +++ b/keyserver/addons/rust-node-addon/src/identity_client/login.rs @@ -16,8 +16,6 @@ content_prekey_signature: String, notif_prekey: String, notif_prekey_signature: String, - content_one_time_keys: Vec, - notif_one_time_keys: Vec, force: Option, ) -> Result { debug!("Attempting to log in user: {}", username); @@ -48,8 +46,8 @@ prekey: notif_prekey, prekey_signature: notif_prekey_signature, }), - one_time_content_prekeys: content_one_time_keys, - one_time_notif_prekeys: notif_one_time_keys, + one_time_content_prekeys: Vec::new(), + one_time_notif_prekeys: Vec::new(), device_type: DeviceType::Keyserver.into(), }), force, diff --git a/keyserver/src/user/login.js b/keyserver/src/user/login.js --- a/keyserver/src/user/login.js +++ b/keyserver/src/user/login.js @@ -3,9 +3,13 @@ import type { Account as OlmAccount } from '@commapp/olm'; import { getRustAPI } from 'rust-node-addon'; +import { ONE_TIME_KEYS_NUMBER } from 'lib/types/identity-service-types.js'; import { getCommConfig } from 'lib/utils/comm-config.js'; import { ServerError } from 'lib/utils/errors.js'; -import { retrieveAccountKeysSet } from 'lib/utils/olm-utils.js'; +import { + retrieveIdentityKeysAndPrekeys, + getAccountOneTimeKeys, +} from 'lib/utils/olm-utils.js'; import type { UserCredentials } from './checks.js'; import { @@ -74,16 +78,17 @@ identityKeys: notificationsIdentityKeys, prekey: notificationsPrekey, prekeySignature: notificationsPrekeySignature, - oneTimeKeys: notificationsOneTimeKeys, - } = await fetchCallUpdateOlmAccount('notifications', retrieveAccountKeysSet); + } = await fetchCallUpdateOlmAccount( + 'notifications', + retrieveIdentityKeysAndPrekeys, + ); - const contentAccountCallback = async (account: OlmAccount) => { + const contentAccountCallback = (account: OlmAccount) => { const { identityKeys: contentIdentityKeys, - oneTimeKeys, prekey, prekeySignature, - } = await retrieveAccountKeysSet(account); + } = retrieveIdentityKeysAndPrekeys(account); const identityKeysBlob = { primaryIdentityPublicKeys: JSON.parse(contentIdentityKeys), @@ -97,7 +102,6 @@ return { signedIdentityKeysBlob, - oneTimeKeys, prekey, prekeySignature, }; @@ -109,7 +113,6 @@ signedIdentityKeysBlob, prekey: contentPrekey, prekeySignature: contentPrekeySignature, - oneTimeKeys: contentOneTimeKeys, }, ] = await Promise.all([ rustAPIPromise, @@ -125,8 +128,6 @@ contentPrekeySignature, notificationsPrekey, notificationsPrekeySignature, - contentOneTimeKeys, - notificationsOneTimeKeys, userInfo.forceLogin, ); await Promise.all([ @@ -136,6 +137,14 @@ return identity_info; } catch (e) { console.warn('Failed to login user: ' + getMessageForException(e)); + const [contentOneTimeKeys, notificationsOneTimeKeys] = await Promise.all([ + fetchCallUpdateOlmAccount('content', (account: OlmAccount) => + getAccountOneTimeKeys(account, ONE_TIME_KEYS_NUMBER), + ), + fetchCallUpdateOlmAccount('notifications', (account: OlmAccount) => + getAccountOneTimeKeys(account, ONE_TIME_KEYS_NUMBER), + ), + ]); try { const identity_info = await rustAPI.registerUser( userInfo.username, diff --git a/lib/utils/olm-utils.js b/lib/utils/olm-utils.js --- a/lib/utils/olm-utils.js +++ b/lib/utils/olm-utils.js @@ -18,6 +18,12 @@ +oneTimeKeys: $ReadOnlyArray, }; +type IdentityKeysAndPrekeys = { + +identityKeys: string, + +prekey: string, + +prekeySignature: string, +}; + function validateAccountPrekey(account: OlmAccount) { if (shouldRotatePrekey(account)) { account.generate_prekey(); @@ -89,6 +95,15 @@ } function retrieveAccountKeysSet(account: OlmAccount): AccountKeysSet { + const { identityKeys, prekey, prekeySignature } = + retrieveIdentityKeysAndPrekeys(account); + const oneTimeKeys = getAccountOneTimeKeys(account, ONE_TIME_KEYS_NUMBER); + return { identityKeys, oneTimeKeys, prekey, prekeySignature }; +} + +function retrieveIdentityKeysAndPrekeys( + account: OlmAccount, +): IdentityKeysAndPrekeys { const identityKeys = account.identity_keys(); validateAccountPrekey(account); @@ -98,9 +113,7 @@ throw new Error('invalid_prekey'); } - const oneTimeKeys = getAccountOneTimeKeys(account, ONE_TIME_KEYS_NUMBER); - - return { identityKeys, oneTimeKeys, prekey, prekeySignature }; + return { identityKeys, prekey, prekeySignature }; } export { @@ -109,4 +122,5 @@ shouldForgetPrekey, shouldRotatePrekey, getAccountOneTimeKeys, + retrieveIdentityKeysAndPrekeys, };