diff options
Diffstat (limited to 'src/lib/libssl/src/apps/dsa.c')
| -rw-r--r-- | src/lib/libssl/src/apps/dsa.c | 140 |
1 files changed, 101 insertions, 39 deletions
diff --git a/src/lib/libssl/src/apps/dsa.c b/src/lib/libssl/src/apps/dsa.c index fbd85a467a..9da1a41645 100644 --- a/src/lib/libssl/src/apps/dsa.c +++ b/src/lib/libssl/src/apps/dsa.c | |||
| @@ -56,17 +56,18 @@ | |||
| 56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
| 57 | */ | 57 | */ |
| 58 | 58 | ||
| 59 | #ifndef OPENSSL_NO_DSA | ||
| 59 | #include <stdio.h> | 60 | #include <stdio.h> |
| 60 | #include <stdlib.h> | 61 | #include <stdlib.h> |
| 61 | #include <string.h> | 62 | #include <string.h> |
| 62 | #include <time.h> | 63 | #include <time.h> |
| 63 | #include "apps.h" | 64 | #include "apps.h" |
| 64 | #include "bio.h" | 65 | #include <openssl/bio.h> |
| 65 | #include "err.h" | 66 | #include <openssl/err.h> |
| 66 | #include "dsa.h" | 67 | #include <openssl/dsa.h> |
| 67 | #include "evp.h" | 68 | #include <openssl/evp.h> |
| 68 | #include "x509.h" | 69 | #include <openssl/x509.h> |
| 69 | #include "pem.h" | 70 | #include <openssl/pem.h> |
| 70 | 71 | ||
| 71 | #undef PROG | 72 | #undef PROG |
| 72 | #define PROG dsa_main | 73 | #define PROG dsa_main |
| @@ -78,21 +79,28 @@ | |||
| 78 | * -des - encrypt output if PEM format with DES in cbc mode | 79 | * -des - encrypt output if PEM format with DES in cbc mode |
| 79 | * -des3 - encrypt output if PEM format | 80 | * -des3 - encrypt output if PEM format |
| 80 | * -idea - encrypt output if PEM format | 81 | * -idea - encrypt output if PEM format |
| 82 | * -aes128 - encrypt output if PEM format | ||
| 83 | * -aes192 - encrypt output if PEM format | ||
| 84 | * -aes256 - encrypt output if PEM format | ||
| 81 | * -text - print a text version | 85 | * -text - print a text version |
| 82 | * -modulus - print the DSA public key | 86 | * -modulus - print the DSA public key |
| 83 | */ | 87 | */ |
| 84 | 88 | ||
| 85 | int MAIN(argc, argv) | 89 | int MAIN(int, char **); |
| 86 | int argc; | 90 | |
| 87 | char **argv; | 91 | int MAIN(int argc, char **argv) |
| 88 | { | 92 | { |
| 93 | ENGINE *e = NULL; | ||
| 89 | int ret=1; | 94 | int ret=1; |
| 90 | DSA *dsa=NULL; | 95 | DSA *dsa=NULL; |
| 91 | int i,badops=0; | 96 | int i,badops=0; |
| 92 | EVP_CIPHER *enc=NULL; | 97 | const EVP_CIPHER *enc=NULL; |
| 93 | BIO *in=NULL,*out=NULL; | 98 | BIO *in=NULL,*out=NULL; |
| 94 | int informat,outformat,text=0,noout=0; | 99 | int informat,outformat,text=0,noout=0; |
| 95 | char *infile,*outfile,*prog; | 100 | int pubin = 0, pubout = 0; |
| 101 | char *infile,*outfile,*prog,*engine; | ||
| 102 | char *passargin = NULL, *passargout = NULL; | ||
| 103 | char *passin = NULL, *passout = NULL; | ||
| 96 | int modulus=0; | 104 | int modulus=0; |
| 97 | 105 | ||
| 98 | apps_startup(); | 106 | apps_startup(); |
| @@ -101,6 +109,10 @@ char **argv; | |||
| 101 | if ((bio_err=BIO_new(BIO_s_file())) != NULL) | 109 | if ((bio_err=BIO_new(BIO_s_file())) != NULL) |
| 102 | BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); | 110 | BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); |
| 103 | 111 | ||
| 112 | if (!load_config(bio_err, NULL)) | ||
| 113 | goto end; | ||
| 114 | |||
| 115 | engine=NULL; | ||
| 104 | infile=NULL; | 116 | infile=NULL; |
| 105 | outfile=NULL; | 117 | outfile=NULL; |
| 106 | informat=FORMAT_PEM; | 118 | informat=FORMAT_PEM; |
| @@ -131,12 +143,31 @@ char **argv; | |||
| 131 | if (--argc < 1) goto bad; | 143 | if (--argc < 1) goto bad; |
| 132 | outfile= *(++argv); | 144 | outfile= *(++argv); |
| 133 | } | 145 | } |
| 146 | else if (strcmp(*argv,"-passin") == 0) | ||
| 147 | { | ||
| 148 | if (--argc < 1) goto bad; | ||
| 149 | passargin= *(++argv); | ||
| 150 | } | ||
| 151 | else if (strcmp(*argv,"-passout") == 0) | ||
| 152 | { | ||
| 153 | if (--argc < 1) goto bad; | ||
| 154 | passargout= *(++argv); | ||
| 155 | } | ||
| 156 | else if (strcmp(*argv,"-engine") == 0) | ||
| 157 | { | ||
| 158 | if (--argc < 1) goto bad; | ||
| 159 | engine= *(++argv); | ||
| 160 | } | ||
| 134 | else if (strcmp(*argv,"-noout") == 0) | 161 | else if (strcmp(*argv,"-noout") == 0) |
| 135 | noout=1; | 162 | noout=1; |
| 136 | else if (strcmp(*argv,"-text") == 0) | 163 | else if (strcmp(*argv,"-text") == 0) |
| 137 | text=1; | 164 | text=1; |
| 138 | else if (strcmp(*argv,"-modulus") == 0) | 165 | else if (strcmp(*argv,"-modulus") == 0) |
| 139 | modulus=1; | 166 | modulus=1; |
| 167 | else if (strcmp(*argv,"-pubin") == 0) | ||
| 168 | pubin=1; | ||
| 169 | else if (strcmp(*argv,"-pubout") == 0) | ||
| 170 | pubout=1; | ||
| 140 | else if ((enc=EVP_get_cipherbyname(&(argv[0][1]))) == NULL) | 171 | else if ((enc=EVP_get_cipherbyname(&(argv[0][1]))) == NULL) |
| 141 | { | 172 | { |
| 142 | BIO_printf(bio_err,"unknown option %s\n",*argv); | 173 | BIO_printf(bio_err,"unknown option %s\n",*argv); |
| @@ -152,23 +183,37 @@ char **argv; | |||
| 152 | bad: | 183 | bad: |
| 153 | BIO_printf(bio_err,"%s [options] <infile >outfile\n",prog); | 184 | BIO_printf(bio_err,"%s [options] <infile >outfile\n",prog); |
| 154 | BIO_printf(bio_err,"where options are\n"); | 185 | BIO_printf(bio_err,"where options are\n"); |
| 155 | BIO_printf(bio_err," -inform arg input format - one of DER NET PEM\n"); | 186 | BIO_printf(bio_err," -inform arg input format - DER or PEM\n"); |
| 156 | BIO_printf(bio_err," -outform arg output format - one of DER NET PEM\n"); | 187 | BIO_printf(bio_err," -outform arg output format - DER or PEM\n"); |
| 157 | BIO_printf(bio_err," -in arg inout file\n"); | 188 | BIO_printf(bio_err," -in arg input file\n"); |
| 158 | BIO_printf(bio_err," -out arg output file\n"); | 189 | BIO_printf(bio_err," -passin arg input file pass phrase source\n"); |
| 159 | BIO_printf(bio_err," -des encrypt PEM output with cbc des\n"); | 190 | BIO_printf(bio_err," -out arg output file\n"); |
| 160 | BIO_printf(bio_err," -des3 encrypt PEM output with ede cbc des using 168 bit key\n"); | 191 | BIO_printf(bio_err," -passout arg output file pass phrase source\n"); |
| 161 | #ifndef NO_IDEA | 192 | BIO_printf(bio_err," -engine e use engine e, possibly a hardware device.\n"); |
| 162 | BIO_printf(bio_err," -idea encrypt PEM output with cbc idea\n"); | 193 | BIO_printf(bio_err," -des encrypt PEM output with cbc des\n"); |
| 194 | BIO_printf(bio_err," -des3 encrypt PEM output with ede cbc des using 168 bit key\n"); | ||
| 195 | #ifndef OPENSSL_NO_IDEA | ||
| 196 | BIO_printf(bio_err," -idea encrypt PEM output with cbc idea\n"); | ||
| 197 | #endif | ||
| 198 | #ifndef OPENSSL_NO_AES | ||
| 199 | BIO_printf(bio_err," -aes128, -aes192, -aes256\n"); | ||
| 200 | BIO_printf(bio_err," encrypt PEM output with cbc aes\n"); | ||
| 163 | #endif | 201 | #endif |
| 164 | BIO_printf(bio_err," -text print the key in text\n"); | 202 | BIO_printf(bio_err," -text print the key in text\n"); |
| 165 | BIO_printf(bio_err," -noout don't print key out\n"); | 203 | BIO_printf(bio_err," -noout don't print key out\n"); |
| 166 | BIO_printf(bio_err," -modulus print the DSA public value\n"); | 204 | BIO_printf(bio_err," -modulus print the DSA public value\n"); |
| 167 | goto end; | 205 | goto end; |
| 168 | } | 206 | } |
| 169 | 207 | ||
| 170 | ERR_load_crypto_strings(); | 208 | ERR_load_crypto_strings(); |
| 171 | 209 | ||
| 210 | e = setup_engine(bio_err, engine, 0); | ||
| 211 | |||
| 212 | if(!app_passwd(bio_err, passargin, passargout, &passin, &passout)) { | ||
| 213 | BIO_printf(bio_err, "Error getting passwords\n"); | ||
| 214 | goto end; | ||
| 215 | } | ||
| 216 | |||
| 172 | in=BIO_new(BIO_s_file()); | 217 | in=BIO_new(BIO_s_file()); |
| 173 | out=BIO_new(BIO_s_file()); | 218 | out=BIO_new(BIO_s_file()); |
| 174 | if ((in == NULL) || (out == NULL)) | 219 | if ((in == NULL) || (out == NULL)) |
| @@ -188,25 +233,35 @@ bad: | |||
| 188 | } | 233 | } |
| 189 | } | 234 | } |
| 190 | 235 | ||
| 191 | BIO_printf(bio_err,"read DSA private key\n"); | 236 | BIO_printf(bio_err,"read DSA key\n"); |
| 192 | if (informat == FORMAT_ASN1) | 237 | if (informat == FORMAT_ASN1) { |
| 193 | dsa=d2i_DSAPrivateKey_bio(in,NULL); | 238 | if(pubin) dsa=d2i_DSA_PUBKEY_bio(in,NULL); |
| 194 | else if (informat == FORMAT_PEM) | 239 | else dsa=d2i_DSAPrivateKey_bio(in,NULL); |
| 195 | dsa=PEM_read_bio_DSAPrivateKey(in,NULL,NULL); | 240 | } else if (informat == FORMAT_PEM) { |
| 196 | else | 241 | if(pubin) dsa=PEM_read_bio_DSA_PUBKEY(in,NULL, NULL, NULL); |
| 242 | else dsa=PEM_read_bio_DSAPrivateKey(in,NULL,NULL,passin); | ||
| 243 | } else | ||
| 197 | { | 244 | { |
| 198 | BIO_printf(bio_err,"bad input format specified for key\n"); | 245 | BIO_printf(bio_err,"bad input format specified for key\n"); |
| 199 | goto end; | 246 | goto end; |
| 200 | } | 247 | } |
| 201 | if (dsa == NULL) | 248 | if (dsa == NULL) |
| 202 | { | 249 | { |
| 203 | BIO_printf(bio_err,"unable to load Private Key\n"); | 250 | BIO_printf(bio_err,"unable to load Key\n"); |
| 204 | ERR_print_errors(bio_err); | 251 | ERR_print_errors(bio_err); |
| 205 | goto end; | 252 | goto end; |
| 206 | } | 253 | } |
| 207 | 254 | ||
| 208 | if (outfile == NULL) | 255 | if (outfile == NULL) |
| 256 | { | ||
| 209 | BIO_set_fp(out,stdout,BIO_NOCLOSE); | 257 | BIO_set_fp(out,stdout,BIO_NOCLOSE); |
| 258 | #ifdef OPENSSL_SYS_VMS | ||
| 259 | { | ||
| 260 | BIO *tmpbio = BIO_new(BIO_f_linebuffer()); | ||
| 261 | out = BIO_push(tmpbio, out); | ||
| 262 | } | ||
| 263 | #endif | ||
| 264 | } | ||
| 210 | else | 265 | else |
| 211 | { | 266 | { |
| 212 | if (BIO_write_filename(out,outfile) <= 0) | 267 | if (BIO_write_filename(out,outfile) <= 0) |
| @@ -232,12 +287,16 @@ bad: | |||
| 232 | } | 287 | } |
| 233 | 288 | ||
| 234 | if (noout) goto end; | 289 | if (noout) goto end; |
| 235 | BIO_printf(bio_err,"writing DSA private key\n"); | 290 | BIO_printf(bio_err,"writing DSA key\n"); |
| 236 | if (outformat == FORMAT_ASN1) | 291 | if (outformat == FORMAT_ASN1) { |
| 237 | i=i2d_DSAPrivateKey_bio(out,dsa); | 292 | if(pubin || pubout) i=i2d_DSA_PUBKEY_bio(out,dsa); |
| 238 | else if (outformat == FORMAT_PEM) | 293 | else i=i2d_DSAPrivateKey_bio(out,dsa); |
| 239 | i=PEM_write_bio_DSAPrivateKey(out,dsa,enc,NULL,0,NULL); | 294 | } else if (outformat == FORMAT_PEM) { |
| 240 | else { | 295 | if(pubin || pubout) |
| 296 | i=PEM_write_bio_DSA_PUBKEY(out,dsa); | ||
| 297 | else i=PEM_write_bio_DSAPrivateKey(out,dsa,enc, | ||
| 298 | NULL,0,NULL, passout); | ||
| 299 | } else { | ||
| 241 | BIO_printf(bio_err,"bad output format specified for outfile\n"); | 300 | BIO_printf(bio_err,"bad output format specified for outfile\n"); |
| 242 | goto end; | 301 | goto end; |
| 243 | } | 302 | } |
| @@ -249,9 +308,12 @@ bad: | |||
| 249 | else | 308 | else |
| 250 | ret=0; | 309 | ret=0; |
| 251 | end: | 310 | end: |
| 252 | if (in != NULL) BIO_free(in); | 311 | if(in != NULL) BIO_free(in); |
| 253 | if (out != NULL) BIO_free(out); | 312 | if(out != NULL) BIO_free_all(out); |
| 254 | if (dsa != NULL) DSA_free(dsa); | 313 | if(dsa != NULL) DSA_free(dsa); |
| 314 | if(passin) OPENSSL_free(passin); | ||
| 315 | if(passout) OPENSSL_free(passout); | ||
| 316 | apps_shutdown(); | ||
| 255 | EXIT(ret); | 317 | EXIT(ret); |
| 256 | } | 318 | } |
| 257 | 319 | #endif | |
