pgg.texi 18 KB

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