add missing 'static'
[openssl.git] / apps / smime.c
index 9c84841..f0c3027 100644 (file)
@@ -101,8 +101,10 @@ int MAIN(int argc, char **argv)
        int badarg = 0;
        int flags = PKCS7_DETACHED;
        char *to = NULL, *from = NULL, *subject = NULL;
-       char *CAfile = NULL, *CApath = NULL, *passin = NULL;
-
+       char *CAfile = NULL, *CApath = NULL;
+       char *passargin = NULL, *passin = NULL;
+       char *inrand = NULL;
+       int need_rand = 0;
        args = argv + 1;
 
        ret = 1;
@@ -145,17 +147,17 @@ int MAIN(int argc, char **argv)
                                flags |= PKCS7_BINARY;
                else if (!strcmp (*args, "-nosigs"))
                                flags |= PKCS7_NOSIGS;
-               else if (!strcmp(*argv,"-passin")) {
-                       if (--argc < 1) badarg = 1;
-                       else passin= *(++argv);
-               } else if (!strcmp(*argv,"-envpassin")) {
-                       if (--argc < 1) badarg = 1;
-                       else if(!(passin= getenv(*(++argv)))) {
-                               BIO_printf(bio_err,
-                                "Can't read environment variable %s\n",
-                                                               *argv);
-                               badarg = 1;
-                       }
+               else if (!strcmp(*args,"-rand")) {
+                       if (args[1]) {
+                               args++;
+                               inrand = *args;
+                       } else badarg = 1;
+                       need_rand = 1;
+               } else if (!strcmp(*args,"-passin")) {
+                       if (args[1]) {
+                               args++;
+                               passargin = *args;
+                       } else badarg = 1;
                } else if (!strcmp (*args, "-to")) {
                        if (args[1]) {
                                args++;
@@ -220,6 +222,7 @@ int MAIN(int argc, char **argv)
                        BIO_printf(bio_err, "No signer certificate specified\n");
                        badarg = 1;
                }
+               need_rand = 1;
        } else if(operation == SMIME_DECRYPT) {
                if(!recipfile) {
                        BIO_printf(bio_err, "No recipient certificate and key specified\n");
@@ -230,6 +233,7 @@ int MAIN(int argc, char **argv)
                        BIO_printf(bio_err, "No recipient(s) certificate(s) specified\n");
                        badarg = 1;
                }
+               need_rand = 1;
        } else if(!operation) badarg = 1;
 
        if (badarg) {
@@ -268,10 +272,25 @@ int MAIN(int argc, char **argv)
                BIO_printf (bio_err, "-text          include or delete text MIME headers\n");
                BIO_printf (bio_err, "-CApath dir    trusted certificates directory\n");
                BIO_printf (bio_err, "-CAfile file   trusted certificates file\n");
+               BIO_printf(bio_err,  "-rand file:file:...\n");
+               BIO_printf(bio_err,  "               load the file (or the files in the directory) into\n");
+               BIO_printf(bio_err,  "               the random number generator\n");
                BIO_printf (bio_err, "cert.pem       recipient certificate(s) for encryption\n");
                goto end;
        }
 
+       if(!app_passwd(bio_err, passargin, NULL, &passin, NULL)) {
+               BIO_printf(bio_err, "Error getting password\n");
+               goto end;
+       }
+
+       if (need_rand) {
+               app_RAND_load_file(NULL, bio_err, (inrand != NULL));
+               if (inrand != NULL)
+                       BIO_printf(bio_err,"%ld semi-random bytes loaded\n",
+                               app_RAND_load_files(inrand));
+       }
+
        ret = 2;
 
        if(operation != SMIME_SIGN) flags &= ~PKCS7_DETACHED;
@@ -499,6 +518,8 @@ end:
 #ifdef CRYPTO_MDEBUG
        CRYPTO_remove_all_info();
 #endif
+       if (need_rand)
+               app_RAND_write_file(NULL, bio_err);
        if(ret) ERR_print_errors(bio_err);
        sk_X509_pop_free(encerts, X509_free);
        sk_X509_pop_free(other, X509_free);
@@ -511,6 +532,7 @@ end:
        BIO_free(in);
        BIO_free(indata);
        BIO_free(out);
+       if(passin) Free(passin);
        return (ret);
 }
 
@@ -529,7 +551,7 @@ static EVP_PKEY *load_key(char *file, char *pass)
        BIO *in;
        EVP_PKEY *key;
        if(!(in = BIO_new_file(file, "r"))) return NULL;
-       key = PEM_read_bio_PrivateKey(in, NULL,PEM_cb,pass);
+       key = PEM_read_bio_PrivateKey(in, NULL,NULL,pass);
        BIO_free(in);
        return key;
 }
@@ -609,7 +631,7 @@ static X509_STORE *setup_verify(char *CAfile, char *CApath)
        return NULL;
 }
 
-int save_certs(char *signerfile, STACK_OF(X509) *signers)
+static int save_certs(char *signerfile, STACK_OF(X509) *signers)
 {
        int i;
        BIO *tmp;