secure telnet
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
local Config = require('opus.config')
|
||||
local ECC = require('opus.crypto.ecc')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local Security = { }
|
||||
|
||||
@@ -13,32 +11,18 @@ function Security.hasPassword()
|
||||
return not not Security.getPassword()
|
||||
end
|
||||
|
||||
local function genKey()
|
||||
local key = { }
|
||||
for _ = 1, 32 do
|
||||
table.insert(key, ("%02x"):format(math.random(0, 0xFF)))
|
||||
end
|
||||
return table.concat(key)
|
||||
end
|
||||
|
||||
function Security.getSecretKey()
|
||||
local config = Config.load('os')
|
||||
if not config.secretKey then
|
||||
config.secretKey = genKey()
|
||||
Config.update('os', config)
|
||||
end
|
||||
return Util.hexToByteArray(config.secretKey)
|
||||
end
|
||||
|
||||
function Security.getIdentifier()
|
||||
local config = Config.load('os')
|
||||
if config.identifier then
|
||||
return config.identifier
|
||||
|
||||
if not config.identifier then
|
||||
local key = { }
|
||||
for _ = 1, 32 do
|
||||
table.insert(key, ("%02x"):format(math.random(0, 0xFF)))
|
||||
end
|
||||
config.identifier = table.concat(key)
|
||||
|
||||
Config.update('os', config)
|
||||
end
|
||||
-- preserve the hash the user generated
|
||||
local identifier = ECC.publicKey(Security.getSecretKey())
|
||||
config.identifier = Util.byteArrayToHex(identifier)
|
||||
Config.update('os', config)
|
||||
|
||||
return config.identifier
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user