diff options
author | Viktor Dukhovni <openssl-users@dukhovni.org> | 2015-12-13 02:51:44 -0500 |
---|---|---|
committer | Viktor Dukhovni <openssl-users@dukhovni.org> | 2015-12-13 20:13:49 -0500 |
commit | 7eff6aa0d627c2bdbce0493bdb029e477a8caf1e (patch) | |
tree | ec211202a6ba2bc4079bef4a9b5168d2d83a7f86 /apps/rsa.c | |
parent | b9749432346f69b29d82070041e71b237d718ce7 (diff) |
Avoid erroneous "assert(private)" failures.
When processing a public key input via "-pubin", "private" was
sometimes erroneously set, or else not set and incorrectly asserted.
Reviewed-by: Rich salz <rsalz@openssl.org>
Diffstat (limited to 'apps/rsa.c')
-rw-r--r-- | apps/rsa.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/apps/rsa.c b/apps/rsa.c index 0640ba4fad..cafa6f4617 100644 --- a/apps/rsa.c +++ b/apps/rsa.c @@ -250,7 +250,7 @@ int rsa_main(int argc, char **argv) } argc = opt_num_rest(); argv = opt_rest(); - private = text || (!pubout && !noout) ? 1 : 0; + private = (text && !pubin) || (!pubout && !noout) ? 1 : 0; if (!app_passwd(passinarg, passoutarg, &passin, &passout)) { BIO_printf(bio_err, "Error getting passwords\n"); @@ -293,7 +293,7 @@ int rsa_main(int argc, char **argv) goto end; if (text) { - assert(private); + assert(pubin || private); if (!RSA_print(out, rsa, 0)) { perror(outfile); ERR_print_errors(bio_err); @@ -364,11 +364,17 @@ int rsa_main(int argc, char **argv) EVP_PKEY *pk; pk = EVP_PKEY_new(); EVP_PKEY_set1_RSA(pk, rsa); - if (outformat == FORMAT_PVK) + if (outformat == FORMAT_PVK) { + if (pubin) { + BIO_printf(bio_err, "PVK form impossible with public key input\n"); + EVP_PKEY_free(pk); + goto end; + } + assert(private); i = i2b_PVK_bio(out, pk, pvk_encr, 0, passout); - else if (pubin || pubout) + } else if (pubin || pubout) { i = i2b_PublicKey_bio(out, pk); - else { + } else { assert(private); i = i2b_PrivateKey_bio(out, pk); } |