X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=apps%2Fdhparam.c;h=bd91234abd664d6e2cbeb46c5862e12aae4ff17e;hb=50615b3c969d1cc2d4beb09f141c678bfe06382b;hp=0ab16e8d2ff13d754cc74959cd1f22b3ba6fcde8;hpb=aa01b82c69eeb0cfd255174111fc34a7ed5f8429;p=oweals%2Fopenssl.git diff --git a/apps/dhparam.c b/apps/dhparam.c index 0ab16e8d2f..bd91234abd 100644 --- a/apps/dhparam.c +++ b/apps/dhparam.c @@ -159,10 +159,8 @@ int MAIN(int argc, char **argv) int informat, outformat, check = 0, noout = 0, C = 0, ret = 1; char *infile, *outfile, *prog; char *inrand = NULL; -# ifndef OPENSSL_NO_ENGINE char *engine = NULL; ENGINE *e = NULL; -# endif int num = 0, g = 0; apps_startup(); @@ -271,9 +269,7 @@ int MAIN(int argc, char **argv) ERR_load_crypto_strings(); -# ifndef OPENSSL_NO_ENGINE e = setup_engine(bio_err, engine, 0); -# endif if (g && !num) num = DEFBITS; @@ -385,10 +381,19 @@ int MAIN(int argc, char **argv) } else # endif { - if (informat == FORMAT_ASN1) + if (informat == FORMAT_ASN1) { + /* + * We have no PEM header to determine what type of DH params it + * is. We'll just try both. + */ dh = d2i_DHparams_bio(in, NULL); - else /* informat == FORMAT_PEM */ + /* BIO_reset() returns 0 for success for file BIOs only!!! */ + if (dh == NULL && BIO_reset(in) == 0) + dh = d2i_DHxparams_bio(in, NULL); + } else { + /* informat == FORMAT_PEM */ dh = PEM_read_bio_DHparams(in, NULL, NULL, NULL); + } if (dh == NULL) { BIO_printf(bio_err, "unable to load DH parameters\n"); @@ -488,10 +493,13 @@ int MAIN(int argc, char **argv) } if (!noout) { - if (outformat == FORMAT_ASN1) - i = i2d_DHparams_bio(out, dh); - else if (outformat == FORMAT_PEM) { - if (dh->q) + if (outformat == FORMAT_ASN1) { + if (dh->q != NULL) + i = i2d_DHxparams_bio(out, dh); + else + i = i2d_DHparams_bio(out, dh); + } else if (outformat == FORMAT_PEM) { + if (dh->q != NULL) i = PEM_write_bio_DHxparams(out, dh); else i = PEM_write_bio_DHparams(out, dh); @@ -513,10 +521,7 @@ int MAIN(int argc, char **argv) BIO_free_all(out); if (dh != NULL) DH_free(dh); -# ifndef OPENSSL_NO_ENGINE - if (e != NULL) - release_engine(e); -# endif + release_engine(e); apps_shutdown(); OPENSSL_EXIT(ret); }