Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions bitwarden/lua/bitwarden/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function M.new(opts)
local session
local backend = {}

local function unlock(cb)
local function unlock(cb, progress)
if session then
return cb(session)
end
Expand All @@ -26,6 +26,7 @@ function M.new(opts)
if not password or password == "" then
return cb(nil)
end
progress("unlocking the vault")
site.run(rt.spawn, { cmd, "unlock", "--passwordenv", "RT_BW_PASSWORD", "--raw" },
{ env = { RT_BW_PASSWORD = password } },
function(out)
Expand All @@ -35,6 +36,7 @@ function M.new(opts)
function(err) cb(nil, err) end)
end
local function ask()
progress("waiting for your master password")
rt.ui.input({ prompt = "Bitwarden master password", secret = true }, with)
end
-- The master password saved on the Plugins tab, from the OS keyring (riptide 0.4+).
Expand All @@ -47,11 +49,13 @@ function M.new(opts)
end
end

local function search(host, cb, retried)
local function search(host, cb, progress, retried)
progress = progress or function() end
unlock(function(key, err)
if not key then
return cb(nil, err)
end
progress("searching the vault")
site.run(rt.spawn, { cmd, "list", "items", "--search", site.search_term(host) }, { env = { BW_SESSION = key } },
function(out)
local ok, items = pcall(rt.json.decode, out)
Expand Down Expand Up @@ -83,9 +87,9 @@ function M.new(opts)
if retried or not (e:lower():find("lock") or e:lower():find("session")) then
return cb(nil, e)
end
search(host, cb, true)
search(host, cb, progress, true)
end)
end)
end, progress)
end

backend.find = search
Expand Down
14 changes: 10 additions & 4 deletions keepassxc/lua/keepassxc/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ function M.new(opts)
return out
end

local function with_password(cb)
local function with_password(cb, progress)
if cached and remember > 0 and os.time() - cached_at < remember then
return cb(cached)
end
cached = nil
local function ask()
progress("waiting for the database password")
rt.ui.input({ prompt = "KeePassXC database password", secret = true }, function(password)
if not password then
return cb(nil)
Expand All @@ -83,19 +84,22 @@ function M.new(opts)
end
end

function backend.find(host, cb)
function backend.find(host, cb, progress)
progress = progress or function() end
with_password(function(password)
if not password then
return cb(nil)
end
local input = { stdin = password .. "\n" }
progress("opening the database")
site.run(rt.spawn, argv("search", site.search_term(host)), input, function(out)
local paths = {}
for _, path in ipairs(site.lines(out)) do
if #paths < site.MAX_CANDIDATES then
table.insert(paths, path)
end
end
progress("reading entries", 0, #paths)
site.each(paths, function(path, done)
site.run(rt.spawn, argv("show", "-s", "-a", "Title", "-a", "UserName", "-a", "Password", "-a", "URL", path), input,
function(shown)
Expand All @@ -111,13 +115,15 @@ function M.new(opts)
done({ label = label, saved = { url, title }, login = { username = username ~= "" and username or nil, password = pass } })
end,
function() done(nil) end)
end, function(entries) cb(entries) end)
end, function(entries) cb(entries) end, function(n, total)
progress("reading entries", n, total)
end)
end, function(err)
-- Most likely a wrong password; don't keep it.
cached = nil
cb(nil, err)
end)
end)
end, progress)
end

function backend.get(entry, cb)
Expand Down
3 changes: 2 additions & 1 deletion pass/lua/pass/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ function M.new(opts)
local cmd = command(opts)
local backend = {}

function backend.find(host, cb)
function backend.find(host, cb, progress)
if progress then progress("listing the store") end
local argv, run_opts
if gopass then
argv = { cmd, "ls", "--flat" }
Expand Down
26 changes: 20 additions & 6 deletions pass/test/pass_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,35 @@ local function open_login()
run("open " .. page("login.html"))
wait_for("load_finished", { pattern = "plugin-test.localhost" })
end
-- The passwords picker, once its logins have arrived.
local function open_picker()
local passwords = require("passwords")
wait_until(function()
local p = passwords.picker()
return p and p.ready
end)
wait(200)
return passwords.picker()
end

describe("pass", function()
it("offers the site's entries and fills the one picked", function()
open_login()
run("password-fill")
-- Two entries belong here; the lookalike sites' don't. The picker's keys
-- follow the entries' order.
wait(500)
keys("1")
-- Two entries belong here; the lookalike sites' don't.
local picker = open_picker()
picker.type("alice")
wait(200)
picker.key("Enter")
wait_field("pass", "pw-alice")
assert.equals("alice@example.com", field("user"))

-- The username alone, from the path after the site.
run("password-fill-username")
wait(500)
keys("2")
picker = open_picker()
picker.type("bob")
wait(200)
picker.key("Enter")
wait_field("user", "bob")
assert.equals("pw-alice", field("pass"), "only the username changed")
end)
Expand Down
16 changes: 12 additions & 4 deletions passwords/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,22 @@ one with it.
| [keepassxc](../keepassxc) | a KeePassXC database (`keepassxc-cli`) |

`<Space>pp` (`:password-fill`) fills the username and password, `<Space>pu`
the username and `<Space>pw` the password. With several password managers on,
the picker lists the logins of all of them. Add this plugin yourself only to
change its options:
the username and `<Space>pw` the password. While the password managers unlock
and search, a box in the top-right corner shows how each is getting on, then
what was filled.

When the site has several logins, a picker opens over the page: type to filter
them, Enter fills, Alt-u fills only the username and Alt-p only the password.
`<Space>ps` (`:password-search`) opens it even for one login. With several
password managers on, it lists the logins of all of them. The picker only sees
each login's name; the passwords stay with the plugin.

Add this plugin yourself only to change its options:

```lua
rt.pack.add({ "https://github.com/joshzcold/riptide-plugins", subdir = "passwords", opts = {
submit = true, -- press the form's button after :password-fill
keys = { login = "<Ctrl-Shift-l>" }, -- your own keys; false for none
keys = { login = "<Ctrl-Shift-l>", search = "<Ctrl-Shift-k>" }, -- your own keys; false for none
} })
```

Expand Down
Loading
Loading