When doing partial marks update, get the range update right.
[gnus] / contrib / gpg.el
1 ;;; gpg.el --- Interface to GNU Privacy Guard
2
3 ;; Copyright (C) 2000 RUS-CERT, University Of Stuttgart
4
5 ;; Author: Florian Weimer <Florian.Weimer@RUS.Uni-Stuttgart.DE>
6 ;; Maintainer: Florian Weimer <Florian.Weimer@RUS.Uni-Stuttgart.DE>
7 ;; Keywords: crypto
8 ;; Created: 2000-04-15
9
10 ;; This file is NOT (yet?) part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
26
27 ;;; Commentary:
28
29 ;; ALPHA ALPHA ALPHA ALPHA ALPHA ALPHA ALPHA ALPHA ALPHA ALPHA ALPHA
30 ;; ALPHA ALPHA ALPHA ALPHA ALPHA ALPHA ALPHA ALPHA ALPHA ALPHA ALPHA
31 ;;
32 ;; This code is not well-tested.  BE CAREFUL!
33 ;; 
34 ;; ALPHA ALPHA ALPHA ALPHA ALPHA ALPHA ALPHA ALPHA ALPHA ALPHA ALPHA
35 ;; ALPHA ALPHA ALPHA ALPHA ALPHA ALPHA ALPHA ALPHA ALPHA ALPHA ALPHA
36
37 ;; Implemented features which can be tested:
38 ;;
39 ;; * Customization for all flavors of PGP is possible.
40 ;; * The main operations (verify, decrypt, sign, encrypt, sign &
41 ;;   encrypt) are implemented.
42 ;; * Optionally, Gero Treuner's gpg-2comp script is supported, 
43 ;;   to generate data which is compatible with PGP 2.6.3.
44
45 ;; Customizing external programs 
46 ;; =============================
47
48 ;; The customization are very similar to those of others programs,
49 ;; only the C-ish "%" constructs have been replaced by more Lisp-like
50 ;; syntax.
51 ;;
52 ;; First, you have to adjust the default executable paths
53 ;; (`gpg-command-default-alist', customization group `gpg-options',
54 ;; "Controlling GnuPG invocation.").  After that, you should
55 ;; change the configuration options which control how specific
56 ;; command line flags are built (`gpg-command-flag-sign-with-key',
57 ;; (`gpg-command-flag-recipient').  The elements of these lists are
58 ;; concatenated without spaces, and a new argument is only started
59 ;; where indicated.  The `gpg-command-flag-recipient' list is special:
60 ;; it consists of two parts, the first one remains at the beginning
61 ;; of the argument, the second one is repeated for each recipient.
62 ;; Finally, `gpg-command-passphrase-env' has to be changed if there's
63 ;; no command line flag to force the external program to read the data
64 ;; from standard input before the message.
65 ;;
66 ;; In customization group `gpg-commands', "Controlling GnuPG
67 ;; invocation.", you have to supply the actual syntax for external
68 ;; program calls.  Each variable consists of a pair of a program
69 ;; specification (if a Lisp symbol is given here, it is translated
70 ;; via `gpg-command-default-alist') and a list of program arguments
71 ;; with placeholders.  Please read the documentation of each variable
72 ;; before making your adjustments and try to match the given
73 ;; requirements as closely as possible!
74 ;;
75 ;; The `gpg-commands-key' group, "GnuPG Key Management Commands.",
76 ;; specifies key management commands.  The syntax of these variables
77 ;; is like those in the `gpg-commands' group.  Note that the output
78 ;; format of some of these external programs has to match very close
79 ;; that of GnuPG.  Additional tools (Thomas Roessler's "pgpring.c")
80 ;; are available if your favorite implementation of OpenPGP cannot
81 ;; output the this format.
82
83 ;; Security considerations 
84 ;; =======================
85
86 ;; On a typical multiuser UNIX system, the memory image of the
87 ;; Emacs process is not locked, therefore it can be swapped to disk
88 ;; at any time.  As a result, the passphrase might show up in the
89 ;; swap space (even if you don't use the passphrase cache, i.e. if
90 ;; `gpg-passphrase-timeout' is 0).  If someone is able to run `gdb' or
91 ;; another debugger on your Emacs process, he might be able to recover
92 ;; the passphrase as well.  Unfortunately, nothing can be done in
93 ;; order to prevent this at the moment.
94 ;;
95 ;; BE CAREFUL: If you use the passphrase cache feature, the passphrase
96 ;; is stored in the variable `gpg-passphrase' -- and it is NOT
97 ;; encrypted in any way.  (This is a conceptual problem because the
98 ;; nature of the passphrase cache requires that Emacs is able to
99 ;; decrypt automatically, so only a very weak protection could be
100 ;; applied anyway.)
101 ;;
102 ;; In addition, if you use an unpatched Emacs 20 (and earlier
103 ;; versions), passwords show up in the output of the `view-lossage'
104 ;; function (bound to `C-h l' by default).
105
106 \f
107 ;;; Code:
108
109 (if (featurep 'xemacs)
110     (require 'timer-funcs)
111   (require 'timer))
112 (eval-when-compile (require 'cl))
113
114 (eval-and-compile 
115   (defalias 'gpg-point-at-eol
116     (if (fboundp 'point-at-eol)
117         'point-at-eol
118       'line-end-position)))
119
120 ;; itimer/timer compatibility
121 (eval-and-compile
122   (if (featurep 'xemacs)
123       (progn
124         (defalias 'gpg-cancel-timer 'delete-itimer)
125         (defalias 'gpg-timer-activate 'activate-itimer)
126         (defalias 'gpg-timer-create 'make-itimer)
127         (defalias 'gpg-timer-set-function 'set-itimer-function)
128         (defalias 'gpg-timer-set-time 'set-itimer-value))
129     (defalias 'gpg-cancel-timer 'cancel-timer)
130     (defalias 'gpg-timer-activate 'timer-activate)
131     (defalias 'gpg-timer-create 'timer-create)
132     (defalias 'gpg-timer-set-function 'timer-set-function)
133     (defalias 'gpg-timer-set-time 'timer-set-time)))
134
135 ;;;; Customization:
136
137 ;;; Customization: Groups:
138
139 (defgroup gpg nil
140   "GNU Privacy Guard interface."
141   :tag "GnuPG"
142   :group 'processes)
143
144 (defgroup gpg-options nil
145   "Controlling GnuPG invocation."
146   :tag "GnuPG Options"
147   :group 'gpg)
148
149 (defgroup gpg-commands nil
150   "Primary GnuPG Operations."
151   :tag "GnuPG Commands"
152   :group 'gpg)
153
154 (defgroup gpg-commands-key nil
155   "Commands for GnuPG key management."
156   :tag "GnuPG Key Commands"
157   :group 'gpg-commands)
158
159 ;;; Customization: Widgets:
160
161 (if (get 'alist 'widget-type)
162     (define-widget 'gpg-command-alist 'alist
163       "An association list for GnuPG command names."
164       :key-type '(symbol :tag   "Abbreviation")
165       :value-type '(string :tag "Program name")
166       :convert-widget 'widget-alist-convert-widget
167       :tag "Alist")
168     (define-widget 'gpg-command-alist 'repeat
169       "An association list for GnuPG command names."
170       :args '((cons :format "%v"
171                     (symbol :tag   "Abbreviation")
172                     (string :tag "Program name")))
173       :tag "Alist"))
174
175 (define-widget 'gpg-command-program 'choice
176   "Widget for entering the name of a program (mostly the GnuPG binary)."
177   :tag "Program"
178   :args '((const :tag "Default GnuPG program."
179                  :value gpg)
180           (const :tag "GnuPG compatibility wrapper."
181                  :value gpg-2comp)
182           (const :tag "Disabled"
183                  :value nil)
184           (string :tag "Custom program" :format "%v")))
185
186 (define-widget 'gpg-command-sign-options 'cons
187   "Widget for entering signing options."
188   :args '(gpg-command-program
189           (repeat 
190            :tag "Arguments"
191            (choice 
192             :format "%[Type%] %v"
193             (const :tag "Insert armor option here if necessary."
194                    :value armor)
195             (const :tag "Insert text mode option here if necessary."
196                    :value textmode)
197             (const :tag "Insert the sign with key option here if necessary."
198                    :value sign-with-key)
199             (string :format "%v")))))
200
201 (define-widget 'gpg-command-key-options 'cons
202   "Widget for entering key command options."
203   :args '(gpg-command-program
204           (repeat 
205            :tag "Arguments"
206            (choice 
207             :format "%[Type%] %v"
208             (const :tag "Insert key ID here." 
209                    :value key-id)