1
0
mirror of https://github.com/kepler155c/opus synced 2024-12-28 01:20:27 +00:00
opus/sys/apps/trust.lua

49 lines
970 B
Lua
Raw Normal View History

2017-05-05 11:34:20 +00:00
require = requireInjector(getfenv(1))
local Socket = require('socket')
local SHA1 = require('sha1')
2017-05-06 01:43:17 +00:00
local Terminal = require('terminal')
local Crypto = require('crypto')
2017-05-05 11:34:20 +00:00
local remoteId
local args = { ... }
if #args == 1 then
remoteId = tonumber(args[1])
else
print('Enter host ID')
remoteId = tonumber(read())
end
if not remoteId then
error('Syntax: trust <host ID>')
end
2017-05-06 01:43:17 +00:00
local password = Terminal.readPassword('Enter password: ')
if not password then
error('Invalid password')
end
2017-05-05 11:34:20 +00:00
print('connecting...')
local socket = Socket.connect(remoteId, 19)
if not socket then
error('Unable to connect to ' .. remoteId .. ' on port 19')
end
2017-05-19 23:00:23 +00:00
local publicKey = os.getPublicKey()
2017-05-06 01:43:17 +00:00
local password = SHA1.sha1(password)
2017-05-05 11:34:20 +00:00
2017-05-09 05:57:00 +00:00
socket:write(Crypto.encrypt({ pk = publicKey, dh = os.getComputerID() }, password))
2017-05-05 11:34:20 +00:00
2017-05-19 23:00:23 +00:00
local data = socket:read(2)
2017-05-05 11:34:20 +00:00
socket:close()
2017-05-19 23:00:23 +00:00
if data and data.success then
print(data.msg)
elseif data then
error(data.msg)
else
error('No response')
end