|
1 |
| -;; -*- lexical-binding: t; -*- |
| 1 | +;; ecryptfs.el -- eCryptfs integration -*- lexical-binding: t; -*- |
2 | 2 |
|
3 | 3 | ;; Copyright (C) 2022-2023 Abdelhak Bougouffa
|
4 | 4 |
|
|
8 | 8 |
|
9 | 9 | ;; This allows me to mount my private directory encrypted using ecryptfs-utils.
|
10 | 10 | ;; It is a port of "ecryptfs-mount-private" shell command. It extracts the
|
11 |
| -;; encryption key from a GPG encrypted file containting the ecryptfs password. |
| 11 | +;; encryption key from a GPG encrypted file containing the eCryptfs password. |
12 | 12 | ;; The decryption of the password is performed using Emacs' `epg'.
|
13 | 13 |
|
14 | 14 | ;;; Code:
|
15 | 15 |
|
16 | 16 | (require 'epg)
|
| 17 | +(autoload 'cl-every "cl-extras") |
17 | 18 |
|
18 | 19 | (defgroup minemacs-ecryptfs nil
|
19 | 20 | "MinEmacs eCryptfs."
|
20 | 21 | :group 'minemacs)
|
21 | 22 |
|
22 | 23 | (defcustom ecryptfs-private-dir-name "Private"
|
23 |
| - "eCryptfs private directory name." |
| 24 | + "The eCryptfs private directory name." |
24 | 25 | :group 'minemacs-ecryptfs
|
25 | 26 | :type 'string)
|
26 | 27 |
|
|
29 | 30 | :group 'minemacs-ecryptfs
|
30 | 31 | :type 'directory)
|
31 | 32 |
|
32 |
| -(defcustom ecryptfs-passphrase-file (concat ecryptfs-root-dir "my-pass.gpg") |
33 |
| - "GPG encrypted file containing eCryptfs password.") |
| 33 | +(defcustom ecryptfs-passphrase-file (concat ecryptfs-root-dir "password.gpg") |
| 34 | + "GPG encrypted file containing eCryptfs password." |
| 35 | + :group 'minemacs-ecryptfs |
| 36 | + :type 'file) |
34 | 37 |
|
35 | 38 | (defvar ecryptfs-buffer-name " *emacs-ecryptfs*")
|
36 | 39 | (defvar ecryptfs-process-name "emacs-ecryptfs")
|
37 | 40 | (defvar ecryptfs--mount-private-cmd "/sbin/mount.ecryptfs_private")
|
38 | 41 | (defvar ecryptfs--umount-private-cmd "/sbin/umount.ecryptfs_private")
|
39 | 42 |
|
40 | 43 | (defun ecryptfs--wrapped-passphrase-file ()
|
| 44 | + "Return eCryptfs' wrapped passphrase file path." |
41 | 45 | (concat ecryptfs-root-dir "wrapped-passphrase"))
|
42 | 46 |
|
43 | 47 | (defun ecryptfs--mount-passphrase-sig-file ()
|
| 48 | + "Return eCryptfs' wrapped passphrase signature file path." |
44 | 49 | (concat ecryptfs-root-dir ecryptfs-private-dir-name ".sig"))
|
45 | 50 |
|
46 | 51 | (defun ecryptfs--passphrase ()
|
| 52 | + "Return eCryptfs' passphrase from the GPG encrypted password file." |
47 | 53 | (string-trim-right
|
48 | 54 | (epg-decrypt-file
|
49 | 55 | (epg-make-context)
|
|
52 | 58 | "[\n\r]+"))
|
53 | 59 |
|
54 | 60 | (defun ecryptfs--encrypt-filenames-p ()
|
| 61 | + "Des eCryptfs is configured with encrypted file names." |
55 | 62 | (/= 1 (with-temp-buffer
|
56 | 63 | (insert-file-contents (ecryptfs--mount-passphrase-sig-file))
|
57 | 64 | (count-lines (point-min) (point-max)))))
|
58 | 65 |
|
59 | 66 | (defun ecryptfs-available-p ()
|
| 67 | + "Is eCryptfs available on the current system?" |
60 | 68 | (and (file-directory-p (expand-file-name ecryptfs-private-dir-name "~"))
|
61 | 69 | (cl-every #'file-exists-p (list ecryptfs--mount-private-cmd
|
62 | 70 | ecryptfs--umount-private-cmd
|
63 | 71 | (ecryptfs--wrapped-passphrase-file)
|
64 | 72 | (ecryptfs--mount-passphrase-sig-file)))))
|
65 | 73 |
|
66 | 74 | (defun ecryptfs--unwrap-passphrase-command ()
|
| 75 | + "Return eCryptfs' command that unwraps the passphrase." |
67 | 76 | (format
|
68 | 77 | (if (ecryptfs--encrypt-filenames-p)
|
69 | 78 | "ecryptfs-insert-wrapped-passphrase-into-keyring %s '%s'"
|
70 | 79 | "ecryptfs-unwrap-passphrase %s '%s' | ecryptfs-add-passphrase -")
|
71 | 80 | (ecryptfs--wrapped-passphrase-file) (ecryptfs--passphrase)))
|
72 | 81 |
|
73 | 82 | (defun ecryptfs-private-mounted-p ()
|
| 83 | + "Is eCryptfs' private directory is mounted?" |
74 | 84 | (let ((mount (shell-command-to-string "mount")))
|
75 | 85 | (and (string-match-p (concat ".*" (expand-file-name ecryptfs-private-dir-name "~") ".*ecryptfs.*") mount)
|
76 | 86 | t)))
|
|
100 | 110 | (prog1 try-again (setq try-again nil)))
|
101 | 111 | (if (zerop (shell-command (ecryptfs--unwrap-passphrase-command) ecryptfs-buffer-name))
|
102 | 112 | (message "Successfully mounted private directory.")
|
103 |
| - (user-error "A problem occured while mounting the private directory, see %s" |
| 113 | + (user-error "A problem occurred while mounting the private directory, see %s" |
104 | 114 | ecryptfs-buffer-name))))))
|
105 | 115 |
|
106 | 116 | ;;;###autoload
|
|
0 commit comments