1
0
mirror of https://github.com/kepler155c/opus synced 2024-12-28 01:20:27 +00:00
opus/sys/network/trust.lua
kepler155c@gmail.com f866d2bd58 socket improvement
2017-05-09 01:57:00 -04:00

34 lines
901 B
Lua

local Socket = require('socket')
local process = require('process')
local Crypto = require('crypto')
process:newThread('trust_server', function()
print('trust: listening on port 19')
while true do
local socket = Socket.server(19)
print('trust: connection from ' .. socket.dhost)
local data = socket:read(2)
if data then
local password = os.getPassword()
if not password then
socket:write('No password has been set')
else
data = Crypto.decrypt(data, password)
if data and data.pk and data.dh then
local trustList = Util.readTable('.known_hosts') or { }
trustList[data.dh] = data.pk
Util.writeTable('.known_hosts', trustList)
socket:write('Trust accepted')
else
socket:write('Invalid password or password is not set')
end
end
end
socket:close()
end
end)