This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
eat4fun's profile picture

Remote Authenticated Access Card

Started by eat4fun, 01 August 2012 - 12:46 AM
eat4fun #1
Posted 01 August 2012 - 02:46 AM
First post – thought I’d share a script I wrote a while ago. The script’s goal is to make complex security systems more robust and scalable.

Let’s say that you have a single room that you want to secure. Of course, the most obvious solution is to simply put a password on the machine. The problem with this, however, is that anybody with the password can get in (it’s easily shared), and that if the password needs to be changed, the admin would have to change the password on the terminal’s hard drive. Of course this is no problem on a small install.

But let’s say you have five doors that you want to secure, and a number of users, each needing access to different doors. I came up with a solution that I think is ideal in this situation.

It works in three parts: the first is the disk which each user holds in their inventory containing a password unique to that user, the second is the client (installed on the terminal near to the door) which reads a code off of the user’s disk and verifies it remotely, and the server which provides the verification.

In normal operation, the system will work as follows: the user’s code is read from their disk, this code is sent from the client to the server via rednet, the server checks for the user’s code on a list corresponding to the ID of the client terminal, the server responds with either a yes or no, the client then either spits back an error or allows the user through the door.


Client

local server = 41
local opentime = 2
local output = "bottom"
local diskside = "left"
local rednetside = "top"

rednet.open(rednetside)

while true do

os.pullEvent("disk")
print("Disk found")
file = fs.open("/disk/user", "r")
print("File opened")
if file then
local text = file.readAll()
file.close()
print(text)
rednet.send(server, text)
print("Reqeust sent")
senderID, message, distance = rednet.receive()
print(message)
if senderID == server then
  if text == message then
   print("User verified")
   rs.setOutput(output, true)
   disk.eject(diskside)
   os.sleep(opentime)
   rs.setOutput(output, false)
  else
   print("User is forbidden")
  end
else
  print("The transmissed was hijacked")
end
else
print("User ID cannot be found")
end
end

Server

rednet.open("right")
while true do

sender, message, distance = rednet.receive()
print("Message received")

recordpath = table.concat({"/disk/records", sender}, "/")
print(recordpath)

file = fs.open(recordpath, "r")

if file then
local text = file.readAll()
file.close()
if string.find(text, message) then
  print("User found")
  rednet.send(sender, message)
else
  print("User not found")
  rednet.send(sender, "denied")
end
else
print("Records not found")
rednet.send("denied")
end
end


Any comments or criticisms are welcome!
Blocky_Balboa #2
Posted 04 August 2012 - 09:36 AM
Looks amazing! Definatly using this when my servers up and running :P/>/>
ScSEre #3
Posted 05 August 2012 - 12:58 AM
Hey,
sorry i'm a lua noob, but can you explain me what kind of file or table you'r using on the server to check whether the name is correct or not?
eat4fun #4
Posted 08 August 2012 - 12:26 AM
Hey,
sorry i'm a lua noob, but can you explain me what kind of file or table you'r using on the server to check whether the name is correct or not?

It basically just checks whether the string exists in a text file assigned to the client. It's akin to the String.Contains() method in the .NET namespace. This means that it could be easily exploited by having a sufficiently short string. A fix could be applied that would accept the string only if it is isolated (i.e. endline + string + endline), but I can't be bothered to do that.


string.find(file_containing_user_list, user_name_to_search_for)

http://msdn.microsof...y/dy85x1sa.aspx
norfair00 #5
Posted 13 August 2012 - 02:11 PM
how do you make it work for you
I do not understand is that I must master in "disk / record" on the server
and also what should be master on the client disk
D3matt #6
Posted 13 August 2012 - 08:57 PM
I like the idea. However I must point on flaw in your logic (But not the program itself). It's only slightly more difficult to dulicate a disk than it is to share a password :P/>/>