Skip to content

Commit

Permalink
Revert "[keyserver][lib] don't generate one time keys on identity login"
Browse files Browse the repository at this point in the history
Summary:
This reverts commit d2f01b5.

Depends on D13575

Resolves https://linear.app/comm/issue/ENG-9440/clients-should-include-otks-on-first-login

Test Plan: set up a new keyserver with my test user credentials, on login my keyserver's OTKs were present in DynamoDB

Reviewers: will, bartek, ashoat

Reviewed By: ashoat

Subscribers: ashoat, tomek

Differential Revision: https://phab.comm.dev/D13577
  • Loading branch information
vdhanan committed Oct 7, 2024
1 parent f3dce85 commit 259f596
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 35 deletions.
2 changes: 2 additions & 0 deletions keyserver/addons/rust-node-addon/rust-binding-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type RustNativeBindingAPI = {
contentPrekeySignature: string,
notifPrekey: string,
notifPrekeySignature: string,
contentOneTimeKeys: $ReadOnlyArray<string>,
notifOneTimeKeys: $ReadOnlyArray<string>,
force: ?boolean,
) => Promise<IdentityInfo>,
+registerUser: (
Expand Down
6 changes: 4 additions & 2 deletions keyserver/addons/rust-node-addon/src/identity_client/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub async fn login_user(
content_prekey_signature: String,
notif_prekey: String,
notif_prekey_signature: String,
content_one_time_keys: Vec<String>,
notif_one_time_keys: Vec<String>,
force: Option<bool>,
) -> Result<UserLoginInfo> {
debug!("Attempting to log in user: {}", username);
Expand Down Expand Up @@ -47,8 +49,8 @@ pub async fn login_user(
prekey: notif_prekey,
prekey_signature: notif_prekey_signature,
}),
one_time_content_prekeys: Vec::new(),
one_time_notif_prekeys: Vec::new(),
one_time_content_prekeys: content_one_time_keys,
one_time_notif_prekeys: notif_one_time_keys,
device_type: DeviceType::Keyserver.into(),
}),
force,
Expand Down
26 changes: 10 additions & 16 deletions keyserver/src/user/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
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 {
retrieveIdentityKeysAndPrekeys,
getAccountOneTimeKeys,
} from 'lib/utils/olm-utils.js';
import { retrieveAccountKeysSet } from 'lib/utils/olm-utils.js';

import type { UserCredentials } from './checks.js';
import {
Expand Down Expand Up @@ -156,14 +152,16 @@ async function registerOrLogInBase<T>(
identityKeys: notificationsIdentityKeys,
prekey: notificationsPrekey,
prekeySignature: notificationsPrekeySignature,
} = await getUpdateNotificationsAccount(retrieveIdentityKeysAndPrekeys);
oneTimeKeys: notificationsOneTimeKeys,
} = await fetchCallUpdateOlmAccount('notifications', retrieveAccountKeysSet);

const contentAccountCallback = (account: OlmAccount) => {
const contentAccountCallback = async (account: OlmAccount) => {
const {
identityKeys: contentIdentityKeys,
oneTimeKeys,
prekey,
prekeySignature,
} = retrieveIdentityKeysAndPrekeys(account);
} = await retrieveAccountKeysSet(account);

const identityKeysBlob = {
primaryIdentityPublicKeys: JSON.parse(contentIdentityKeys),
Expand All @@ -177,6 +175,7 @@ async function registerOrLogInBase<T>(

return {
signedIdentityKeysBlob,
oneTimeKeys,
prekey,
prekeySignature,
};
Expand All @@ -188,6 +187,7 @@ async function registerOrLogInBase<T>(
signedIdentityKeysBlob,
prekey: contentPrekey,
prekeySignature: contentPrekeySignature,
oneTimeKeys: contentOneTimeKeys,
},
] = await Promise.all([
rustAPIPromise,
Expand All @@ -203,6 +203,8 @@ async function registerOrLogInBase<T>(
contentPrekeySignature,
notificationsPrekey,
notificationsPrekeySignature,
contentOneTimeKeys,
notificationsOneTimeKeys,
userInfo.forceLogin,
);
await Promise.all([
Expand All @@ -212,14 +214,6 @@ async function registerOrLogInBase<T>(
return identity_info;
} catch (e) {
console.warn('Failed to login user: ' + getMessageForException(e));
const [contentOneTimeKeys, notificationsOneTimeKeys] = await Promise.all([
getUpdateContentAccount((account: OlmAccount) =>
getAccountOneTimeKeys(account, ONE_TIME_KEYS_NUMBER),
),
getUpdateNotificationsAccount((account: OlmAccount) =>
getAccountOneTimeKeys(account, ONE_TIME_KEYS_NUMBER),
),
]);
try {
await Promise.all([
getUpdateContentAccount(markOneTimeKeysAsPublished),
Expand Down
20 changes: 3 additions & 17 deletions lib/utils/olm-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ type AccountKeysSet = {
+oneTimeKeys: $ReadOnlyArray<string>,
};

type IdentityKeysAndPrekeys = {
+identityKeys: string,
+prekey: string,
+prekeySignature: string,
};

function validateAccountPrekey(account: OlmAccount) {
if (shouldRotatePrekey(account)) {
account.generate_prekey();
Expand Down Expand Up @@ -95,15 +89,6 @@ function getAccountOneTimeKeys(
}

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);
Expand All @@ -113,7 +98,9 @@ function retrieveIdentityKeysAndPrekeys(
throw new Error('invalid_prekey');
}

return { identityKeys, prekey, prekeySignature };
const oneTimeKeys = getAccountOneTimeKeys(account, ONE_TIME_KEYS_NUMBER);

return { identityKeys, oneTimeKeys, prekey, prekeySignature };
}

export const OLM_SESSION_ERROR_PREFIX = 'OLM_';
Expand Down Expand Up @@ -155,7 +142,6 @@ export {
shouldForgetPrekey,
shouldRotatePrekey,
getAccountOneTimeKeys,
retrieveIdentityKeysAndPrekeys,
hasHigherDeviceID,
olmSessionErrors,
};

0 comments on commit 259f596

Please sign in to comment.