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