summaryrefslogtreecommitdiff
path: root/src/lib/libssl/src/apps/dsa.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libssl/src/apps/dsa.c')
-rw-r--r--src/lib/libssl/src/apps/dsa.c57
1 files changed, 50 insertions, 7 deletions
diff --git a/src/lib/libssl/src/apps/dsa.c b/src/lib/libssl/src/apps/dsa.c
index cbc1fe3f81..5222487ab9 100644
--- a/src/lib/libssl/src/apps/dsa.c
+++ b/src/lib/libssl/src/apps/dsa.c
@@ -112,6 +112,8 @@ int MAIN(int argc, char **argv)
112 char *passin = NULL, *passout = NULL; 112 char *passin = NULL, *passout = NULL;
113 int modulus=0; 113 int modulus=0;
114 114
115 int pvk_encr = 2;
116
115 apps_startup(); 117 apps_startup();
116 118
117 if (bio_err == NULL) 119 if (bio_err == NULL)
@@ -171,6 +173,12 @@ int MAIN(int argc, char **argv)
171 engine= *(++argv); 173 engine= *(++argv);
172 } 174 }
173#endif 175#endif
176 else if (strcmp(*argv,"-pvk-strong") == 0)
177 pvk_encr=2;
178 else if (strcmp(*argv,"-pvk-weak") == 0)
179 pvk_encr=1;
180 else if (strcmp(*argv,"-pvk-none") == 0)
181 pvk_encr=0;
174 else if (strcmp(*argv,"-noout") == 0) 182 else if (strcmp(*argv,"-noout") == 0)
175 noout=1; 183 noout=1;
176 else if (strcmp(*argv,"-text") == 0) 184 else if (strcmp(*argv,"-text") == 0)
@@ -238,16 +246,30 @@ bad:
238 goto end; 246 goto end;
239 } 247 }
240 248
249 in=BIO_new(BIO_s_file());
241 out=BIO_new(BIO_s_file()); 250 out=BIO_new(BIO_s_file());
242 if (out == NULL) 251 if ((in == NULL) || (out == NULL))
243 { 252 {
244 ERR_print_errors(bio_err); 253 ERR_print_errors(bio_err);
245 goto end; 254 goto end;
246 } 255 }
247 256
257 if (infile == NULL)
258 BIO_set_fp(in,stdin,BIO_NOCLOSE);
259 else
260 {
261 if (BIO_read_filename(in,infile) <= 0)
262 {
263 perror(infile);
264 goto end;
265 }
266 }
267
248 BIO_printf(bio_err,"read DSA key\n"); 268 BIO_printf(bio_err,"read DSA key\n");
249 { 269
270 {
250 EVP_PKEY *pkey; 271 EVP_PKEY *pkey;
272
251 if (pubin) 273 if (pubin)
252 pkey = load_pubkey(bio_err, infile, informat, 1, 274 pkey = load_pubkey(bio_err, infile, informat, 1,
253 passin, e, "Public Key"); 275 passin, e, "Public Key");
@@ -255,10 +277,12 @@ bad:
255 pkey = load_key(bio_err, infile, informat, 1, 277 pkey = load_key(bio_err, infile, informat, 1,
256 passin, e, "Private Key"); 278 passin, e, "Private Key");
257 279
258 if (pkey != NULL) 280 if (pkey)
259 dsa = pkey == NULL ? NULL : EVP_PKEY_get1_DSA(pkey); 281 {
260 EVP_PKEY_free(pkey); 282 dsa = EVP_PKEY_get1_DSA(pkey);
261 } 283 EVP_PKEY_free(pkey);
284 }
285 }
262 if (dsa == NULL) 286 if (dsa == NULL)
263 { 287 {
264 BIO_printf(bio_err,"unable to load Key\n"); 288 BIO_printf(bio_err,"unable to load Key\n");
@@ -310,11 +334,24 @@ bad:
310 i=PEM_write_bio_DSA_PUBKEY(out,dsa); 334 i=PEM_write_bio_DSA_PUBKEY(out,dsa);
311 else i=PEM_write_bio_DSAPrivateKey(out,dsa,enc, 335 else i=PEM_write_bio_DSAPrivateKey(out,dsa,enc,
312 NULL,0,NULL, passout); 336 NULL,0,NULL, passout);
337#if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_RC4)
338 } else if (outformat == FORMAT_MSBLOB || outformat == FORMAT_PVK) {
339 EVP_PKEY *pk;
340 pk = EVP_PKEY_new();
341 EVP_PKEY_set1_DSA(pk, dsa);
342 if (outformat == FORMAT_PVK)
343 i = i2b_PVK_bio(out, pk, pvk_encr, 0, passout);
344 else if (pubin || pubout)
345 i = i2b_PublicKey_bio(out, pk);
346 else
347 i = i2b_PrivateKey_bio(out, pk);
348 EVP_PKEY_free(pk);
349#endif
313 } else { 350 } else {
314 BIO_printf(bio_err,"bad output format specified for outfile\n"); 351 BIO_printf(bio_err,"bad output format specified for outfile\n");
315 goto end; 352 goto end;
316 } 353 }
317 if (!i) 354 if (i <= 0)
318 { 355 {
319 BIO_printf(bio_err,"unable to write private key\n"); 356 BIO_printf(bio_err,"unable to write private key\n");
320 ERR_print_errors(bio_err); 357 ERR_print_errors(bio_err);
@@ -330,4 +367,10 @@ end:
330 apps_shutdown(); 367 apps_shutdown();
331 OPENSSL_EXIT(ret); 368 OPENSSL_EXIT(ret);
332 } 369 }
370#else /* !OPENSSL_NO_DSA */
371
372# if PEDANTIC
373static void *dummy=&dummy;
374# endif
375
333#endif 376#endif