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