Added Blowfish decryption fallback

This commit is contained in:
RemixDev 2021-07-25 13:22:17 +02:00
parent 4c935fa2e3
commit 159f527d9a
3 changed files with 22 additions and 3 deletions

View file

@ -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 = {

View file

@ -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"

View file

@ -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"