1pass.lua
author Ryan C. Gordon <icculus@icculus.org>
Sun, 18 Jun 2017 19:50:43 -0400
changeset 57 4974e5368a29
parent 56 a573346e6f7b
permissions -rw-r--r--
Minor type cleanup ("unsigned char" -> "uint8_t").
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
JSON = (loadfile "JSON.lua")()
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
     2
dofile("dumptable.lua")
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
     3
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
     4
local basedir = "1Password/1Password.agilekeychain/data/default"  -- !!! FIXME
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
     5
local password = argv[2]
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
     6
local items = nil
35
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
     7
local faveitems = nil
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
     8
local keyhookRunning = false
45
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
     9
local keyhookGuiMenus = nil
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
    10
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
    11
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
    12
local function runGarbageCollector()
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
    13
    --local memused = math.floor(collectgarbage("count") * 1024.0)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
    14
    --print("Collecting garbage (currently using " .. memused .. " bytes).")
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
    15
    collectgarbage()
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
    16
    --local newmemused = math.floor(collectgarbage("count") * 1024.0)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
    17
    --print("Now using " .. newmemused .. " bytes (" .. memused - newmemused .. " bytes savings).")
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
    18
end
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
    19
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    20
local passwordTypeNameMap = {
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    21
    ["webforms.WebForm"] = "Logins",
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    22
    ["wallet.financial.CreditCard"] = "Credit cards",
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    23
    ["passwords.Password"] = "Passwords",
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    24
    ["wallet.financial.BankAccountUS"] = "Bank accounts",
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    25
    ["wallet.membership.Membership"] = "Memberships",
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    26
    ["wallet.government.DriversLicense"] = "Drivers licenses",
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    27
    ["system.Tombstone"] = "Dead items",
25
44b6b8b34eb8 Added Secure Notes items to menu.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
    28
    ["securenotes.SecureNote"] = "Secure notes",
49
2c57a0ad7c8f Added some missing categories (US Social Security Numbers and Router logins).
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    29
    ["wallet.government.SsnUS"] = "Social Security Numbers",
2c57a0ad7c8f Added some missing categories (US Social Security Numbers and Router logins).
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    30
    ["wallet.computer.Router"] = "Router passwords",
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    31
    -- !!! FIXME: more!
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    32
}
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    33
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    34
local passwordTypeOrdering = {
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    35
    "webforms.WebForm",
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    36
    "wallet.financial.CreditCard",
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    37
    "passwords.Password",
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    38
    "wallet.financial.BankAccountUS",
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    39
    "wallet.membership.Membership",
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    40
    "wallet.government.DriversLicense",
49
2c57a0ad7c8f Added some missing categories (US Social Security Numbers and Router logins).
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    41
    "wallet.government.SsnUS",
25
44b6b8b34eb8 Added Secure Notes items to menu.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
    42
    "securenotes.SecureNote",
49
2c57a0ad7c8f Added some missing categories (US Social Security Numbers and Router logins).
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    43
    "wallet.computer.Router",
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    44
    -- never show "system.Tombstone",
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    45
    -- !!! FIXME: more!
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    46
}
0
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
6
b7f19e0599db Dump out all the encrypted data.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    48
local function load_json_str(str, desc)
b7f19e0599db Dump out all the encrypted data.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    49
    local retval = JSON:decode(str)
b7f19e0599db Dump out all the encrypted data.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    50
    return retval
b7f19e0599db Dump out all the encrypted data.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    51
end
b7f19e0599db Dump out all the encrypted data.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    52
0
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
local function load_json(fname)
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
    local f = io.open(fname, "rb")
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
    if (f == nil) then
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
        return nil
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
    end
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
46
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
    59
    local str = f:read("*a")
0
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
    f:close()
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
6
b7f19e0599db Dump out all the encrypted data.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    62
    return load_json_str(str, fname)
0
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
end
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
5
6f80cd157c13 Cache loaded encryption keys.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
    66
local keys = {}
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
    67
local function loadKey(level, password)
5
6f80cd157c13 Cache loaded encryption keys.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
    68
    if keys[level] ~= nil then
6f80cd157c13 Cache loaded encryption keys.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
    69
        return keys[level]
6f80cd157c13 Cache loaded encryption keys.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
    70
    end
6f80cd157c13 Cache loaded encryption keys.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
    71
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    72
    local keysjson = load_json(basedir .. "/encryptionKeys.js")
0
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
    if (keysjson == nil) or (keysjson[level] == nil) then
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
        return nil
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
    end
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
    local identifier = keysjson[level]
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
    for i,v in ipairs(keysjson.list) do
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
        if v.identifier == identifier then
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
			local iterations = v.iterations
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
            if (iterations == nil) or (iterations < 1000) then
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
			    iterations = 1000
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
            end
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
			local decrypted = decryptUsingPBKDF2(v.data, password, iterations)
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
			if decrypted == nil then
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
                return nil
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
            end
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
			local validate = decryptBase64UsingKey(v.validation, decrypted)
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
			if validate ~= decrypted then
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
                return nil
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
            end
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
5
6f80cd157c13 Cache loaded encryption keys.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
    95
            keys[level] = decrypted
0
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
            return decrypted
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
        end
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
    end
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
    return nil
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
end
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   103
local function getHint()
0
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
    local f = io.open(basedir .. "/.password.hint", "r")
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
    if (f == nil) then
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
        return
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
    end
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
46
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   109
    local str = "(hint is '" .. f:read("*a") .. "')."
0
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
    f:close()
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   111
    --print(str)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   112
    return str
