1
0
mirror of https://github.com/kepler155c/opus synced 2025-02-07 12:40:01 +00:00
opus/sys/apps/trust.lua

52 lines
951 B
Lua
Raw Normal View History

2018-01-24 17:39:38 -05:00
_G.requireInjector(_ENV)
local Crypto = require('crypto')
local Security = require('security')
local SHA1 = require('sha1')
local Socket = require('socket')
2017-05-05 21:43:17 -04:00
local Terminal = require('terminal')
2017-05-05 07:34:20 -04:00
2017-10-08 17:45:01 -04:00
local os = _G.os
2017-05-05 07:34:20 -04:00
local remoteId
local args = { ... }
if #args == 1 then
2018-01-24 17:39:38 -05:00
remoteId = tonumber(args[1])
2017-05-05 07:34:20 -04:00
else
2018-01-24 17:39:38 -05:00
print('Enter host ID')
remoteId = tonumber(_G.read())
2017-05-05 07:34:20 -04:00
end
if not remoteId then
2018-01-24 17:39:38 -05:00
error('Syntax: trust <host ID>')
2017-05-05 07:34:20 -04:00
end
2017-05-05 21:43:17 -04:00
local password = Terminal.readPassword('Enter password: ')
if not password then
2018-01-24 17:39:38 -05:00
error('Invalid password')
2017-05-05 21:43:17 -04:00
end
2017-05-05 07:34:20 -04:00
print('connecting...')
2017-10-11 11:37:52 -04:00
local socket, msg = Socket.connect(remoteId, 19)
2017-05-05 07:34:20 -04:00
if not socket then
2018-01-24 17:39:38 -05:00
error(msg)
2017-05-05 07:34:20 -04:00
end
local publicKey = Security.getPublicKey()
2017-05-05 07:34:20 -04:00
2017-10-08 17:45:01 -04:00
socket:write(Crypto.encrypt({ pk = publicKey, dh = os.getComputerID() }, SHA1.sha1(password)))
2017-05-05 07:34:20 -04:00
2017-05-19 19:00:23 -04:00
local data = socket:read(2)
2017-05-05 07:34:20 -04:00
socket:close()
2017-05-19 19:00:23 -04:00
if data and data.success then
2018-01-24 17:39:38 -05:00
print(data.msg)
2017-05-19 19:00:23 -04:00
elseif data then
2018-01-24 17:39:38 -05:00
error(data.msg)
2017-05-19 19:00:23 -04:00
else
2018-01-24 17:39:38 -05:00
error('No response')
2017-05-19 19:00:23 -04:00
end