Page MenuHomePhabricator

D8118.diff
No OneTemporary

D8118.diff

diff --git a/web/database/utils/worker-crypto-utils.js b/web/database/utils/worker-crypto-utils.js
--- a/web/database/utils/worker-crypto-utils.js
+++ b/web/database/utils/worker-crypto-utils.js
@@ -7,13 +7,17 @@
+ciphertext: Uint8Array,
};
-function generateDatabaseCryptoKey(): Promise<CryptoKey> {
+function generateDatabaseCryptoKey({
+ extractable,
+}: {
+ +extractable: boolean,
+}): Promise<CryptoKey> {
return crypto.subtle.generateKey(
{
name: ENCRYPTION_ALGORITHM,
length: 256,
},
- false,
+ extractable,
['encrypt', 'decrypt'],
);
}
diff --git a/web/database/utils/worker-crypto-utlis.test.js b/web/database/utils/worker-crypto-utlis.test.js
--- a/web/database/utils/worker-crypto-utlis.test.js
+++ b/web/database/utils/worker-crypto-utlis.test.js
@@ -36,7 +36,7 @@
database = new SQL.Database();
setUpMockDb(database);
- cryptoKey = await generateDatabaseCryptoKey();
+ cryptoKey = await generateDatabaseCryptoKey({ extractable: false });
});
it('should encrypt database content', async () => {
@@ -57,7 +57,9 @@
const dbContent: Uint8Array = database.export();
const encryptedData = await encryptDatabaseFile(dbContent, cryptoKey);
- const newCryptoKey = await generateDatabaseCryptoKey();
+ const newCryptoKey = await generateDatabaseCryptoKey({
+ extractable: false,
+ });
expect(decryptDatabaseFile(encryptedData, newCryptoKey)).rejects.toThrow();
});
diff --git a/web/database/worker/db-worker.js b/web/database/worker/db-worker.js
--- a/web/database/worker/db-worker.js
+++ b/web/database/worker/db-worker.js
@@ -61,7 +61,7 @@
async function initDatabase(sqljsFilePath: string, sqljsFilename: ?string) {
encryptionKey = await localforage.getItem(SQLITE_ENCRYPTION_KEY);
if (!encryptionKey) {
- const cryptoKey = await generateDatabaseCryptoKey();
+ const cryptoKey = await generateDatabaseCryptoKey({ extractable: false });
await localforage.setItem(SQLITE_ENCRYPTION_KEY, cryptoKey);
}
@@ -191,7 +191,7 @@
} else if (
message.type === workerRequestMessageTypes.GENERATE_DATABASE_ENCRYPTION_KEY
) {
- const cryptoKey = await generateDatabaseCryptoKey();
+ const cryptoKey = await generateDatabaseCryptoKey({ extractable: false });
await localforage.setItem(SQLITE_ENCRYPTION_KEY, cryptoKey);
return undefined;
}

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 6:51 AM (20 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2574351
Default Alt Text
D8118.diff (2 KB)

Event Timeline