1pass.lua
author Ryan C. Gordon <icculus@icculus.org>
Sun, 09 Feb 2014 00:17:23 -0500
changeset 22 9adb804d66b0
parent 21 9884f4078c68
child 24 c34cc914f09d
permissions -rw-r--r--
Commented out a debug string.
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
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
     7
local keyhookRunning = false
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
     8
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
     9
local passwordTypeNameMap = {
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    10
    ["webforms.WebForm"] = "Logins",
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    11
    ["wallet.financial.CreditCard"] = "Credit cards",
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    12
    ["passwords.Password"] = "Passwords",
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    13
    ["wallet.financial.BankAccountUS"] = "Bank accounts",
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    14
    ["wallet.membership.Membership"] = "Memberships",
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    15
    ["wallet.government.DriversLicense"] = "Drivers licenses",
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    16
    ["system.Tombstone"] = "Dead items",
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    17
    -- !!! FIXME: more!
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    18
}
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    19
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    20
local passwordTypeOrdering = {
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    21
    "webforms.WebForm",
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    22
    "wallet.financial.CreditCard",
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    23
    "passwords.Password",
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    24
    "wallet.financial.BankAccountUS",
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    25
    "wallet.membership.Membership",
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    26
    "wallet.government.DriversLicense",
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    27
    -- never show "system.Tombstone",
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    28
    -- !!! FIXME: more!
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    29
}
0
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
6
b7f19e0599db Dump out all the encrypted data.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    31
local function load_json_str(str, desc)
b7f19e0599db Dump out all the encrypted data.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    32
    local retval = JSON:decode(str)
b7f19e0599db Dump out all the encrypted data.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    33
    return retval
b7f19e0599db Dump out all the encrypted data.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    34
end
b7f19e0599db Dump out all the encrypted data.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    35
0
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
local function load_json(fname)
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
    local f = io.open(fname, "rb")
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
    if (f == nil) then
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
        return nil
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
    end
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
    local str = f:read("*all")
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
    f:close()
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
6
b7f19e0599db Dump out all the encrypted data.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    45
    return load_json_str(str, fname)
0
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
end
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
5
6f80cd157c13 Cache loaded encryption keys.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
    49
local keys = {}
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
    50
local function loadKey(level, password)
5
6f80cd157c13 Cache loaded encryption keys.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
    51
    if keys[level] ~= nil then
6f80cd157c13 Cache loaded encryption keys.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
    52
        return keys[level]
6f80cd157c13 Cache loaded encryption keys.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
    53
    end
6f80cd157c13 Cache loaded encryption keys.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
    54
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    55
    local keysjson = load_json(basedir .. "/encryptionKeys.js")
0
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
    if (keysjson == nil) or (keysjson[level] == nil) then
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
        return nil
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
    end
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
    local identifier = keysjson[level]
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
    for i,v in ipairs(keysjson.list) do
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
        if v.identifier == identifier then
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
			local iterations = v.iterations
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
            if (iterations == nil) or (iterations < 1000) then
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
			    iterations = 1000
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
            end
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
			local decrypted = decryptUsingPBKDF2(v.data, password, iterations)
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
			if decrypted == nil then
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
                return nil
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
            end
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
			local validate = decryptBase64UsingKey(v.validation, decrypted)
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
			if validate ~= decrypted then
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
                return nil
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
            end
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
5
6f80cd157c13 Cache loaded encryption keys.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
    78
            keys[level] = decrypted
0
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
            return decrypted
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
        end
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
    end
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
    return nil
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
end
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
    86
local function getHint()
0
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
    local f = io.open(basedir .. "/.password.hint", "r")
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
    if (f == nil) then
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
        return
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
    end
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    92
    local str = "(hint is '" .. f:read("*all") .. "')."
0
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
    f:close()
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    94
    --print(str)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
    95
    return str
