From 4aef3c63204f7c8fa470301428f52b0307a7d2a7 Mon Sep 17 00:00:00 2001 From: pathmapper Date: Sat, 1 Jan 2022 12:51:24 +0100 Subject: [PATCH 1/4] Use md5 hashing for OpenSSL 3 --- src/cache.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cache.js b/src/cache.js index 35e78819..fed60a54 100644 --- a/src/cache.js +++ b/src/cache.js @@ -63,10 +63,10 @@ const write = async function (filename, compress, result) { * @return {String} */ const filename = function (source, identifier, options) { - // md4 hashing is not supported starting with node v17.0.0 - const majorNodeVersion = parseInt(process.versions.node.split(".")[0], 10); + // md4 hashing is not supported starting with OpenSSL v3.0.0 + const majorOpensslVersion = parseInt(process.versions.openssl.split(".")[0], 10); let hashType = "md4"; - if (majorNodeVersion >= 17) { + if (majorOpensslVersion >= 3) { hashType = "md5"; } From 1461df80b5e009bce8c9497cc681e091b602de89 Mon Sep 17 00:00:00 2001 From: pathmapper Date: Sat, 1 Jan 2022 13:59:38 +0100 Subject: [PATCH 2/4] Fix lint --- src/cache.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cache.js b/src/cache.js index fed60a54..6757cbff 100644 --- a/src/cache.js +++ b/src/cache.js @@ -64,7 +64,10 @@ const write = async function (filename, compress, result) { */ const filename = function (source, identifier, options) { // md4 hashing is not supported starting with OpenSSL v3.0.0 - const majorOpensslVersion = parseInt(process.versions.openssl.split(".")[0], 10); + const majorOpensslVersion = parseInt( + process.versions.openssl.split(".")[0], + 10, + ); let hashType = "md4"; if (majorOpensslVersion >= 3) { hashType = "md5"; From ba921159211569c040b011336aba3b3bcfeec363 Mon Sep 17 00:00:00 2001 From: pathmapper Date: Sat, 1 Jan 2022 17:47:43 +0100 Subject: [PATCH 3/4] Use 'md5' hashing if 'md4' could not be created --- src/cache.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/cache.js b/src/cache.js index 6757cbff..9a59e461 100644 --- a/src/cache.js +++ b/src/cache.js @@ -63,13 +63,11 @@ const write = async function (filename, compress, result) { * @return {String} */ const filename = function (source, identifier, options) { - // md4 hashing is not supported starting with OpenSSL v3.0.0 - const majorOpensslVersion = parseInt( - process.versions.openssl.split(".")[0], - 10, - ); let hashType = "md4"; - if (majorOpensslVersion >= 3) { + + try { + crypto.createHash(hashType); + } catch (err) { hashType = "md5"; } From e8e5932594cbe1e35b6408bd609800570f026e31 Mon Sep 17 00:00:00 2001 From: pathmapper Date: Fri, 7 Jan 2022 07:11:30 +0100 Subject: [PATCH 4/4] Move hash detection to top level --- src/cache.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cache.js b/src/cache.js index 9a59e461..29482924 100644 --- a/src/cache.js +++ b/src/cache.js @@ -19,6 +19,14 @@ const transform = require("./transform"); // Lazily instantiated when needed let defaultCacheDirectory = null; +let hashType = "md4"; +// use md5 hashing if md4 is not available +try { + crypto.createHash(hashType); +} catch (err) { + hashType = "md5"; +} + const readFile = promisify(fs.readFile); const writeFile = promisify(fs.writeFile); const gunzip = promisify(zlib.gunzip); @@ -63,14 +71,6 @@ const write = async function (filename, compress, result) { * @return {String} */ const filename = function (source, identifier, options) { - let hashType = "md4"; - - try { - crypto.createHash(hashType); - } catch (err) { - hashType = "md5"; - } - const hash = crypto.createHash(hashType); const contents = JSON.stringify({ source, options, identifier });