summaryrefslogtreecommitdiff
path: root/src/usr.bin/openssl/pkcs7.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/usr.bin/openssl/pkcs7.c')
-rw-r--r--src/usr.bin/openssl/pkcs7.c58
1 files changed, 29 insertions, 29 deletions
diff --git a/src/usr.bin/openssl/pkcs7.c b/src/usr.bin/openssl/pkcs7.c
index b0acf3fd98..4e66855a8d 100644
--- a/src/usr.bin/openssl/pkcs7.c
+++ b/src/usr.bin/openssl/pkcs7.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pkcs7.c,v 1.13 2023/02/08 07:59:24 tb Exp $ */ 1/* $OpenBSD: pkcs7.c,v 1.14 2023/03/06 14:32:06 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 *
@@ -79,7 +79,7 @@ static struct {
79 int p7_print; 79 int p7_print;
80 int print_certs; 80 int print_certs;
81 int text; 81 int text;
82} pkcs7_config; 82} cfg;
83 83
84static const struct option pkcs7_options[] = { 84static const struct option pkcs7_options[] = {
85 { 85 {
@@ -87,52 +87,52 @@ static const struct option pkcs7_options[] = {
87 .argname = "file", 87 .argname = "file",
88 .desc = "Input file (default stdin)", 88 .desc = "Input file (default stdin)",
89 .type = OPTION_ARG, 89 .type = OPTION_ARG,
90 .opt.arg = &pkcs7_config.infile, 90 .opt.arg = &cfg.infile,
91 }, 91 },
92 { 92 {
93 .name = "inform", 93 .name = "inform",
94 .argname = "format", 94 .argname = "format",
95 .desc = "Input format (DER or PEM (default))", 95 .desc = "Input format (DER or PEM (default))",
96 .type = OPTION_ARG_FORMAT, 96 .type = OPTION_ARG_FORMAT,
97 .opt.value = &pkcs7_config.informat, 97 .opt.value = &cfg.informat,
98 }, 98 },
99 { 99 {
100 .name = "noout", 100 .name = "noout",
101 .desc = "Do not output encoded version of PKCS#7 structure", 101 .desc = "Do not output encoded version of PKCS#7 structure",
102 .type = OPTION_FLAG, 102 .type = OPTION_FLAG,
103 .opt.flag = &pkcs7_config.noout, 103 .opt.flag = &cfg.noout,
104 }, 104 },
105 { 105 {
106 .name = "out", 106 .name = "out",
107 .argname = "file", 107 .argname = "file",
108 .desc = "Output file (default stdout)", 108 .desc = "Output file (default stdout)",
109 .type = OPTION_ARG, 109 .type = OPTION_ARG,
110 .opt.arg = &pkcs7_config.outfile, 110 .opt.arg = &cfg.outfile,
111 }, 111 },
112 { 112 {
113 .name = "outform", 113 .name = "outform",
114 .argname = "format", 114 .argname = "format",
115 .desc = "Output format (DER or PEM (default))", 115 .desc = "Output format (DER or PEM (default))",
116 .type = OPTION_ARG_FORMAT, 116 .type = OPTION_ARG_FORMAT,
117 .opt.value = &pkcs7_config.outformat, 117 .opt.value = &cfg.outformat,
118 }, 118 },
119 { 119 {
120 .name = "print", 120 .name = "print",
121 .desc = "Output ASN.1 representation of PKCS#7 structure", 121 .desc = "Output ASN.1 representation of PKCS#7 structure",
122 .type = OPTION_FLAG, 122 .type = OPTION_FLAG,
123 .opt.flag = &pkcs7_config.p7_print, 123 .opt.flag = &cfg.p7_print,
124 }, 124 },
125 { 125 {
126 .name = "print_certs", 126 .name = "print_certs",
127 .desc = "Print out any certificates or CRLs contained in file", 127 .desc = "Print out any certificates or CRLs contained in file",
128 .type = OPTION_FLAG, 128 .type = OPTION_FLAG,
129 .opt.flag = &pkcs7_config.print_certs, 129 .opt.flag = &cfg.print_certs,
130 }, 130 },
131 { 131 {
132 .name = "text", 132 .name = "text",
133 .desc = "Print out full certificate details", 133 .desc = "Print out full certificate details",
134 .type = OPTION_FLAG, 134 .type = OPTION_FLAG,
135 .opt.flag = &pkcs7_config.text, 135 .opt.flag = &cfg.text,
136 }, 136 },
137 { NULL }, 137 { NULL },
138}; 138};
@@ -159,10 +159,10 @@ pkcs7_main(int argc, char **argv)
159 exit(1); 159 exit(1);
160 } 160 }
161 161
162 memset(&pkcs7_config, 0, sizeof(pkcs7_config)); 162 memset(&cfg, 0, sizeof(cfg));
163 163
164 pkcs7_config.informat = FORMAT_PEM; 164 cfg.informat = FORMAT_PEM;
165 pkcs7_config.outformat = FORMAT_PEM; 165 cfg.outformat = FORMAT_PEM;
166 166
167 if (options_parse(argc, argv, pkcs7_options, NULL, NULL) != 0) { 167 if (options_parse(argc, argv, pkcs7_options, NULL, NULL) != 0) {
168 pkcs7_usage(); 168 pkcs7_usage();
@@ -175,18 +175,18 @@ pkcs7_main(int argc, char **argv)
175 ERR_print_errors(bio_err); 175 ERR_print_errors(bio_err);
176 goto end; 176 goto end;
177 } 177 }
178 if (pkcs7_config.infile == NULL) 178 if (cfg.infile == NULL)
179 BIO_set_fp(in, stdin, BIO_NOCLOSE); 179 BIO_set_fp(in, stdin, BIO_NOCLOSE);
180 else { 180 else {
181 if (BIO_read_filename(in, pkcs7_config.infile) <= 0) { 181 if (BIO_read_filename(in, cfg.infile) <= 0) {
182 perror(pkcs7_config.infile); 182 perror(cfg.infile);
183 goto end; 183 goto end;
184 } 184 }
185 } 185 }
186 186
187 if (pkcs7_config.informat == FORMAT_ASN1) 187 if (cfg.informat == FORMAT_ASN1)
188 p7 = d2i_PKCS7_bio(in, NULL); 188 p7 = d2i_PKCS7_bio(in, NULL);
189 else if (pkcs7_config.informat == FORMAT_PEM) 189 else if (cfg.informat == FORMAT_PEM)
190 p7 = PEM_read_bio_PKCS7(in, NULL, NULL, NULL); 190 p7 = PEM_read_bio_PKCS7(in, NULL, NULL, NULL);
191 else { 191 else {
192 BIO_printf(bio_err, "bad input format specified for pkcs7 object\n"); 192 BIO_printf(bio_err, "bad input format specified for pkcs7 object\n");
@@ -197,19 +197,19 @@ pkcs7_main(int argc, char **argv)
197 ERR_print_errors(bio_err); 197 ERR_print_errors(bio_err);
198 goto end; 198 goto end;
199 } 199 }
200 if (pkcs7_config.outfile == NULL) { 200 if (cfg.outfile == NULL) {
201 BIO_set_fp(out, stdout, BIO_NOCLOSE); 201 BIO_set_fp(out, stdout, BIO_NOCLOSE);
202 } else { 202 } else {
203 if (BIO_write_filename(out, pkcs7_config.outfile) <= 0) { 203 if (BIO_write_filename(out, cfg.outfile) <= 0) {
204 perror(pkcs7_config.outfile); 204 perror(cfg.outfile);
205 goto end; 205 goto end;
206 } 206 }
207 } 207 }
208 208
209 if (pkcs7_config.p7_print) 209 if (cfg.p7_print)
210 PKCS7_print_ctx(out, p7, 0, NULL); 210 PKCS7_print_ctx(out, p7, 0, NULL);
211 211
212 if (pkcs7_config.print_certs) { 212 if (cfg.print_certs) {
213 STACK_OF(X509) * certs = NULL; 213 STACK_OF(X509) * certs = NULL;
214 STACK_OF(X509_CRL) * crls = NULL; 214 STACK_OF(X509_CRL) * crls = NULL;
215 215
@@ -236,12 +236,12 @@ pkcs7_main(int argc, char **argv)
236 236
237 for (i = 0; i < sk_X509_num(certs); i++) { 237 for (i = 0; i < sk_X509_num(certs); i++) {
238 x = sk_X509_value(certs, i); 238 x = sk_X509_value(certs, i);
239 if (pkcs7_config.text) 239 if (cfg.text)
240 X509_print(out, x); 240 X509_print(out, x);
241 else 241 else
242 dump_cert_text(out, x); 242 dump_cert_text(out, x);
243 243
244 if (!pkcs7_config.noout) 244 if (!cfg.noout)
245 PEM_write_bio_X509(out, x); 245 PEM_write_bio_X509(out, x);
246 BIO_puts(out, "\n"); 246 BIO_puts(out, "\n");
247 } 247 }
@@ -254,7 +254,7 @@ pkcs7_main(int argc, char **argv)
254 254
255 X509_CRL_print(out, crl); 255 X509_CRL_print(out, crl);
256 256
257 if (!pkcs7_config.noout) 257 if (!cfg.noout)
258 PEM_write_bio_X509_CRL(out, crl); 258 PEM_write_bio_X509_CRL(out, crl);
259 BIO_puts(out, "\n"); 259 BIO_puts(out, "\n");
260 } 260 }
@@ -262,10 +262,10 @@ pkcs7_main(int argc, char **argv)
262 ret = 0; 262 ret = 0;
263 goto end; 263 goto end;
264 } 264 }
265 if (!pkcs7_config.noout) { 265 if (!cfg.noout) {
266 if (pkcs7_config.outformat == FORMAT_ASN1) 266 if (cfg.outformat == FORMAT_ASN1)
267 i = i2d_PKCS7_bio(out, p7); 267 i = i2d_PKCS7_bio(out, p7);
268 else if (pkcs7_config.outformat == FORMAT_PEM) 268 else if (cfg.outformat == FORMAT_PEM)
269 i = PEM_write_bio_PKCS7(out, p7); 269 i = PEM_write_bio_PKCS7(out, p7);
270 else { 270 else {
271 BIO_printf(bio_err, "bad output format specified for outfile\n"); 271 BIO_printf(bio_err, "bad output format specified for outfile\n");