summaryrefslogtreecommitdiff
path: root/src/usr.bin/openssl/crl.c
diff options
context:
space:
mode:
authortb <>2023-03-06 14:32:06 +0000
committertb <>2023-03-06 14:32:06 +0000
commit6c965e26b1a93da63948edae6b68564be1ded507 (patch)
treebbe07d6e06b695cebe22802551f2db0a61354d7c /src/usr.bin/openssl/crl.c
parent48e828ea26ee91710242131cd75cd9d1d20b773c (diff)
downloadopenbsd-6c965e26b1a93da63948edae6b68564be1ded507.tar.gz
openbsd-6c965e26b1a93da63948edae6b68564be1ded507.tar.bz2
openbsd-6c965e26b1a93da63948edae6b68564be1ded507.zip
Rename struct ${app}_config to plain cfg
All the structs are static and we need to reach into them many times. Having a shorter name is more concise and results in less visual clutter. It also avoids many overlong lines and we will be able to get rid of some unfortunate line wrapping down the road. Discussed with jsing
Diffstat (limited to 'src/usr.bin/openssl/crl.c')
-rw-r--r--src/usr.bin/openssl/crl.c90
1 files changed, 45 insertions, 45 deletions
diff --git a/src/usr.bin/openssl/crl.c b/src/usr.bin/openssl/crl.c
index 6b7bc5b72e..e64038dfda 100644
--- a/src/usr.bin/openssl/crl.c
+++ b/src/usr.bin/openssl/crl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: crl.c,v 1.16 2022/11/11 17:07:38 joshua Exp $ */ 1/* $OpenBSD: crl.c,v 1.17 2023/03/06 14:32:05 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -86,7 +86,7 @@ static struct {
86 int outformat; 86 int outformat;
87 int text; 87 int text;
88 int verify; 88 int verify;
89} crl_config; 89} cfg;
90 90
91static const struct option crl_options[] = { 91static const struct option crl_options[] = {
92 { 92 {
@@ -94,109 +94,109 @@ static const struct option crl_options[] = {
94 .argname = "file", 94 .argname = "file",
95 .desc = "Verify the CRL using certificates in the given file", 95 .desc = "Verify the CRL using certificates in the given file",
96 .type = OPTION_ARG, 96 .type = OPTION_ARG,
97 .opt.arg = &crl_config.cafile, 97 .opt.arg = &cfg.cafile,
98 }, 98 },
99 { 99 {
100 .name = "CApath", 100 .name = "CApath",
101 .argname = "path", 101 .argname = "path",
102 .desc = "Verify the CRL using certificates in the given path", 102 .desc = "Verify the CRL using certificates in the given path",
103 .type = OPTION_ARG, 103 .type = OPTION_ARG,
104 .opt.arg = &crl_config.capath, 104 .opt.arg = &cfg.capath,
105 }, 105 },
106 { 106 {
107 .name = "crlnumber", 107 .name = "crlnumber",
108 .desc = "Print the CRL number", 108 .desc = "Print the CRL number",
109 .type = OPTION_FLAG_ORD, 109 .type = OPTION_FLAG_ORD,
110 .opt.flag = &crl_config.crlnumber, 110 .opt.flag = &cfg.crlnumber,
111 }, 111 },
112 { 112 {
113 .name = "fingerprint", 113 .name = "fingerprint",
114 .desc = "Print the CRL fingerprint", 114 .desc = "Print the CRL fingerprint",
115 .type = OPTION_FLAG_ORD, 115 .type = OPTION_FLAG_ORD,
116 .opt.flag = &crl_config.fingerprint, 116 .opt.flag = &cfg.fingerprint,
117 }, 117 },
118 { 118 {
119 .name = "hash", 119 .name = "hash",
120 .desc = "Print the hash of the issuer name", 120 .desc = "Print the hash of the issuer name",
121 .type = OPTION_FLAG_ORD, 121 .type = OPTION_FLAG_ORD,
122 .opt.flag = &crl_config.hash, 122 .opt.flag = &cfg.hash,
123 }, 123 },
124 { 124 {
125 .name = "hash_old", 125 .name = "hash_old",
126 .desc = "Print an old-style (MD5) hash of the issuer name", 126 .desc = "Print an old-style (MD5) hash of the issuer name",
127 .type = OPTION_FLAG_ORD, 127 .type = OPTION_FLAG_ORD,
128 .opt.flag = &crl_config.hash_old, 128 .opt.flag = &cfg.hash_old,
129 }, 129 },
130 { 130 {
131 .name = "in", 131 .name = "in",
132 .argname = "file", 132 .argname = "file",
133 .desc = "Input file to read from (stdin if unspecified)", 133 .desc = "Input file to read from (stdin if unspecified)",
134 .type = OPTION_ARG, 134 .type = OPTION_ARG,
135 .opt.arg = &crl_config.infile, 135 .opt.arg = &cfg.infile,
136 }, 136 },
137 { 137 {
138 .name = "inform", 138 .name = "inform",
139 .argname = "format", 139 .argname = "format",
140 .desc = "Input format (DER or PEM)", 140 .desc = "Input format (DER or PEM)",
141 .type = OPTION_ARG_FORMAT, 141 .type = OPTION_ARG_FORMAT,
142 .opt.value = &crl_config.informat, 142 .opt.value = &cfg.informat,
143 }, 143 },
144 { 144 {
145 .name = "issuer", 145 .name = "issuer",
146 .desc = "Print the issuer name", 146 .desc = "Print the issuer name",
147 .type = OPTION_FLAG_ORD, 147 .type = OPTION_FLAG_ORD,
148 .opt.flag = &crl_config.issuer, 148 .opt.flag = &cfg.issuer,
149 }, 149 },
150 { 150 {
151 .name = "lastupdate", 151 .name = "lastupdate",
152 .desc = "Print the lastUpdate field", 152 .desc = "Print the lastUpdate field",
153 .type = OPTION_FLAG_ORD, 153 .type = OPTION_FLAG_ORD,
154 .opt.flag = &crl_config.lastupdate, 154 .opt.flag = &cfg.lastupdate,
155 }, 155 },
156 { 156 {
157 .name = "nameopt", 157 .name = "nameopt",
158 .argname = "options", 158 .argname = "options",
159 .desc = "Specify certificate name options", 159 .desc = "Specify certificate name options",
160 .type = OPTION_ARG, 160 .type = OPTION_ARG,
161 .opt.arg = &crl_config.nameopt, 161 .opt.arg = &cfg.nameopt,
162 }, 162 },
163 { 163 {
164 .name = "nextupdate", 164 .name = "nextupdate",
165 .desc = "Print the nextUpdate field", 165 .desc = "Print the nextUpdate field",
166 .type = OPTION_FLAG_ORD, 166 .type = OPTION_FLAG_ORD,
167 .opt.flag = &crl_config.nextupdate, 167 .opt.flag = &cfg.nextupdate,
168 }, 168 },
169 { 169 {
170 .name = "noout", 170 .name = "noout",
171 .desc = "Do not output the encoded version of the CRL", 171 .desc = "Do not output the encoded version of the CRL",
172 .type = OPTION_FLAG, 172 .type = OPTION_FLAG,
173 .opt.flag = &crl_config.noout, 173 .opt.flag = &cfg.noout,
174 }, 174 },
175 { 175 {
176 .name = "out", 176 .name = "out",
177 .argname = "file", 177 .argname = "file",
178 .desc = "Output file to write to (stdout if unspecified)", 178 .desc = "Output file to write to (stdout if unspecified)",
179 .type = OPTION_ARG, 179 .type = OPTION_ARG,
180 .opt.arg = &crl_config.outfile, 180 .opt.arg = &cfg.outfile,
181 }, 181 },
182 { 182 {
183 .name = "outform", 183 .name = "outform",
184 .argname = "format", 184 .argname = "format",
185 .desc = "Output format (DER or PEM)", 185 .desc = "Output format (DER or PEM)",
186 .type = OPTION_ARG_FORMAT, 186 .type = OPTION_ARG_FORMAT,
187 .opt.value = &crl_config.outformat, 187 .opt.value = &cfg.outformat,
188 }, 188 },
189 { 189 {
190 .name = "text", 190 .name = "text",
191 .desc = "Print out the CRL in text form", 191 .desc = "Print out the CRL in text form",
192 .type = OPTION_FLAG, 192 .type = OPTION_FLAG,
193 .opt.flag = &crl_config.text, 193 .opt.flag = &cfg.text,
194 }, 194 },
195 { 195 {
196 .name = "verify", 196 .name = "verify",
197 .desc = "Verify the signature on the CRL", 197 .desc = "Verify the signature on the CRL",
198 .type = OPTION_FLAG, 198 .type = OPTION_FLAG,
199 .opt.flag = &crl_config.verify, 199 .opt.flag = &cfg.verify,
200 }, 200 },
201 {NULL}, 201 {NULL},
202}; 202};
@@ -243,23 +243,23 @@ crl_main(int argc, char **argv)
243 243
244 digest = EVP_sha256(); 244 digest = EVP_sha256();
245 245
246 memset(&crl_config, 0, sizeof(crl_config)); 246 memset(&cfg, 0, sizeof(cfg));
247 crl_config.informat = FORMAT_PEM; 247 cfg.informat = FORMAT_PEM;
248 crl_config.outformat = FORMAT_PEM; 248 cfg.outformat = FORMAT_PEM;
249 249
250 if (options_parse(argc, argv, crl_options, &digest_name, NULL) != 0) { 250 if (options_parse(argc, argv, crl_options, &digest_name, NULL) != 0) {
251 crl_usage(); 251 crl_usage();
252 goto end; 252 goto end;
253 } 253 }
254 254
255 if (crl_config.cafile != NULL || crl_config.capath != NULL) 255 if (cfg.cafile != NULL || cfg.capath != NULL)
256 crl_config.verify = 1; 256 cfg.verify = 1;
257 257
258 if (crl_config.nameopt != NULL) { 258 if (cfg.nameopt != NULL) {
259 if (set_name_ex(&nmflag, crl_config.nameopt) != 1) { 259 if (set_name_ex(&nmflag, cfg.nameopt) != 1) {
260 fprintf(stderr, 260 fprintf(stderr,
261 "Invalid -nameopt argument '%s'\n", 261 "Invalid -nameopt argument '%s'\n",
262 crl_config.nameopt); 262 cfg.nameopt);
263 goto end; 263 goto end;
264 } 264 }
265 } 265 }
@@ -273,18 +273,18 @@ crl_main(int argc, char **argv)
273 } 273 }
274 } 274 }
275 275
276 x = load_crl(crl_config.infile, crl_config.informat); 276 x = load_crl(cfg.infile, cfg.informat);
277 if (x == NULL) 277 if (x == NULL)
278 goto end; 278 goto end;
279 279
280 if (crl_config.verify) { 280 if (cfg.verify) {
281 store = X509_STORE_new(); 281 store = X509_STORE_new();
282 if (store == NULL) 282 if (store == NULL)
283 goto end; 283 goto end;
284 lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()); 284 lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file());
285 if (lookup == NULL) 285 if (lookup == NULL)
286 goto end; 286 goto end;
287 if (!X509_LOOKUP_load_file(lookup, crl_config.cafile, 287 if (!X509_LOOKUP_load_file(lookup, cfg.cafile,
288 X509_FILETYPE_PEM)) 288 X509_FILETYPE_PEM))
289 X509_LOOKUP_load_file(lookup, NULL, 289 X509_LOOKUP_load_file(lookup, NULL,
290 X509_FILETYPE_DEFAULT); 290 X509_FILETYPE_DEFAULT);
@@ -292,7 +292,7 @@ crl_main(int argc, char **argv)
292 lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir()); 292 lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir());
293 if (lookup == NULL) 293 if (lookup == NULL)
294 goto end; 294 goto end;
295 if (!X509_LOOKUP_add_dir(lookup, crl_config.capath, 295 if (!X509_LOOKUP_add_dir(lookup, cfg.capath,
296 X509_FILETYPE_PEM)) 296 X509_FILETYPE_PEM))
297 X509_LOOKUP_add_dir(lookup, NULL, 297 X509_LOOKUP_add_dir(lookup, NULL,
298 X509_FILETYPE_DEFAULT); 298 X509_FILETYPE_DEFAULT);
@@ -335,11 +335,11 @@ crl_main(int argc, char **argv)
335 335
336 /* Print requested information the order that the flags were given. */ 336 /* Print requested information the order that the flags were given. */
337 for (i = 1; i <= argc; i++) { 337 for (i = 1; i <= argc; i++) {
338 if (crl_config.issuer == i) { 338 if (cfg.issuer == i) {
339 print_name(bio_out, "issuer=", 339 print_name(bio_out, "issuer=",
340 X509_CRL_get_issuer(x), nmflag); 340 X509_CRL_get_issuer(x), nmflag);
341 } 341 }
342 if (crl_config.crlnumber == i) { 342 if (cfg.crlnumber == i) {
343 ASN1_INTEGER *crlnum; 343 ASN1_INTEGER *crlnum;
344 crlnum = X509_CRL_get_ext_d2i(x, 344 crlnum = X509_CRL_get_ext_d2i(x,
345 NID_crl_number, NULL, NULL); 345 NID_crl_number, NULL, NULL);
@@ -351,23 +351,23 @@ crl_main(int argc, char **argv)
351 BIO_puts(bio_out, "<NONE>"); 351 BIO_puts(bio_out, "<NONE>");
352 BIO_printf(bio_out, "\n"); 352 BIO_printf(bio_out, "\n");
353 } 353 }
354 if (crl_config.hash == i) { 354 if (cfg.hash == i) {
355 BIO_printf(bio_out, "%08lx\n", 355 BIO_printf(bio_out, "%08lx\n",
356 X509_NAME_hash(X509_CRL_get_issuer(x))); 356 X509_NAME_hash(X509_CRL_get_issuer(x)));
357 } 357 }
358#ifndef OPENSSL_NO_MD5 358#ifndef OPENSSL_NO_MD5
359 if (crl_config.hash_old == i) { 359 if (cfg.hash_old == i) {
360 BIO_printf(bio_out, "%08lx\n", 360 BIO_printf(bio_out, "%08lx\n",
361 X509_NAME_hash_old(X509_CRL_get_issuer(x))); 361 X509_NAME_hash_old(X509_CRL_get_issuer(x)));
362 } 362 }
363#endif 363#endif
364 if (crl_config.lastupdate == i) { 364 if (cfg.lastupdate == i) {
365 BIO_printf(bio_out, "lastUpdate="); 365 BIO_printf(bio_out, "lastUpdate=");
366 ASN1_TIME_print(bio_out, 366 ASN1_TIME_print(bio_out,
367 X509_CRL_get_lastUpdate(x)); 367 X509_CRL_get_lastUpdate(x));
368 BIO_printf(bio_out, "\n"); 368 BIO_printf(bio_out, "\n");
369 } 369 }
370 if (crl_config.nextupdate == i) { 370 if (cfg.nextupdate == i) {
371 BIO_printf(bio_out, "nextUpdate="); 371 BIO_printf(bio_out, "nextUpdate=");
372 if (X509_CRL_get_nextUpdate(x)) 372 if (X509_CRL_get_nextUpdate(x))
373 ASN1_TIME_print(bio_out, 373 ASN1_TIME_print(bio_out,
@@ -376,7 +376,7 @@ crl_main(int argc, char **argv)
376 BIO_printf(bio_out, "NONE"); 376 BIO_printf(bio_out, "NONE");
377 BIO_printf(bio_out, "\n"); 377 BIO_printf(bio_out, "\n");
378 } 378 }
379 if (crl_config.fingerprint == i) { 379 if (cfg.fingerprint == i) {
380 int j; 380 int j;
381 unsigned int n; 381 unsigned int n;
382 unsigned char md[EVP_MAX_MD_SIZE]; 382 unsigned char md[EVP_MAX_MD_SIZE];
@@ -399,25 +399,25 @@ crl_main(int argc, char **argv)
399 ERR_print_errors(bio_err); 399 ERR_print_errors(bio_err);
400 goto end; 400 goto end;
401 } 401 }
402 if (crl_config.outfile == NULL) { 402 if (cfg.outfile == NULL) {
403 BIO_set_fp(out, stdout, BIO_NOCLOSE); 403 BIO_set_fp(out, stdout, BIO_NOCLOSE);
404 } else { 404 } else {
405 if (BIO_write_filename(out, crl_config.outfile) <= 0) { 405 if (BIO_write_filename(out, cfg.outfile) <= 0) {
406 perror(crl_config.outfile); 406 perror(cfg.outfile);
407 goto end; 407 goto end;
408 } 408 }
409 } 409 }
410 410
411 if (crl_config.text) 411 if (cfg.text)
412 X509_CRL_print(out, x); 412 X509_CRL_print(out, x);
413 413
414 if (crl_config.noout) { 414 if (cfg.noout) {
415 ret = 0; 415 ret = 0;
416 goto end; 416 goto end;
417 } 417 }
418 if (crl_config.outformat == FORMAT_ASN1) 418 if (cfg.outformat == FORMAT_ASN1)
419 i = (int) i2d_X509_CRL_bio(out, x); 419 i = (int) i2d_X509_CRL_bio(out, x);
420 else if (crl_config.outformat == FORMAT_PEM) 420 else if (cfg.outformat == FORMAT_PEM)
421 i = PEM_write_bio_X509_CRL(out, x); 421 i = PEM_write_bio_X509_CRL(out, x);
422 else { 422 else {
423 BIO_printf(bio_err, 423 BIO_printf(bio_err,