From 159f527d9ae0aa23044417bcb0ecff447a54d456 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Sun, 25 Jul 2021 13:22:17 +0200 Subject: [PATCH] Added Blowfish decryption fallback --- deemix/utils/crypto.js | 19 ++++++++++++++++--- package.json | 1 + yarn.lock | 5 +++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/deemix/utils/crypto.js b/deemix/utils/crypto.js index 195898a..d76fa78 100644 --- a/deemix/utils/crypto.js +++ b/deemix/utils/crypto.js @@ -1,4 +1,8 @@ const crypto = require('crypto') +let Blowfish +try { + Blowfish = require('egoroof-blowfish') +} catch (e) { /* empty */ } function _md5 (data, type = 'binary') { let md5sum = crypto.createHash('md5') @@ -29,9 +33,18 @@ function generateBlowfishKey(trackId) { } function decryptChunk(chunk, blowFishKey){ - var cipher = crypto.createDecipheriv('bf-cbc', blowFishKey, Buffer.from([0, 1, 2, 3, 4, 5, 6, 7])) - cipher.setAutoPadding(false) - return Buffer.concat([cipher.update(chunk), cipher.final()]) + let ciphers = crypto.getCiphers() + if (ciphers.includes('bf-cbc')){ + let cipher = crypto.createDecipheriv('bf-cbc', blowFishKey, Buffer.from([0, 1, 2, 3, 4, 5, 6, 7])) + cipher.setAutoPadding(false) + return Buffer.concat([cipher.update(chunk), cipher.final()]) + } + if (Blowfish){ + let cipher = new Blowfish(blowFishKey, Blowfish.MODE.CBC, Blowfish.PADDING.NULL) + cipher.setIv(Buffer.from([0, 1, 2, 3, 4, 5, 6, 7])) + return Buffer.from(cipher.decode(chunk, Blowfish.TYPE.UINT8_ARRAY)) + } + throw new Error("Can't find a way to decrypt chunks") } module.exports = { diff --git a/package.json b/package.json index 528a43d..5be378f 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "async": "^3.2.0", "crypto": "^1.0.1", "deezer-js": "^1.0.2", + "egoroof-blowfish": "^2.2.2", "got": "^11.8.2", "metaflac-js2": "^1.0.7", "spotify-web-api-node": "^5.0.2" diff --git a/yarn.lock b/yarn.lock index 7f02cd6..3f5d801 100644 --- a/yarn.lock +++ b/yarn.lock @@ -403,6 +403,11 @@ ecc-jsbn@~0.1.1: jsbn "~0.1.0" safer-buffer "^2.1.0" +egoroof-blowfish@^2.2.2: + version "2.2.2" + resolved "https://registry.yarnpkg.com/egoroof-blowfish/-/egoroof-blowfish-2.2.2.tgz#d9ad386a8d2f8ddb55f2f7ff00341fc7565f9222" + integrity sha512-J2YRdTmgeebSiLB/WN2p5shat6eCnc7L/fM5SX9E8Yi0HGBWHcE6lQnHVCoXmkUflIwFU2j1/XcERYBdilMECA== + emoji-regex@^8.0.0: version "8.0.0" resolved "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz"