mirror of
https://github.com/kepler155c/opus
synced 2025-10-21 10:47:40 +00:00
rework app registry - trust tweaks
This commit is contained in:
@@ -3,27 +3,6 @@ local Crypto = require('crypto')
|
||||
|
||||
local socketClass = { }
|
||||
|
||||
local exchange = {
|
||||
base = 11,
|
||||
primeMod = 625210769
|
||||
}
|
||||
|
||||
local function modexp(base, exponent, modulo)
|
||||
local remainder = base
|
||||
|
||||
for i = 1, exponent-1 do
|
||||
remainder = remainder * remainder
|
||||
if remainder >= modulo then
|
||||
remainder = remainder % modulo
|
||||
end
|
||||
end
|
||||
|
||||
return remainder
|
||||
end
|
||||
|
||||
exchange.secretKey = os.getSecretKey()
|
||||
exchange.publicKey = modexp(exchange.base, exchange.secretKey, exchange.primeMod)
|
||||
|
||||
function socketClass:read(timeout)
|
||||
|
||||
local data, distance = transport.read(self)
|
||||
@@ -131,7 +110,7 @@ function Socket.connect(host, port)
|
||||
type = 'OPEN',
|
||||
shost = socket.shost,
|
||||
dhost = socket.dhost,
|
||||
t = Crypto.encrypt({ ts = os.time(), seq = socket.seq }, exchange.publicKey),
|
||||
t = Crypto.encrypt({ ts = os.time(), seq = socket.seq }, os.getPublicKey()),
|
||||
rseq = socket.wseq,
|
||||
wseq = socket.rseq,
|
||||
})
|
||||
|
@@ -69,6 +69,30 @@ function os.getSecretKey()
|
||||
return config.secretKey
|
||||
end
|
||||
|
||||
function os.getPublicKey()
|
||||
|
||||
local exchange = {
|
||||
base = 11,
|
||||
primeMod = 625210769
|
||||
}
|
||||
|
||||
local function modexp(base, exponent, modulo)
|
||||
local remainder = base
|
||||
|
||||
for i = 1, exponent-1 do
|
||||
remainder = remainder * remainder
|
||||
if remainder >= modulo then
|
||||
remainder = remainder % modulo
|
||||
end
|
||||
end
|
||||
|
||||
return remainder
|
||||
end
|
||||
|
||||
local secretKey = os.getSecretKey()
|
||||
return modexp(exchange.base, secretKey, exchange.primeMod)
|
||||
end
|
||||
|
||||
function os.updatePassword(password)
|
||||
Config.load('os', config)
|
||||
config.password = password
|
||||
@@ -127,6 +151,8 @@ function os.getVersion()
|
||||
return version or 1.7
|
||||
end
|
||||
|
||||
-- move completely into overview
|
||||
-- just post event from appstore
|
||||
function os.registerApp(entry)
|
||||
local apps = { }
|
||||
Config.load('apps', apps)
|
||||
|
@@ -14,17 +14,17 @@ process:newThread('trust_server', function()
|
||||
if data then
|
||||
local password = os.getPassword()
|
||||
if not password then
|
||||
socket:write('No password has been set')
|
||||
socket:write({ msg = 'No password has been set' })
|
||||
else
|
||||
data = Crypto.decrypt(data, password)
|
||||
if data and data.pk and data.dh then
|
||||
if data and data.pk and data.dh == socket.dhost then
|
||||
local trustList = Util.readTable('.known_hosts') or { }
|
||||
trustList[data.dh] = data.pk
|
||||
Util.writeTable('.known_hosts', trustList)
|
||||
|
||||
socket:write('Trust accepted')
|
||||
socket:write({ success = true, msg = 'Trust accepted' })
|
||||
else
|
||||
socket:write('Invalid password')
|
||||
socket:write({ msg = 'Invalid password' })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user