From: Richard Levitte Date: Mon, 25 Jun 2001 14:23:36 +0000 (+0000) Subject: Make better use of load_cert, load_certs and load_key. X-Git-Tag: OpenSSL_0_9_6c~182^2~67 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=7953b8ff1b1a60c50fa56543b78d37bd0ca66490;p=oweals%2Fopenssl.git Make better use of load_cert, load_certs and load_key. --- diff --git a/apps/pkcs8.c b/apps/pkcs8.c index 5e20a2be70..cfc4851e00 100644 --- a/apps/pkcs8.c +++ b/apps/pkcs8.c @@ -217,21 +217,13 @@ int MAIN(int argc, char **argv) } #endif } - if (topk8) { - if(informat == FORMAT_PEM) - pkey = PEM_read_bio_PrivateKey(in, NULL, NULL, passin); - else if(informat == FORMAT_ASN1) - pkey = d2i_PrivateKey_bio(in, NULL); - else { - BIO_printf(bio_err, "Bad format specified for key\n"); - return (1); - } + if (topk8) + { + BIO_free(in); /* Not needed in this section */ + pkey = load_key(bio_err, infile, informat, passin, e, "key"); if (!pkey) { - BIO_printf(bio_err, "Error reading key\n", outfile); - ERR_print_errors(bio_err); return (1); } - BIO_free(in); if (!(p8inf = EVP_PKEY2PKCS8_broken(pkey, p8_broken))) { BIO_printf(bio_err, "Error converting key\n", outfile); ERR_print_errors(bio_err); diff --git a/apps/spkac.c b/apps/spkac.c index 538a419345..918efc0e5a 100644 --- a/apps/spkac.c +++ b/apps/spkac.c @@ -84,7 +84,7 @@ int MAIN(int argc, char **argv) { ENGINE *e = NULL; int i,badops=0, ret = 1; - BIO *in = NULL,*out = NULL, *key = NULL; + BIO *in = NULL,*out = NULL; int verify=0,noout=0,pubkey=0; char *infile = NULL,*outfile = NULL,*prog; char *passargin = NULL, *passin = NULL; @@ -182,17 +182,10 @@ bad: e = setup_engine(bio_err, engine, 0); if(keyfile) { - if(strcmp(keyfile, "-")) key = BIO_new_file(keyfile, "r"); - else key = BIO_new_fp(stdin, BIO_NOCLOSE); - if(!key) { - BIO_printf(bio_err, "Error opening key file\n"); - ERR_print_errors(bio_err); - goto end; - } - pkey = PEM_read_bio_PrivateKey(key, NULL, NULL, passin); + pkey = load_key(bio_err, + strcmp(keyfile, "-") ? keyfile : NULL, + FORMAT_PEM, passin, e, "private key"); if(!pkey) { - BIO_printf(bio_err, "Error reading private key\n"); - ERR_print_errors(bio_err); goto end; } spki = NETSCAPE_SPKI_new(); @@ -296,8 +289,8 @@ end: NETSCAPE_SPKI_free(spki); BIO_free(in); BIO_free_all(out); - BIO_free(key); EVP_PKEY_free(pkey); if(passin) OPENSSL_free(passin); + apps_shutdown(); EXIT(ret); } diff --git a/apps/verify.c b/apps/verify.c index d5f07c2db4..60da5c5a24 100644 --- a/apps/verify.c +++ b/apps/verify.c @@ -71,7 +71,7 @@ #define PROG verify_main static int MS_CALLBACK cb(int ok, X509_STORE_CTX *ctx); -static int check(X509_STORE *ctx, char *file, STACK_OF(X509) *uchain, STACK_OF(X509) *tchain, int purpose); +static int check(X509_STORE *ctx, char *file, STACK_OF(X509) *uchain, STACK_OF(X509) *tchain, int purpose, ENGINE *e); static STACK_OF(X509) *load_untrusted(char *file); static int v_verbose=0, vflags = 0; @@ -208,10 +208,10 @@ int MAIN(int argc, char **argv) } } - if (argc < 1) check(cert_ctx, NULL, untrusted, trusted, purpose); + if (argc < 1) check(cert_ctx, NULL, untrusted, trusted, purpose, e); else for (i=0; i