openssl-ts.pod.in 20 KB

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