2017-09-05 06:09:31 +00:00
|
|
|
local Crypto = require('crypto')
|
|
|
|
local Event = require('event')
|
|
|
|
local Security = require('security')
|
|
|
|
local Socket = require('socket')
|
|
|
|
local Util = require('util')
|
2017-05-05 11:34:20 +00:00
|
|
|
|
2017-08-03 05:46:39 +00:00
|
|
|
Event.addRoutine(function()
|
2017-05-05 11:34:20 +00:00
|
|
|
|
2018-01-24 22:39:38 +00:00
|
|
|
print('trust: listening on port 19')
|
|
|
|
while true do
|
|
|
|
local socket = Socket.server(19)
|
2017-05-05 11:34:20 +00:00
|
|
|
|
2018-01-24 22:39:38 +00:00
|
|
|
print('trust: connection from ' .. socket.dhost)
|
2017-05-05 11:34:20 +00:00
|
|
|
|
2018-01-24 22:39:38 +00:00
|
|
|
local data = socket:read(2)
|
|
|
|
if data then
|
|
|
|
local password = Security.getPassword()
|
|
|
|
if not password then
|
|
|
|
socket:write({ msg = 'No password has been set' })
|
|
|
|
else
|
|
|
|
data = Crypto.decrypt(data, password)
|
|
|
|
if data and data.pk and data.dh == socket.dhost then
|
|
|
|
local trustList = Util.readTable('usr/.known_hosts') or { }
|
|
|
|
trustList[data.dh] = data.pk
|
|
|
|
Util.writeTable('usr/.known_hosts', trustList)
|
2017-05-06 01:43:17 +00:00
|
|
|
|
2018-01-24 22:39:38 +00:00
|
|
|
socket:write({ success = true, msg = 'Trust accepted' })
|
|
|
|
else
|
|
|
|
socket:write({ msg = 'Invalid password' })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
socket:close()
|
|
|
|
end
|
2017-05-05 11:34:20 +00:00
|
|
|
end)
|