Gnus development mailing list
 help / color / mirror / Atom feed
From: Michael Sperber <sperber@informatik.uni-tuebingen.de>
To: ding@gnus.org
Cc: Daiki Ueno <ueno@unixuser.org>, Sascha Wilde <wilde@sha-bang.de>
Subject: pgg-gpg doesn't work at all [fix included]
Date: Wed, 25 Jul 2007 12:15:48 +0200	[thread overview]
Message-ID: <y9lbqe094bv.fsf@informatik.uni-tuebingen.de> (raw)

[-- Attachment #1: Type: text/plain, Size: 1007 bytes --]


Hi there,

I've long been frustrated by GnuPG decryption not working from Gnus.
(It just wouldn't accept the passphrase I entered.) I finally tracked
down the reasons for it:

pgg-gpg runs gpg with --command-fd, and then dumps the data to be
decryped its way.  The problem is that gpg (1.4.7) doesn't buffer the
data: After it's received enough lines, it asks for the passphrase.  If
the data is sufficiently large, this will be before the end of the data.
However, pgg-gpg merrily throws more data at it---which won't wash as a
passphrase.  (This is really a GnuPG problem at its heart, I believe.)
Also because of this, the handling of the pending status list doesn't
work.  Moreover, for me, gpg exits abnormally even when it's done its
job right.

I've included an abominable fix, which sends the data line-by-line, and,
of course, slows everything down.  But at least it works for decryption.
Suggestions for improvement welcome.

-- 
Cheers =8-} Mike
Friede, Völkerverständigung und überhaupt blabla

[-- Attachment #2: Type: text/plain, Size: 3286 bytes --]

Index: pgg-gpg.el
===================================================================
RCS file: /usr/local/cvsroot/gnus/lisp/pgg-gpg.el,v
retrieving revision 7.27
diff -u -r7.27 pgg-gpg.el
--- pgg-gpg.el	1 Mar 2007 23:43:33 -0000	7.27
+++ pgg-gpg.el	25 Jul 2007 10:14:45 -0000
@@ -124,8 +124,9 @@
 		(let* ((status (match-string 1))
 		       (symbol (intern-soft (concat "pgg-gpg-status-"
 						    status))))
-		  (if (member status pgg-gpg-pending-status-list)
-		      (setq pgg-gpg-pending-status-list nil))
+		  (if (not (member status pgg-gpg-pending-status-list))
+		      (setq pgg-gpg-pending-status-list
+			    (cons status pgg-gpg-pending-status-list)))
 		  (if (and symbol
 			   (fboundp symbol))
 		      (funcall symbol process (buffer-substring
@@ -150,23 +151,29 @@
 	(set-buffer (get-buffer-create pgg-output-buffer))
 	(buffer-disable-undo)
 	(erase-buffer)
-	(if (equal status "finished\n")
-	    (let ((output-file-name
-		   (with-current-buffer (process-buffer process)
-		     pgg-gpg-output-file-name)))
-	      (when (file-exists-p output-file-name)
-		(let ((coding-system-for-read (if pgg-text-mode
-						  'raw-text
-						'binary)))
-		  (insert-file-contents output-file-name))
-		(delete-file output-file-name))))
+	(let ((output-file-name
+	       (with-current-buffer (process-buffer process)
+		 pgg-gpg-output-file-name)))
+	  (when (file-exists-p output-file-name)
+	    (let ((coding-system-for-read (if pgg-text-mode
+					      'raw-text
+					    'binary)))
+	      (insert-file-contents output-file-name))
+	    (delete-file output-file-name)))
 	(kill-buffer (process-buffer process)))))
 
+(defun pgg-gpg-status-list-received (status-list)
+  (catch 'pgg-gpg-status-list-received
+    (while status-list
+      (if (not (member (car status-list) pgg-gpg-pending-status-list))
+	  (throw 'pgg-gpg-status-list-received nil))
+      (setq status-list (cdr status-list)))
+    t))
+
 (defun pgg-gpg-wait-for-status (process status-list)
   (with-current-buffer (process-buffer process)
-    (setq pgg-gpg-pending-status-list status-list)
     (while (and (eq (process-status process) 'run)
-		pgg-gpg-pending-status-list)
+		(not (pgg-gpg-status-list-received status-list)))
       (accept-process-output process 1))))
 
 (defun pgg-gpg-wait-for-completion (process)
@@ -282,7 +289,7 @@
   "Decrypt the current region between START and END."
   (let* ((args '("--decrypt"))
 	 (process (pgg-gpg-start-process args)))
-    (process-send-region process start end)
+    (pgg-gpg-send-region process start end)
     (pgg-gpg-wait-for-status process '("BEGIN_DECRYPTION"))
     (pgg-gpg-wait-for-completion process)
     (save-excursion
@@ -346,6 +353,19 @@
       (goto-char (point-max))
       (not (null (re-search-backward "^\\[GNUPG:] IMPORT_RES\\>"
 				     nil t))))))
+
+(defun pgg-gpg-send-region (process start end)
+  "Send region to process line-by-line, as GnuPG may intersperse
+it with output."
+  (goto-char start)
+  (while (< (point) end)
+    (let ((bol (point)))
+      (end-of-line)
+      (let ((line (buffer-substring bol (point))))
+	(forward-line)
+	(process-send-string process (concat line "\n"))
+	(if (accept-process-output process 0 1)
+	    (while (accept-process-output process 0.3)))))))
 
 (provide 'pgg-gpg)
 

             reply	other threads:[~2007-07-25 10:15 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-25 10:15 Michael Sperber [this message]
2007-07-25 10:44 ` Daiki Ueno
2007-07-25 10:55   ` Michael Sperber
2007-07-25 12:18   ` Sascha Wilde
2007-07-25 12:40     ` Daiki Ueno
2007-07-25 17:40       ` Leo
2007-07-26  0:21         ` Miles Bader
2007-07-26  0:43           ` Daiki Ueno
2007-07-26  1:00             ` Miles Bader
2007-07-26 21:16           ` Reiner Steib
2007-07-26 23:53             ` Daiki Ueno
2007-07-28 15:22               ` Reiner Steib
2007-07-28 18:18                 ` Daiki Ueno
2007-07-29  8:03                   ` Daiki Ueno
2007-08-31  9:33                   ` PGG and EasyPG (was: pgg-gpg doesn't work at all [fix included]) Reiner Steib
2007-08-31 10:21                     ` Reverting PGG to v5-10 code base on the trunk (was: PGG and EasyPG) Reiner Steib
2007-10-03 13:59                       ` Reverting PGG to v5-10 code base on the trunk Reiner Steib
2007-10-03 14:17                         ` Simon Josefsson
2007-08-31 14:13                     ` PGG and EasyPG (was: pgg-gpg doesn't work at all [fix included]) Daiki Ueno
2007-09-03 21:36                       ` Leo
2007-09-04  7:00                         ` Daiki Ueno
2007-09-04  7:20                           ` Leo
2007-07-26 21:27     ` pgg-gpg doesn't work at all [fix included] Reiner Steib

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=y9lbqe094bv.fsf@informatik.uni-tuebingen.de \
    --to=sperber@informatik.uni-tuebingen.de \
    --cc=ding@gnus.org \
    --cc=ueno@unixuser.org \
    --cc=wilde@sha-bang.de \
    /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.
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 NNTP newsgroup(s).