From: Chong Yidong <cyd@stupidchicken.com>
To: emacs-devel@gnu.org
Cc: wilde@sha-bang.de, wk@gnupg.org, ueno@unixuser.org, rms@gnu.org,
miles@gnu.org
Subject: Re: Fix needed for communication with gpg-agent
Date: Thu, 22 Feb 2007 12:44:39 -0500 [thread overview]
Message-ID: <E1HKHzj-0000w7-00@localhost> (raw)
In-Reply-To: <873b4yt7xx.fsf@stupidchicken.com> (message from Chong Yidong on Thu, 22 Feb 2007 12:31:54 -0500)
FWIW, here is a patch that implements the idea I outlined above. I
have tested it, and it works with the curses version of pinentry.
Admittedly, it is a rather naughty solution: GPG is called through an
elisp terminal (as implemented by `make-term' in term.el), with a
modified process filter whose purpose is to send GPG the string to be
encrypted when required. The terminal is run in a recursive editing
level, so that the user can input to pinentry if necessary; the
process sentinel is modified to call `exit-recursive-edit' when GPG
exits, to return control to pgg-gpg-process-region.
Whoops, minor typo in that patch. Please consider this one, which
works on all configurations I have tested.
*** emacs/lisp/pgg-gpg.el.~1.22.~ 2007-02-18 11:07:52.000000000 -0500
--- emacs/lisp/pgg-gpg.el 2007-02-22 12:41:44.000000000 -0500
***************
*** 60,65 ****
--- 60,67 ----
(defvar pgg-gpg-user-id nil
"GnuPG ID of your default identity.")
+ (defvar pgg-gpg-term-input nil)
+
(defun pgg-gpg-process-region (start end passphrase program args)
(let* ((use-agent (and (null passphrase) (pgg-gpg-use-agent-p)))
(output-file-name (pgg-make-temp-file "pgg-output"))
***************
*** 84,114 ****
(unwind-protect
(progn
(set-default-file-modes 448)
! (let ((coding-system-for-write 'binary))
! (setq process
! (apply #'start-process "*GnuPG*" errors-buffer
! program args)))
! (set-process-sentinel process #'ignore)
! (when passphrase
! (setq passphrase-with-newline (concat passphrase "\n"))
! (if pgg-passphrase-coding-system
! (progn
! (setq encoded-passphrase-with-new-line
! (encode-coding-string
! passphrase-with-newline
! (coding-system-change-eol-conversion
! pgg-passphrase-coding-system 'unix)))
! (pgg-clear-string passphrase-with-newline))
! (setq encoded-passphrase-with-new-line passphrase-with-newline
! passphrase-with-newline nil))
! (process-send-string process encoded-passphrase-with-new-line))
! (process-send-region process start end)
! (process-send-eof process)
! (while (eq 'run (process-status process))
! (accept-process-output process 5))
! (setq status (process-status process)
! exit-status (process-exit-status process))
! (delete-process process)
(with-current-buffer (get-buffer-create output-buffer)
(buffer-disable-undo)
(erase-buffer)
--- 86,129 ----
(unwind-protect
(progn
(set-default-file-modes 448)
! (if (and (not window-system) use-agent)
! (let ((term-term-name "vt100")
! (buf (current-buffer)))
! (apply #'make-term "GPGTERM" "gpg" nil args)
! (switch-to-buffer "*GPGTERM*")
! (set (make-local-variable 'pgg-gpg-term-input)
! (list buf start end))
! (setq process (get-buffer-process "*GPGTERM*"))
! (term-char-mode)
! (set-process-filter process 'pgg-gpg-filter)
! (set-process-sentinel process 'pgg-gpg-sentinel)
! (recursive-edit)
! (setq exit-status (process-exit-status process)))
! (let ((coding-system-for-write 'binary))
! (setq process
! (apply #'start-process "*GnuPG*" errors-buffer
! program args)))
! (set-process-sentinel process #'ignore)
! (when passphrase
! (setq passphrase-with-newline (concat passphrase "\n"))
! (if pgg-passphrase-coding-system
! (progn
! (setq encoded-passphrase-with-new-line
! (encode-coding-string
! passphrase-with-newline
! (coding-system-change-eol-conversion
! pgg-passphrase-coding-system 'unix)))
! (pgg-clear-string passphrase-with-newline))
! (setq encoded-passphrase-with-new-line passphrase-with-newline
! passphrase-with-newline nil))
! (process-send-string process encoded-passphrase-with-new-line))
! (process-send-region process start end)
! (process-send-eof process)
! (while (eq 'run (process-status process))
! (accept-process-output process 5))
! (setq status (process-status process)
! exit-status (process-exit-status process))
! (delete-process process))
(with-current-buffer (get-buffer-create output-buffer)
(buffer-disable-undo)
(erase-buffer)
***************
*** 132,137 ****
--- 147,173 ----
(delete-file output-file-name))
(set-default-file-modes orig-mode))))
+ (defun pgg-gpg-filter (proc str)
+ (if (and (string-match "writing to" str) pgg-gpg-term-input)
+ (let ((buf (nth 0 pgg-gpg-term-input))
+ (start (nth 1 pgg-gpg-term-input))
+ (end (nth 2 pgg-gpg-term-input)))
+ (erase-buffer)
+ (with-current-buffer buf
+ (process-send-region proc start end)
+ (process-send-eof proc)
+ (process-send-eof proc)
+ (setq pgg-gpg-filter-args nil)))
+ (term-emulate-terminal proc str)))
+
+ (defun pgg-gpg-sentinel (proc msg)
+ (let ((buffer (process-buffer proc)))
+ (when (memq (process-status proc) '(signal exit))
+ (delete-process proc)
+ (unless (null (buffer-name buffer))
+ (kill-buffer buffer))
+ (exit-recursive-edit))))
+
(defun pgg-gpg-possibly-cache-passphrase (passphrase &optional key notruncate)
(if (and passphrase
pgg-cache-passphrase
next prev parent reply other threads:[~2007-02-22 17:44 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-17 20:57 Fix needed for communication with gpg-agent Richard Stallman
2007-02-18 17:42 ` Chong Yidong
2007-02-19 23:35 ` Miles Bader
2007-02-20 1:59 ` Chong Yidong
2007-02-22 17:31 ` Chong Yidong
2007-02-22 17:44 ` Chong Yidong [this message]
2007-02-22 18:04 ` Werner Koch
2007-02-22 18:40 ` Chong Yidong
2007-02-22 22:00 ` Sascha Wilde
2007-02-22 22:47 ` Chong Yidong
2007-02-23 20:01 ` Sascha Wilde
2007-02-24 8:28 ` Richard Stallman
2007-02-23 22:09 ` Richard Stallman
2007-02-23 23:41 ` Sascha Wilde
2007-02-25 4:06 ` Richard Stallman
2007-02-25 19:32 ` Chong Yidong
2007-02-25 19:50 ` Andreas Schwab
2007-02-25 20:22 ` David Kastrup
2007-02-26 3:27 ` Richard Stallman
2007-02-26 10:27 ` Werner Koch
2007-02-27 7:38 ` Richard Stallman
2007-02-27 8:53 ` Werner Koch
2007-02-28 2:37 ` Richard Stallman
2007-02-23 8:53 ` Werner Koch
2007-02-23 10:27 ` Sascha Wilde
2007-02-23 16:23 ` Chong Yidong
2007-02-23 16:47 ` Werner Koch
2007-02-23 19:37 ` Chong Yidong
2007-02-23 20:10 ` Sascha Wilde
2007-02-23 22:10 ` Richard Stallman
2007-02-23 22:09 ` Richard Stallman
2007-02-23 23:03 ` Chong Yidong
2007-02-23 17:13 ` Andreas Schwab
2007-02-23 18:30 ` Kim F. Storm
2007-02-23 18:07 ` Stefan Monnier
2007-02-24 14:08 ` Miles Bader
2007-02-23 19:35 ` Richard Stallman
2007-02-20 13:43 ` Richard Stallman
2007-02-20 15:35 ` Chong Yidong
2007-02-21 8:37 ` Richard Stallman
2007-02-21 12:04 ` Chong Yidong
2007-02-22 17:21 ` Richard Stallman
2007-02-20 15:11 ` Kim F. Storm
2007-02-20 15:45 ` Chong Yidong
2007-02-21 8:37 ` Richard Stallman
2007-02-21 13:11 ` Chong Yidong
2007-02-22 7:19 ` Richard Stallman
[not found] ` <E1HJCsN-000541-DO@fencepost.gnu.org>
2007-02-21 22:41 ` Sascha Wilde
2007-02-21 23:15 ` Kim F. Storm
2007-02-22 0:14 ` Chong Yidong
2007-02-22 8:04 ` Werner Koch
2007-02-22 12:09 ` Kim F. Storm
2007-02-22 8:13 ` Werner Koch
2007-02-23 10:22 ` Richard Stallman
2007-02-23 13:20 ` Werner Koch
2007-02-23 16:40 ` Chong Yidong
2007-02-23 22:09 ` Richard Stallman
2007-02-23 19:36 ` Richard Stallman
2007-02-23 23:25 ` Chong Yidong
2007-02-23 23:58 ` Kim F. Storm
2007-02-24 0:19 ` Chong Yidong
2007-02-24 0:57 ` Kim F. Storm
2007-02-24 9:58 ` Sascha Wilde
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E1HKHzj-0000w7-00@localhost \
--to=cyd@stupidchicken.com \
--cc=emacs-devel@gnu.org \
--cc=miles@gnu.org \
--cc=rms@gnu.org \
--cc=ueno@unixuser.org \
--cc=wilde@sha-bang.de \
--cc=wk@gnupg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).