Page MenuHomePhabricator

D10491.diff
No OneTemporary

D10491.diff

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
@@ -32,7 +32,7 @@
import createIDs from './id-creator.js';
import createMessages from './message-creator.js';
-import { createOlmSession } from './olm-session-creator.js';
+import { createAndPersistOlmSession } from './olm-session-creator.js';
import {
createThread,
createPrivateThread,
@@ -125,7 +125,7 @@
const olmSessionPromise = (async () => {
if (userViewerData.cookieID && initialNotificationsEncryptedMessage) {
- await createOlmSession(
+ await createAndPersistOlmSession(
initialNotificationsEncryptedMessage,
'notifications',
userViewerData.cookieID,
diff --git a/keyserver/src/creators/olm-session-creator.js b/keyserver/src/creators/olm-session-creator.js
--- a/keyserver/src/creators/olm-session-creator.js
+++ b/keyserver/src/creators/olm-session-creator.js
@@ -11,26 +11,29 @@
async function createOlmSession(
initialEncryptedMessage: string,
olmSessionType: 'content' | 'notifications',
- cookieID: string,
-): Promise<void> {
+ theirCurve25519Key?: string,
+): Promise<string> {
const callback = (account: OlmAccount, picklingKey: string) =>
- createPickledOlmSession(account, picklingKey, initialEncryptedMessage);
+ createPickledOlmSession(
+ account,
+ picklingKey,
+ initialEncryptedMessage,
+ theirCurve25519Key,
+ );
- let pickledOlmSession;
try {
- pickledOlmSession = await fetchCallUpdateOlmAccount(
- olmSessionType,
- callback,
- );
+ return await fetchCallUpdateOlmAccount(olmSessionType, callback);
} catch (e) {
- console.warn(
- `failed to create olm session of type: ${olmSessionType} ` +
- `for user with cookie id: ${cookieID}`,
- e,
- );
+ console.warn(`failed to create olm session of type: ${olmSessionType}`, e);
throw new ServerError('olm_session_creation_failure');
}
+}
+async function persistFreshOlmSession(
+ pickledOlmSession: string,
+ olmSessionType: 'content' | 'notifications',
+ cookieID: string,
+): Promise<void> {
const isContent = olmSessionType === 'content';
// We match the native client behavior here where olm session is overwritten
// in case it is initialized twice for the same pair of identities
@@ -45,4 +48,19 @@
);
}
-export { createOlmSession };
+async function createAndPersistOlmSession(
+ initialEncryptedMessage: string,
+ olmSessionType: 'content' | 'notifications',
+ cookieID: string,
+ theirCurve25519Key?: string,
+): Promise<void> {
+ const pickledOlmSession = await createOlmSession(
+ initialEncryptedMessage,
+ olmSessionType,
+ theirCurve25519Key,
+ );
+
+ await persistFreshOlmSession(pickledOlmSession, olmSessionType, cookieID);
+}
+
+export { createOlmSession, persistFreshOlmSession, createAndPersistOlmSession };
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,7 +101,7 @@
createAccount,
processSIWEAccountCreation,
} from '../creators/account-creator.js';
-import { createOlmSession } from '../creators/olm-session-creator.js';
+import { createAndPersistOlmSession } from '../creators/olm-session-creator.js';
import { dbQuery, SQL } from '../database/database.js';
import { deleteAccount } from '../deleters/account-deleters.js';
import { deleteCookie } from '../deleters/cookie-deleters.js';
@@ -354,7 +354,7 @@
initialNotificationsEncryptedMessage &&
signedIdentityKeysBlob
) {
- await createOlmSession(
+ await createAndPersistOlmSession(
initialNotificationsEncryptedMessage,
'notifications',
userViewerData.cookieID,
diff --git a/keyserver/src/socket/session-utils.js b/keyserver/src/socket/session-utils.js
--- a/keyserver/src/socket/session-utils.js
+++ b/keyserver/src/socket/session-utils.js
@@ -38,7 +38,7 @@
tPlatformDetails,
} from 'lib/utils/validation-utils.js';
-import { createOlmSession } from '../creators/olm-session-creator.js';
+import { createAndPersistOlmSession } from '../creators/olm-session-creator.js';
import { saveOneTimeKeys } from '../creators/one-time-keys-creator.js';
import createReport from '../creators/report-creator.js';
import { fetchEntriesForSession } from '../fetchers/entry-fetchers.js';
@@ -234,7 +234,7 @@
);
const { initialNotificationsEncryptedMessage } = clientResponse;
try {
- await createOlmSession(
+ await createAndPersistOlmSession(
initialNotificationsEncryptedMessage,
'notifications',
viewer.cookieID,

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 29, 5:11 AM (9 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2730760
Default Alt Text
D10491.diff (4 KB)

Event Timeline