Got stable, functional, reliable connection between the server. Fixed issues with JavaScript strings.

This commit is contained in:
jsrobson10 2019-04-09 21:03:05 +10:00
parent 6447085c29
commit 66e0db11bd
2 changed files with 33 additions and 13 deletions

View File

@ -191,11 +191,13 @@ function make_encryption_key(string)
var key = new Object(); var key = new Object();
// Set the varibles // Set the varibles
key.str = string; key.str = toBuffer(string);
key.at = new Object(); key.at = new Object();
key.at.rx = 0; key.at.rx = 0;
key.at.tx = 0; key.at.tx = 0;
console.log("make_encryption_key:", key.str);
// Return the key // Return the key
return key; return key;
} }
@ -303,8 +305,8 @@ function connect(hostname, port=22068)
if(g.sock_new != 0) if(g.sock_new != 0)
{ {
// Split the data by newlines // Parse the string
data = JSON.parse(data.toString()); data = JSON.parse(toBytes(data));
// Is this the key // Is this the key
if(data.mode == "encryption_key") if(data.mode == "encryption_key")
@ -314,6 +316,9 @@ function connect(hostname, port=22068)
mode: "decrypt", mode: "decrypt",
data: data.key data: data.key
})); }));
// Set sock new
g.sock_new = 0;
} }
} }
@ -322,14 +327,12 @@ function connect(hostname, port=22068)
// Decrypt the data // Decrypt the data
data = string_decrypt(g.encryption, data); data = string_decrypt(g.encryption, data);
// Split the data by newlines // Convert it from JSON
data = bsplit(data, Buffer.from("\n")); data = JSON.parse(data);
// Iterate over them console.log("From server:", data);
for(var i=0;i<data.length-1;i++)
{ // Note to self: do something here
console.log(JSON.parse(data[i]));
}
} }
}); });
}); });
@ -372,12 +375,27 @@ function connect(hostname, port=22068)
// Set the key // Set the key
g.encryption = make_encryption_key(atob(data['out'])); g.encryption = make_encryption_key(atob(data['out']));
console.log("Sending 1:",atob(data['out'])); console.log("Sending 1:", data['out']);
// Send status // Send status
socket_write(client, g.encryption, 1); socket_write(client, g.encryption, 1);
socket_write(client, g.encryption, {
mode: "Hello",
text: "This is from the client!",
array: [
[1, 2, 3],
{4: 5, 6: "7"},
"8",
9,
true,
false,
],
});
console.log("Done."); console.log("Done.");
// Perform initialise operations here
} }
}); });

6
rsa.js
View File

@ -68,12 +68,14 @@ process.on('message', function(message)
{ {
// Decrypt the data with the RSA key // Decrypt the data with the RSA key
console.log(args['data']); console.log(args['data']);
var data = rsa_key.decrypt(args['data'], 'utf-8'); var data = rsa_key.decrypt(args['data'], 'base64');
console.log("Decoded:",data)
// Send the data back // Send the data back
callback({ callback({
mode: "decrypt", mode: "decrypt",
out: btoa(data) out: data
}) })
} }