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