0
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
end
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
1
0919d17b13f9 Move the mainline into Lua.
Ryan C. Gordon <icculus@icculus.org>
parents: 0
diff changeset
    98
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
    99
local function loadContents()
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   100
    return load_json(basedir .. "/contents.js")
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   101
end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   102
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   103
local function build_secret_menuitem(menu, type, str, hidden)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   104
    if str == nil then
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   105
        return nil
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   106
    end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   107
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   108
    local valuestr = str
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   109
    if hidden == true then
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   110
        valuestr = "*****"
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   111
    end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   112
    local text = type .. " " .. valuestr
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   113
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   114
    local callback = function()
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   115
        copyToClipboard(str)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   116
        --print("Copied data [" .. str .. "] to clipboard.")
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   117
        keyhookRunning = false
12
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
    return appendGuiMenuItem(menu, text, callback)
6
b7f19e0599db Dump out all the encrypted data.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   120
end
b7f19e0599db Dump out all the encrypted data.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   121
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   122
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   123
local secret_menuitem_builders = {}
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   124
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   125
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
   126
    local addthis = false
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   127
    local username = nil
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   128
    local password = nil
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   129
    local email = nil
21
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   130
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   131
    for i,v in ipairs(secure.fields) do
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   132
        --print(info.name .. ": " .. v.type .. ", " .. v.value)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   133
        local ignored = false
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   134
        if (v.type == "P") and (password == nil) and (v.value ~= "") then
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   135
            password = v.value
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   136
        elseif (v.type == "T") and (usenname == nil) and (v.value ~= "") then
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   137
            username = v.value
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   138
        elseif (v.type == "E") and (email == nil) and (v.value ~= "") then
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   139
            email = v.value
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   140
        else
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   141
            ignored = true
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   142
        end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   143
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   144
        if not ignored then
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   145
            addthis = true
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
    end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   148
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   149
    if addthis then
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   150
        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
   151
            email = nil
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   152
        end
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
        build_secret_menuitem(menu, "username", username)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   155
        build_secret_menuitem(menu, "email", email)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   156
        build_secret_menuitem(menu, "password", password, true)
8
eada72719d17 Make the app basically useful.
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   157
    end
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   158
end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   159
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
   160
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   161
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   162
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
   163
    build_secret_menuitem(menu, "password", secure.password, true)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   164
end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   165
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
   166
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   167
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   168
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
   169
    -- !!! 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
   170
    build_secret_menuitem(menu, "Account type", secure.accountType)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   171
    build_secret_menuitem(menu, "Routing number", secure.routingNo)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   172
    build_secret_menuitem(menu, "Account number", secure.accountNo)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   173
    build_secret_menuitem(menu, "Bank name", secure.bankName)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   174
    build_secret_menuitem(menu, "Owner", secure.owner)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   175
end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   176
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
   177
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   178
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   179
local function build_secret_menuitem_driverslic(menu, info, secure)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   180
    -- !!! 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
   181
    local birthdate = secure.birthdate_yy .. "/" .. string.sub("00" .. secure.birthdate_mm, -2) .. "/" .. string.sub("00" .. secure.birthdate_dd, -2)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   182
    local expiredate = secure.expiry_date_yy .. "/" .. string.sub("00" .. secure.expiry_date_mm, -2)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   183
    build_secret_menuitem(menu, "License number", secure.number)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   184
    build_secret_menuitem(menu, "Class", secure.class)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   185
    build_secret_menuitem(menu, "Expires", expiredate)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   186
    build_secret_menuitem(menu, "State", secure.state)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   187
    build_secret_menuitem(menu, "Country", secure.country)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   188
    build_secret_menuitem(menu, "Conditions", secure.conditions)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   189
    build_secret_menuitem(menu, "Full name", secure.fullname)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   190
    build_secret_menuitem(menu, "Address", secure.address)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   191
    build_secret_menuitem(menu, "Gender", secure.sex)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   192
    build_secret_menuitem(menu, "Birthdate", birthdate)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   193
    build_secret_menuitem(menu, "Height", secure.height)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   194
