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