Simple to use request->response based encrypted networking API that uses rednet

Started by ShreksHellraiser, Jun 19, 2022, 07:32 PM

Previous topic - Next topic

ShreksHellraiser

This is an API to make encrypted communication and protocols over rednet easy.

Here's all it takes for a simple ping protocol
Client:
local client = require("client")

local a = client.new("encping") -- Make a client object for protocol "encping"
local b,c = a:sendReq({"hello world!"}) -- Send a table that just contains "Hello world!" at [1]
print(b,textutils.serialize(c)) -- Print out the reply we got!

Server:
local server = require("server")

local srv = server.new("encping", "testserver") -- Make a server object for protocol "encping" with hostname "testserver"

local function handleMessage(self, id, msg) -- This is the message handler function, when the server recieves an encrypted message it'll pass it in here along with the rednet ID of the computer.
  self:sendEncryptedMessage(id, msg) -- Just send the message straight back
end

srv.msgHandle = handleMessage -- Set our handleMessage function as the message handler for this server object
srv:start() -- Start the server

There's a lot more detail about how the protocol works in readme.md on my github page.

https://github.com/MasonGulu/cc-rednet-encrypt

But it basically works with the client sending a request to the server and the server sending a request back, these are both encrypted through the use of this ECC api. Before any encrypted communication can occur, my API will perform a public key exchange with the server to establish a common key on both ends. This API also timestamps and puts a UUID in every message sent, discarding any messages that are too old, or contain the same UUID, this acts as a protection against replay attacks. Currently the main attack vector I can think about would be a DOS attack by instantly sending responses claiming to be errors.