Merge branch 'master' of https://git.gnus.org/gnus
[gnus] / texi / auth.texi
1 \input texinfo                  @c -*-texinfo-*-
2
3 @include overrides.texi
4
5 @setfilename auth
6 @settitle Emacs auth-source Library @value{VERSION}
7
8 @set VERSION 0.2
9
10 @copying
11 This file describes the Emacs auth-source library.
12
13 Copyright @copyright{} 2008-2011 Free Software Foundation, Inc.
14
15 @quotation
16 Permission is granted to copy, distribute and/or modify this document
17 under the terms of the GNU Free Documentation License, Version 1.3 or
18 any later version published by the Free Software Foundation; with no
19 Invariant Sections, with the Front-Cover texts being ``A GNU Manual,''
20 and with the Back-Cover Texts as in (a) below.  A copy of the license
21 is included in the section entitled ``GNU Free Documentation License''
22 in the Emacs manual.
23
24 (a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
25 modify this GNU manual.  Buying copies from the FSF supports it in
26 developing GNU and promoting software freedom.''
27
28 This document is part of a collection distributed under the GNU Free
29 Documentation License.  If you want to distribute this document
30 separately from the collection, you can do so by adding a copy of the
31 license to the document, as described in section 6 of the license.
32 @end quotation
33 @end copying
34
35 @dircategory Emacs
36 @direntry
37 * Auth-source: (auth).          The Emacs auth-source library.
38 @end direntry
39
40 @titlepage
41 @ifset WEBHACKDEVEL
42 @title Emacs auth-source Library (DEVELOPMENT VERSION)
43 @end ifset
44 @ifclear WEBHACKDEVEL
45 @title Emacs auth-source Library
46 @end ifclear
47 @author by Ted Zlatanov
48 @page
49 @vskip 0pt plus 1filll
50 @insertcopying
51 @end titlepage
52
53 @contents
54
55 @ifnottex
56 @node Top
57 @top Emacs auth-source
58 This manual describes the Emacs auth-source library.
59
60 It is a way for multiple applications to share a single configuration
61 (in Emacs and in files) for user convenience.
62
63 @insertcopying
64
65 @menu
66 * Overview::                    Overview of the auth-source library.
67 * Help for users::              
68 * Secret Service API::          
69 * Help for developers::         
70 * GnuPG and EasyPG Assistant Configuration::  
71 * Index::                       
72 * Function Index::              
73 * Variable Index::              
74 @end menu
75 @end ifnottex
76
77 @node Overview
78 @chapter Overview
79
80 The auth-source library is simply a way for Emacs and Gnus, among
81 others, to answer the old burning question ``I have a server name and
82 a port, what are my user name and password?''
83
84 The auth-source library actually supports more than just the user name
85 (known as the login) or the password, but only those two are in use
86 today in Emacs or Gnus.  Similarly, the auth-source library supports
87 multiple storage formats, currently either the classic ``netrc''
88 format, examples of which you can see later in this document, or the
89 Secret Service API.
90
91 @node Help for users
92 @chapter Help for users
93
94 ``Netrc'' files are a de facto standard.  They look like this:
95 @example
96 machine @var{mymachine} login @var{myloginname} password @var{mypassword} port @var{myport}
97 @end example
98
99 The machine is the server (either a DNS name or an IP address).
100
101 The port is optional.  If it's missing, auth-source will assume any
102 port is OK.  Actually the port is a protocol name or a port number so
103 you can have separate entries for port @var{143} and for protocol
104 @var{imap} if you fancy that.  Anyway, you can just omit the port if
105 you don't need it.
106
107 The login and password are simply your login credentials to the server.
108
109 ``Netrc'' files are usually called @code{.authinfo} or @code{.netrc};
110 nowadays @code{.authinfo} seems to be more popular and the auth-source
111 library encourages this confusion by making it the default, as you'll
112 see later.
113
114 If you have problems with the port, set @code{auth-source-debug} to
115 @code{t} and see what port the library is checking in the
116 @code{*Messages*} buffer.  Ditto for any other problems, your first
117 step is always to see what's being checked.  The second step, of
118 course, is to write a blog entry about it and wait for the answer in
119 the comments.
120
121 You can customize the variable @code{auth-sources}.  The following may
122 be needed if you are using an older version of Emacs or if the
123 auth-source library is not loaded for some other reason.
124
125 @lisp
126 (require 'auth-source)             ;; probably not necessary
127 (customize-variable 'auth-sources) ;; optional, do it once
128 @end lisp
129
130 @defvar auth-sources
131
132 The @code{auth-sources} variable tells the auth-source library where
133 your netrc files or Secret Service API collection items live for a
134 particular host and protocol.  While you can get fancy, the default
135 and simplest configuration is:
136
137 @lisp
138 ;;; old default: required :host and :protocol, not needed anymore
139 (setq auth-sources '((:source "~/.authinfo.gpg" :host t :protocol t)))
140 ;;; mostly equivalent (see below about fallbacks) but shorter:
141 (setq auth-sources '((:source "~/.authinfo.gpg")))
142 @end lisp
143
144 This says ``for any host and any protocol, use just that one file.''
145 Sweet simplicity.  In fact, the latter is already the default, so
146 unless you want to move your netrc file, it will just work if you have
147 that file.  Make sure it exists.
148
149 By adding multiple entries to @code{auth-sources} with a particular
150 host or protocol, you can have specific netrc files for that host or
151 protocol.  Usually this is unnecessary but may make sense if you have
152 shared netrc files or some other unusual setup (90% of Emacs users
153 have unusual setups and the remaining 10% are @emph{really} unusual).
154
155 Here's an example that uses the Secret Service API for all lookups,
156 using the default collection:
157
158 @lisp
159 (setq auth-sources '((:source (:secrets default))))
160 @end lisp
161
162 And here's a mixed example, using two sources:
163
164 @lisp
165 (setq auth-sources '((:source (:secrets default) :host "myserver" :user "joe")
166                      (:source "~/.authinfo.gpg")))
167 @end lisp
168
169 The best match is determined by order (starts from the bottom) only
170 for the first pass, where things are checked exactly.  In the example
171 above, the first pass would find a single match for host
172 @code{myserver}.  The netrc choice would fail because it matches any
173 host and protocol implicitly (as a @emph{fallback}).  A specified
174 value of @code{:host t} in @code{auth-sources} is considered a match
175 on the first pass, unlike a missing @code{:host}.
176
177 Now if you look for host @code{missing}, it won't match either source
178 explicitly.  The second pass (the @emph{fallback} pass) will look at
179 all the implicit matches and collect them.  They will be scored and
180 returned sorted by score.  The score is based on the number of
181 explicit parameters that matched. See the @code{auth-pick} function
182 for details.
183
184 @end defvar
185
186 If you don't customize @code{auth-sources}, you'll have to live with
187 the defaults: any host and any port are looked up in the netrc
188 file @code{~/.authinfo.gpg}, which is a GnuPG encrypted file
189 (@pxref{GnuPG and EasyPG Assistant Configuration}).
190
191 The simplest working netrc line example is one without a port.
192
193 @example
194 machine YOURMACHINE login YOU password YOURPASSWORD
195 @end example
196
197 This will match any authentication port.  Simple, right?  But what if
198 there's a SMTP server on port 433 of that machine that needs a
199 different password from the IMAP server?
200
201 @example
202 machine YOURMACHINE login YOU password SMTPPASSWORD port 433
203 machine YOURMACHINE login YOU password GENERALPASSWORD
204 @end example
205
206 For url-auth authentication (HTTP/HTTPS), you need to put this in your
207 netrc file:
208
209 @example
210 machine yourmachine.com:80 port http login testuser password testpass
211 @end example
212
213 This will match any realm and authentication method (basic or digest)
214 over HTTP.  HTTPS is set up similarly.  If you want finer controls,
215 explore the url-auth source code and variables.
216
217 For Tramp authentication, use:
218
219 @example
220 machine yourmachine.com port scp login testuser password testpass
221 @end example
222
223 Note that the port denotes the Tramp connection method.  When you
224 don't use a port entry, you match any Tramp method, as explained
225 earlier.  Since Tramp has about 88 connection methods, this may be
226 necessary if you have an unusual (see earlier comment on those) setup.
227
228 @node Secret Service API
229 @chapter Secret Service API
230
231 TODO: how does it work generally, how does secrets.el work, some examples.
232
233 @node Help for developers
234 @chapter Help for developers
235
236 The auth-source library only has one function for external use.
237
238 @defun auth-source-user-or-password mode host port &optional username
239
240 Retrieve appropriate authentication tokens, determined by @var{mode},
241 for host @var{host} and @var{port}.  If @var{username} is provided it
242 will also be checked.  If @code{auth-source-debug} is t, debugging
243 messages will be printed.  Set @code{auth-source-debug} to a function
244 to use that function for logging.  The parameters passed will be the
245 same that the @code{message} function takes, that is, a string
246 formatting spec and optional parameters.
247
248 If @var{mode} is a list of strings, the function will return a list of
249 strings or @code{nil} objects (thus you can avoid parsing the netrc
250 file or checking the Secret Service API more than once).  If it's a
251 string, the function will return a string or a @code{nil} object.
252 Currently only the modes ``login'' and ``password'' are recognized but
253 more may be added in the future.
254
255 @var{host} is a string containing the host name.
256
257 @var{port} contains the protocol name (e.g. ``imap'') or
258 a port number.  It must be a string, corresponding to the port in the
259 users' netrc files.
260
261 @var{username} contains the user name (e.g. ``joe'') as a string.
262
263 @example
264 ;; IMAP example
265 (setq auth (auth-source-user-or-password
266             '("login" "password")
267             "anyhostnamehere"
268             "imap"))
269 (nth 0 auth) ; the login name
270 (nth 1 auth) ; the password
271 @end example
272
273 @end defun
274
275 @node GnuPG and EasyPG Assistant Configuration
276 @appendix GnuPG and EasyPG Assistant Configuration
277
278 If you don't customize @code{auth-sources}, the auth-source library
279 reads @code{~/.authinfo.gpg}, which is a GnuPG encrypted file.
280
281 In Emacs 23 or later there is an option @code{auto-encryption-mode} to
282 automatically decrypt @code{*.gpg} files.  It is enabled by default.
283 If you are using earlier versions of Emacs, you will need:
284
285 @lisp
286 (require 'epa-file)
287 (epa-file-enable)
288 @end lisp
289
290 If you want your GnuPG passwords to be cached, set up @code{gpg-agent}
291 or EasyPG Assitant
292 (@pxref{Caching Passphrases, , Caching Passphrases, epa}).
293
294 To quick start, here are some questions:
295
296 @enumerate
297 @item
298 Do you use GnuPG version 2 instead of GnuPG version 1?
299 @item
300 Do you use symmetric encryption rather than public key encryption?
301 @item
302 Do you want to use gpg-agent?
303 @end enumerate
304
305 Here are configurations depending on your answers:
306
307 @multitable {111} {222} {333} {configuration configuration configuration}
308 @item @b{1} @tab @b{2} @tab @b{3} @tab Configuration
309 @item Yes @tab Yes @tab Yes @tab Set up gpg-agent.
310 @item Yes @tab Yes @tab No @tab You can't, without gpg-agent.
311 @item Yes @tab No @tab Yes @tab Set up gpg-agent.
312 @item Yes @tab No @tab No @tab You can't, without gpg-agent.
313 @item No @tab Yes @tab Yes @tab Set up elisp passphrase cache.
314 @item No @tab Yes @tab No @tab Set up elisp passphrase cache.
315 @item No @tab No @tab Yes @tab Set up gpg-agent.
316 @item No @tab No @tab No @tab You can't, without gpg-agent.
317 @end multitable
318
319 To set up gpg-agent, follow the instruction in GnuPG manual
320 (@pxref{Invoking GPG-AGENT, , Invoking GPG-AGENT, gnupg}).
321
322 To set up elisp passphrase cache, set
323 @code{epa-file-cache-passphrase-for-symmetric-encryption}.
324
325 @node Index
326 @chapter Index
327 @printindex cp
328
329 @node Function Index
330 @chapter Function Index
331 @printindex fn
332
333 @node Variable Index
334 @chapter Variable Index
335 @printindex vr
336
337 @bye
338
339 @c End: