2014-06-26 Encrypting Mail using Gnus on OSX

Today I learned...

1. If you want to use GPG, and you’re on OSX, pinentry will not work. You need a graphical pinentry tool. Your best bet is GPG Tools which is linked from the GnuPG website. You get Mail and Keychain integration for free, which I don’t really care about at the moment, and you get all the command line tools. Thus when I ran gpg in eshell just now, I was asked for my passphrase.

2. If you want Emacs to know about your gpg-agent, you need to tell it about the PID and the temporary file and all that. My solution is Emacs-only. There’s probably a better way to do this such that you can use GPG from elsewhere as well. See the code snippet below.

3. If you use Gnus to send mail, you cannot read the encrypted mails unless you set a mysterious variable. See the code snippet below.

GPG Tools

GnuPG

First, how to run gpg-agent from your init file:

(setenv "GPG_AGENT_INFO"
	(with-temp-buffer
	  (shell-command "/usr/local/bin/gpg-agent --daemon" (current-buffer))
	  (goto-char (point-min))
	  (when (re-search-forward "GPG_AGENT_INFO=\\([^;\n]+\\)" nil t)
	    (match-string 1))))
;; (getenv "GPG_AGENT_INFO")

How to make sure that mails are always encrypted to you, too:

(setq mml2015-encrypt-to-self t
      mml2015-signers '("353AEFEF"))

There you go.

The alternative to mml2015-signers would be to set mml2015-sign-with-sender to t, I guess.

​#Emacs ​#Gnus

Comments

(Please contact me if you want to remove your comment.)

Thanks! I’ve been meaning to get round to this for ages.

– Alok Singh 2014-06-28 14:09 UTC

---

Now that I have GPG Tools installed, I’m not sure the GPG_AGENT_INFO environment variable is still needed. The entire business of setting environment variables for OSX Maverick is a mess. 😡

– Alex Schroeder 2014-06-28 14:47 UTC

Alex Schroeder