end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   195
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
   196
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   197
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   198
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
   199
    -- !!! 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
   200
    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
   201
end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   202
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
   203
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   204
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   205
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
   206
    -- !!! 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
   207
    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
   208
    build_secret_menuitem(menu, "Type", secure.type)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   209
    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
   210
    build_secret_menuitem(menu, "CVV", secure.cvv, true)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   211
    build_secret_menuitem(menu, "Expires", secure.expirydate)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   212
    build_secret_menuitem(menu, "Card holder", secure.cardholder)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   213
    build_secret_menuitem(menu, "Bank", secure.bank)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   214
end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   215
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
   216
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   217
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   218
local function build_secret_menuitems(info, menu)
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   219
    local metadata = load_json(basedir .. "/" .. info.uuid .. ".1password")
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   220
    if metadata == nil then
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   221
        return
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   222
    end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   223
21
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   224
    local securityLevel = metadata.securityLevel
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   225
    if securityLevel == nil then
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   226
	securityLevel = metadata.openContents.securityLevel
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   227
    end
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   228
    print("title: " .. metadata.title)
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   229
    if securityLevel == nil then
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   230
        --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
   231
        securityLevel = "SL5"
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   232
    end
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   233
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   234
    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
   235
    if plaintext == nil then
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   236
        return
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   237
    end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   238
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   239
    local secure = load_json_str(plaintext, info.uuid)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   240
    if secure == nil then
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   241
        return
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   242
    end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   243
    --dumptable("secure " .. info.name, secure)
21
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   244
    if secure.fields == nil then
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   245
      print("no secure fields, don't know how to handle this item") 
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   246
      return
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   247
    end
12
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   248
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   249
    local menuitem = appendGuiMenuItem(menu, info.name)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   250
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   251
    if secret_menuitem_builders[info.type] == nil then
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   252
        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
   253
        dumptable("secure " .. info.type .. " (" .. info.name .. ")", secure)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   254
        return
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   255
    end
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   256
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   257
    local submenu = makeGuiMenu()
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   258
    secret_menuitem_builders[info.type](submenu, info, secure)
6a2d5b34d5ca Whole bunch of GUI work.
Ryan C. Gordon <icculus@icculus.org>
parents: 11
diff changeset
   259
    setGuiMenuItemSubmenu(menuitem, submenu)
8
eada72719d17 Make the app basically useful.
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   260
end
eada72719d17 Make the app basically useful.
Ryan C. Gordon <icculus@icculus.org>
parents: 7
diff changeset
   261
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   262
local function prepItems()
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   263
    items = {}
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   264
    local contents = loadContents()
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   265
    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
   266
        local t = v[2]
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   267
        if items[t] == nil then
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   268
            items[t] = {}
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   269
        end
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   270
        local bucket = items[t]
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   271
        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
   272
    end
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   273
end
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   274
18
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   275
local passwordUnlockTime = nil
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   276
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   277
function keyhookPressed()  -- not local! Called from C!
22
9adb804d66b0 Commented out a debug string.
Ryan C. Gordon <icculus@icculus.org>
parents: 21
diff changeset
   278
--print("keyhookPressed: running==" .. tostring(keyhookRunning))
19
bee74433ed86 Added LICENSE.txt
Ryan C. Gordon <icculus@icculus.org>
parents: 18
diff changeset
   279
--    if keyhookRunning then
bee74433ed86 Added LICENSE.txt
Ryan C. Gordon <icculus@icculus.org>
parents: 18
diff changeset
   280
--        return
bee74433ed86 Added LICENSE.txt
Ryan C. Gordon <icculus@icculus.org>
parents: 18
diff changeset
   281
