auth 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. This is ../../info/auth, produced by makeinfo version 4.13 from
  2. auth.texi.
  3. This file describes the Emacs auth-source library.
  4. Copyright (C) 2008-2012 Free Software Foundation, Inc.
  5. Permission is granted to copy, distribute and/or modify this
  6. document under the terms of the GNU Free Documentation License,
  7. Version 1.3 or any later version published by the Free Software
  8. Foundation; with no Invariant Sections, with the Front-Cover texts
  9. being "A GNU Manual," and with the Back-Cover Texts as in (a)
  10. below. A copy of the license is included in the section entitled
  11. "GNU Free Documentation License" in the Emacs manual.
  12. (a) The FSF's Back-Cover Text is: "You have the freedom to copy and
  13. modify this GNU manual. Buying copies from the FSF supports it in
  14. developing GNU and promoting software freedom."
  15. This document is part of a collection distributed under the GNU
  16. Free Documentation License. If you want to distribute this
  17. document separately from the collection, you can do so by adding a
  18. copy of the license to the document, as described in section 6 of
  19. the license.
  20. INFO-DIR-SECTION Emacs lisp libraries
  21. START-INFO-DIR-ENTRY
  22. * Auth-source: (auth). The Emacs auth-source library.
  23. END-INFO-DIR-ENTRY
  24. 
  25. File: auth, Node: Top, Next: Overview, Up: (dir)
  26. Emacs auth-source
  27. *****************
  28. This manual describes the Emacs auth-source library.
  29. It is a way for multiple applications to share a single configuration
  30. (in Emacs and in files) for user convenience.
  31. This file describes the Emacs auth-source library.
  32. Copyright (C) 2008-2012 Free Software Foundation, Inc.
  33. Permission is granted to copy, distribute and/or modify this
  34. document under the terms of the GNU Free Documentation License,
  35. Version 1.3 or any later version published by the Free Software
  36. Foundation; with no Invariant Sections, with the Front-Cover texts
  37. being "A GNU Manual," and with the Back-Cover Texts as in (a)
  38. below. A copy of the license is included in the section entitled
  39. "GNU Free Documentation License" in the Emacs manual.
  40. (a) The FSF's Back-Cover Text is: "You have the freedom to copy and
  41. modify this GNU manual. Buying copies from the FSF supports it in
  42. developing GNU and promoting software freedom."
  43. This document is part of a collection distributed under the GNU
  44. Free Documentation License. If you want to distribute this
  45. document separately from the collection, you can do so by adding a
  46. copy of the license to the document, as described in section 6 of
  47. the license.
  48. * Menu:
  49. * Overview:: Overview of the auth-source library.
  50. * Help for users::
  51. * Secret Service API::
  52. * Help for developers::
  53. * GnuPG and EasyPG Assistant Configuration::
  54. * Index::
  55. * Function Index::
  56. * Variable Index::
  57. 
  58. File: auth, Node: Overview, Next: Help for users, Prev: Top, Up: Top
  59. 1 Overview
  60. **********
  61. The auth-source library is simply a way for Emacs and Gnus, among
  62. others, to answer the old burning question "What are my user name and
  63. password?"
  64. (This is different from the old question about burning "Where is the
  65. fire extinguisher, please?".)
  66. The auth-source library supports more than just the user name or the
  67. password (known as the secret).
  68. Similarly, the auth-source library supports multiple storage backend,
  69. currently either the classic "netrc" backend, examples of which you can
  70. see later in this document, or the Secret Service API. This is done
  71. with EIEIO-based backends and you can write your own if you want.
  72. 
  73. File: auth, Node: Help for users, Next: Secret Service API, Prev: Overview, Up: Top
  74. 2 Help for users
  75. ****************
  76. "Netrc" files are a de facto standard. They look like this:
  77. machine MYMACHINE login MYLOGINNAME password MYPASSWORD port MYPORT
  78. The `machine' is the server (either a DNS name or an IP address).
  79. It's known as :HOST in `auth-source-search' queries. You can also use
  80. `host'.
  81. The `port' is the connection port or protocol. It's known as :PORT
  82. in `auth-source-search' queries.
  83. The `user' is the user name. It's known as :USER in
  84. `auth-source-search' queries. You can also use `login' and `account'.
  85. Spaces are always OK as far as auth-source is concerned (but other
  86. programs may not like them). Just put the data in quotes, escaping
  87. quotes as you'd expect with `\'.
  88. All these are optional. You could just say (but we don't recommend
  89. it, we're just showing that it's possible)
  90. password MYPASSWORD
  91. to use the same password everywhere. Again, _DO NOT DO THIS_ or you
  92. will be pwned as the kids say.
  93. "Netrc" files are usually called `.authinfo' or `.netrc'; nowadays
  94. `.authinfo' seems to be more popular and the auth-source library
  95. encourages this confusion by accepting both, as you'll see later.
  96. If you have problems with the search, set `auth-source-debug' to
  97. `'trivia' and see what host, port, and user the library is checking in
  98. the `*Messages*' buffer. Ditto for any other problems, your first step
  99. is always to see what's being checked. The second step, of course, is
  100. to write a blog entry about it and wait for the answer in the comments.
  101. You can customize the variable `auth-sources'. The following may be
  102. needed if you are using an older version of Emacs or if the auth-source
  103. library is not loaded for some other reason.
  104. (require 'auth-source) ;; probably not necessary
  105. (customize-variable 'auth-sources) ;; optional, do it once
  106. -- Variable: auth-sources
  107. The `auth-sources' variable tells the auth-source library where
  108. your netrc files or Secret Service API collection items live for a
  109. particular host and protocol. While you can get fancy, the default
  110. and simplest configuration is:
  111. ;;; old default: required :host and :port, not needed anymore
  112. (setq auth-sources '((:source "~/.authinfo.gpg" :host t :port t)))
  113. ;;; mostly equivalent (see below about fallbacks) but shorter:
  114. (setq auth-sources '((:source "~/.authinfo.gpg")))
  115. ;;; even shorter and the _default_:
  116. (setq auth-sources '("~/.authinfo.gpg" "~/.authinfo" "~/.netrc"))
  117. ;;; use the Secrets API LOGIN collection (*note Secret Service API::)
  118. (setq auth-sources '("secrets:Login"))
  119. By adding multiple entries to `auth-sources' with a particular
  120. host or protocol, you can have specific netrc files for that host
  121. or protocol. Usually this is unnecessary but may make sense if
  122. you have shared netrc files or some other unusual setup (90% of
  123. Emacs users have unusual setups and the remaining 10% are _really_
  124. unusual).
  125. Here's a mixed example using two sources:
  126. (setq auth-sources '((:source (:secrets default) :host "myserver" :user "joe")
  127. "~/.authinfo.gpg"))
  128. If you don't customize `auth-sources', you'll have to live with the
  129. defaults: any host and any port are looked up in the netrc file
  130. `~/.authinfo.gpg', which is a GnuPG encrypted file (*note GnuPG and
  131. EasyPG Assistant Configuration::).
  132. If that fails, the unencrypted netrc files `~/.authinfo' and
  133. `~/.netrc' will be used.
  134. The typical netrc line example is without a port.
  135. machine YOURMACHINE login YOU password YOURPASSWORD
  136. This will match any authentication port. Simple, right? But what if
  137. there's a SMTP server on port 433 of that machine that needs a
  138. different password from the IMAP server?
  139. machine YOURMACHINE login YOU password SMTPPASSWORD port 433
  140. machine YOURMACHINE login YOU password GENERALPASSWORD
  141. For url-auth authentication (HTTP/HTTPS), you need to put this in
  142. your netrc file:
  143. machine yourmachine.com:80 port http login testuser password testpass
  144. This will match any realm and authentication method (basic or digest)
  145. over HTTP. HTTPS is set up similarly. If you want finer controls,
  146. explore the url-auth source code and variables.
  147. For Tramp authentication, use:
  148. machine yourmachine.com port scp login testuser password testpass
  149. Note that the port denotes the Tramp connection method. When you
  150. don't use a port entry, you match any Tramp method, as explained
  151. earlier. Since Tramp has about 88 connection methods, this may be
  152. necessary if you have an unusual (see earlier comment on those) setup.
  153. 
  154. File: auth, Node: Secret Service API, Next: Help for developers, Prev: Help for users, Up: Top
  155. 3 Secret Service API
  156. ********************
  157. The "Secret Service API" is a standard from freedesktop.org to securely
  158. store passwords and other confidential information. This API is
  159. implemented by system daemons such as the GNOME Keyring and the KDE
  160. Wallet (these are GNOME and KDE packages respectively and should be
  161. available on most modern GNU/Linux systems).
  162. The auth-source library uses the `secrets.el' library to connect
  163. through the Secret Service API. You can also use that library in other
  164. packages, it's not exclusive to auth-source.
  165. -- Variable: secrets-enabled
  166. After loading `secrets.el', a non-`nil' value of this variable
  167. indicates the existence of a daemon providing the Secret Service
  168. API.
  169. -- Command: secrets-show-secrets
  170. This command shows all collections, items, and their attributes.
  171. The atomic objects managed by the Secret Service API are "secret
  172. items", which contain things an application wishes to store securely,
  173. like a password. Secret items have a label (a name), the "secret"
  174. (which is the string we want, like a password), and a set of lookup
  175. attributes. The attributes can be used to search and retrieve a secret
  176. item at a later date.
  177. Secret items are grouped in "collections". A collection is
  178. sometimes called a `keyring' or `wallet' in GNOME Keyring and KDE
  179. Wallet but it's the same thing, a group of secrets. Collections are
  180. personal and protected so only the owner can open them.
  181. The most common collection is called `"login"'.
  182. A collection can have an alias. The alias `"default"' is commonly
  183. used so the clients don't have to know the specific name of the
  184. collection they open. Other aliases are not supported yet. Since
  185. aliases are globally accessible, set the `"default"' alias only when
  186. you're sure it's appropriate.
  187. -- Function: secrets-list-collections
  188. This function returns all the collection names as a list.
  189. -- Function: secrets-set-alias collection alias
  190. Set ALIAS as alias of collection labeled COLLECTION. Currently
  191. only the alias `"default"' is supported.
  192. -- Function: secrets-get-alias alias
  193. Return the collection name ALIAS is referencing to. Currently
  194. only the alias `"default"' is supported.
  195. Collections can be created and deleted by the functions
  196. `secrets-create-collection' and `secrets-delete-collection'. Usually,
  197. this is not done from within Emacs. Do not delete standard collections
  198. such as `"login"'.
  199. The special collection `"session"' exists for the lifetime of the
  200. corresponding client session (in our case, Emacs's lifetime). It is
  201. created automatically when Emacs uses the Secret Service interface and
  202. it is deleted when Emacs is killed. Therefore, it can be used to store
  203. and retrieve secret items temporarily. The `"session"' collection is
  204. better than a persistent collection when the secret items should not
  205. live longer than Emacs. The session collection can be specified either
  206. by the string `"session"', or by `nil', whenever a collection parameter
  207. is needed in the following functions.
  208. -- Function: secrets-list-items collection
  209. Returns all the item labels of COLLECTION as a list.
  210. -- Function: secrets-create-item collection item password &rest
  211. attributes
  212. This function creates a new item in COLLECTION with label ITEM and
  213. password PASSWORD. ATTRIBUTES are key-value pairs set for the
  214. created item. The keys are keyword symbols, starting with a
  215. colon. Example:
  216. ;;; The session "session", the label is "my item"
  217. ;;; and the secret (password) is "geheim"
  218. (secrets-create-item "session" "my item" "geheim"
  219. :method "sudo" :user "joe" :host "remote-host")
  220. -- Function: secrets-get-secret collection item
  221. Return the secret of item labeled ITEM in COLLECTION. If there is
  222. no such item, return `nil'.
  223. -- Function: secrets-delete-item collection item
  224. This function deletes item ITEM in COLLECTION.
  225. The lookup attributes, which are specified during creation of a
  226. secret item, must be a key-value pair. Keys are keyword symbols,
  227. starting with a colon; values are strings. They can be retrieved from
  228. a given secret item and they can be used for searching of items.
  229. -- Function: secrets-get-attribute collection item attribute
  230. Returns the value of key ATTRIBUTE of item labeled ITEM in
  231. COLLECTION. If there is no such item, or the item doesn't own
  232. this key, the function returns `nil'.
  233. -- Function: secrets-get-attributes collection item
  234. Return the lookup attributes of item labeled ITEM in COLLECTION.
  235. If there is no such item, or the item has no attributes, it
  236. returns `nil'. Example:
  237. (secrets-get-attributes "session" "my item")
  238. => ((:user . "joe") (:host ."remote-host"))
  239. -- Function: secrets-search-items collection &rest attributes
  240. Search for the items in COLLECTION with matching ATTRIBUTES. The
  241. ATTRIBUTES are key-value pairs, as used in `secrets-create-item'.
  242. Example:
  243. (secrets-search-items "session" :user "joe")
  244. => ("my item" "another item")
  245. The auth-source library uses the `secrets.el' library and thus the
  246. Secret Service API when you specify a source matching
  247. `"secrets:COLLECTION"'. For instance, you could use
  248. `"secrets:session"' to use the `"session"' collection, open only for
  249. the lifetime of Emacs. Or you could use `"secrets:Login"' to open the
  250. `"Login"' collection. As a special case, you can use the symbol
  251. `default' in `auth-sources' (not a string, but a symbol) to specify the
  252. `"default"' alias. Here is a contrived example that sets
  253. `auth-sources' to search three collections and then fall back to
  254. `~/.authinfo.gpg'.
  255. (setq auth-sources '(default
  256. "secrets:session"
  257. "secrets:Login"
  258. "~/.authinfo.gpg"))
  259. 
  260. File: auth, Node: Help for developers, Next: GnuPG and EasyPG Assistant Configuration, Prev: Secret Service API, Up: Top
  261. 4 Help for developers
  262. *********************
  263. The auth-source library lets you control logging output easily.
  264. -- Variable: auth-source-debug
  265. Set this variable to `'trivia' to see lots of output in
  266. `*Messages*', or set it to a function that behaves like `message'
  267. to do your own logging.
  268. The auth-source library only has a few functions for external use.
  269. -- Function: auth-source-search &rest spec &key type max host user
  270. port secret require create delete &allow-other-keys
  271. This function searches (or modifies) authentication backends
  272. according to SPEC. See the function's doc-string for details.
  273. Let's take a look at an example of using `auth-source-search' from
  274. Gnus's `nnimap.el'.
  275. (defun nnimap-credentials (address ports)
  276. (let* ((auth-source-creation-prompts
  277. '((user . "IMAP user at %h: ")
  278. (secret . "IMAP password for %u@%h: ")))
  279. (found (nth 0 (auth-source-search :max 1
  280. :host address
  281. :port ports
  282. :require '(:user :secret)
  283. :create t))))
  284. (if found
  285. (list (plist-get found :user)
  286. (let ((secret (plist-get found :secret)))
  287. (if (functionp secret)
  288. (funcall secret)
  289. secret))
  290. (plist-get found :save-function))
  291. nil)))
  292. This call requires the user and password (secret) to be in the
  293. results. It also requests that an entry be created if it doesn't exist
  294. already. While the created entry is being assembled, the shown prompts
  295. will be used to interact with the user. The caller can also pass data
  296. in `auth-source-creation-defaults' to supply defaults for any of the
  297. prompts.
  298. Note that the password needs to be evaluated if it's a function.
  299. It's wrapped in a function to provide some security.
  300. Later, after a successful login, `nnimap.el' calls the
  301. `:save-function' like so:
  302. (when (functionp (nth 2 credentials))
  303. (funcall (nth 2 credentials)))
  304. This will work whether the `:save-function' was provided or not.
  305. `:save-function' will be provided only when a new entry was created, so
  306. this effectively says "after a successful login, save the
  307. authentication information we just used, if it was newly created."
  308. After the first time it's called, the `:save-function' will not run
  309. again (but it will log something if you have set `auth-source-debug' to
  310. `'trivia'). This is so it won't ask the same question again, which is
  311. annoying. This is so it won't ask the same question again, which is
  312. annoying. This is so it won't ask the same question again, which is
  313. annoying.
  314. So the responsibility of the API user that specified `:create t' is
  315. to call the `:save-function' if it's provided.
  316. -- Function: auth-source-delete &rest spec &key delete
  317. &allow-other-keys
  318. This function deletes entries matching SPEC from the
  319. authentication backends. It returns the entries that were deleted.
  320. The backend may not actually delete the entries.
  321. -- Function: auth-source-forget spec
  322. This function forgets any cached data that exactly matches SPEC.
  323. It returns `t' if it forget some data, and `nil' if no matching
  324. data was found.
  325. -- Function: auth-source-forget+ &rest spec &allow-other-keys
  326. This function forgets any cached data matching SPEC. It returns
  327. the number of items forgotten.
  328. 
  329. File: auth, Node: GnuPG and EasyPG Assistant Configuration, Next: Index, Prev: Help for developers, Up: Top
  330. Appendix A GnuPG and EasyPG Assistant Configuration
  331. ***************************************************
  332. If you don't customize `auth-sources', the auth-source library reads
  333. `~/.authinfo.gpg', which is a GnuPG encrypted file. Then it will check
  334. `~/.authinfo' but it's not recommended to use such an unencrypted file.
  335. In Emacs 23 or later there is an option `auto-encryption-mode' to
  336. automatically decrypt `*.gpg' files. It is enabled by default. If you
  337. are using earlier versions of Emacs, you will need:
  338. (require 'epa-file)
  339. (epa-file-enable)
  340. If you want your GnuPG passwords to be cached, set up `gpg-agent' or
  341. EasyPG Assistant (*note Caching Passphrases: (epa)Caching Passphrases.).
  342. To quick start, here are some questions:
  343. 1. Do you use GnuPG version 2 instead of GnuPG version 1?
  344. 2. Do you use symmetric encryption rather than public key encryption?
  345. 3. Do you want to use gpg-agent?
  346. Here are configurations depending on your answers:
  347. 1 2 3 Configuration
  348. Yes Yes Yes Set up gpg-agent.
  349. Yes Yes No You can't, without gpg-agent.
  350. Yes No Yes Set up gpg-agent.
  351. Yes No No You can't, without gpg-agent.
  352. No Yes Yes Set up elisp passphrase cache.
  353. No Yes No Set up elisp passphrase cache.
  354. No No Yes Set up gpg-agent.
  355. No No No You can't, without gpg-agent.
  356. To set up gpg-agent, follow the instruction in GnuPG manual (*note
  357. Invoking GPG-AGENT: (gnupg)Invoking GPG-AGENT.).
  358. To set up elisp passphrase cache, set
  359. `epa-file-cache-passphrase-for-symmetric-encryption'.
  360. 
  361. File: auth, Node: Index, Next: Function Index, Prev: GnuPG and EasyPG Assistant Configuration, Up: Top
  362. 2 Index
  363. *******
  364. [index]
  365. * Menu:
  366. 
  367. File: auth, Node: Function Index, Next: Variable Index, Prev: Index, Up: Top
  368. 3 Function Index
  369. ****************
  370. [index]
  371. * Menu:
  372. * auth-source-delete: Help for developers. (line 74)
  373. * auth-source-forget: Help for developers. (line 79)
  374. * auth-source-forget+: Help for developers. (line 84)
  375. * auth-source-search: Help for developers. (line 17)
  376. * secrets-create-item: Secret Service API. (line 75)
  377. * secrets-delete-item: Secret Service API. (line 90)
  378. * secrets-get-alias: Secret Service API. (line 52)
  379. * secrets-get-attribute: Secret Service API. (line 98)
  380. * secrets-get-attributes: Secret Service API. (line 103)
  381. * secrets-get-secret: Secret Service API. (line 86)
  382. * secrets-list-collections: Secret Service API. (line 45)
  383. * secrets-list-items: Secret Service API. (line 71)
  384. * secrets-search-items: Secret Service API. (line 111)
  385. * secrets-set-alias: Secret Service API. (line 48)
  386. * secrets-show-secrets: Secret Service API. (line 22)
  387. 
  388. File: auth, Node: Variable Index, Prev: Function Index, Up: Top
  389. 4 Variable Index
  390. ****************
  391. [index]
  392. * Menu:
  393. * auth-source-debug: Help for developers. (line 9)
  394. * auth-sources: Help for users. (line 49)
  395. * secrets-enabled: Secret Service API. (line 17)
  396. 
  397. Tag Table:
  398. Node: Top1298
  399. Node: Overview2885
  400. Node: Help for users3621
  401. Node: Secret Service API8406
  402. Node: Help for developers14397
  403. Node: GnuPG and EasyPG Assistant Configuration18115
  404. Node: Index19807
  405. Node: Function Index19954
  406. Node: Variable Index21190
  407. 
  408. End Tag Table