Fill in missing information about the string returned from
[openssl.git] / apps / smime.c
index e380443d6c4f3369d738e32411c9995f5764f78b..0a16bbc4dd638b58961c216fca51b85bed653cb1 100644 (file)
@@ -64,6 +64,7 @@
 #include <openssl/crypto.h>
 #include <openssl/pem.h>
 #include <openssl/err.h>
+#include <openssl/engine.h>
 
 #undef PROG
 #define PROG smime_main
@@ -81,6 +82,7 @@ int MAIN(int, char **);
 
 int MAIN(int argc, char **argv)
 {
+       ENGINE *e = NULL;
        int operation = 0;
        int ret = 0;
        char **args;
@@ -103,8 +105,9 @@ int MAIN(int argc, char **argv)
        char *inrand = NULL;
        int need_rand = 0;
        int informat = FORMAT_SMIME, outformat = FORMAT_SMIME;
-       args = argv + 1;
+       char *engine=NULL;
 
+       args = argv + 1;
        ret = 1;
 
        while (!badarg && *args && *args[0] == '-') {
@@ -141,6 +144,8 @@ int MAIN(int argc, char **argv)
                                flags |= PKCS7_NOATTR;
                else if (!strcmp (*args, "-nodetach")) 
                                flags &= ~PKCS7_DETACHED;
+               else if (!strcmp (*args, "-nosmimecap"))
+                               flags |= PKCS7_NOSMIMECAP;
                else if (!strcmp (*args, "-binary"))
                                flags |= PKCS7_BINARY;
                else if (!strcmp (*args, "-nosigs"))
@@ -151,6 +156,11 @@ int MAIN(int argc, char **argv)
                                inrand = *args;
                        } else badarg = 1;
                        need_rand = 1;
+               } else if (!strcmp(*args,"-engine")) {
+                       if (args[1]) {
+                               args++;
+                               engine = *args;
+                       } else badarg = 1;
                } else if (!strcmp(*args,"-passin")) {
                        if (args[1]) {
                                args++;
@@ -288,6 +298,7 @@ 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, "-engine e      use engine e, possibly a hardware device.\n");
                BIO_printf(bio_err,  "-rand file%cfile%c...\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR);
                BIO_printf(bio_err,  "               load the file (or the files in the directory) into\n");
                BIO_printf(bio_err,  "               the random number generator\n");
@@ -295,6 +306,24 @@ int MAIN(int argc, char **argv)
                goto end;
        }
 
+       if (engine != NULL)
+               {
+               if((e = ENGINE_by_id(engine)) == NULL)
+                       {
+                       BIO_printf(bio_err,"invalid engine \"%s\"\n",
+                               engine);
+                       goto end;
+                       }
+               if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
+                       {
+                       BIO_printf(bio_err,"can't use that engine\n");
+                       goto end;
+                       }
+               BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
+               /* Free our "structural" reference. */
+               ENGINE_free(e);
+               }
+
        if(!app_passwd(bio_err, passargin, NULL, &passin, NULL)) {
                BIO_printf(bio_err, "Error getting password\n");
                goto end;
@@ -370,7 +399,7 @@ int MAIN(int argc, char **argv)
        } else keyfile = NULL;
 
        if(keyfile) {
-               if(!(key = load_key(bio_err,keyfile, FORMAT_PEM, passin))) {
+               if(!(key = load_key(bio_err,keyfile, FORMAT_PEM, passin, NULL))) {
                        BIO_printf(bio_err, "Can't read recipient certificate file %s\n", keyfile);
                        ERR_print_errors(bio_err);
                        goto end;
@@ -391,7 +420,15 @@ int MAIN(int argc, char **argv)
                                 "Can't open output file %s\n", outfile);
                        goto end;
                }
-       } else out = BIO_new_fp(stdout, BIO_NOCLOSE);
+       } else {
+               out = BIO_new_fp(stdout, BIO_NOCLOSE);
+#ifdef VMS
+               {
+                   BIO *tmpbio = BIO_new(BIO_f_linebuffer());
+                   out = BIO_push(tmpbio, out);
+               }
+#endif
+       }
 
        if(operation == SMIME_VERIFY) {
                if(!(store = setup_verify(CAfile, CApath))) goto end;
@@ -488,7 +525,7 @@ end:
        PKCS7_free(p7);
        BIO_free(in);
        BIO_free(indata);
-       BIO_free(out);
+       BIO_free_all(out);
        if(passin) OPENSSL_free(passin);
        return (ret);
 }