0
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
end
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
1
0919d17b13f9 Move the mainline into Lua.
Ryan C. Gordon <icculus@icculus.org>
parents: 0
diff changeset
   115
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   116
local function loadContents()
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   117
    return load_json(basedir .. "/contents.js")
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   118
end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   119
45
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   120
local function makeMenu()
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   121
    return {}
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   122
end
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   123
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   124
local function appendMenuItem(menu, text, callback)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   125
    local item = {}
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   126
    item["text"] = text
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   127
    if callback ~= nil then
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   128
        item["callback"] = callback
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   129
    end
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   130
    menu[#menu+1] = item
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   131
    return item
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   132
end
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   133
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   134
local function setMenuItemSubmenu(menuitem, submenu)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   135
    menuitem["submenu"] = submenu
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   136
end
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   137
46
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   138
local function setMenuItemChecked(menuitem, ischecked)
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   139
    menuitem["checked"] = ischecked
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   140
end
45
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   141
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   142
56
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   143
local function build_secret_menuitem(menu, type, str, hidden, transform)
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   144
    if str == nil then
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   145
        return nil
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   146
    end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   147
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   148
    local valuestr = str
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   149
    if hidden == true then
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   150
        valuestr = "*****"
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   151
    end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   152
    local text = type .. " " .. valuestr
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   153
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   154
    local callback = function()
56
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   155
        if transform ~= nil then
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   156
            str = transform(str)
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   157
        end
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   158
        copyToClipboard(str)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   159
        --print("Copied data [" .. str .. "] to clipboard.")
45
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   160
        guiDestroyMenu(keyhookGuiMenus[1])
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   161
    end
45
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   162
    return appendMenuItem(menu, text, callback)
6
b7f19e0599db Dump out all the encrypted data.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   163
end
b7f19e0599db Dump out all the encrypted data.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   164
56
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   165
local function transform_otp(str)
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   166
    local algorithm, name, argstr = string.match(str, "^otpauth://(.-)/(.-)?(.+)$")
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   167
    if algorithm == nil then algorithm = "" end
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   168
    if algorithm ~= "totp" then
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   169
        print("FIXME: don't know how to handle One Time Passwords using the '" .. algorithm .. "' algorithm!")
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   170
        return "000000"
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   171
    end
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   172
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   173
    local args = {}
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   174
    while argstr ~= nil and argstr ~= "" do
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   175
        local arg
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   176
        local idx = string.find(argstr, "&")
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   177
        if idx == nil then
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   178
            arg = argstr
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   179
            argstr = nil
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   180
        else
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   181
            arg = string.sub(argstr, 0, idx);
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   182
            argstr = string.sub(argstr, idx + 1);
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   183
        end
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   184
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   185
        local key, val = string.match(arg, "^(.-)=(.*)$")
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   186
        if (key ~= nil) and (val ~= nil) then
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   187
            args[key] = val
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   188
        end
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   189
    end
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   190
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   191
    --dumptable("otpauth://" .. algorithm .. "/" .. name, args);
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   192
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   193
    if args["secret"] == nil then
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   194
        print("FIXME: this One Time Password doesn't seem to have a secret key!")
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   195
        return "000000"
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   196
    end
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   197
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   198
    local retval = decryptTopt(args["secret"]);
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   199
    if retval == nil then
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   200
        print("FIXME: failed to generate One Time Password; is the secret key bogus?")
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   201
        retval = "000000"
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   202
    end
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   203
    return retval
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   204
end
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   205
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   206
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   207
local secret_menuitem_builders = {}
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   208
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   209
local function build_secret_menuitem_webform(menu, info, secure)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   210
    local addthis = false
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   211
    local username = nil
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   212
    local password = nil
56
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   213
    local otp = nil
32
8f45f1e8bcfa Pick out the right password when multiple passwords are included.
Ryan C. Gordon <icculus@icculus.org>
parents: 30
diff changeset
   214
    local designated_password = nil
8f45f1e8bcfa Pick out the right password when multiple passwords are included.
Ryan C. Gordon <icculus@icculus.org>
parents: 30
diff changeset
   215
    local designated_username = nil
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   216
    local email = nil
21
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   217
24
c34cc914f09d Checked for secure.fields in the wrong place.
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   218
    if secure.fields == nil then
c34cc914f09d Checked for secure.fields in the wrong place.
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   219
      print("no secure fields, don't know how to handle this item") 
c34cc914f09d Checked for secure.fields in the wrong place.
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   220
      return
c34cc914f09d Checked for secure.fields in the wrong place.
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   221
    end
c34cc914f09d Checked for secure.fields in the wrong place.
Ryan C. Gordon <icculus@icculus.org>
parents: 22
diff changeset
   222
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   223
    for i,v in ipairs(secure.fields) do
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   224
        --print(info.name .. ": " .. v.type .. ", " .. v.value)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   225
        local ignored = false
32
8f45f1e8bcfa Pick out the right password when multiple passwords are included.
Ryan C. Gordon <icculus@icculus.org>
parents: 30
diff changeset
   226
        if (v.value == nil) or (v.value == "") then
8f45f1e8bcfa Pick out the right password when multiple passwords are included.
Ryan C. Gordon <icculus@icculus.org>
parents: 30
diff changeset
   227
            ignored = true
8f45f1e8bcfa Pick out the right password when multiple passwords are included.
Ryan C. Gordon <icculus@icculus.org>
parents: 30
diff changeset
   228
        elseif (v.designation ~= nil) and (v.designation == "password") then
8f45f1e8bcfa Pick out the right password when multiple passwords are included.
Ryan C. Gordon <icculus@icculus.org>
parents: 30
diff changeset
   229
            designated_password = v.value
8f45f1e8bcfa Pick out the right password when multiple passwords are included.
Ryan C. Gordon <icculus@icculus.org>
parents: 30
diff changeset
   230
        elseif (v.designation ~= nil) and (v.designation == "username") then
8f45f1e8bcfa Pick out the right password when multiple passwords are included.
Ryan C. Gordon <icculus@icculus.org>
parents: 30
diff changeset
   231
            designated_username = v.value
8f45f1e8bcfa Pick out the right password when multiple passwords are included.
Ryan C. Gordon <icculus@icculus.org>
parents: 30
diff changeset
   232
        elseif (v.type == "P") then
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   233
            password = v.value
32
8f45f1e8bcfa Pick out the right password when multiple passwords are included.
Ryan C. Gordon <icculus@icculus.org>
parents: 30
diff changeset
   234
        elseif (v.type == "T") then
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   235
            username = v.value
32
8f45f1e8bcfa Pick out the right password when multiple passwords are included.
Ryan C. Gordon <icculus@icculus.org>
parents: 30
diff changeset
   236
        elseif (v.type == "E") then
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   237
            email = v.value
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   238
        else
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   239
            ignored = true
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   240
        end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   241
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   242
        if not ignored then
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   243
            addthis = true
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   244
        end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   245
    end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   246
56
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   247
    -- this is probably all wrong.
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   248
    if secure.sections ~= nil then
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   249
        for i,v in ipairs(secure.sections) do
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   250
            if v.fields ~= nil then
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   251
                for i2,v2 in ipairs(v.fields) do
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   252
                    if (type(v2.v) == "string") and (string.sub(v2.v, 0, 10) == "otpauth://") then
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   253
                        otp = v2.v
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   254
                        addthis = true
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   255
                    end
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   256
                end
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   257
            end
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   258
        end
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   259
    end
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   260
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   261
    if addthis then
32
8f45f1e8bcfa Pick out the right password when multiple passwords are included.
Ryan C. Gordon <icculus@icculus.org>
parents: 30
diff changeset
   262
        -- designated fields always win out.
8f45f1e8bcfa Pick out the right password when multiple passwords are included.
Ryan C. Gordon <icculus@icculus.org>
parents: 30
diff changeset
   263
        if (designated_username ~= nil) then
8f45f1e8bcfa Pick out the right password when multiple passwords are included.
Ryan C. Gordon <icculus@icculus.org>
parents: 30
diff changeset
   264
            username = designated_username
8f45f1e8bcfa Pick out the right password when multiple passwords are included.
Ryan C. Gordon <icculus@icculus.org>
parents: 30
diff changeset
   265
        end
8f45f1e8bcfa Pick out the right password when multiple passwords are included.
Ryan C. Gordon <icculus@icculus.org>
parents: 30
diff changeset
   266
8f45f1e8bcfa Pick out the right password when multiple passwords are included.
Ryan C. Gordon <icculus@icculus.org>
parents: 30
diff changeset
   267
        if (designated_password ~= nil) then
8f45f1e8bcfa Pick out the right password when multiple passwords are included.
Ryan C. Gordon <icculus@icculus.org>
parents: 30
diff changeset
   268
            password = designated_password
8f45f1e8bcfa Pick out the right password when multiple passwords are included.
Ryan C. Gordon <icculus@icculus.org>
parents: 30
diff changeset
   269
        end
8f45f1e8bcfa Pick out the right password when multiple passwords are included.
Ryan C. Gordon <icculus@icculus.org>
parents: 30
diff changeset
   270
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   271
        if (username ~= nil) and (email ~= nil) and (email == username) then
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   272
            email = nil
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   273
        end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   274
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   275
        build_secret_menuitem(menu, "username", username)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   276
        build_secret_menuitem(menu, "email", email)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   277
        build_secret_menuitem(menu, "password", password, true)
56
a573346e6f7b Added One Time Password support.
Ryan C. Gordon <icculus@icculus.org>
parents: 49
diff changeset
   278
        build_secret_menuitem(menu, "otp", otp, true, transform_otp)
8
eada72719d17 Make the app basically useful.
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   279
    end
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   280
end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   281
secret_menuitem_builders["webforms.WebForm"] = build_secret_menuitem_webform
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   282
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   283
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   284
local function build_secret_menuitem_password(menu, info, secure)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   285
    build_secret_menuitem(menu, "password", secure.password, true)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   286
end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   287
secret_menuitem_builders["passwords.Password"] = build_secret_menuitem_password
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   288
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   289
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   290
local function build_secret_menuitem_bankacctus(menu, info, secure)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   291
    -- !!! FIXME: there's more data than this in a generic dictionary.
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   292
    build_secret_menuitem(menu, "Account type", secure.accountType)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   293
    build_secret_menuitem(menu, "Routing number", secure.routingNo)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   294
    build_secret_menuitem(menu, "Account number", secure.accountNo)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   295
    build_secret_menuitem(menu, "Bank name", secure.bankName)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   296
    build_secret_menuitem(menu, "Owner", secure.owner)
41
5155ff0e6d3d Added SWIFT code and PIN fields to bank account menus.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   297
    build_secret_menuitem(menu, "SWIFT code", secure.swift)
5155ff0e6d3d Added SWIFT code and PIN fields to bank account menus.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   298
    build_secret_menuitem(menu, "PIN", secure.telephonePin)
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   299
end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   300
secret_menuitem_builders["wallet.financial.BankAccountUS"] = build_secret_menuitem_bankacctus
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   301
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   302
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   303
local function build_secret_menuitem_driverslic(menu, info, secure)
42
ca071626bfa0 Fixed driver license dates that might be missing (thanks, Patrick!).
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   304
    -- !!! FIXME: there's more data for this menuitem than this, in a generic dictionary.
ca071626bfa0 Fixed driver license dates that might be missing (thanks, Patrick!).
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   305
ca071626bfa0 Fixed driver license dates that might be missing (thanks, Patrick!).
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   306
    local birthdate = nil
ca071626bfa0 Fixed driver license dates that might be missing (thanks, Patrick!).
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   307
    if secure.birthdate_yy ~= nil then
ca071626bfa0 Fixed driver license dates that might be missing (thanks, Patrick!).
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   308
        birthdate = secure.birthdate_yy
ca071626bfa0 Fixed driver license dates that might be missing (thanks, Patrick!).
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   309
        if secure.birthdate_mm ~= nil then
ca071626bfa0 Fixed driver license dates that might be missing (thanks, Patrick!).
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   310
            birthdate = birthdate .. "/" .. string.sub("00" .. secure.birthdate_mm, -2)
ca071626bfa0 Fixed driver license dates that might be missing (thanks, Patrick!).
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   311
            if secure.birthdate_dd ~= nil then
ca071626bfa0 Fixed driver license dates that might be missing (thanks, Patrick!).
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   312
                birthdate = birthdate .. "/" .. string.sub("00" .. secure.birthdate_dd, -2)
ca071626bfa0 Fixed driver license dates that might be missing (thanks, Patrick!).
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   313
            end
ca071626bfa0 Fixed driver license dates that might be missing (thanks, Patrick!).
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   314
        end
ca071626bfa0 Fixed driver license dates that might be missing (thanks, Patrick!).
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   315
    end
ca071626bfa0 Fixed driver license dates that might be missing (thanks, Patrick!).
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   316
43
85b1cb11d948 Whoops, forgot to remove original code that I was fixing. :)
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
   317
    local expiredate = nil
