]> www.average.org Git - pam_pcsc_cr.git/blob - README.md
replace README_CR with svg pic
[pam_pcsc_cr.git] / README.md
1 % Challenge-Response PAM Module
2
3 ```
4 Copyright (c) 2013 Eugene Crosser
5
6 This software is provided 'as-is', without any express or implied
7 warranty. In no event will the authors be held liable for any damages
8 arising from the use of this software.
9
10 Permission is granted to anyone to use this software for any purpose,
11 including commercial applications, and to alter it and redistribute it
12 freely, subject to the following restrictions:
13
14     1. The origin of this software must not be misrepresented; you must
15     not claim that you wrote the original software. If you use this
16     software in a product, an acknowledgment in the product documentation
17     would be appreciated but is not required.
18
19     2. Altered source versions must be plainly marked as such, and must
20     not be misrepresented as being the original software.
21
22     3. This notice may not be removed or altered from any source
23     distribution.
24 ```
25
26 ------------------------------------------------------------------------
27
28 ## Challenge-Response PAM Module for HMAC-SHA1 Hardware Token(s)
29
30 This package provides a UNIX
31 [PAM](http://en.wikipedia.org/wiki/Pluggable_Authentication_Modules)
32 module and accompanying setup program implementing
33 [HMAC-SHA1](http://en.wikipedia.org/wiki/HMAC-SHA1) challenge-response
34 user authentication with hardware crypto token supporting
35 [PC/SC](http://en.wikipedia.org/wiki/PC/SC) (Smartcard) interface.
36
37 At the time of writing, I know of just one such hardware token, Yubikey
38 Neo from [Yubico](http://www.yubico.com/).
39 [Pcsclite](http://pcsclite.alioth.debian.org/) infrastructure (i.e.
40 library and a daemon) is used to communicate with the token over
41 [CCID](http://en.wikipedia.org/wiki/Integrated_Circuit_Card_Interface_Device)
42 (i.e. PC/SC over USB) or
43 [NFC](http://en.wikipedia.org/wiki/Near_field_communication). It means
44 that it works equally well when you plug the token in a USB slot and if
45 you put it on an NFC reader.
46
47 ## Theory of Challenge-Response Authentication
48
49 There are two ways to do challenge-response authentication: with shared
50 secret and with pre-produced response. In pre-produced response, the
51 host does not need to store the token's HMAC secret; on every session
52 conversation with the token is performed twice with different challenges.
53 The first response is used to decrypt stored encrypted challenge and
54 compare it with cleartext challenge. A new challenge is then sent
55 to the token, and response is used to encrypt it and store for the
56 future authentication session.  The advantage is that the secret is not
57 kept anywhere except the token, so it's less chance of compromise. The
58 drawback is that the response is transferred in cleartext long before
59 being used, and can be eavesdropped on and used in a replay attack. This
60 is of particular concern when using NFC. This approach is used by the
61 [PAM module provided by Yubico](https://github.com/Yubico/yubico-pam).
62
63 My module uses the second approach, under which the HMAC secret is
64 stored both in the token and on the host. To minimize the danger of
65 compromise, the host copy of the shared secret is encrypted by the key
66 which is the expected response from the token. In the process of
67 authentication, token's response is used to decrypt the secret, then
68 this secret is used to compute the next expected token's response, and
69 this expected response is used to encrypt the secret again. This next
70 expected response is not transferred over the air, and the shared secret
71 stays in unencrypted form in the RAM (unless paged out) for a very short
72 period. The downside is that if the token is used against multiple
73 hosts, and one of them leaks the secret to an adversary, all hosts are
74 compromised. This is not the case with the first approach.
75
76 The particular data structure is outlined in the picture:
77 ![](auth-data-structure.svg)
78
79 ## Module Operation
80
81 Authentication file, containing nonce, encrypted shared secret,
82 encrypted additional payload, and anciliary information, is named
83 according to template that can be provided both to PAM module and to the
84 setup program (and must be the same, obviously). In the template string,
85 character '~' in the first position is substituted with the userid's
86 home directory, '~' in a position other than first - with the userid
87 itself, and character '?' - with the "tokenid". This latter is just an
88 arbitrary string that is not involved in the authentication process.
89 But, if the template contains '?' but not '~', login process can start
90 without the knowlege of the userid. Userid will be picked from the file
91 and injected into the PAM environment, given that tokenid is known from
92 the start.
93
94 Default template string is `~/.pam_cr/auth`, i.e. the file lives in the
95 user's home directory, in the subdirectory `.pam_cr`.
96
97 Authentication file must be initially created by the program
98 `pam_cr_setup` included in this package.
99
100 ```
101 usage: pam_cr_setup [options] [username]
102     -h                - show this help and exit
103     -o backend-option - token option "backend:key=val"
104     -f template       - template for auth state filepath
105     -a secret | -A file-with-secret | -A -
106                       - 40-character hexadecimal secret
107     -s token-serial   - public I.D. of the token
108     -n nonce          - initial nonce
109     -l payload        - keyring unlock password
110     -p password       - login password
111     -v                - show returned data
112 ```
113
114 The only backend option existing is "ykneo:slot=1" or "ykneo:slot=2".
115 Slot 2 is the default. Secret must be supplied when creating the file,
116 and when modifying the file in the absense of the token. Password is
117 used to construct the challenge. If not supplied empty string is used.
118 The pam module also used empty string when given "noaskpass" argument,
119 so this can be used for "one factor" authentication mode with token
120 only. Payload is a string that can be optionally injected as the PAM
121 authentication token after successful authentication; subsequent PAM
122 modules like gnome keyring unlocker module will pick it up. Note that
123 this keyring unlocker password may be different from the login
124 password, and it is generally a good idea to make it so. The "returned
125 data" is the userid as recorded in the file and the aforementioned
126 payload string.
127
128 PAM module has the following parameters:
129
130 ```
131         verbose         write more errors to syslog.
132         noaskpass       do not try to ask the user for the challenge
133                         password, use empty string for the password.
134         injectauth      inject payload as PAM_AUTHTOK for the benefit
135                         of subsequent PAM modules.
136         path=<string>   template used to find the file.
137         backend:key=val backend options.
138 ```
139
140 ## Getting the Source
141
142 Check the [project homepage](http://www.average.org/chal-resp-auth/).
143
144 Pick the source tarball
145 [here](http://www.average.org/chal-resp-auth/pam_pcsc_cr-0.9.1.tar.xz),
146 or you can [clone](git://git.average.org/git/pam_pcsc_cr.git) or
147 [browse](http://www.average.org/gitweb/?p=pam_pcsc_cr.git;a=summary)
148 the git repo.
149
150 ## Author
151
152 Eugene Crosser \<crosser at average dot org\>   
153 <http://www.average.org/~crosser/>
154
155 ---