Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

mobile: fix encryption key not found error on login

Ammar Ahmed096602150e46
diff --git a/apps/mobile/app/common/database/encryption.js b/apps/mobile/app/common/database/encryption.js
index 794701e60..8456b0588 100644
--- a/apps/mobile/app/common/database/encryption.js
+++ b/apps/mobile/app/common/database/encryption.js
@@ -232,7 +232,8 @@ export async function deriveCryptoKey(data) {
let credentials = await Sodium.deriveKey(data.password, data.salt);
const userKeyCipher = await encrypt(
{
- key: await getDatabaseKey()
+ key: await getDatabaseKey(),
+ salt: NOTESNOOK_DB_KEY_SALT
},
credentials.key
);
@@ -257,13 +258,12 @@ export async function getCryptoKey(_name) {
const key = await decrypt(
{
- key: await getDatabaseKey()
+ key: await getDatabaseKey(),
+ salt: keyCipher.salt
},
keyCipher
);
- DatabaseLogger.info("User key decrypted: ", !!key);
-
return key;
} catch (e) {
console.log("getCryptoKey", e);
diff --git a/apps/mobile/app/components/auth/session-expired.js b/apps/mobile/app/components/auth/session-expired.js
index 7c81d8d4c..6b2d0ee00 100644
--- a/apps/mobile/app/components/auth/session-expired.js
+++ b/apps/mobile/app/components/auth/session-expired.js
@@ -112,6 +112,10 @@ export const SessionExpired = () => {
if (!res) throw new Error("no token found");
if (db.tokenManager._isTokenExpired(res))
throw new Error("token expired");
+
+ const key = await db.user.getEncryptionKey();
+ if (!key) throw new Error("No encryption key found.");
+
Sync.run("global", false, "full", async (complete) => {
if (!complete) {
let user = await db.user.getUser();
@@ -127,7 +131,6 @@ export const SessionExpired = () => {
setVisible(false);
});
} catch (e) {
- console.log(e);
let user = await db.user.getUser();
if (!user) return;
email.current = user.email;