openssl-ts.pod.in 20 KB

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