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