Page MenuHomePhabricator

D8588.diff
No OneTemporary

D8588.diff

diff --git a/keyserver/src/push/crypto.js b/keyserver/src/push/crypto.js
--- a/keyserver/src/push/crypto.js
+++ b/keyserver/src/push/crypto.js
@@ -37,13 +37,11 @@
let encryptedSerializedPayload;
try {
const unencryptedSerializedPayload = JSON.stringify(unencryptedPayload);
- const { serializedPayload } = await encryptAndUpdateOlmSession(
- cookieID,
- 'notifications',
- {
- serializedPayload: unencryptedSerializedPayload,
- },
- );
+ const {
+ encryptedMessages: { serializedPayload },
+ } = await encryptAndUpdateOlmSession(cookieID, 'notifications', {
+ serializedPayload: unencryptedSerializedPayload,
+ });
encryptedSerializedPayload = serializedPayload;
} catch (e) {
console.log('Notification encryption failed: ' + e);
@@ -78,13 +76,11 @@
if (!unencryptedSerializedPayload) {
return unencryptedPayload;
}
- const { serializedPayload } = await encryptAndUpdateOlmSession(
- cookieID,
- 'notifications',
- {
- serializedPayload: unencryptedSerializedPayload,
- },
- );
+ const {
+ encryptedMessages: { serializedPayload },
+ } = await encryptAndUpdateOlmSession(cookieID, 'notifications', {
+ serializedPayload: unencryptedSerializedPayload,
+ });
return { encryptedPayload: serializedPayload.body };
} catch (e) {
console.log('Notification encryption failed: ' + e);
diff --git a/keyserver/src/updaters/olm-session-updater.js b/keyserver/src/updaters/olm-session-updater.js
--- a/keyserver/src/updaters/olm-session-updater.js
+++ b/keyserver/src/updaters/olm-session-updater.js
@@ -12,11 +12,17 @@
const maxOlmSessionUpdateAttemptTime = 30000;
const olmSessionUpdateRetryDelay = 50;
+type OlmEncryptionResult = {
+ +encryptedMessages: { +[string]: EncryptResult },
+ +dbPersistConditionViolated?: boolean,
+};
+
async function encryptAndUpdateOlmSession(
cookieID: string,
olmSessionType: 'content' | 'notifications',
messagesToEncrypt: $ReadOnly<{ [string]: string }>,
-): Promise<{ [string]: EncryptResult }> {
+ dbPersistCondition?: ({ +[string]: EncryptResult }) => boolean,
+): Promise<OlmEncryptionResult> {
const isContent = olmSessionType === 'content';
const { picklingKey } = await fetchOlmAccount(olmSessionType);
const olmUpdateAttemptStartTime = Date.now();
@@ -47,6 +53,10 @@
);
}
+ if (dbPersistCondition && !dbPersistCondition(encryptedMessages)) {
+ return { encryptedMessages, dbPersistConditionViolated: true };
+ }
+
const updatedSession = session.pickle(picklingKey);
const [transactionResult] = await dbQuery(
@@ -76,7 +86,7 @@
const [{ versionOnUpdateAttempt }] = selectResult;
if (version === versionOnUpdateAttempt) {
- return encryptedMessages;
+ return { encryptedMessages };
}
await sleep(olmSessionUpdateRetryDelay);

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 27, 8:40 PM (20 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2591632
Default Alt Text
D8588.diff (2 KB)

Event Timeline