Pick a KeePassXC entry in the minibuffer, copy or type it, and forget it.
keepass-pick is a small wrapper around keepassxc-cli. It does not reinvent a KeePass client. It gives Emacs a dmenu-like interface to your database: one prompt to pick an entry, one to pick a field, and the secret goes where you need it.
There is no buffer, no mode and nothing to manage. Pick, complete, forget. It should never get in the way.
Many Emacs packages already talk to KeePass (see Credits). Each one solves it in its own way: a tree buffer, an Ivy front end, the browser protocol with a running app, or a compiled module.
keepass-pick keeps only the essential:
- Every choice is a
completing-read. Vertico, Orderless, Marginalia and Embark integrate well. The entry list has the completion categorykeepass-pick-entry. - Built-ins only.
keepassxc-cliis the one external program. - A copied secret leaves the kill ring and the clipboard after 30 seconds.
- Anything bigger belongs in the KeePassXC app: delete, groups, attachments, TOTP setup, history.
(use-package keepass-pick
:vc (:url "https://github.com/idlip/keepass-pick")
:config
(setopt keepass-pick-database "~/Passwords.kdbx")
(keymap-global-set "C-c k" #'keepass-pick)
(with-eval-after-load 'auth-source
(keepass-pick-auth-source-enable)))If keepass-pick-database is nil, each command asks for the file. Loading the package changes nothing. You bind the keys, and you enable the auth-source backend.
The repository has a test database with throwaway entries, test/fixtures/test.kdbx. Its master password is test.
M-x load-file keepass-pick.elfrom a clone of the repository.M-x keepass-pick. When it asks for the database, choosetest/fixtures/test.kdbx. It asks only ifkeepass-pick-databaseis not set.
keepass-pick-edit and keepass-pick-add change the test database and play around.
| Command | What it does |
|---|---|
keepass-pick | Pick an entry, then a field: password, user name, URL, notes, TOTP code or another attribute. RET RET copies the password. |
keepass-pick-totp | Pick an entry and copy its current TOTP code. |
keepass-pick-edit | Change the password, user name, URL or title of an entry. |
keepass-pick-add | Add an entry with a user name, URL and a typed or generated password. |
keepass-pick-forget-password | Remove the cached master password now. |
keepass-pick-auth-source-enable | Let auth-source read passwords from the database. |
With C-u, keepass-pick and keepass-pick-totp type the secret instead of copying it, or copy instead of type.
| Option | Default | Meaning |
|---|---|---|
keepass-pick-database | nil | The database file. Nil means ask each time. |
keepass-pick-clear-seconds | 30 | Remove a copied secret after this many seconds. |
keepass-pick-cache-seconds | 300 | Keep the master password this long. Nil keeps it for the session. |
keepass-pick-deliver-function | keepass-pick-copy | What to do with a picked secret: copy, type, or your function. |
keepass-pick-type-command | ("wtype" "-s" "300" "-") | The program that types text from its standard input. |
keepass-pick-generate-arguments | nil | Options for generated passwords, see man keepassxc-cli. |
keepass-pick-timeout-seconds | 15 | Stop a keepassxc-cli call after this many seconds. |
keepass-pick-program | "keepassxc-cli" | The CLI, or a wrapper with the same arguments. |
A replaceable step is a function in a variable. A deliver function gets the secret and a label, and it owns the secret string.
(defun my-keepass-pick-copy-briefly (secret label)
"Copy SECRET like `keepass-pick-copy', but clear it after 10 seconds."
(let ((keepass-pick-clear-seconds 10))
(keepass-pick-copy secret label)))
(setq keepass-pick-deliver-function #'my-keepass-pick-copy-briefly)To type on X11 or with another tool, set keepass-pick-type-command to a program that reads the text from standard input. Only wtype was tested.
You can also advise any function as you prefer.
keepass-pick-auth-source-enable adds the backend at the end of auth-sources.
- A lookup searches the database for the host. An entry matches when its URL host or its title is exactly that host. If a user is given, the user name must match too.
- The password is read only when the caller needs it.
- The master password prompt says why it appears, for example
(auth-source: smtp.example.org).
- The master password and a new entry password go to
keepassxc-clion standard input, never on the command line. - Output from the CLI is read into a string and wiped after use. No secret goes into a buffer or
*Messages*. - The master password is cached with the built-in
password-cache, which wipes it when it expires. - A copied secret is removed from the kill ring and the menu of kills. The clipboard is cleared only if it still holds that secret.
- A clipboard manager can keep its own copy. Emacs cannot prevent that.
- If you save
kill-ringwith savehist, a secret can reach the disk when Emacs exits before the clear. - Typing sends the secret to the window that has focus. Make sure it is the right one and keep wait time or sleep before entering.
- A program that gets a password from auth-source keeps its own copy.
Because hacking with Elisp is fun, and breathing Elisp is salvation.
It needs the KeePassXC app running, and Secret Service turned on in its settings. keepass-pick works with the app closed.
It needs the app running and a compiled module, and it finds passwords only by URL.
The database file uses 256-bit symmetric encryption. Known quantum attacks only halve its strength, which is still considered safe. keepass-pick adds no cryptography and no network use. Check that your database uses Argon2 with keepassxc-cli db-info.
keepass-pick exists because many people solved this before. It took ideas from their work and kept the smallest part.
- KeePassXC and its
keepassxc-cli, which do the real work. - keepmenu, the dmenu front end for KeePass that set the idea of “pick and go”.
- keepass-mode, a small Emacs wrapper around the CLI.
- keemacs, for the master password on standard input and the
password-cacheuse. - keepassxc.el, for the kill-ring timer idea and a careful study of the browser protocol.
- counsel-keepassxc, for completion over the CLI and for clearing the cache on a wrong password.
- pass.el and password-store.el, for clearing the kill ring with a timer.
auth-source-pass.elin Emacs, the template for the auth-source backend.imenu.elin Emacs, whose flat list with a path prefix shaped the entry list.
