annotate lisp/mailcrypt/mc-pgp.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ec9a17fef872
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;; mc-pgp.el, PGP support for Mailcrypt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Copyright (C) 1995 Jin Choi <jin@atype.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Patrick LoPresti <patl@lcs.mit.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;;{{{ Licensing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; This file is intended to be used with GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This program is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; This program is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; along with GNU Emacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;}}}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 (require 'mailcrypt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 (defvar mc-pgp-user-id (user-login-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 "*PGP ID of your default identity.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 (defvar mc-pgp-always-sign nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 "*If t, always sign encrypted PGP messages, or never sign if 'never.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 (defvar mc-pgp-path "pgp" "*The PGP executable.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 (defvar mc-pgp-display-snarf-output nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 "*If t, pop up the PGP output window when snarfing keys.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 (defvar mc-pgp-alternate-keyring nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 "*Public keyring to use instead of default.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (defvar mc-pgp-comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (format "Processed by Mailcrypt %s, an Emacs/PGP interface" mc-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 "*Comment field to appear in ASCII armor output. If nil, let PGP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 use its default.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (defconst mc-pgp-msg-begin-line "-----BEGIN PGP MESSAGE-----"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 "Text for start of PGP message delimiter.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (defconst mc-pgp-msg-end-line "-----END PGP MESSAGE-----\n?"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 "Text for end of PGP message delimiter.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (defconst mc-pgp-signed-begin-line "-----BEGIN PGP SIGNED MESSAGE-----"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 "Text for start of PGP signed messages.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (defconst mc-pgp-signed-end-line "-----END PGP SIGNATURE-----"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 "Text for end of PGP signed messages.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (defconst mc-pgp-key-begin-line "^-----BEGIN PGP PUBLIC KEY BLOCK-----\r?$"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 "Text for start of PGP public key.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (defconst mc-pgp-key-end-line "^-----END PGP PUBLIC KEY BLOCK-----\r?$"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 "Text for end of PGP public key.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (defconst mc-pgp-error-re "^\\(ERROR:\\|WARNING:\\).*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 "Regular expression matching an error from PGP")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (defconst mc-pgp-sigok-re "^.*Good signature.*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 "Regular expression matching a PGP signature validation message")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (defconst mc-pgp-newkey-re "^[ \t]*\\(No\\|[0-9]+\\) +new [ku].*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 "Regular expression matching a PGP key snarf message")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (defconst mc-pgp-nokey-re
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 "Cannot find the public key matching userid '\\(.+\\)'$"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 "Regular expression matching a PGP missing-key messsage")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (defconst mc-pgp-key-expected-re
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 "Key matching expected Key ID \\(\\S +\\) not found")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (defvar mc-pgp-keydir nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 "Directory in which keyrings are stored.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (defun mc-get-pgp-keydir ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (if (null mc-pgp-keydir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (let ((buffer (generate-new-buffer " *mailcrypt temp*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (obuf (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (call-process mc-pgp-path nil buffer nil "+verbose=1"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 "+language=en" "-kv" "XXXXXXXXXX")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (re-search-forward "^Key ring:\\s *'\\(.*\\)'")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (setq mc-pgp-keydir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (file-name-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (buffer-substring-no-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (match-beginning 1) (match-end 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (set-buffer obuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (kill-buffer buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 mc-pgp-keydir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (defvar mc-pgp-key-cache nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 "Association list mapping PGP IDs to canonical \"keys\". A \"key\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 is a pair (USER-ID . KEY-ID) which identifies the canonical IDs of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 PGP ID.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (defun mc-pgp-lookup-key (str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;; Look up the string STR in the user's secret key ring. Return a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;; pair of strings (USER-ID . KEY-ID) which uniquely identifies the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;; matching key, or nil if no key matches.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (if (equal str "***** CONVENTIONAL *****") nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (let ((keyring (concat (mc-get-pgp-keydir) "secring"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (result (cdr-safe (assoc str mc-pgp-key-cache)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (key-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 "^\\(pub\\|sec\\)\\s +[^/]+/\\(\\S *\\)\\s +\\S +\\s +\\(.*\\)$")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (obuf (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (if (null result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (setq buffer (generate-new-buffer " *mailcrypt temp"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (call-process mc-pgp-path nil buffer nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 "+language=en" "-kv" str keyring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (if (re-search-forward key-regexp nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (setq result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (cons (buffer-substring-no-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (match-beginning 3) (match-end 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 "0x"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (buffer-substring-no-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (match-beginning 2) (match-end 2)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (setq mc-pgp-key-cache (cons (cons str result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 mc-pgp-key-cache)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (if buffer (kill-buffer buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (set-buffer obuf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (if (null result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (error "No PGP secret key for %s" str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (defun mc-pgp-generic-parser (result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (let (start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (cond ((not (eq result 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (if (mc-message "^\aError: +Bad pass phrase\\.$" (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (mc-deactivate-passwd t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (mc-message mc-pgp-error-re (current-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (format "PGP exited with status %d" result)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ((re-search-forward mc-pgp-nokey-re nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (re-search-forward "-----BEGIN PGP.*-----$" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (setq start (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (re-search-backward "^-----END PGP.*-----\n" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (cons start (match-end 0)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (defun mc-pgp-encrypt-region (recipients start end &optional id sign)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (let ((process-environment process-environment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (buffer (get-buffer-create mc-buffer-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 ;; Crock. Rewrite someday.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (mc-pgp-always-sign mc-pgp-always-sign)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (obuf (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 action msg args key passwd result pgp-id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (setq args (list "+encrypttoself=off +verbose=1" "+batchmode"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 "+language=en" "-fat"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (setq action (if recipients "Encrypting" "Armoring"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (setq msg (format "%s..." action)) ; May get overridden below
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (if recipients (setq args (cons "-e" args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (if mc-pgp-comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (setq args (cons (format "+comment=%s" mc-pgp-comment) args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (if mc-pgp-alternate-keyring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (setq args (append args (list (format "+pubring=%s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 mc-pgp-alternate-keyring)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (if (and (not (eq mc-pgp-always-sign 'never))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (or mc-pgp-always-sign sign (y-or-n-p "Sign the message? ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (setq mc-pgp-always-sign t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (setq key (mc-pgp-lookup-key (or id mc-pgp-user-id)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (setq passwd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (mc-activate-passwd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (cdr key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (format "PGP passphrase for %s (%s): " (car key) (cdr key))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (setq args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (nconc args (list "-s" "-u" (cdr key))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (setenv "PGPPASSFD" "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (setq msg (format "%s+signing as %s ..." action (car key))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (setq mc-pgp-always-sign 'never))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (or key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (setq key (mc-pgp-lookup-key mc-pgp-user-id)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (if (and recipients mc-encrypt-for-me)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (setq recipients (cons (cdr key) recipients)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (setq args (append args recipients))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (message "%s" msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (setq result (mc-process-region start end passwd mc-pgp-path args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 'mc-pgp-generic-parser buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (if (re-search-forward mc-pgp-nokey-re nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (if result (error "This should never happen."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (setq pgp-id (buffer-substring-no-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (match-beginning 1) (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (if (and (not (eq mc-pgp-always-fetch 'never))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (or mc-pgp-always-fetch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (y-or-n-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (format "Key for '%s' not found; try to fetch? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 pgp-id))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (mc-pgp-fetch-key (cons pgp-id nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (set-buffer obuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (mc-pgp-encrypt-region recipients start end id))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (mc-message mc-pgp-nokey-re buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (if (not result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (message "%s Done." msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (defun mc-pgp-decrypt-parser (result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (cond ((eq result 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 ;; Valid signature
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (re-search-forward "^Signature made.*\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (if (looking-at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 "\a\nWARNING: Because this public key.*\n.*\n.*\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (goto-char (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (cons (point) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 ((eq result 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (re-search-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 "\\(\\(^File is conven.*\\)?Just a moment\\.+\\)\\|\\(^\\.\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (if (eq (match-beginning 2) (match-end 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (if (looking-at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 "\nFile has signature.*\\(\n\a.*\n\\)*\nWARNING:.*\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (goto-char (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (if (looking-at "Pass phrase appears good\\. \\.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (goto-char (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (cons (point) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (t nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (defun mc-pgp-decrypt-region (start end &optional id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 ;; returns a pair (SUCCEEDED . VERIFIED) where SUCCEEDED is t if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 ;; the decryption succeeded and verified is t if there was a valid signature
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (let ((process-environment process-environment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (buffer (get-buffer-create mc-buffer-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 args key new-key passwd result pgp-id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (undo-boundary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (setq key (mc-pgp-lookup-key (or id mc-pgp-user-id)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (setq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 passwd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (if key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (mc-activate-passwd (cdr key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (and id
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (format "PGP passphrase for %s (%s): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (car key) (cdr key))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (mc-activate-passwd id "PGP passphrase for conventional decryption: ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (if passwd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (setenv "PGPPASSFD" "0"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (setq args '("+verbose=1" "+batchmode" "+language=en" "-f"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (if mc-pgp-alternate-keyring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (setq args (append args (list (format "+pubring=%s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 mc-pgp-alternate-keyring)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (message "Decrypting...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (setq result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (mc-process-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 start end passwd mc-pgp-path args 'mc-pgp-decrypt-parser buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (message "Decrypting... Done.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;; If verification failed due to missing key, offer to fetch it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (if (re-search-forward mc-pgp-key-expected-re nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (setq pgp-id (concat "0x" (buffer-substring-no-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (match-end 1))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (if (and pgp-id
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (not (eq mc-pgp-always-fetch 'never))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (or mc-pgp-always-fetch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (y-or-n-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (format "Key %s not found; attempt to fetch? " pgp-id)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (mc-pgp-fetch-key (cons nil pgp-id)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (undo-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (undo-more 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (mc-pgp-decrypt-region start end id))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (mc-message mc-pgp-key-expected-re buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (cons t (eq result 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 ;; Decryption failed; maybe we need to use a different user-id
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 ((save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (re-search-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 "^Key for user ID:.*\n.*Key ID \\([0-9A-F]+\\)" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (setq new-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (mc-pgp-lookup-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (concat "0x" (buffer-substring-no-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (match-end 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (not (and id (equal key new-key)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (mc-pgp-decrypt-region start end (cdr new-key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 ;; Or maybe it is conventionally encrypted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 ((save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (re-search-forward "^File is conventionally encrypted" nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (if (null key) (mc-deactivate-passwd t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (mc-pgp-decrypt-region start end "***** CONVENTIONAL *****"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (mc-display-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (if (mc-message "^\aError: +Bad pass phrase\\.$" buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (mc-deactivate-passwd t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (mc-message mc-pgp-error-re buffer "Error decrypting buffer"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (cons nil nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (defun mc-pgp-sign-region (start end &optional id unclear)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (let ((process-environment process-environment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (buffer (get-buffer-create mc-buffer-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 passwd args key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (setq key (mc-pgp-lookup-key (or id mc-pgp-user-id)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (setq passwd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (mc-activate-passwd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (cdr key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (format "PGP passphrase for %s (%s): " (car key) (cdr key))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (setenv "PGPPASSFD" "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (setq args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 "-fast" "+verbose=1" "+language=en"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (format "+clearsig=%s" (if unclear "off" "on"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 "+batchmode" "-u" (cdr key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (if mc-pgp-comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (setq args (cons (format "+comment=%s" mc-pgp-comment) args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (message "Signing as %s ..." (car key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (if (mc-process-region start end passwd mc-pgp-path args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 'mc-pgp-generic-parser buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (message "Signing as %s ... Done." (car key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (defun mc-pgp-verify-parser (result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (cond ((eq result 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (mc-message mc-pgp-sigok-re (current-buffer) "Good signature")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 ((eq result 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (mc-message mc-pgp-error-re (current-buffer) "Bad signature")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (mc-message mc-pgp-error-re (current-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (format "PGP exited with status %d" result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (defun mc-pgp-verify-region (start end &optional no-fetch)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (let ((buffer (get-buffer-create mc-buffer-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (obuf (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 args pgp-id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (setq args '("+verbose=1" "+batchmode" "+language=en" "-f"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (if mc-pgp-alternate-keyring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (setq args (append args (list (format "+pubring=%s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 mc-pgp-alternate-keyring)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (message "Verifying...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (if (mc-process-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 start end nil mc-pgp-path args 'mc-pgp-verify-parser buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (if (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (not no-fetch)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (re-search-forward mc-pgp-key-expected-re nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (setq pgp-id
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (concat "0x" (buffer-substring-no-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (match-end 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (not (eq mc-pgp-always-fetch 'never))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (or mc-pgp-always-fetch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (y-or-n-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (format "Key %s not found; attempt to fetch? " pgp-id)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (mc-pgp-fetch-key (cons nil pgp-id))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (set-buffer obuf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (mc-pgp-verify-region start end t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (mc-message mc-pgp-error-re buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (defun mc-pgp-insert-public-key (&optional id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (let ((buffer (get-buffer-create mc-buffer-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (setq id (or id mc-pgp-user-id))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (setq args (list "+verbose=1" "+batchmode" "+language=en" "-kxaf" id))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (if mc-pgp-comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (setq args (cons (format "+comment=%s" mc-pgp-comment) args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (if mc-pgp-alternate-keyring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (setq args (append args (list (format "+pubring=%s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 mc-pgp-alternate-keyring)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (if (mc-process-region (point) (point) nil mc-pgp-path
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 args 'mc-pgp-generic-parser buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (mc-message "Key for user ID: .*" buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (defun mc-pgp-snarf-parser (result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (eq result 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (defun mc-pgp-snarf-keys (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 ;; Returns number of keys found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (let ((buffer (get-buffer-create mc-buffer-name)) tmpstr args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (setq args '("+verbose=1" "+batchmode" "+language=en" "-kaf"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (if mc-pgp-alternate-keyring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (setq args (append args (list (format "+pubring=%s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 mc-pgp-alternate-keyring)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (message "Snarfing...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (if (mc-process-region start end nil mc-pgp-path args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 'mc-pgp-snarf-parser buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (if (re-search-forward mc-pgp-newkey-re nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (if mc-pgp-display-snarf-output (mc-display-buffer buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (setq tmpstr (buffer-substring-no-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (if (equal tmpstr "No")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (car (read-from-string tmpstr))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (mc-display-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (mc-message mc-pgp-error-re buffer "Error snarfing PGP keys")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (defun mc-scheme-pgp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (cons 'encryption-func 'mc-pgp-encrypt-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (cons 'decryption-func 'mc-pgp-decrypt-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (cons 'signing-func 'mc-pgp-sign-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (cons 'verification-func 'mc-pgp-verify-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (cons 'key-insertion-func 'mc-pgp-insert-public-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (cons 'snarf-func 'mc-pgp-snarf-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (cons 'msg-begin-line mc-pgp-msg-begin-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (cons 'msg-end-line mc-pgp-msg-end-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (cons 'signed-begin-line mc-pgp-signed-begin-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (cons 'signed-end-line mc-pgp-signed-end-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (cons 'key-begin-line mc-pgp-key-begin-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (cons 'key-end-line mc-pgp-key-end-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (cons 'user-id mc-pgp-user-id)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 ;;{{{ Key fetching
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (defvar mc-pgp-always-fetch nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 "*If t, always attempt to fetch missing keys, or never fetch if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 'never.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (defvar mc-pgp-keyserver-url-template
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 "/htbin/pks-extract-key.pl?op=get&search=%s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 "The URL to pass to the keyserver.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (defvar mc-pgp-keyserver-address "pgp.ai.mit.edu"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 "Host name of keyserver.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (defvar mc-pgp-keyserver-port 80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 "Port on which the keyserver's HTTP daemon lives.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (defvar mc-pgp-fetch-timeout 20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 "*Timeout, in seconds, for any particular key fetch operation.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (defvar mc-pgp-fetch-keyring-list nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 "*List of strings which are filenames of public keyrings to search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 when fetching keys.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (defsubst mc-pgp-buffer-get-key (buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 "Return the first key block in BUF as a string, or nil if none found."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (let (start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (and (re-search-forward mc-pgp-key-begin-line nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (setq start (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (re-search-forward mc-pgp-key-end-line nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (buffer-substring-no-properties start (match-end 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (defun mc-pgp-fetch-from-keyrings (id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (let ((keyring-list mc-pgp-fetch-keyring-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 buf proc key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (message "Fetching %s from keyrings..." (or (cdr id) (car id)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (while (and (not key) keyring-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (setq buf (generate-new-buffer " *mailcrypt temp*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (setq proc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (start-process "*PGP*" buf mc-pgp-path "-kxaf"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 "+verbose=0" "+batchmode"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (format "+pubring=%s" (car keyring-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (or (cdr id) (car id))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 ;; Because PGPPASSFD might be set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (process-send-string proc "\r\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (while (eq 'run (process-status proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (accept-process-output proc 5))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (setq key (mc-pgp-buffer-get-key buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (setq keyring-list (cdr keyring-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (if buf (kill-buffer buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (if (and proc (eq 'run (process-status proc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (interrupt-process proc)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (defun mc-pgp-fetch-from-http (id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (let (buf connection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (message "Fetching %s via HTTP to %s..."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (or (cdr id) (car id)) mc-pgp-keyserver-address)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (setq buf (generate-new-buffer " *mailcrypt temp*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (setq connection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (open-network-stream "*key fetch*" buf mc-pgp-keyserver-address
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 mc-pgp-keyserver-port))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (process-send-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 connection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (concat "GET " (format mc-pgp-keyserver-url-template
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (or (cdr id) (car id))) "\r\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (while (and (eq 'open (process-status connection))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (accept-process-output connection mc-pgp-fetch-timeout)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (mc-pgp-buffer-get-key buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (if buf (kill-buffer buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (if connection (delete-process connection)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (defun mc-pgp-fetch-from-finger (id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (let (buf connection user host)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (and (car id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (string-match "^\\(.+\\)@\\([^@]+\\)$" (car id))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (message "Trying finger %s..." (car id))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (setq user (substring (car id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (match-beginning 1) (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (setq host (substring (car id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (match-beginning 2) (match-end 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (setq buf (generate-new-buffer " *mailcrypt temp*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (setq connection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (open-network-stream "*key fetch*" buf host 79))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (process-send-string connection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (concat "/W " user "\r\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (and (eq 'open (process-status connection))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (accept-process-output connection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 mc-pgp-fetch-timeout)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (mc-pgp-buffer-get-key buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (error nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (if buf (kill-buffer buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (if connection (delete-process connection)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (defvar mc-pgp-fetch-methods '(mc-pgp-fetch-from-keyrings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 mc-pgp-fetch-from-finger
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 mc-pgp-fetch-from-http)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 "List of methods to try when attempting to fetch a key. Each
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 element is a function to call with an ID as argument. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 documentation for the function mc-pgp-fetch-key for a description of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 the ID.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (defun mc-pgp-fetch-key (&optional id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 "Attempt to fetch a key for addition to PGP keyring. Interactively,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 prompt for string matching key to fetch.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 Non-interactively, ID must be a pair. The CAR must be a bare Email
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 address and the CDR a keyID (with \"0x\" prefix). Either, but not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 both, may be nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 Return t if we think we were successful; nil otherwise. Note that nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 is not necessarily an error, since we may have merely fired off an Email
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 request for the key."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (let ((methods mc-pgp-fetch-methods)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (process-connection-type nil) key proc buf args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (if (null id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (setq id (cons (read-string "Fetch key for: ") nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (while (and (not key) methods)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (setq key (funcall (car methods) id))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (setq methods (cdr methods)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (if (not (stringp key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (message "Key not found.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 ;; Maybe I'll do this right someday.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (setq buf (generate-new-buffer " *PGP Key Info*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (pop-to-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (if (< (window-height) (/ (frame-height) 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (enlarge-window (- (/ (frame-height) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (window-height))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (setq args '("-f" "+verbose=0" "+batchmode"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (if mc-pgp-alternate-keyring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 (setq args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 (append args (list (format "+pubring=%s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 mc-pgp-alternate-keyring)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (setq proc (apply 'start-process "*PGP*" buf mc-pgp-path args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 ;; Because PGPPASSFD might be set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (process-send-string proc "\r\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 (process-send-string proc key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (process-send-string proc "\r\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (process-send-eof proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (while (eq 'run (process-status proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (accept-process-output proc 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (goto-char (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (if (y-or-n-p "Add this key to keyring? ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (setq args (append args '("-ka")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (setq proc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (apply 'start-process "*PGP*" buf mc-pgp-path args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 ;; Because PGPPASSFD might be set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 (process-send-string proc "\r\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (process-send-string proc key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (process-send-string proc "\r\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (process-send-eof proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (while (eq 'run (process-status proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (accept-process-output proc 5))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (if buf (kill-buffer buf))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 ;;}}}