Merge from gnus--rel--5.10
[gnus] / texi / pgg.texi
1 \input texinfo                  @c -*-texinfo-*-
2
3 @setfilename pgg
4
5 @set VERSION 0.1
6
7
8 @copying
9 This file describes PGG, an Emacs interface to various PGP implementations.
10
11 Copyright @copyright{} 2001, 2003, 2004, 2005, 2006, 2007  Free Software
12 Foundation, Inc.
13
14 @quotation
15 Permission is granted to copy, distribute and/or modify this document
16 under the terms of the GNU Free Documentation License, Version 1.2 or
17 any later version published by the Free Software Foundation; with no
18 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
19 Texts.  A copy of the license is included in the section entitled ``GNU
20 Free Documentation License.''
21 @end quotation
22 @end copying
23
24 @dircategory Emacs
25 @direntry
26 * PGG: (pgg).   Emacs interface to various PGP implementations.
27 @end direntry
28
29 @settitle PGG @value{VERSION}
30
31
32 @titlepage
33 @title PGG
34
35 @author by Daiki Ueno
36 @page
37
38 @vskip 0pt plus 1filll
39 @insertcopying
40 @end titlepage
41 @page
42
43 @node Top
44 @top PGG
45 This manual describes PGG.  PGG is an interface library between Emacs
46 and various tools for secure communication.  PGG also provides a simple
47 user interface to encrypt, decrypt, sign, and verify MIME messages.
48
49 @menu
50 * Overview::                    What PGG is.
51 * Prerequisites::               Complicated stuff you may have to do.
52 * How to use::                  Getting started quickly.
53 * Architecture::                
54 * Parsing OpenPGP packets::     
55 * Function Index::              
56 * Variable Index::              
57 @end menu
58
59 @node Overview
60 @chapter Overview
61
62 PGG is an interface library between Emacs and various tools for secure
63 communication.  Even though Mailcrypt has similar feature, it does not
64 deal with detached PGP messages, normally used in PGP/MIME
65 infrastructure.  This was the main reason why I wrote the new library.
66
67 PGP/MIME is an application of MIME Object Security Services (RFC1848).
68 The standard is documented in RFC2015.
69
70 @node Prerequisites
71 @chapter Prerequisites
72
73 PGG requires at least one implementation of privacy guard system.
74 This document assumes that you have already obtained and installed them
75 and that you are familiar with its basic functions.
76
77 By default, PGG uses GnuPG.  If you are new to such a system, I
78 recommend that you should look over the GNU Privacy Handbook (GPH)
79 which is available at @uref{http://www.gnupg.org/documentation/}.
80
81 When using GnuPG, we recommend the use of the @code{gpg-agent}
82 program, which is distributed with versions 2.0 and later of GnuPG.
83 This is a daemon to manage private keys independently from any
84 protocol, and provides the most secure way to input and cache your
85 passphrases (@pxref{Caching passphrase}).  By default, PGG will
86 attempt to use @code{gpg-agent} if it is running.  @xref{Invoking
87 GPG-AGENT,,,gnupg,Using the GNU Privacy Guard}.
88
89 PGG also supports Pretty Good Privacy version 2 or version 5.
90
91 @node How to use
92 @chapter How to use
93
94 The toplevel interface of this library is quite simple, and only
95 intended to use with public-key cryptographic operation.
96
97 To use PGG, evaluate following expression at the beginning of your
98 application program.
99
100 @lisp
101 (require 'pgg)
102 @end lisp
103
104 If you want to check existence of pgg.el at runtime, instead you can
105 list autoload setting for desired functions as follows.
106
107 @lisp
108 (autoload 'pgg-encrypt-region "pgg"
109   "Encrypt the current region." t)
110 (autoload 'pgg-encrypt-symmetric-region "pgg"
111   "Encrypt the current region with symmetric algorithm." t)
112 (autoload 'pgg-decrypt-region "pgg"
113   "Decrypt the current region." t)
114 (autoload 'pgg-sign-region "pgg"
115   "Sign the current region." t)
116 (autoload 'pgg-verify-region "pgg"
117   "Verify the current region." t)
118 (autoload 'pgg-insert-key "pgg"
119   "Insert the ASCII armored public key." t)
120 (autoload 'pgg-snarf-keys-region "pgg"
121   "Import public keys in the current region." t)
122 @end lisp
123
124 @menu
125 * User Commands::               
126 * Selecting an implementation::  
127 * Caching passphrase::          
128 * Default user identity::       
129 @end menu
130
131 @node User Commands
132 @section User Commands
133
134 At this time you can use some cryptographic commands.  The behavior of
135 these commands relies on a fashion of invocation because they are also
136 intended to be used as library functions.  In case you don't have the
137 signer's public key, for example, the function @code{pgg-verify-region}
138 fails immediately, but if the function had been called interactively, it
139 would ask you to retrieve the signer's public key from the server.
140
141 @deffn Command pgg-encrypt-region start end recipients &optional sign passphrase
142 Encrypt the current region between @var{start} and @var{end} for
143 @var{recipients}.  When the function were called interactively, you
144 would be asked about the recipients.
145
146 If encryption is successful, it replaces the current region contents (in
147 the accessible portion) with the resulting data.
148
149 If optional argument @var{sign} is non-@code{nil}, the function is
150 request to do a combined sign and encrypt.  This currently is
151 confirmed to work with GnuPG, but might not work with PGP or PGP5.
152
153 If optional @var{passphrase} is @code{nil}, the passphrase will be
154 obtained from the passphrase cache or user.
155 @end deffn
156
157 @deffn Command pgg-encrypt-symmetric-region &optional start end passphrase
158 Encrypt the current region between @var{start} and @var{end} using a
159 symmetric cipher.  After invocation you are asked for a passphrase.
160
161 If optional @var{passphrase} is @code{nil}, the passphrase will be
162 obtained from the passphrase cache or user.
163
164 symmetric-cipher encryption is currently only implemented for GnuPG.
165 @end deffn
166
167 @deffn Command pgg-decrypt-region start end &optional passphrase
168 Decrypt the current region between @var{start} and @var{end}.  If
169 decryption is successful, it replaces the current region contents (in
170 the accessible portion) with the resulting data.
171
172 If optional @var{passphrase} is @code{nil}, the passphrase will be
173 obtained from the passphrase cache or user.
174 @end deffn
175
176 @deffn Command pgg-sign-region start end &optional cleartext passphrase
177 Make the signature from text between @var{start} and @var{end}.  If the
178 optional third argument @var{cleartext} is non-@code{nil}, or the
179 function is called interactively, it does not create a detached
180 signature.  In such a case, it replaces the current region contents (in
181 the accessible portion) with the resulting data.
182
183 If optional @var{passphrase} is @code{nil}, the passphrase will be
184 obtained from the passphrase cache or user.
185 @end deffn
186
187 @deffn Command pgg-verify-region start end &optional signature fetch
188 Verify the current region between @var{start} and @var{end}.  If the
189 optional third argument @var{signature} is non-@code{nil}, it is treated
190 as the detached signature file of the current region.
191
192 If the optional 4th argument @var{fetch} is non-@code{nil}, or the
193 function is called interactively, we attempt to fetch the signer's
194 public key from the key server.
195 @end deffn
196
197 @deffn Command pgg-insert-key
198 Retrieve the user's public key and insert it as ASCII-armored format.
199 @end deffn
200
201 @deffn Command pgg-snarf-keys-region start end
202 Collect public keys in the current region between @var{start} and
203 @var{end}, and add them into the user's keyring.
204 @end deffn
205
206 @node Selecting an implementation
207 @section Selecting an implementation
208
209 Since PGP has a long history and there are a number of PGP
210 implementations available today, the function which each one has differs
211 considerably.  For example, if you are using GnuPG, you know you can
212 select cipher algorithm from 3DES, CAST5, BLOWFISH, and so on, but on
213 the other hand the version 2 of PGP only supports IDEA.
214
215 Which implementation is used is controlled by the @code{pgg-scheme}
216 variable.  If it is @code{nil} (the default), the value of the
217 @code{pgg-default-scheme} variable will be used instead.
218
219 @defvar pgg-scheme
220 Force specify the scheme of PGP implementation.  The value can be set to
221 @code{gpg}, @code{pgp}, and @code{pgp5}.  The default is @code{nil}.
222 @end defvar
223
224 @defvar pgg-default-scheme
225 The default scheme of PGP implementation.  The value should be one of
226 @code{gpg}, @code{pgp}, and @code{pgp5}.  The default is @code{gpg}.
227 @end defvar
228
229 @node Caching passphrase
230 @section Caching passphrase
231
232 When using GnuPG (gpg) as the PGP scheme, we recommend using a program
233 called @code{gpg-agent} for entering and caching
234 passphrases@footnote{Actually, @code{gpg-agent} does not cache
235 passphrases but private keys.  On the other hand, from a user's point
236 of view, this technical difference isn't visible.}.
237
238 @defvar pgg-gpg-use-agent
239 If non-@code{nil}, attempt to use @code{gpg-agent} whenever possible.
240 The default is @code{t}.  If @code{gpg-agent} is not running, or GnuPG
241 is not the current PGP scheme, PGG's own passphrase-caching mechanism
242 is used (see below).
243 @end defvar
244
245 To use @code{gpg-agent} with PGG, you must first ensure that
246 @code{gpg-agent} is running.  For example, if you are running in the X
247 Window System, you can do this by putting the following line in your
248 @file{.xsession} file:
249
250 @smallexample
251 eval "$(gpg-agent --daemon)"
252 @end smallexample
253
254 For more details on invoking @code{gpg-agent}, @xref{Invoking
255 GPG-AGENT,,,gnupg,Using the GNU Privacy Guard}.
256
257 Whenever you perform a PGG operation that requires a GnuPG passphrase,
258 GnuPG will contact @code{gpg-agent}, which prompts you for the
259 passphrase.  Furthermore, @code{gpg-agent} ``caches'' the result, so
260 that subsequent uses will not require you to enter the passphrase
261 again.  (This cache usually expires after a certain time has passed;
262 you can change this using the @code{--default-cache-ttl} option when
263 invoking @code{gpg-agent}.)
264
265 If you are running in a X Window System environment, @code{gpg-agent}
266 prompts for a passphrase by opening a graphical window.  However, if
267 you are running Emacs on a text terminal, @code{gpg-agent} has trouble
268 receiving input from the terminal, since it is being sent to Emacs.
269 One workaround for this problem is to run @code{gpg-agent} on a
270 different terminal from Emacs, with the @code{--keep-tty} option; this
271 tells @code{gpg-agent} use its own terminal to prompt for passphrases.
272
273 When @code{gpg-agent} is not being used, PGG prompts for a passphrase
274 through Emacs.  It also has its own passphrase caching mechanism,
275 which is controlled by the variable @code{pgg-read-passphrase} (see
276 below).
277
278 There is a security risk in handling passphrases through PGG rather
279 than @code{gpg-agent}.  When you enter your passphrase into an Emacs
280 prompt, it is temporarily stored as a cleartext string in the memory
281 of the Emacs executable.  If the executable memory is swapped to disk,
282 the root user can, in theory, extract the passphrase from the
283 swapfile.  Furthermore, the swapfile containing the cleartext
284 passphrase might remain on the disk after the system is discarded or
285 stolen.  @code{gpg-agent} avoids this problem by using certain tricks,
286 such as memory locking, which have not been implemented in Emacs.
287
288 @defvar pgg-cache-passphrase
289 If non-@code{nil}, store passphrases.  The default value of this
290 variable is @code{t}.  If you are worried about security issues,
291 however, you could stop the caching of passphrases by setting this
292 variable to @code{nil}.
293 @end defvar
294
295 @defvar pgg-passphrase-cache-expiry
296 Elapsed time for expiration in seconds.
297 @end defvar
298
299 @node Default user identity
300 @section Default user identity
301
302 The PGP implementation is usually able to select the proper key to use
303 for signing and decryption, but if you have more than one key, you may
304 need to specify the key id to use.
305
306 @defvar pgg-default-user-id
307 User ID of your default identity.  It defaults to the value returned
308 by @samp{(user-login-name)}.  You can customize this variable.
309 @end defvar
310
311 @defvar pgg-gpg-user-id
312 User ID of the GnuPG default identity.  It defaults to @samp{nil}.
313 This overrides @samp{pgg-default-user-id}.  You can customize this
314 variable.
315 @end defvar
316
317 @defvar pgg-pgp-user-id
318 User ID of the PGP 2.x/6.x default identity.  It defaults to
319 @samp{nil}.  This overrides @samp{pgg-default-user-id}.  You can
320 customize this variable.
321 @end defvar
322
323 @defvar pgg-pgp5-user-id
324 User ID of the PGP 5.x default identity.  It defaults to @samp{nil}.
325 This overrides @samp{pgg-default-user-id}.  You can customize this
326 variable.
327 @end defvar
328
329 @node Architecture
330 @chapter Architecture
331
332 PGG introduces the notion of a "scheme of PGP implementation" (used
333 interchangeably with "scheme" in this document).  This term refers to a
334 singleton object wrapped with the luna object system.
335
336 Since PGG was designed for accessing and developing PGP functionality,
337 the architecture had to be designed not just for interoperability but
338 also for extensiblity.  In this chapter we explore the architecture
339 while finding out how to write the PGG back end.
340
341 @menu
342 * Initializing::                
343 * Back end methods::             
344 * Getting output::              
345 @end menu
346
347 @node Initializing
348 @section Initializing
349
350 A scheme must be initialized before it is used.
351 It had better guarantee to keep only one instance of a scheme.
352
353 The following code is snipped out of @file{pgg-gpg.el}.  Once an
354 instance of @code{pgg-gpg} scheme is initialized, it's stored to the
355 variable @code{pgg-scheme-gpg-instance} and will be reused from now on.
356
357 @lisp
358 (defvar pgg-scheme-gpg-instance nil)
359
360 (defun pgg-make-scheme-gpg ()
361   (or pgg-scheme-gpg-instance
362       (setq pgg-scheme-gpg-instance
363             (luna-make-entity 'pgg-scheme-gpg))))
364 @end lisp
365
366 The name of the function must follow the
367 regulation---@code{pgg-make-scheme-} follows the back end name.
368
369 @node Back end methods
370 @section Back end methods
371
372 In each back end, these methods must be present.  The output of these
373 methods is stored in special buffers (@ref{Getting output}), so that
374 these methods must tell the status of the execution.
375
376 @deffn Method pgg-scheme-lookup-key scheme string &optional type
377 Return keys associated with @var{string}.  If the optional third
378 argument @var{type} is non-@code{nil}, it searches from the secret
379 keyrings.
380 @end deffn
381
382 @deffn Method pgg-scheme-encrypt-region scheme start end recipients &optional sign passphrase
383 Encrypt the current region between @var{start} and @var{end} for
384 @var{recipients}.  If @var{sign} is non-@code{nil}, do a combined sign
385 and encrypt.  If encryption is successful, it returns @code{t},
386 otherwise @code{nil}.
387 @end deffn
388
389 @deffn Method pgg-scheme-encrypt-symmetric-region scheme start end &optional passphrase
390 Encrypt the current region between @var{start} and @var{end} using a
391 symmetric cipher and a passphrases.  If encryption is successful, it
392 returns @code{t}, otherwise @code{nil}.  This function is currently only
393 implemented for GnuPG.
394 @end deffn
395
396 @deffn Method pgg-scheme-decrypt-region scheme start end &optional passphrase
397 Decrypt the current region between @var{start} and @var{end}.  If
398 decryption is successful, it returns @code{t}, otherwise @code{nil}.
399 @end deffn
400
401 @deffn Method pgg-scheme-sign-region scheme start end &optional cleartext passphrase
402 Make the signature from text between @var{start} and @var{end}.  If the
403 optional third argument @var{cleartext} is non-@code{nil}, it does not
404 create a detached signature.  If signing is successful, it returns
405 @code{t}, otherwise @code{nil}.
406 @end deffn
407
408 @deffn Method pgg-scheme-verify-region scheme start end &optional signature
409 Verify the current region between @var{start} and @var{end}.  If the
410 optional third argument @var{signature} is non-@code{nil}, it is treated
411 as the detached signature of the current region.  If the signature is
412 successfully verified, it returns @code{t}, otherwise @code{nil}.
413 @end deffn
414
415 @deffn Method pgg-scheme-insert-key scheme
416 Retrieve the user's public key and insert it as ASCII-armored format.
417 On success, it returns @code{t}, otherwise @code{nil}.
418 @end deffn
419
420 @deffn Method pgg-scheme-snarf-keys-region scheme start end
421 Collect public keys in the current region between @var{start} and
422 @var{end}, and add them into the user's keyring.
423 On success, it returns @code{t}, otherwise @code{nil}.
424 @end deffn
425
426 @node Getting output
427 @section Getting output
428
429 The output of the back end methods (@ref{Back end methods}) is stored in
430 special buffers, so that these methods must tell the status of the
431 execution.
432
433 @defvar pgg-errors-buffer
434 The standard error output of the execution of the PGP command is stored
435 here.
436 @end defvar
437
438 @defvar pgg-output-buffer
439 The standard output of the execution of the PGP command is stored here.
440 @end defvar
441
442 @defvar pgg-status-buffer
443 The rest of status information of the execution of the PGP command is
444 stored here.
445 @end defvar
446
447 @node Parsing OpenPGP packets
448 @chapter Parsing OpenPGP packets
449
450 The format of OpenPGP messages is maintained in order to publish all
451 necessary information needed to develop interoperable applications.
452 The standard is documented in RFC 2440.
453
454 PGG has its own parser for the OpenPGP packets.
455
456 @defun pgg-parse-armor string
457 List the sequence of packets in @var{string}.
458 @end defun
459
460 @defun pgg-parse-armor-region start end
461 List the sequence of packets in the current region between @var{start}
462 and @var{end}.
463 @end defun
464
465 @defvar pgg-ignore-packet-checksum
466 If non-@code{nil}, don't check the checksum of the packets.
467 @end defvar
468
469 @node Function Index
470 @chapter Function Index
471 @printindex fn
472
473 @node Variable Index
474 @chapter Variable Index
475 @printindex vr
476
477 @summarycontents
478 @contents
479 @bye
480
481 @c End:
482
483 @ignore
484    arch-tag: 0c205838-34b9-41a5-b9d7-49ae57ccac85
485 @end ignore