opus/sys/apps/trust.lua

51 lines
1.0 KiB
Lua
Raw Normal View History

local Crypto = require('opus.crypto.chacha20')
local Security = require('opus.security')
local SHA = require('opus.crypto.sha2')
local Socket = require('opus.socket')
local Terminal = require('opus.terminal')
2017-05-05 11:34:20 +00:00
2017-10-08 21:45:01 +00:00
local os = _G.os
2017-05-05 11:34:20 +00:00
local remoteId
local args = { ... }
if #args == 1 then
2018-01-24 22:39:38 +00:00
remoteId = tonumber(args[1])
2017-05-05 11:34:20 +00:00
else
2018-01-24 22:39:38 +00:00
print('Enter host ID')
remoteId = tonumber(_G.read())
2017-05-05 11:34:20 +00:00
end
if not remoteId then
2018-01-24 22:39:38 +00:00
error('Syntax: trust <host ID>')
2017-05-05 11:34:20 +00:00
end
2017-05-06 01:43:17 +00:00
local password = Terminal.readPassword('Enter password: ')
if not password then
2018-01-24 22:39:38 +00:00
error('Invalid password')
2017-05-06 01:43:17 +00:00
end
2017-05-05 11:34:20 +00:00
print('connecting...')
2019-06-29 20:35:33 +00:00
local trustId = '01c3ba27fe01383a03a1785276d99df27c3edcef68fbf231ca'
local socket, msg = Socket.connect(remoteId, 19, { identifier = trustId })
2017-05-05 11:34:20 +00:00
if not socket then
2018-01-24 22:39:38 +00:00
error(msg)
2017-05-05 11:34:20 +00:00
end
2019-06-29 20:35:33 +00:00
local identifier = Security.getIdentifier()
2017-05-05 11:34:20 +00:00
2019-06-29 20:35:33 +00:00
socket:write(Crypto.encrypt({ pk = identifier, dh = os.getComputerID() }, SHA.compute(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
2018-01-24 22:39:38 +00:00
print(data.msg)
2017-05-19 23:00:23 +00:00
elseif data then
2018-01-24 22:39:38 +00:00
error(data.msg)
2017-05-19 23:00:23 +00:00
else
2018-01-24 22:39:38 +00:00
error('No response')
2017-05-19 23:00:23 +00:00
end