Skip to content

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

fix: locked notes could not be unlocked

thecodrrc16c58657d60
diff --git a/apps/web/packages/nncrypto/src/decryption.ts b/apps/web/packages/nncrypto/src/decryption.ts
index 32054e53b..cebc06bab 100644
--- a/apps/web/packages/nncrypto/src/decryption.ts
+++ b/apps/web/packages/nncrypto/src/decryption.ts
@@ -23,6 +23,8 @@ export default class Decryption {
cipherData: Cipher,
outputFormat: OutputFormat = "text"
): Plaintext {
+ if (!key.salt && cipherData.salt) key.salt = cipherData.salt;
+
const encryptionKey = KeyUtils.transform(key);
let input: Uint8Array = cipherData.cipher as Uint8Array;
if (
diff --git a/apps/web/packages/nncrypto/src/keyutils.ts b/apps/web/packages/nncrypto/src/keyutils.ts
index af27c4565..60756b9c5 100644
--- a/apps/web/packages/nncrypto/src/keyutils.ts
+++ b/apps/web/packages/nncrypto/src/keyutils.ts
@@ -9,10 +9,8 @@ import {
} from "libsodium-wrappers";
import { EncryptionKey, SerializedKey } from "./types";
-type KeyCipherData = { iv: Uint8Array; cipher: Uint8Array };
-
export default class KeyUtils {
- static deriveKey(password: string, salt: string): EncryptionKey {
+ static deriveKey(password: string, salt?: string): EncryptionKey {
let saltBytes: Uint8Array;
if (!salt) saltBytes = randombytes_buf(crypto_pwhash_SALTBYTES);
else {
@@ -51,7 +49,7 @@ export default class KeyUtils {
if ("password" in input && !!input.password) {
const { password, salt } = input;
return this.deriveKey(password, salt);
- } else if ("key" in input && !!input.key) {
+ } else if ("key" in input && !!input.salt && !!input.key) {
return { key: from_base64(input.key), salt: input.salt };
}
throw new Error("Invalid input.");
diff --git a/apps/web/packages/nncrypto/src/types.ts b/apps/web/packages/nncrypto/src/types.ts
index c73dc8e93..53fdedd0c 100644
--- a/apps/web/packages/nncrypto/src/types.ts
+++ b/apps/web/packages/nncrypto/src/types.ts
@@ -19,7 +19,7 @@ export type Plaintext = {
export type SerializedKey = {
password?: string;
key?: string;
- salt: string;
+ salt?: string;
};
export type EncryptionKey = {
diff --git a/apps/web/src/components/dialogs/password-dialog.js b/apps/web/src/components/dialogs/password-dialog.js
index bbda3548f..32c89c903 100644
--- a/apps/web/src/components/dialogs/password-dialog.js
+++ b/apps/web/src/components/dialogs/password-dialog.js
@@ -17,11 +17,11 @@ function PasswordDialog(props) {
setIsLoading(true);
setError(false);
try {
- console.log(data);
if (await props.validate(data)) {
props.onDone();
} else {
setError("Wrong password.");
+ setIsLoading(false);
}
} catch (e) {
setError(e.message);