123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536 |
- This is ../../info/auth, produced by makeinfo version 4.13 from
- auth.texi.
- This file describes the Emacs auth-source library.
- Copyright (C) 2008-2012 Free Software Foundation, Inc.
- Permission is granted to copy, distribute and/or modify this
- document under the terms of the GNU Free Documentation License,
- Version 1.3 or any later version published by the Free Software
- Foundation; with no Invariant Sections, with the Front-Cover texts
- being "A GNU Manual," and with the Back-Cover Texts as in (a)
- below. A copy of the license is included in the section entitled
- "GNU Free Documentation License" in the Emacs manual.
- (a) The FSF's Back-Cover Text is: "You have the freedom to copy and
- modify this GNU manual. Buying copies from the FSF supports it in
- developing GNU and promoting software freedom."
- This document is part of a collection distributed under the GNU
- Free Documentation License. If you want to distribute this
- document separately from the collection, you can do so by adding a
- copy of the license to the document, as described in section 6 of
- the license.
- INFO-DIR-SECTION Emacs lisp libraries
- START-INFO-DIR-ENTRY
- * Auth-source: (auth). The Emacs auth-source library.
- END-INFO-DIR-ENTRY
- File: auth, Node: Top, Next: Overview, Up: (dir)
- Emacs auth-source
- *****************
- This manual describes the Emacs auth-source library.
- It is a way for multiple applications to share a single configuration
- (in Emacs and in files) for user convenience.
- This file describes the Emacs auth-source library.
- Copyright (C) 2008-2012 Free Software Foundation, Inc.
- Permission is granted to copy, distribute and/or modify this
- document under the terms of the GNU Free Documentation License,
- Version 1.3 or any later version published by the Free Software
- Foundation; with no Invariant Sections, with the Front-Cover texts
- being "A GNU Manual," and with the Back-Cover Texts as in (a)
- below. A copy of the license is included in the section entitled
- "GNU Free Documentation License" in the Emacs manual.
- (a) The FSF's Back-Cover Text is: "You have the freedom to copy and
- modify this GNU manual. Buying copies from the FSF supports it in
- developing GNU and promoting software freedom."
- This document is part of a collection distributed under the GNU
- Free Documentation License. If you want to distribute this
- document separately from the collection, you can do so by adding a
- copy of the license to the document, as described in section 6 of
- the license.
- * Menu:
- * Overview:: Overview of the auth-source library.
- * Help for users::
- * Secret Service API::
- * Help for developers::
- * GnuPG and EasyPG Assistant Configuration::
- * Index::
- * Function Index::
- * Variable Index::
- File: auth, Node: Overview, Next: Help for users, Prev: Top, Up: Top
- 1 Overview
- **********
- The auth-source library is simply a way for Emacs and Gnus, among
- others, to answer the old burning question "What are my user name and
- password?"
- (This is different from the old question about burning "Where is the
- fire extinguisher, please?".)
- The auth-source library supports more than just the user name or the
- password (known as the secret).
- Similarly, the auth-source library supports multiple storage backend,
- currently either the classic "netrc" backend, examples of which you can
- see later in this document, or the Secret Service API. This is done
- with EIEIO-based backends and you can write your own if you want.
- File: auth, Node: Help for users, Next: Secret Service API, Prev: Overview, Up: Top
- 2 Help for users
- ****************
- "Netrc" files are a de facto standard. They look like this:
- machine MYMACHINE login MYLOGINNAME password MYPASSWORD port MYPORT
- The `machine' is the server (either a DNS name or an IP address).
- It's known as :HOST in `auth-source-search' queries. You can also use
- `host'.
- The `port' is the connection port or protocol. It's known as :PORT
- in `auth-source-search' queries.
- The `user' is the user name. It's known as :USER in
- `auth-source-search' queries. You can also use `login' and `account'.
- Spaces are always OK as far as auth-source is concerned (but other
- programs may not like them). Just put the data in quotes, escaping
- quotes as you'd expect with `\'.
- All these are optional. You could just say (but we don't recommend
- it, we're just showing that it's possible)
- password MYPASSWORD
- to use the same password everywhere. Again, _DO NOT DO THIS_ or you
- will be pwned as the kids say.
- "Netrc" files are usually called `.authinfo' or `.netrc'; nowadays
- `.authinfo' seems to be more popular and the auth-source library
- encourages this confusion by accepting both, as you'll see later.
- If you have problems with the search, set `auth-source-debug' to
- `'trivia' and see what host, port, and user the library is checking in
- the `*Messages*' buffer. Ditto for any other problems, your first step
- is always to see what's being checked. The second step, of course, is
- to write a blog entry about it and wait for the answer in the comments.
- You can customize the variable `auth-sources'. The following may be
- needed if you are using an older version of Emacs or if the auth-source
- library is not loaded for some other reason.
- (require 'auth-source) ;; probably not necessary
- (customize-variable 'auth-sources) ;; optional, do it once
- -- Variable: auth-sources
- The `auth-sources' variable tells the auth-source library where
- your netrc files or Secret Service API collection items live for a
- particular host and protocol. While you can get fancy, the default
- and simplest configuration is:
- ;;; old default: required :host and :port, not needed anymore
- (setq auth-sources '((:source "~/.authinfo.gpg" :host t :port t)))
- ;;; mostly equivalent (see below about fallbacks) but shorter:
- (setq auth-sources '((:source "~/.authinfo.gpg")))
- ;;; even shorter and the _default_:
- (setq auth-sources '("~/.authinfo.gpg" "~/.authinfo" "~/.netrc"))
- ;;; use the Secrets API LOGIN collection (*note Secret Service API::)
- (setq auth-sources '("secrets:Login"))
- By adding multiple entries to `auth-sources' with a particular
- host or protocol, you can have specific netrc files for that host
- or protocol. Usually this is unnecessary but may make sense if
- you have shared netrc files or some other unusual setup (90% of
- Emacs users have unusual setups and the remaining 10% are _really_
- unusual).
- Here's a mixed example using two sources:
- (setq auth-sources '((:source (:secrets default) :host "myserver" :user "joe")
- "~/.authinfo.gpg"))
- If you don't customize `auth-sources', you'll have to live with the
- defaults: any host and any port are looked up in the netrc file
- `~/.authinfo.gpg', which is a GnuPG encrypted file (*note GnuPG and
- EasyPG Assistant Configuration::).
- If that fails, the unencrypted netrc files `~/.authinfo' and
- `~/.netrc' will be used.
- The typical netrc line example is without a port.
- machine YOURMACHINE login YOU password YOURPASSWORD
- This will match any authentication port. Simple, right? But what if
- there's a SMTP server on port 433 of that machine that needs a
- different password from the IMAP server?
- machine YOURMACHINE login YOU password SMTPPASSWORD port 433
- machine YOURMACHINE login YOU password GENERALPASSWORD
- For url-auth authentication (HTTP/HTTPS), you need to put this in
- your netrc file:
- machine yourmachine.com:80 port http login testuser password testpass
- This will match any realm and authentication method (basic or digest)
- over HTTP. HTTPS is set up similarly. If you want finer controls,
- explore the url-auth source code and variables.
- For Tramp authentication, use:
- machine yourmachine.com port scp login testuser password testpass
- Note that the port denotes the Tramp connection method. When you
- don't use a port entry, you match any Tramp method, as explained
- earlier. Since Tramp has about 88 connection methods, this may be
- necessary if you have an unusual (see earlier comment on those) setup.
- File: auth, Node: Secret Service API, Next: Help for developers, Prev: Help for users, Up: Top
- 3 Secret Service API
- ********************
- The "Secret Service API" is a standard from freedesktop.org to securely
- store passwords and other confidential information. This API is
- implemented by system daemons such as the GNOME Keyring and the KDE
- Wallet (these are GNOME and KDE packages respectively and should be
- available on most modern GNU/Linux systems).
- The auth-source library uses the `secrets.el' library to connect
- through the Secret Service API. You can also use that library in other
- packages, it's not exclusive to auth-source.
- -- Variable: secrets-enabled
- After loading `secrets.el', a non-`nil' value of this variable
- indicates the existence of a daemon providing the Secret Service
- API.
- -- Command: secrets-show-secrets
- This command shows all collections, items, and their attributes.
- The atomic objects managed by the Secret Service API are "secret
- items", which contain things an application wishes to store securely,
- like a password. Secret items have a label (a name), the "secret"
- (which is the string we want, like a password), and a set of lookup
- attributes. The attributes can be used to search and retrieve a secret
- item at a later date.
- Secret items are grouped in "collections". A collection is
- sometimes called a `keyring' or `wallet' in GNOME Keyring and KDE
- Wallet but it's the same thing, a group of secrets. Collections are
- personal and protected so only the owner can open them.
- The most common collection is called `"login"'.
- A collection can have an alias. The alias `"default"' is commonly
- used so the clients don't have to know the specific name of the
- collection they open. Other aliases are not supported yet. Since
- aliases are globally accessible, set the `"default"' alias only when
- you're sure it's appropriate.
- -- Function: secrets-list-collections
- This function returns all the collection names as a list.
- -- Function: secrets-set-alias collection alias
- Set ALIAS as alias of collection labeled COLLECTION. Currently
- only the alias `"default"' is supported.
- -- Function: secrets-get-alias alias
- Return the collection name ALIAS is referencing to. Currently
- only the alias `"default"' is supported.
- Collections can be created and deleted by the functions
- `secrets-create-collection' and `secrets-delete-collection'. Usually,
- this is not done from within Emacs. Do not delete standard collections
- such as `"login"'.
- The special collection `"session"' exists for the lifetime of the
- corresponding client session (in our case, Emacs's lifetime). It is
- created automatically when Emacs uses the Secret Service interface and
- it is deleted when Emacs is killed. Therefore, it can be used to store
- and retrieve secret items temporarily. The `"session"' collection is
- better than a persistent collection when the secret items should not
- live longer than Emacs. The session collection can be specified either
- by the string `"session"', or by `nil', whenever a collection parameter
- is needed in the following functions.
- -- Function: secrets-list-items collection
- Returns all the item labels of COLLECTION as a list.
- -- Function: secrets-create-item collection item password &rest
- attributes
- This function creates a new item in COLLECTION with label ITEM and
- password PASSWORD. ATTRIBUTES are key-value pairs set for the
- created item. The keys are keyword symbols, starting with a
- colon. Example:
- ;;; The session "session", the label is "my item"
- ;;; and the secret (password) is "geheim"
- (secrets-create-item "session" "my item" "geheim"
- :method "sudo" :user "joe" :host "remote-host")
- -- Function: secrets-get-secret collection item
- Return the secret of item labeled ITEM in COLLECTION. If there is
- no such item, return `nil'.
- -- Function: secrets-delete-item collection item
- This function deletes item ITEM in COLLECTION.
- The lookup attributes, which are specified during creation of a
- secret item, must be a key-value pair. Keys are keyword symbols,
- starting with a colon; values are strings. They can be retrieved from
- a given secret item and they can be used for searching of items.
- -- Function: secrets-get-attribute collection item attribute
- Returns the value of key ATTRIBUTE of item labeled ITEM in
- COLLECTION. If there is no such item, or the item doesn't own
- this key, the function returns `nil'.
- -- Function: secrets-get-attributes collection item
- Return the lookup attributes of item labeled ITEM in COLLECTION.
- If there is no such item, or the item has no attributes, it
- returns `nil'. Example:
- (secrets-get-attributes "session" "my item")
- => ((:user . "joe") (:host ."remote-host"))
- -- Function: secrets-search-items collection &rest attributes
- Search for the items in COLLECTION with matching ATTRIBUTES. The
- ATTRIBUTES are key-value pairs, as used in `secrets-create-item'.
- Example:
- (secrets-search-items "session" :user "joe")
- => ("my item" "another item")
- The auth-source library uses the `secrets.el' library and thus the
- Secret Service API when you specify a source matching
- `"secrets:COLLECTION"'. For instance, you could use
- `"secrets:session"' to use the `"session"' collection, open only for
- the lifetime of Emacs. Or you could use `"secrets:Login"' to open the
- `"Login"' collection. As a special case, you can use the symbol
- `default' in `auth-sources' (not a string, but a symbol) to specify the
- `"default"' alias. Here is a contrived example that sets
- `auth-sources' to search three collections and then fall back to
- `~/.authinfo.gpg'.
- (setq auth-sources '(default
- "secrets:session"
- "secrets:Login"
- "~/.authinfo.gpg"))
- File: auth, Node: Help for developers, Next: GnuPG and EasyPG Assistant Configuration, Prev: Secret Service API, Up: Top
- 4 Help for developers
- *********************
- The auth-source library lets you control logging output easily.
- -- Variable: auth-source-debug
- Set this variable to `'trivia' to see lots of output in
- `*Messages*', or set it to a function that behaves like `message'
- to do your own logging.
- The auth-source library only has a few functions for external use.
- -- Function: auth-source-search &rest spec &key type max host user
- port secret require create delete &allow-other-keys
- This function searches (or modifies) authentication backends
- according to SPEC. See the function's doc-string for details.
- Let's take a look at an example of using `auth-source-search' from
- Gnus's `nnimap.el'.
- (defun nnimap-credentials (address ports)
- (let* ((auth-source-creation-prompts
- '((user . "IMAP user at %h: ")
- (secret . "IMAP password for %u@%h: ")))
- (found (nth 0 (auth-source-search :max 1
- :host address
- :port ports
- :require '(:user :secret)
- :create t))))
- (if found
- (list (plist-get found :user)
- (let ((secret (plist-get found :secret)))
- (if (functionp secret)
- (funcall secret)
- secret))
- (plist-get found :save-function))
- nil)))
- This call requires the user and password (secret) to be in the
- results. It also requests that an entry be created if it doesn't exist
- already. While the created entry is being assembled, the shown prompts
- will be used to interact with the user. The caller can also pass data
- in `auth-source-creation-defaults' to supply defaults for any of the
- prompts.
- Note that the password needs to be evaluated if it's a function.
- It's wrapped in a function to provide some security.
- Later, after a successful login, `nnimap.el' calls the
- `:save-function' like so:
- (when (functionp (nth 2 credentials))
- (funcall (nth 2 credentials)))
- This will work whether the `:save-function' was provided or not.
- `:save-function' will be provided only when a new entry was created, so
- this effectively says "after a successful login, save the
- authentication information we just used, if it was newly created."
- After the first time it's called, the `:save-function' will not run
- again (but it will log something if you have set `auth-source-debug' to
- `'trivia'). This is so it won't ask the same question again, which is
- annoying. This is so it won't ask the same question again, which is
- annoying. This is so it won't ask the same question again, which is
- annoying.
- So the responsibility of the API user that specified `:create t' is
- to call the `:save-function' if it's provided.
- -- Function: auth-source-delete &rest spec &key delete
- &allow-other-keys
- This function deletes entries matching SPEC from the
- authentication backends. It returns the entries that were deleted.
- The backend may not actually delete the entries.
- -- Function: auth-source-forget spec
- This function forgets any cached data that exactly matches SPEC.
- It returns `t' if it forget some data, and `nil' if no matching
- data was found.
- -- Function: auth-source-forget+ &rest spec &allow-other-keys
- This function forgets any cached data matching SPEC. It returns
- the number of items forgotten.
- File: auth, Node: GnuPG and EasyPG Assistant Configuration, Next: Index, Prev: Help for developers, Up: Top
- Appendix A GnuPG and EasyPG Assistant Configuration
- ***************************************************
- If you don't customize `auth-sources', the auth-source library reads
- `~/.authinfo.gpg', which is a GnuPG encrypted file. Then it will check
- `~/.authinfo' but it's not recommended to use such an unencrypted file.
- In Emacs 23 or later there is an option `auto-encryption-mode' to
- automatically decrypt `*.gpg' files. It is enabled by default. If you
- are using earlier versions of Emacs, you will need:
- (require 'epa-file)
- (epa-file-enable)
- If you want your GnuPG passwords to be cached, set up `gpg-agent' or
- EasyPG Assistant (*note Caching Passphrases: (epa)Caching Passphrases.).
- To quick start, here are some questions:
- 1. Do you use GnuPG version 2 instead of GnuPG version 1?
- 2. Do you use symmetric encryption rather than public key encryption?
- 3. Do you want to use gpg-agent?
- Here are configurations depending on your answers:
- 1 2 3 Configuration
- Yes Yes Yes Set up gpg-agent.
- Yes Yes No You can't, without gpg-agent.
- Yes No Yes Set up gpg-agent.
- Yes No No You can't, without gpg-agent.
- No Yes Yes Set up elisp passphrase cache.
- No Yes No Set up elisp passphrase cache.
- No No Yes Set up gpg-agent.
- No No No You can't, without gpg-agent.
- To set up gpg-agent, follow the instruction in GnuPG manual (*note
- Invoking GPG-AGENT: (gnupg)Invoking GPG-AGENT.).
- To set up elisp passphrase cache, set
- `epa-file-cache-passphrase-for-symmetric-encryption'.
- File: auth, Node: Index, Next: Function Index, Prev: GnuPG and EasyPG Assistant Configuration, Up: Top
- 2 Index
- *******
|