A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
feat: hash passwords client-side
thecodrr6501ea8ffc63
diff --git a/apps/web/public/crypto.worker.js b/apps/web/public/crypto.worker.jsindex 381d53b5c..a073459df 100644--- a/apps/web/public/crypto.worker.js+++ b/apps/web/public/crypto.worker.js@@ -28,6 +28,12 @@ function onMessage(ev) {sendMessage("deriveKey", derivedKey, messageId);break;}+ case "hashPassword": {+ const { password, userId } = data;+ const hashedPassword = hashPassword.call(context, password, userId);+ sendMessage("hashPassword", hashedPassword, messageId);+ break;+ }case "load": {const { seed } = data;self.sodium = {@@ -80,6 +86,26 @@ const deriveKey = (password, salt, exportKey = false) => {return { key, salt: saltHex };};+const hashPassword = (password, userId) => {+ const { sodium } = this;++ const appSalt = "oVzKtazBo7d8sb7TBvY9jw";+ const salt = sodium.crypto_generichash(+ sodium.crypto_pwhash_SALTBYTES,+ `${appSalt}${userId}`+ );+ const hash = sodium.crypto_pwhash(+ 32,+ password,+ salt,+ 3, // operations limit+ 1024 * 1024 * 64, // memory limit (8MB)+ sodium.crypto_pwhash_ALG_ARGON2ID13,+ "base64"+ );+ return hash;+};+const _getKey = (passwordOrKey) => {const { sodium } = this;diff --git a/apps/web/src/common/index.js b/apps/web/src/common/index.jsindex 63f9ea49d..d83f81445 100644--- a/apps/web/src/common/index.js+++ b/apps/web/src/common/index.js@@ -13,18 +13,18 @@ import { hashNavigate } from "../navigation";export const db = new Database(StorageInterface, EventSource);-db.host({- API_HOST: "https://api.notesnook.com",- AUTH_HOST: "https://auth.streetwriters.co",- SSE_HOST: "https://events.streetwriters.co",-});-// db.host({-// API_HOST: "http://localhost:5264",-// AUTH_HOST: "http://localhost:8264",-// SSE_HOST: "http://localhost:7264",+// API_HOST: "https://api.notesnook.com",+// AUTH_HOST: "https://auth.streetwriters.co",+// SSE_HOST: "https://events.streetwriters.co",// });+db.host({+ API_HOST: "http://localhost:5264",+ AUTH_HOST: "http://localhost:8264",+ SSE_HOST: "http://localhost:7264",+});+// db.host({// API_HOST: "http://192.168.10.8:5264",// AUTH_HOST: "http://192.168.10.8:8264",diff --git a/apps/web/src/interfaces/crypto.js b/apps/web/src/interfaces/crypto.jsindex c3e2aafbb..0cea7b3d2 100644--- a/apps/web/src/interfaces/crypto.js+++ b/apps/web/src/interfaces/crypto.js@@ -42,6 +42,11 @@ class Crypto {await this._initialize();return global.ncrypto.deriveKey.call(this, password, salt, exportKey);};++ hashPassword = async (password, userId) => {+ await this._initialize();+ return global.ncrypto.hashPassword.call(this, password, userId);+ };}class CryptoWorker {@@ -129,6 +134,10 @@ class CryptoWorker {deriveKey = (password, salt, exportKey = false) => {return this._communicate("deriveKey", { password, salt, exportKey });};++ hashPassword = (password, userId) => {+ return this._communicate("hashPassword", { password, userId });+ };}const NCrypto =diff --git a/apps/web/src/interfaces/storage.js b/apps/web/src/interfaces/storage.jsindex 466960221..dc5ea1c63 100644--- a/apps/web/src/interfaces/storage.js+++ b/apps/web/src/interfaces/storage.js@@ -73,6 +73,7 @@ export default {getAllKeys,deriveCryptoKey,getCryptoKey,+ hash: crypto.hashPassword,encrypt: crypto.encrypt,decrypt: crypto.decrypt,};diff --git a/apps/web/yarn.lock b/apps/web/yarn.lockindex af7c592e4..d2c2be5d5 100644--- a/apps/web/yarn.lock+++ b/apps/web/yarn.lock@@ -8999,9 +8999,21 @@ normalize-url@^3.0.0, normalize-url@^3.0.1:resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-3.3.0.tgz#b2e1c4dc4f7c6d57743df733a4f5978d18650559"integrity sha512-U+JJi7duF1o+u2pynbp2zXDW2/PADgC30f0GsHZtRh+HOcXHnw137TrNlyxxRvWW5fjKd3bcLHPxofWuCjaeZg==+notes-core@../notes-core:+ version "5.4.1"+ dependencies:+ fast-sort "^2.0.1"+ fuzzysearch "^1.0.3"+ jshashes "^1.0.8"+ no-internet "^1.5.2"+ qclone "^1.0.4"+ quill-delta-to-html "^0.12.0"+ quill-delta-to-markdown "https://github.com/streetwriters/quill-delta-to-markdown"+ transfun "^1.0.2"+"notes-core@git+ssh://[email protected]:streetwriters/notesnook-core.git":version "5.4.1"- resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#2ae486038a4f81bc359024941b44ba9b3e5c882a"+ resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#41ce0e95476b25a7c84c13eaa29aa34e371318f5"dependencies:fast-sort "^2.0.1"fuzzysearch "^1.0.3"