1 \input texinfo @c -*-texinfo-*-
8 * PGG: (pgg). Emacs interface to various PGP implementations.
11 @settitle PGG @value{VERSION}
14 This file describes the PGG.
16 Copyright (C) 2003, 2004 Free Software Foundation, Inc.
17 Copyright (C) 2001 Daiki Ueno.
19 Permission is granted to copy, distribute and/or modify this document
20 under the terms of the GNU Free Documentation License, Version 1.1 or
21 any later version published by the Free Software Foundation; with no
22 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
23 Texts. A copy of the license is included in the section entitled "GNU
24 Free Documentation License".
35 @vskip 0pt plus 1filll
36 Copyright @copyright{} 2001 Daiki Ueno.
38 Permission is granted to copy, distribute and/or modify this document
39 under the terms of the GNU Free Documentation License, Version 1.1 or
40 any later version published by the Free Software Foundation; with no
41 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
42 Texts. A copy of the license is included in the section entitled "GNU
43 Free Documentation License".
51 This manual describes PGG. PGG is an interface library between Emacs
52 and various tools for secure communication. PGG also provides a simple
53 user interface to encrypt, decrypt, sign, and verify MIME messages.
56 * Overview:: What PGG is.
57 * Prerequisites:: Complicated stuff you may have to do.
58 * How to use:: Getting started quickly.
60 * Parsing OpenPGP packets::
68 PGG is an interface library between Emacs and various tools for secure
69 communication. Even though Mailcrypt has similar feature, it does not
70 deal with detached PGP messages, normally used in PGP/MIME
71 infrastructure. This was the main reason why I wrote the new library.
73 PGP/MIME is an application of MIME Object Security Services (RFC1848).
74 The standard is documented in RFC2015.
77 @chapter Prerequisites
79 PGG requires at least one implementation of privacy guard system.
80 This document assumes that you have already obtained and installed them
81 and that you are familiar with its basic functions.
83 By default, PGG uses GnuPG, but Pretty Good Privacy version 2 or version
84 5 are also supported. If you are new to such a system, I recommend that
85 you should look over the GNU Privacy Handbook (GPH) which is available
86 at @uref{http://www.gnupg.org/gph/}.
91 The toplevel interface of this library is quite simple, and only
92 intended to use with public-key cryptographic operation.
94 To use PGG, evaluate following expression at the beginning of your
101 If you want to check existence of pgg.el at runtime, instead you can
102 list autoload setting for desired functions as follows.
105 (autoload 'pgg-encrypt-region "pgg"
106 "Encrypt the current region." t)
107 (autoload 'pgg-decrypt-region "pgg"
108 "Decrypt the current region." t)
109 (autoload 'pgg-sign-region "pgg"
110 "Sign the current region." t)
111 (autoload 'pgg-verify-region "pgg"
112 "Verify the current region." t)
113 (autoload 'pgg-insert-key "pgg"
114 "Insert the ASCII armored public key." t)
115 (autoload 'pgg-snarf-keys-region "pgg"
116 "Import public keys in the current region." t)
121 * Selecting an implementation::
122 * Caching passphrase::
123 * Default user identity::
127 @section User Commands
129 At this time you can use some cryptographic commands. The behavior of
130 these commands relies on a fashion of invocation because they are also
131 intended to be used as library functions. In case you don't have the
132 signer's public key, for example, the function @code{pgg-verify-region}
133 fails immediately, but if the function had been called interactively, it
134 would ask you to retrieve the signer's public key from the server.
136 @deffn Command pgg-encrypt-region start end recipients &optional sign
137 Encrypt the current region between @var{start} and @var{end} for
138 @var{recipients}. When the function were called interactively, you
139 would be asked about the recipients.
141 If encryption is successful, it replaces the current region contents (in
142 the accessible portion) with the resulting data.
144 If optional argument @var{sign} is non-nil, the function is request to
145 do a combined sign and encrypt. This currently only work with GnuPG.
148 @deffn Command pgg-decrypt-region start end
149 Decrypt the current region between @var{start} and @var{end}. If
150 decryption is successful, it replaces the current region contents (in
151 the accessible portion) with the resulting data.
154 @deffn Command pgg-sign-region start end &optional cleartext
155 Make the signature from text between @var{start} and @var{end}. If the
156 optional third argument @var{cleartext} is non-@code{nil}, or the
157 function is called interactively, it does not create a detached
158 signature. In such a case, it replaces the current region contents (in
159 the accessible portion) with the resulting data.
162 @deffn Command pgg-verify-region start end &optional signature fetch
163 Verify the current region between @var{start} and @var{end}. If the
164 optional third argument @var{signature} is non-@code{nil}, or the function
165 is called interactively, it is treated as the detached signature of the
168 If the optional 4th argument @var{fetch} is non-@code{nil}, or the
169 function is called interactively, we attempt to fetch the signer's
170 public key from the key server.
173 @deffn Command pgg-insert-key
174 Retrieve the user's public key and insert it as ASCII-armored format.
177 @deffn Command pgg-snarf-keys-region start end
178 Collect public keys in the current region between @var{start} and
179 @var{end}, and add them into the user's keyring.
182 @node Selecting an implementation
183 @section Selecting an implementation
185 Since PGP has a long history and there are a number of PGP
186 implementations available today, the function which each one has differs
187 considerably. For example, if you are using GnuPG, you know you can
188 select cipher algorithm from 3DES, CAST5, BLOWFISH, and so on, but on
189 the other hand the version 2 of PGP only supports IDEA.
191 By default, if the variable @code{pgg-scheme} is not set, PGG searches the
192 registered scheme for an implementation of the requested service
193 associated with the named algorithm. If there are no match, PGG uses
194 @code{pgg-default-scheme}. In other words, there are two options to
195 control which command is used to process the incoming PGP armors. One
196 is for encrypting and signing, the other is for decrypting and
200 Force specify the scheme of PGP implementation for decrypting and verifying.
201 The value can be @code{gpg}, @code{pgp}, and @code{pgp5}.
204 @defvar pgg-default-scheme
205 Force specify the scheme of PGP implementation for encrypting and signing.
206 The value can be @code{gpg}, @code{pgp}, and @code{pgp5}.
209 @node Caching passphrase
210 @section Caching passphrase
212 PGG uses a simple passphrase caching mechanism, which is enabled by
215 @defvar pgg-cache-passphrase
216 If non-@code{nil}, store passphrases. The default value of this
217 variable is @code{t}. If you were worry about security issue, however,
218 you could stop caching with setting it @code{nil}.
221 @defvar pgg-passphrase-cache-expiry
222 Elapsed time for expiration in seconds.
225 @node Default user identity
226 @section Default user identity
228 The PGP implementation is usually able to select the proper key to use
229 for signing and decryption, but if you have more than one key, you may
230 need to specify the key id to use.
232 @defvar pgg-default-user-id
233 User ID of your default identity. It defaults to the value returned
234 by @samp{(user-login-name)}. You can customize this variable.
237 @defvar pgg-gpg-user-id
238 User ID of the GnuPG default identity. It defaults to @samp{nil}.
239 This overrides @samp{pgg-default-user-id}. You can customize this
243 @defvar pgg-pgp-user-id
244 User ID of the PGP 2.x/6.x default identity. It defaults to
245 @samp{nil}. This overrides @samp{pgg-default-user-id}. You can
246 customize this variable.
249 @defvar pgg-pgp5-user-id
250 User ID of the PGP 5.x default identity. It defaults to @samp{nil}.
251 This overrides @samp{pgg-default-user-id}. You can customize this
256 @chapter Architecture
258 PGG introduces the notion of a "scheme of PGP implementation" (used
259 interchangeably with "scheme" in this document). This term refers to a
260 singleton object wrapped with the luna object system.
262 Since PGG was designed for accessing and developing PGP functionality,
263 the architecture had to be designed not just for interoperability but
264 also for extensiblity. In this chapter we explore the architecture
265 while finding out how to write the PGG backend.
274 @section Initializing
276 A scheme must be initialized before it is used.
277 It had better guarantee to keep only one instance of a scheme.
279 The following code is snipped out of @file{pgg-gpg.el}. Once an
280 instance of @code{pgg-gpg} scheme is initialized, it's stored to the
281 variable @code{pgg-scheme-gpg-instance} and will be reused from now on.
284 (defvar pgg-scheme-gpg-instance nil)
286 (defun pgg-make-scheme-gpg ()
287 (or pgg-scheme-gpg-instance
288 (setq pgg-scheme-gpg-instance
289 (luna-make-entity 'pgg-scheme-gpg))))
292 The name of the function must follow the
293 regulation---@code{pgg-make-scheme-} follows the backend name.
295 @node Backend methods
296 @section Backend methods
298 In each backend, these methods must be present. The output of these
299 methods is stored in special buffers (@ref{Getting output}), so that
300 these methods must tell the status of the execution.
302 @deffn Method pgg-scheme-lookup-key scheme string &optional type
303 Return keys associated with @var{string}. If the optional third
304 argument @var{type} is non-@code{nil}, it searches from the secret
308 @deffn Method pgg-scheme-encrypt-region scheme start end recipients &optional sign
309 Encrypt the current region between @var{start} and @var{end} for
310 @var{recipients}. If @var{sign} is non-nil, do a combined sign and
311 encrypt. If encryption is successful, it returns @code{t}, otherwise
315 @deffn Method pgg-scheme-decrypt-region scheme start end
316 Decrypt the current region between @var{start} and @var{end}. If
317 decryption is successful, it returns @code{t}, otherwise @code{nil}.
320 @deffn Method pgg-scheme-sign-region scheme start end &optional cleartext
321 Make the signature from text between @var{start} and @var{end}. If the
322 optional third argument @var{cleartext} is non-@code{nil}, it does not
323 create a detached signature. If signing is successful, it returns
324 @code{t}, otherwise @code{nil}.
327 @deffn Method pgg-scheme-verify-region scheme start end &optional signature
328 Verify the current region between @var{start} and @var{end}. If the
329 optional third argument @var{signature} is non-@code{nil}, it is treated
330 as the detached signature of the current region. If the signature is
331 successfully verified, it returns @code{t}, otherwise @code{nil}.
334 @deffn Method pgg-scheme-insert-key scheme
335 Retrieve the user's public key and insert it as ASCII-armored format.
336 On success, it returns @code{t}, otherwise @code{nil}.
339 @deffn Method pgg-scheme-snarf-keys-region scheme start end
340 Collect public keys in the current region between @var{start} and
341 @var{end}, and add them into the user's keyring.
342 On success, it returns @code{t}, otherwise @code{nil}.
346 @section Getting output
348 The output of the backend methods (@ref{Backend methods}) is stored in
349 special buffers, so that these methods must tell the status of the
352 @defvar pgg-errors-buffer
353 The standard error output of the execution of the PGP command is stored
357 @defvar pgg-output-buffer
358 The standard output of the execution of the PGP command is stored here.
361 @defvar pgg-status-buffer
362 The rest of status information of the execution of the PGP command is
366 @node Parsing OpenPGP packets
367 @chapter Parsing OpenPGP packets
369 The format of OpenPGP messages is maintained in order to publish all
370 necessary information needed to develop interoperable applications.
371 The standard is documented in RFC 2440.
373 PGG has its own parser for the OpenPGP packets.
375 @defun pgg-parse-armor string
376 List the sequence of packets in @var{string}.
379 @defun pgg-parse-armor-region start end
380 List the sequence of packets in the current region between @var{start}
384 @defvar pgg-ignore-packet-checksum
385 If non-@code{nil}, don't check the checksum of the packets.
389 @chapter Function Index
393 @chapter Variable Index