security update round 2

This commit is contained in:
kepler155c@gmail.com
2019-06-29 02:44:30 -04:00
parent d90aa0e2fd
commit 00293033c8
8 changed files with 91 additions and 159 deletions

View File

@@ -13,13 +13,28 @@ 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.generateKeyPair()
local privateKey = Util.hexToByteArray(genKey())
return privateKey, ECC.publicKey(privateKey)
end
function Security.getIdentifier()
return Security.geetPublicKey()
end
-- deprecate - will use getIdentifier
function Security.getSecretKey()
local config = Config.load('os')
if not config.secretKey then
config.secretKey = ""
for _ = 1, 32 do
config.secretKey = config.secretKey .. ("%02x"):format(math.random(0, 0xFF))
end
config.secretKey = genKey()
Config.update('os', config)
end
return Util.hexToByteArray(config.secretKey)