2022-12-01 18:30:34 +00:00
|
|
|
const express = require("express")
|
2022-12-15 15:33:17 +00:00
|
|
|
const body_parser = require("body-parser")
|
|
|
|
const base = require("base-64")
|
2022-12-19 20:40:43 +00:00
|
|
|
const hex = require("string-hex")
|
|
|
|
const aesjs = require("aes-js")
|
2022-12-15 15:33:17 +00:00
|
|
|
|
2022-12-01 18:30:34 +00:00
|
|
|
const app = express()
|
|
|
|
const PORT = 443
|
|
|
|
|
2022-12-15 15:33:17 +00:00
|
|
|
// express configuration
|
|
|
|
app.use(body_parser.urlencoded({
|
|
|
|
extended: true
|
|
|
|
}))
|
|
|
|
|
2022-12-19 20:40:43 +00:00
|
|
|
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
|
|
|
|
]
|
|
|
|
|
2022-12-15 15:33:17 +00:00
|
|
|
// Backend - Routes
|
|
|
|
|
|
|
|
// API - Routes
|
|
|
|
app.post("/client-fetch-keys", (req, res) => { // client sends here the keys
|
2022-12-19 20:40:43 +00:00
|
|
|
let keys = req.body.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);
|
2022-12-15 15:33:17 +00:00
|
|
|
|
2022-12-19 20:40:43 +00:00
|
|
|
console.log(decrypted_text);
|
2022-12-01 18:30:34 +00:00
|
|
|
|
2022-12-15 15:33:17 +00:00
|
|
|
res.send("PIVOTER_OK\n");
|
2022-12-01 18:30:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
app.listen(PORT)
|