Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3382466
D11780.id39530.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D11780.id39530.diff
View Options
diff --git a/keyserver/src/creators/account-creator.js b/keyserver/src/creators/account-creator.js
--- a/keyserver/src/creators/account-creator.js
+++ b/keyserver/src/creators/account-creator.js
@@ -274,13 +274,7 @@
viewer: Viewer,
request: ProcessOLMAccountCreationRequest,
): Promise<void> {
- const { calendarQuery, signedIdentityKeysBlob } = request;
- await verifyCalendarQueryThreadIDs(calendarQuery);
-
const time = Date.now();
- const deviceToken = request.deviceTokenUpdateRequest
- ? request.deviceTokenUpdateRequest.deviceToken
- : viewer.deviceToken;
const newUserRow = [
request.userID,
request.username,
@@ -291,20 +285,7 @@
INSERT INTO users(id, username, ethereum_address, creation_time)
VALUES ${[newUserRow]}
`;
- const [userViewerData] = await Promise.all([
- createNewUserCookie(request.userID, {
- platformDetails: request.platformDetails,
- deviceToken,
- signedIdentityKeysBlob,
- }),
- deleteCookie(viewer.cookieID),
- dbQuery(newUserQuery),
- ]);
- viewer.setNewCookie(userViewerData);
-
- await setNewSession(viewer, calendarQuery, 0);
-
- await processAccountCreationCommon(viewer);
+ await dbQuery(newUserQuery);
}
async function processAccountCreationCommon(viewer: Viewer) {
@@ -375,4 +356,9 @@
await rustAPI.addReservedUsernames(stringifiedMessage, signature);
}
-export { createAccount, processSIWEAccountCreation, processOLMAccountCreation };
+export {
+ createAccount,
+ processSIWEAccountCreation,
+ processOLMAccountCreation,
+ processAccountCreationCommon,
+};
diff --git a/keyserver/src/responders/user-responders.js b/keyserver/src/responders/user-responders.js
--- a/keyserver/src/responders/user-responders.js
+++ b/keyserver/src/responders/user-responders.js
@@ -101,13 +101,13 @@
} from './entry-responders.js';
import {
processOLMAccountCreation,
+ processAccountCreationCommon,
createAccount,
processSIWEAccountCreation,
} from '../creators/account-creator.js';
import {
createOlmSession,
persistFreshOlmSession,
- createAndPersistOlmSession,
} from '../creators/olm-session-creator.js';
import { dbQuery, SQL } from '../database/database.js';
import { deleteAccount } from '../deleters/account-deleters.js';
@@ -302,7 +302,6 @@
+signedIdentityKeysBlob?: ?SignedIdentityKeysBlob,
+initialNotificationsEncryptedMessage?: string,
+pickledContentOlmSession?: string,
- +cookieHasBeenSet?: boolean,
};
async function processSuccessfulLogin(
@@ -317,18 +316,24 @@
signedIdentityKeysBlob,
initialNotificationsEncryptedMessage,
pickledContentOlmSession,
- cookieHasBeenSet,
} = params;
+ const olmNotifSession = await (async () => {
+ if (initialNotificationsEncryptedMessage && signedIdentityKeysBlob) {
+ return await createOlmSession(
+ initialNotificationsEncryptedMessage,
+ 'notifications',
+ );
+ }
+ return null;
+ })();
+
const request: LogInRequest = input;
const newServerTime = Date.now();
const deviceToken = request.deviceTokenUpdateRequest
? request.deviceTokenUpdateRequest.deviceToken
: viewer.deviceToken;
const setNewCookiePromise = (async () => {
- if (cookieHasBeenSet) {
- return;
- }
const [userViewerData] = await Promise.all([
createNewUserCookie(userID, {
platformDetails: request.platformDetails,
@@ -366,16 +371,13 @@
}
if (calendarQuery) {
+ await verifyCalendarQueryThreadIDs(calendarQuery);
await setNewSession(viewer, calendarQuery, newServerTime);
}
- const olmNotifSessionPromise = (async () => {
- if (
- viewer.cookieID &&
- initialNotificationsEncryptedMessage &&
- signedIdentityKeysBlob
- ) {
- await createAndPersistOlmSession(
- initialNotificationsEncryptedMessage,
+ const persistOlmNotifSessionPromise = (async () => {
+ if (olmNotifSession && viewer.cookieID) {
+ await persistFreshOlmSession(
+ olmNotifSession,
'notifications',
viewer.cookieID,
);
@@ -384,7 +386,7 @@
// `pickledContentOlmSession` is created in `keyserverAuthResponder(...)` in
// order to authenticate the user. Here, we simply persist the session if it
// exists.
- const olmContentSessionPromise = (async () => {
+ const persistOlmContentSessionPromise = (async () => {
if (viewer.cookieID && pickledContentOlmSession) {
await persistFreshOlmSession(
pickledContentOlmSession,
@@ -419,8 +421,8 @@
entriesPromise,
fetchKnownUserInfos(viewer),
fetchLoggedInUserInfo(viewer),
- olmNotifSessionPromise,
- olmContentSessionPromise,
+ persistOlmNotifSessionPromise,
+ persistOlmContentSessionPromise,
]);
const rawEntryInfos = entriesResult ? entriesResult.rawEntryInfos : null;
@@ -778,9 +780,7 @@
);
// 4. Create account with call to `processOLMAccountCreation(...)`
- // if username does not correspond to an existing user. If we successfully
- // create a new account, we set `cookieHasBeenSet` to true to avoid
- // creating a new cookie again in `processSuccessfulLogin`.
+ // if username does not correspond to an existing user.
const signedIdentityKeysBlob: SignedIdentityKeysBlob = {
payload: inboundKeysForUser.payload,
signature: inboundKeysForUser.payloadSignature,
@@ -807,7 +807,7 @@
]);
// 5. Complete login with call to `processSuccessfulLogin(...)`.
- return await processSuccessfulLogin({
+ const result = await processSuccessfulLogin({
viewer,
input: request,
userID,
@@ -815,8 +815,15 @@
signedIdentityKeysBlob,
initialNotificationsEncryptedMessage,
pickledContentOlmSession,
- cookieHasBeenSet: !existingUsername,
});
+
+ // 6. Create threads with call to `processAccountCreationCommon(...)`,
+ // if the account has just been registered.
+ if (!existingUsername) {
+ await processAccountCreationCommon(viewer);
+ }
+
+ return result;
}
export const updatePasswordRequestInputValidator: TInterface<UpdatePasswordRequest> =
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 29, 10:56 AM (10 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2596728
Default Alt Text
D11780.id39530.diff (5 KB)
Attached To
Mode
D11780: [keyserver] Fix sending a user cookie when olm session creation failed
Attached
Detach File
Event Timeline
Log In to Comment