42
ca071626bfa0 Fixed driver license dates that might be missing (thanks, Patrick!).
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   318
    if secure.expiry_date_yy ~= nil then
ca071626bfa0 Fixed driver license dates that might be missing (thanks, Patrick!).
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   319
        expiredate = secure.expiry_date_yy
ca071626bfa0 Fixed driver license dates that might be missing (thanks, Patrick!).
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   320
        if secure.expiry_date_mm ~= nil then
ca071626bfa0 Fixed driver license dates that might be missing (thanks, Patrick!).
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   321
            expiredate = expiredate .. "/" .. string.sub("00" .. secure.expiry_date_mm, -2)
ca071626bfa0 Fixed driver license dates that might be missing (thanks, Patrick!).
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   322
            if secure.expiry_date_dd ~= nil then
ca071626bfa0 Fixed driver license dates that might be missing (thanks, Patrick!).
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   323
                expiredate = expiredate .. "/" .. string.sub("00" .. secure.expiry_date_dd, -2)
ca071626bfa0 Fixed driver license dates that might be missing (thanks, Patrick!).
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   324
            end
ca071626bfa0 Fixed driver license dates that might be missing (thanks, Patrick!).
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   325
        end
ca071626bfa0 Fixed driver license dates that might be missing (thanks, Patrick!).
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   326
    end
