Page MenuHomePhabricator

D9107.id31194.diff
No OneTemporary

D9107.id31194.diff

diff --git a/web/database/database-module-provider.js b/web/database/database-module-provider.js
--- a/web/database/database-module-provider.js
+++ b/web/database/database-module-provider.js
@@ -1,10 +1,17 @@
// @flow
+import localforage from 'localforage';
+
import {
DATABASE_WORKER_PATH,
DATABASE_MODULE_FILE_PATH,
+ SQLITE_ENCRYPTION_KEY,
} from './utils/constants.js';
import { isDesktopSafari, isSQLiteSupported } from './utils/db-utils.js';
+import {
+ exportKeyToJWK,
+ generateDatabaseCryptoKey,
+} from './utils/worker-crypto-utils.js';
import WorkerConnectionProxy from './utils/WorkerConnectionProxy.js';
import type { AppState } from '../redux/redux-setup.js';
import {
@@ -72,10 +79,7 @@
})();
}
- initDBForLoggedInUser(
- currentLoggedInUserID: ?string,
- encryptionKey?: ?SubtleCrypto$JsonWebKey,
- ) {
+ async initDBForLoggedInUser(currentLoggedInUserID: ?string) {
if (this.status === databaseStatuses.initSuccess) {
return;
}
@@ -84,6 +88,11 @@
this.status === databaseStatuses.notSupported &&
isSQLiteSupported(currentLoggedInUserID)
) {
+ let encryptionKey = null;
+ if (isDesktopSafari) {
+ encryptionKey = await getSafariEncryptionKey();
+ }
+
this.init(encryptionKey);
}
}
@@ -121,6 +130,18 @@
}
}
+async function getSafariEncryptionKey(): Promise<SubtleCrypto$JsonWebKey> {
+ const encryptionKey = await localforage.getItem(SQLITE_ENCRYPTION_KEY);
+ if (encryptionKey) {
+ return await exportKeyToJWK(encryptionKey);
+ }
+ const newEncryptionKey = await generateDatabaseCryptoKey({
+ extractable: true,
+ });
+ await localforage.setItem(SQLITE_ENCRYPTION_KEY, newEncryptionKey);
+ return await exportKeyToJWK(newEncryptionKey);
+}
+
let databaseModule: ?DatabaseModule = null;
async function getDatabaseModule(): Promise<DatabaseModule> {
if (!databaseModule) {
diff --git a/web/database/sqlite-data-handler.js b/web/database/sqlite-data-handler.js
--- a/web/database/sqlite-data-handler.js
+++ b/web/database/sqlite-data-handler.js
@@ -1,6 +1,5 @@
// @flow
-import localforage from 'localforage';
import * as React from 'react';
import { useDispatch } from 'react-redux';
@@ -8,27 +7,9 @@
import { reportStoreOpsHandlers } from 'lib/ops/report-store-ops.js';
import { getDatabaseModule } from './database-module-provider.js';
-import { SQLITE_ENCRYPTION_KEY } from './utils/constants.js';
-import { isDesktopSafari } from './utils/db-utils.js';
-import {
- exportKeyToJWK,
- generateDatabaseCryptoKey,
-} from './utils/worker-crypto-utils.js';
import { useSelector } from '../redux/redux-utils.js';
import { workerRequestMessageTypes } from '../types/worker-types.js';
-async function getSafariEncryptionKey(): Promise<SubtleCrypto$JsonWebKey> {
- const encryptionKey = await localforage.getItem(SQLITE_ENCRYPTION_KEY);
- if (encryptionKey) {
- return await exportKeyToJWK(encryptionKey);
- }
- const newEncryptionKey = await generateDatabaseCryptoKey({
- extractable: true,
- });
- await localforage.setItem(SQLITE_ENCRYPTION_KEY, newEncryptionKey);
- return await exportKeyToJWK(newEncryptionKey);
-}
-
function SQLiteDataHandler(): React.Node {
const dispatch = useDispatch();
const rehydrateConcluded = useSelector(
@@ -69,14 +50,7 @@
const databaseModule = await getDatabaseModule();
if (currentLoggedInUserID) {
- let databaseEncryptionKeyJWK = null;
- if (isDesktopSafari) {
- databaseEncryptionKeyJWK = await getSafariEncryptionKey();
- }
- await databaseModule.initDBForLoggedInUser(
- currentLoggedInUserID,
- databaseEncryptionKeyJWK,
- );
+ await databaseModule.initDBForLoggedInUser(currentLoggedInUserID);
}
if (!rehydrateConcluded) {

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 30, 6:48 AM (20 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2599739
Default Alt Text
D9107.id31194.diff (3 KB)

Event Timeline