@@ -3,9 +3,12 @@ require("dotenv").config();
33const cors = require ( "cors" ) ;
44const ftp = require ( "basic-ftp" ) ;
55const CryptoJS = require ( "crypto-js" ) ;
6+ var SimpleCrypto = require ( "simple-crypto-js" ) . default ;
67
78const PORT = process . env . PORT || 3000 ;
89
10+ // playground end
11+
912const app = express ( ) ;
1013app . use ( express . json ( ) ) ; // for parsing application/json
1114app . use ( cors ( ) ) ;
@@ -25,22 +28,17 @@ const clients = {};
2528// basic-ftp
2629
2730app . post ( "/navigate" , ( req , res ) => {
28- if ( req . body && req . body . ciphertext ) {
31+ if ( req . body && req . body . cipherText ) {
2932 init ( ) ;
3033
3134 async function init ( ) {
32- const { ciphertext } = req . body ;
33- // decrypt data received from frontend
34- console . log ( "Ciphertext:" , ciphertext ) ;
35- const bytes = CryptoJS . AES . decrypt ( ciphertext , process . env . PASSWORD ) ;
36- console . log ( "Bytes:" , bytes ) ;
37-
38- console . log ( "CryptoJS keys:" , Object . keys ( CryptoJS ) . length ) ;
39- console . log ( "Decrypteddata:" , bytes . toString ( CryptoJS . enc . Utf8 ) ) ;
35+ const { cipherText } = req . body ;
4036
41- var decryptedData = JSON . parse ( bytes . toString ( CryptoJS . enc . Utf8 ) ) ;
37+ // decrypt data received from frontend
38+ var simpleCrypto = new SimpleCrypto ( process . env . PASSWORD ) ;
39+ var decipherText = simpleCrypto . decrypt ( cipherText ) ;
4240
43- const { ftpHost, ftpUser, ftpPassword, path } = decryptedData ;
41+ const { ftpHost, ftpUser, ftpPassword, path } = JSON . parse ( decipherText ) ;
4442
4543 // if user is found and logged in
4644 if (
@@ -97,20 +95,19 @@ app.post("/navigate", (req, res) => {
9795
9896// removes and disconnects client
9997app . post ( "/disconnect" , ( req , res ) => {
100- if ( req . body && req . body . ciphertext ) {
98+ if ( req . body && req . body . cipherText ) {
10199 } else {
102100 res . status ( 400 ) . send ( "Unauthorized access." ) ;
103101 }
104102
105103 const init = async ( ) => {
106- const { ciphertext } = req . body ;
104+ const { cipherText } = req . body ;
107105
108106 // decrypt data received from frontend
109- const bytes = CryptoJS . AES . decrypt ( ciphertext , process . env . PASSWORD ) ;
110-
111- var decryptedData = JSON . parse ( bytes . toString ( CryptoJS . enc . Utf8 ) ) ;
107+ var simpleCrypto = new SimpleCrypto ( process . env . PASSWORD ) ;
108+ var decipherText = simpleCrypto . decrypt ( cipherText ) ;
112109
113- const { ftpUser } = decryptedData ;
110+ const { ftpUser } = JSON . parse ( decipherText ) ;
114111
115112 if (
116113 clients [ ftpUser ] !== undefined &&
0 commit comments