1
0
mirror of https://github.com/kepler155c/opus synced 2025-02-10 22:10:02 +00:00
opus/sys/network/trust.lua

36 lines
1010 B
Lua
Raw Normal View History

local Crypto = require('crypto')
local Event = require('event')
local Security = require('security')
local Socket = require('socket')
local Util = require('util')
2017-05-05 07:34:20 -04:00
2017-08-03 01:46:39 -04:00
Event.addRoutine(function()
2017-05-05 07:34:20 -04:00
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 = Security.getPassword()
2017-05-05 21:43:17 -04:00
if not password then
2017-05-19 19:00:23 -04:00
socket:write({ msg = 'No password has been set' })
2017-05-05 07:34:20 -04:00
else
2017-05-05 21:43:17 -04:00
data = Crypto.decrypt(data, password)
2017-05-19 19:00:23 -04:00
if data and data.pk and data.dh == socket.dhost then
2017-05-20 18:27:26 -04:00
local trustList = Util.readTable('usr/.known_hosts') or { }
2017-05-09 01:57:00 -04:00
trustList[data.dh] = data.pk
2017-05-20 18:27:26 -04:00
Util.writeTable('usr/.known_hosts', trustList)
2017-05-05 21:43:17 -04:00
2017-05-19 19:00:23 -04:00
socket:write({ success = true, msg = 'Trust accepted' })
2017-05-05 21:43:17 -04:00
else
2017-05-19 19:00:23 -04:00
socket:write({ msg = 'Invalid password' })
2017-05-05 21:43:17 -04:00
end
2017-05-05 07:34:20 -04:00
end
end
socket:close()
end
end)