Compare commits

..
4 Commits
Author SHA1 Message Date
juhnsa 3ebb2d08d6 Fix issue 2025-08-27 13:37:00 +02:00
juhnsa b76c21bf74 Add feedback 2025-08-27 13:31:20 +02:00
juhnsa 1ad962d223 Fix issues 2025-08-27 13:27:36 +02:00
Juhn-Vitus Saß dca01a4116 Merge pull request 'issue-2 Resolves #2' (#4) from issue-2 into main
Reviewed-on: #4
2025-08-27 13:11:27 +02:00
+9 -8
View File
@@ -31,25 +31,22 @@ end
local function validate_key(card_holder, card_clearance, random_chars) local function validate_key(card_holder, card_clearance, random_chars)
local card_hash = hash(card_holder..','..card_clearance..','..random_chars) local card_hash = hash(card_holder..','..card_clearance..','..random_chars)
local key_file = fs.open(dir..config.key_file, 'r') local key_file = fs.open(dir..config.key_file, 'r')
local card_authentic = false
while true do while true do
local trusted_hash = key_file.readLine() local trusted_hash = key_file.readLine()
if trusted_hash == card_hash then if trusted_hash == card_hash then
print("Valid card "..card_hash) print("Valid card "..card_hash)
card_authentic = true key_file.close()
return true, card_hash return true, card_hash
end end
if not line then break end -- Stop when EOF reached if not trusted_hash then break end -- Stop when EOF reached
end end
key_file.close() key_file.close()
if card_authentic == false then
print("Unknown card "..card_hash) print("Unknown card "..card_hash)
return false return false
end end
end
if args[1] == "serve" then if args[1] == "serve" then
rednet.open(config.modem_side) rednet.open(config.modem_side)
@@ -115,15 +112,17 @@ elseif args[1] == "add_card" then
local new_card = args[2] local new_card = args[2]
local new_card_parts = split(new_card, ',') local new_card_parts = split(new_card, ',')
local card_holder = new_card_parts[1] local card_holder = new_card_parts[1]
local card_hash = hash(new_card)
local key_file = fs.open(card_holder..'.key', 'w') local key_file = fs.open(card_hash..'.key', 'w')
key_file.write(new_card) key_file.write(new_card..'\n')
key_file.close() key_file.close()
local trusted_keys = fs.open(dir..config.key_file, 'a') local trusted_keys = fs.open(dir..config.key_file, 'a')
local card_hash = hash(new_card)
trusted_keys.write(card_hash) trusted_keys.write(card_hash)
trusted_keys.close() trusted_keys.close()
print("Created key "..card_hash..".key in root dir")
end end
elseif args[1] == "remove_card" then elseif args[1] == "remove_card" then
if args[2] then if args[2] then
@@ -134,6 +133,8 @@ elseif args[1] == "remove_card" then
local trusted_hash = trusted_keys.readLine() local trusted_hash = trusted_keys.readLine()
if trusted_hash ~= key_hash then if trusted_hash ~= key_hash then
table.insert(new_key_table, trusted_hash) table.insert(new_key_table, trusted_hash)
else
print("Removed "..key_hash)
end end
if not trusted_hash then break end -- Stop when EOF reached if not trusted_hash then break end -- Stop when EOF reached
end end