diff options
Diffstat (limited to 'src/usr.bin/openssl/spkac.c')
-rw-r--r-- | src/usr.bin/openssl/spkac.c | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/src/usr.bin/openssl/spkac.c b/src/usr.bin/openssl/spkac.c index 3a45d5d4bc..12d530e3cf 100644 --- a/src/usr.bin/openssl/spkac.c +++ b/src/usr.bin/openssl/spkac.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: spkac.c,v 1.12 2022/11/11 17:07:39 joshua Exp $ */ | 1 | /* $OpenBSD: spkac.c,v 1.13 2023/03/06 14:32:06 tb Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 1999. Based on an original idea by Massimiliano Pala | 3 | * project 1999. Based on an original idea by Massimiliano Pala |
4 | * (madwolf@openca.org). | 4 | * (madwolf@openca.org). |
@@ -84,7 +84,7 @@ static struct { | |||
84 | char *spkac; | 84 | char *spkac; |
85 | char *spksect; | 85 | char *spksect; |
86 | int verify; | 86 | int verify; |
87 | } spkac_config; | 87 | } cfg; |
88 | 88 | ||
89 | static const struct option spkac_options[] = { | 89 | static const struct option spkac_options[] = { |
90 | { | 90 | { |
@@ -92,54 +92,54 @@ static const struct option spkac_options[] = { | |||
92 | .argname = "string", | 92 | .argname = "string", |
93 | .desc = "Specify challenge string if SPKAC is generated", | 93 | .desc = "Specify challenge string if SPKAC is generated", |
94 | .type = OPTION_ARG, | 94 | .type = OPTION_ARG, |
95 | .opt.arg = &spkac_config.challenge, | 95 | .opt.arg = &cfg.challenge, |
96 | }, | 96 | }, |
97 | { | 97 | { |
98 | .name = "in", | 98 | .name = "in", |
99 | .argname = "file", | 99 | .argname = "file", |
100 | .desc = "Input file (default stdin)", | 100 | .desc = "Input file (default stdin)", |
101 | .type = OPTION_ARG, | 101 | .type = OPTION_ARG, |
102 | .opt.arg = &spkac_config.infile, | 102 | .opt.arg = &cfg.infile, |
103 | }, | 103 | }, |
104 | { | 104 | { |
105 | .name = "key", | 105 | .name = "key", |
106 | .argname = "file", | 106 | .argname = "file", |
107 | .desc = "Create SPKAC using private key file", | 107 | .desc = "Create SPKAC using private key file", |
108 | .type = OPTION_ARG, | 108 | .type = OPTION_ARG, |
109 | .opt.arg = &spkac_config.keyfile, | 109 | .opt.arg = &cfg.keyfile, |
110 | }, | 110 | }, |
111 | { | 111 | { |
112 | .name = "noout", | 112 | .name = "noout", |
113 | .desc = "Do not print text version of SPKAC", | 113 | .desc = "Do not print text version of SPKAC", |
114 | .type = OPTION_FLAG, | 114 | .type = OPTION_FLAG, |
115 | .opt.flag = &spkac_config.noout, | 115 | .opt.flag = &cfg.noout, |
116 | }, | 116 | }, |
117 | { | 117 | { |
118 | .name = "out", | 118 | .name = "out", |
119 | .argname = "file", | 119 | .argname = "file", |
120 | .desc = "Output file (default stdout)", | 120 | .desc = "Output file (default stdout)", |
121 | .type = OPTION_ARG, | 121 | .type = OPTION_ARG, |
122 | .opt.arg = &spkac_config.outfile, | 122 | .opt.arg = &cfg.outfile, |
123 | }, | 123 | }, |
124 | { | 124 | { |
125 | .name = "passin", | 125 | .name = "passin", |
126 | .argname = "src", | 126 | .argname = "src", |
127 | .desc = "Input file passphrase source", | 127 | .desc = "Input file passphrase source", |
128 | .type = OPTION_ARG, | 128 | .type = OPTION_ARG, |
129 | .opt.arg = &spkac_config.passargin, | 129 | .opt.arg = &cfg.passargin, |
130 | }, | 130 | }, |
131 | { | 131 | { |
132 | .name = "pubkey", | 132 | .name = "pubkey", |
133 | .desc = "Output public key of an SPKAC (not used if creating)", | 133 | .desc = "Output public key of an SPKAC (not used if creating)", |
134 | .type = OPTION_FLAG, | 134 | .type = OPTION_FLAG, |
135 | .opt.flag = &spkac_config.pubkey, | 135 | .opt.flag = &cfg.pubkey, |
136 | }, | 136 | }, |
137 | { | 137 | { |
138 | .name = "spkac", | 138 | .name = "spkac", |
139 | .argname = "name", | 139 | .argname = "name", |
140 | .desc = "SPKAC name (default \"SPKAC\")", | 140 | .desc = "SPKAC name (default \"SPKAC\")", |
141 | .type = OPTION_ARG, | 141 | .type = OPTION_ARG, |
142 | .opt.arg = &spkac_config.spkac, | 142 | .opt.arg = &cfg.spkac, |
143 | }, | 143 | }, |
144 | { | 144 | { |
145 | .name = "spksect", | 145 | .name = "spksect", |
@@ -147,13 +147,13 @@ static const struct option spkac_options[] = { | |||
147 | .desc = "Name of the section containing SPKAC (default" | 147 | .desc = "Name of the section containing SPKAC (default" |
148 | " \"default\")", | 148 | " \"default\")", |
149 | .type = OPTION_ARG, | 149 | .type = OPTION_ARG, |
150 | .opt.arg = &spkac_config.spksect, | 150 | .opt.arg = &cfg.spksect, |
151 | }, | 151 | }, |
152 | { | 152 | { |
153 | .name = "verify", | 153 | .name = "verify", |
154 | .desc = "Verify digital signature on supplied SPKAC", | 154 | .desc = "Verify digital signature on supplied SPKAC", |
155 | .type = OPTION_FLAG, | 155 | .type = OPTION_FLAG, |
156 | .opt.flag = &spkac_config.verify, | 156 | .opt.flag = &cfg.verify, |
157 | }, | 157 | }, |
158 | { NULL } | 158 | { NULL } |
159 | }; | 159 | }; |
@@ -186,32 +186,32 @@ spkac_main(int argc, char **argv) | |||
186 | exit(1); | 186 | exit(1); |
187 | } | 187 | } |
188 | 188 | ||
189 | memset(&spkac_config, 0, sizeof(spkac_config)); | 189 | memset(&cfg, 0, sizeof(cfg)); |
190 | spkac_config.spkac = "SPKAC"; | 190 | cfg.spkac = "SPKAC"; |
191 | spkac_config.spksect = "default"; | 191 | cfg.spksect = "default"; |
192 | 192 | ||
193 | if (options_parse(argc, argv, spkac_options, NULL, NULL) != 0) { | 193 | if (options_parse(argc, argv, spkac_options, NULL, NULL) != 0) { |
194 | spkac_usage(); | 194 | spkac_usage(); |
195 | return (1); | 195 | return (1); |
196 | } | 196 | } |
197 | 197 | ||
198 | if (!app_passwd(bio_err, spkac_config.passargin, NULL, &passin, NULL)) { | 198 | if (!app_passwd(bio_err, cfg.passargin, NULL, &passin, NULL)) { |
199 | BIO_printf(bio_err, "Error getting password\n"); | 199 | BIO_printf(bio_err, "Error getting password\n"); |
200 | goto end; | 200 | goto end; |
201 | } | 201 | } |
202 | 202 | ||
203 | if (spkac_config.keyfile) { | 203 | if (cfg.keyfile) { |
204 | pkey = load_key(bio_err, | 204 | pkey = load_key(bio_err, |
205 | strcmp(spkac_config.keyfile, "-") ? spkac_config.keyfile | 205 | strcmp(cfg.keyfile, "-") ? cfg.keyfile |
206 | : NULL, FORMAT_PEM, 1, passin, "private key"); | 206 | : NULL, FORMAT_PEM, 1, passin, "private key"); |
207 | if (!pkey) { | 207 | if (!pkey) { |
208 | goto end; | 208 | goto end; |
209 | } | 209 | } |
210 | spki = NETSCAPE_SPKI_new(); | 210 | spki = NETSCAPE_SPKI_new(); |
211 | if (spkac_config.challenge) | 211 | if (cfg.challenge) |
212 | ASN1_STRING_set(spki->spkac->challenge, | 212 | ASN1_STRING_set(spki->spkac->challenge, |
213 | spkac_config.challenge, | 213 | cfg.challenge, |
214 | (int) strlen(spkac_config.challenge)); | 214 | (int) strlen(cfg.challenge)); |
215 | NETSCAPE_SPKI_set_pubkey(spki, pkey); | 215 | NETSCAPE_SPKI_set_pubkey(spki, pkey); |
216 | NETSCAPE_SPKI_sign(spki, pkey, EVP_md5()); | 216 | NETSCAPE_SPKI_sign(spki, pkey, EVP_md5()); |
217 | spkstr = NETSCAPE_SPKI_b64_encode(spki); | 217 | spkstr = NETSCAPE_SPKI_b64_encode(spki); |
@@ -221,8 +221,8 @@ spkac_main(int argc, char **argv) | |||
221 | goto end; | 221 | goto end; |
222 | } | 222 | } |
223 | 223 | ||
224 | if (spkac_config.outfile) | 224 | if (cfg.outfile) |
225 | out = BIO_new_file(spkac_config.outfile, "w"); | 225 | out = BIO_new_file(cfg.outfile, "w"); |
226 | else | 226 | else |
227 | out = BIO_new_fp(stdout, BIO_NOCLOSE); | 227 | out = BIO_new_fp(stdout, BIO_NOCLOSE); |
228 | 228 | ||
@@ -236,8 +236,8 @@ spkac_main(int argc, char **argv) | |||
236 | free(spkstr); | 236 | free(spkstr); |
237 | goto end; | 237 | goto end; |
238 | } | 238 | } |
239 | if (spkac_config.infile) | 239 | if (cfg.infile) |
240 | in = BIO_new_file(spkac_config.infile, "r"); | 240 | in = BIO_new_file(cfg.infile, "r"); |
241 | else | 241 | else |
242 | in = BIO_new_fp(stdin, BIO_NOCLOSE); | 242 | in = BIO_new_fp(stdin, BIO_NOCLOSE); |
243 | 243 | ||
@@ -254,12 +254,12 @@ spkac_main(int argc, char **argv) | |||
254 | ERR_print_errors(bio_err); | 254 | ERR_print_errors(bio_err); |
255 | goto end; | 255 | goto end; |
256 | } | 256 | } |
257 | spkstr = NCONF_get_string(conf, spkac_config.spksect, | 257 | spkstr = NCONF_get_string(conf, cfg.spksect, |
258 | spkac_config.spkac); | 258 | cfg.spkac); |
259 | 259 | ||
260 | if (!spkstr) { | 260 | if (!spkstr) { |
261 | BIO_printf(bio_err, "Can't find SPKAC called \"%s\"\n", | 261 | BIO_printf(bio_err, "Can't find SPKAC called \"%s\"\n", |
262 | spkac_config.spkac); | 262 | cfg.spkac); |
263 | ERR_print_errors(bio_err); | 263 | ERR_print_errors(bio_err); |
264 | goto end; | 264 | goto end; |
265 | } | 265 | } |
@@ -270,8 +270,8 @@ spkac_main(int argc, char **argv) | |||
270 | ERR_print_errors(bio_err); | 270 | ERR_print_errors(bio_err); |
271 | goto end; | 271 | goto end; |
272 | } | 272 | } |
273 | if (spkac_config.outfile) | 273 | if (cfg.outfile) |
274 | out = BIO_new_file(spkac_config.outfile, "w"); | 274 | out = BIO_new_file(cfg.outfile, "w"); |
275 | else { | 275 | else { |
276 | out = BIO_new_fp(stdout, BIO_NOCLOSE); | 276 | out = BIO_new_fp(stdout, BIO_NOCLOSE); |
277 | } | 277 | } |
@@ -281,10 +281,10 @@ spkac_main(int argc, char **argv) | |||
281 | ERR_print_errors(bio_err); | 281 | ERR_print_errors(bio_err); |
282 | goto end; | 282 | goto end; |
283 | } | 283 | } |
284 | if (!spkac_config.noout) | 284 | if (!cfg.noout) |
285 | NETSCAPE_SPKI_print(out, spki); | 285 | NETSCAPE_SPKI_print(out, spki); |
286 | pkey = NETSCAPE_SPKI_get_pubkey(spki); | 286 | pkey = NETSCAPE_SPKI_get_pubkey(spki); |
287 | if (spkac_config.verify) { | 287 | if (cfg.verify) { |
288 | i = NETSCAPE_SPKI_verify(spki, pkey); | 288 | i = NETSCAPE_SPKI_verify(spki, pkey); |
289 | if (i > 0) | 289 | if (i > 0) |
290 | BIO_printf(bio_err, "Signature OK\n"); | 290 | BIO_printf(bio_err, "Signature OK\n"); |
@@ -294,7 +294,7 @@ spkac_main(int argc, char **argv) | |||
294 | goto end; | 294 | goto end; |
295 | } | 295 | } |
296 | } | 296 | } |
297 | if (spkac_config.pubkey) | 297 | if (cfg.pubkey) |
298 | PEM_write_bio_PUBKEY(out, pkey); | 298 | PEM_write_bio_PUBKEY(out, pkey); |
299 | 299 | ||
300 | ret = 0; | 300 | ret = 0; |