diff options
author | Dr. Stephen Henson <steve@openssl.org> | 2006-06-05 11:52:46 +0000 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 2006-06-05 11:52:46 +0000 |
commit | 01b8b3c7d2d8f835257ac1cb2512273aa27bfba8 (patch) | |
tree | fb224473dca22be551086f10ed34240c802c6335 /apps/genpkey.c | |
parent | 8fecd4b4f1bd6f066ba0a9f96387f00ac0dd99bf (diff) |
Complete EVP_PKEY_ASN1_METHOD ENGINE support.
Diffstat (limited to 'apps/genpkey.c')
-rw-r--r-- | apps/genpkey.c | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/apps/genpkey.c b/apps/genpkey.c index 8468fb20b3..70e2e31971 100644 --- a/apps/genpkey.c +++ b/apps/genpkey.c @@ -61,6 +61,9 @@ #include <openssl/pem.h> #include <openssl/err.h> #include <openssl/evp.h> +#ifndef OPENSSL_NO_ENGINE +#include <openssl/engine.h> +#endif static int init_keygen_file(BIO *err, EVP_PKEY_CTX **pctx, const char *file, ENGINE *e); @@ -85,7 +88,7 @@ int MAIN(int argc, char **argv) EVP_PKEY_CTX *ctx = NULL; char *pass = NULL; int badarg = 0; - int ret = 1; + int ret = 1, rv; int do_param = 0; @@ -204,7 +207,7 @@ int MAIN(int argc, char **argv) #ifndef OPENSSL_NO_ENGINE BIO_printf(bio_err, "-engine e use engine e, possibly a hardware device.\n"); #endif - return 1; + goto end; } if (!app_passwd(bio_err, passarg, NULL, &pass, NULL)) @@ -256,25 +259,36 @@ int MAIN(int argc, char **argv) } if (do_param) - PEM_write_bio_Parameters(out, pkey); + rv = PEM_write_bio_Parameters(out, pkey); else if (outformat == FORMAT_PEM) - PEM_write_bio_PrivateKey(out, pkey, cipher, NULL, 0, + rv = PEM_write_bio_PrivateKey(out, pkey, cipher, NULL, 0, NULL, pass); else if (outformat == FORMAT_ASN1) - i2d_PrivateKey_bio(out, pkey); + rv = i2d_PrivateKey_bio(out, pkey); else { BIO_printf(bio_err, "Bad format specified for key\n"); goto end; } + if (rv <= 0) + { + BIO_puts(bio_err, "Error writing key\n"); + ERR_print_errors(bio_err); + } if (text) { if (do_param) - EVP_PKEY_print_params(out, pkey, 0, NULL); + rv = EVP_PKEY_print_params(out, pkey, 0, NULL); else - EVP_PKEY_print_private(out, pkey, 0, NULL); + rv = EVP_PKEY_print_private(out, pkey, 0, NULL); + + if (rv <= 0) + { + BIO_puts(bio_err, "Error printing key\n"); + ERR_print_errors(bio_err); + } } ret = 0; @@ -346,14 +360,16 @@ static int init_gen_str(BIO *err, EVP_PKEY_CTX **pctx, { EVP_PKEY_CTX *ctx = NULL; const EVP_PKEY_ASN1_METHOD *ameth; + ENGINE *tmpeng = NULL; int pkey_id; + if (*pctx) { BIO_puts(err, "Algorithm already set!\n"); return 0; } + ameth = EVP_PKEY_asn1_find_str(&tmpeng, algname, -1); - ameth = EVP_PKEY_asn1_find_str(algname, -1); if (!ameth) { BIO_printf(bio_err, "Algorithm %s not found\n", algname); @@ -361,6 +377,10 @@ static int init_gen_str(BIO *err, EVP_PKEY_CTX **pctx, } EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, NULL, NULL, ameth); +#ifndef OPENSSL_NO_ENGINE + if (tmpeng) + ENGINE_finish(tmpeng); +#endif ctx = EVP_PKEY_CTX_new_id(pkey_id, e); if (!ctx) |