diff options
Diffstat (limited to '')
| -rw-r--r-- | src/usr.bin/openssl/pkey.c | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/src/usr.bin/openssl/pkey.c b/src/usr.bin/openssl/pkey.c index 2d9b69f5c3..cb558f5ac8 100644 --- a/src/usr.bin/openssl/pkey.c +++ b/src/usr.bin/openssl/pkey.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: pkey.c,v 1.18 2022/11/11 17:07:39 joshua Exp $ */ | 1 | /* $OpenBSD: pkey.c,v 1.19 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 2006 | 3 | * project 2006 |
| 4 | */ | 4 | */ |
| @@ -80,7 +80,7 @@ static struct { | |||
| 80 | int pubout; | 80 | int pubout; |
| 81 | int pubtext; | 81 | int pubtext; |
| 82 | int text; | 82 | int text; |
| 83 | } pkey_config; | 83 | } cfg; |
| 84 | 84 | ||
| 85 | static int | 85 | static int |
| 86 | pkey_opt_cipher(int argc, char **argv, int *argsused) | 86 | pkey_opt_cipher(int argc, char **argv, int *argsused) |
| @@ -90,7 +90,7 @@ pkey_opt_cipher(int argc, char **argv, int *argsused) | |||
| 90 | if (*name++ != '-') | 90 | if (*name++ != '-') |
| 91 | return (1); | 91 | return (1); |
| 92 | 92 | ||
| 93 | if ((pkey_config.cipher = EVP_get_cipherbyname(name)) == NULL) { | 93 | if ((cfg.cipher = EVP_get_cipherbyname(name)) == NULL) { |
| 94 | BIO_printf(bio_err, "Unknown cipher %s\n", name); | 94 | BIO_printf(bio_err, "Unknown cipher %s\n", name); |
| 95 | return (1); | 95 | return (1); |
| 96 | } | 96 | } |
| @@ -104,87 +104,87 @@ static const struct option pkey_options[] = { | |||
| 104 | .name = "check", | 104 | .name = "check", |
| 105 | .desc = "Check validity of key", | 105 | .desc = "Check validity of key", |
| 106 | .type = OPTION_FLAG, | 106 | .type = OPTION_FLAG, |
| 107 | .opt.flag = &pkey_config.check, | 107 | .opt.flag = &cfg.check, |
| 108 | }, | 108 | }, |
| 109 | { | 109 | { |
| 110 | .name = "in", | 110 | .name = "in", |
| 111 | .argname = "file", | 111 | .argname = "file", |
| 112 | .desc = "Input file (default stdin)", | 112 | .desc = "Input file (default stdin)", |
| 113 | .type = OPTION_ARG, | 113 | .type = OPTION_ARG, |
| 114 | .opt.arg = &pkey_config.infile, | 114 | .opt.arg = &cfg.infile, |
| 115 | }, | 115 | }, |
| 116 | { | 116 | { |
| 117 | .name = "inform", | 117 | .name = "inform", |
| 118 | .argname = "format", | 118 | .argname = "format", |
| 119 | .desc = "Input format (DER or PEM (default))", | 119 | .desc = "Input format (DER or PEM (default))", |
| 120 | .type = OPTION_ARG_FORMAT, | 120 | .type = OPTION_ARG_FORMAT, |
| 121 | .opt.value = &pkey_config.informat, | 121 | .opt.value = &cfg.informat, |
| 122 | }, | 122 | }, |
| 123 | { | 123 | { |
| 124 | .name = "noout", | 124 | .name = "noout", |
| 125 | .desc = "Do not print encoded version of the key", | 125 | .desc = "Do not print encoded version of the key", |
| 126 | .type = OPTION_FLAG, | 126 | .type = OPTION_FLAG, |
| 127 | .opt.flag = &pkey_config.noout, | 127 | .opt.flag = &cfg.noout, |
| 128 | }, | 128 | }, |
| 129 | { | 129 | { |
| 130 | .name = "out", | 130 | .name = "out", |
| 131 | .argname = "file", | 131 | .argname = "file", |
| 132 | .desc = "Output file (default stdout)", | 132 | .desc = "Output file (default stdout)", |
| 133 | .type = OPTION_ARG, | 133 | .type = OPTION_ARG, |
| 134 | .opt.arg = &pkey_config.outfile, | 134 | .opt.arg = &cfg.outfile, |
| 135 | }, | 135 | }, |
| 136 | { | 136 | { |
| 137 | .name = "outform", | 137 | .name = "outform", |
| 138 | .argname = "format", | 138 | .argname = "format", |
| 139 | .desc = "Output format (DER or PEM (default))", | 139 | .desc = "Output format (DER or PEM (default))", |
| 140 | .type = OPTION_ARG_FORMAT, | 140 | .type = OPTION_ARG_FORMAT, |
| 141 | .opt.value = &pkey_config.outformat, | 141 | .opt.value = &cfg.outformat, |
| 142 | }, | 142 | }, |
| 143 | { | 143 | { |
| 144 | .name = "passin", | 144 | .name = "passin", |
| 145 | .argname = "src", | 145 | .argname = "src", |
| 146 | .desc = "Input file passphrase source", | 146 | .desc = "Input file passphrase source", |
| 147 | .type = OPTION_ARG, | 147 | .type = OPTION_ARG, |
| 148 | .opt.arg = &pkey_config.passargin, | 148 | .opt.arg = &cfg.passargin, |
| 149 | }, | 149 | }, |
| 150 | { | 150 | { |
| 151 | .name = "passout", | 151 | .name = "passout", |
| 152 | .argname = "src", | 152 | .argname = "src", |
| 153 | .desc = "Output file passphrase source", | 153 | .desc = "Output file passphrase source", |
| 154 | .type = OPTION_ARG, | 154 | .type = OPTION_ARG, |
| 155 | .opt.arg = &pkey_config.passargout, | 155 | .opt.arg = &cfg.passargout, |
| 156 | }, | 156 | }, |
| 157 | { | 157 | { |
| 158 | .name = "pubcheck", | 158 | .name = "pubcheck", |
| 159 | .desc = "Check validity of public key", | 159 | .desc = "Check validity of public key", |
| 160 | .type = OPTION_FLAG, | 160 | .type = OPTION_FLAG, |
| 161 | .opt.flag = &pkey_config.pubcheck, | 161 | .opt.flag = &cfg.pubcheck, |
| 162 | }, | 162 | }, |
| 163 | { | 163 | { |
| 164 | .name = "pubin", | 164 | .name = "pubin", |
| 165 | .desc = "Expect a public key (default private key)", | 165 | .desc = "Expect a public key (default private key)", |
| 166 | .type = OPTION_VALUE, | 166 | .type = OPTION_VALUE, |
| 167 | .value = 1, | 167 | .value = 1, |
| 168 | .opt.value = &pkey_config.pubin, | 168 | .opt.value = &cfg.pubin, |
| 169 | }, | 169 | }, |
| 170 | { | 170 | { |
| 171 | .name = "pubout", | 171 | .name = "pubout", |
| 172 | .desc = "Output a public key (default private key)", | 172 | .desc = "Output a public key (default private key)", |
| 173 | .type = OPTION_VALUE, | 173 | .type = OPTION_VALUE, |
| 174 | .value = 1, | 174 | .value = 1, |
| 175 | .opt.value = &pkey_config.pubout, | 175 | .opt.value = &cfg.pubout, |
| 176 | }, | 176 | }, |
| 177 | { | 177 | { |
| 178 | .name = "text", | 178 | .name = "text", |
| 179 | .desc = "Print the public/private key in plain text", | 179 | .desc = "Print the public/private key in plain text", |
| 180 | .type = OPTION_FLAG, | 180 | .type = OPTION_FLAG, |
| 181 | .opt.flag = &pkey_config.text, | 181 | .opt.flag = &cfg.text, |
| 182 | }, | 182 | }, |
| 183 | { | 183 | { |
| 184 | .name = "text_pub", | 184 | .name = "text_pub", |
| 185 | .desc = "Print out only public key in plain text", | 185 | .desc = "Print out only public key in plain text", |
| 186 | .type = OPTION_FLAG, | 186 | .type = OPTION_FLAG, |
| 187 | .opt.flag = &pkey_config.pubtext, | 187 | .opt.flag = &cfg.pubtext, |
| 188 | }, | 188 | }, |
| 189 | { | 189 | { |
| 190 | .name = NULL, | 190 | .name = NULL, |
| @@ -226,61 +226,61 @@ pkey_main(int argc, char **argv) | |||
| 226 | exit(1); | 226 | exit(1); |
| 227 | } | 227 | } |
| 228 | 228 | ||
| 229 | memset(&pkey_config, 0, sizeof(pkey_config)); | 229 | memset(&cfg, 0, sizeof(cfg)); |
| 230 | pkey_config.informat = FORMAT_PEM; | 230 | cfg.informat = FORMAT_PEM; |
| 231 | pkey_config.outformat = FORMAT_PEM; | 231 | cfg.outformat = FORMAT_PEM; |
| 232 | 232 | ||
| 233 | if (options_parse(argc, argv, pkey_options, NULL, NULL) != 0) { | 233 | if (options_parse(argc, argv, pkey_options, NULL, NULL) != 0) { |
| 234 | pkey_usage(); | 234 | pkey_usage(); |
| 235 | goto end; | 235 | goto end; |
| 236 | } | 236 | } |
| 237 | 237 | ||
| 238 | if (pkey_config.pubtext) | 238 | if (cfg.pubtext) |
| 239 | pkey_config.text = 1; | 239 | cfg.text = 1; |
| 240 | if (pkey_config.pubin) | 240 | if (cfg.pubin) |
| 241 | pkey_config.pubout = pkey_config.pubtext = 1; | 241 | cfg.pubout = cfg.pubtext = 1; |
| 242 | 242 | ||
| 243 | if (!app_passwd(bio_err, pkey_config.passargin, pkey_config.passargout, | 243 | if (!app_passwd(bio_err, cfg.passargin, cfg.passargout, |
| 244 | &passin, &passout)) { | 244 | &passin, &passout)) { |
| 245 | BIO_printf(bio_err, "Error getting passwords\n"); | 245 | BIO_printf(bio_err, "Error getting passwords\n"); |
| 246 | goto end; | 246 | goto end; |
| 247 | } | 247 | } |
| 248 | if (pkey_config.outfile) { | 248 | if (cfg.outfile) { |
| 249 | if (!(out = BIO_new_file(pkey_config.outfile, "wb"))) { | 249 | if (!(out = BIO_new_file(cfg.outfile, "wb"))) { |
| 250 | BIO_printf(bio_err, | 250 | BIO_printf(bio_err, |
| 251 | "Can't open output file %s\n", pkey_config.outfile); | 251 | "Can't open output file %s\n", cfg.outfile); |
| 252 | goto end; | 252 | goto end; |
| 253 | } | 253 | } |
| 254 | } else { | 254 | } else { |
| 255 | out = BIO_new_fp(stdout, BIO_NOCLOSE); | 255 | out = BIO_new_fp(stdout, BIO_NOCLOSE); |
| 256 | } | 256 | } |
| 257 | 257 | ||
| 258 | if (pkey_config.pubin) | 258 | if (cfg.pubin) |
| 259 | pkey = load_pubkey(bio_err, pkey_config.infile, | 259 | pkey = load_pubkey(bio_err, cfg.infile, |
| 260 | pkey_config.informat, 1, passin, "Public Key"); | 260 | cfg.informat, 1, passin, "Public Key"); |
| 261 | else | 261 | else |
| 262 | pkey = load_key(bio_err, pkey_config.infile, | 262 | pkey = load_key(bio_err, cfg.infile, |
| 263 | pkey_config.informat, 1, passin, "key"); | 263 | cfg.informat, 1, passin, "key"); |
| 264 | if (!pkey) | 264 | if (!pkey) |
| 265 | goto end; | 265 | goto end; |
| 266 | 266 | ||
| 267 | if (pkey_config.check) { | 267 | if (cfg.check) { |
| 268 | if (!pkey_check(out, pkey, EVP_PKEY_check, "Key pair")) | 268 | if (!pkey_check(out, pkey, EVP_PKEY_check, "Key pair")) |
| 269 | goto end; | 269 | goto end; |
| 270 | } else if (pkey_config.pubcheck) { | 270 | } else if (cfg.pubcheck) { |
| 271 | if (!pkey_check(out, pkey, EVP_PKEY_public_check, "Public key")) | 271 | if (!pkey_check(out, pkey, EVP_PKEY_public_check, "Public key")) |
| 272 | goto end; | 272 | goto end; |
| 273 | } | 273 | } |
| 274 | 274 | ||
| 275 | if (!pkey_config.noout) { | 275 | if (!cfg.noout) { |
| 276 | if (pkey_config.outformat == FORMAT_PEM) { | 276 | if (cfg.outformat == FORMAT_PEM) { |
| 277 | if (pkey_config.pubout) | 277 | if (cfg.pubout) |
| 278 | PEM_write_bio_PUBKEY(out, pkey); | 278 | PEM_write_bio_PUBKEY(out, pkey); |
| 279 | else | 279 | else |
| 280 | PEM_write_bio_PrivateKey(out, pkey, | 280 | PEM_write_bio_PrivateKey(out, pkey, |
| 281 | pkey_config.cipher, NULL, 0, NULL, passout); | 281 | cfg.cipher, NULL, 0, NULL, passout); |
| 282 | } else if (pkey_config.outformat == FORMAT_ASN1) { | 282 | } else if (cfg.outformat == FORMAT_ASN1) { |
| 283 | if (pkey_config.pubout) | 283 | if (cfg.pubout) |
| 284 | i2d_PUBKEY_bio(out, pkey); | 284 | i2d_PUBKEY_bio(out, pkey); |
| 285 | else | 285 | else |
| 286 | i2d_PrivateKey_bio(out, pkey); | 286 | i2d_PrivateKey_bio(out, pkey); |
| @@ -290,8 +290,8 @@ pkey_main(int argc, char **argv) | |||
| 290 | } | 290 | } |
| 291 | 291 | ||
| 292 | } | 292 | } |
| 293 | if (pkey_config.text) { | 293 | if (cfg.text) { |
| 294 | if (pkey_config.pubtext) | 294 | if (cfg.pubtext) |
| 295 | EVP_PKEY_print_public(out, pkey, 0, NULL); | 295 | EVP_PKEY_print_public(out, pkey, 0, NULL); |
| 296 | else | 296 | else |
| 297 | EVP_PKEY_print_private(out, pkey, 0, NULL); | 297 | EVP_PKEY_print_private(out, pkey, 0, NULL); |
