diff --git a/monkey-patch-crypto.js b/monkey-patch-crypto.js new file mode 100644 index 00000000..aacb5554 --- /dev/null +++ b/monkey-patch-crypto.js @@ -0,0 +1,33 @@ +/** + * Copyright (c) 2022 BlockDev AG + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +// eslint-disable-next-line @typescript-eslint/no-var-requires +const crypto = require("crypto") + +/** + * @see {@link https://stackoverflow.com/a/72219174} + */ +let cryptoPatched = false +const monkeyPatchCrypto = () => { + if (cryptoPatched) return + cryptoPatched = true + + /** + * The MD4 algorithm is not available anymore in Node.js 17+ (because of library SSL 3). + * In that case, silently replace MD4 by the MD5 algorithm. + */ + try { + crypto.createHash("md4") + } catch (e) { + console.warn('Crypto "MD4" is not supported anymore by this Node.js version') + const origCreateHash = crypto.createHash + crypto.createHash = (alg, opts) => { + return origCreateHash(alg === "md4" ? "md5" : alg, opts) + } + } +} + +monkeyPatchCrypto() diff --git a/package.json b/package.json index 3d77e7f8..41dee8b9 100644 --- a/package.json +++ b/package.json @@ -84,6 +84,7 @@ "@typescript-eslint/eslint-plugin": "^5.23.0", "@typescript-eslint/parser": "^5.23.0", "chmodr": "^1.2.0", + "cross-env": "^7.0.3", "electron": "^20.1.2", "electron-builder": "^23.3.3", "electron-devtools-installer": "^3.2.0", @@ -115,6 +116,9 @@ "sourceDirectory": "src/app", "template": "src/app/index.html", "webpackConfig": "webpack.renderer.additions.js" + }, + "main": { + "webpackConfig": "webpack.main.additions.js" } }, "build": { diff --git a/webpack.main.additions.js b/webpack.main.additions.js new file mode 100644 index 00000000..0185800c --- /dev/null +++ b/webpack.main.additions.js @@ -0,0 +1,7 @@ +/** + * Copyright (c) 2022 BlockDev AG + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +require("./monkey-patch-crypto.js") diff --git a/webpack.renderer.additions.js b/webpack.renderer.additions.js index 528c69b4..2dca4482 100644 --- a/webpack.renderer.additions.js +++ b/webpack.renderer.additions.js @@ -7,3 +7,5 @@ module.exports = { externals: ["react", "react-dom"], } + +require("./monkey-patch-crypto.js") diff --git a/yarn.lock b/yarn.lock index ecd089ed..e39ded98 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3148,6 +3148,13 @@ crocket@^0.9.11: dependencies: xpipe "*" +cross-env@^7.0.3: + version "7.0.3" + resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.3.tgz#865264b29677dc015ba8418918965dd232fc54cf" + integrity sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw== + dependencies: + cross-spawn "^7.0.1" + cross-spawn@6.0.5, cross-spawn@^6.0.0: version "6.0.5" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4"