Provide an application-common setup function for engines and use it

everywhere.
This commit is contained in:
Richard Levitte 2001-06-18 06:22:33 +00:00
parent 853b1eb424
commit 531d630b5c
26 changed files with 55 additions and 412 deletions

View File

@ -1037,3 +1037,32 @@ X509_STORE *setup_verify(BIO *bp, char *CAfile, char *CApath)
X509_STORE_free(store);
return NULL;
}
ENGINE *setup_engine(BIO *err, const char *engine, int debug)
{
ENGINE *e = NULL;
if (engine)
{
if((e = ENGINE_by_id(engine)) == NULL)
{
BIO_printf(err,"invalid engine \"%s\"\n", engine);
return NULL;
}
if (debug)
{
ENGINE_ctrl(e, ENGINE_CTRL_SET_LOGSTREAM,
0, err, 0);
}
ENGINE_ctrl_cmd(e, "SET_USER_INTERFACE", 0, UI_OpenSSL(), 0, 1);
if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
{
BIO_printf(err,"can't use that engine\n");
return NULL;
}
BIO_printf(err,"engine \"%s\" set.\n", engine);
/* Free our "structural" reference. */
ENGINE_free(e);
}
return e;
}

View File

@ -176,6 +176,7 @@ EVP_PKEY *load_pubkey(BIO *err, const char *file, int format,
STACK_OF(X509) *load_certs(BIO *err, const char *file, int format,
const char *pass, ENGINE *e, const char *cert_descrip);
X509_STORE *setup_verify(BIO *bp, char *CAfile, char *CApath);
ENGINE *setup_engine(BIO *err, const char *engine, int debug);
#define FORMAT_UNDEF 0
#define FORMAT_ASN1 1

View File

@ -549,23 +549,7 @@ bad:
ERR_load_crypto_strings();
if (engine != NULL)
{
if ((e = ENGINE_by_id(engine)) == NULL)
{
BIO_printf(bio_err,"invalid engine \"%s\"\n",
engine);
goto err;
}
if (!ENGINE_set_default(e, ENGINE_METHOD_ALL))
{
BIO_printf(bio_err,"can't use that engine\n");
goto err;
}
BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
/* Free our "structural" reference. */
ENGINE_free(e);
}
e = setup_engine(bio_err, engine, 0);
/*****************************************************************/
if (configfile == NULL) configfile = getenv("OPENSSL_CONF");

View File

@ -225,23 +225,7 @@ 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);
}
e = setup_engine(bio_err, engine, 0);
in=BIO_new(BIO_s_file());
bmd=BIO_new(BIO_f_md());

View File

@ -174,23 +174,7 @@ bad:
ERR_load_crypto_strings();
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);
}
e = setup_engine(bio_err, engine, 0);
in=BIO_new(BIO_s_file());
out=BIO_new(BIO_s_file());

View File

@ -257,23 +257,7 @@ bad:
ERR_load_crypto_strings();
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);
}
e = setup_engine(bio_err, engine, 0);
if (g && !num)
num = DEFBITS;

View File

@ -198,23 +198,7 @@ bad:
ERR_load_crypto_strings();
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);
}
e = ENGINE_setup(engine, bio_err);
if(!app_passwd(bio_err, passargin, passargout, &passin, &passout)) {
BIO_printf(bio_err, "Error getting passwords\n");

View File

@ -232,23 +232,7 @@ bad:
}
}
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);
}
e = ENGINE_setup(engine, bio_err);
if (need_rand)
{

View File

@ -285,23 +285,7 @@ bad:
argv++;
}
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);
}
e = setup_engine(bio_err, engine, 0);
if (bufsize != NULL)
{

View File

@ -143,23 +143,7 @@ bad:
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);
}
e = setup_engine(bio_err, engine, 0);
out=BIO_new(BIO_s_file());
if (out == NULL)

View File

@ -162,23 +162,7 @@ bad:
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);
}
e = ENGINE_setup(engine, bio_err);
if(!app_passwd(bio_err, NULL, passargout, NULL, &passout)) {
BIO_printf(bio_err, "Error getting password\n");

View File

@ -176,23 +176,7 @@ bad:
goto err;
}
if (engine != NULL)
{
if((e = ENGINE_by_id(engine)) == NULL)
{
BIO_printf(bio_err,"invalid engine \"%s\"\n",
engine);
goto err;
}
if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
{
BIO_printf(bio_err,"can't use that engine\n");
goto err;
}
BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
/* Free our "structural" reference. */
ENGINE_free(e);
}
e = setup_engine(bio_err, engine, 0);
if (outfile == NULL)
{

View File

@ -300,19 +300,7 @@ 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);
}
e = setup_engine(bio_err, engine, 0);
if(passarg) {
if(export_cert) passargout = passarg;

View File

@ -168,23 +168,7 @@ bad:
ERR_load_crypto_strings();
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);
}
e = setup_engine(bio_err, engine, 0);
in=BIO_new(BIO_s_file());
out=BIO_new(BIO_s_file());

View File

