Compare commits
2 Commits
39caa32908
...
4a233b1c55
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a233b1c55 | ||
|
|
9e06241ac3 |
@@ -25,11 +25,11 @@ end
|
||||
local function trustConnection(socket)
|
||||
local data = socket:read(2)
|
||||
if data then
|
||||
local password = Security.getPassword()
|
||||
if not password then
|
||||
local trustKey = Security.getTrustKey()
|
||||
if not trustKey then
|
||||
socket:write({ msg = 'No password has been set' })
|
||||
else
|
||||
if validateData(data, password, socket.dhost) then
|
||||
if validateData(data, trustKey, socket.dhost) then
|
||||
print("Accepted trust from " .. socket.dhost)
|
||||
socket:write({ success = true, msg = 'Trust accepted' })
|
||||
return
|
||||
|
||||
@@ -64,6 +64,7 @@ function Security.updatePassword(password)
|
||||
hash = derived:toHex(),
|
||||
salt = salt,
|
||||
iter = PBKDF2_ITERATIONS,
|
||||
trustKey = SHA.compute(password),
|
||||
}
|
||||
Config.update('os', config)
|
||||
end
|
||||
@@ -72,4 +73,15 @@ function Security.getPassword()
|
||||
return Config.load('os').password
|
||||
end
|
||||
|
||||
-- Returns the trust key for ChaCha20-based trust protocol.
|
||||
-- Compatible with both new (PBKDF2 table) and legacy (SHA-256 string) formats.
|
||||
function Security.getTrustKey()
|
||||
local stored = Security.getPassword()
|
||||
if type(stored) == 'table' then
|
||||
return stored.trustKey
|
||||
end
|
||||
-- Legacy: the stored string IS the SHA-256 hex
|
||||
return stored
|
||||
end
|
||||
|
||||
return Security
|
||||
|
||||
Reference in New Issue
Block a user