summaryrefslogtreecommitdiff
path: root/src/usr.bin/openssl/ts.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/usr.bin/openssl/ts.c')
-rw-r--r--src/usr.bin/openssl/ts.c120
1 files changed, 60 insertions, 60 deletions
diff --git a/src/usr.bin/openssl/ts.c b/src/usr.bin/openssl/ts.c
index 05387de130..84008183e7 100644
--- a/src/usr.bin/openssl/ts.c
+++ b/src/usr.bin/openssl/ts.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ts.c,v 1.25 2022/11/11 17:07:39 joshua Exp $ */ 1/* $OpenBSD: ts.c,v 1.26 2023/03/06 14:32:06 tb Exp $ */
2/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL 2/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
3 * project 2002. 3 * project 2002.
4 */ 4 */
@@ -138,7 +138,7 @@ static struct {
138 int token_in; 138 int token_in;
139 int token_out; 139 int token_out;
140 char *untrusted; 140 char *untrusted;
141} ts_config; 141} cfg;
142 142
143static int 143static int
144ts_opt_md(int argc, char **argv, int *argsused) 144ts_opt_md(int argc, char **argv, int *argsused)
@@ -148,7 +148,7 @@ ts_opt_md(int argc, char **argv, int *argsused)
148 if (*name++ != '-') 148 if (*name++ != '-')
149 return (1); 149 return (1);
150 150
151 if ((ts_config.md = EVP_get_digestbyname(name)) == NULL) 151 if ((cfg.md = EVP_get_digestbyname(name)) == NULL)
152 return (1); 152 return (1);
153 153
154 *argsused = 1; 154 *argsused = 1;
@@ -158,27 +158,27 @@ ts_opt_md(int argc, char **argv, int *argsused)
158static int 158static int
159ts_opt_query(void) 159ts_opt_query(void)
160{ 160{
161 if (ts_config.mode != CMD_NONE) 161 if (cfg.mode != CMD_NONE)
162 return (1); 162 return (1);
163 ts_config.mode = CMD_QUERY; 163 cfg.mode = CMD_QUERY;
164 return (0); 164 return (0);
165} 165}
166 166
167static int 167static int
168ts_opt_reply(void) 168ts_opt_reply(void)
169{ 169{
170 if (ts_config.mode != CMD_NONE) 170 if (cfg.mode != CMD_NONE)
171 return (1); 171 return (1);
172 ts_config.mode = CMD_REPLY; 172 cfg.mode = CMD_REPLY;
173 return (0); 173 return (0);
174} 174}
175 175
176static int 176static int
177ts_opt_verify(void) 177ts_opt_verify(void)
178{ 178{
179 if (ts_config.mode != CMD_NONE) 179 if (cfg.mode != CMD_NONE)
180 return (1); 180 return (1);
181 ts_config.mode = CMD_VERIFY; 181 cfg.mode = CMD_VERIFY;
182 return (0); 182 return (0);
183} 183}
184 184
@@ -188,89 +188,89 @@ static const struct option ts_options[] = {
188 .argname = "file", 188 .argname = "file",
189 .desc = "Certificate Authority file", 189 .desc = "Certificate Authority file",
190 .type = OPTION_ARG, 190 .type = OPTION_ARG,
191 .opt.arg = &ts_config.ca_file, 191 .opt.arg = &cfg.ca_file,
192 }, 192 },
193 { 193 {
194 .name = "CApath", 194 .name = "CApath",
195 .argname = "path", 195 .argname = "path",
196 .desc = "Certificate Authority path", 196 .desc = "Certificate Authority path",
197 .type = OPTION_ARG, 197 .type = OPTION_ARG,
198 .opt.arg = &ts_config.ca_path, 198 .opt.arg = &cfg.ca_path,
199 }, 199 },
200 { 200 {
201 .name = "cert", 201 .name = "cert",
202 .desc = "Include signing certificate in the response", 202 .desc = "Include signing certificate in the response",
203 .type = OPTION_FLAG, 203 .type = OPTION_FLAG,
204 .opt.flag = &ts_config.cert, 204 .opt.flag = &cfg.cert,
205 }, 205 },
206 { 206 {
207 .name = "chain", 207 .name = "chain",
208 .argname = "file", 208 .argname = "file",
209 .desc = "PEM certificates that will be included in the response", 209 .desc = "PEM certificates that will be included in the response",
210 .type = OPTION_ARG, 210 .type = OPTION_ARG,
211 .opt.arg = &ts_config.chain, 211 .opt.arg = &cfg.chain,
212 }, 212 },
213 { 213 {
214 .name = "config", 214 .name = "config",
215 .argname = "file", 215 .argname = "file",
216 .desc = "Specify an alternative configuration file", 216 .desc = "Specify an alternative configuration file",
217 .type = OPTION_ARG, 217 .type = OPTION_ARG,
218 .opt.arg = &ts_config.configfile, 218 .opt.arg = &cfg.configfile,
219 }, 219 },
220 { 220 {
221 .name = "data", 221 .name = "data",
222 .argname = "file", 222 .argname = "file",
223 .desc = "Data file for which the time stamp request needs to be created", 223 .desc = "Data file for which the time stamp request needs to be created",
224 .type = OPTION_ARG, 224 .type = OPTION_ARG,
225 .opt.arg = &ts_config.data, 225 .opt.arg = &cfg.data,
226 }, 226 },
227 { 227 {
228 .name = "digest", 228 .name = "digest",
229 .argname = "arg", 229 .argname = "arg",
230 .desc = "Specify the message imprint explicitly without the data file", 230 .desc = "Specify the message imprint explicitly without the data file",
231 .type = OPTION_ARG, 231 .type = OPTION_ARG,
232 .opt.arg = &ts_config.digest, 232 .opt.arg = &cfg.digest,
233 }, 233 },
234 { 234 {
235 .name = "in", 235 .name = "in",
236 .argname = "file", 236 .argname = "file",
237 .desc = "Input file", 237 .desc = "Input file",
238 .type = OPTION_ARG, 238 .type = OPTION_ARG,
239 .opt.arg = &ts_config.in, 239 .opt.arg = &cfg.in,
240 }, 240 },
241 { 241 {
242 .name = "inkey", 242 .name = "inkey",
243 .argname = "file", 243 .argname = "file",
244 .desc = "Input key file", 244 .desc = "Input key file",
245 .type = OPTION_ARG, 245 .type = OPTION_ARG,
246 .opt.arg = &ts_config.inkey, 246 .opt.arg = &cfg.inkey,
247 }, 247 },
248 { 248 {
249 .name = "no_nonce", 249 .name = "no_nonce",
250 .desc = "Specify no nonce in the request", 250 .desc = "Specify no nonce in the request",
251 .type = OPTION_FLAG, 251 .type = OPTION_FLAG,
252 .opt.flag = &ts_config.no_nonce, 252 .opt.flag = &cfg.no_nonce,
253 }, 253 },
254 { 254 {
255 .name = "out", 255 .name = "out",
256 .argname = "file", 256 .argname = "file",
257 .desc = "Output file", 257 .desc = "Output file",
258 .type = OPTION_ARG, 258 .type = OPTION_ARG,
259 .opt.arg = &ts_config.out, 259 .opt.arg = &cfg.out,
260 }, 260 },
261 { 261 {
262 .name = "passin", 262 .name = "passin",
263 .argname = "src", 263 .argname = "src",
264 .desc = "Private key password source", 264 .desc = "Private key password source",
265 .type = OPTION_ARG, 265 .type = OPTION_ARG,
266 .opt.arg = &ts_config.passin, 266 .opt.arg = &cfg.passin,
267 }, 267 },
268 { 268 {
269 .name = "policy", 269 .name = "policy",
270 .argname = "object_id", 270 .argname = "object_id",
271 .desc = "Policy for the TSA to use when creating the time stamp token", 271 .desc = "Policy for the TSA to use when creating the time stamp token",
272 .type = OPTION_ARG, 272 .type = OPTION_ARG,
273 .opt.arg = &ts_config.policy, 273 .opt.arg = &cfg.policy,
274 }, 274 },
275 { 275 {
276 .name = "query", 276 .name = "query",
@@ -283,7 +283,7 @@ static const struct option ts_options[] = {
283 .argname = "file", 283 .argname = "file",
284 .desc = "File containing a DER-encoded time stamp request", 284 .desc = "File containing a DER-encoded time stamp request",
285 .type = OPTION_ARG, 285 .type = OPTION_ARG,
286 .opt.arg = &ts_config.queryfile, 286 .opt.arg = &cfg.queryfile,
287 }, 287 },
288 { 288 {
289 .name = "reply", 289 .name = "reply",
@@ -296,39 +296,39 @@ static const struct option ts_options[] = {
296 .argname = "arg", 296 .argname = "arg",
297 .desc = "TSA section containing the settings for response generation", 297 .desc = "TSA section containing the settings for response generation",
298 .type = OPTION_ARG, 298 .type = OPTION_ARG,
299 .opt.arg = &ts_config.section, 299 .opt.arg = &cfg.section,
300 }, 300 },
301 { 301 {
302 .name = "signer", 302 .name = "signer",
303 .argname = "file", 303 .argname = "file",
304 .desc = "Signer certificate file", 304 .desc = "Signer certificate file",
305 .type = OPTION_ARG, 305 .type = OPTION_ARG,
306 .opt.arg = &ts_config.signer, 306 .opt.arg = &cfg.signer,
307 }, 307 },
308 { 308 {
309 .name = "text", 309 .name = "text",
310 .desc = "Output in human-readable text format", 310 .desc = "Output in human-readable text format",
311 .type = OPTION_FLAG, 311 .type = OPTION_FLAG,
312 .opt.flag = &ts_config.text, 312 .opt.flag = &cfg.text,
313 }, 313 },
314 { 314 {
315 .name = "token_in", 315 .name = "token_in",
316 .desc = "Input is a DER-encoded time stamp token", 316 .desc = "Input is a DER-encoded time stamp token",
317 .type = OPTION_FLAG, 317 .type = OPTION_FLAG,
318 .opt.flag = &ts_config.token_in, 318 .opt.flag = &cfg.token_in,
319 }, 319 },
320 { 320 {
321 .name = "token_out", 321 .name = "token_out",
322 .desc = "Output is a DER-encoded time stamp token", 322 .desc = "Output is a DER-encoded time stamp token",
323 .type = OPTION_FLAG, 323 .type = OPTION_FLAG,
324 .opt.flag = &ts_config.token_out, 324 .opt.flag = &cfg.token_out,
325 }, 325 },
326 { 326 {
327 .name = "untrusted", 327 .name = "untrusted",
328 .argname = "file", 328 .argname = "file",
329 .desc = "File containing untrusted certificates", 329 .desc = "File containing untrusted certificates",
330 .type = OPTION_ARG, 330 .type = OPTION_ARG,
331 .opt.arg = &ts_config.untrusted, 331 .opt.arg = &cfg.untrusted,
332 }, 332 },
333 { 333 {
334 .name = "verify", 334 .name = "verify",
@@ -382,15 +382,15 @@ ts_main(int argc, char **argv)
382 exit(1); 382 exit(1);
383 } 383 }
384 384
385 memset(&ts_config, 0, sizeof(ts_config)); 385 memset(&cfg, 0, sizeof(cfg));
386 ts_config.mode = CMD_NONE; 386 cfg.mode = CMD_NONE;
387 387
388 if (options_parse(argc, argv, ts_options, NULL, NULL) != 0) 388 if (options_parse(argc, argv, ts_options, NULL, NULL) != 0)
389 goto usage; 389 goto usage;
390 390
391 /* Get the password if required. */ 391 /* Get the password if required. */
392 if (ts_config.mode == CMD_REPLY && ts_config.passin != NULL && 392 if (cfg.mode == CMD_REPLY && cfg.passin != NULL &&
393 !app_passwd(bio_err, ts_config.passin, NULL, &password, NULL)) { 393 !app_passwd(bio_err, cfg.passin, NULL, &password, NULL)) {
394 BIO_printf(bio_err, "Error getting password.\n"); 394 BIO_printf(bio_err, "Error getting password.\n");
395 goto cleanup; 395 goto cleanup;
396 } 396 }
@@ -398,7 +398,7 @@ ts_main(int argc, char **argv)
398 * Check consistency of parameters and execute the appropriate 398 * Check consistency of parameters and execute the appropriate
399 * function. 399 * function.
400 */ 400 */
401 switch (ts_config.mode) { 401 switch (cfg.mode) {
402 case CMD_NONE: 402 case CMD_NONE:
403 goto usage; 403 goto usage;
404 case CMD_QUERY: 404 case CMD_QUERY:
@@ -406,50 +406,50 @@ ts_main(int argc, char **argv)
406 * Data file and message imprint cannot be specified at the 406 * Data file and message imprint cannot be specified at the
407 * same time. 407 * same time.
408 */ 408 */
409 ret = ts_config.data != NULL && ts_config.digest != NULL; 409 ret = cfg.data != NULL && cfg.digest != NULL;
410 if (ret) 410 if (ret)
411 goto usage; 411 goto usage;
412 /* Load the config file for possible policy OIDs. */ 412 /* Load the config file for possible policy OIDs. */
413 conf = load_config_file(ts_config.configfile); 413 conf = load_config_file(cfg.configfile);
414 ret = !query_command(ts_config.data, ts_config.digest, 414 ret = !query_command(cfg.data, cfg.digest,
415 ts_config.md, ts_config.policy, ts_config.no_nonce, 415 cfg.md, cfg.policy, cfg.no_nonce,
416 ts_config.cert, ts_config.in, ts_config.out, 416 cfg.cert, cfg.in, cfg.out,
417 ts_config.text); 417 cfg.text);
418 break; 418 break;
419 case CMD_REPLY: 419 case CMD_REPLY:
420 conf = load_config_file(ts_config.configfile); 420 conf = load_config_file(cfg.configfile);
421 if (ts_config.in == NULL) { 421 if (cfg.in == NULL) {
422 ret = !(ts_config.queryfile != NULL && conf != NULL && 422 ret = !(cfg.queryfile != NULL && conf != NULL &&
423 !ts_config.token_in); 423 !cfg.token_in);
424 if (ret) 424 if (ret)
425 goto usage; 425 goto usage;
426 } else { 426 } else {
427 /* 'in' and 'queryfile' are exclusive. */ 427 /* 'in' and 'queryfile' are exclusive. */
428 ret = !(ts_config.queryfile == NULL); 428 ret = !(cfg.queryfile == NULL);
429 if (ret) 429 if (ret)
430 goto usage; 430 goto usage;
431 } 431 }
432 432
433 ret = !reply_command(conf, ts_config.section, 433 ret = !reply_command(conf, cfg.section,
434 ts_config.queryfile, password, ts_config.inkey, 434 cfg.queryfile, password, cfg.inkey,
435 ts_config.signer, ts_config.chain, ts_config.policy, 435 cfg.signer, cfg.chain, cfg.policy,
436 ts_config.in, ts_config.token_in, ts_config.out, 436 cfg.in, cfg.token_in, cfg.out,
437 ts_config.token_out, ts_config.text); 437 cfg.token_out, cfg.text);
438 break; 438 break;
439 case CMD_VERIFY: 439 case CMD_VERIFY:
440 ret = !(((ts_config.queryfile != NULL && ts_config.data == NULL && 440 ret = !(((cfg.queryfile != NULL && cfg.data == NULL &&
441 ts_config.digest == NULL) || 441 cfg.digest == NULL) ||
442 (ts_config.queryfile == NULL && ts_config.data != NULL && 442 (cfg.queryfile == NULL && cfg.data != NULL &&
443 ts_config.digest == NULL) || 443 cfg.digest == NULL) ||
444 (ts_config.queryfile == NULL && ts_config.data == NULL && 444 (cfg.queryfile == NULL && cfg.data == NULL &&
445 ts_config.digest != NULL)) && 445 cfg.digest != NULL)) &&
446 ts_config.in != NULL); 446 cfg.in != NULL);
447 if (ret) 447 if (ret)
448 goto usage; 448 goto usage;
449 449
450 ret = !verify_command(ts_config.data, ts_config.digest, 450 ret = !verify_command(cfg.data, cfg.digest,
451 ts_config.queryfile, ts_config.in, ts_config.token_in, 451 cfg.queryfile, cfg.in, cfg.token_in,
452 ts_config.ca_path, ts_config.ca_file, ts_config.untrusted); 452 cfg.ca_path, cfg.ca_file, cfg.untrusted);
453 } 453 }
454 454
455 goto cleanup; 455 goto cleanup;