Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3339752
D11728.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D11728.diff
View Options
diff --git a/web/shared-worker/worker/worker-crypto.js b/web/shared-worker/worker/worker-crypto.js
--- a/web/shared-worker/worker/worker-crypto.js
+++ b/web/shared-worker/worker/worker-crypto.js
@@ -24,6 +24,7 @@
IdentityExistingDeviceKeyUpload,
} from 'lib/types/identity-service-types.js';
import type { OlmSessionInitializationInfo } from 'lib/types/request-types.js';
+import type { ReceivedMessageToDevice } from 'lib/types/sqlite-types.js';
import { entries } from 'lib/utils/objects.js';
import {
retrieveAccountKeysSet,
@@ -80,7 +81,7 @@
cryptoStore = null;
}
-function persistCryptoStore() {
+function persistCryptoStore(withoutTransaction: boolean = false) {
const sqliteQueryExecutor = getSQLiteQueryExecutor();
const dbModule = getDBModule();
if (!sqliteQueryExecutor || !dbModule) {
@@ -119,7 +120,9 @@
};
try {
- sqliteQueryExecutor.beginTransaction();
+ if (!withoutTransaction) {
+ sqliteQueryExecutor.beginTransaction();
+ }
sqliteQueryExecutor.storeOlmPersistAccount(
sqliteQueryExecutor.getContentAccountID(),
JSON.stringify(pickledContentAccount),
@@ -131,9 +134,13 @@
sqliteQueryExecutor.getNotifsAccountID(),
JSON.stringify(pickledNotificationAccount),
);
- sqliteQueryExecutor.commitTransaction();
+ if (!withoutTransaction) {
+ sqliteQueryExecutor.commitTransaction();
+ }
} catch (err) {
- sqliteQueryExecutor.rollbackTransaction();
+ if (!withoutTransaction) {
+ sqliteQueryExecutor.rollbackTransaction();
+ }
throw new Error(getProcessingStoreOpsExceptionMessage(err, dbModule));
}
}
@@ -458,7 +465,6 @@
async decryptSequential(
encryptedData: EncryptedData,
deviceID: string,
- // eslint-disable-next-line no-unused-vars
messageID: string,
): Promise<string> {
if (!cryptoStore) {
@@ -475,7 +481,30 @@
encryptedData.message,
);
- persistCryptoStore();
+ const sqliteQueryExecutor = getSQLiteQueryExecutor();
+ const dbModule = getDBModule();
+ if (!sqliteQueryExecutor || !dbModule) {
+ throw new Error(
+ "Couldn't persist crypto store because database is not initialized",
+ );
+ }
+
+ const receivedMessage: ReceivedMessageToDevice = {
+ messageID,
+ senderDeviceID: deviceID,
+ plaintext: result,
+ status: 'decrypted',
+ };
+
+ sqliteQueryExecutor.beginTransaction();
+ try {
+ sqliteQueryExecutor.addReceivedMessageToDevice(receivedMessage);
+ persistCryptoStore(true);
+ sqliteQueryExecutor.commitTransaction();
+ } catch (e) {
+ sqliteQueryExecutor.rollbackTransaction();
+ throw e;
+ }
return result;
},
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 22, 8:37 PM (17 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2564775
Default Alt Text
D11728.diff (2 KB)
Attached To
Mode
D11728: [web] decrypt and persist plaintext in SQL transaction
Attached
Detach File
Event Timeline
Log In to Comment