X-Git-Url: https://git.openssl.org/?a=blobdiff_plain;f=apps%2Fdsa.c;h=091f936571d9f2f703872b9f72b7e00046c5a5bc;hb=228b4e426b5b8998ca23587d6de5a73690e27a02;hp=e9de3a3bdfb6f55aa6c7de6dbb609d764b35d4b7;hpb=0b13e9f055d3f7be066dc2e89fc9f9822b12eca7;p=openssl.git diff --git a/apps/dsa.c b/apps/dsa.c index e9de3a3bdf..091f936571 100644 --- a/apps/dsa.c +++ b/apps/dsa.c @@ -56,6 +56,7 @@ * [including the GNU Public Licence.] */ +#include /* for OPENSSL_NO_DSA */ #ifndef OPENSSL_NO_DSA #include #include @@ -68,6 +69,7 @@ #include #include #include +#include #undef PROG #define PROG dsa_main @@ -108,6 +110,8 @@ int MAIN(int argc, char **argv) char *passin = NULL, *passout = NULL; int modulus=0; + int pvk_encr = 2; + apps_startup(); if (bio_err == NULL) @@ -167,6 +171,12 @@ int MAIN(int argc, char **argv) engine= *(++argv); } #endif + else if (strcmp(*argv,"-pvk-strong") == 0) + pvk_encr=2; + else if (strcmp(*argv,"-pvk-weak") == 0) + pvk_encr=1; + else if (strcmp(*argv,"-pvk-none") == 0) + pvk_encr=0; else if (strcmp(*argv,"-noout") == 0) noout=1; else if (strcmp(*argv,"-text") == 0) @@ -247,16 +257,22 @@ bad: } BIO_printf(bio_err,"read DSA key\n"); - if (informat == FORMAT_ASN1) { - if(pubin) dsa=d2i_DSA_PUBKEY_bio(in,NULL); - else dsa=d2i_DSAPrivateKey_bio(in,NULL); - } else if (informat == FORMAT_PEM) { - if(pubin) dsa=PEM_read_bio_DSA_PUBKEY(in,NULL, NULL, NULL); - else dsa=PEM_read_bio_DSAPrivateKey(in,NULL,NULL,passin); - } else + { - BIO_printf(bio_err,"bad input format specified for key\n"); - goto end; + EVP_PKEY *pkey; + + if (pubin) + pkey = load_pubkey(bio_err, infile, informat, 1, + passin, e, "Public Key"); + else + pkey = load_key(bio_err, infile, informat, 1, + passin, e, "Private Key"); + + if (pkey) + { + dsa = EVP_PKEY_get1_DSA(pkey); + EVP_PKEY_free(pkey); + } } if (dsa == NULL) { @@ -309,6 +325,17 @@ bad: i=PEM_write_bio_DSA_PUBKEY(out,dsa); else i=PEM_write_bio_DSAPrivateKey(out,dsa,enc, NULL,0,NULL, passout); + } else if (outformat == FORMAT_MSBLOB || outformat == FORMAT_PVK) { + EVP_PKEY *pk; + pk = EVP_PKEY_new(); + EVP_PKEY_set1_DSA(pk, dsa); + if (outformat == FORMAT_PVK) + i = i2b_PVK_bio(out, pk, pvk_encr, 0, passout); + else if (pubin || pubout) + i = i2b_PublicKey_bio(out, pk); + else + i = i2b_PrivateKey_bio(out, pk); + EVP_PKEY_free(pk); } else { BIO_printf(bio_err,"bad output format specified for outfile\n"); goto end;