\input texinfo @c -*-texinfo-*-@setfilename ../../info/pgg@set VERSION 0.1@copyingThis file describes PGG, an Emacs interface to various PGP implementations.Copyright @copyright{} 2001, 2003, 2004, 2005, 2006, 2007, 2008Free Software Foundation, Inc.@quotationPermission is granted to copy, distribute and/or modify this documentunder the terms of the GNU Free Documentation License, Version 1.2 orany later version published by the Free Software Foundation; with noInvariant Sections, with the Front-Cover texts being ``A GNU Manual,''and with the Back-Cover Texts as in (a) below. A copy of the licenseis included in the section entitled ``GNU Free Documentation License.''(a) The FSF's Back-Cover Text is: ``You have the freedom to copy andmodify this GNU manual. Buying copies from the FSF supports it indeveloping GNU and promoting software freedom.''@end quotation@end copying@dircategory Emacs@direntry* PGG: (pgg). Emacs interface to various PGP implementations.@end direntry@settitle PGG @value{VERSION}@titlepage@title PGG@author by Daiki Ueno@page@vskip 0pt plus 1filll@insertcopying@end titlepage@page@node Top@top PGGThis manual describes PGG. PGG is an interface library between Emacsand various tools for secure communication. PGG also provides a simpleuser interface to encrypt, decrypt, sign, and verify MIME messages.@menu* Overview:: What PGG is.* Prerequisites:: Complicated stuff you may have to do.* How to use:: Getting started quickly.* Architecture:: * Parsing OpenPGP packets:: * GNU Free Documentation License:: The license for this documentation.* Function Index:: * Variable Index:: @end menu@node Overview@chapter OverviewPGG is an interface library between Emacs and various tools for securecommunication. Even though Mailcrypt has similar feature, it does notdeal with detached PGP messages, normally used in PGP/MIMEinfrastructure. This was the main reason why I wrote the new library.PGP/MIME is an application of MIME Object Security Services (RFC1848).The standard is documented in RFC2015.@node Prerequisites@chapter PrerequisitesPGG requires at least one implementation of privacy guard system.This document assumes that you have already obtained and installed themand that you are familiar with its basic functions.By default, PGG uses GnuPG. If you are new to such a system, Irecommend that you should look over the GNU Privacy Handbook (GPH)which is available at @uref{http://www.gnupg.org/documentation/}.When using GnuPG, we recommend the use of the @code{gpg-agent}program, which is distributed with versions 2.0 and later of GnuPG.This is a daemon to manage private keys independently from anyprotocol, and provides the most secure way to input and cache yourpassphrases (@pxref{Caching passphrase}). By default, PGG willattempt to use @code{gpg-agent} if it is running. @xref{InvokingGPG-AGENT,,,gnupg,Using the GNU Privacy Guard}.PGG also supports Pretty Good Privacy version 2 or version 5.@node How to use@chapter How to useThe toplevel interface of this library is quite simple, and onlyintended to use with public-key cryptographic operation.To use PGG, evaluate following expression at the beginning of yourapplication program.@lisp(require 'pgg)@end lispIf you want to check existence of pgg.el at runtime, instead you canlist autoload setting for desired functions as follows.@lisp(autoload 'pgg-encrypt-region "pgg" "Encrypt the current region." t)(autoload 'pgg-encrypt-symmetric-region "pgg" "Encrypt the current region with symmetric algorithm." t)(autoload 'pgg-decrypt-region "pgg" "Decrypt the current region." t)(autoload 'pgg-sign-region "pgg" "Sign the current region." t)(autoload 'pgg-verify-region "pgg" "Verify the current region." t)(autoload 'pgg-insert-key "pgg" "Insert the ASCII armored public key." t)(autoload 'pgg-snarf-keys-region "pgg" "Import public keys in the current region." t)@end lisp@menu* User Commands:: * Selecting an implementation:: * Caching passphrase:: * Default user identity:: @end menu@node User Commands@section User CommandsAt this time you can use some cryptographic commands. The behavior ofthese commands relies on a fashion of invocation because they are alsointended to be used as library functions. In case you don't have thesigner's public key, for example, the function @code{pgg-verify-region}fails immediately, but if the function had been called interactively, itwould ask you to retrieve the signer's public key from the server.@deffn Command pgg-encrypt-region start end recipients &optional sign passphraseEncrypt the current region between @var{start} and @var{end} for@var{recipients}. When the function were called interactively, youwould be asked about the recipients.If encryption is successful, it replaces the current region contents (inthe accessible portion) with the resulting data.If optional argument @var{sign} is non-@code{nil}, the function isrequest to do a combined sign and encrypt. This currently isconfirmed to work with GnuPG, but might not work with PGP or PGP5.If optional @var{passphrase} is @code{nil}, the passphrase will beobtained from the passphrase cache or user.@end deffn@deffn Command pgg-encrypt-symmetric-region &optional start end passphraseEncrypt the current region between @var{start} and @var{end} using asymmetric cipher. After invocation you are asked for a passphrase.If optional @var{passphrase} is @code{nil}, the passphrase will beobtained from the passphrase cache or user.symmetric-cipher encryption is currently only implemented for GnuPG.@end deffn@deffn Command pgg-decrypt-region start end &optional passphraseDecrypt the current region between @var{start} and @var{end}. Ifdecryption is successful, it replaces the current region contents (inthe accessible portion) with the resulting data.If optional @var{passphrase} is @code{nil}, the passphrase will beobtained from the passphrase cache or user.@end deffn@deffn Command pgg-sign-region start end &optional cleartext passphraseMake the signature from text between @var{start} and @var{end}. If theoptional third argument @var{cleartext} is non-@code{nil}, or thefunction is called interactively, it does not create a detachedsignature. In such a case, it replaces the current region contents (inthe accessible portion) with the resulting data.If optional @var{passphrase} is @code{nil}, the passphrase will beobtained from the passphrase cache or user.@end deffn@deffn Command pgg-verify-region start end &optional signature fetchVerify the current region between @var{start} and @var{end}. If theoptional third argument @var{signature} is non-@code{nil}, it is treatedas the detached signature file of the current region.If the optional 4th argument @var{fetch} is non-@code{nil}, or thefunction is called interactively, we attempt to fetch the signer'spublic key from the key server.@end deffn@deffn Command pgg-insert-keyRetrieve the user's public key and insert it as ASCII-armored format.@end deffn@deffn Command pgg-snarf-keys-region start endCollect public keys in the current region between @var{start} and@var{end}, and add them into the user's keyring.@end deffn@node Selecting an implementation@section Selecting an implementationSince PGP has a long history and there are a number of PGPimplementations available today, the function which each one has differsconsiderably. For example, if you are using GnuPG, you know you canselect cipher algorithm from 3DES, CAST5, BLOWFISH, and so on, but onthe other hand the version 2 of PGP only supports IDEA.Which implementation is used is controlled by the @code{pgg-scheme}variable. If it is @code{nil} (the default), the value of the@code{pgg-default-scheme} variable will be used instead.@defvar pgg-schemeForce specify the scheme of PGP implementation. The value can be set to@code{gpg}, @code{pgp}, and @code{pgp5}. The default is @code{nil}.@end defvar@defvar pgg-default-schemeThe default scheme of PGP implementation. The value should be one of@code{gpg}, @code{pgp}, and @code{pgp5}. The default is @code{gpg}.@end defvar@node Caching passphrase@section Caching passphraseWhen using GnuPG (gpg) as the PGP scheme, we recommend using a programcalled @code{gpg-agent} for entering and cachingpassphrases@footnote{Actually, @code{gpg-agent} does not cachepassphrases but private keys. On the other hand, from a user's pointof view, this technical difference isn't visible.}.@defvar pgg-gpg-use-agentIf non-@code{nil}, attempt to use @code{gpg-agent} whenever possible.The default is @code{t}. If @code{gpg-agent} is not running, or GnuPGis not the current PGP scheme, PGG's own passphrase-caching mechanismis used (see below).@end defvarTo use @code{gpg-agent} with PGG, you must first ensure that@code{gpg-agent} is running. For example, if you are running in the XWindow System, you can do this by putting the following line in your@file{.xsession} file:@smallexampleeval "$(gpg-agent --daemon)"@end smallexampleFor more details on invoking @code{gpg-agent}, @xref{InvokingGPG-AGENT,,,gnupg,Using the GNU Privacy Guard}.Whenever you perform a PGG operation that requires a GnuPG passphrase,GnuPG will contact @code{gpg-agent}, which prompts you for thepassphrase. Furthermore, @code{gpg-agent} ``caches'' the result, sothat subsequent uses will not require you to enter the passphraseagain. (This cache usually expires after a certain time has passed;you can change this using the @code{--default-cache-ttl} option wheninvoking @code{gpg-agent}.)If you are running in a X Window System environment, @code{gpg-agent}prompts for a passphrase by opening a graphical window. However, ifyou are running Emacs on a text terminal, @code{gpg-agent} has troublereceiving input from the terminal, since it is being sent to Emacs.One workaround for this problem is to run @code{gpg-agent} on adifferent terminal from Emacs, with the @code{--keep-tty} option; thistells @code{gpg-agent} use its own terminal to prompt for passphrases.When @code{gpg-agent} is not being used, PGG prompts for a passphrasethrough Emacs. It also has its own passphrase caching mechanism,which is controlled by the variable @code{pgg-cache-passphrase} (seebelow).There is a security risk in handling passphrases through PGG ratherthan @code{gpg-agent}. When you enter your passphrase into an Emacsprompt, it is temporarily stored as a cleartext string in the memoryof the Emacs executable. If the executable memory is swapped to disk,the root user can, in theory, extract the passphrase from theswapfile. Furthermore, the swapfile containing the cleartextpassphrase might remain on the disk after the system is discarded orstolen. @code{gpg-agent} avoids this problem by using certain tricks,such as memory locking, which have not been implemented in Emacs.@defvar pgg-cache-passphraseIf non-@code{nil}, store passphrases. The default value of thisvariable is @code{t}. If you are worried about security issues,however, you could stop the caching of passphrases by setting thisvariable to @code{nil}.@end defvar@defvar pgg-passphrase-cache-expiryElapsed time for expiration in seconds.@end defvarIf your passphrase contains non-ASCII characters, you might need tospecify the coding system to be used to encode your passphrases, sinceGnuPG treats them as a byte sequence, not as a character sequence.@defvar pgg-passphrase-coding-systemCoding system used to encode passphrase.@end defvar@node Default user identity@section Default user identityThe PGP implementation is usually able to select the proper key to usefor signing and decryption, but if you have more than one key, you mayneed to specify the key id to use.@defvar pgg-default-user-idUser ID of your default identity. It defaults to the value returnedby @samp{(user-login-name)}. You can customize this variable.@end defvar@defvar pgg-gpg-user-idUser ID of the GnuPG default identity. It defaults to @samp{nil}.This overrides @samp{pgg-default-user-id}. You can customize thisvariable.@end defvar@defvar pgg-pgp-user-idUser ID of the PGP 2.x/6.x default identity. It defaults to@samp{nil}. This overrides @samp{pgg-default-user-id}. You cancustomize this variable.@end defvar@defvar pgg-pgp5-user-idUser ID of the PGP 5.x default identity. It defaults to @samp{nil}.This overrides @samp{pgg-default-user-id}. You can customize thisvariable.@end defvar@node Architecture@chapter ArchitecturePGG introduces the notion of a "scheme of PGP implementation" (usedinterchangeably with "scheme" in this document). This term refers to asingleton object wrapped with the luna object system.Since PGG was designed for accessing and developing PGP functionality,the architecture had to be designed not just for interoperability butalso for extensiblity. In this chapter we explore the architecturewhile finding out how to write the PGG back end.@menu* Initializing:: * Back end methods:: * Getting output:: @end menu@node Initializing@section InitializingA scheme must be initialized before it is used.It had better guarantee to keep only one instance of a scheme.The following code is snipped out of @file{pgg-gpg.el}. Once aninstance of @code{pgg-gpg} scheme is initialized, it's stored to thevariable @code{pgg-scheme-gpg-instance} and will be reused from now on.@lisp(defvar pgg-scheme-gpg-instance nil)(defun pgg-make-scheme-gpg () (or pgg-scheme-gpg-instance (setq pgg-scheme-gpg-instance (luna-make-entity 'pgg-scheme-gpg))))@end lispThe name of the function must follow theregulation---@code{pgg-make-scheme-} follows the back end name.@node Back end methods@section Back end methodsIn each back end, these methods must be present. The output of thesemethods is stored in special buffers (@ref{Getting output}), so thatthese methods must tell the status of the execution.@deffn Method pgg-scheme-lookup-key scheme string &optional typeReturn keys associated with @var{string}. If the optional thirdargument @var{type} is non-@code{nil}, it searches from the secretkeyrings.@end deffn@deffn Method pgg-scheme-encrypt-region scheme start end recipients &optional sign passphraseEncrypt the current region between @var{start} and @var{end} for@var{recipients}. If @var{sign} is non-@code{nil}, do a combined signand encrypt. If encryption is successful, it returns @code{t},otherwise @code{nil}.@end deffn@deffn Method pgg-scheme-encrypt-symmetric-region scheme start end &optional passphraseEncrypt the current region between @var{start} and @var{end} using asymmetric cipher and a passphrases. If encryption is successful, itreturns @code{t}, otherwise @code{nil}. This function is currently onlyimplemented for GnuPG.@end deffn@deffn Method pgg-scheme-decrypt-region scheme start end &optional passphraseDecrypt the current region between @var{start} and @var{end}. Ifdecryption is successful, it returns @code{t}, otherwise @code{nil}.@end deffn@deffn Method pgg-scheme-sign-region scheme start end &optional cleartext passphraseMake the signature from text between @var{start} and @var{end}. If theoptional third argument @var{cleartext} is non-@code{nil}, it does notcreate a detached signature. If signing is successful, it returns@code{t}, otherwise @code{nil}.@end deffn@deffn Method pgg-scheme-verify-region scheme start end &optional signatureVerify the current region between @var{start} and @var{end}. If theoptional third argument @var{signature} is non-@code{nil}, it is treatedas the detached signature of the current region. If the signature issuccessfully verified, it returns @code{t}, otherwise @code{nil}.@end deffn@deffn Method pgg-scheme-insert-key schemeRetrieve the user's public key and insert it as ASCII-armored format.On success, it returns @code{t}, otherwise @code{nil}.@end deffn@deffn Method pgg-scheme-snarf-keys-region scheme start endCollect public keys in the current region between @var{start} and@var{end}, and add them into the user's keyring.On success, it returns @code{t}, otherwise @code{nil}.@end deffn@node Getting output@section Getting outputThe output of the back end methods (@ref{Back end methods}) is stored inspecial buffers, so that these methods must tell the status of theexecution.@defvar pgg-errors-bufferThe standard error output of the execution of the PGP command is storedhere.@end defvar@defvar pgg-output-bufferThe standard output of the execution of the PGP command is stored here.@end defvar@defvar pgg-status-bufferThe rest of status information of the execution of the PGP command isstored here.@end defvar@node Parsing OpenPGP packets@chapter Parsing OpenPGP packetsThe format of OpenPGP messages is maintained in order to publish allnecessary information needed to develop interoperable applications.The standard is documented in RFC 2440.PGG has its own parser for the OpenPGP packets.@defun pgg-parse-armor stringList the sequence of packets in @var{string}.@end defun@defun pgg-parse-armor-region start endList the sequence of packets in the current region between @var{start}and @var{end}.@end defun@defvar pgg-ignore-packet-checksumIf non-@code{nil}, don't check the checksum of the packets.@end defvar@node GNU Free Documentation License@appendix GNU Free Documentation License@include doclicense.texi@node Function Index@unnumbered Function Index@printindex fn@node Variable Index@unnumbered Variable Index@printindex vr@summarycontents@contents@bye@c End:@ignore arch-tag: 0c205838-34b9-41a5-b9d7-49ae57ccac85@end ignore