ca071626bfa0 Fixed driver license dates that might be missing (thanks, Patrick!).
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   327
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   328
    build_secret_menuitem(menu, "License number", secure.number)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   329
    build_secret_menuitem(menu, "Class", secure.class)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   330
    build_secret_menuitem(menu, "Expires", expiredate)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   331
    build_secret_menuitem(menu, "State", secure.state)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   332
    build_secret_menuitem(menu, "Country", secure.country)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   333
    build_secret_menuitem(menu, "Conditions", secure.conditions)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   334
    build_secret_menuitem(menu, "Full name", secure.fullname)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   335
    build_secret_menuitem(menu, "Address", secure.address)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   336
    build_secret_menuitem(menu, "Gender", secure.sex)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   337
    build_secret_menuitem(menu, "Birthdate", birthdate)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   338
    build_secret_menuitem(menu, "Height", secure.height)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   339
end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   340
secret_menuitem_builders["wallet.government.DriversLicense"] = build_secret_menuitem_driverslic
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   341
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   342
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   343
local function build_secret_menuitem_membership(menu, info, secure)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   344
    -- !!! FIXME: there's more data than this in a generic dictionary.
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   345
    build_secret_menuitem(menu, "Membership number", secure.membership_no)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   346
end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   347
secret_menuitem_builders["wallet.membership.Membership"] = build_secret_menuitem_membership
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   348
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   349
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   350
local function build_secret_menuitem_creditcard(menu, info, secure)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   351
    -- !!! FIXME: there's more data than this in a generic dictionary.
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   352
    local expiredate = secure.expiry_yy .. "/" .. string.sub("00" .. secure.expiry_mm, -2)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   353
    build_secret_menuitem(menu, "Type", secure.type)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   354
    build_secret_menuitem(menu, "CC number", secure.ccnum, true)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   355
    build_secret_menuitem(menu, "CVV", secure.cvv, true)
38
115b6a0bd0af Fixed display of credit card expiration date.
Ryan C. Gordon <icculus@icculus.org>
parents: 37
diff changeset
   356
    build_secret_menuitem(menu, "Expires", expiredate)
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   357
    build_secret_menuitem(menu, "Card holder", secure.cardholder)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   358
    build_secret_menuitem(menu, "Bank", secure.bank)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   359
end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   360
secret_menuitem_builders["wallet.financial.CreditCard"] = build_secret_menuitem_creditcard
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   361
49
2c57a0ad7c8f Added some missing categories (US Social Security Numbers and Router logins).
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   362
25
44b6b8b34eb8 Added Secure Notes items to menu.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
   363
local function build_secret_menuitem_securenote(menu, info, secure)
44b6b8b34eb8 Added Secure Notes items to menu.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
   364
    build_secret_menuitem(menu, "Notes", secure.notesPlain, true)
44b6b8b34eb8 Added Secure Notes items to menu.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
   365
end
44b6b8b34eb8 Added Secure Notes items to menu.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
   366
secret_menuitem_builders["securenotes.SecureNote"] = build_secret_menuitem_securenote
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   367
49
2c57a0ad7c8f Added some missing categories (US Social Security Numbers and Router logins).
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   368
2c57a0ad7c8f Added some missing categories (US Social Security Numbers and Router logins).
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   369
local function build_secret_menuitem_ssnus(menu, info, secure)
2c57a0ad7c8f Added some missing categories (US Social Security Numbers and Router logins).
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   370
    build_secret_menuitem(menu, "Name", secure.name, false)
2c57a0ad7c8f Added some missing categories (US Social Security Numbers and Router logins).
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   371
    build_secret_menuitem(menu, "SSN", secure.number, true)
