Debian Codegraph @

doc/contrib/mod_sql_passwd.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>ProFTPD module mod_sql_passwd</title>
5 </head>
6
7 <body bgcolor=white>
8
9 <hr>
10 <center>
11 <h2><b>ProFTPD module <code>mod_sql_passwd</code></b></h2>
12 </center>
13 <hr><br>
14
15 <p>
16 Many FTP sites use SQL databases for storing user accounts, including the
17 user name and password. And while the <code>mod_sql</code> module provides
18 support for some formats for the passwords stored in SQL databases, many
19 sites have other formats which are <i>not</i> supported by <code>mod_sql</code>.
20 These other formats often include MD5 or SHA1 passwords, base64-encoded
21 or hex-encoded, <i>without</i> the prefix which is required by
22 <code>mod_sql</code>'s "OpenSSL" <code>SQLAuthType</code>.
23
24 <p>
25 The <code>mod_sql_passwd</code> module provides support for some of these
26 other formats. When the <code>mod_sql_passwd</code> module is enabled,
27 you can configure <code>SQLAuthTypes</code> of:
28 <ul>
29 <li>Argon2
30 <li>Bcrypt
31 <li>MD5
32 <li>PBKDF2
33 <li>Scrypt
34 <li>SHA1
35 <li>SHA256
36 <li>SHA512
37 </ul>
38 as well as the existing types supported by <code>mod_sql</code>.
39
40 <p>
41 This module is contained in the <code>mod_sql_passwd.c</code> file for
42 ProFTPD 1.3.<i>x</i>, and is not compiled by default. Installation
43 instructions are discussed <a href="#Installation">here</a>; a discussion
44 on <a href="#Usage">usage</a> is also available.
45
46 <p>
47 This product includes software developed by the OpenSSL Project for use in the
48 OpenSSL Toolkit (http://www.openssl.org/).
49
50 <p>
51 This product includes cryptographic software written by Eric Young
52 ([email protected]).
53
54 <p>
55 The most current version of <code>mod_sql_passwd</code> is distributed with
56 ProFTPD.
57
58 <h2>Author</h2>
59 <p>
60 Please contact TJ Saunders &lt;tj <i>at</i> castaglia.org&gt; with any
61 questions, concerns, or suggestions regarding this module.
62
63 <h2>Directives</h2>
64 <ul>
65 <li><a href="#SQLPasswordArgon2">SQLPasswordArgon2</a>
66 <li><a href="#SQLPasswordCost">SQLPasswordCost</a>
67 <li><a href="#SQLPasswordEncoding">SQLPasswordEncoding</a>
68 <li><a href="#SQLPasswordEngine">SQLPasswordEngine</a>
69 <li><a href="#SQLPasswordOptions">SQLPasswordOptions</a>
70 <li><a href="#SQLPasswordPBKDF2">SQLPasswordPBKDF2</a>
71 <li><a href="#SQLPasswordRounds">SQLPasswordRounds</a>
72 <li><a href="#SQLPasswordSaltEncoding">SQLPasswordSaltEncoding</a>
73 <li><a href="#SQLPasswordSaltFile">SQLPasswordSaltFile</a>
74 <li><a href="#SQLPasswordScrypt">SQLPasswordScrypt</a>
75 <li><a href="#SQLPasswordUserSalt">SQLPasswordUserSalt</a>
76 </ul>
77
78 <hr>
79 <h3><a name="SQLPasswordArgon2">SQLPasswordArgon2</a></h3>
80 <strong>Syntax:</strong> SQLPasswordArgon2 <em>length</em><br>
81 <strong>Default:</strong> <em>32</em><br>
82 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
83 <strong>Module:</strong> mod_sql_passwd<br>
84 <strong>Compatibility:</strong> 1.3.6rc5 and later
85
86 <p>
87 The <code>SQLPasswordArgon2</code> directive configures the <em>length</em>
88 of the calculated Argon2 output hash <em>in bytes</em>. The default length
89 is 32 bytes.
90
91 <hr>
92 <h3><a name="SQLPasswordCost">SQLPasswordCost</a></h3>
93 <strong>Syntax:</strong> SQLPasswordCost <em>interactive|sensitive</em><br>
94 <strong>Default:</strong> <em>interactive</em><br>
95 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
96 <strong>Module:</strong> mod_sql_passwd<br>
97 <strong>Compatibility:</strong> 1.3.6rc3 and later
98
99 <p>
100 The <code>SQLPasswordCost</code> directive configures the high-level
101 <em>cost</em> settings to use for memory-hard algorithms like
102 <code>scrypt</code> and <code>argon2</code>. The supported <em>cost</em>
103 cost values are:
104 <ul>
105 <li>interactive
106 <p>
107 This <em>cost</em> uses parameters where generating the value is part of
108 an "interactive" session.
109
110 <p>
111 For <code>scrypt</code>, depending on the version of <code>libsodium</code>
112 used, this <em>cost</em> uses:
113 <pre>
114 N=16384, r=8, p=1
115 </pre>
116 </li>
117
118 <p>
119 <li>sensitive
120 <p>
121 This <em>cost</em> uses parameters where the value generated is considered
122 very "sensitive".
123
124 <p>
125 For <code>scrypt</code>, depending on the version of <code>libsodium</code>
126 used, this <em>cost</em> uses:
127 <pre>
128 N=1048576, r=8, p=1
129 </pre>
130 </li>
131 </ul>
132
133 <hr>
134 <h3><a name="SQLPasswordEncoding">SQLPasswordEncoding</a></h3>
135 <strong>Syntax:</strong> SQLPasswordEncoding <em>encoding</em><br>
136 <strong>Default:</strong> <em>hex</em><br>
137 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
138 <strong>Module:</strong> mod_sql_passwd<br>
139 <strong>Compatibility:</strong> 1.3.3rc2 and later
140
141 <p>
142 The <code>SQLPasswordEncoding</code> directive configures the encoding that
143 <code>mod_sql_passwd</code> expects when handling password values retrieved
144 from a SQL database.
145
146 <p>
147 The following <em>encoding</em> values are currently supported:
148 <ul>
149 <li>base64
150 <li>hex (<i>for lowercase hex values</i>)
151 <li>HEX (<i>for uppercase hex values</i>)
152 </ul>
153
154 <p>
155 If no <code>SQLPasswordEncoding</code> directive is configured,
156 <code>mod_sql_passwd</code> will use "hex" by default.
157
158 <hr>
159 <h3><a name="SQLPasswordEngine">SQLPasswordEngine</a></h3>
160 <strong>Syntax:</strong> SQLPasswordEngine <em>on|off</em><br>
161 <strong>Default:</strong> <em>off</em><br>
162 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
163 <strong>Module:</strong> mod_sql_passwd<br>
164 <strong>Compatibility:</strong> 1.3.3rc2 and later
165
166 <p>
167 The <code>SQLPasswordEngine</code> directive enables or disables the module's
168 registered <code>SQLAuthType</code> handlers.
169
170 <hr>
171 <h3><a name="SQLPasswordOptions">SQLPasswordOptions</a></h3>
172 <strong>Syntax:</strong> SQLPasswordOptions <em>opts</em><br>
173 <strong>Default:</strong> None<br>
174 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
175 <strong>Module:</strong> mod_sql_passwd<br>
176 <strong>Compatibility:</strong> 1.3.4rc2 and later
177
178 <p>
179 The <code>SQLPasswordOptions</code> directive is used to configure various
180 behaviors of <code>mod_sql_passwd</code>. <b>Note</b>: all of the configured
181 <code>SQLPasswordOptions</code> parameters <b>must</b> appear on the same line
182 in the configuration; only the first <code>SQLPassworOptions</code> directive
183 that appears in the configuration is used.
184
185 <p>
186 Example:
187 <pre>
188 SQLPasswordOptions HashEncodeSalt HashEncodePassword
189 </pre>
190
191 <p>
192 The following <em>options</em> are currently supported:
193 <ul>
194 <li><code>HashPassword</code>
195 <li><code>HashEncodePassword</code>
196 <li><code>HashSalt</code>
197 <li><code>HashEncodeSalt</code>
198 </ul>
199
200 <p>
201 See the <a href="#Transformations">transformations</a> section for a fuller
202 description of how <code>mod_sql_passwd</code> operates on the password and
203 salt data.
204
205 <hr>
206 <h3><a name="SQLPasswordPBKDF2">SQLPasswordPBKDF2</a></h3>
207 <strong>Syntax:</strong> SQLPasswordPBKDF2 <em>digest</em> <em>iterations</em> <em>length</em><br>
208 <strong>Default:</strong> None<br>
209 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
210 <strong>Module:</strong> mod_sql_passwd<br>
211 <strong>Compatibility:</strong> 1.3.5rc3 and later
212
213 <p>
214 The <code>SQLPasswordPBKDF2</code> directive configures the input parameters
215 to be used for <a href="http://en.wikipedia.org/wiki/PBKDF2">PBKDF2</a>
216 (Password-Based Key Derivation Function, version 2) passwords. The
217 <em>digest</em> parameter specifies the digest algorithm to use (<i>e.g.</i>
218 "sha1" or "sha512"); the <em>iterations</em> specifies the number of iterations
219 to use for the key derivation, and <em>length</em> indicates the number of
220 bytes to emit for the derived key.
221
222 <p>
223 <b>Note</b> that PBKDF2 <b>requires</b> that a salt be available, <i>e.g.</i>
224 via <a href="#SQLPasswordSaltFile"><code>SQLPasswordSaltFile</code></a> or
225 <a href="#SQLPasswordUserSalt"><code>SQLPasswordUserSalt</code></a>.
226
227 <p>
228 Per <a href="http://www.faqs.org/rfcs/rfc2898.html">RFC 2898</a>, the salt
229 used should be 8 bytes or longer in length; this RFC also recommends that
230 <em>iterations</em> be 1000 or greater.
231
232 <p>
233 Example:
234 <pre>
235 # Tell mod_sql to use PBKDF2 passwords
236 SQLAuthTypes pbkdf2
237 ...
238
239 # Use the SHA1 digest algorithm, 200K iterations, and expect an output
240 # length of 20 bytes.
241 SQLPasswordPBKDF2 sha1 200000 20
242
243 SQLPasswordSaltFile /path/to/salt/file
244 </pre>
245
246 <p>
247 Use of <em>digest</em> algorithms other than SHA1 for
248 <code>SQLPasswordPBKDF2</code> requires OpenSSL-1.0.0c or later; earlier
249 versions did not have the necessary APIs.
250
251 <p>
252 As of <code>proftpd-1.3.5</code>, the <code>SQLPasswordPBKDF2</code> directive
253 can instead take a named query, for determining the digest algorithm,
254 iteration count, and output length <i>on a per-user basis</i>. For example:
255 <pre>
256 SQLNamedQuery get-user-pbkdf2 SELECT "algo, iter, len FROM user_pbkdf2 WHERE user = '%{0}'
257 SQLPasswordPBKDF2 sql:/get-user-pbkdf2
258 </pre>
259
260 <hr>
261 <h3><a name="SQLPasswordRounds">SQLPasswordRounds</a></h3>
262 <strong>Syntax:</strong> SQLPasswordRounds <em>count</em><br>
263 <strong>Default:</strong> <em>1</em><br>
264 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
265 <strong>Module:</strong> mod_sql_passwd<br>
266 <strong>Compatibility:</strong> 1.3.4rc2 and later
267
268 <p>
269 The <code>SQLPasswordRounds</code> directive configures the number of
270 rounds through which the password (and possibly salt) data will be hashed
271 and encoded. The <em>count</em> parameter must be greater than 1.
272
273 <p>
274 See the <a href="#Transformations">transformations</a> section for a fuller
275 description of how <code>mod_sql_passwd</code> operates on the password and
276 salt data.
277
278 <hr>
279 <h3><a name="SQLPasswordSaltEncoding">SQLPasswordSaltEncoding</a></h3>
280 <strong>Syntax:</strong> SQLPasswordSaltEncoding <em>encoding</em><br>
281 <strong>Default:</strong> <em>none</em><br>
282 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
283 <strong>Module:</strong> mod_sql_passwd<br>
284 <strong>Compatibility:</strong> 1.3.6rc1 and later
285
286 <p>
287 The <code>SQLPasswordSaltEncoding</code> directive configures the encoding that
288 <code>mod_sql_passwd</code> expects when handling <b><i>salt</i></b> values
289 retrieved either from a SQL database, <i>or</i> from a file.
290
291 <p>
292 The following <em>encoding</em> values are currently supported:
293 <ul>
294 <li>base64
295 <li>hex (<i>for lowercase hex values</i>)
296 <li>HEX (<i>for uppercase hex values</i>)
297 <li>none (use salt value as is)
298 </ul>
299
300 <p>
301 If no <code>SQLPasswordSaltEncoding</code> directive is configured,
302 <code>mod_sql_passwd</code> will use "none" by default.
303
304 <hr>
305 <h3><a name="SQLPasswordSaltFile">SQLPasswordSaltFile</a></h3>
306 <strong>Syntax:</strong> SQLPasswordSaltFile <em>path|"none" ["Prepend"|"Append"]</em><br>
307 <strong>Default:</strong> <em>none</em><br>
308 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
309 <strong>Module:</strong> mod_sql_passwd<br>
310 <strong>Compatibility:</strong> 1.3.3rc2 and later
311
312 <p>
313 The <code>SQLPasswordSaltFile</code> directive configures a file which contains
314 salt data. This salt will be added to the digest, along with the password
315 sent by the client. Note that the salt will be used for all users.
316
317 <p>
318 Since many editors will automatically add a newline when writing a file,
319 the <code>mod_sql_passwd</code> file will automatically trim the last newline
320 in the salt data, if there is one. This means that if your salt <b>must</b>
321 end in a newline character, then your <code>SQLPasswordSaltFile</code> must
322 contain "<i>salt</i>\n\n".
323
324 <p>
325 When using salted passwords, some systems will <i>prepend</i> the salt as a
326 prefix to the data, and others will <i>append</i> the salt as a suffix. The
327 optional second parameter to <code>SQLPasswordSaltFile</code> controls how
328 this module will use the salt:
329 <pre>
330 SQLPasswordSaltFile /path/to/salt Prepend
331 </pre>
332 tells <code>mod_sql_passwd</code> to prepend the salt as a prefix, and:
333 <pre>
334 SQLPasswordSaltFile /path/to/salt Append
335 </pre>
336 will cause the salt to be appended as a sufix. <b>Note</b> that the default
337 behavior is to <i>append</i> the salt as a suffix.
338
339 <p>
340 If no <code>SQLPasswordSaltFile</code> is configured, then no salting is done.
341
342 <hr>
343 <h3><a name="SQLPasswordScrypt">SQLPasswordScrypt</a></h3>
344 <strong>Syntax:</strong> SQLPasswordScrypt <em>length</em><br>
345 <strong>Default:</strong> <em>32</em><br>
346 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
347 <strong>Module:</strong> mod_sql_passwd<br>
348 <strong>Compatibility:</strong> 1.3.6rc5 and later
349
350 <p>
351 The <code>SQLPasswordScrypt</code> directive configures the <em>length</em>
352 of the calculated Scrypt output hash <em>in bytes</em>. The default length
353 is 32 bytes.
354
355 <hr>
356 <h3><a name="SQLPasswordUserSalt">SQLPasswordUserSalt</a></h3>
357 <strong>Syntax:</strong> SQLPasswordUserSalt <em>"name"|source ["Prepend"|"Append"]</em><br>
358 <strong>Default:</strong> <em>none</em><br>
359 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
360 <strong>Module:</strong> mod_sql_passwd<br>
361 <strong>Compatibility:</strong> 1.3.3 and later
362
363 <p>
364 The <code>SQLPasswordUserSalt</code> directive configures a per-user
365 salt that will be added to the digest, along with the password sent by the
366 client.
367
368 <p>
369 If <em>"name"</em> is specified, then the per-user salt data will be the
370 name of the user logging in. Alternatively, you can configure a
371 <code>SQLNamedQuery</code> which returns a single column of a single
372 row, containing a string to use as the salt data, <i>e.g.</i>:
373 <pre>
374 SQLNamedQuery get-user-salt SELECT "salt FROM user_salts WHERE user_name = '%{0}'"
375 SQLPasswordUserSalt sql:/get-user-salt
376 </pre>
377
378 <p>
379 When using salted passwords, some systems will <i>prepend</i> the salt as a
380 prefix to the data, and others will <i>append</i> the salt as a suffix. The
381 optional second parameter to <code>SQLPasswordUserSalt</code> controls how
382 this module will use the salt:
383 <pre>
384 SQLPasswordUserSalt name Prepend
385 SQLPasswordUserSalt sql:/get-user-salt Prepend
386 </pre>
387 tells <code>mod_sql_passwd</code> to prepend the salt as a prefix, and:
388 <pre>
389 SQLPasswordUserSalt name Append
390 SQLPasswordUserSalt sql:/get-user-salt Append
391 </pre>
392 will cause the salt to be appended as a sufix. <b>Note</b> that the default
393 behavior is to <i>append</i> the salt as a suffix.
394
395 <hr>
396 <h2><a name="Installation">Installation</a></h2>
397 The <code>mod_sql_passwd</code> module is distributed with ProFTPD. Simply
398 follow the normal steps for using third-party modules in proftpd. The
399 <code>mod_sql_passwd</code> module requires OpenSSL support, so you <b>must</b>
400 use the <code>--enable-openssl</code> configuration option. In addition,
401 if you have the <code>libsodium</code> library installed, simply include the
402 <code>libsodium</code> headers/libraries in the build command to enable
403 additional algorithms.
404
405 <p>
406 <b>NOTE</b>: it is <b>important</b> that <code>mod_sql_passwd</code> appear
407 <i>after</i> <code>mod_sql</code> in your <code>--with-modules</code> configure
408 option:
409 <pre>
410 $ ./configure --enable-openssl --with-modules=mod_sql:mod_sql_passwd ...
411 </pre>
412 To build <code>mod_sql_passwd</code> as a DSO module:
413 <pre>
414 $ ./configure --enable-dso --enable-openssl --with-shared=mod_sql_passwd
415 </pre>
416 Then follow the usual steps:
417 <pre>
418 $ make
419 $ make install
420 </pre>
421
422 <p>
423 For those with an existing ProFTPD installation, you can use the
424 <code>prxs</code> tool to add <code>mod_sql_passwd</code>, as a DSO module, to
425 your existing server:
426 <pre>
427 $ prxs -c -i -d mod_sql_passwd.c
428 </pre>
429
430 <hr>
431 <h2><a name="Usage">Usage</a></h2>
432
433 <p>
434 The following examples demonstrate how the <code>mod_sql_passwd</code> can
435 be used.
436
437 <p>
438 To configure <code>mod_sql_passwd</code> to handle MD5 passwords that are
439 base64-encoded, use:
440 <pre>
441 &lt;IfModule mod_sql_passwd.c&gt;
442 SQLPasswordEngine on
443 SQLPasswordEncoding base64
444 &lt;/IfModule&gt;
445
446 &lt;IfModule mod_sql.c&gt;
447 ...
448
449 # Now that mod_sql_passwd is used, we can configure "MD5" as an
450 # SQLAuthType that mod_sql will handle.
451 SQLAuthTypes MD5
452 &lt;/IfModule&gt;
453 </pre>
454
455 <p>
456 To have <code>mod_sql_passwd</code> to handle hex-encoded (<i>and</i> in
457 lowercase) passwords, use:
458 <pre>
459 &lt;IfModule mod_sql_passwd.c&gt;
460 SQLPasswordEngine on
461 SQLPasswordEncoding hex
462 &lt;/IfModule&gt;
463 </pre>
464
465 <p>
466 And if for some reason your database values are stored as hex values in
467 uppercase, you would use:
468 <pre>
469 &lt;IfModule mod_sql_passwd.c&gt;
470 SQLPasswordEngine on
471 SQLPasswordEncoding HEX
472 &lt;/IfModule&gt;
473 </pre>
474
475 <p>
476 To use salted passwords, write the salt to use into a file, and configure
477 the <code>mod_sql_passwd</code> module to use it:
478 <pre>
479 &lt;IfModule mod_sql_passwd.c&gt;
480 SQLPasswordEngine on
481 SQLPasswordEncoding hex
482 SQLPasswordSaltFile /path/to/salt
483 &lt;/IfModule&gt;
484 </pre>
485
486 <p><a name="SQLPasswordSodium">
487 <b>Argon2, Scrypt</b><br>
488 When <code>mod_sql_passwd</code> is compiled/linked with the <a href="https://github.com/jedisct1/libsodium"><code>libsodium</code></a> library, then the
489 Argon2 and Scrypt algorithms become available for use:
490 <pre>
491 &lt;IfModule mod_sql_passwd.c&gt;
492 SQLPasswordEngine on
493 SQLPasswordEncoding hex
494 SQLPasswordSaltFile /path/to/salt
495 &lt;/IfModule&gt;
496
497 &lt;IfModule mod_sql.c&gt;
498 ...
499
500 # Now that mod_sql_passwd is used, we can configure "SCRYPT" as an
501 # SQLAuthType that mod_sql will handle.
502 SQLAuthTypes SCRYPT
503 &lt;/IfModule&gt;
504 </pre>
505
506 <p>
507 The <code>scrypt</code> algorithm <b>requires</b> 32 bytes of salt data;
508 lack of salt, or salt of the wrong amount, will result in authentication
509 failure. The <code>argon2</code> algorithm <b>requires</b> 16 bytes of salt
510 data; lack of salt or the wrong amount will result in failure.
511
512 <p>
513 The <code>argon2</code> algorithm requires <code>libsodium-1.0.9</code> or
514 later.
515
516 <p>
517 <b>Logging</b><br>
518 The <code>mod_sql_passwd</code> module supports <a href="../howto/Tracing.html">trace logging</a>, via the module-specific log
519 channels:
520 <ul>
521 <li>sql.passwd
522 </ul>
523 Thus for trace logging, to aid in debugging, you would use the following in
524 your <code>proftpd.conf</code>:
525 <pre>
526 TraceLog /path/to/ftpd/trace.log
527 Trace sql.passwd:20
528 </pre>
529 This trace logging can generate large files; it is intended for debugging use
530 only, and should be removed from any production configuration.
531
532 <p><a name="Transformations">
533 <b>Processing of Password and Salt Data</b><br>
534 The logical description of the processing that <code>mod_sql_passwd</code>
535 does can be expressed as:
536 <pre>
537 ENCODE(HASH(<i>data</i>))
538 </pre>
539 where <em>data</em> is comprised of the password, and possibly a salt. The
540 function <code>ENCODE()</code> is determined by
541 <a href="#SQLPasswordEncoding"><code>SQLPasswordEncoding</code></a>, and
542 the function <code>HASH()</code> by <code>SQLAuthTypes</code>.
543
544 <p>
545 Thus if we use a configuration like:
546 <pre>
547 SQLAuthTypes MD5
548 SQLPasswordEncoding hex
549 </pre>
550 Then <code>mod_sql_passwd</code> performs the following processing:
551 <pre>
552 hex(MD5(<i>data</i>))
553 </pre>
554 in order to calculate the value that it will compare against the password
555 value stored for the authenticating client.
556
557 <p>
558 <b><i>Using Salts</i></b><br>
559 By default, the <code>mod_sql_passwd</code> module uses the password, as
560 sent by the client, as the <i>data</i> on which to perform its processing.
561 In many cases, however, a <a href="http://en.wikipedia.org/wiki/Salt_(cryptography)"><i>salt</i></a> is needed in addition to the password. The
562 <a href="#SQLPasswordSaltFile"><code>SQLPasswordSaltFile</code></a> and
563 <a href="#SQLPasswordUserSalt"><code>SQLPasswordUserSalt</code></a> directives
564 are used to tell <code>mod_sql_passwd</code> that it should add a <i>salt</i>
565 to the data before processing it. These directives also specify whether the
566 salt should be <i>prepended</i> to the password, <i>e.g.</i>:
567 <pre>
568 <i>data</i> = <i>salt</i> + <i>password</i>
569 </pre>
570 or <i>appended</i> to the password, <i>e.g.</i>:
571 <pre>
572 <i>data</i> = <i>password</i> + <i>salt</i>
573 </pre>
574
575 <p>
576 Let's show a configuration which uses a prepended salt:
577 <pre>
578 SQLAuthTypes MD5
579 SQLPasswordEncoding hex
580 SQLPasswordSaltFile /path/to/salt.data Prepend
581 </pre>
582 This means that <code>mod_sql_passwd</code> would end up checking the
583 following computed value against the value in the database:
584 <pre>
585 hex(MD5(<i>salt</i> + <i>password</i>))
586 </pre>
587
588 <p>
589 Some sites will have even more complex requirements for how the <i>data</i>
590 processed by <code>mod_sql_passwd</code> need to be constructed. The salt
591 data may need to be hashed before being used with the password, or may need
592 to be hashed <i>and</i> encoded before use. Or maybe the password data needs
593 to be hashed before use with the salt, or hashed <i>and</i> encoded.
594 The <a href="#SQLPasswordOptions"><code>SQLPasswordOptions</code></a> directive
595 supports options for supporting these use cases.
596
597 <p>
598 Each of the following examples assumes the following configuration:
599 <pre>
600 SQLAuthTypes MD5
601 SQLPasswordEncoding hex
602 SQLPasswordSaltFile /path/to/salt.data Prepend
603 </pre>
604 Let's look at each of the <code>SQLPasswordOptions</code> in turn:
605 <ul>
606 <li><code>HashPassword</code>
607 <p>
608 This option says that <code>mod_sql_passwd</code> should use the
609 <code>HASH()</code> function on the password data before using it,
610 regardless of whether a salt is used or not. <i>I.e.</i>:
611 <pre>
612 <i>data</i> = <i>salt</i> + HASH(<i>password</i>)
613 </pre>
614 which assuming hex and MD5, means:
615 <pre>
616 <i>data</i> = <i>salt</i> + MD5(<i>password</i>)
617 </pre>
618 </li>
619
620 <p>
621 <li><code>HashSalt</code>
622 <p>
623 This option says that <code>mod_sql_passwd</code> should use the
624 <code>HASH()</code> function on the salt data before using it.
625 If no salt is used, this option is silently ignored. Thus:
626 <pre>
627 <i>data</i> = HASH(<i>salt</i>) + <i>password</i>
628 </pre>
629 which assuming hex and MD5, means:
630 <pre>
631 <i>data</i> = MD5(<i>salt</i>) + <i>password</i>
632 </pre>
633 </li>
634
635 <p>
636 <li><code>HashEncodePassword</code>
637 <p>
638 This option says that <code>mod_sql_passwd</code> should use the
639 <code>HASH()</code> function and then the <code>ENCODE()</code> function
640 on the password data before using it. This option is <i>only</i>
641 useful when salts are also used. Thus:
642 <pre>
643 <i>data</i> = <i>salt</i> + ENCODE(HASH(<i>password</i>))
644 </pre>
645 which assuming hex and MD5, means:
646 <pre>
647 <i>data</i> = <i>salt</i> + hex(MD5(<i>password</i>))
648 </pre>
649 <b>Note</b>: If no salt is present, this option will be ignored. Without
650 a salt, this option is equivalent to adding another round of transformation,
651 which is not an obvious side effect.
652 </li>
653
654 <p>
655 <li><code>HashEncodeSalt</code>
656 <p>
657 This option says that <code>mod_sql_passwd</code> should use the
658 <code>HASH()</code> function and then the <code>ENCODE()</code> function
659 on the salt data before using it. If no salt is used, this option is
660 silently ignored. Thus:
661 <pre>
662 <i>data</i> = ENCODE(HASH(<i>salt</i>)) + <i>password</i>
663 </pre>
664 which assuming hex and MD5, means:
665 <pre>
666 <i>data</i> = hex(MD5(<i>salt</i>)) + <i>password</i>
667 </pre>
668 </li>
669 </ul>
670
671 <p>
672 Of course, these various options can be combined:
673 <pre>
674 SQLPasswordOptions HashEncodePassword HashEncodeSalt
675 </pre>
676 which would cause the data on which <code>mod_sql_passwd</code> operates to
677 be constructed like so:
678 <pre>
679 <i>data</i> = ENCODE(HASH(<i>salt</i>)) + ENCODE(HASH(<i>password</i>))
680 <i>data</i> = hex(MD5(<i>salt</i>)) + hex(MD5(<i>password</i>))
681 </pre>
682
683 <p>
684 <b><i>Rounds</i></b><br>
685 For convenience, let's assume that the function <code>TRANSFORM</code>
686 encompasses the entire <code>ENCODE(HASH())</code> operation:
687 <pre>
688 TRANSFORM(<i>data</i>) = ENCODE(HASH(<i>data</i>))
689 </pre>
690 Let's also assume that passwords are stored in your database using something
691 like this:
692 <pre>
693 hex(MD5(hex(MD5(hex(MD5(<i>data</i>))))))
694 </pre>
695 That means that the <i>data</i> value has gone through multiple <i>rounds</i>
696 of the <code>TRANSFORM</code> function, <i>e.g.</i>:
697 <pre>
698 TRANSFORM(TRANSFORM(TRANSFORM(<i>data</i>)))
699 </pre>
700 In this case, there are 3 rounds of transformation:
701 <pre>
702 for (<i>i</i> = 0; <i>i</i> &lt; <i>nrounds</i>; <i>i</i>++) {
703 <i>data</i> = TRANSFORM(<i>data</i>)
704 }
705 </pre>
706
707 <p>
708 Using the above example case, you would configure <code>mod_sql_passwd</code>
709 to perform multiple rounds of transformation using the
710 <a href="#SQLPasswordRounds"><code>SQLPasswordRounds</code></a> directive,
711 like so:
712 <pre>
713 SQLAuthTypes MD5
714 SQLPasswordEncoding hex
715 SQLPasswordRounds 3
716 </pre>
717 The combination of <code>SQLPasswordOptions</code> and
718 <code>SQLPasswordRounds</code> means that quite few combinations of password
719 values can be supported by the <code>mod_sql_passwd</code> module.
720
721 <p>
722 <hr>
723 <font size=2><b><i>
724 &copy; Copyright 2009-2019 TJ Saunders<br>
725 All Rights Reserved<br>
726 </i></b></font>
727 <hr>
728
729 </body>
730 </html>