Skip to content

About

Emacs KeePassXC password picker: completing-read over keepassxc-cli to copy or type passwords and auth-source

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

13 Commits

Folders and files

Repository files navigation

keepass-pick

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.

screenshot.png

Why this package

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 category keepass-pick-entry.
  • Built-ins only. keepassxc-cli is 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.

Install

(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.

Try it

The repository has a test database with throwaway entries, test/fixtures/test.kdbx. Its master password is test.

  1. M-x load-file keepass-pick.el from a clone of the repository.
  2. M-x keepass-pick. When it asks for the database, choose test/fixtures/test.kdbx. It asks only if keepass-pick-database is not set.

keepass-pick-edit and keepass-pick-add change the test database and play around.

Commands

CommandWhat it does
keepass-pickPick an entry, then a field: password, user name, URL, notes, TOTP code or another attribute. RET RET copies the password.
keepass-pick-totpPick an entry and copy its current TOTP code.
keepass-pick-editChange the password, user name, URL or title of an entry.
keepass-pick-addAdd an entry with a user name, URL and a typed or generated password.
keepass-pick-forget-passwordRemove the cached master password now.
keepass-pick-auth-source-enableLet 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.

Options

OptionDefaultMeaning
keepass-pick-databasenilThe database file. Nil means ask each time.
keepass-pick-clear-seconds30Remove a copied secret after this many seconds.
keepass-pick-cache-seconds300Keep the master password this long. Nil keeps it for the session.
keepass-pick-deliver-functionkeepass-pick-copyWhat 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-argumentsnilOptions for generated passwords, see man keepassxc-cli.
keepass-pick-timeout-seconds15Stop a keepassxc-cli call after this many seconds.
keepass-pick-program"keepassxc-cli"The CLI, or a wrapper with the same arguments.

Extending

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.

auth-source

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).

Security notes

  • The master password and a new entry password go to keepassxc-cli on 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-ring with 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.

FAQ

Why not simply use a dmenu tool such as keepmenu?

Because hacking with Elisp is fun, and breathing Elisp is salvation.

Why not the Secret Service with secrets.el?

It needs the KeePassXC app running, and Secret Service turned on in its settings. keepass-pick works with the app closed.

Why not the KeePassXC browser protocol?

It needs the app running and a compiled module, and it finds passwords only by URL.

Is it post-quantum safe?

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.

Credits

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-cache use.
  • 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.el in Emacs, the template for the auth-source backend.
  • imenu.el in Emacs, whose flat list with a path prefix shaped the entry list.

About

Emacs KeePassXC password picker: completing-read over keepassxc-cli to copy or type passwords and auth-source

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages