1 \input texinfo @c -*-texinfo-*-
3 @setfilename ../../info/pgg
9 This file describes PGG, an Emacs interface to various PGP implementations.
11 Copyright @copyright{} 2001, 2003, 2004, 2005, 2006, 2007, 2008
12 Free Software Foundation, Inc.
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.''
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.''
30 * PGG: (pgg). Emacs interface to various PGP implementations.
33 @settitle PGG @value{VERSION}
42 @vskip 0pt plus 1filll
49 This manual describes PGG. PGG is an interface library between Emacs
50 and various tools for secure communication. PGG also provides a simple
51 user interface to encrypt, decrypt, sign, and verify MIME messages.
54 * Overview:: What PGG is.
55 * Prerequisites:: Complicated stuff you may have to do.
56 * How to use:: Getting started quickly.
58 * Parsing OpenPGP packets::
59 * GNU Free Documentation License:: The license for this documentation.
67 PGG is an interface library between Emacs and various tools for secure
68 communication. Even though Mailcrypt has similar feature, it does not
69 deal with detached PGP messages, normally used in PGP/MIME
70 infrastructure. This was the main reason why I wrote the new library.
72 PGP/MIME is an application of MIME Object Security Services (RFC1848).
73 The standard is documented in RFC2015.
76 @chapter Prerequisites
78 PGG requires at least one implementation of privacy guard system.
79 This document assumes that you have already obtained and installed them
80 and that you are familiar with its basic functions.
82 By default, PGG uses GnuPG. If you are new to such a system, I
83 recommend that you should look over the GNU Privacy Handbook (GPH)
84 which is available at @uref{http://www.gnupg.org/documentation/}.
86 When using GnuPG, we recommend the use of the @code{gpg-agent}
87 program, which is distributed with versions 2.0 and later of GnuPG.
88 This is a daemon to manage private keys independently from any
89 protocol, and provides the most secure way to input and cache your
90 passphrases (@pxref{Caching passphrase}). By default, PGG will
91 attempt to use @code{gpg-agent} if it is running. @xref{Invoking
92 GPG-AGENT,,,gnupg,Using the GNU Privacy Guard}.
94 PGG also supports Pretty Good Privacy version 2 or version 5.
99 The toplevel interface of this library is quite simple, and only
100 intended to use with public-key cryptographic operation.
102 To use PGG, evaluate following expression at the beginning of your
109 If you want to check existence of pgg.el at runtime, instead you can
110 list autoload setting for desired functions as follows.
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)
131 * Selecting an implementation::
132 * Caching passphrase::
133 * Default user identity::
137 @section User Commands
139 At this time you can use some cryptographic commands. The behavior of
140 these commands relies on a fashion of invocation because they are also
141 intended to be used as library functions. In case you don't have the
142 signer's public key, for example, the function @code{pgg-verify-region}
143 fails immediately, but if the function had been called interactively, it
144 would ask you to retrieve the signer's public key from the server.
146 @deffn Command pgg-encrypt-region start end recipients &optional sign passphrase
147 Encrypt the current region between @var{start} and @var{end} for
148 @var{recipients}. When the function were called interactively, you
149 would be asked about the recipients.
151 If encryption is successful, it replaces the current region contents (in
152 the accessible portion) with the resulting data.
154 If optional argument @var{sign} is non-@code{nil}, the function is
155 request to do a combined sign and encrypt. This currently is
156 confirmed to work with GnuPG, but might not work with PGP or PGP5.
158 If optional @var{passphrase} is @code{nil}, the passphrase will be
159 obtained from the passphrase cache or user.
162 @deffn Command pgg-encrypt-symmetric-region &optional start end passphrase
163 Encrypt the current region between @var{start} and @var{end} using a
164 symmetric cipher. After invocation you are asked for a passphrase.
166 If optional @var{passphrase} is @code{nil}, the passphrase will be
167 obtained from the passphrase cache or user.
169 symmetric-cipher encryption is currently only implemented for GnuPG.
172 @deffn Command pgg-decrypt-region start end &optional passphrase
173 Decrypt the current region between @var{start} and @var{end}. If
174 decryption is successful, it replaces the current region contents (in
175 the accessible portion) with the resulting data.
177 If optional @var{passphrase} is @code{nil}, the passphrase will be
178 obtained from the passphrase cache or user.
181 @deffn Command pgg-sign-region start end &optional cleartext passphrase
182 Make the signature from text between @var{start} and @var{end}. If the
183 optional third argument @var{cleartext} is non-@code{nil}, or the
184 function is called interactively, it does not create a detached
185 signature. In such a case, it replaces the current region contents (in
186 the accessible portion) with the resulting data.
188 If optional @var{passphrase} is @code{nil}, the passphrase will be
189 obtained from the passphrase cache or user.
192 @deffn Command pgg-verify-region start end &optional signature fetch
193 Verify the current region between @var{start} and @var{end}. If the
194 optional third argument @var{signature} is non-@code{nil}, it is treated
195 as the detached signature file of the current region.
197 If the optional 4th argument @var{fetch} is non-@code{nil}, or the
198 function is called interactively, we attempt to fetch the signer's
199 public key from the key server.
202 @deffn Command pgg-insert-key
203 Retrieve the user's public key and insert it as ASCII-armored format.
206 @deffn Command pgg-snarf-keys-region start end
207 Collect public keys in the current region between @var{start} and
208 @var{end}, and add them into the user's keyring.
211 @node Selecting an implementation
212 @section Selecting an implementation
214 Since PGP has a long history and there are a number of PGP
215 implementations available today, the function which each one has differs
216 considerably. For example, if you are using GnuPG, you know you can
217 select cipher algorithm from 3DES, CAST5, BLOWFISH, and so on, but on
218 the other hand the version 2 of PGP only supports IDEA.
220 Which implementation is used is controlled by the @code{pgg-scheme}
221 variable. If it is @code{nil} (the default), the value of the
222 @code{pgg-default-scheme} variable will be used instead.
225 Force 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}.
229 @defvar pgg-default-scheme
230 The default scheme of PGP implementation. The value should be one of
231 @code{gpg}, @code{pgp}, and @code{pgp5}. The default is @code{gpg}.
234 @node Caching passphrase
235 @section Caching passphrase
237 When using GnuPG (gpg) as the PGP scheme, we recommend using a program
238 called @code{gpg-agent} for entering and caching
239 passphrases@footnote{Actually, @code{gpg-agent} does not cache
240 passphrases but private keys. On the other hand, from a user's point
241 of view, this technical difference isn't visible.}.
243 @defvar pgg-gpg-use-agent
244 If non-@code{nil}, attempt to use @code{gpg-agent} whenever possible.
245 The default is @code{t}. If @code{gpg-agent} is not running, or GnuPG
246 is not the current PGP scheme, PGG's own passphrase-caching mechanism
250 To 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
252 Window System, you can do this by putting the following line in your
253 @file{.xsession} file:
256 eval "$(gpg-agent --daemon)"
259 For more details on invoking @code{gpg-agent}, @xref{Invoking
260 GPG-AGENT,,,gnupg,Using the GNU Privacy Guard}.
262 Whenever you perform a PGG operation that requires a GnuPG passphrase,
263 GnuPG will contact @code{gpg-agent}, which prompts you for the
264 passphrase. Furthermore, @code{gpg-agent} ``caches'' the result, so
265 that subsequent uses will not require you to enter the passphrase
266 again. (This cache usually expires after a certain time has passed;
267 you can change this using the @code{--default-cache-ttl} option when
268 invoking @code{gpg-agent}.)
270 If you are running in a X Window System environment, @code{gpg-agent}
271 prompts for a passphrase by opening a graphical window. However, if
272 you are running Emacs on a text terminal, @code{gpg-agent} has trouble
273 receiving input from the terminal, since it is being sent to Emacs.
274 One workaround for this problem is to run @code{gpg-agent} on a
275 different terminal from Emacs, with the @code{--keep-tty} option; this
276 tells @code{gpg-agent} use its own terminal to prompt for passphrases.
278 When @code{gpg-agent} is not being used, PGG prompts for a passphrase
279 through Emacs. It also has its own passphrase caching mechanism,
280 which is controlled by the variable @code{pgg-cache-passphrase} (see
283 There is a security risk in handling passphrases through PGG rather
284 than @code{gpg-agent}. When you enter your passphrase into an Emacs
285 prompt, it is temporarily stored as a cleartext string in the memory
286 of the Emacs executable. If the executable memory is swapped to disk,
287 the root user can, in theory, extract the passphrase from the
288 swapfile. Furthermore, the swapfile containing the cleartext
289 passphrase might remain on the disk after the system is discarded or
290 stolen. @code{gpg-agent} avoids this problem by using certain tricks,
291 such as memory locking, which have not been implemented in Emacs.
293 @defvar pgg-cache-passphrase
294 If non-@code{nil}, store passphrases. The default value of this
295 variable is @code{t}. If you are worried about security issues,
296 however, you could stop the caching of passphrases by setting this
297 variable to @code{nil}.
300 @defvar pgg-passphrase-cache-expiry
301 Elapsed time for expiration in seconds.
304 If your passphrase contains non-ASCII characters, you might need to
305 specify the coding system to be used to encode your passphrases, since
306 GnuPG treats them as a byte sequence, not as a character sequence.
308 @defvar pgg-passphrase-coding-system
309 Coding system used to encode passphrase.
312 @node Default user identity
313 @section Default user identity
315 The PGP implementation is usually able to select the proper key to use
316 for signing and decryption, but if you have more than one key, you may
317 need to specify the key id to use.
319 @defvar pgg-default-user-id
320 User ID of your default identity. It defaults to the value returned
321 by @samp{(user-login-name)}. You can customize this variable.
324 @defvar pgg-gpg-user-id
325 User ID of the GnuPG default identity. It defaults to @samp{nil}.
326 This overrides @samp{pgg-default-user-id}. You can customize this
330 @defvar pgg-pgp-user-id
331 User 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
333 customize this variable.
336 @defvar pgg-pgp5-user-id
337 User ID of the PGP 5.x default identity. It defaults to @samp{nil}.
338 This overrides @samp{pgg-default-user-id}. You can customize this
343 @chapter Architecture
345 PGG introduces the notion of a "scheme of PGP implementation" (used
346 interchangeably with "scheme" in this document). This term refers to a
347 singleton object wrapped with the luna object system.
349 Since PGG was designed for accessing and developing PGP functionality,
350 the architecture had to be designed not just for interoperability but
351 also for extensiblity. In this chapter we explore the architecture
352 while finding out how to write the PGG back end.
361 @section Initializing
363 A scheme must be initialized before it is used.
364 It had better guarantee to keep only one instance of a scheme.
366 The following code is snipped out of @file{pgg-gpg.el}. Once an
367 instance of @code{pgg-gpg} scheme is initialized, it's stored to the
368 variable @code{pgg-scheme-gpg-instance} and will be reused from now on.
371 (defvar pgg-scheme-gpg-instance nil)
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))))
379 The name of the function must follow the
380 regulation---@code{pgg-make-scheme-} follows the back end name.
382 @node Back end methods
383 @section Back end methods
385 In each back end, these methods must be present. The output of these
386 methods is stored in special buffers (@ref{Getting output}), so that
387 these methods must tell the status of the execution.
389 @deffn Method pgg-scheme-lookup-key scheme string &optional type
390 Return keys associated with @var{string}. If the optional third
391 argument @var{type} is non-@code{nil}, it searches from the secret
395 @deffn Method pgg-scheme-encrypt-region scheme start end recipients &optional sign passphrase
396 Encrypt the current region between @var{start} and @var{end} for
397 @var{recipients}. If @var{sign} is non-@code{nil}, do a combined sign
398 and encrypt. If encryption is successful, it returns @code{t},
399 otherwise @code{nil}.
402 @deffn Method pgg-scheme-encrypt-symmetric-region scheme start end &optional passphrase
403 Encrypt the current region between @var{start} and @var{end} using a
404 symmetric cipher and a passphrases. If encryption is successful, it
405 returns @code{t}, otherwise @code{nil}. This function is currently only
406 implemented for GnuPG.
409 @deffn Method pgg-scheme-decrypt-region scheme start end &optional passphrase
410 Decrypt the current region between @var{start} and @var{end}. If
411 decryption is successful, it returns @code{t}, otherwise @code{nil}.
414 @deffn Method pgg-scheme-sign-region scheme start end &optional cleartext passphrase
415 Make the signature from text between @var{start} and @var{end}. If the
416 optional third argument @var{cleartext} is non-@code{nil}, it does not
417 create a detached signature. If signing is successful, it returns
418 @code{t}, otherwise @code{nil}.
421 @deffn Method pgg-scheme-verify-region scheme start end &optional signature
422 Verify the current region between @var{start} and @var{end}. If the
423 optional third argument @var{signature} is non-@code{nil}, it is treated
424 as the detached signature of the current region. If the signature is
425 successfully verified, it returns @code{t}, otherwise @code{nil}.
428 @deffn Method pgg-scheme-insert-key scheme
429 Retrieve the user's public key and insert it as ASCII-armored format.
430 On success, it returns @code{t}, otherwise @code{nil}.
433 @deffn Method pgg-scheme-snarf-keys-region scheme start end
434 Collect public keys in the current region between @var{start} and
435 @var{end}, and add them into the user's keyring.
436 On success, it returns @code{t}, otherwise @code{nil}.
440 @section Getting output
442 The output of the back end methods (@ref{Back end methods}) is stored in
443 special buffers, so that these methods must tell the status of the
446 @defvar pgg-errors-buffer
447 The standard error output of the execution of the PGP command is stored
451 @defvar pgg-output-buffer
452 The standard output of the execution of the PGP command is stored here.
455 @defvar pgg-status-buffer
456 The rest of status information of the execution of the PGP command is
460 @node Parsing OpenPGP packets
461 @chapter Parsing OpenPGP packets
463 The format of OpenPGP messages is maintained in order to publish all
464 necessary information needed to develop interoperable applications.
465 The standard is documented in RFC 2440.
467 PGG has its own parser for the OpenPGP packets.
469 @defun pgg-parse-armor string
470 List the sequence of packets in @var{string}.
473 @defun pgg-parse-armor-region start end
474 List the sequence of packets in the current region between @var{start}
478 @defvar pgg-ignore-packet-checksum
479 If non-@code{nil}, don't check the checksum of the packets.
482 @node GNU Free Documentation License
483 @appendix GNU Free Documentation License
484 @include doclicense.texi
487 @unnumbered Function Index
491 @unnumbered Variable Index
501 arch-tag: 0c205838-34b9-41a5-b9d7-49ae57ccac85