diff options
Diffstat (limited to 'src/usr.bin/openssl/rsautl.c')
-rw-r--r-- | src/usr.bin/openssl/rsautl.c | 96 |
1 files changed, 48 insertions, 48 deletions
diff --git a/src/usr.bin/openssl/rsautl.c b/src/usr.bin/openssl/rsautl.c index 2916b2d9a0..9327223123 100644 --- a/src/usr.bin/openssl/rsautl.c +++ b/src/usr.bin/openssl/rsautl.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: rsautl.c,v 1.20 2023/03/05 13:12:53 tb Exp $ */ | 1 | /* $OpenBSD: rsautl.c,v 1.21 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 2000. | 3 | * project 2000. |
4 | */ | 4 | */ |
@@ -87,131 +87,131 @@ static struct { | |||
87 | char *passargin; | 87 | char *passargin; |
88 | int rev; | 88 | int rev; |
89 | int rsa_mode; | 89 | int rsa_mode; |
90 | } rsautl_config; | 90 | } cfg; |
91 | 91 | ||
92 | static const struct option rsautl_options[] = { | 92 | static const struct option rsautl_options[] = { |
93 | { | 93 | { |
94 | .name = "asn1parse", | 94 | .name = "asn1parse", |
95 | .desc = "ASN.1 parse the output data", | 95 | .desc = "ASN.1 parse the output data", |
96 | .type = OPTION_FLAG, | 96 | .type = OPTION_FLAG, |
97 | .opt.flag = &rsautl_config.asn1parse, | 97 | .opt.flag = &cfg.asn1parse, |
98 | }, | 98 | }, |
99 | { | 99 | { |
100 | .name = "certin", | 100 | .name = "certin", |
101 | .desc = "Input is a certificate containing an RSA public key", | 101 | .desc = "Input is a certificate containing an RSA public key", |
102 | .type = OPTION_VALUE, | 102 | .type = OPTION_VALUE, |
103 | .value = KEY_CERT, | 103 | .value = KEY_CERT, |
104 | .opt.value = &rsautl_config.key_type, | 104 | .opt.value = &cfg.key_type, |
105 | }, | 105 | }, |
106 | { | 106 | { |
107 | .name = "decrypt", | 107 | .name = "decrypt", |
108 | .desc = "Decrypt the input data using RSA private key", | 108 | .desc = "Decrypt the input data using RSA private key", |
109 | .type = OPTION_VALUE, | 109 | .type = OPTION_VALUE, |
110 | .value = RSA_DECRYPT, | 110 | .value = RSA_DECRYPT, |
111 | .opt.value = &rsautl_config.rsa_mode, | 111 | .opt.value = &cfg.rsa_mode, |
112 | }, | 112 | }, |
113 | { | 113 | { |
114 | .name = "encrypt", | 114 | .name = "encrypt", |
115 | .desc = "Encrypt the input data using RSA public key", | 115 | .desc = "Encrypt the input data using RSA public key", |
116 | .type = OPTION_VALUE, | 116 | .type = OPTION_VALUE, |
117 | .value = RSA_ENCRYPT, | 117 | .value = RSA_ENCRYPT, |
118 | .opt.value = &rsautl_config.rsa_mode, | 118 | .opt.value = &cfg.rsa_mode, |
119 | }, | 119 | }, |
120 | { | 120 | { |
121 | .name = "hexdump", | 121 | .name = "hexdump", |
122 | .desc = "Hex dump the output data", | 122 | .desc = "Hex dump the output data", |
123 | .type = OPTION_FLAG, | 123 | .type = OPTION_FLAG, |
124 | .opt.flag = &rsautl_config.hexdump, | 124 | .opt.flag = &cfg.hexdump, |
125 | }, | 125 | }, |
126 | { | 126 | { |
127 | .name = "in", | 127 | .name = "in", |
128 | .argname = "file", | 128 | .argname = "file", |
129 | .desc = "Input file (default stdin)", | 129 | .desc = "Input file (default stdin)", |
130 | .type = OPTION_ARG, | 130 | .type = OPTION_ARG, |
131 | .opt.arg = &rsautl_config.infile, | 131 | .opt.arg = &cfg.infile, |
132 | }, | 132 | }, |
133 | { | 133 | { |
134 | .name = "inkey", | 134 | .name = "inkey", |
135 | .argname = "file", | 135 | .argname = "file", |
136 | .desc = "Input key file", | 136 | .desc = "Input key file", |
137 | .type = OPTION_ARG, | 137 | .type = OPTION_ARG, |
138 | .opt.arg = &rsautl_config.keyfile, | 138 | .opt.arg = &cfg.keyfile, |
139 | }, | 139 | }, |
140 | { | 140 | { |
141 | .name = "keyform", | 141 | .name = "keyform", |
142 | .argname = "fmt", | 142 | .argname = "fmt", |
143 | .desc = "Input key format (DER, TXT or PEM (default))", | 143 | .desc = "Input key format (DER, TXT or PEM (default))", |
144 | .type = OPTION_ARG_FORMAT, | 144 | .type = OPTION_ARG_FORMAT, |
145 | .opt.value = &rsautl_config.keyform, | 145 | .opt.value = &cfg.keyform, |
146 | }, | 146 | }, |
147 | { | 147 | { |
148 | .name = "oaep", | 148 | .name = "oaep", |
149 | .desc = "Use PKCS#1 OAEP padding", | 149 | .desc = "Use PKCS#1 OAEP padding", |
150 | .type = OPTION_VALUE, | 150 | .type = OPTION_VALUE, |
151 | .value = RSA_PKCS1_OAEP_PADDING, | 151 | .value = RSA_PKCS1_OAEP_PADDING, |
152 | .opt.value = &rsautl_config.pad, | 152 | .opt.value = &cfg.pad, |
153 | }, | 153 | }, |
154 | { | 154 | { |
155 | .name = "out", | 155 | .name = "out", |
156 | .argname = "file", | 156 | .argname = "file", |
157 | .desc = "Output file (default stdout)", | 157 | .desc = "Output file (default stdout)", |
158 | .type = OPTION_ARG, | 158 | .type = OPTION_ARG, |
159 | .opt.arg = &rsautl_config.outfile, | 159 | .opt.arg = &cfg.outfile, |
160 | }, | 160 | }, |
161 | { | 161 | { |
162 | .name = "passin", | 162 | .name = "passin", |
163 | .argname = "arg", | 163 | .argname = "arg", |
164 | .desc = "Key password source", | 164 | .desc = "Key password source", |
165 | .type = OPTION_ARG, | 165 | .type = OPTION_ARG, |
166 | .opt.arg = &rsautl_config.passargin, | 166 | .opt.arg = &cfg.passargin, |
167 | }, | 167 | }, |
168 | { | 168 | { |
169 | .name = "pkcs", | 169 | .name = "pkcs", |
170 | .desc = "Use PKCS#1 v1.5 padding (default)", | 170 | .desc = "Use PKCS#1 v1.5 padding (default)", |
171 | .type = OPTION_VALUE, | 171 | .type = OPTION_VALUE, |
172 | .value = RSA_PKCS1_PADDING, | 172 | .value = RSA_PKCS1_PADDING, |
173 | .opt.value = &rsautl_config.pad, | 173 | .opt.value = &cfg.pad, |
174 | }, | 174 | }, |
175 | { | 175 | { |
176 | .name = "pubin", | 176 | .name = "pubin", |
177 | .desc = "Input is an RSA public key", | 177 | .desc = "Input is an RSA public key", |
178 | .type = OPTION_VALUE, | 178 | .type = OPTION_VALUE, |
179 | .value = KEY_PUBKEY, | 179 | .value = KEY_PUBKEY, |
180 | .opt.value = &rsautl_config.key_type, | 180 | .opt.value = &cfg.key_type, |
181 | }, | 181 | }, |
182 | { | 182 | { |
183 | .name = "raw", | 183 | .name = "raw", |
184 | .desc = "Use no padding", | 184 | .desc = "Use no padding", |
185 | .type = OPTION_VALUE, | 185 | .type = OPTION_VALUE, |
186 | .value = RSA_NO_PADDING, | 186 | .value = RSA_NO_PADDING, |
187 | .opt.value = &rsautl_config.pad, | 187 | .opt.value = &cfg.pad, |
188 | }, | 188 | }, |
189 | { | 189 | { |
190 | .name = "rev", | 190 | .name = "rev", |
191 | .desc = "Reverse the input data", | 191 | .desc = "Reverse the input data", |
192 | .type = OPTION_FLAG, | 192 | .type = OPTION_FLAG, |
193 | .opt.flag = &rsautl_config.rev, | 193 | .opt.flag = &cfg.rev, |
194 | }, | 194 | }, |
195 | { | 195 | { |
196 | .name = "sign", | 196 | .name = "sign", |
197 | .desc = "Sign the input data using RSA private key", | 197 | .desc = "Sign the input data using RSA private key", |
198 | .type = OPTION_VALUE, | 198 | .type = OPTION_VALUE, |
199 | .value = RSA_SIGN, | 199 | .value = RSA_SIGN, |
200 | .opt.value = &rsautl_config.rsa_mode, | 200 | .opt.value = &cfg.rsa_mode, |
201 | }, | 201 | }, |
202 | { | 202 | { |
203 | .name = "verify", | 203 | .name = "verify", |
204 | .desc = "Verify the input data using RSA public key", | 204 | .desc = "Verify the input data using RSA public key", |
205 | .type = OPTION_VALUE, | 205 | .type = OPTION_VALUE, |
206 | .value = RSA_VERIFY, | 206 | .value = RSA_VERIFY, |
207 | .opt.value = &rsautl_config.rsa_mode, | 207 | .opt.value = &cfg.rsa_mode, |
208 | }, | 208 | }, |
209 | { | 209 | { |
210 | .name = "x931", | 210 | .name = "x931", |
211 | .desc = "Use ANSI X9.31 padding", | 211 | .desc = "Use ANSI X9.31 padding", |
212 | .type = OPTION_VALUE, | 212 | .type = OPTION_VALUE, |
213 | .value = RSA_X931_PADDING, | 213 | .value = RSA_X931_PADDING, |
214 | .opt.value = &rsautl_config.pad, | 214 | .opt.value = &cfg.pad, |
215 | }, | 215 | }, |
216 | 216 | ||
217 | {NULL}, | 217 | {NULL}, |
@@ -249,44 +249,44 @@ rsautl_main(int argc, char **argv) | |||
249 | exit(1); | 249 | exit(1); |
250 | } | 250 | } |
251 | 251 | ||
252 | memset(&rsautl_config, 0, sizeof(rsautl_config)); | 252 | memset(&cfg, 0, sizeof(cfg)); |
253 | rsautl_config.keyform = FORMAT_PEM; | 253 | cfg.keyform = FORMAT_PEM; |
254 | rsautl_config.key_type = KEY_PRIVKEY; | 254 | cfg.key_type = KEY_PRIVKEY; |
255 | rsautl_config.pad = RSA_PKCS1_PADDING; | 255 | cfg.pad = RSA_PKCS1_PADDING; |
256 | rsautl_config.rsa_mode = RSA_VERIFY; | 256 | cfg.rsa_mode = RSA_VERIFY; |
257 | 257 | ||
258 | if (options_parse(argc, argv, rsautl_options, NULL, NULL) != 0) { | 258 | if (options_parse(argc, argv, rsautl_options, NULL, NULL) != 0) { |
259 | rsautl_usage(); | 259 | rsautl_usage(); |
260 | return (1); | 260 | return (1); |
261 | } | 261 | } |
262 | 262 | ||
263 | if (rsautl_config.rsa_mode == RSA_SIGN || | 263 | if (cfg.rsa_mode == RSA_SIGN || |
264 | rsautl_config.rsa_mode == RSA_DECRYPT) | 264 | cfg.rsa_mode == RSA_DECRYPT) |
265 | need_priv = 1; | 265 | need_priv = 1; |
266 | 266 | ||
267 | if (need_priv && rsautl_config.key_type != KEY_PRIVKEY) { | 267 | if (need_priv && cfg.key_type != KEY_PRIVKEY) { |
268 | BIO_printf(bio_err, "A private key is needed for this operation\n"); | 268 | BIO_printf(bio_err, "A private key is needed for this operation\n"); |
269 | goto end; | 269 | goto end; |
270 | } | 270 | } |
271 | if (!app_passwd(bio_err, rsautl_config.passargin, NULL, &passin, NULL)) { | 271 | if (!app_passwd(bio_err, cfg.passargin, NULL, &passin, NULL)) { |
272 | BIO_printf(bio_err, "Error getting password\n"); | 272 | BIO_printf(bio_err, "Error getting password\n"); |
273 | goto end; | 273 | goto end; |
274 | } | 274 | } |
275 | 275 | ||
276 | switch (rsautl_config.key_type) { | 276 | switch (cfg.key_type) { |
277 | case KEY_PRIVKEY: | 277 | case KEY_PRIVKEY: |
278 | pkey = load_key(bio_err, rsautl_config.keyfile, | 278 | pkey = load_key(bio_err, cfg.keyfile, |
279 | rsautl_config.keyform, 0, passin, "Private Key"); | 279 | cfg.keyform, 0, passin, "Private Key"); |
280 | break; | 280 | break; |
281 | 281 | ||
282 | case KEY_PUBKEY: | 282 | case KEY_PUBKEY: |
283 | pkey = load_pubkey(bio_err, rsautl_config.keyfile, | 283 | pkey = load_pubkey(bio_err, cfg.keyfile, |
284 | rsautl_config.keyform, 0, NULL, "Public Key"); | 284 | cfg.keyform, 0, NULL, "Public Key"); |
285 | break; | 285 | break; |
286 | 286 | ||
287 | case KEY_CERT: | 287 | case KEY_CERT: |
288 | x = load_cert(bio_err, rsautl_config.keyfile, | 288 | x = load_cert(bio_err, cfg.keyfile, |
289 | rsautl_config.keyform, NULL, "Certificate"); | 289 | cfg.keyform, NULL, "Certificate"); |
290 | if (x) { | 290 | if (x) { |
291 | pkey = X509_get_pubkey(x); | 291 | pkey = X509_get_pubkey(x); |
292 | X509_free(x); | 292 | X509_free(x); |
@@ -305,8 +305,8 @@ rsautl_main(int argc, char **argv) | |||
305 | ERR_print_errors(bio_err); | 305 | ERR_print_errors(bio_err); |
306 | goto end; | 306 | goto end; |
307 | } | 307 | } |
308 | if (rsautl_config.infile) { | 308 | if (cfg.infile) { |
309 | if (!(in = BIO_new_file(rsautl_config.infile, "rb"))) { | 309 | if (!(in = BIO_new_file(cfg.infile, "rb"))) { |
310 | BIO_printf(bio_err, "Error Reading Input File\n"); | 310 | BIO_printf(bio_err, "Error Reading Input File\n"); |
311 | ERR_print_errors(bio_err); | 311 | ERR_print_errors(bio_err); |
312 | goto end; | 312 | goto end; |
@@ -314,8 +314,8 @@ rsautl_main(int argc, char **argv) | |||
314 | } else | 314 | } else |
315 | in = BIO_new_fp(stdin, BIO_NOCLOSE); | 315 | in = BIO_new_fp(stdin, BIO_NOCLOSE); |
316 | 316 | ||
317 | if (rsautl_config.outfile) { | 317 | if (cfg.outfile) { |
318 | if (!(out = BIO_new_file(rsautl_config.outfile, "wb"))) { | 318 | if (!(out = BIO_new_file(cfg.outfile, "wb"))) { |
319 | BIO_printf(bio_err, "Error Reading Output File\n"); | 319 | BIO_printf(bio_err, "Error Reading Output File\n"); |
320 | ERR_print_errors(bio_err); | 320 | ERR_print_errors(bio_err); |
321 | goto end; | 321 | goto end; |
@@ -343,7 +343,7 @@ rsautl_main(int argc, char **argv) | |||
343 | BIO_printf(bio_err, "Error reading input Data\n"); | 343 | BIO_printf(bio_err, "Error reading input Data\n"); |
344 | exit(1); | 344 | exit(1); |
345 | } | 345 | } |
346 | if (rsautl_config.rev) { | 346 | if (cfg.rev) { |
347 | int i; | 347 | int i; |
348 | unsigned char ctmp; | 348 | unsigned char ctmp; |
349 | for (i = 0; i < rsa_inlen / 2; i++) { | 349 | for (i = 0; i < rsa_inlen / 2; i++) { |
@@ -353,25 +353,25 @@ rsautl_main(int argc, char **argv) | |||
353 | } | 353 | } |
354 | } | 354 | } |
355 | 355 | ||
356 | switch (rsautl_config.rsa_mode) { | 356 | switch (cfg.rsa_mode) { |
357 | case RSA_VERIFY: | 357 | case RSA_VERIFY: |
358 | rsa_outlen = RSA_public_decrypt(rsa_inlen, rsa_in, rsa_out, | 358 | rsa_outlen = RSA_public_decrypt(rsa_inlen, rsa_in, rsa_out, |
359 | rsa, rsautl_config.pad); | 359 | rsa, cfg.pad); |
360 | break; | 360 | break; |
361 | 361 | ||
362 | case RSA_SIGN: | 362 | case RSA_SIGN: |
363 | rsa_outlen = RSA_private_encrypt(rsa_inlen, rsa_in, rsa_out, | 363 | rsa_outlen = RSA_private_encrypt(rsa_inlen, rsa_in, rsa_out, |
364 | rsa, rsautl_config.pad); | 364 | rsa, cfg.pad); |
365 | break; | 365 | break; |
366 | 366 | ||
367 | case RSA_ENCRYPT: | 367 | case RSA_ENCRYPT: |
368 | rsa_outlen = RSA_public_encrypt(rsa_inlen, rsa_in, rsa_out, | 368 | rsa_outlen = RSA_public_encrypt(rsa_inlen, rsa_in, rsa_out, |
369 | rsa, rsautl_config.pad); | 369 | rsa, cfg.pad); |
370 | break; | 370 | break; |
371 | 371 | ||
372 | case RSA_DECRYPT: | 372 | case RSA_DECRYPT: |
373 | rsa_outlen = RSA_private_decrypt(rsa_inlen, rsa_in, rsa_out, | 373 | rsa_outlen = RSA_private_decrypt(rsa_inlen, rsa_in, rsa_out, |
374 | rsa, rsautl_config.pad); | 374 | rsa, cfg.pad); |
375 | break; | 375 | break; |
376 | } | 376 | } |
377 | 377 | ||
@@ -381,11 +381,11 @@ rsautl_main(int argc, char **argv) | |||
381 | goto end; | 381 | goto end; |
382 | } | 382 | } |
383 | ret = 0; | 383 | ret = 0; |
384 | if (rsautl_config.asn1parse) { | 384 | if (cfg.asn1parse) { |
385 | if (!ASN1_parse_dump(out, rsa_out, rsa_outlen, 1, -1)) { | 385 | if (!ASN1_parse_dump(out, rsa_out, rsa_outlen, 1, -1)) { |
386 | ERR_print_errors(bio_err); | 386 | ERR_print_errors(bio_err); |
387 | } | 387 | } |
388 | } else if (rsautl_config.hexdump) | 388 | } else if (cfg.hexdump) |
389 | BIO_dump(out, (char *) rsa_out, rsa_outlen); | 389 | BIO_dump(out, (char *) rsa_out, rsa_outlen); |
390 | else | 390 | else |
391 | BIO_write(out, rsa_out, rsa_outlen); | 391 | BIO_write(out, rsa_out, rsa_outlen); |