Experimental: replace OpenSSL RC4 functions with pure JS ('npm install' required)

This commit is contained in:
zefie
2023-08-26 13:59:47 -04:00
parent 67ac8ec29d
commit c9f78b1e3b
3 changed files with 22 additions and 15 deletions

View File

@@ -1,5 +1,6 @@
const CryptoJS = require('crypto-js');
const endianness = require('endianness');
var RC4 = require('rc4-crypto');
var crypto = require('crypto');
/**
@@ -296,7 +297,7 @@ class WTVSec {
/**
* Starts an encryption session
* @param {Number} rc4session Session Type (0 = enc k1, 1 = dec k1, 3 = enc k2, 4 = dec k2, default: all)
* @param {Number} rc4session Session Type (0 = enc k1, 1 = dec k1, 2 = enc k2, 3 = dec k2, default: all)
*
*/
SecureOn(rc4session = null) {
@@ -310,22 +311,22 @@ class WTVSec {
var key2 = this.wordArrayToBuffer(this.hRC4_Key2);
switch (rc4session) {
case 0:
this.RC4Session[0] = crypto.createCipheriv('rc4', key1,'');
this.RC4Session[0] = new RC4.RC4(key1);
break;
case 1:
this.RC4Session[1] = crypto.createDecipheriv('rc4', key1,'');
this.RC4Session[1] = new RC4.RC4(key1);
break;
case 2:
this.RC4Session[2] = crypto.createCipheriv('rc4', key2,'');
this.RC4Session[2] = new RC4.RC4(key2);
break;
case 3:
this.RC4Session[3] = crypto.createDecipheriv('rc4', key2,'');
this.RC4Session[3] = new RC4.RC4(key2);
break;
default:
this.RC4Session[0] = crypto.createCipheriv('rc4', key1, '');
this.RC4Session[1] = crypto.createDecipheriv('rc4', key1, '');
this.RC4Session[2] = crypto.createCipheriv('rc4', key2, '');
this.RC4Session[3] = crypto.createDecipheriv('rc4', key2, '');
this.RC4Session[0] = new RC4.RC4(key1);
this.RC4Session[1] = new RC4.RC4(key1);
this.RC4Session[2] = new RC4.RC4(key2);
this.RC4Session[3] = new RC4.RC4(key2);
break;
}
}
@@ -355,10 +356,10 @@ class WTVSec {
}
if (data.words) {
data = this.wordArrayToBuffer(data);
} else if (data.constructor === ArrayBuffer) {
} else if (data.constructor === ArrayBuffer || typeof data == 'string') {
data = new Buffer.from(data);
}
return this.RC4Session[session_id].update(data);
return this.RC4Session[session_id].updateFromBuffer(data);
}
/**
@@ -386,10 +387,10 @@ class WTVSec {
}
if (data.words) {
data = this.wordArrayToBuffer(data);
} else if (data.constructor === ArrayBuffer) {
} else if (data.constructor === ArrayBuffer || typeof data == 'string') {
data = new Buffer.from(data);
}
return this.RC4Session[session_id].update(data);
return this.RC4Session[session_id].updateFromBuffer(data);
}
}

View File

@@ -22,6 +22,7 @@
"newsie": "^1.2.1",
"nntp-server-zefie": "^3.1.0",
"proxy-agent": "^6.3.0",
"rc4-crypto": "^1.5.0",
"sanitize-html": "^2.11.0",
"socks-proxy-agent": "^8.0.1",
"strftime": "^0.10.2",
@@ -1155,6 +1156,11 @@
"node": ">=0.10.0"
}
},
"node_modules/rc4-crypto": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/rc4-crypto/-/rc4-crypto-1.5.0.tgz",
"integrity": "sha512-0auP5EfZ21/RP437NgmH+eCTgwDGA611KYCU/2ywk1aIUhR1rHToI4z3ZtQ9BRZYw44M9htklIZK5khkBJerAw=="
},
"node_modules/safe-buffer": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",

View File

@@ -6,8 +6,7 @@
"homepage": "https://github.com/zefie/zefie_wtvp_minisrv",
"license": "GPL3",
"scripts": {
"start": "node --openssl-legacy-provider app.js",
"start16": "node app.js",
"start": "node app.js",
"test": "node test.js"
},
"author": {
@@ -40,6 +39,7 @@
"newsie": "^1.2.1",
"nntp-server-zefie": "^3.1.0",
"proxy-agent": "^6.3.0",
"rc4-crypto": "^1.5.0",
"sanitize-html": "^2.11.0",
"socks-proxy-agent": "^8.0.1",
"strftime": "^0.10.2",