From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Chong Yidong Newsgroups: gmane.emacs.devel Subject: Re: Fix needed for communication with gpg-agent Date: Thu, 22 Feb 2007 12:31:54 -0500 Message-ID: <873b4yt7xx.fsf@stupidchicken.com> References: <87irdzs6pp.fsf@stupidchicken.com> <87fy91g1pl.fsf@catnip.gol.com> <87wt2dk2rv.fsf@stupidchicken.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1172165600 31179 80.91.229.12 (22 Feb 2007 17:33:20 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 22 Feb 2007 17:33:20 +0000 (UTC) Cc: Sascha Wilde , Werner Koch , Daiki Ueno , rms@gnu.org, Miles Bader To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Feb 22 18:33:08 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HKHoa-0005IX-07 for ged-emacs-devel@m.gmane.org; Thu, 22 Feb 2007 18:33:08 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HKHoZ-00057J-HF for ged-emacs-devel@m.gmane.org; Thu, 22 Feb 2007 12:33:07 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HKHnx-0004py-L9 for emacs-devel@gnu.org; Thu, 22 Feb 2007 12:32:29 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HKHnx-0004ph-4t for emacs-devel@gnu.org; Thu, 22 Feb 2007 12:32:29 -0500 Original-Received: from south-station-annex.mit.edu ([18.72.1.2]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1HKHnw-0005YL-GL; Thu, 22 Feb 2007 12:32:28 -0500 Original-Received: from grand-central-station.mit.edu (GRAND-CENTRAL-STATION.MIT.EDU [18.7.21.82]) by south-station-annex.mit.edu (8.13.6/8.9.2) with ESMTP id l1MHWQGJ024590; Thu, 22 Feb 2007 12:32:26 -0500 (EST) Original-Received: from outgoing-legacy.mit.edu (OUTGOING-LEGACY.MIT.EDU [18.7.22.104]) by grand-central-station.mit.edu (8.13.6/8.9.2) with ESMTP id l1MHW8kL000161; Thu, 22 Feb 2007 12:32:08 -0500 (EST) Original-Received: from localhost (MAIN-TWELVE-FOUR-EIGHTY-THREE.MIT.EDU [18.19.6.228]) ) by outgoing-legacy.mit.edu (8.13.6/8.12.4) with ESMTP id l1MHVscU005409; Thu, 22 Feb 2007 12:31:55 -0500 (EST) Original-Received: from cyd by localhost with local (Exim 3.36 #1 (Debian)) id 1HKHnO-0000si-00; Thu, 22 Feb 2007 12:31:54 -0500 In-Reply-To: <87wt2dk2rv.fsf@stupidchicken.com> (Chong Yidong's message of "Mon\, 19 Feb 2007 20\:59\:16 -0500") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.93 (gnu/linux) X-Scanned-By: MIMEDefang 2.42 X-Spam-Score: -2.599 X-detected-kernel: Solaris 9.1 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:66633 Archived-At: > Another solution might be to cannibalize the ansi-term code, and have > the pinentry program run in an elisp terminal. I looked into this, > and concluded that it is a big job. It should be left till after the > release. 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. *** emacs/lisp/pgg-gpg.el.~1.22.~ 2007-02-18 11:07:52.000000000 -0500 --- emacs/lisp/pgg-gpg.el 2007-02-22 12:23:11.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")) *************** *** 83,114 **** (erase-buffer)) (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) --- 85,130 ---- (erase-buffer)) (unwind-protect (progn ! (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))) ! (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) ! (accept-process-output process nil nil 1) ! (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 **** --- 148,174 ---- (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