ts.pod 19 KB

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