--    end
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   282
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   283
    keyhookRunning = true
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   284
18
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   285
    if passwordUnlockTime ~= nil then
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   286
        local now = os.time()
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   287
        local maxTime = (15 * 60)  -- !!! FIXME: don't hardcode.
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   288
        if os.difftime(now, passwordUnlockTime) > maxTime then
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   289
            -- lose the existing password and key, prompt user again.
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   290
            password = argv[2]  -- might be nil, don't reset if on command line.
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   291
            keys["SL5"] = nil
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   292
        end
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   293
    end
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   294
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   295
    while password == nil do
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   296
        password = runGuiPasswordPrompt(getHint())
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   297
        if password == nil then
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   298
            keyhookRunning = false
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   299
            return
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   300
        end
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   301
        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
   302
            password = nil  -- wrong password
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   303
            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
   304
            local now = start
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   305
            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
   306
                now = os.time()
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   307
            end
18
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   308
        else
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   309
            passwordUnlockTime = os.time()
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   310
        end
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   311
    end
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   312
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   313
    prepItems()
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   314
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   315
    local topmenu = makeGuiMenu()
18
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   316
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   317
    local lock_callback = function()
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   318
        password = argv[2]  -- might be nil, don't reset if on command line.
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   319
        keys["SL5"] = nil
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   320
        passwordUnlockTime = nil
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   321
        keyhookRunning = false
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   322
    end
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   323
    appendGuiMenuItem(topmenu, "Lock keychain", lock_callback)
e7821efc78f6 Added some keychain lock management.
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   324
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   325
    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
   326
        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
   327
        if bucket ~= nil then
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   328
            local realname = passwordTypeNameMap[type]
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   329
            if realname == nil then
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   330
                realname = type
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   331
            end
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   332
            local menuitem = appendGuiMenuItem(topmenu, realname)
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   333
            local submenu = makeGuiMenu()
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   334
            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
   335
            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
   336
                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
   337
            end
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   338
            setGuiMenuItemSubmenu(menuitem, submenu)
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   339
        else
9884f4078c68 Build on Ubuntu 12.04, fix some crash problems
Robbie Vanbrabant <robbie.vanbrabant@gmail.com>
parents: 19
diff changeset
   340
            print("no bucket found")
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   341
        end
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   342
    end
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   343
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   344
    popupGuiMenu(topmenu)
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   345
end
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   346
6
b7f19e0599db Dump out all the encrypted data.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
   347
1
0919d17b13f9 Move the mainline into Lua.
Ryan C. Gordon <icculus@icculus.org>
parents: 0
diff changeset
   348
-- Mainline!
0919d17b13f9 Move the mainline into Lua.
Ryan C. Gordon <icculus@icculus.org>
parents: 0
diff changeset
   349
7
682d7ea1e7f3 Moved command lines into Lua.
Ryan C. Gordon <icculus@icculus.org>
parents: 6
diff changeset
   350
--for i,v in ipairs(argv) do
682d7ea1e7f3 Moved command lines into Lua.
Ryan C. Gordon <icculus@icculus.org>
parents: 6
diff changeset
   351
--    print("argv[" .. i .. "] = " .. v)
682d7ea1e7f3 Moved command lines into Lua.
Ryan C. Gordon <icculus@icculus.org>
parents: 6
diff changeset
   352
--end
682d7ea1e7f3 Moved command lines into Lua.
Ryan C. Gordon <icculus@icculus.org>
parents: 6
diff changeset
   353
17
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   354
-- !!! FIXME: message box, exit if basedir is wack.
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   355
-- !!! FIXME: this can probably happen in C now (the Lua mainline is basically gone now).
e884dbb403cc Added keyhook code, reworked things to use it.
Ryan C. Gordon <icculus@icculus.org>
parents: 12
diff changeset
   356
--print("Now waiting for keyhook.")
11
b52e0f1798b8 Start building in GUI stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 9
diff changeset
   357
giveControlToGui()
b52e0f1798b8 Start building in GUI stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 9
diff changeset
   358
0
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   359
-- end of 1pass.lua ...
d7ee4e2ed49d Initial work.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   360