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.c86
1 files changed, 60 insertions, 26 deletions
diff --git a/src/lib/libssl/src/apps/dsa.c b/src/lib/libssl/src/apps/dsa.c
index fedecf2739..4977671b8a 100644
--- a/src/lib/libssl/src/apps/dsa.c
+++ b/src/lib/libssl/src/apps/dsa.c
@@ -83,6 +83,8 @@
83 * -modulus - print the DSA public key 83 * -modulus - print the DSA public key
84 */ 84 */
85 85
86int MAIN(int, char **);
87
86int MAIN(int argc, char **argv) 88int MAIN(int argc, char **argv)
87 { 89 {
88 int ret=1; 90 int ret=1;
@@ -91,7 +93,10 @@ int MAIN(int argc, char **argv)
91 const EVP_CIPHER *enc=NULL; 93 const EVP_CIPHER *enc=NULL;
92 BIO *in=NULL,*out=NULL; 94 BIO *in=NULL,*out=NULL;
93 int informat,outformat,text=0,noout=0; 95 int informat,outformat,text=0,noout=0;
96 int pubin = 0, pubout = 0;
94 char *infile,*outfile,*prog; 97 char *infile,*outfile,*prog;
98 char *passargin = NULL, *passargout = NULL;
99 char *passin = NULL, *passout = NULL;
95 int modulus=0; 100 int modulus=0;
96 101
97 apps_startup(); 102 apps_startup();
@@ -130,12 +135,26 @@ int MAIN(int argc, char **argv)
130 if (--argc < 1) goto bad; 135 if (--argc < 1) goto bad;
131 outfile= *(++argv); 136 outfile= *(++argv);
132 } 137 }
138 else if (strcmp(*argv,"-passin") == 0)
139 {
140 if (--argc < 1) goto bad;
141 passargin= *(++argv);
142 }
143 else if (strcmp(*argv,"-passout") == 0)
144 {
145 if (--argc < 1) goto bad;
146 passargout= *(++argv);
147 }
133 else if (strcmp(*argv,"-noout") == 0) 148 else if (strcmp(*argv,"-noout") == 0)
134 noout=1; 149 noout=1;
135 else if (strcmp(*argv,"-text") == 0) 150 else if (strcmp(*argv,"-text") == 0)
136 text=1; 151 text=1;
137 else if (strcmp(*argv,"-modulus") == 0) 152 else if (strcmp(*argv,"-modulus") == 0)
138 modulus=1; 153 modulus=1;
154 else if (strcmp(*argv,"-pubin") == 0)
155 pubin=1;
156 else if (strcmp(*argv,"-pubout") == 0)
157 pubout=1;
139 else if ((enc=EVP_get_cipherbyname(&(argv[0][1]))) == NULL) 158 else if ((enc=EVP_get_cipherbyname(&(argv[0][1]))) == NULL)
140 { 159 {
141 BIO_printf(bio_err,"unknown option %s\n",*argv); 160 BIO_printf(bio_err,"unknown option %s\n",*argv);
@@ -151,23 +170,30 @@ int MAIN(int argc, char **argv)
151bad: 170bad:
152 BIO_printf(bio_err,"%s [options] <infile >outfile\n",prog); 171 BIO_printf(bio_err,"%s [options] <infile >outfile\n",prog);
153 BIO_printf(bio_err,"where options are\n"); 172 BIO_printf(bio_err,"where options are\n");
154 BIO_printf(bio_err," -inform arg input format - one of DER NET PEM\n"); 173 BIO_printf(bio_err," -inform arg input format - DER or PEM\n");
155 BIO_printf(bio_err," -outform arg output format - one of DER NET PEM\n"); 174 BIO_printf(bio_err," -outform arg output format - DER or PEM\n");
156 BIO_printf(bio_err," -in arg input file\n"); 175 BIO_printf(bio_err," -in arg input file\n");
157 BIO_printf(bio_err," -out arg output file\n"); 176 BIO_printf(bio_err," -passin arg input file pass phrase source\n");
158 BIO_printf(bio_err," -des encrypt PEM output with cbc des\n"); 177 BIO_printf(bio_err," -out arg output file\n");
159 BIO_printf(bio_err," -des3 encrypt PEM output with ede cbc des using 168 bit key\n"); 178 BIO_printf(bio_err," -passout arg output file pass phrase source\n");
179 BIO_printf(bio_err," -des encrypt PEM output with cbc des\n");
180 BIO_printf(bio_err," -des3 encrypt PEM output with ede cbc des using 168 bit key\n");
160#ifndef NO_IDEA 181#ifndef NO_IDEA
161 BIO_printf(bio_err," -idea encrypt PEM output with cbc idea\n"); 182 BIO_printf(bio_err," -idea encrypt PEM output with cbc idea\n");
162#endif 183#endif
163 BIO_printf(bio_err," -text print the key in text\n"); 184 BIO_printf(bio_err," -text print the key in text\n");
164 BIO_printf(bio_err," -noout don't print key out\n"); 185 BIO_printf(bio_err," -noout don't print key out\n");
165 BIO_printf(bio_err," -modulus print the DSA public value\n"); 186 BIO_printf(bio_err," -modulus print the DSA public value\n");
166 goto end; 187 goto end;
167 } 188 }
168 189
169 ERR_load_crypto_strings(); 190 ERR_load_crypto_strings();
170 191
192 if(!app_passwd(bio_err, passargin, passargout, &passin, &passout)) {
193 BIO_printf(bio_err, "Error getting passwords\n");
194 goto end;
195 }
196
171 in=BIO_new(BIO_s_file()); 197 in=BIO_new(BIO_s_file());
172 out=BIO_new(BIO_s_file()); 198 out=BIO_new(BIO_s_file());
173 if ((in == NULL) || (out == NULL)) 199 if ((in == NULL) || (out == NULL))
@@ -187,19 +213,21 @@ bad:
187 } 213 }
188 } 214 }
189 215
190 BIO_printf(bio_err,"read DSA private key\n"); 216 BIO_printf(bio_err,"read DSA key\n");
191 if (informat == FORMAT_ASN1) 217 if (informat == FORMAT_ASN1) {
192 dsa=d2i_DSAPrivateKey_bio(in,NULL); 218 if(pubin) dsa=d2i_DSA_PUBKEY_bio(in,NULL);
193 else if (informat == FORMAT_PEM) 219 else dsa=d2i_DSAPrivateKey_bio(in,NULL);
194 dsa=PEM_read_bio_DSAPrivateKey(in,NULL,NULL,NULL); 220 } else if (informat == FORMAT_PEM) {
195 else 221 if(pubin) dsa=PEM_read_bio_DSA_PUBKEY(in,NULL, NULL, NULL);
222 else dsa=PEM_read_bio_DSAPrivateKey(in,NULL,NULL,passin);
223 } else
196 { 224 {
197 BIO_printf(bio_err,"bad input format specified for key\n"); 225 BIO_printf(bio_err,"bad input format specified for key\n");
198 goto end; 226 goto end;
199 } 227 }
200 if (dsa == NULL) 228 if (dsa == NULL)
201 { 229 {
202 BIO_printf(bio_err,"unable to load Private Key\n"); 230 BIO_printf(bio_err,"unable to load Key\n");
203 ERR_print_errors(bio_err); 231 ERR_print_errors(bio_err);
204 goto end; 232 goto end;
205 } 233 }
@@ -231,12 +259,16 @@ bad:
231 } 259 }
232 260
233 if (noout) goto end; 261 if (noout) goto end;
234 BIO_printf(bio_err,"writing DSA private key\n"); 262 BIO_printf(bio_err,"writing DSA key\n");
235 if (outformat == FORMAT_ASN1) 263 if (outformat == FORMAT_ASN1) {
236 i=i2d_DSAPrivateKey_bio(out,dsa); 264 if(pubin || pubout) i=i2d_DSA_PUBKEY_bio(out,dsa);
237 else if (outformat == FORMAT_PEM) 265 else i=i2d_DSAPrivateKey_bio(out,dsa);
238 i=PEM_write_bio_DSAPrivateKey(out,dsa,enc,NULL,0,NULL,NULL); 266 } else if (outformat == FORMAT_PEM) {
239 else { 267 if(pubin || pubout)
268 i=PEM_write_bio_DSA_PUBKEY(out,dsa);
269 else i=PEM_write_bio_DSAPrivateKey(out,dsa,enc,
270 NULL,0,NULL, passout);
271 } else {
240 BIO_printf(bio_err,"bad output format specified for outfile\n"); 272 BIO_printf(bio_err,"bad output format specified for outfile\n");
241 goto end; 273 goto end;
242 } 274 }
@@ -248,9 +280,11 @@ bad:
248 else 280 else
249 ret=0; 281 ret=0;
250end: 282end:
251 if (in != NULL) BIO_free(in); 283 if(in != NULL) BIO_free(in);
252 if (out != NULL) BIO_free(out); 284 if(out != NULL) BIO_free(out);
253 if (dsa != NULL) DSA_free(dsa); 285 if(dsa != NULL) DSA_free(dsa);
286 if(passin) Free(passin);
287 if(passout) Free(passout);
254 EXIT(ret); 288 EXIT(ret);
255 } 289 }
256#endif 290#endif