Route ClientFetchKeys: Add AES support

This commit is contained in:
osamu-kj 2022-12-19 15:40:43 -05:00
parent 592a2beca1
commit 43e2742387
3 changed files with 71 additions and 5 deletions

View File

@ -1,7 +1,8 @@
const express = require("express")
const body_parser = require("body-parser")
const base = require("base-64")
const hex = require("string-hex")
const aesjs = require("aes-js")
const app = express()
const PORT = 443
@ -11,13 +12,37 @@ app.use(body_parser.urlencoded({
extended: true
}))
function hex_to_bytes(hex) {
for (var bytes = [], c = 0; c < hex.length; c += 2)
bytes.push(parseInt(hex.substr(c, 2), 16));
return bytes;
}
// aes configuration
const iv = [
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
]
const key = [
0x6B, 0x28, 0x31, 0x33, 0x23, 0x21, 0x31, 0x39,
0x21, 0x4C, 0x6C, 0x34, 0x24, 0x31, 0x22, 0x39
]
// Backend - Routes
// API - Routes
app.post("/client-fetch-keys", (req, res) => { // client sends here the keys
let keys = req.body.keys
console.log(base.decode(keys));
keys = keys.substring(0, keys.length-2);
let aes_cbc = new aesjs.ModeOfOperation.cbc(key, iv);
let encrypted_bytes = aesjs.utils.hex.toBytes(keys)
let decrypted_bytes = aes_cbc.decrypt(encrypted_bytes);
let decrypted_text = aesjs.utils.utf8.fromBytes(decrypted_bytes);
console.log(decrypted_text);
res.send("PIVOTER_OK\n");
})

View File

@ -9,9 +9,14 @@
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"aes-cross": "^1.1.2",
"aes-encryption": "^1.0.4",
"aes-js": "^3.1.2",
"base-64": "^1.0.0",
"crypto-js": "^4.1.1",
"express": "^4.18.2",
"mongodb": "^4.12.1"
"mongodb": "^4.12.1",
"string-hex": "^1.0.0"
}
},
"node_modules/@aws-crypto/ie11-detection": {
@ -1089,6 +1094,24 @@
"node": ">= 0.6"
}
},
"node_modules/aes-cross": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/aes-cross/-/aes-cross-1.1.2.tgz",
"integrity": "sha512-gkt2o9FvkWcnRUQiLyE9LDs2pOpkeqojle4sQ8PS1+fpB/qrSGaPZ24xqFeHYEiLTkLMSBJ9Bhrm+jNNo/blDQ=="
},
"node_modules/aes-encryption": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/aes-encryption/-/aes-encryption-1.0.4.tgz",
"integrity": "sha512-Mb3UAbIvY0wiK6GjZGolVLXvIRHukUoSUQOOItjHNGuEWuClSsBPWEMdLYbCPuIKIFF5YkHTtWT+VqbLIQK/Og==",
"engines": {
"node": ">= 0.10.0"
}
},
"node_modules/aes-js": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/aes-js/-/aes-js-3.1.2.tgz",
"integrity": "sha512-e5pEa2kBnBOgR4Y/p20pskXI74UEz7de8ZGVo58asOtvSVG5YAbJeELPZxOmt+Bnz3rX753YKhfIn4X4l1PPRQ=="
},
"node_modules/array-flatten": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
@ -1233,6 +1256,11 @@
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
"integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ=="
},
"node_modules/crypto-js": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.1.1.tgz",
"integrity": "sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw=="
},
"node_modules/debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
@ -1796,6 +1824,14 @@
"node": ">= 0.8"
}
},
"node_modules/string-hex": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/string-hex/-/string-hex-1.0.0.tgz",
"integrity": "sha512-BVj+jcFkid8p2hDu96wRks4U3Dz/OfPnNR4vmABQqVIZgeSRAXYB5/zGrYT/8QhGhcEi/fMnjtLDz0rcJ5pEIQ==",
"engines": {
"node": ">= 8.9.4"
}
},
"node_modules/strnum": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/strnum/-/strnum-1.0.5.tgz",

View File

@ -10,8 +10,13 @@
"author": "osamu-kj",
"license": "ISC",
"dependencies": {
"aes-cross": "^1.1.2",
"aes-encryption": "^1.0.4",
"aes-js": "^3.1.2",
"base-64": "^1.0.0",
"crypto-js": "^4.1.1",
"express": "^4.18.2",
"mongodb": "^4.12.1"
"mongodb": "^4.12.1",
"string-hex": "^1.0.0"
}
}