#include <openssl/crypto.h>
#include <openssl/pem.h>
#include <openssl/err.h>
+#include <openssl/engine.h>
#undef PROG
#define PROG smime_main
int MAIN(int argc, char **argv)
{
+ ENGINE *e = NULL;
int operation = 0;
int ret = 0;
char **args;
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] == '-') {
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++;
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");
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;
} 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;
"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;
PKCS7_free(p7);
BIO_free(in);
BIO_free(indata);
- BIO_free(out);
+ BIO_free_all(out);
if(passin) OPENSSL_free(passin);
return (ret);
}