Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32429239
D11728.1765354828.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D11728.1765354828.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) {
@@ -470,12 +476,35 @@
throw new Error(`No session for deviceID: ${deviceID}`);
}
- const result = session.decrypt(
+ const result = session.decrypt_sequential(
encryptedData.messageType,
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
Wed, Dec 10, 8:20 AM (14 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5862434
Default Alt Text
D11728.1765354828.diff (2 KB)
Attached To
Mode
D11728: [web] decrypt and persist plaintext in SQL transaction
Attached
Detach File
Event Timeline
Log In to Comment