From 7d7fb323da25096360637c9b5ed72d0b42ce2bc7 Mon Sep 17 00:00:00 2001 From: signalhunter Date: Sat, 22 Aug 2020 00:57:15 -0400 Subject: [PATCH 1/3] Add trust manager prototype --- sys/apps/system/trust.lua | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 sys/apps/system/trust.lua diff --git a/sys/apps/system/trust.lua b/sys/apps/system/trust.lua new file mode 100644 index 0000000..c795ab8 --- /dev/null +++ b/sys/apps/system/trust.lua @@ -0,0 +1,44 @@ +local UI = require("opus.ui") +local Util = require("opus.util") +local SHA = require('opus.crypto.sha2') + +local function split(s) + local b = "" + for i = 1, #s, 5 do + b = b .. s:sub(i, i+4) + if i ~= #s-4 then + b = b .. "-" + end + end + return b +end + +return UI.Tab { + title = 'Trust', + description = 'Manage trusted devices', + grid = UI.Grid { + x = 2, y = 2, ex = -2, ey = -3, + autospace = true, + sortColumn = 'id', + columns = { + { heading = 'Computer ID', key = 'id'}, + { heading = 'Identity', key = 'pkey'} + } + }, + statusBar = UI.StatusBar { values = 'double-click to revoke trust' }, + reload = function(self) + local values = {} + for k,v in pairs(Util.readTable('usr/.known_hosts') or {}) do + table.insert(values, { + id = k, + pkey = split(SHA.compute(v):sub(-20):upper()) -- Obfuscate private key for visual ident + }) + end + self.grid:setValues(values) + self.grid:setIndex(1) + end, + enable = function(self) + self:reload() + UI.Tab.enable(self) + end +} \ No newline at end of file -- 2.49.1 From 17391c1e000172418533a4eb42890d819570da14 Mon Sep 17 00:00:00 2001 From: signalhunter Date: Sat, 22 Aug 2020 03:11:29 -0400 Subject: [PATCH 2/3] Made the prototype functional --- sys/apps/system/trust.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sys/apps/system/trust.lua b/sys/apps/system/trust.lua index c795ab8..bb6a703 100644 --- a/sys/apps/system/trust.lua +++ b/sys/apps/system/trust.lua @@ -40,5 +40,14 @@ return UI.Tab { enable = function(self) self:reload() UI.Tab.enable(self) + end, + eventHandler = function(self, event) + if event.type == 'grid_select' then + local hosts = Util.readTable('usr/.known_hosts') + hosts[event.selected.id] = nil + Util.writeTable('usr/.known_hosts', hosts) + self:reload() + return true + end end } \ No newline at end of file -- 2.49.1 From 38ae5bcf787fd6d9c280136ff72716b439bc24c3 Mon Sep 17 00:00:00 2001 From: signalhunter Date: Sat, 22 Aug 2020 03:45:35 -0400 Subject: [PATCH 3/3] Better event handling --- sys/apps/system/trust.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sys/apps/system/trust.lua b/sys/apps/system/trust.lua index bb6a703..399fb8e 100644 --- a/sys/apps/system/trust.lua +++ b/sys/apps/system/trust.lua @@ -47,7 +47,9 @@ return UI.Tab { hosts[event.selected.id] = nil Util.writeTable('usr/.known_hosts', hosts) self:reload() - return true + else + return UI.Tab.eventHandler(self, event) end + return true end } \ No newline at end of file -- 2.49.1