Gnus development mailing list
 help / color / mirror / Atom feed
* PGG with multiple GnuPG keys
@ 2003-11-08 21:43 Satyaki Das
  2003-11-09  4:04 ` Simon Josefsson
  0 siblings, 1 reply; 12+ messages in thread
From: Satyaki Das @ 2003-11-08 21:43 UTC (permalink / raw)



I've two GPG keys, the older one being a revoked key of
length 768. However with PGG, I can't decrypt any of the
messages that were encrypted for the older key. The problem is
that PGG feeds the pass phrase of my new key when trying to
decrypt messages with the old key.

The attached patch solves this by checking the message to be
decrypted to find the secret key in the user's ring that it
was encrypted for. Then the passphrase of this key is prompted
for, or read from the cache, and the correct passphrase given
to gpg.

Such functionality in PGG would be very helpful.

Thanks,
Satyaki

Index: pgg-gpg.el
===================================================================
RCS file: /usr/local/cvsroot/gnus/lisp/pgg-gpg.el,v
retrieving revision 6.19
diff -u -r6.19 pgg-gpg.el
--- pgg-gpg.el	27 Oct 2003 21:46:41 -0000	6.19
+++ pgg-gpg.el	8 Nov 2003 21:17:43 -0000
@@ -103,6 +103,26 @@
 		 (substring (match-string 0) -8))))
        passphrase)))
 
+(defvar pgg-gpg-all-secret-keys 'unknown)
+
+(defun pgg-gpg-lookup-all-secret-keys ()
+  "Return all secret keys present in secret key ring."
+  (when (eq pgg-gpg-all-secret-keys 'unknown)
+    (setq pgg-gpg-all-secret-keys '())
+    (let ((args (list "--with-colons" "--no-greeting" "--batch"
+                      "--list-secret-keys")))
+      (with-temp-buffer
+        (apply #'call-process pgg-gpg-program nil t nil args)
+        (goto-char (point-min))
+        (while (re-search-forward "^\\(sec\\|pub\\):"  nil t)
+          (push (substring
+                 (nth 3 (split-string
+                         (buffer-substring (match-end 0)
+                                           (progn (end-of-line) (point)))
+                         ":")) 8)
+                pgg-gpg-all-secret-keys)))))
+  pgg-gpg-all-secret-keys)
+
 (defun pgg-gpg-lookup-key (string &optional type)
   "Search keys associated with STRING."
   (let ((args (list "--with-colons" "--no-greeting" "--batch"
@@ -147,7 +167,13 @@
 
 (defun pgg-gpg-decrypt-region (start end)
   "Decrypt the current region between START and END."
-  (let* ((pgg-gpg-user-id (or pgg-gpg-user-id pgg-default-user-id))
+  (let* ((current-buffer (current-buffer))
+         (message-keys (with-temp-buffer
+                         (insert-buffer-substring current-buffer)
+                         (pgg-decode-armor-region (point-min) (point-max))))
+         (secret-keys (pgg-gpg-lookup-all-secret-keys))
+         (key (pgg-gpg-select-matching-key message-keys secret-keys))
+         (pgg-gpg-user-id (or key pgg-gpg-user-id pgg-default-user-id))
 	 (passphrase
 	  (pgg-read-passphrase
 	   (format "GnuPG passphrase for %s: " pgg-gpg-user-id)
@@ -158,6 +184,14 @@
       (pgg-gpg-possibly-cache-passphrase passphrase pgg-gpg-user-id)
       (goto-char (point-min))
       (re-search-forward "^\\[GNUPG:] DECRYPTION_OKAY\\>" nil t))))
+
+(defun pgg-gpg-select-matching-key (message-keys secret-keys)
+  "Choose a key from MESSAGE-KEYS that matches one of the keys in SECRET-KEYS."
+  (loop for message-key in message-keys
+        for message-key-id = (and (equal (car message-key) 1)
+                                  (cdr (assq 'key-identifier message-key)))
+        for key = (and message-key-id (pgg-lookup-key message-key-id 'encrypt))
+        when (and key (member key secret-keys)) return key))
 
 (defun pgg-gpg-sign-region (start end &optional cleartext)
   "Make detached signature from text between START and END."



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2003-11-10 20:53 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-08 21:43 PGG with multiple GnuPG keys Satyaki Das
2003-11-09  4:04 ` Simon Josefsson
2003-11-09 20:16   ` Satyaki Das
2003-11-09 21:45     ` Simon Josefsson
2003-11-09 22:00       ` PGG default values (was: Re: PGG with multiple GnuPG keys) Simon Josefsson
2003-11-09 22:22         ` PGG default values Jesper Harder
2003-11-10  2:31         ` PGG default values (was: Re: PGG with multiple GnuPG keys) Satyaki Das
2003-11-10  3:13           ` PGG default values Simon Josefsson
2003-11-10 15:12         ` Jorge Godoy
2003-11-10 16:19           ` Simon Josefsson
2003-11-10 20:53             ` Jorge Godoy
2003-11-10  2:20       ` PGG with multiple GnuPG keys Satyaki Das

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).