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();
// Set the varibles
key.str = string;
key.str = toBuffer(string);
key.at = new Object();
key.at.rx = 0;
key.at.tx = 0;
console.log("make_encryption_key:", key.str);
// Return the key
return key;
}
@ -303,8 +305,8 @@ function connect(hostname, port=22068)
if(g.sock_new != 0)
{
// Split the data by newlines
data = JSON.parse(data.toString());
// Parse the string
data = JSON.parse(toBytes(data));
// Is this the key
if(data.mode == "encryption_key")
@ -314,6 +316,9 @@ function connect(hostname, port=22068)
mode: "decrypt",
data: data.key
}));
// Set sock new
g.sock_new = 0;
}
}
@ -322,14 +327,12 @@ function connect(hostname, port=22068)
// Decrypt the data
data = string_decrypt(g.encryption, data);
// Split the data by newlines
data = bsplit(data, Buffer.from("\n"));
// Convert it from JSON
data = JSON.parse(data);
// Iterate over them
for(var i=0;i<data.length-1;i++)
{
console.log(JSON.parse(data[i]));
}
console.log("From server:", data);
// Note to self: do something here
}
});
});
@ -372,12 +375,27 @@ function connect(hostname, port=22068)
// Set the key
g.encryption = make_encryption_key(atob(data['out']));
console.log("Sending 1:",atob(data['out']));
console.log("Sending 1:", data['out']);
// Send status
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.");
// 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
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
callback({
mode: "decrypt",
out: btoa(data)
out: data
})
}