2c57a0ad7c8f Added some missing categories (US Social Security Numbers and Router logins).
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   372
end
2c57a0ad7c8f Added some missing categories (US Social Security Numbers and Router logins).
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   373
secret_menuitem_builders["wallet.government.SsnUS"] = build_secret_menuitem_ssnus
2c57a0ad7c8f Added some missing categories (US Social Security Numbers and Router logins).
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   374
2c57a0ad7c8f Added some missing categories (US Social Security Numbers and Router logins).
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   375
2c57a0ad7c8f Added some missing categories (US Social Security Numbers and Router logins).
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   376
local function build_secret_menuitem_router(menu, info, secure)
2c57a0ad7c8f Added some missing categories (US Social Security Numbers and Router logins).
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   377
    build_secret_menuitem(menu, "Name", secure.name, false)
2c57a0ad7c8f Added some missing categories (US Social Security Numbers and Router logins).
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   378
    build_secret_menuitem(menu, "Password", secure.password, true)
2c57a0ad7c8f Added some missing categories (US Social Security Numbers and Router logins).
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   379
end
2c57a0ad7c8f Added some missing categories (US Social Security Numbers and Router logins).
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   380
secret_menuitem_builders["wallet.computer.Router"] = build_secret_menuitem_router
2c57a0ad7c8f Added some missing categories (US Social Security Numbers and Router logins).
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   381
2c57a0ad7c8f Added some missing categories (US Social Security Numbers and Router logins).
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   382
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   383
local function build_secret_menuitems(info, menu)
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   384
    local metadata = load_json(basedir .. "/" .. info.uuid .. ".1password")
40
3c2fddfada9f Don't crash if you get one of these "{}" entries that 1Password makes.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   385
    if (metadata == nil) or (next(metadata) == nil) then  -- the "next" trick tests if table is empty.
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   386
        return
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   387
    end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   388
21
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   389
    local securityLevel = metadata.securityLevel
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   390
    if securityLevel == nil then
36
54a2884aba01 Fixed whitespace.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   391
        securityLevel = metadata.openContents.securityLevel
21
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   392
    end
30
c8f3db869ce0 Comment out some debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 29
diff changeset
   393
    --print("title: " .. metadata.title)
21
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   394
    if securityLevel == nil then
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   395
        --print("can't find security level, assuming SL5" .. metadata.title)
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   396
        securityLevel = "SL5"
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   397
    end
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   398
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   399
    local plaintext = decryptBase64UsingKey(metadata.encrypted, loadKey(securityLevel, password))
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   400
    if plaintext == nil then
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   401
        return
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   402
    end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   403
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   404
    local secure = load_json_str(plaintext, info.uuid)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   405
    if secure == nil then
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   406
        return
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   407
    end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   408
    --dumptable("secure " .. info.name, secure)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   409
45
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   410
    local menuitem = appendMenuItem(menu, info.name)
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   411
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   412
    if secret_menuitem_builders[info.type] == nil then
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   413
        print("WARNING: don't know how to handle items of type " .. info.type)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   414
        dumptable("secure " .. info.type .. " (" .. info.name .. ")", secure)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   415
        return
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   416
    end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   417
35
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   418
    if metadata.faveIndex ~= nil then
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   419
        --dumptable("fave metadata " .. info.name, metadata)
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   420
        faveitems[metadata.faveIndex] = { info=info, secure=secure }
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   421
    end
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   422
45
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   423
    local submenu = makeMenu()
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   424
    secret_menuitem_builders[info.type](submenu, info, secure)
45
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   425
    setMenuItemSubmenu(menuitem, submenu)
8
eada72719d17 Make the app basically useful.
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   426
end
eada72719d17 Make the app basically useful.
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   427
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   428
local function prepItems()
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   429
    items = {}
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   430
    local contents = loadContents()
44
2150bce729df Be more robust about i/o failures to the keychain.
Ryan C. Gordon <icculus@icculus.org>
parents: 43
diff changeset
   431
    if contents == nil then
2150bce729df Be more robust about i/o failures to the keychain.
Ryan C. Gordon <icculus@icculus.org>
parents: 43
diff changeset
   432
        return false
