1pass.lua
changeset 6 b7f19e0599db
parent 5 6f80cd157c13
child 7 682d7ea1e7f3
equal deleted inserted replaced
5:6f80cd157c13 6:b7f19e0599db
    40     if tabname ~= nil then
    40     if tabname ~= nil then
    41         print("}")
    41         print("}")
    42     end
    42     end
    43 end
    43 end
    44 
    44 
       
    45 local function load_json_str(str, desc)
       
    46     local retval = JSON:decode(str)
       
    47     dumptable("JSON " .. desc, retval)
       
    48     return retval
       
    49 end
       
    50 
    45 local function load_json(fname)
    51 local function load_json(fname)
    46     local f = io.open(fname, "rb")
    52     local f = io.open(fname, "rb")
    47     if (f == nil) then
    53     if (f == nil) then
    48         return nil
    54         return nil
    49     end
    55     end
    50 
    56 
    51     local str = f:read("*all")
    57     local str = f:read("*all")
    52     f:close()
    58     f:close()
    53 
    59 
    54     local retval = JSON:decode(str)
    60     return load_json_str(str, fname)
    55     dumptable("JSON " .. fname, retval)
       
    56     return retval
       
    57 end
    61 end
    58 
    62 
    59 
    63 
    60 local keys = {}
    64 local keys = {}
    61 function loadKey(basedir, level, password)
    65 function loadKey(basedir, level, password)
   105 
   109 
   106     print("(hint is '" .. str .. "').")
   110     print("(hint is '" .. str .. "').")
   107 end
   111 end
   108 
   112 
   109 
   113 
       
   114 function loadContents(basedir)
       
   115     return load_json(basedir .. "/contents.js");
       
   116 end
       
   117 
       
   118 
   110 -- Mainline!
   119 -- Mainline!
   111 
   120 
   112 local basedir = "1Password/1Password.agilekeychain/data/default"  -- !!! FIXME
   121 local basedir = "1Password/1Password.agilekeychain/data/default"  -- !!! FIXME
   113 
   122 
   114 showHint(basedir)
   123 showHint(basedir)
   118 if loadKey(basedir, "SL5", password) == nil then
   127 if loadKey(basedir, "SL5", password) == nil then
   119     print("wrong password?\n")
   128     print("wrong password?\n")
   120     os.exit(1)
   129     os.exit(1)
   121 end
   130 end
   122 
   131 
   123 
   132 items = loadContents(basedir)
       
   133 for i,v in ipairs(items) do
       
   134     if v[2] ~= "system.Tombstone" then  -- I guess those are dead items?
       
   135         local metadata = load_json(basedir .. "/" .. v[1] .. ".1password")
       
   136         if metadata ~= nil then
       
   137             local plaintext = decryptBase64UsingKey(metadata.encrypted, loadKey(basedir, metadata.securityLevel, password))
       
   138             if plaintext ~= nil then
       
   139                 local secure = load_json_str(plaintext, v[1])
       
   140             end
       
   141         end
       
   142     end
       
   143 end
   124 
   144 
   125 -- end of 1pass.lua ...
   145 -- end of 1pass.lua ...
   126 
   146