Forcibly lock keychain on timeout instead of checking timeout on next access.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 15 Apr 2014 12:10:14 -0400
changeset 29 769393898e93
parent 28 60136c984e3b
child 30 c8f3db869ce0
Forcibly lock keychain on timeout instead of checking timeout on next access.
1pass.c
1pass.lua
--- a/1pass.c	Tue Apr 15 10:06:56 2014 -0400
+++ b/1pass.c	Tue Apr 15 12:10:14 2014 -0400
@@ -390,8 +390,16 @@
 } // keyhookPressed
 
 
+static int pumpLua(void)
+{
+    lua_getglobal(luaState, "pumpLua");
+    lua_call(luaState, 0, 0);
+} // pumpLua
+
+
 static gboolean keyhookPumper(void *arg)
 {
+    pumpLua();
     if (pumpKeyHook())
         keyhookPressed();
     else if (pumpPowermate())
--- a/1pass.lua	Tue Apr 15 10:06:56 2014 -0400
+++ b/1pass.lua	Tue Apr 15 12:10:14 2014 -0400
@@ -281,6 +281,30 @@
 
 local passwordUnlockTime = nil
 
+local function lockKeychain()
+    -- lose the existing password and key, prompt user again.
+    password = argv[2]  -- might be nil, don't reset if on command line.
+    keys["SL5"] = nil
+    passwordUnlockTime = nil
+    keyhookRunning = false
+    setPowermateLED(false)
+    collectgarbage()
+end
+
+function pumpLua()  -- not local! Called from C!
+    -- !!! FIXME: this should lose the key in RAM and turn off the Powermate
+    -- !!! FIXME:  LED when the time expires instead of if the time has
+    -- !!! FIXME:  expired when the user is trying to get at the keychain.
+    if passwordUnlockTime ~= nil then
+        local now = os.time()
+        local maxTime = (15 * 60)  -- !!! FIXME: don't hardcode.
+        if os.difftime(now, passwordUnlockTime) > maxTime then
+            lockKeychain()
+        end
+    end
+end
+
+
 function keyhookPressed()  -- not local! Called from C!
 --print("keyhookPressed: running==" .. tostring(keyhookRunning))
 --    if keyhookRunning then
@@ -289,20 +313,6 @@
 
     keyhookRunning = true
 
-    -- !!! FIXME: this should lose the key in RAM and turn off the Powermate
-    -- !!! FIXME:  LED when the time expires instead of if the time has
-    -- !!! FIXME:  expired when the user is trying to get at the keychain.
-    if passwordUnlockTime ~= nil then
-        local now = os.time()
-        local maxTime = (15 * 60)  -- !!! FIXME: don't hardcode.
-        if os.difftime(now, passwordUnlockTime) > maxTime then
-            -- lose the existing password and key, prompt user again.
-            setPowermateLED(false)
-            password = argv[2]  -- might be nil, don't reset if on command line.
-            keys["SL5"] = nil
-        end
-    end
-
     while password == nil do
         password = runGuiPasswordPrompt(getHint())
         if password == nil then
@@ -326,14 +336,7 @@
 
     local topmenu = makeGuiMenu()
 
-    local lock_callback = function()
-        password = argv[2]  -- might be nil, don't reset if on command line.
-        keys["SL5"] = nil
-        passwordUnlockTime = nil
-        keyhookRunning = false
-        setPowermateLED(false)
-    end
-    appendGuiMenuItem(topmenu, "Lock keychain", lock_callback)
+    appendGuiMenuItem(topmenu, "Lock keychain", function() lockKeychain() end)
 
     for orderi,type in ipairs(passwordTypeOrdering) do
         local bucket = items[type]