Emacs 29.2 fixes my Mac-specific bug with GPG
This commit is contained in:
parent
a11c9b7290
commit
5db1762ef0
2 changed files with 29 additions and 77 deletions
|
@ -46,7 +46,7 @@ Helper functions to allow code for specific operating systems:
|
||||||
|
|
||||||
With the way I start Emacs, I may not have the =PATH= I /actually/ use (from the shell) available, so we'll force it (code taken [[https://www.emacswiki.org/emacs/ExecPath][from here]]):
|
With the way I start Emacs, I may not have the =PATH= I /actually/ use (from the shell) available, so we'll force it (code taken [[https://www.emacswiki.org/emacs/ExecPath][from here]]):
|
||||||
|
|
||||||
#+begin_src emacs-lisp :tangle no
|
#+begin_src emacs-lisp
|
||||||
(defun set-exec-path-from-shell ()
|
(defun set-exec-path-from-shell ()
|
||||||
"Set up Emacs' `exec-path' and PATH environment variable to match
|
"Set up Emacs' `exec-path' and PATH environment variable to match
|
||||||
that used by the user's shell.
|
that used by the user's shell.
|
||||||
|
@ -81,31 +81,6 @@ Getting tired off all the packages that I load spewing a bunch of warnings that
|
||||||
(setq native-comp-async-report-warnings-errors nil
|
(setq native-comp-async-report-warnings-errors nil
|
||||||
native-comp-deferred-compilation t))
|
native-comp-deferred-compilation t))
|
||||||
#+end_src
|
#+end_src
|
||||||
** GNU Pretty Good Privacy
|
|
||||||
On Linux, GPG is pretty straight-forward, but on the Mac, I often have troubles doing:
|
|
||||||
#+begin_src sh
|
|
||||||
brew install gpg
|
|
||||||
#+end_src
|
|
||||||
Next, on every reboot, start the agent:
|
|
||||||
#+begin_src sh
|
|
||||||
/opt/homebrew/bin/gpg-agent --daemon
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
Since =brew link gpg= doesn’t always work, this helper function may find the executable:
|
|
||||||
#+begin_src emacs-lisp
|
|
||||||
(defun executable (path)
|
|
||||||
"Return PATH if executable, see `file-executable-p'."
|
|
||||||
(let ((epath (first (file-expand-wildcards path))))
|
|
||||||
(when (and epath (file-executable-p epath)) epath)))
|
|
||||||
|
|
||||||
(use-package epa-file
|
|
||||||
:straight (:type built-in)
|
|
||||||
:custom (epg-gpg-program (or (executable "/opt/homebrew/bin/gpg")
|
|
||||||
(executable "/usr/local/bin/gpg")
|
|
||||||
(executable "/usr/local/opt/gpg")
|
|
||||||
(executable "/usr/bin/pgp")))
|
|
||||||
:config (epa-file-enable))
|
|
||||||
#+end_src
|
|
||||||
* Basic Libraries
|
* Basic Libraries
|
||||||
The following packages come with Emacs, but seems like they still need loading:
|
The following packages come with Emacs, but seems like they still need loading:
|
||||||
#+begin_src emacs-lisp
|
#+begin_src emacs-lisp
|
||||||
|
|
|
@ -20,7 +20,7 @@ A literate programming file for configuring Emacs.
|
||||||
;;
|
;;
|
||||||
;; *NB:* Do not edit this file. Instead, edit the original literate file at:
|
;; *NB:* Do not edit this file. Instead, edit the original literate file at:
|
||||||
;; ~/other/hamacs/ha-config.org
|
;; ~/other/hamacs/ha-config.org
|
||||||
;; Using `find-file-at-point', and tangle the file to recreate this one .
|
;; Using `find-file-at-point', and tangle the file to recreate this.
|
||||||
;;
|
;;
|
||||||
;;; Code:
|
;;; Code:
|
||||||
#+end_src
|
#+end_src
|
||||||
|
@ -775,63 +775,40 @@ Once we create the new perspective workspace, if it matches a particular name, I
|
||||||
* Pretty Good Encryption
|
* Pretty Good Encryption
|
||||||
For details on using GnuPG in Emacs, see Mickey Petersen’s [[https://www.masteringemacs.org/article/keeping-secrets-in-emacs-gnupg-auth-sources][GnuPG Essay]].
|
For details on using GnuPG in Emacs, see Mickey Petersen’s [[https://www.masteringemacs.org/article/keeping-secrets-in-emacs-gnupg-auth-sources][GnuPG Essay]].
|
||||||
|
|
||||||
|
On Linux, GPG is pretty straight-forward, but on the Mac, I often have troubles doing:
|
||||||
|
#+begin_src sh
|
||||||
|
brew install gpg
|
||||||
|
#+end_src
|
||||||
|
Next, on every reboot, start the agent:
|
||||||
|
#+begin_src sh
|
||||||
|
/opt/homebrew/bin/gpg-agent --daemon
|
||||||
|
#+end_src
|
||||||
|
|
||||||
Also, as [[https://www.bytedude.com/gpg-in-emacs/][bytedude]] mentions, I need to use the =epa-pineentry-mode= to =loopback= to actually get a prompt for the password, instead of an error. Also let's cache as much as possible, as my home machine is pretty safe, and my laptop is shutdown a lot.
|
Also, as [[https://www.bytedude.com/gpg-in-emacs/][bytedude]] mentions, I need to use the =epa-pineentry-mode= to =loopback= to actually get a prompt for the password, instead of an error. Also let's cache as much as possible, as my home machine is pretty safe, and my laptop is shutdown a lot.
|
||||||
|
|
||||||
#+begin_src emacs-lisp
|
#+begin_src emacs-lisp
|
||||||
(use-package epa-file
|
(use-package epa-file
|
||||||
:config
|
:straight (:type built-in)
|
||||||
(setq epg-debug t auth-source-debug t
|
:custom
|
||||||
|
(epg-debug t)
|
||||||
|
(auth-source-debug t)
|
||||||
;; Since I normally want symmetric encryption, and don't want
|
;; Since I normally want symmetric encryption, and don't want
|
||||||
;; to use the "key selection":
|
;; to use the "key selection":
|
||||||
epa-file-select-keys 'symmetric-only
|
(epa-file-select-keys 'symmetric-only)
|
||||||
;; Make sure we prompt in the minibuffer for the password:
|
;; Make sure we prompt in the minibuffer for the password:
|
||||||
epg-pinentry-mode 'loopback
|
(epg-pinentry-mode 'loopback)
|
||||||
;; I trust my Emacs session, so I don't bother expiring my pass:
|
;; I trust my Emacs session, so I don't bother expiring my pass:
|
||||||
auth-source-cache-expiry nil)
|
(auth-source-cache-expiry nil))
|
||||||
;; Make sure that for Emacs, we will handle the prompts:
|
#+end_src
|
||||||
|
|
||||||
|
Need to make sure that Emacs will handle the prompts, and turn it on:
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
(use-package epa-file
|
||||||
|
:config
|
||||||
(setenv "GPG_AGENT_INFO" nil)
|
(setenv "GPG_AGENT_INFO" nil)
|
||||||
(epa-file-enable))
|
(epa-file-enable))
|
||||||
#+end_src
|
|
||||||
|
|
||||||
Make sure that the following passes:
|
|
||||||
#+begin_src emacs-lisp :tangle no
|
|
||||||
(let ((macos-gpg "/opt/homebrew/bin/gpg1"))
|
|
||||||
(when (and (file-exists-p macos-gpg)
|
|
||||||
(file-executable-p macos-gpg))
|
|
||||||
(setq epg-gpg-program macos-gpg)))
|
|
||||||
#+end_src
|
|
||||||
As well as:
|
|
||||||
#+begin_src emacs-lisp :tangle no
|
|
||||||
(let ((macos-gpg "/opt/homebrew/bin/pinentry-tty"))
|
|
||||||
(when (and (file-exists-p macos-gpg)
|
|
||||||
(file-executable-p macos-gpg))
|
|
||||||
(setq pinentry-program macos-gpg)))
|
|
||||||
|
|
||||||
#+end_src
|
#+end_src
|
||||||
According to [[https://emacs.stackexchange.com/questions/78140/emacs-failing-to-save-encrypted-file][this discussion]], I seem to first, downgrade the version of GPG to version 2.2:
|
|
||||||
#+begin_src sh :results replace raw :wrap example
|
|
||||||
gpg --version
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
#+begin_example
|
|
||||||
gpg (GnuPG) 2.2.42
|
|
||||||
libgcrypt 1.10.3
|
|
||||||
Copyright (C) 2023 g10 Code GmbH
|
|
||||||
License GNU GPL-3.0-or-later <https://gnu.org/licenses/gpl.html>
|
|
||||||
This is free software: you are free to change and redistribute it.
|
|
||||||
There is NO WARRANTY, to the extent permitted by law.
|
|
||||||
|
|
||||||
Home: /Users/howard.abrams/.gnupg
|
|
||||||
Supported algorithms:
|
|
||||||
Pubkey: RSA, ELG, DSA, ECDH, ECDSA, EDDSA
|
|
||||||
Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,
|
|
||||||
CAMELLIA128, CAMELLIA192, CAMELLIA256
|
|
||||||
Hash: SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
|
|
||||||
Compression: Uncompressed, ZIP, ZLIB, BZIP2
|
|
||||||
#+end_example
|
|
||||||
|
|
||||||
However, for Emacs 29, and even with GPG1 or GPG2.2, it still hangs when saving encrypted files.
|
|
||||||
|
|
||||||
* Technical Artifacts :noexport:
|
* Technical Artifacts :noexport:
|
||||||
Let's provide a name so we can =require= this file:
|
Let's provide a name so we can =require= this file:
|
||||||
#+begin_src emacs-lisp :exports none
|
#+begin_src emacs-lisp :exports none
|
||||||
|
|
Loading…
Reference in a new issue