An open API service indexing awesome lists of open source software.

https://github.com/pivaldi/emacs-passfile

Very simple Emacs package allowing to view and edit securely a GnuPG encrypted file
https://github.com/pivaldi/emacs-passfile

emacs password-store passwords security

Last synced: 10 months ago
JSON representation

Very simple Emacs package allowing to view and edit securely a GnuPG encrypted file

Awesome Lists containing this project

README

          

#+title: Emacs PassFile

This simple Emacs package allows you to securely view and edit a GnuPG-encrypted file.

* Why This Package?

Consider the decrypted file [[secret.txt]] and its encrypted counterpart ~secret.gpg~.\\
While you could open the ~.gpg~ file in Emacs, especially if you have many
packages installed, this comes with the risk that malicious code embedded in
those packages (automatically downloaded and installed) could access your
secrets.

To prevent this, the goal of this package is to open your secret file in a
*minimalist Emacs configuration* that *hides sensitive text and provides
functions to generate strong passwords*.

Your secret file does not need to follow any specific structure, write whatever you want, however you like.

** Without ~emacs-passfile~
#+html:


** With ~emacs-passfile~
#+html:

* Getting Started

#+BEGIN_SRC bash
cd WHERE_YOU_WANT
git clone https://github.com/pivaldi/emacs-passfile
emacs --init-directory=WHERE_YOU_WANT/emacs-passfile/ WHERE_YOU_WANT/emacs-passfile/secret.gpg
#+END_SRC

The password is ~plop~.

Personally, I created a script to open my favorite encrypted file:
#+BEGIN_SRC bash
#!/usr/bin/env bash

emacs --init-directory="$HOME/src/emacs-passfile/" "$HOME/secret.gpg"
#+END_SRC

* Hiding Content
** Hiding Passwords
- ~pwd: xxxxxxxxxx~ : hides the ~xxxxxxxxxx~, stopping at the next space. Useful for one-line content.
- ~password: xxxxx xxxxx~ : hides the entire ~xxxxx xxxxx~ string, regardless of spaces. Cannot be mixed with other content on the same line.

** Hiding Usernames
- ~user: xxxxxxxxxx~ : hides the ~xxxxxxxxxx~, stopping at the next space. Useful for one-line content.
- ~username: xxxxx xxxxx~ : hides the full ~xxxxx xxxxx~ string, regardless of spaces. Cannot be mixed with other content on the same line.
- ~[xxxxxxxxxx]~ : hides the ~xxxxxxxxxx~. Only one bracketed block can be used per line due to overlap.

** Hiding Paragraphs
A whole paragraph can be hidden using the block delimiters ~#+hidden~ and ~#-hidden~ as shown:
#+BEGIN_SRC
#+hidden
…content…
#-hidden
#+END_SRC

* Password Generation

This package uses [[https://github.com/vandrlexay/emacs-password-genarator][password-generator]] to provide useful functions for creating passwords:
- ~epf-password-generate~: generates a strong password for security-focused users.
- ~password-generator-simple~: generates a simple password sufficient for most websites (not highly secure, but usually enough to register).
- ~password-generator-strong~: generates the strongest possible password, omitting certain symbols (like $, \, etc.) to avoid shell escaping issues.
- ~password-generator-numeric~: generates numeric-only passwords, such as credit card PIN codes.
- ~password-generator-phonetic~: generates passwords that are easy to remember because of their phonetic structure, though they are less secure.

* Dependencies

This package has two dependencies:
- [[https://github.com/vandrlexay/emacs-password-genarator][password-generator]]: provides simple functions to create passwords and insert them directly into the buffer.\\
~emacs-passfile~ provides the function ~epf-password-generate~, which wraps ~password-generator-paranoid~.
- [[https://github.com/jekor/hidepw][hidepw]]: a minor mode for hiding passwords. This is useful if you view your passwords in Emacs and want to prevent shoulder surfing.

* Customization & Configuration
** hidepw
- ~emacs-passfile~ uses the following configuration:
#+BEGIN_SRC emacs-lisp
(setq hidepw-patterns
'("#\\+hidden\n\\([^
]*?\\)\n#-hidden$"
" \\[\\(.+\\)\\] ?"
"^\\[\\(.+\\)\\] ?"
"[pP]wd[  ]?: \\([^ \n]+\\)"
"[pP]assword[  ]?: \\(.+\\)$"
"[uU]ser[  ]?: \\([^ \n]+\\)"
"[uU]sername[  ]?: \\(.+\\)"))
#+END_SRC
- You can customize the variable ~hidepw-patterns~ from the [[https://github.com/jekor/hidepw][hidepw]] package using the ~customize-variable~ command.
- See ~M-x customize-group [RET]hidepw[RET]~ for further customization.

** Emacs configuration
For convenience, you can add your own Emacs configuration in the personal file
~configure.el~. However, it is not recommended to install external packages in this setup.

Here is my personal configuration:

#+BEGIN_SRC emacs-lisp
;;; configure.el --- My personal configuration -*- lexical-binding: t; -*-
;;
;;; Commentary:
;;; Code:

(delete-selection-mode 1)
(show-paren-mode 1)

(require 'skeleton)
(setq skeleton-pair t)

;;;###autoload
(defun epf-kill-window-and-buffer()
"Delete current window and buffer."
(interactive)
(kill-current-buffer)
(condition-case nil (delete-window) (error nil)))
(global-set-key [f12] #'epf-kill-window-and-buffer)

;;;###autoload
(defun epf-new-login()
"Insert a new login entry: Username:… Pwd:…."
(interactive)
(let ((user (read-from-minibuffer "Username: ")))
(insert (format "Username: %s\nPwd: %s\n" user (epf-password-generate nil t)))))

;;;###autoload
(defun epf-scroll-up()
"Scroll up keeping the cursor on the same line."
(interactive)
(let ((scroll-preserve-screen-position t))
(scroll-up 1)))

;;;###autoload
(defun epf-scroll-down()
"Scroll down keeping the cursor on the same line."
(interactive)
(let ((scroll-preserve-screen-position t))
(scroll-down 1)))

(global-set-key (kbd "C-c p") #'epf-password-generate)
(global-set-key (kbd "C-M-") #'move-beginning-of-line)
(global-set-key (kbd "C-M-") #'move-end-of-line)
(global-set-key (kbd "C-") (lambda nil (interactive) (other-window -1 nil)))
(global-set-key (kbd "C-") (lambda nil (interactive) (other-window 1 nil)))
(global-set-key (kbd "C-c l") #'epf-new-login)
(global-set-key (kbd "C-M-") #'epf-scroll-down)
(global-set-key (kbd "C-M-") #'epf-scroll-up)
(global-set-key (kbd "C-:") 'undo-redo)
(global-set-key "\{" 'skeleton-pair-insert-maybe)
(global-set-key "\(" 'skeleton-pair-insert-maybe)
(global-set-key "[" 'skeleton-pair-insert-maybe)
(global-set-key "\"" 'skeleton-pair-insert-maybe)
(global-set-key "'" 'skeleton-pair-insert-maybe)

(provide 'configure)
;;; configure.el ends here
#+END_SRC

* License

This project is licensed under the MIT License. See the LICENSE file for details.

* Acknowledgments

- Inspired by the need for simple, secure, and minimal password management within Emacs.
- Thanks to the authors of [[https://github.com/vandrlexay/emacs-password-genarator][password-generator]] and [[https://github.com/jekor/hidepw][hidepw]] for their useful libraries.

For more information, bug reports, or contributions, please visit the [[https://github.com/pivaldi/emacs-passfile][GitHub repository]].