Debian Codegraph @

doc/contrib/mod_digest.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>ProFTPD module mod_digest</title>
5 </head>
6
7 <body bgcolor=white>
8
9 <hr>
10 <center>
11 <h2><b>ProFTPD module <code>mod_digest</code></b></h2>
12 </center>
13 <hr><br>
14
15 <p>
16 The <code>mod_digest</code> module offers functionality for calculating the hash
17 (or <em>digest</em>) value of files. This is particularly useful when verifying
18 the integrity of files. This functionality is used by the following custom
19 FTP commands:
20 <ul>
21 <li><code>XCRC</code> (requests CRC32 digest/checksum)
22 <li><code>MD5/XMD5</code> (requests MD5 digest/checksum)
23 <li><code>XSHA</code>/<code>XSHA1</code> (requests SHA1 digest/checksum)
24 <li><code>XSHA256</code> (requests SHA256 digest/checksum)
25 <li><code>XSHA512</code> (requests SHA512 digest/checksum)
26 </ul>
27 In addition, <code>mod_digest</code> supports the more modern <a href="https://tools.ietf.org/html/draft-bryan-ftpext-hash-02"><code>HASH</code></a> command.
28
29 <p>
30 Depending on the file size and the hash function, it takes a fair amount of
31 CPU and IO resources to calculate the result. Therefore decide wisely where
32 to enable the features and set the <a href="#DigestMaxSize">DigestMaxSize</a>
33 configuration directive appropriately.
34
35 <p>
36 This module was compiled and tested against ProFTPD 1.3.3 Installation
37 instructions are discussed <a href="#Installation">here</a>.
38
39 <p>
40 The most current version of <code>mod_digest</code> is distributed with the
41 ProFTPD source code.
42
43 <h2>Author</h2>
44 <p>
45 Please contact TJ Saunders &lt;tj <i>at</i> castaglia.org&gt; with any
46 questions, concerns, or suggestions regarding this module.
47
48 <h2>Thanks</h2>
49 <p>
50 <i>2016-01-09</i>: Thanks to Mathias Berchtold &lt;mb <i>at</i>
51 smartftp.com&gt; for his original <code>mod_digest</code>, upon which this
52 version is based.
53
54 <h2>Directives</h2>
55 <ul>
56 <li><a href="#DigestAlgorithms">DigestAlgorithms</a>
57 <li><a href="#DigestCache">DigestCache</a>
58 <li><a href="#DigestDefaultAlgorithm">DigestDefaultAlgorithm</a>
59 <li><a href="#DigestEnable">DigestEnable</a>
60 <li><a href="#DigestEngine">DigestEngine</a>
61 <li><a href="#DigestMaxSize">DigestMaxSize</a>
62 <li><a href="#DigestOptions">DigestOptions</a>
63 </ul>
64
65 <hr>
66 <h3><a name="DigestAlgorithms">DigestAlgorithms</a></h3>
67 <strong>Syntax:</strong> DigestAlgorithms <em>["crc32"|"md5"|"sha1"|"sha256"|"sha512"|"all"]</em><br>
68 <strong>Default:</strong> DigestAlgorithms all<br>
69 <strong>Context:</strong> server config, &lt;VirtualHost&gt;, &lt;Global&gt;, &lt;Anonymous&gt;<br>
70 <strong>Module:</strong> mod_digest<br>
71 <strong>Compatibility:</strong> 1.3.6rc2 or later
72
73 <p>
74 The <code>DigestAlgorithms</code> directive configures the enabled digest
75 algorithms. If no <code>DigestAlgorithms</code> directive is configured, then
76 <b>all</b> supported digest algorithms are enabled.
77
78 <p>
79 Enabled digest algorithms are announced/discovered via the <code>FEAT</code>
80 response.
81
82 The following algorithms are currently supported by <code>mod_digest</code>:
83 <ul>
84 <li><code>crc32</code> (<i>e.g.</i> for the <code>XCRC</code> command)
85 <li><code>md5</code> (<i>e.g.</i> for the <code>XMD5</code> command)
86 <li><code>sha1</code> (<i>e.g.</i> for the <code>XSHA</code>/<code>XSHA1</code> commands)
87 <li><code>sha256</code> (<i>e.g.</i> for the <code>XSHA256</code> command)
88 <li><code>sha512</code> (<i>e.g.</i> for the <code>XSHA512</code> command)
89 </ul>
90
91 <p>
92 <hr>
93 <h3><a name="DigestCache">DigestCache</a></h3>
94 <strong>Syntax:</strong> DigestCache <em>on|off|"size" count ["maxAge" secs]</em><br>
95 <strong>Default:</strong> DigestCache size 10000 maxAge 30s<br>
96 <strong>Context:</strong> server config, &lt;VirtualHost&gt;, &lt;Global&gt;, &lt;Anonymous&gt;<br>
97 <strong>Module:</strong> mod_digest<br>
98 <strong>Compatibility:</strong> 1.3.6rc2 or later
99
100 <p>
101 The <code>mod_digest</code> module will cache the results of any checksum
102 command, on a per-file basis. This improves performance, and reduces
103 computational overhead. To disable this caching for any reason, use this
104 directive:
105 <pre>
106 # Disable checksum caching
107 DigestCache off
108 </pre>
109 <b>This is not recommended.</b>
110
111 <p>
112 The <code>DigestCache</code> directive can also be used to configure/tune the
113 <em>max-size</em> of the in-memory cache. Note that once the maximum cache
114 size is reached, any checksum FTP commands will be temporarily refused:
115 <pre>
116 # Use a smaller cache size
117 DigestCache size 100
118 </pre>
119 Cached digests will be expired/ignored after 30 seconds, by default. To change
120 the expiration, you would use:
121 <pre>
122 # Retain cached entries longer
123 DigestCache maxAge 60s
124 </pre>
125
126 <p>
127 If <em>on</em> is used, <code>mod_digest</code> will use the default
128 <em>max-size</em> of 10000:
129 <pre>
130 DigestCache on
131 </pre>
132
133 <p>
134 <hr>
135 <h3><a name="DigestDefaultAlgorithm">DigestDefaultAlgorithm</a></h3>
136 <strong>Syntax:</strong> DigestDefaultAlgorithm <em>algo</em><br>
137 <strong>Default:</strong> DigestDefaultAlgorithm sha1<br>
138 <strong>Context:</strong> server config, &lt;VirtualHost&gt;, &lt;Global&gt;<br>
139 <strong>Module:</strong> mod_digest<br>
140 <strong>Compatibility:</strong> 1.3.6rc3 or later
141
142 <p>
143 The default digest algorithm that the <code>mod_digest</code> module uses,
144 for <i>e.g.</i> opportunistic digesting of file transfers, is SHA1. For
145 selecting a different default algorithm, use the
146 <code>DigestDefaultAlgorithm</code> directive:
147 <pre>
148 # Use MD5 rather than SHA1 as the default algorithm
149 DigestDefaultAlgorithm md5
150 </pre>
151
152 <p>
153 <b>Note</b> that the <code>DigestAlgorithms</code> directive takes precedence;
154 if the <code>DigestDefaultAlgorithm</code> is not included in the
155 <code>DigestAlgorithms</code>, the default algorithm setting will be ignored.
156
157 <p>
158 <hr>
159 <h3><a name="DigestEnable">DigestEnable</a></h3>
160 <strong>Syntax:</strong> DigestEnable <em>on|off</em><br>
161 <strong>Default:</strong> Non<br>
162 <strong>Context:</strong> <code>&lt;Directory&gt;</code>, <code>.ftpaccess</code><br>
163 <strong>Module:</strong> mod_digest<br>
164 <strong>Compatibility:</strong> 1.3.6rc2 or later
165
166 <p>
167 The <code>DigestEnable</code> directive can be used to block or prevent
168 checksumming/digests on files in the configured <code>&lt;Directory&gt;</code>.
169 This can be <b>very</b> useful for preventing checksumming of files located
170 on network-mounted filesystems, for example.
171
172 <p>
173 <hr>
174 <h3><a name="DigestEngine">DigestEngine</a></h3>
175 <strong>Syntax:</strong> DigestEngine <em>on|off</em><br>
176 <strong>Default:</strong> DigestEngine on<br>
177 <strong>Context:</strong> server config, &lt;VirtualHost&gt;, &lt;Global&gt;, &lt;Anonymous&gt;<br>
178 <strong>Module:</strong> mod_digest<br>
179 <strong>Compatibility:</strong> 1.3.6rc2 or later
180
181 <p>
182 The <code>DigestEngine</code> directive enables or disables the handling of
183 the checksum-related FTP commands by <code>mod_digest</code>, <i>i.e.</i>:
184 <ul>
185 <li><code>XCRC</code>
186 <li><code>XMD5</code>
187 <li><code>XSHA</code>
188 <li><code>XSHA1</code>
189 <li><code>XSHA256</code>
190 <li><code>XSHA512</code>
191 </ul>
192 If the parameter is <em>off</em>, then these commands will be ignored.
193
194 <p>
195 <hr>
196 <h3><a name="DigestMaxSize">DigestMaxSize</a></h3>
197 <strong>Syntax:</strong> DigestMaxSize <em>number [units]</em><br>
198 <strong>Default:</strong> None<br>
199 <strong>Context:</strong> server config, &lt;VirtualHost&gt;, &lt;Global&gt;, &lt;Anonymous&gt;<br>
200 <strong>Module:</strong> mod_digest<br>
201 <strong>Compatibility:</strong> 1.3.6rc2 or later
202
203 <p>
204 The <code>DigestMaxSize</code> directive configures the maximum number of bytes
205 a single hash command is allowed to read from a file. If the number of bytes
206 to be read from the file is greater than the configured <em>number</em> the
207 server will refuse that command.
208
209 <p>
210 If no <code>DigestMaxSize</code> directive is configured, then there is no
211 limit. It is highly <b>recommended</b> to set an upper limit.
212
213 <p>
214 Example:
215 <pre>
216 # Limit hashing to 1GB of data
217 DigestMaxSize 1 GB
218 </pre>
219
220 <p>
221 <hr>
222 <h3><a name="DigestOptions">DigestOptions</a></h3>
223 <strong>Syntax:</strong> DigestOptions <em>opt1 ...</em><br>
224 <strong>Default:</strong> None<br>
225 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
226 <strong>Module:</strong> mod_digest<br>
227 <strong>Compatibility:</strong> 1.3.6rc2 and later
228
229 <p>
230 The <code>DigestOptions</code> directive is used to configure various optional
231 behavior of <code>mod_digest</code>.
232
233 <p>
234 The currently implemented options are:
235 <ul>
236 <li><code>NoTransferCache</code><br>
237 <p>
238 The <code>mod_digest</code> module will automatically calculate <b>and</b>
239 cache the results of any transferred file, on a per-file basis. This is
240 done assuming that many FTP clients will want to verify the integrity of
241 the file just uploaded/downloaded. This improves performance, and
242 reduces computational overhead. To disable this caching for any reason,
243 use this option. <b>Not recommended.</b>
244
245 <p>
246 <b>Note</b>: The <code>NoTransferCache</code> option is
247 <em>automatically</em> enabled when using ProFTPD versions before
248 1.3.6rc2, due to bugs/missing support in the older versions.
249 </li>
250 </ul>
251
252 <p>
253 <hr>
254 <h2><a name="Installation">Installation</a></h2>
255 The <code>mod_digest</code> module is distributed with ProFTPD. Follow the
256 normal steps for using third-party modules in ProFTPD:
257 <pre>
258 $ ./configure --enable-openssl --with-modules=mod_digest
259 </pre>
260 To build <code>mod_digest</code> as a shared/DSO module:
261 <pre>
262 $ ./configure --enable-dso --enable-openssl --with-shared=mod_digest
263 </pre>
264 Then follow the usual steps:
265 <pre>
266 $ make
267 $ make install
268 </pre>
269
270 <p>
271 Alternatively, if your proftpd was compiled with DSO support, you can
272 use the <code>prxs</code> tool to build <code>mod_digest</code> as a shared
273 module:
274 <pre>
275 $ prxs -c -i -d mod_digest.c
276 </pre>
277
278 <p>
279 <hr>
280 <h2>Usage</h2>
281 Example Configuration
282 <pre>
283 &lt;IfModule mod_digest.c&gt;
284 # Set a limit on file sizes that can be digested
285 DigestMaxSize 1 GB
286 &lt;/IfModule&gt;
287 </pre>
288
289 <p>
290 <b>Recording Uploaded/Downloaded File Checksums</b><br>
291 One particular use case that comes up is whether the <code>mod_digest</code>
292 can be used to record the digests ("checksums") of uploaded/downloaded files
293 in <i>e.g.</i> a SQL database. The answer is "yes", with some caveats.
294
295 <p>
296 First, here is a configuration excerpt showing show such functionality might
297 be implemented, using <code>mod_digest</code> and <code>mod_sql</code>:
298 <pre>
299 &lt;IfModule mod_digest.c&gt;
300 &lt;/IfModule&gt;
301
302 &lt;IfModule mod_sql.c&gt;
303 ...
304 SQLNamedQuery log-file-checksum FREEFORM "INSERT INTO file_checksums (user, file, algo, checksum) VALUES ('%u', '%f', '%{note:mod_digest.algo}', '%{note:mod_digest.digest}')"
305 SQLLog RETR,STOR log-file-checksum
306 ...
307 &lt;/IfModule&gt;
308 </pre>
309 As you can see, this makes use of the <code>%{note:...}</code> syntax of
310 the <code>SQLLog</code> directive; the same syntax <em>also</em> works for
311 <code>LogFormat</code> definitions as well. The <code>mod_digest</code> module
312 uses the following notes:
313 <ul>
314 <li><em>mod_digest.algo</em>
315 <p>
316 Name of the digest algorithm used, <i>e.g.</i> "SHA1".
317 </li>
318
319 <p>
320 <li><em>mod_digest.digest</em>
321 <p>
322 Calculated digest of the file as a hex-encoded lowercase string.
323 </li>
324 </ul>
325
326 <p>
327 Now, the caveats with this technique:
328 <ul>
329 <li>Does <b>not</b> work if the <code>NoTransferCache</code> <a href="#DigestOption">DigestOption</a> is used.
330 <li>Only works for binary, not ASCII, FTP uploads/downloads currently.
331 <li>Only works for uploads (<code>STOR</code>) and downloads (<code>RETR</code>), but not for appends (<code>APPE</code>) <b>or</b> resumed uploads/downloads (<code>REST</code> + <code>RETR/STOR</code>).
332 <li>Does <b>not</b> work for FTP downloads if <code>UseSendfile</code> is in effect.
333 </ul>
334 In addition, the order in which the <code>mod_digest</code> and
335 <code>mod_sql</code> appear in your build command is important;
336 <code>mod_digest</code> <em>must come <b>after</b></em> <code>mod_sql</code>,
337 otherwise the note values will <b>not</b> be populated properly in the
338 <code>SQLLog</code> statement. Thus, if you are building static modules,
339 your <code>--with-modules</code> parameter would look something like:
340 <pre>
341 $ ./configure --with-modules=mod_sql:mod_sql_mysql:mod_digest ...
342 </pre>
343 Or, if you are using shared modules, then your <code>LoadModule</code>
344 directives must look like:
345 <pre>
346 LoadModule mod_sql.c
347 LoadModule mod_sql_mysql.c
348 LoadModule mod_digest.c
349 </pre>
350
351 <!--
352 Why?
353
354 TCP-level checksums
355 packet-level checksums
356 _file_-level checksums (which is really what most people usually have in mind)
357
358 transfers interrupted by timeouts
359
360 SFTP has different ways of achieving this, via extensions (link to mod_sftp
361 docs on extensions)
362
363 validating uploads AND downloads (did I download everything? Did the upload
364 succeed?)
365
366 <p>
367 It's also recommended to disable all features within the &lt;Anonymous&gt; context. How?
368
369 <Anonymous>
370 <IfModule mod_digest.c>
371 DigestEngine off
372 </IfModule>
373 </Anonymous>
374
375 <p>
376 <b>Supported FTP Commands</b><br>
377 cmd path
378 cmd path [end]
379 cmd path [off] [len]
380 <pre>
381 XCRC "/path/to/file with spaces" 0 100
382 </pre>
383 -->
384
385 <p>
386 <hr>
387 <font size=2><b><i>
388 &copy; Copyright 2016 TJ Saunders<br>
389 All Rights Reserved<br>
390 </i></b></font>
391 <hr>
392
393 </body>
394 </html>