socket update

This commit is contained in:
kepler155c@gmail.com 2019-06-27 16:29:12 -04:00
parent 3c22a872b0
commit 97a442e999
1 changed files with 5 additions and 1 deletions

View File

@ -115,7 +115,7 @@ function Socket.connect(host, port)
type = 'OPEN',
shost = socket.shost,
dhost = socket.dhost,
t = Crypto.encrypt({ ts = os.time(), seq = socket.seq }, Security.getPublicKey()),
t = Crypto.encrypt({ ts = os.time(), seq = socket.seq, nts = os.epoch('utc') }, Security.getPublicKey()),
rseq = socket.wseq,
wseq = socket.rseq,
})
@ -170,6 +170,10 @@ local function trusted(msg, port)
if pubKey then
local data = Crypto.decrypt(msg.t or '', pubKey)
if data.nts then -- upgraded security
return data.nts and tonumber(data.nts) and math.abs(os.epoch('utc') - data.nts) < 1024
end
--local sharedKey = modexp(pubKey, exchange.secretKey, public.primeMod)
return data.ts and tonumber(data.ts) and math.abs(os.time() - data.ts) < 24
end