Debian Codegraph @

hashcash.pod

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 =head1 NAME
2
3 hashcash - hashcash anti-spam / denial of service counter-measure tool
4
5 =head1 SYNOPSIS
6
7 =head2 Mint (create) stamps:
8
9 B<hashcash> I<-m> [ [ I<options> ] [ I<resource> ... ] ... ]
10
11 =head2 Check stamps:
12
13 B<hashcash> I<-c> [ [ I<options> ] I<-r resource> ... ] [ I<stamp> ... ]
14
15 =head2 Speed estimates:
16
17 B<hashcash> I<-s> [ I<options> ] [ I<-b bits> ]
18
19 =head2 Purge database:
20
21 B<hashcash> I<-p now> [ I<-j resource> ] [ I<-k> ] [ I<-t time> ] [ I<-u> ]
22
23 =head2 Count partial preimage bits:
24
25 B<hashcash> I<-w> [ I<options> ] [ I<stamp> ... ]
26
27 =head2 Get resource name:
28
29 B<hashcash> I<-n> [ I<options> ] [ I<stamp> ... ]
30
31 =head2 Get time remaining until expiry
32
33 B<hashcash> I<-l> [ I<options> ] I<-e period> [ I<stamp> ... ]
34
35 =head1 DESCRIPTION
36
37 Hashcash is a denial-of-service counter measure tool. Its main
38 current use is to help hashcash users avoid losing email due to
39 content based and blacklist based anti-spam systems.
40
41 The hashcash tool allows you to create hashcash stamps to attach to
42 emails you send, and to verify hashcash stamps attached to emails you
43 receive. Email senders attach hashcash stamps with the X-Hashcash:
44 header. Vendors and authors of anti-spam tools are encouraged to
45 exempt mail sent with hashcash from their blacklists and content based
46 filtering rules.
47
48 A hashcash stamp constitutes a proof-of-work which takes a
49 parameterizable amount of work to compute for the sender. The
50 recipient can verify received stamps efficiently. This package also
51 includes a sha1 implementation which is equivalent in functionality to
52 the sha1sum program available on some systems.
53
54 The hashcash proof-of-work function is to compute partial hash
55 preimages (the SHA1 hash function is used). By choosing the number of
56 bits of the preimage that are equal to 0, the work required to compute
57 a partial preimage can be made arbitrarily expensive -- from fractions
58 of a second to minutes or hours. The verification is efficient
59 requiring the same small cost whatever the preimage size.
60
61 For more detailed discussion of other applications hashcash has been
62 used for see http://www.hashcash.org/
63
64 =head1 USAGE NOTES
65
66 In this man page a resource name is the name of the service or address
67 the stamp is created for. In the case of email, the resource name is
68 the recipient's email address in the form [email protected].
69
70 =head2 Minting stamps
71
72 The I<-m> flag must be given to mint a stamp.
73
74 The resource name (recipient's email address) to mint the stamp
75 against can be passed as an argument, or if omitted is read from
76 stdin. If stdin is a tty the user is prompted, if stdin is a pipe the
77 resource name is just silently read. The desired preimage size can
78 be specified with the -b option. If no preimage size is specified,
79 the default is 20 bits. See also the I<-b default> option.
80
81 =head2 Checking stamps
82
83 The I<-c> flag must be given to check a stamps expiry. The stamp to
84 check can be given as an argument to C<hashcash>. If no stamp is
85 given the stamp is read from stdin. If stdin is a tty the user will
86 be prompted, if stdin is a pipe the stamp is just silently read. A
87 resource name (the recipient's email address) can be given with the
88 I<-r> option. If a resource name is given the resource name is
89 compared to the resource name in the stamp, if they do not match, the
90 stamp is rejected.
91
92 Note: if no resource name is given the stamp is anyway checked to see
93 if it is otherwise valid, but it could be minted for a different
94 resource, which would allow stamps to be reused across different
95 resources, so hashcash will return unchecked exit code on exit.
96
97 Stamps are by default considered to be valid for 28 days. The validity
98 period can be changed using the I<-e> flag.
99
100 If the stamp has expired or has a date in the future the stamp is
101 rejected and the program exits immediately.
102
103 If a required preimage size is given with the I<-b> flag, the stamps value
104 is computed and compared, if the stamp has insufficent value it is rejected,
105 and the program exits immediately. If the I<-b> flag is not given, the
106 stamp is checked to see if it is otherwise valid, but hashcash will return
107 unchecked exit code on exit.
108
109 If the stamp is double spent the stamp is rejected. Double spending
110 protection is discussed in more detail below in
111 L<Double Spending Protection>. If double spending protection is not
112 enabled, the stamp could be double spent, so hashcash will return
113 unchecked exit code (exit code 2) on exit.
114
115 The I<-w> flag can be used to request that the number of bits of the
116 preimage are counted and displayed. The I<-n> flag can be used to
117 request that the resource name in the stamp is parsed out and
118 displayed. The I<-l> flag can be used to request the number of
119 seconds until expiry of the stamp is output.
120
121 The program will only return exit codes valid or invalid if the I<-c>
122 flag is used, the I<-b> flag is used, I<-d>, I<-r resource> are used.
123 These are the minimum set of options necessary to fully check the
124 validty of a stamp. If these criteria are not met, the program will
125 return exit code unchecked (exit code 2) on exit. (See also the I<-y>
126 flag.)
127
128 =head2 Double Spending Protection
129
130 If the I<-d> flag is used when checking stamps, a database of spent
131 stamps is kept.
132
133 By default stamps expire after 28 days, without expiry the database
134 would grow indefinately. You can specify an alternate expiry period
135 with the I<-e> flag. The recommended (and default) expiry period for
136 email is 28 days. After the expiry period amount of time, the stamp
137 is anyway considered expired and may be purged from the database to
138 save space. (See L<Purging Periodically vs on Next Access> for how to
139 purge stamps.)
140
141 For efficiency reasons a stamp is verified before it is checked in the
142 database; if it is otherwise invalid no database activity will occur.
143
144 Note: The decision about how long the stamp should be considered valid
145 is up to the verifier. If it is too short it is possible for some
146 applications that the stamp will expire before arriving at the
147 recipient (eg with email.) The suggested value of 28 days should be
148 safe for normal email delivery delays. The choice is a trade-off
149 between database size and risk of expiry prior to arrival, and depends
150 on the application.
151
152 Note: Different stamps in the same database can have different
153 validity periods, so for example stamps for different resources with
154 different validity periods can be stored in the same database, or the
155 recipient may change the validity period for future stamps without
156 affecting the validity of old stamps.
157
158 =head2 Purging Periodically vs on Next Access
159
160 To purge old stamps periodically while checking stamps use the I<-p
161 period> option to purge no sooner than the given time period since the
162 last purge. Purging can be used with the I<-k> option to purge
163 unexpired stamps also, and with the I<-j resource> flag to purge only
164 stamps for the given resource.
165
166 There are circumstances where it may be inconvenient to purge stamps
167 on the next access, for example if there is a large double spend
168 database which takes some time to purge, and the response time of the
169 hashcash checker is important. To avoid this problem, purging can be
170 done separately using just the I<-p now> option to request just the
171 purge operation. On unix for example you could call C<hashcash -p
172 now> in a cron job once per day, or on demand when disk was running
173 low.
174
175 =head2 Speed Estimates
176
177 The I<-s> flag requests measurement of how many preimage can be
178 tested per second. No stamp is minted, or verified.
179
180 If the I<-b> flag is used with this option, instead an estimate of how
181 many seconds it would take to mint a stamp of the given size in bits
182 is computed. To find out how much time it will take to mint a default
183 sized stamp use I<-s -b default>.
184
185 =head2 Notes
186
187 All informational output is printed on stderr. Minted stamps, and
188 results of stamp verification and timing are printed on stdout. The
189 quiet flag I<-q> suppresses all informational output. The I<-v> flag
190 requests more informational output. The requested output, which is
191 the only information that is output in quiet mode (when I<-q> is
192 specified) is printed on standard output. If stdout is a pipe, or
193 when quiet mode is in effect the output is printed without description
194 (ie just bits, just seconds, just resource).
195
196 =head1 OPTIONS
197
198 =over 4
199
200 =item I<-c>
201
202 Check the expiry information of stamps given as an argument or on
203 stdin. (Use with I<-b>, I<-d> and I<-r resource> to fully check
204 stamps).
205
206 =item I<-m>
207
208 Mint stamps with the resources given as arguments or on stdin.
209
210 =item I<-b bits>
211
212 When minting a stamp, create a preimage of at least this many bits.
213 When verifying a stamp require that it have a preimage of at minimum
214 this many bits, otherwise reject it. If omitted the default is used.
215
216 When checking stamps, require that the stamps have this many bits.
217
218 The default number of bits can be specified with I<-b default>. Bits
219 relative to the default can also be specified with I<-b +n> for n bits
220 more than the default and I<-b -n> for n bits less than the default.
221
222 I<-b default>, I<-b +0> and I<-b -0> are all equivalent.
223
224 When doing the speed test I<-s>, can to measure speed of default
225 token with I<-s -b default>.
226
227 =item I<-r resource>
228
229 When minting stamps, the resource name (recipient's email address) to
230 mint the stamp against can be given either with I<-r resource> or as
231 an argument to C<hashcash>.
232
233 When checking stamps, the resource name (your own email address) is
234 given with the I<-r> option. If the resource name is given it is
235 checked against the resource name in the stamp, and if they do not
236 match the stamp is rejected. Note if the resource name is not given,
237 stamps for other resources would be accepted, and therefore hashcash
238 returns exit code unchecked (exit code 2) on exit.
239
240 =item I<-o>
241
242 When verifying stamps multiple resources can be given. By default the
243 resources are just checked one by one until a matching valid resource is
244 found. However when you use wildcards or regular expressions (see I<-E>),
245 it is useful to be able to specify that one resource overrides another. For
246 example this: I<-b15 -r [email protected] -o -b10 *@dev.null> states that mail
247 to address I<[email protected]> requires 15 bits, but mail to I<*@dev.null>
248 requires only 10 bits. If we omitted the I<-o> override relationship
249 between the two resources, a stamp of 10 bits would be accepted for address
250 I<[email protected]> because while it would be rejected as having insufficient
251 bits under the first rule, it would be accepted under the 2nd rule. The
252 I<-o> option allows you avoid this problem.
253
254 =item I<-e time>
255
256 Expiry period for spent stamps. While checking stamps (using the I<-c>
257 flag), if the stamp was minted more than the specified amount of time ago,
258 it is considered expired. If this option is not used, by default stamps
259 expire after 28 days. The expiry period is given in seconds by default (an
260 argument of 0 means forever). A single character suffix can be used to
261 specify alternate units (m = minutes, h = hours, d = days, M = months, y = Y
262 = years, and s = seconds).
263
264 If used with the I<-d> option, the spent stamp and its expiry period
265 is recorded in the database. See the I<-p> option for description of
266 how to purge stamps from the database.
267
268 While minting stamps, the I<-e> flag can have an effect on the
269 resolution of time created in the stamp. Without the I<-e> option,
270 the default resolution is days (time format: YYMMDD). Alternate
271 formats based on range of expiry period are as follows:
272
273 While minting you can also given an explicit time width with the I<-z>
274 option instead. (I<-z> overrides I<-e> if both are given. If neither
275 are given the default is 6 chars (time format: YYMMDD)).
276
277 The rules for automatically determining appropriate time width from
278 I<-e> if no I<-z> option is given are:
279
280 =over 8
281
282 =item * period E<gt>= 2 years then time format YY is used rounded down
283 to the nearest year start;
284
285 =item * 2 years E<lt> period E<lt>= 2 months then time format YYMM is
286 used rounded down to the nearest month start;
287
288 =item * 2 months E<lt> period E<lt>= 2 days then time format YYMMDD is
289 used rounded down to the begining of the nearest day;
290
291 =item * 2 days E<lt> period E<lt>= 2 minutes then time format
292 YYMMDDhhmm is used rounded down to the begining of the nearest minute;
293
294 =item * period E<lt> 2 minutes then time format YYMMDDhhmmss is used in
295 seconds.
296
297 =back
298
299 Note the rounding down is based on UTC time, not local time. This can
300 lead to initially suprising results when rounding down to eg days in
301 time zones other than GMT (UTC = GMT). It may be clearer to
302 understand if you use the I<-u> option.
303
304 =item I<-z width>
305
306 The I<-z> option is for use during minting and allows user choice of
307 width of time width field. See also the I<-e> option given in
308 combination with I<-m> to specify an implicit time field width under
309 the description of the I<-e> flag. Valid widths are 6,10 or 12 chars
310 corresponding respectively to: YYMMDD, YYMMDDhhmm, and YYMMDDhhmmss
311 rounded down to the nearest day, or minute respectively.
312
313 Note the rounding down is based on UTC time, not local time. This can
314 lead to initially suprising results when rounding down to eg days in
315 time zones other than GMT (UTC = GMT). It may be clearer to
316 understand if you use the I<-u> option.
317
318 =item I<-g period>
319
320 The I<-g> option is for use when checking hashcash stamps with the
321 I<-c> option and specifies a grace period for clock skew, ie if a
322 hashcash stamp arrives with a date in the future or in the past it
323 will not be rejected as having a futuristic date (or as being expired)
324 unless it is more futuristic (or has been expired for longer) than
325 this period. The default is 2 days, which means as long as the
326 sending system's clock is no more than 2 days ahead (or 2 days behind)
327 of the receiving system's clock, the hashcash stamp will still be
328 accepted.
329
330 The default units for grace period are seconds. A single character
331 suffix can be used to specify alternate units (m = minutes, h = hours,
332 d = days, M = months, y = Y = years, and s = seconds).
333
334 =item I<-d>
335
336 Store stamps in a double spend database. If stamp has been seen
337 before it will be rejected even if it is otherwise valid. The default
338 database file is F<database.sdb> in the current directory. Only
339 otherwise valid stamps will be stored in the database. Only fully
340 validated stamps will be stored in the database, unless the I<-y>
341 option is given.
342
343 =item I<-f dbname>
344
345 Use F<dbname> instead of default filename for double spend database.
346
347 =item I<-p period>
348
349 Purges the database of expired stamps if the given time period has
350 passed since the last time it was purged. As a convenience I<-p now>
351 is equivalent to I<-p 0> both of which mean purge now, regardless of
352 when the database was last purged.
353
354 If used in combination with I<-j resource> only the stamps minted for
355 the given resource are purged.
356
357 If used in combination with I<-k> all stamps even un-expired stamps
358 are purged. Can be used in combination with I<-t time> to expire as
359 if the current time were the given time.
360
361 =item I<-k>
362
363 Use with option I<-p> to request all stamps are purged rather than
364 just expired ones.
365
366 =item I<-j resource>
367
368 Use with option I<-p> to request that just stamps matching the given
369 resource name are to be purged, rather than the default which is to
370 purge all expired stamps. If the resource name is the empty string,
371 all stamps are matched (this is equivalent to omitting the I<-j>
372 option).
373
374 Note the I<-E>, I<-M> and I<-S> type of match flags also apply to
375 resources given with the I<-j resource> flag.
376
377 =item I<-s>
378
379 Print timing information only, and don't proceed to create a stamp.
380 If combined with I<-b bits> flag print estimate of how long the
381 requested preimage size would take to compute, if I<-s> given by
382 itself, just prints speed of the preimage finder. To print an
383 estimate of how long the default number of bits would take use I<-b
384 default>.
385
386 =item I<-h>
387
388 Print short usage information.
389
390 =item I<-v>
391
392 Print more verbose informational output about the stamp minting or
393 verification. (If -v is the only argument, prints the tool version
394 number.)
395
396 =item I<-V>
397
398 Prints tool version number.
399
400 =item I<-q>
401
402 Batch mode. Prints no information other than output. This option
403 overrides the I<-v> option.
404
405 =item I<-X>
406
407 When minting, prints the hashcash email X-header 'X-Hashcash: ' before
408 the stamp. Without this option just the bare stamp is printed.
409
410 When checking, after scanning stamps given as arguments, scans stdin
411 for lines starting with the string 'X-Hashcash:', and uses the rest of
412 the matching line as the stamp. Only the lines up to and ending at
413 the first blank line are scanned (see also I<-i> flag which can be
414 used to override this). A blank line is the separator used to
415 separate the headers from the body of a mail message or USENET
416 article. This is meant to make it convenient to pipe a mail message
417 or USENET article to hashcash on stdin.
418
419 =item I<-x extension>
420
421 An extension string composed of name value sets. The extension format
422 is described below in the section on the hashcash stamp format. This
423 allows users to define their own stamp extensions which are hashed
424 into the stamp, verified by recipients that support them, and ignored
425 by recipients that don't support them. Note the extension hook
426 mechanism has not yet been implemented. This will come in a
427 subsequent release.
428
429 =item I<-i>
430
431 When checking and using the I<-X> flag, ignore the blank line
432 boundary between headers and body of the message, and check for
433 stamps in the body too if one is not found in the headers.
434
435 =item I<-t time>
436
437 Pretend the current time is the time given for purposes of minting
438 stamps, verifying stamps and purging old stamps from the database.
439 Time is given in a format based on UTCTIME format
440 YYMMDD[hhmm[ss]].
441
442 Time is expressed in local time by default. Use with I<-u> flag to
443 give time in UTC (GMT).
444
445 You can also give time relative to the current time by prefixing the
446 argument with + or -. The default units for relative time are
447 seconds. A single character suffix can be used to specify alternate
448 units (m = minutes, h = hours, d = days, M = months, y = Y = years,
449 and s = seconds).
450
451 Note: when time is expressed in local time, if there is daylight
452 savings in your timezone, there are one or two ambiguous hours per
453 year at the time of change from daylight savings time to normal time.
454
455 =item I<-u>
456
457 Input and output absolute times in UTC (GMT) instead of local time.
458
459 =item I<-a period>
460
461 Add (or subtract if number is negative) a random value from the
462 current time before minting the stamp. This hides the time the stamp
463 was created, which may be useful for anonymous users. Note adding
464 (rather than subtracting) a random time may be risky if the stamp
465 takes less than the added time to arrive as the recipient will reject
466 stamps with time stamps in the future.
467
468 =item I<-n>
469
470 Print resource name parsed from stamp being verified. Returns exit
471 code unchecked on exit.
472
473 =item I<-l>
474
475 Print number of seconds left before stamp expires. Returns exit code
476 unchecked on exit.
477
478 Note: the calculation includes the grace period, so can be up to 2
479 times grace period longer than you might otherwise expect (clock fast
480 but system has to presume it could be slow). If you want to exclude
481 the grace period add I<-g0> to set grace period to 0 for the
482 calculation.
483
484 =item I<-w>
485
486 Print number of bits of preimage of stamp. Returns exit code
487 unchecked on exit.
488
489 =item I<-y>
490
491 Returns success if the stamp is valid even if it is not fully checked.
492 Use with I<-c> where not all of I<-d>, I<-r> are specified to get
493 success exit code on valid but partially checked stamp. Similarly can
494 use with I<-n>, I<-l>, I<-w> with same effect.
495
496 =item I<-M>
497
498 When checking stamps, allow wildcard I<*> matching in the resource
499 name to make it simpler to specify multiple email addresses and to
500 allow matching catch-all addresses and addresses including subdomains.
501 This is the default. See also I<-S>, I<-E> and I<-C>
502
503 =item I<-S>
504
505 When checking stamps use simple text compare to compare resource names
506 to those in stamps. See also I<-M>, I<-E> and I<-C>.
507
508 =item I<-E>
509
510 When checking stamps use regular expressions to specify resource names
511 to make it simpler to specify multiple email addresses, catch-all
512 addresses, classes of extension addresses and addresses including
513 subdomains. Note regular expression syntax is POSIX style: special
514 characters do not need to be quoted to have their special meaning; but
515 they do have to be quoted with \ to that character in the searched
516 string. The regular expression automatically has ^ added at the
517 beginning and $ added at the end, if they are not specified. The
518 special characters ^ matches the beginning of the resouce, and $
519 matches the end of resource.
520
521 (Note even if compiled with BSD regular expressions, POSIX style
522 syntax is used; also note BSD regular expressions do not support
523 ranges {}.)
524
525 =item I<-C>
526
527 By default resources are canonicalized to lower case on minting and on
528 checking. The I<-C> flag overrides this so that resources are treated
529 as case sensitive on checking, and not canonizalized on minting.
530
531 =item I<-P>
532
533 Print progress info (number of iterations, expected iterations,
534 percentage done, best stamp size found so far).
535
536 =item I<-O core>
537
538 Select hashcash core with that number. Currently 0-9 are valid cores.
539 Not all cores work on all architectures. Eg some are x86 specific
540 assembler, others PPC specific assembler. If a core is not valid
541 hashcash returns failure and explains what happened.
542
543 =item I<-Z n>
544
545 Compress the stamp. This is a time vs space trade off. Larger stamps
546 are faster, but arguably slightly ugly. For fastest stamps (the
547 default) use -Z 0; for partly compressed stamps use -Z 1; for very
548 compressed, but somewhat slow stamps use -Z 2. (Note: due to a late
549 discovered bug, -Z2 is the same as -Z1 for now until I can fix that.)
550
551 =back
552
553 =head1 EXAMPLES
554
555 =head2 Creating stamps
556
557 =over 4
558
559 =item C<hashcash -s>
560
561 Print timing information about how many preimages the machine can try
562 per second.
563
564 =item C<hashcash -sv>
565
566 More accurate but quite slow benchmarking of different processor
567 specific minting cores.
568
569 =item C<hashcash -s -b default>
570
571 Print how long it would take the machine to compute a default sized
572 preimage (but don't actually compute a preimage).
573
574 =item C<hashcash -s -b 32>
575
576 Print how long it would take the machine to compute a 32 bit preimage
577 (but don't actually compute a preimage).
578
579 =item C<hashcash -m>
580
581 Mint a stamp. Will prompt for resource name and mint with default
582 value (number of preimage bits).
583
584 =item C<hashcash -m foo>
585
586 Compute preimage on resource foo. Will mint with default value
587 (number of preimage bits).
588
589 =item C<hashcash -m foo -b 10>
590
591 Compute 10 bit preimage on resource foo.
592
593 =item C<hashcash -a -3d>
594
595 Subtract a random time of between 0 days and 3 days from the stamp's
596 creation time. This is the same fuzz factor used by mixmaster to
597 reduce risk of timing-correlations.
598
599 =back
600
601 =head2 Examining Stamps
602
603 =over 4
604
605 =item C<hashcash -w 1:24:040806:foo::511801694b4cd6b0:1e7297a>
606
607 Report the value of the stamp (how many bits of preimage) there are.
608 The example is a 24 bit preimage, which takes on average 25 seconds
609 to create on a 3Ghz P4.
610
611 =item C<hashcash -mq -b 10 foo | hashcash -w>
612
613 Create a stamp in batch mode, pass to hashcash on stdin to verify,
614 have it print how many bits there were.
615
616 =item C<hashcash -n 1:24:040806:foo::511801694b4cd6b0:1e7297a>
617
618 Report the resource name from the stamp. The resource name in the
619 example is foo.
620
621 =item C<hashcash -l -e 30y 1:24:040806:foo::511801694b4cd6b0:1e7297a>
622
623 Report how long until the stamp expires if it expires in 30 years from
624 its creation date. (Note dates too far into the future run into the
625 2038 end of Epoch, which is the unix time analog of the y2k bug).
626
627 =back
628
629 =head2 Verifying Stamps
630
631 =over 4
632
633 =item C<hashcash -c 1:24:040806:foo::511801694b4cd6b0:1e7297a>
634
635 Check if the stamp is valid. Note as we are not checking the stamp in
636 a double spend database, and did not specify a resource name or
637 required number of bits of preimage and hashcash will consider the
638 stamp not fully checked, and it will report it as valid but not fully
639 unchecked, or as invalid if there is any problem with the stamp.
640
641 =item C<hashcash -c -b24 1:24:040806:foo::511801694b4cd6b0:1e7297a>
642
643 Check that the value of the stamp is greater or equal to 24 bits.
644 This example has 24 bit value. If you increase the requested number
645 of bits or replace the stamp with one with less than 24 bit preimage
646 the stamp will be rejected.
647
648 =item C<hashcash -c -b24 -r foo 1:24:040806:foo::511801694b4cd6b0:1e7297a>
649
650 As above check if the stamp has sufficient value, but in addition
651 check that the resource name given matches the resource name in the
652 stamp.
653
654 =back
655
656 =head2 Double Spending Prevention
657
658 The examples given in L<Verifying Stamps> can be modified to keep a
659 double spend database so that the same stamp will not be accepted
660 twice. Note a stamp will only be checked in and added to the database
661 if it is otherwise valid and fully checked (a required number of bits
662 of preimage has been specified and a resource has been specified).
663
664 =over 4
665
666 =item C<hashcash -cd -b 10 -r foo 1:24:040806:foo::511801694b4cd6b0:1e7297a>
667
668 Check the stamp and add to double spent database if it's valid (has
669 correct resource name and sufficient value).
670
671 =item C<hashcash -cd -b 10 -r foo 1:24:040806:foo::511801694b4cd6b0:1e7297a>
672
673 Try to double spend the stamp. It will be rejected as double spent.
674
675 =back
676
677 =head2 Stamp Expiry
678
679 To prevent the double spend database growing indefinately, the
680 recipient can request that stamps be no older than a specified period.
681 After expiry old stamps can dropped from the double spend database as
682 they will no longer be needed -- expired stamps can be rejected based
683 purely on their old date, so the space taken by expired stamps in the
684 double spend database can be saved without risk of accepting an
685 expired though otherwise valid stamp.
686
687 The third field of the stamp is the UTC time since 1st January 1970.
688 The default time format is YYMMDD, time rounded down to the nearest
689 day. The default validity period is 28 days.
690
691 You can provide an alternative validity period with the I<-e> option.
692
693 =over 4
694
695 =item C<hashcash -cd -b 10 -e 2d -r foo 1:24:040806:foo::511801694b4cd6b0:1e7297a>
696
697 Try verifying an old stamp, the above stamp was created 11 Aug 2002.
698
699 We gave option I<-e 2d> so the stamps expiry date is 2 days after
700 creation, which is now in the past.
701
702 Note: if the creation time is expressed in the stamp in days, the
703 precise creation date is the begining of the specified day in UTC time
704 (similarly for alternate units the creation time is rounded down to
705 the begining of the unit it is expressed in). For units in days, for
706 example, this may mean depending on your time zone that the stamp
707 appears to be considered invalid in under the specified expiry period
708 in days relative to your relative view of what day it is, as the
709 calculation is based on current time in UTC, and the creation time of
710 the stamp is expressed in UTC time.
711
712 =item C<hashcash -cd -b 10 -r foo 1:24:040806:foo::511801694b4cd6b0:1e7297a>
713
714 Test whether the stamp is otherwise valid, apart from having expired.
715 Omitting the I<-e> tells hashcash that the stamp will never expire.
716 An expiry period of forever can also be given explitly like this: I<-e
717 0>, where an expiry period of 0 means forever.
718
719 =back
720
721 =head2 Purging old stamps
722
723 If the I<-c>, I<-d> options are used together, each time a stamp is
724 checked, if it is valid and all of the mandatory aspects of the stamp
725 are verified (preimage bits check, resource name check) then the
726 stamp and its expiry period is written to the database file. The
727 default expiry period if an expiry period is not given explicitly with
728 the I<-e> option is 28 days (ie stamps expire after 4 weeks).
729
730 First mint and then add a stamp:
731
732 =over 4
733
734 =item C<hashcash -m -b 10 foo -e 1m E<gt> stamp>
735
736 Note: we specified an expiry on minting in this example, to ensure
737 that the stamp creation time is given in high enough resolution in the
738 stamp that the stamp will not be considered expired at time of
739 creation. (Recall the default resolution is in days, a stamp created
740 with a creation time rounded down to the beginging of the day is
741 unlikely to be considered valid 1 minute later unless you mint it at
742 midnight UTC time.)
743
744 =item C<hashcash -cd -e 1m -b 10 -r foo E<lt> stamp>
745
746 The stamp expires in 1 minute. Wait 1 minute and then explicitly
747 request that expired stamps be purged:
748
749 =item C<hashcash -p now>
750
751 Then try resubmitting the same stamp:
752
753 =item C<hashcash -cd -e 1m -b 10 -r foo E<lt> stamp>
754
755 and the stamp will be rejected anyway as it has expired, illustrating
756 why it was not necessary to keep this stamp in the database.
757
758 With the default database (the sdb format) the database contents are
759 human readable, so you can view their contents by cating them to the
760 terminal:
761
762 =item C<cat hashcash.sdb>
763
764 to see that the stamp really is added and then after puring
765 subsequently purged due to expiry.
766
767 =back
768
769 =head2 Purging old stamps on Demand
770
771 As a convenience you can purge at the same time as checking stamps by
772 using the I<-p> option with the I<-c> option.
773
774 =over 4
775
776 =item C<hashcash -m -b 10 foo E<gt> stamp>
777
778 =item C<hashcash -cd -p now -e 1 -b 10 -r foo E<lt> stamp>
779
780 It may be inefficient to purge stamps on every use as the entire
781 database has to be scanned for expired stamps. By giving a time
782 period to the I<-p> option, you can tell C<hashcash> to purge no more
783 frequently than that time period since the previous purge.
784
785 For example:
786
787 =item C<hashcash -cd -p 1d -e 1 -b 10 -r foo E<lt> stamp>
788
789 tells C<hashcash> to purge any expired stamps no more than once per
790 day.
791
792 =item C<hashcash -p 1M -j foo>
793
794 tells C<hashcash> to purge only expired stamps matching resource foo
795 once per month.
796
797 =item C<hashcash -p now -k>
798
799 tells C<hashcash> to purge all stamps (expired and unexpired) now.
800
801 =back
802
803 =head1 stamp format (version 1)
804
805 The current stamp format is version 1. This tool can verify hashcash
806 version 0 stamps also, but version 0 stamps are no longer created as
807 they are being phased out in favor of the more extensible v1 stamp
808 format.
809
810 =over 4
811
812 =item I<ver>:I<bits>:I<date>:I<resource>:[I<ext>]:I<rand>:I<counter>
813
814 =back
815
816 where
817
818 =over 4
819
820 =item I<ver> = 1
821
822 =item I<bits> = how many bits of partial-preimage the stamp is claimed to have
823
824 =item I<date> = YYMMDD[hhmm[ss]]
825
826 =item I<resource> = resource string (eg IP address, email address)
827
828 =item I<ext> = extension -- ignored in the current version
829
830 Format of extension:
831
832 =over 4
833
834 =item [name1[=val1[,val2...]];[name2[=val1[,val2...]]...]]
835
836 Note the value can also contain =. Example extension (not a real one):
837
838 name1=2,3;name2;name3=var1=2,var2=3,2,val
839
840 Which would be extension name1 has values 2 and 3; extension name2 has
841 no values; extension name3 has 3 values "var1=2", "var2=3", "2" and
842 "val". The hashcash extension may interpret the values as it sees fit
843 eg "var1=2" could be the value of an option to the extension name3.
844
845 =back
846
847 =item I<rand> = string of random characters from alphabet
848 a-zA-Z0-9+/= to avoid preimage with other sender's
849 stamps
850
851 =item I<counter> = to find a stamp with the desired number of
852 preimage bits need to try lots of different strings
853 this counter is incremented on each try.
854 The Counter is also composed of characters from the
855 alphabet a-zA-Z0-9+/=. (Note an implementation is
856 not required to count sequentially).
857
858 =back
859
860 =head1 FILES
861
862 =over 4
863
864 =item F<hashcash.sdb>
865
866 default double spend database
867
868 =back
869
870 =head1 EXIT STATUS
871
872 C<hashcash> returns success (exit code 0) after successfully minting a
873 stamp, after fully checking a stamp and finding it valid, and after a
874 timing test.
875
876 If when checking a stamp it is found to be invalid (due to being
877 malformed, being expired, having insufficient value, having a date in
878 the future, or being double spent), C<hashcash> returns failure (exit
879 code 1).
880
881 If insufficient options are given to fully check a stamp, if the stamp
882 is otherwise valid return unchecked (exit code 2). If the I<-y> flag
883 is given and hashcash would normally return unchecked, exit code
884 success is returned instead.
885
886 If any exception occurs (file read failure for database checking or
887 corrupted database contents) an exit status of 3 is returned.
888
889 =head1 AUTHOR
890
891 Written by Adam Back E<lt>[email protected]<gt>
892
893 =head1 SEE ALSO
894
895 sha1sum(1), sha1-hashcash(1), sha1(1), http://www.hashcash.org/