Pick out the right password when multiple passwords are included.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 18 Apr 2014 22:19:10 -0400
changeset 32 8f45f1e8bcfa
parent 31 838492d40709
child 33 bc1736f8e74d
Pick out the right password when multiple passwords are included.

This happens when you update a password field in the official 1Password app,
at least on Mac OS X, as I discovered thanks to Heartbleed.
1pass.lua
--- a/1pass.lua	Wed Apr 16 17:11:54 2014 -0400
+++ b/1pass.lua	Fri Apr 18 22:19:10 2014 -0400
@@ -128,6 +128,8 @@
     local addthis = false
     local username = nil
     local password = nil
+    local designated_password = nil
+    local designated_username = nil
     local email = nil
 
     if secure.fields == nil then
@@ -138,11 +140,17 @@
     for i,v in ipairs(secure.fields) do
         --print(info.name .. ": " .. v.type .. ", " .. v.value)
         local ignored = false
-        if (v.type == "P") and (password == nil) and (v.value ~= "") then
+        if (v.value == nil) or (v.value == "") then
+            ignored = true
+        elseif (v.designation ~= nil) and (v.designation == "password") then
+            designated_password = v.value
+        elseif (v.designation ~= nil) and (v.designation == "username") then
+            designated_username = v.value
+        elseif (v.type == "P") then
             password = v.value
-        elseif (v.type == "T") and (usenname == nil) and (v.value ~= "") then
+        elseif (v.type == "T") then
             username = v.value
-        elseif (v.type == "E") and (email == nil) and (v.value ~= "") then
+        elseif (v.type == "E") then
             email = v.value
         else
             ignored = true
@@ -154,6 +162,15 @@
     end
 
     if addthis then
+        -- designated fields always win out.
+        if (designated_username ~= nil) then
+            username = designated_username
+        end
+
+        if (designated_password ~= nil) then
+            password = designated_password
+        end
+
         if (username ~= nil) and (email ~= nil) and (email == username) then
             email = nil
         end