X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=apps%2Frsa.c;h=60a33815276443949c23f32cf9b0d9ffe6213a09;hb=1aecc34e9ee95db71f6f033e9c61aa2d80d2c864;hp=18964fedd2f00ed8428bcb30ea64acf549c06f77;hpb=c04f8cf44a3b204b82f5f1f5d1ad9dbc738459f1;p=oweals%2Fopenssl.git diff --git a/apps/rsa.c b/apps/rsa.c index 18964fedd2..60a3381527 100644 --- a/apps/rsa.c +++ b/apps/rsa.c @@ -68,7 +68,6 @@ #include #include #include -#include #undef PROG #define PROG rsa_main @@ -80,6 +79,9 @@ * -des - encrypt output if PEM format with DES in cbc mode * -des3 - encrypt output if PEM format * -idea - encrypt output if PEM format + * -aes128 - encrypt output if PEM format + * -aes192 - encrypt output if PEM format + * -aes256 - encrypt output if PEM format * -text - print a text version * -modulus - print the RSA key modulus * -check - verify key consistency @@ -96,7 +98,7 @@ int MAIN(int argc, char **argv) RSA *rsa=NULL; int i,badops=0, sgckey=0; const EVP_CIPHER *enc=NULL; - BIO *in=NULL,*out=NULL; + BIO *out=NULL; int informat,outformat,text=0,check=0,noout=0; int pubin = 0, pubout = 0; char *infile,*outfile,*prog; @@ -111,6 +113,9 @@ int MAIN(int argc, char **argv) if ((bio_err=BIO_new(BIO_s_file())) != NULL) BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); + if (!load_config(bio_err, NULL)) + goto end; + infile=NULL; outfile=NULL; informat=FORMAT_PEM; @@ -196,6 +201,10 @@ bad: BIO_printf(bio_err," -des3 encrypt PEM output with ede cbc des using 168 bit key\n"); #ifndef OPENSSL_NO_IDEA BIO_printf(bio_err," -idea encrypt PEM output with cbc idea\n"); +#endif +#ifndef OPENSSL_NO_AES + BIO_printf(bio_err," -aes128, -aes192, -aes256\n"); + BIO_printf(bio_err," encrypt PEM output with cbc aes\n"); #endif BIO_printf(bio_err," -text print the key in text\n"); BIO_printf(bio_err," -noout don't print key out\n"); @@ -221,69 +230,29 @@ bad: goto end; } - in=BIO_new(BIO_s_file()); out=BIO_new(BIO_s_file()); - if ((in == NULL) || (out == NULL)) - { - ERR_print_errors(bio_err); - goto end; - } - if (infile == NULL) - BIO_set_fp(in,stdin,BIO_NOCLOSE); - else - { - if (BIO_read_filename(in,infile) <= 0) - { - perror(infile); - goto end; - } - } + { + EVP_PKEY *pkey; - BIO_printf(bio_err,"read RSA key\n"); - if (informat == FORMAT_ASN1) { - if (pubin) rsa=d2i_RSA_PUBKEY_bio(in,NULL); - else rsa=d2i_RSAPrivateKey_bio(in,NULL); - } -#ifndef OPENSSL_NO_RC4 - else if (informat == FORMAT_NETSCAPE) - { - BUF_MEM *buf=NULL; - const unsigned char *p; - int size=0; + if (pubin) + pkey = load_pubkey(bio_err, infile, + (informat == FORMAT_NETSCAPE && sgckey ? + FORMAT_IISSGC : informat), + passin, e, "Public Key"); + else + pkey = load_key(bio_err, infile, + (informat == FORMAT_NETSCAPE && sgckey ? + FORMAT_IISSGC : informat), + passin, e, "Private Key"); - buf=BUF_MEM_new(); - for (;;) - { - if ((buf == NULL) || (!BUF_MEM_grow(buf,size+1024*10))) - goto end; - i=BIO_read(in,&(buf->data[size]),1024*10); - size+=i; - if (i == 0) break; - if (i < 0) - { - perror("reading private key"); - BUF_MEM_free(buf); - goto end; - } - } - p=(unsigned char *)buf->data; - rsa=d2i_RSA_NET(NULL,&p,(long)size,NULL, sgckey); - BUF_MEM_free(buf); - } -#endif - else if (informat == FORMAT_PEM) { - if(pubin) rsa=PEM_read_bio_RSA_PUBKEY(in,NULL,NULL,NULL); - else rsa=PEM_read_bio_RSAPrivateKey(in,NULL, NULL,passin); + if (pkey != NULL) + rsa = pkey == NULL ? NULL : EVP_PKEY_get1_RSA(pkey); + EVP_PKEY_free(pkey); } - else - { - BIO_printf(bio_err,"bad input format specified for key\n"); - goto end; - } + if (rsa == NULL) { - BIO_printf(bio_err,"unable to load key\n"); ERR_print_errors(bio_err); goto end; } @@ -395,7 +364,6 @@ bad: else ret=0; end: - if(in != NULL) BIO_free(in); if(out != NULL) BIO_free_all(out); if(rsa != NULL) RSA_free(rsa); if(passin) OPENSSL_free(passin);