Compare commits
3
Commits
dca01a4116
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ebb2d08d6 | ||
|
|
b76c21bf74 | ||
|
|
1ad962d223 |
@@ -31,24 +31,21 @@ end
|
||||
local function validate_key(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 card_authentic = false
|
||||
|
||||
while true do
|
||||
local trusted_hash = key_file.readLine()
|
||||
if trusted_hash == card_hash then
|
||||
print("Valid card "..card_hash)
|
||||
card_authentic = true
|
||||
key_file.close()
|
||||
return true, card_hash
|
||||
end
|
||||
if not line then break end -- Stop when EOF reached
|
||||
if not trusted_hash then break end -- Stop when EOF reached
|
||||
end
|
||||
|
||||
key_file.close()
|
||||
|
||||
if card_authentic == false then
|
||||
print("Unknown card "..card_hash)
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
if args[1] == "serve" then
|
||||
@@ -115,15 +112,17 @@ elseif args[1] == "add_card" then
|
||||
local new_card = args[2]
|
||||
local new_card_parts = split(new_card, ',')
|
||||
local card_holder = new_card_parts[1]
|
||||
local card_hash = hash(new_card)
|
||||
|
||||
local key_file = fs.open(card_holder..'.key', 'w')
|
||||
key_file.write(new_card)
|
||||
local key_file = fs.open(card_hash..'.key', 'w')
|
||||
key_file.write(new_card..'\n')
|
||||
key_file.close()
|
||||
|
||||
local trusted_keys = fs.open(dir..config.key_file, 'a')
|
||||
local card_hash = hash(new_card)
|
||||
trusted_keys.write(card_hash)
|
||||
trusted_keys.close()
|
||||
|
||||
print("Created key "..card_hash..".key in root dir")
|
||||
end
|
||||
elseif args[1] == "remove_card" then
|
||||
if args[2] then
|
||||
@@ -134,6 +133,8 @@ elseif args[1] == "remove_card" then
|
||||
local trusted_hash = trusted_keys.readLine()
|
||||
if trusted_hash ~= key_hash then
|
||||
table.insert(new_key_table, trusted_hash)
|
||||
else
|
||||
print("Removed "..key_hash)
|
||||
end
|
||||
if not trusted_hash then break end -- Stop when EOF reached
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user