Debian Codegraph @

doc/contrib/mod_auth_otp.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>ProFTPD module mod_auth_otp</title>
5 </head>
6
7 <body bgcolor=white>
8
9 <hr>
10 <center>
11 <h2><b>ProFTPD module <code>mod_auth_otp</code></b></h2>
12 </center>
13 <hr><br>
14
15 <p>
16 The purpose of the <code>mod_auth_otp</code> module is to enable the use
17 of <em>one-time-passwords (OTP)</em> for proftpd authentication. There have
18 been multiple different OTP algorithms devised over the years; this module
19 implements the HOTP and TOTP algorithms. Note that <code>mod_auth_otp</code>
20 requires storage/retrieval for per-user shared keys and counters, and thus
21 this module currently <b>requires mod_sql</b>.
22
23 <p>
24 <b>One-Time Password RFCs</b><br>
25 For those wishing to learn more about these one-time password algorithms, see:
26 <ul>
27 <li><a href="http://www.faqs.org/rfcs/rfc4226.html">HOTP: An HMAC-Based One-Time Password Algorithm (RFC 4226)</a>
28 <li><a href="http://www.faqs.org/rfcs/rfc6238.html">TOTP: Time-Based One-Time Password Algorithm(RFC 6238)</a>
29 </ul>
30 Note that <a href="http://en.wikipedia.org/wiki/Google_Authenticator"><code>Google Authenticator</code></a> is based on the TOTP algorithm;
31 <code>mod_auth_otp</code> thus enables use of Google Authenticator for ProFTPD
32 authentication.
33
34 <p>
35 Installation instructions are discussed <a href="#Installation">here</a>;
36 detailed notes on best practices for using this module are
37 <a href="#Usage">here</a>.
38
39 <p>
40 The most current version of <code>mod_auth_otp</code> is distributed with the
41 ProFTPD source code.
42
43 <p>
44 This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit (http://www.openssl.org/).
45
46 <p>
47 This product includes cryptographic software written by Eric Young ([email protected]).
48
49 <h2>Author</h2>
50 <p>
51 Please contact TJ Saunders &lt;tj <i>at</i> castaglia.org&gt; with any
52 questions, concerns, or suggestions regarding this module.
53
54 <h2>Directives</h2>
55 <ul>
56 <li><a href="#AuthOTPAlgorithm">AuthOTPAlgorithm</a>
57 <li><a href="#AuthOTPEngine">AuthOTPEngine</a>
58 <li><a href="#AuthOTPLog">AuthOTPLog</a>
59 <li><a href="#AuthOTPOptions">AuthOTPOptions</a>
60 <li><a href="#AuthOTPTable">AuthOTPTable</a>
61 <li><a href="#AuthOTPTableLock">AuthOTPTableLock</a>
62 </ul>
63
64 <p>
65 <hr>
66 <h3><a name="AuthOTPAlgorithm">AuthOTPAlgorithm</a></h3>
67 <strong>Syntax:</strong> AuthOTPAlgorithm <em>hotp|totp</em><br>
68 <strong>Default:</strong> AuthOTPAlgorithm totp<br>
69 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
70 <strong>Module:</strong> mod_auth_otp<br>
71 <strong>Compatibility:</strong> 1.3.5rc4 and later
72
73 <p>
74 The <code>AuthOTPAlgorithm</code> directive configures which one-time password
75 algorithm will be used when calculating codes for connections to the virtual
76 host.
77
78 <p>
79 The supported algorithm names are:
80 <ul>
81 <li><code>hotp</code> (counter-based codes)
82 <li><code>totp</code> (time-based codes, using HMAC-SHA1)
83 <li><code>totp-sha256</code> (time-based codes, using HMAC-SHA256)
84 <li><code>totp-sha512</code> (time-based codes, using HMAC-SHA512)
85 </ul>
86 The default algorithm is "totp".
87
88 <p>
89 <hr>
90 <h3><a name="AuthOTPEngine">AuthOTPEngine</a></h3>
91 <strong>Syntax:</strong> AuthOTPEngine <em>on|off</em><br>
92 <strong>Default:</strong> None<br>
93 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
94 <strong>Module:</strong> mod_auth_otp<br>
95 <strong>Compatibility:</strong> 1.3.5rc4 and later
96
97 <p>
98 The <code>AuthOTPEngine</code> directive enables the handling of one-time
99 password codes for authentication, both for FTP/FTPS as well as SFTP/SCP
100 sessions. By default, use of one-time passwords is disabled.
101
102 <p>
103 <hr>
104 <h3><a name="AuthOTPLog">AuthOTPLog</a></h3>
105 <strong>Syntax:</strong> AuthOTPLog <em>path|"none"</em><br>
106 <strong>Default:</strong> None<br>
107 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
108 <strong>Module:</strong> mod_auth_otp<br>
109 <strong>Compatibility:</strong> 1.3.5rc4 and later
110
111 <p>
112 The <code>AuthOTPLog</code> directive is used to specify a log file for
113 <code>mod_auth_otp</code>'s reporting on a per-server basis. The <em>path</em>
114 parameter given must be the full path to the file to use for logging.
115
116 <p>
117 Note that this path must <b>not</b> be to a world-writable directory and,
118 unless <code>AllowLogSymlinks</code> is explicitly set to <em>on</em>
119 (generally a bad idea), the path must <b>not</b> be a symbolic link.
120
121 <p>
122 <hr>
123 <h3><a name="AuthOTPOptions">AuthOTPOptions</a></h3>
124 <strong>Syntax:</strong> AuthOTPOptions <em>opt1 ...</em><br>
125 <strong>Default:</strong> None<br>
126 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
127 <strong>Module:</strong> mod_auth_otp<br>
128 <strong>Compatibility:</strong> 1.3.5rc4 and later
129
130 <p>
131 The <code>AuthOTPOptions</code> directive is used to configure various optional
132 behavior of <code>mod_auth_otp</code>.
133
134 <p>
135 For example:
136 <pre>
137 AuthOTPOptions FTPStandardResponse
138 </pre>
139
140 <p>
141 The currently implemented options are:
142 <ul>
143 <li><code>DisplayVerificationCode</code><br>
144 When <code>mod_auth_otp</code> prompts the user for the OTP code, it
145 requests that the client <b>not</b> echo/display the verification code
146 as it is entered by the user. In some cases, however, administrators
147 may wish to have the OTP code be displayed. For these situations, use
148 this option, <i>e.g.</i>:
149 <pre>
150 AuthOTPOptions DisplayVerificationCode
151 </pre>
152 </li>
153
154 <p>
155 <li><code>FTPStandardResponse</code><br>
156 <p>
157 When <code>mod_auth_otp</code> is handling FTP sessions, it will respond
158 to a <code>USER</code> command with a response message indicating the
159 expectation of a one-time password:
160 <pre>
161 331 One-time password required for <i>user</i>
162 </pre>
163 However, this change of the response message "leaks" information about
164 the server configuration, <i>i.e.</i> that OTPs will be used. To
165 tell <code>mod_auth_otp</code> to continue using the standard/normal
166 response message, use this option.
167 </li>
168
169 <p>
170 <li><code>OptionalTableEntry</code><br>
171 <p>
172 If this option is used, then when <code>mod_auth_otp</code> requests
173 information for a user from the <code>AuthOTPTable</code> and no
174 information is found, it will allow other auth modules to handle the login
175 attempt, <b>even if <code>mod_auth_otp</code> is authoritative</b>.
176 This behavior allows for a seamless transition of your user base,
177 provisioning users with shared keys/secrets for their one-time passwords
178 as time allows.
179
180 <p>
181 <b>Note</b> that this option first appeared in
182 <code>proftpd-1.3.9rc1</code>.
183 </li>
184
185 <p>
186 <li><code>RequireTableEntry</code><br>
187 <p>
188 When <code>mod_auth_otp</code> requests information for a user from the
189 <code>AuthOTPTable</code> and no information is found, it <i>could</i>
190 allow other auth modules to handle the login attempt, <b>even if
191 <code>mod_auth_otp</code> is authoritative</b>. This behavior allows
192 for a seamless transition of your user base, provisioning users with
193 shared keys/secrets for their one-time passwords as time allows.
194
195 <p>
196 However, there may be sites which <b>require</b> the use of one-time
197 passwords; any login attempt which does not use a valid one-time
198 password <b>must</b> be rejected. Thus the lack of an entry for a user
199 in the <code>AuthOTPTable</code> is, for this policy, a fatal error and
200 should be handled as such. For this kind of very secure configuration,
201 use this option, in conjunction with the <code>AuthOrder</code>
202 directive, <i>e.g.</i>:
203 <pre>
204 AuthOrder mod_auth_otp.c* ...
205 AuthOTPOptions RequireTableEntry StandardResponse
206 </pre>
207
208 <p>
209 <b>Note</b> that as of ProFTPD 1.3.9rc1, this option is enabled by
210 default. Use the <code>OptionalTableEntry</code> option to enable
211 the "opt in" behavior for supporting transitions.
212 </li>
213 </ul>
214
215 <p>
216 <hr>
217 <h3><a name="AuthOTPTable">AuthOTPTable</a></h3>
218 <strong>Syntax:</strong> AuthOTPTable <em>table-info</em><br>
219 <strong>Default:</strong> None<br>
220 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
221 <strong>Module:</strong> mod_auth_otp<br>
222 <strong>Compatibility:</strong> 1.3.5rc4 and later
223
224 <p>
225 The <code>AuthOTPTable</code> directive configures the information necessary
226 for <code>mod_auth_otp</code> to retrieve the shared key/secret and current
227 counter, on a per-user basis; this directive is <b>required</b> for
228 <code>mod_auth_otp</code> to function. If <code>AuthOTPTable</code> is
229 <b>not configured</b>, <code>mod_auth_otp</code> will refuse to work.
230
231 <p>
232 The <code>mod_auth_otp</code> module currently expects/uses SQL tables for
233 retrieval/storage of its data on a per-user basis. Thus the
234 <code>AuthOTPTable</code> directives requires two separate
235 <code>SQLNamedQuery</code> directives: one for looking up the needed data,
236 the other for updating that data. The <em>table-info</em> parameter
237 encodes these <code>SQLNamedQuery</code> names like so:
238 <pre>
239 SQLNamedQuery get-user-totp SELECT ...
240 SQLNamedQuery update-user-totp UPDATE ...
241
242 AuthOTPTable sql:/get-user-totp/update-user-totp
243 </pre>
244 See the <a href="#Usage">usage</a> section for a more detailed example.
245
246 <p>
247 <hr>
248 <h3><a name="AuthOTPTableLock">AuthOTPTableLock</a></h3>
249 <strong>Syntax:</strong> AuthOTPTableLock <em>path</em><br>
250 <strong>Default:</strong> None<br>
251 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
252 <strong>Module:</strong> mod_auth_otp<br>
253 <strong>Compatibility:</strong> 1.3.5rc4 and later
254
255 <p>
256 The <code>AuthOTPTableLock</code> directive sets the <em>path</em> for a
257 synchronization lockfile which <code>mod_auth_otp</code> needs when updating
258 the <code>AuthOTPTable</code> for <i>e.g.</i> counter-based codes. Use of
259 <code>AuthOTPTableLock</code> is recommended, but not required.
260
261 <p>
262 If <code>AuthOTPTableLock</code> is used, it is <b>strongly advised</b> that
263 the configured <em>path</em> <b>not</b> be on an NFS (or any other network)
264 filesystem.
265
266 <p>
267 <hr>
268 <h2><a name="Usage">Usage</a></h2>
269
270 <p>
271 Note that the following examples assume the existing of an SQL table whose
272 schema looks like the following (using the SQLite schema syntax):
273 <pre>
274 CREATE TABLE auth_otp (
275 user TEXT PRIMARY KEY,
276 secret TEXT,
277 counter INTEGER
278 );
279 </pre>
280
281 The <code>auth_otp.secret</code> column <b>must</b> contain the
282 <b>base32-encoded</b> shared key for the user. Why Base32-encoding? That
283 is what Google Authenticator expects/uses for its shared key storage; its
284 <code>google-authenticator</code> command-line tool generates a Base32-encoded
285 string for entering into the Google Authenticator app on your mobile device.
286
287 <p>
288 To get the base32-encoded shared key using <code>google-authenticator</code>:
289 <pre>
290 $ ./google-authenticator
291 Do you want authentication tokens to be time-based (y/n) y
292 <em>Here you will see generated QR code</em>
293 Your new secret key is: <em>base32-encoded secret here</em>
294 ...
295 </pre>
296
297 <p>
298 <b>Example Time-based (TOTP) Configuration</b><br>
299 <pre>
300 &lt;IfModule mod_auth_otp.c&gt;
301 AuthOTPEngine on
302
303 # Use time-based codes (TOTP)
304 AuthOTPAlgorithm totp
305
306 AuthOTPTable sql:/get-user-totp/update-user-totp
307 &lt;/IfModule&gt;
308
309 &lt;IfModule mod_sql.c&gt;
310 ...
311
312 # Notice that for time-based counters, we do <b>not</b> need to retrieve
313 # the auth_otp.counter column; the counter value is determined from the
314 # system clock.
315 SQLNamedQuery get-user-totp SELECT "secret FROM auth_otp WHERE user = \'%{0}\'"
316 SQLNamedQuery update-user-totp UPDATE "counter = %{1} WHERE user = \'%{0}\'" auth_otp
317 &lt;/IfModule&gt;
318 </pre>
319
320 <p>
321 <b>Example Counter-based (HOTP) Configuration</b><br>
322 <pre>
323 &lt;IfModule mod_auth_otp.c&gt;
324 AuthOTPEngine on
325
326 # Use counter-based codes (HOTP)
327 AuthOTPAlgorithm hotp
328
329 AuthOTPTable sql:/get-user-hotp/update-user-hotp
330 &lt;/IfModule&gt;
331
332 &lt;IfModule mod_sql.c&gt;
333 ...
334 SQLNamedQuery get-user-hotp SELECT "secret, counter FROM auth_otp WHERE user = \'%{0}\'"
335 SQLNamedQuery update-user-hotp UPDATE "counter = %{1} WHERE user = \'%{0}\'" auth_otp
336 &lt;/IfModule&gt;
337 </pre>
338
339 <p>
340 <b>Secure/Paranoid Configurations</b><br>
341 Security-conscious administrators may not want users to notice if/when they
342 have started expecting one-time passwords for their logins; not all users may
343 have been provisioned with the necessary shared key. To prevent
344 <code>mod_auth_otp</code> from "leaking" its presence/usage and instead to
345 continue using the standard FTP response messages, use the following in
346 your configuration for <code>mod_auth_otp</code>:
347 <pre>
348 AuthOTPOptions FTPStandardResponse
349 </pre>
350
351 <p>
352 If, on the other hand, you have successfully provisioned <b>all</b> of your
353 users with OTP shared keys, and now <b>require</b> that all logins use a
354 one-time password (but still want to <b>not</b> leak this information), then
355 you would use:
356 <pre>
357 # Make mod_auth_otp authoritative; if it fails to handle a login attempt,
358 # that login attempt MUST fail.
359 AuthOrder mod_auth_otp.c* ...
360
361 # Use the standard FTP response message, and fail the login if we find
362 # a user that has not been provisioned.
363 AuthOTPOptions FTPStandardResponse RequireTableEntry
364 </pre>
365
366 <p>
367 <b>SFTP/SCP Support</b><br>
368 One-time passwords can also be used for <code>mod_sftp</code> sessions,
369 <i>i.e.</i> for SFTP and SCP clients. The SSH RFCs define any non-standard
370 "password-like" authentication method as "keyboard-interactive". Thus to
371 use <code>mod_auth_otp</code> for your SFTP connections, simply include
372 both <code>mod_sftp</code> and <code>mod_auth_otp</code> in your build. That's
373 it.
374
375 <p>
376 Now, if you want <code>mod_sftp</code> to <b>only</b> try to use one-time
377 passwords (or public keys), and <b>not</b> normal passwords, then you might
378 use a <code>mod_sftp</code> configuration like this:
379 <pre>
380 SFTPAuthMethods publickey password+keyboard-interactive
381 </pre>
382 If you allow the "keyboard-interactive" authentication method by itself,
383 <i>and</i> the user does not have an OTP entry, then that authentication will
384 fail, <b>regardless</b> of any <code>RequireTableEntry</code>
385 <code>AuthOTPOption</code> configuration (or lack of).
386
387 <p>
388 <b>Module Load Order and <code>mod_sftp</code></b><br>
389 In order for <code>mod_auth_otp</code> to work its magic, it <b>must</b>
390 come <b>after</b> the <code>mod_sftp</code> module in the module load order.
391 To do this as a static module, you would use something like this when building
392 proftpd:
393 <pre>
394 $ ./configure --with-modules=...:mod_sftp:mod_auth_otp:...
395 </pre>
396 ensuring that <code>mod_auth_otp</code> comes after <code>mod_sftp</code> in
397 your <code>--with-modules</code> list.
398
399 <p>
400 As a shared module, configuring <code>mod_auth_otp</code> to be after
401 <code>mod_sftp</code> is much easier. Your configuration will have a list
402 of <code>LoadModule</code> directives; make sure <code>mod_auth_otp</code>
403 appears after <code>mod_sftp</code>:
404 <pre>
405 LoadModule mod_sftp.c
406 ...
407 LoadModule mod_auth_otp.c
408 ...
409 </pre>
410 You will know if the module load ordering is wrong if you see the following
411 log message appear in your logs:
412 <pre>
413 proftpd[87129]: mod_auth_otp/0.0: mod_sftp not loaded, skipping keyboard-interactive support
414 </pre>
415
416 <p>
417 <b>Logging</b><br>
418 The <code>mod_auth_otp</code> module supports different forms of logging. The
419 main module logging is done via the <code>AuthOTPLog</code> directive. This
420 log is used for successes/failures. For example, if the user provides an OTP
421 code, but that user is not configured in the <code>AuthOTPTable</code>, you
422 would see a log message such as:
423 <pre>
424 2016-01-18 12:35:46,725 mod_auth_otp/0.2[27192]: user 'foobar' has no OTP info in AuthOTPTable
425 2016-01-18 12:36:47,152 mod_auth_otp/0.2[27192]: FAILED: user 'foobar' provided invalid OTP code
426 </pre>
427 If the user <em>is</em> provisioned in the <code>AuthOTPTable</code>, but the
428 OTP code is invalid, you would see <em>just</em> this message:
429 <pre>
430 2016-01-18 12:40:09,500 mod_auth_otp/0.2[27235]: FAILED: user 'foobar' provided invalid OTP code
431 </pre>
432 And finally, for valid OTP codes, the following is logged:
433 <pre>
434 2016-01-18 12:42:40,115 mod_auth_otp/0.2[27484]: SUCCESS: user 'foobar' provided valid OTP code
435 </pre>
436
437 <p>
438 For debugging purposes, the module also uses
439 <a href="http://www.proftpd.org/docs/howto/Tracing.html">trace logging</a>,
440 via the module-specific channels:
441 <ul>
442 <li>auth_otp
443 </ul>
444 Thus for trace logging, to aid in debugging, you would use the following in
445 your <code>proftpd.conf</code>:
446 <pre>
447 TraceLog /path/to/auth-trace.log
448 Trace auth_otp:20
449 </pre>
450 This trace logging can generate large files; it is intended for debugging
451 use only, and should be removed from any production configuration.
452
453 <p>
454 <b>Suggested Future Features</b><br>
455 The following lists the features I hope to add to <code>mod_auth_otp</code>,
456 according to need, demand, inclination, and time:
457 <ul>
458 <li>Configurable number of digits in the expected code (currently hardcoded as 6)
459 <li>Support "emergency recovery" codes
460 <li>Support resynchronization with clients
461 </ul>
462
463 <p><a name="FAQ">
464 <b>Frequently Asked Questions</b><br>
465
466 <p>
467 <hr>
468 <h2><a name="Installation">Installation</a></h2>
469 The <code>mod_auth_otp</code> module is distributed with ProFTPD. Simply follow
470 the normal steps for using third-party modules in ProFTPD. For including
471 <code>mod_auth_otp</code> as a statically linked module:
472 <pre>
473 $ ./configure --enable-openssl --with-modules=mod_sql:mod_sql_sqlite:mod_auth_otp:...
474 </pre>
475 <b>Note</b> the ordering of modules in the above <code>--with-modules</code>
476 list; <code>mod_sql</code> <b>must</b> precede <code>mod_auth_otp</code>,
477 otherwise you will see errors like this:
478 <pre>
479 mod_auth_otp/0.2: Missing required 'mod_sql.c'; HOTP/TOTP logins will FAIL
480 </pre>
481
482 <p>
483 To build <code>mod_auth_otp</code> as a DSO module:
484 <pre>
485 $ ./configure --enable-dso --enable-openssl --with-shared=mod_auth_otp:...
486 </pre>
487 Then follow the usual steps:
488 <pre>
489 $ make
490 $ make install
491 </pre>
492
493 <p>
494 <hr>
495 <font size=2><b><i>
496 &copy; Copyright 2015-2023 TJ Saunders<br>
497 All Rights Reserved<br>
498 </i></b></font>
499 <hr>
500
501 </body>
502 </html>