2150bce729df Be more robust about i/o failures to the keychain.
Ryan C. Gordon <icculus@icculus.org>
parents: 43
diff changeset
   433
    end
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   434
    for i,v in ipairs(contents) do
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   435
        local t = v[2]
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   436
        if items[t] == nil then
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   437
            items[t] = {}
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   438
        end
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   439
        local bucket = items[t]
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   440
        bucket[#bucket+1] = { uuid=v[1], type=t, name=v[3], url=v[4] }  -- !!! FIXME: there are more fields, don't know what they mean yet.
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   441
    end
44
2150bce729df Be more robust about i/o failures to the keychain.
Ryan C. Gordon <icculus@icculus.org>
parents: 43
diff changeset
   442
    return true
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   443
end
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   444
18
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   445
local passwordUnlockTime = nil
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   446
29
769393898e93 Forcibly lock keychain on timeout instead of checking timeout on next access.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   447
local function lockKeychain()
769393898e93 Forcibly lock keychain on timeout instead of checking timeout on next access.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   448
    -- lose the existing password and key, prompt user again.
769393898e93 Forcibly lock keychain on timeout instead of checking timeout on next access.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   449
    password = argv[2]  -- might be nil, don't reset if on command line.
769393898e93 Forcibly lock keychain on timeout instead of checking timeout on next access.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   450
    keys["SL5"] = nil
769393898e93 Forcibly lock keychain on timeout instead of checking timeout on next access.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   451
    passwordUnlockTime = nil
769393898e93 Forcibly lock keychain on timeout instead of checking timeout on next access.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   452
    setPowermateLED(false)
45
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   453
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   454
    -- kill the popup if it exists.
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   455
    if (keyhookGuiMenus ~= nil) and (keyhookGuiMenus[1] ~= nil) then
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   456
        guiDestroyMenu(keyhookGuiMenus[1])
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   457
    end
29
769393898e93 Forcibly lock keychain on timeout instead of checking timeout on next access.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   458
end
769393898e93 Forcibly lock keychain on timeout instead of checking timeout on next access.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   459
769393898e93 Forcibly lock keychain on timeout instead of checking timeout on next access.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   460
function pumpLua()  -- not local! Called from C!
769393898e93 Forcibly lock keychain on timeout instead of checking timeout on next access.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   461
    -- !!! FIXME: this should lose the key in RAM and turn off the Powermate
769393898e93 Forcibly lock keychain on timeout instead of checking timeout on next access.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   462
    -- !!! FIXME:  LED when the time expires instead of if the time has
769393898e93 Forcibly lock keychain on timeout instead of checking timeout on next access.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   463
    -- !!! FIXME:  expired when the user is trying to get at the keychain.
769393898e93 Forcibly lock keychain on timeout instead of checking timeout on next access.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   464
    if passwordUnlockTime ~= nil then
769393898e93 Forcibly lock keychain on timeout instead of checking timeout on next access.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   465
        local now = os.time()
769393898e93 Forcibly lock keychain on timeout instead of checking timeout on next access.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   466
        local maxTime = (15 * 60)  -- !!! FIXME: don't hardcode.
769393898e93 Forcibly lock keychain on timeout instead of checking timeout on next access.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   467
        if os.difftime(now, passwordUnlockTime) > maxTime then
769393898e93 Forcibly lock keychain on timeout instead of checking timeout on next access.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   468
            lockKeychain()
769393898e93 Forcibly lock keychain on timeout instead of checking timeout on next access.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   469
        end
769393898e93 Forcibly lock keychain on timeout instead of checking timeout on next access.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   470
    end
769393898e93 Forcibly lock keychain on timeout instead of checking timeout on next access.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   471
end
769393898e93 Forcibly lock keychain on timeout instead of checking timeout on next access.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   472
45
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   473
function escapePressed()  -- not local! Called from C!
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   474
    if keyhookGuiMenus[1] then
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   475
        guiDestroyMenu(keyhookGuiMenus[1])
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   476
    end
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   477
end
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   478
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   479
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   480
local buildGuiMenuList
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   481
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   482
local function spawnSubMenu(button, submenu, depth)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   483
    local guimenu = guiCreateSubMenu(button)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   484
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   485
    for i = #keyhookGuiMenus, depth, -1 do
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   486
        if keyhookGuiMenus[i] then
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   487
            --print("Destroying conflicting submenu at depth " .. i)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   488
            guiDestroyMenu(keyhookGuiMenus[i])
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   489
            keyhookGuiMenus[i] = nil
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   490
        end
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   491
    end
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   492
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   493
    --print("New submenu at depth " .. depth)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   494
    keyhookGuiMenus[depth] = guimenu
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   495
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   496
    buildGuiMenuList(guimenu, submenu)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   497
    guiShowWindow(guimenu)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   498
end
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   499
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   500
local function buildGuiMenuItem(guimenu, item)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   501
    local cb = item["callback"]
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   502
    if cb == nil then
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   503
        local submenu = item["submenu"]
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   504
        local depth = #keyhookGuiMenus+1
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   505
        cb = function (button)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   506
            return spawnSubMenu(button, submenu, depth)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   507
        end
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   508
    end
46
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   509
    guiAddMenuItem(guimenu, item["text"], item["checked"], cb)
45
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   510
end
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   511
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   512
buildGuiMenuList = function(guimenu, list)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   513
    for i,v in ipairs(list) do
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   514
        buildGuiMenuItem(guimenu, v)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   515
    end
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   516
end
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   517
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   518
local function buildSearchResultsMenuCategory(guimenu, menu, str)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   519
    local submenu = menu["submenu"]
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   520
    if not submenu then return end
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   521
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   522
    local name = menu["text"]
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   523
    -- !!! FIXME: hacky. We should really list favorites first anyhow.
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   524
    if name == "Favorites" then return end
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   525
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   526
    for i,v in ipairs(submenu) do
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   527
        if string.find(string.lower(v["text"]), str, 1, true) ~= nil then
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   528
            buildGuiMenuItem(guimenu, v)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   529
        end
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   530
    end
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   531
end
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   532
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   533
local function buildSearchResultsMenuList(guimenu, topmenu, str)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   534
    for i,v in ipairs(topmenu) do
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   535
        buildSearchResultsMenuCategory(guimenu, v, str)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   536
    end
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   537
end
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   538
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   539
local function searchEntryChanged(guimenu, str, topmenu)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   540
    --print("search changed to '" .. str .. "' ...")
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   541
    guiRemoveAllMenuItems(guimenu)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   542
    if str == "" then
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   543
        buildGuiMenuList(guimenu, topmenu)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   544
    else
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   545
        buildSearchResultsMenuList(guimenu, topmenu, string.lower(str))
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   546
    end
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   547
    guiShowWindow(guimenu)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   548
end
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   549
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   550
local function handleMenuDestroyed()
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   551
    --print("Destroying main menu...")
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   552
    for i,v in ipairs(keyhookGuiMenus) do
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   553
        if i > 1 then
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   554
            guiDestroyMenu(v)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   555
        end
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   556
    end
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   557
    keyhookGuiMenus = nil
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   558
    keyhookRunning = false
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   559
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   560
    runGarbageCollector()
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   561
end
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   562
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   563
local function launchGuiMenu(topmenu)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   564
    local guimenu = guiCreateTopLevelMenu("1pass",
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   565
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   566
        function(guimenu, str) -- search text changed callback
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   567
            return searchEntryChanged(guimenu, str, topmenu)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   568
        end,
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   569
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   570
        function()  -- window destroyed callback
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   571
            handleMenuDestroyed()
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   572
        end
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   573
    )
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   574
    keyhookGuiMenus = {}
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   575
    keyhookGuiMenus[#keyhookGuiMenus+1] = guimenu
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   576
    buildGuiMenuList(guimenu, topmenu)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   577
    guiShowWindow(guimenu)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   578
end
29
769393898e93 Forcibly lock keychain on timeout instead of checking timeout on next access.
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   579
46
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   580
local trustedDisks = {}
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   581
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   582
local function getTrustedDiskChecksumPath(mntpoint)
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   583
    return mntpoint .. "/1pass.dat"
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   584
end
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   585
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   586
local function getTrustedDiskChecksum(mntpoint)
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   587
    local f = io.open(getTrustedDiskChecksumPath(mntpoint), "rb")
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   588
    if f == nil then
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   589
        return nil
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   590
    end
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   591
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   592
    local str = f:read("*a")
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   593
    f:close()
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   594
    return calcSha256(str)
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   595
end
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   596
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   597
local function choseTrustedDisk(mntpoint)
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   598
    if trustedDisks[mntpoint] ~= nil then
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   599
        trustedDisks[mntpoint] = nil  -- no longer check existing trusted disk.
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   600
    else
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   601
        -- !!! FIXME: probably needs a message box if this fails.
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   602
        local checksum = getTrustedDiskChecksum(mntpoint)
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   603
        -- No checksum file yet? Generate and write out a random string.
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   604
        if checksum == nil then
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   605
            local f = io.open("/dev/urandom", "rb")
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   606
            if f ~= nil then
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   607
                local str = f:read(4096)
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   608
                f:close()
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   609
                if (str ~= nil) and (#str == 4096) then
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   610
                    f = io.open(getTrustedDiskChecksumPath(mntpoint), "wb")
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   611
                    if f ~= nil then
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   612
                        if f:write(str) and f:flush() then
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   613
                            checksum = calcSha256(str)
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   614
                        end
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   615
                        f:close()
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   616
                    end
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   617
                end
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   618
            end
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   619
        end
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   620
        trustedDisks[mntpoint] = checksum
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   621
    end
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   622
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   623
    -- kill the popup if it exists.
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   624
    -- !!! FIXME: put this in its own function, this is a copy/paste from elsewhere.
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   625
    if (keyhookGuiMenus ~= nil) and (keyhookGuiMenus[1] ~= nil) then
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   626
        guiDestroyMenu(keyhookGuiMenus[1])
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   627
    end
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   628
end
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   629
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   630
local function buildTrustedDeviceMenu()
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   631
    local menu = makeMenu()
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   632
    local disks = getMountedDisks()  -- this is a C function.
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   633
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   634
    table.sort(disks, function(a, b) return a < b end)
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   635
    for i,v in ipairs(disks) do
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   636
        local item = appendMenuItem(menu, v, function() choseTrustedDisk(v) end)
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   637
        if trustedDisks[v] ~= nil then
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   638
            setMenuItemChecked(item, true)
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   639
        end
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   640
    end
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   641
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   642
    return menu
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   643
end
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   644
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   645
function keyhookPressed()  -- not local! Called from C!
45
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   646
    --print("keyhookPressed: running==" .. tostring(keyhookRunning))
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   647
    if keyhookRunning then
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   648
        return
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   649
    end
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   650
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   651
    keyhookRunning = true
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   652
46
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   653
    local allowaccess = true;
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   654
    for mntpoint,checksum in pairs(trustedDisks) do
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   655
        if getTrustedDiskChecksum(mntpoint) ~= checksum then
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   656
            allowaccess = false
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   657
            break
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   658
        end
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   659
    end
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   660
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   661
    if not allowaccess then
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   662
        -- !!! FIXME: probably needs a message box if this happens.
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   663
        keyhookRunning = false
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   664
        return
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   665
    end
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   666
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   667
    while password == nil do
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   668
        password = runGuiPasswordPrompt(getHint())
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   669
        if password == nil then
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   670
            keyhookRunning = false
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   671
            return
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   672
        end
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   673
        if loadKey("SL5", password) == nil then
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   674
            password = nil  -- wrong password
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   675
            local start = os.time()  -- cook the CPU for three seconds.
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   676
            local now = start
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   677
            while os.difftime(now, start) < 3 do
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   678
                now = os.time()
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   679
            end
18
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   680
        else
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   681
            passwordUnlockTime = os.time()
28
60136c984e3b Hooked up support for a Griffin Powermate.
Ryan C. Gordon <icculus@icculus.org>
parents: 27
diff changeset
   682
            setPowermateLED(true)
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   683
        end
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   684
    end
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   685
44
2150bce729df Be more robust about i/o failures to the keychain.
Ryan C. Gordon <icculus@icculus.org>
parents: 43
diff changeset
   686
    if not prepItems() then
2150bce729df Be more robust about i/o failures to the keychain.
Ryan C. Gordon <icculus@icculus.org>
parents: 43
diff changeset
   687
        keyhookRunning = false
2150bce729df Be more robust about i/o failures to the keychain.
Ryan C. Gordon <icculus@icculus.org>
parents: 43
diff changeset
   688
        return
2150bce729df Be more robust about i/o failures to the keychain.
Ryan C. Gordon <icculus@icculus.org>
parents: 43
diff changeset
   689
    end
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   690
45
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   691
    local topmenu = makeMenu()
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   692
    local favesmenu = makeMenu()
46
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   693
    local securitymenu = makeMenu()
35
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   694
    faveitems = {}
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   695
45
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   696
    setMenuItemSubmenu(appendMenuItem(topmenu, "Favorites"), favesmenu)
46
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   697
    setMenuItemSubmenu(appendMenuItem(topmenu, "Security"), securitymenu)
18
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   698
46
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   699
    appendMenuItem(securitymenu, "Lock keychain now", function() lockKeychain() end)
fe4f59680246 Added experimental support for using a "trusted device."
Ryan C. Gordon <icculus@icculus.org>
parents: 45
diff changeset
   700
    setMenuItemSubmenu(appendMenuItem(securitymenu, "Require trusted device"), buildTrustedDeviceMenu())
18
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   701
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   702
    for orderi,type in ipairs(passwordTypeOrdering) do
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   703
        local bucket = items[type]
21
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   704
        if bucket ~= nil then
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   705
            local realname = passwordTypeNameMap[type]
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   706
            if realname == nil then
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   707
                realname = type
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   708
            end
45
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   709
            local menuitem = appendMenuItem(topmenu, realname)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   710
            local submenu = makeMenu()
21
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   711
            table.sort(bucket, function(a, b) return a.name < b.name end)
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   712
            for i,v in pairs(bucket) do
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   713
                build_secret_menuitems(v, submenu)
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   714
            end
45
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   715
            setMenuItemSubmenu(menuitem, submenu)
21
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   716
        else
37
7cdad5c73521 Improved, then commented out, some debug output.
Ryan C. Gordon <icculus@icculus.org>
parents: 36
diff changeset
   717
            --print("no bucket found for item type '" .. type .. "'")
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   718
        end
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   719
    end
35
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   720
    
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   721
    -- This favepairs stuff is obnoxious.
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   722
    local function favepairs(t)
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   723
        local a = {}
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   724
        for n in pairs(t) do table.insert(a, n) end
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   725
        table.sort(a)
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   726
        local i = 0
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   727
        local iter = function()
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   728
            i = i + 1
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   729
            if a[i] == nil then
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   730
                return nil
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   731
            else
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   732
                return a[i], t[a[i]]
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   733
            end
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   734
        end
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   735
        return iter
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   736
    end
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   737
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   738
    for i,v in favepairs(faveitems) do
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   739
        --dumptable("fave " .. i, v)
45
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   740
        local menuitem = appendMenuItem(favesmenu, v.info.name)
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   741
        local submenu = makeMenu()
35
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   742
        secret_menuitem_builders[v.info.type](submenu, v.info, v.secure)
45
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   743
        setMenuItemSubmenu(menuitem, submenu)
35
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   744
    end
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   745
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   746
    favepairs = nil
4a970a4f6bc1 Added favorites submenu.
Ryan C. Gordon <icculus@icculus.org>
parents: 32
diff changeset
   747
    faveitems = nil
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   748
45
cf6a06f368e6 Moved to a more robust GTK UI.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
   749
    launchGuiMenu(topmenu)
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   750
end
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   751
6
b7f19e0599db Dump out all the encrypted data.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   752
1
0919d17b13f9 Move the mainline into Lua.
Ryan C. Gordon <icculus@icculus.org>
parents: 0
diff changeset
   753
-- Mainline!
0919d17b13f9 Move the mainline into Lua.
Ryan C. Gordon <icculus@icculus.org>
parents: 0
diff changeset
   754
7
682d7ea1e7f3 Moved command lines into Lua.
Ryan C. Gordon <icculus@icculus.org>
parents: 6
diff changeset
   755
--for i,v in ipairs(argv) do
682d7ea1e7f3 Moved command lines into Lua.
Ryan C. Gordon <icculus@icculus.org>
parents: 6
diff changeset
   756
--    print("argv[" .. i .. "] = " .. v)
682d7ea1e7f3 Moved command lines into Lua.
Ryan C. Gordon <icculus@icculus.org>
parents: 6
diff changeset
   757
--end
682d7ea1e7f3 Moved command lines into Lua.
Ryan C. Gordon <icculus@icculus.org>
parents: 6
diff changeset
   758
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   759
-- !!! FIXME: message box, exit if basedir is wack.
44
2150bce729df Be more robust about i/o failures to the keychain.
Ryan C. Gordon <icculus@icculus.org>
parents: 43
diff changeset
   760
local f = io.open(basedir .. "/contents.js", "rb")
2150bce729df Be more robust about i/o failures to the keychain.
Ryan C. Gordon <icculus@icculus.org>
parents: 43
diff changeset
   761
if f == nil then
2150bce729df Be more robust about i/o failures to the keychain.
Ryan C. Gordon <icculus@icculus.org>
parents: 43
diff changeset
   762
    print("ERROR: Couldn't read your 1Password keychain in '" .. basedir .. "'.")
2150bce729df Be more robust about i/o failures to the keychain.
Ryan C. Gordon <icculus@icculus.org>
parents: 43
diff changeset
   763
    print("ERROR: Please make sure it exists and you have permission to access it.")
2150bce729df Be more robust about i/o failures to the keychain.
Ryan C. Gordon <icculus@icculus.org>
parents: 43
diff changeset
   764
    print("ERROR: (maybe you need to run 'ln -s ~/Dropbox/1Password' here?")
2150bce729df Be more robust about i/o failures to the keychain.
Ryan C. Gordon <icculus@icculus.org>
parents: 43
diff changeset
   765
    print("ERROR: Giving up for now.")
2150bce729df Be more robust about i/o failures to the keychain.
Ryan C. Gordon <icculus@icculus.org>
parents: 43
diff changeset
   766
    os.exit(1)
2150bce729df Be more robust about i/o failures to the keychain.
Ryan C. Gordon <icculus@icculus.org>
parents: 43
diff changeset
   767
end
2150bce729df Be more robust about i/o failures to the keychain.
Ryan C. Gordon <icculus@icculus.org>
parents: 43
diff changeset
   768
f:close()
2150bce729df Be more robust about i/o failures to the keychain.
Ryan C. Gordon <icculus@icculus.org>
parents: 43
diff changeset
   769
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   770
-- !!! FIXME: this can probably happen in C now (the Lua mainline is basically gone now).
28
60136c984e3b Hooked up support for a Griffin Powermate.
Ryan C. Gordon <icculus@icculus.org>
parents: 27
diff changeset
   771
setPowermateLED(false)  -- off by default
27
d4d54dc1ee5f Print a message to stdout at startup, for people that think the app froze up.
Ryan C. Gordon <icculus@icculus.org>
parents: 25
diff changeset
   772
print("Now waiting for the magic key combo (probably Alt-Meta-\\) ...")
11
b52e0f1798b8 Start building in GUI stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 9
diff changeset
   773
giveControlToGui()
b52e0f1798b8 Start building in GUI stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 9
diff changeset
   774
0
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   775
-- end of 1pass.lua ...
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   776