Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.

Commit e85a4a8

Browse files
committed
Switch from argon2-browser to hash-wasm for argon2 implementation
The latest official release argon2-browser doesn't support node.js v18+ and also has some other caveats. Because of this I've used my fork of it in 74099d4 with some patches. Instead of using my patched version this commit uses hash-wasm which also includes a implementation of argon2, works correctly with node.js v18 and works fine in the browser as well.
1 parent a366c1f commit e85a4a8

File tree

4 files changed

+21
-41
lines changed

4 files changed

+21
-41
lines changed

nodecg-io-core/dashboard/esbuild.config.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ const BuildOptions = {
9090
* invalidate the build.
9191
*/
9292
watch: args.has("--watch"),
93-
// argon2-browser has some imports to fs and path that only get actually imported when running in node.js
94-
// because these code paths aren't executed we can just ignore the error that they don't exist in browser environments.
95-
// See https://github.com/antelle/argon2-browser/issues/79 and https://github.com/antelle/argon2-browser/issues/26
96-
external: ["fs", "path"],
9793
};
9894

9995
esbuild

nodecg-io-core/extension/persistenceManager.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { NodeCG, ReplicantServer } from "nodecg-types/types/server";
22
import { InstanceManager } from "./instanceManager";
33
import { BundleManager } from "./bundleManager";
44
import crypto from "crypto-js";
5-
import * as argon2 from "argon2-browser";
5+
import { argon2id } from "hash-wasm";
66
import { emptySuccess, error, Result, success } from "./utils/result";
77
import { ObjectMap, ServiceDependency, ServiceInstance } from "./service";
88
import { ServiceManager } from "./serviceManager";
@@ -108,21 +108,20 @@ export function encryptData(data: PersistentData, encryptionKey: crypto.lib.Word
108108
export async function deriveEncryptionKey(password: string, salt: string): Promise<string> {
109109
const saltBytes = Uint8Array.from(salt.match(/.{1,2}/g)?.map((byte) => parseInt(byte, 16)) ?? []);
110110

111-
const hash = await argon2.hash({
112-
pass: password,
111+
return await argon2id({
112+
password,
113113
salt: saltBytes,
114114
// OWASP reccomends either t=1,m=37MiB or t=2,m=37MiB for argon2id:
115115
// https://www.owasp.org/index.php/Password_Storage_Cheat_Sheet#Argon2id
116116
// On a Ryzen 5 5500u a single iteration is about 220 ms. Two iterations would make that about 440 ms, which is still fine.
117117
// This is run inside the browser when logging in, therefore 37 MiB is acceptable too.
118118
// To future proof this we use 37 MiB ram and 2 iterations.
119-
time: 2,
120-
mem: 37 * 1024,
121-
hashLen: 32, // Output size: 32 bytes = 256 bits as a key for AES-256
122-
type: argon2.ArgonType.Argon2id,
119+
iterations: 2,
120+
memorySize: 37, // KiB
121+
hashLength: 32, // Output size: 32 bytes = 256 bits as a key for AES-256
122+
parallelism: 1,
123+
outputType: "hex",
123124
});
124-
125-
return hash.hashHex;
126125
}
127126

128127
/**

nodecg-io-core/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
},
4545
"license": "MIT",
4646
"devDependencies": {
47-
"@types/argon2-browser": "^1.18.1",
4847
"@types/crypto-js": "^4.1.1",
4948
"@types/jest": "^28.1.6",
5049
"@types/node": "^18.0.3",
@@ -55,7 +54,7 @@
5554
},
5655
"dependencies": {
5756
"ajv": "^8.11.0",
58-
"argon2-browser": "https://github.com/daniel0611/argon2-browser/releases/download/1.19.0/argon2-browser-1.19.0.tgz",
57+
"hash-wasm": "^4.9.0",
5958
"crypto-js": "^4.1.1",
6059
"tslib": "^2.4.0"
6160
}

package-lock.json

Lines changed: 12 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)