95da5b7b5c8ab0fef2f45fc601521555f98c2eee
[openssl.git] / doc / apps / ts.pod
1 =pod
2
3 =head1 NAME
4
5 ts - Time Stamping Authority tool (client/server)
6
7 =head1 SYNOPSIS
8
9 B<openssl> B<ts>
10 B<-query>
11 [B<-rand> file:file...]
12 [B<-config> configfile]
13 [B<-data> file_to_hash]
14 [B<-digest> digest_bytes]
15 [B<-md2>|B<-md4>|B<-md5>|B<-sha>|B<-sha1>|B<-mdc2>|B<-ripemd160>]
16 [B<-policy> object_id]
17 [B<-no_nonce>]
18 [B<-cert>]
19 [B<-in> request.tsq]
20 [B<-out> request.tsq]
21 [B<-text>]
22
23 B<openssl> B<ts>
24 B<-reply>
25 [B<-config> configfile]
26 [B<-section> tsa_section]
27 [B<-queryfile> request.tsq]
28 [B<-passin> password_src]
29 [B<-signer> tsa_cert.pem]
30 [B<-inkey> private.pem]
31 [B<-chain> certs_file.pem]
32 [B<-policy> object_id]
33 [B<-in> response.tsr]
34 [B<-token_in>]
35 [B<-out> response.tsr]
36 [B<-token_out>]
37 [B<-text>]
38 [B<-engine> id]
39
40 B<openssl> B<ts>
41 B<-verify>
42 [B<-data> file_to_hash]
43 [B<-digest> digest_bytes]
44 [B<-queryfile> request.tsq]
45 [B<-in> response.tsr]
46 [B<-token_in>]
47 [B<-CApath> trusted_cert_path]
48 [B<-CAfile> trusted_certs.pem]
49 [B<-untrusted> cert_file.pem]
50
51 =head1 DESCRIPTION
52
53 The B<ts> command is a basic Time Stamping Authority (TSA) client and server
54 application as specified in RFC 3161 (Time-Stamp Protocol, TSP). A
55 TSA can be part of a PKI deployment and its role is to provide long
56 term proof of the existence of a certain datum before a particular
57 time. Here is a brief description of the protocol:
58
59 =over 4
60
61 =item 1.
62
63 The TSA client computes a one-way hash value for a data file and sends
64 the hash to the TSA.
65
66 =item 2.
67
68 The TSA attaches the current date and time to the received hash value,
69 signs them and sends the time stamp token back to the client. By
70 creating this token the TSA certifies the existence of the original
71 data file at the time of response generation.
72
73 =item 3.
74
75 The TSA client receives the time stamp token and verifies the
76 signature on it. It also checks if the token contains the same hash
77 value that it had sent to the TSA.
78
79 =back
80
81 There is one DER encoded protocol data unit defined for transporting a time
82 stamp request to the TSA and one for sending the time stamp response
83 back to the client. The B<ts> command has three main functions:
84 creating a time stamp request based on a data file,
85 creating a time stamp response based on a request, verifying if a
86 response corresponds to a particular request or a data file.
87
88 There is no support for sending the requests/responses automatically
89 over HTTP or TCP yet as suggested in RFC 3161. The users must send the
90 requests either by ftp or e-mail.
91
92 =head1 OPTIONS
93
94 =head2 Time Stamp Request generation
95
96 The B<-query> switch can be used for creating and printing a time stamp
97 request with the following options:
98
99 =over 4
100
101 =item B<-rand> file:file...
102
103 The files containing random data for seeding the random number
104 generator. Multiple files can be specified, the separator is B<;> for
105 MS-Windows, B<,> for VMS and B<:> for all other platforms. (Optional)
106
107 =item B<-config> configfile
108
109 The configuration file to use, this option overrides the
110 B<OPENSSL_CONF> environment variable. Only the OID section
111 of the config file is used with the B<-query> command. (Optional)
112
113 =item B<-data> file_to_hash
114
115 The data file for which the time stamp request needs to be
116 created. stdin is the default if neither the B<-data> nor the B<-digest>
117 parameter is specified. (Optional)
118
119 =item B<-digest> digest_bytes
120
121 It is possible to specify the message imprint explicitly without the data
122 file. The imprint must be specified in a hexadecimal format, two characters
123 per byte, the bytes optionally separated by colons (e.g. 1A:F6:01:... or
124 1AF601...). The number of bytes must match the message digest algorithm 
125 in use. (Optional)
126
127 =item B<-md2>|B<-md4>|B<-md5>|B<-sha>|B<-sha1>|B<-mdc2>|B<-ripemd160>
128
129 The message digest to apply to the data file. The default is SHA-1. (Optional)
130
131 =item B<-policy> object_id
132
133 The policy that the client expects the TSA to use for creating the
134 time stamp token. Either the dotted OID notation or OID names defined
135 in the config file can be used. If no policy is requested the TSA will
136 use its own default policy. (Optional)
137
138 =item B<-no_nonce>
139
140 No nonce is specified in the request if this option is
141 given. Otherwise a 64 bit long pseudo-random none is
142 included in the request. It is recommended to use nonce to
143 protect against replay-attacks. (Optional)
144
145 =item B<-cert>
146
147 The TSA is expected to include its signing certificate in the
148 response. (Optional)
149
150 =item B<-in> request.tsq
151
152 This option specifies a previously created time stamp request in DER
153 format that will be printed into the output file. Useful when you need
154 to examine the content of a request in human-readable
155
156 format. (Optional)
157
158 =item B<-out> request.tsq
159
160 Name of the output file to which the request will be written. Default
161 is stdout. (Optional)
162
163 =item B<-text>
164
165 If this option is specified the output is human-readable text format
166 instead of DER. (Optional)
167
168 =back
169
170 =head2 Time Stamp Response generation
171
172 A time stamp response (TimeStampResp) consists of a response status
173 and the time stamp token itself (ContentInfo), if the token generation was
174 successful. The B<-reply> command is for creating a time stamp
175 response or time stamp token based on a request and printing the
176 response/token in human-readable format. If B<-token_out> is not
177 specified the output is always a time stamp response (TimeStampResp),
178 otherwise it is a time stamp token (ContentInfo).
179
180 =over 4
181
182 =item B<-config> configfile
183
184 The configuration file to use, this option overrides the
185 B<OPENSSL_CONF> environment variable. See B<CONFIGURATION FILE
186 OPTIONS> for configurable variables. (Optional)
187
188 =item B<-section> tsa_section
189
190 The name of the config file section conatining the settings for the
191 response generation. If not specified the default TSA section is
192 used, see B<CONFIGURATION FILE OPTIONS> for details. (Optional)
193
194 =item B<-queryfile> request.tsq
195
196 The name of the file containing a DER encoded time stamp request. (Optional)
197
198 =item B<-passin> password_src
199
200 Specifies the password source for the private key of the TSA. See
201 B<PASS PHRASE ARGUMENTS> in L<openssl(1)|openssl(1)>. (Optional)
202
203 =item B<-signer> tsa_cert.pem
204
205 The signer certificate of the TSA in PEM format. The TSA signing
206 certificate must have exactly one extended key usage assigned to it:
207 timeStamping. The extended key usage must also be critical, otherwise
208 the certificate is going to be refused. Overrides the B<signer_cert>
209 variable of the config file. (Optional)
210
211 =item B<-inkey> private.pem
212
213 The signer private key of the TSA in PEM format. Overrides the
214 B<signer_key> config file option. (Optional)
215
216 =item B<-chain> certs_file.pem
217
218 The collection of certificates in PEM format that will all
219 be included in the response in addition to the signer certificate if
220 the B<-cert> option was used for the request. This file is supposed to
221 contain the certificate chain for the signer certificate from its
222 issuer upwards. The B<-reply> command does not build a certificate
223 chain automatically. (Optional)
224
225 =item B<-policy> object_id
226
227 The default policy to use for the response unless the client
228 explicitly requires a particular TSA policy. The OID can be specified
229 either in dotted notation or with its name. Overrides the
230 B<default_policy> config file option. (Optional)
231
232 =item B<-in> response.tsr
233
234 Specifies a previously created time stamp response or time stamp token
235 (if B<-token_in> is also specified) in DER format that will be written
236 to the output file. This option does not require a request, it is
237 useful e.g. when you need to examine the content of a response or
238 token or you want to extract the time stamp token from a response. If
239 the input is a token and the output is a time stamp response a default
240 'granted' status info is added to the token. (Optional)
241
242 =item B<-token_in>
243
244 This flag can be used together with the B<-in> option and indicates
245 that the input is a DER encoded time stamp token (ContentInfo) instead
246 of a time stamp response (TimeStampResp). (Optional)
247
248 =item B<-out> response.tsr
249
250 The response is written to this file. The format and content of the
251 file depends on other options (see B<-text>, B<-token_out>). The default is
252 stdout. (Optional)
253
254 =item B<-token_out>
255
256 The output is a time stamp token (ContentInfo) instead of time stamp
257 response (TimeStampResp). (Optional)
258
259 =item B<-text>
260
261 If this option is specified the output is human-readable text format
262 instead of DER. (Optional)
263
264 =item B<-engine> id
265
266 Specifying an engine (by it's unique B<id> string) will cause B<ts>
267 to attempt to obtain a functional reference to the specified engine,
268 thus initialising it if needed. The engine will then be set as the default
269 for all available algorithms. Default is builtin. (Optional)
270
271 =back
272
273 =head2 Time Stamp Response verification
274
275 The B<-verify> command is for verifying if a time stamp response or time
276 stamp token is valid and matches a particular time stamp request or
277 data file. The B<-verify> command does not use the configuration file.
278
279 =over 4
280
281 =item B<-data> file_to_hash
282
283 The response or token must be verified against file_to_hash. The file
284 is hashed with the message digest algorithm specified in the token. 
285 The B<-digest> and B<-queryfile> options must not be specified with this one.
286 (Optional)
287
288 =item B<-digest> digest_bytes
289
290 The response or token must be verified against the message digest specified
291 with this option. The number of bytes must match the message digest algorithm
292 specified in the token. The B<-data> and B<-queryfile> options must not be
293 specified with this one. (Optional)
294
295 =item B<-queryfile> request.tsq
296
297 The original time stamp request in DER format. The B<-data> and B<-digest>
298 options must not be specified with this one. (Optional)
299
300 =item B<-in> response.tsr
301
302 The time stamp response that needs to be verified in DER format. (Mandatory)
303
304 =item B<-token_in>
305
306 This flag can be used together with the B<-in> option and indicates
307 that the input is a DER encoded time stamp token (ContentInfo) instead
308 of a time stamp response (TimeStampResp). (Optional)
309
310 =item B<-CApath> trusted_cert_path
311
312 The name of the directory containing the trused CA certificates of the
313 client. See the similar option of L<verify(1)|verify(1)> for additional
314 details. Either this option or B<-CAfile> must be specified. (Optional)
315
316
317 =item B<-CAfile> trusted_certs.pem
318
319 The name of the file containing a set of trusted self-signed CA 
320 certificates in PEM format. See the similar option of 
321 L<verify(1)|verify(1)> for additional details. Either this option 
322 or B<-CApath> must be specified.
323 (Optional)
324
325 =item B<-untrusted> cert_file.pem
326
327 Set of additional untrusted certificates in PEM format which may be
328 needed when building the certificate chain for the TSA's signing
329 certificate. This file must contain the TSA signing certificate and
330 all intermediate CA certificates unless the response includes them.
331 (Optional)
332
333 =back
334
335 =head1 CONFIGURATION FILE OPTIONS
336
337 The B<-query> and B<-reply> commands make use of a configuration file
338 defined by the B<OPENSSL_CONF> environment variable. See L<config(5)|config(5>
339 for a general description of the syntax of the config file. The
340 B<-query> command uses only the symbolic OID names section
341 and it can work without it. However, the B<-reply> command needs the
342 config file for its operation.
343
344 When there is a command line switch equivalent of a variable the
345 switch always overrides the settings in the config file.
346
347 =over 4
348
349 =item B<tsa> section, B<default_tsa>    
350
351 This is the main section and it specifies the name of another section
352 that contains all the options for the B<-reply> command. This default
353 section can be overriden with the B<-section> command line switch. (Optional)
354
355 =item B<oid_file>
356
357 See L<ca(1)|ca(1)> for description. (Optional)
358
359 =item B<oid_section>
360
361 See L<ca(1)|ca(1)> for description. (Optional)
362
363 =item B<RANDFILE>
364
365 See L<ca(1)|ca(1)> for description. (Optional)
366
367 =item B<serial>
368
369 The name of the file containing the hexadecimal serial number of the
370 last time stamp response created. This number is incremented by 1 for
371 each response. If the file does not exit at the time of response
372 generation a new file is created with serial number 1. (Mandatory)
373
374 =item B<crypto_device>
375
376 Specifies the OpenSSL engine that will be set as the default for 
377 all available algorithms. The default value is builtin, you can specify 
378 any other engines supported by OpenSSL (e.g. use chil for the NCipher HSM).
379 (Optional)
380
381 =item B<signer_cert>
382
383 TSA signing certificate in PEM format. The same as the B<-signer>
384 command line option. (Optional)
385
386 =item B<certs>
387
388 A file containing a set of PEM encoded certificates that need to be
389 included in the response. The same as the B<-chain> command line
390 option. (Optional)
391
392 =item B<signer_key>
393
394 The private key of the TSA in PEM format. The same as the B<-inkey>
395 command line option. (Optional)
396
397 =item B<default_policy>
398
399 The default policy to use when the request does not mandate any
400 policy. The same as the B<-policy> command line option. (Optional)
401
402 =item B<other_policies>
403
404 Comma separated list of policies that are also acceptable by the TSA
405 and used only if the request explicitly specifies one of them. (Optional)
406
407 =item B<digests>
408
409 The list of message digest algorithms that the TSA accepts. At least
410 one algorithm must be specified. (Mandatory)
411
412 =item B<accuracy>
413
414 The accuracy of the time source of the TSA in seconds, milliseconds
415 and microseconds. E.g. secs:1, millisecs:500, microsecs:100. If any of
416 the components is missing zero is assumed for that field. (Optional)
417
418 =item B<clock_precision_digits>
419
420 Specifies the maximum number of digits, which represent the fraction of 
421 seconds, that  need to be included in the time field. The trailing zeroes
422 must be removed from the time, so there might actually be fewer digits,
423 or no fraction of seconds at all. Supported only on UNIX platforms.
424 The maximum value is 6, default is 0.
425 (Optional)
426
427 =item B<ordering>
428
429 If this option is yes the responses generated by this TSA can always
430 be ordered, even if the time difference between two responses is less
431 than the sum of their accuracies. Default is no. (Optional)
432
433 =item B<tsa_name>
434
435 Set this option to yes if the subject name of the TSA must be included in
436 the TSA name field of the response. Default is no. (Optional)
437
438 =item B<ess_cert_id_chain>
439
440 The SignedData objects created by the TSA always contain the
441 certificate identifier of the signing certificate in a signed
442 attribute (see RFC 2634, Enhanced Security Services). If this option
443 is set to yes and either the B<certs> variable or the B<-chain> option
444 is specified then the certificate identifiers of the chain will also
445 be included in the SigningCertificate signed attribute. If this
446 variable is set to no, only the signing certificate identifier is
447 included. Default is no. (Optional)
448
449 =back
450
451 =head1 ENVIRONMENT VARIABLES
452
453 B<OPENSSL_CONF> contains the path of the configuration file and can be
454 overriden by the B<-config> command line option.
455
456 =head1 EXAMPLES
457
458 All the examples below presume that B<OPENSSL_CONF> is set to a proper
459 configuration file, e.g. the example configuration file 
460 openssl/apps/openssl.cnf will do.
461
462 =head2 Time Stamp Request
463
464 To create a time stamp request for design1.txt with SHA-1 
465 without nonce and policy and no certificate is required in the response:
466
467   openssl ts -query -data design1.txt -no_nonce \
468         -out design1.tsq
469
470 To create a similar time stamp request with specifying the message imprint
471 explicitly:
472
473   openssl ts -query -digest b7e5d3f93198b38379852f2c04e78d73abdd0f4b \
474          -no_nonce -out design1.tsq
475
476 To print the content of the previous request in human readable format:
477
478   openssl ts -query -in design1.tsq -text
479
480 To create a time stamp request which includes the MD-5 digest 
481 of design2.txt, requests the signer certificate and nonce,
482 specifies a policy id (assuming the tsa_policy1 name is defined in the
483 OID section of the config file):
484
485   openssl ts -query -data design2.txt -md5 \
486         -policy tsa_policy1 -cert -out design2.tsq
487
488 =head2 Time Stamp Response
489
490 Before generating a response a signing certificate must be created for
491 the TSA that contains the B<timeStamping> critical extended key usage extension
492 without any other key usage extensions. You can add the
493 'extendedKeyUsage = critical,timeStamping' line to the user certificate section
494 of the config file to generate a proper certificate. See L<req(1)|req(1)>,
495 L<ca(1)|ca(1)>, L<x509(1)|x509(1)> for instructions. The examples
496 below assume that cacert.pem contains the certificate of the CA,
497 tsacert.pem is the signing certificate issued by cacert.pem and
498 tsakey.pem is the private key of the TSA.
499
500 To create a time stamp response for a request:
501
502   openssl ts -reply -queryfile design1.tsq -inkey tsakey.pem \
503         -signer tsacert.pem -out design1.tsr
504
505 If you want to use the settings in the config file you could just write:
506
507   openssl ts -reply -queryfile design1.tsq -out design1.tsr
508
509 To print a time stamp reply to stdout in human readable format:
510
511   openssl ts -reply -in design1.tsr -text
512
513 To create a time stamp token instead of time stamp response:
514
515   openssl ts -reply -queryfile design1.tsq -out design1_token.der -token_out
516
517 To print a time stamp token to stdout in human readable format:
518
519   openssl ts -reply -in design1_token.der -token_in -text -token_out
520
521 To extract the time stamp token from a response:
522
523   openssl ts -reply -in design1.tsr -out design1_token.der -token_out
524
525 To add 'granted' status info to a time stamp token thereby creating a
526 valid response:
527
528   openssl ts -reply -in design1_token.der -token_in -out design1.tsr
529
530 =head2 Time Stamp Verification
531
532 To verify a time stamp reply against a request:
533
534   openssl ts -verify -queryfile design1.tsq -in design1.tsr \
535         -CAfile cacert.pem -untrusted tsacert.pem
536
537 To verify a time stamp reply that includes the certificate chain:
538
539   openssl ts -verify -queryfile design2.tsq -in design2.tsr \
540         -CAfile cacert.pem
541
542 To verify a time stamp token against the original data file:
543   openssl ts -verify -data design2.txt -in design2.tsr \
544         -CAfile cacert.pem
545
546 To verify a time stamp token against a message imprint:
547   openssl ts -verify -digest b7e5d3f93198b38379852f2c04e78d73abdd0f4b \
548          -in design2.tsr -CAfile cacert.pem
549
550 You could also look at the 'test' directory for more examples.
551
552 =head1 BUGS
553
554 If you find any bugs or you have suggestions please write to
555 Zoltan Glozik <zglozik@opentsa.org>. Known issues:
556
557 =over 4
558
559 =item * No support for time stamps over SMTP, though it is quite easy
560 to implement an automatic e-mail based TSA with L<procmail(1)|procmail(1)> 
561 and L<perl(1)|perl(1)>. HTTP server support is provided in the form of 
562 a separate apache module. HTTP client support is provided by
563 L<tsget(1)|tsget(1)>. Pure TCP/IP protocol is not supported.
564
565 =item * The file containing the last serial number of the TSA is not
566 locked when being read or written. This is a problem if more than one
567 instance of L<openssl(1)|openssl(1)> is trying to create a time stamp
568 response at the same time. This is not an issue when using the apache
569 server module, it does proper locking.
570
571 =item * Look for the FIXME word in the source files.
572
573 =item * The source code should really be reviewed by somebody else, too.
574
575 =item * More testing is needed, I have done only some basic tests (see
576 test/testtsa).
577
578 =back
579
580 =cut
581
582 =head1 AUTHOR
583
584 Zoltan Glozik <zglozik@opentsa.org>, OpenTSA project (http://www.opentsa.org)
585
586 =head1 SEE ALSO
587
588 L<tsget(1)|tsget(1)>, L<openssl(1)|openssl(1)>, L<req(1)|req(1)>, 
589 L<x509(1)|x509(1)>, L<ca(1)|ca(1)>, L<genrsa(1)|genrsa(1)>, 
590 L<config(5)|config(5)>
591
592 =cut