@ -185,23 +185,7 @@ int MAIN(int argc, char **argv)
return (1);
}
if (engine != NULL)
{
if((e = ENGINE_by_id(engine)) == NULL)
{
BIO_printf(bio_err,"invalid engine \"%s\"\n",
engine);
return (1);
}
if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
{
BIO_printf(bio_err,"can't use that engine\n");
return (1);
}
BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
/* Free our "structural" reference. */
ENGINE_free(e);
}
e = setup_engine(bio_err, engine, 0);
if(!app_passwd(bio_err, passargin, passargout, &passin, &passout)) {
BIO_printf(bio_err, "Error getting passwords\n");

View File

@ -101,23 +101,7 @@ int MAIN(int argc, char **argv)
goto err;
}
if (engine != NULL)
{
if((e = ENGINE_by_id(engine)) == NULL)
{
BIO_printf(bio_err,"invalid engine \"%s\"\n",
engine);
goto err;
}
if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
{
BIO_printf(bio_err,"can't use that engine\n");
goto err;
}
BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
/* Free our "structural" reference. */
ENGINE_free(e);
}
e = setup_engine(bio_err, engine, 0);
app_RAND_load_file(NULL, bio_err, (inrand != NULL));
if (inrand != NULL)

View File

@ -586,23 +586,7 @@ bad:
if ((in == NULL) || (out == NULL))
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);
}
e = setup_engine(bio_err, engine, 0);
if (keyfile != NULL)
{

View File

@ -209,23 +209,7 @@ bad:
ERR_load_crypto_strings();
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);
}
e = setup_engine(bio_err, engine, 0);
if(!app_passwd(bio_err, passargin, passargout, &passin, &passout)) {
BIO_printf(bio_err, "Error getting passwords\n");

View File

@ -157,23 +157,7 @@ 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);
}
e = setup_engine(bio_err, engine, 0);
/* FIXME: seed PRNG only if needed */
app_RAND_load_file(NULL, bio_err, 0);

View File

@ -382,28 +382,7 @@ bad:
OpenSSL_add_ssl_algorithms();
SSL_load_error_strings();
if (engine_id != NULL)
{
if((e = ENGINE_by_id(engine_id)) == NULL)
{
BIO_printf(bio_err,"invalid engine\n");
ERR_print_errors(bio_err);
goto end;
}
if (c_debug)
{
ENGINE_ctrl(e, ENGINE_CTRL_SET_LOGSTREAM,
0, bio_err, 0);
}
if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
{
BIO_printf(bio_err,"can't use that engine\n");
ERR_print_errors(bio_err);
goto end;
}
BIO_printf(bio_err,"engine \"%s\" set.\n", engine_id);
ENGINE_free(e);
}
e = setup_engine(bio_err, engine_id, 1);
ctx=SSL_CTX_new(meth);
if (ctx == NULL)

View File

@ -657,28 +657,7 @@ bad:
SSL_load_error_strings();
OpenSSL_add_ssl_algorithms();
if (engine_id != NULL)
{
if((e = ENGINE_by_id(engine_id)) == NULL)
{
BIO_printf(bio_err,"invalid engine\n");
ERR_print_errors(bio_err);
goto end;
}
if (s_debug)
{
ENGINE_ctrl(e, ENGINE_CTRL_SET_LOGSTREAM,
0, bio_err, 0);
}
if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
{
BIO_printf(bio_err,"can't use that engine\n");
ERR_print_errors(bio_err);
goto end;
}
BIO_printf(bio_err,"engine \"%s\" set.\n", engine_id);
ENGINE_free(e);
}
e = setup_engine(bio_err, engine_id, 1);
ctx=SSL_CTX_new(meth);
if (ctx == NULL)

View File

@ -319,23 +319,7 @@ 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);
}
e = setup_engine(bio_err, engine, 0);
if(!app_passwd(bio_err, passargin, NULL, &passin, NULL)) {
BIO_printf(bio_err, "Error getting password\n");

View File

@ -505,21 +505,8 @@ int MAIN(int argc, char **argv)
BIO_printf(bio_err,"no engine given\n");
goto end;
}
if((e = ENGINE_by_id(*argv)) == NULL)
{
BIO_printf(bio_err,"invalid engine \"%s\"\n",
*argv);
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", *argv);
/* Free our "structural" reference. */
ENGINE_free(e);
/* It will be increased again further down. We just
e = setup_engine(bio_err, *argv, 0);
/* j will be increased again further down. We just
don't want speed to confuse an engine with an
algorithm, especially when none is given (which
means all of them should be run) */

View File

@ -179,23 +179,7 @@ bad:
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);
}
e = setup_engine(bio_err, engine, 0);
if(keyfile) {
if(strcmp(keyfile, "-")) key = BIO_new_file(keyfile, "r");

View File

@ -166,23 +166,7 @@ int MAIN(int argc, char **argv)
break;
}
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);
}
e = setup_engine(bio_err, engine, 0);
lookup=X509_STORE_add_lookup(cert_ctx,X509_LOOKUP_file());
if (lookup == NULL) abort();

View File

@ -448,23 +448,7 @@ bad:
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);
}
e = setup_engine(bio_err, engine, 0);
if (need_rand)
app_RAND_load_file(NULL, bio_err, 0);