Loading the config file after processing command line options can
cause problems, e.g. where an engine provides new ciphers/digests
these are not then recoginised on the command line. Move the
default config file loading to before the command line option
processing. Whilst we're doing this we might as well centralise
this instead of doing it individually for each application. Finally
if we do it before the OpenSSL_add_ssl_algorithms() call then
ciphersuites provided by an engine (e.g. GOST) can be available to
the apps.
RT#4085
RT#4086
Reviewed-by: Richard Levitte <levitte@openssl.org>
38 files changed:
argc = opt_num_rest();
argv = opt_rest();
argc = opt_num_rest();
argv = opt_rest();
- if (!app_load_modules(NULL))
- goto end;
-
if (oidfile != NULL) {
in = bio_open_default(oidfile, 'r', FORMAT_TEXT);
if (in == NULL)
if (oidfile != NULL) {
in = bio_open_default(oidfile, 'r', FORMAT_TEXT);
if (in == NULL)
argv = opt_rest();
BIO_printf(bio_err, "Using configuration from %s\n", configfile);
argv = opt_rest();
BIO_printf(bio_err, "Using configuration from %s\n", configfile);
- if ((conf = app_load_config(configfile)) == NULL)
- goto end;
- if (!app_load_modules(conf))
- goto end;
+ /* We already loaded the default config file */
+ if (configfile != default_config_file) {
+ if ((conf = app_load_config(configfile)) == NULL)
+ goto end;
+ if (!app_load_modules(conf))
+ goto end;
+ }
/* Lets get the config section we are using */
if (section == NULL) {
/* Lets get the config section we are using */
if (section == NULL) {
else if (argc != 0)
goto opthelp;
else if (argc != 0)
goto opthelp;
- if (!app_load_modules(NULL))
- goto end;
-
ctx = SSL_CTX_new(meth);
if (ctx == NULL)
goto err;
ctx = SSL_CTX_new(meth);
if (ctx == NULL)
goto err;
- if (!app_load_modules(NULL))
- goto end;
-
if (need_rand) {
app_RAND_load_file(NULL, (inrand != NULL));
if (inrand != NULL)
if (need_rand) {
app_RAND_load_file(NULL, (inrand != NULL));
if (inrand != NULL)
if (!nmflag_set)
nmflag = XN_FLAG_ONELINE;
if (!nmflag_set)
nmflag = XN_FLAG_ONELINE;
- if (!app_load_modules(NULL))
- goto end;
-
x = load_crl(infile, informat);
if (x == NULL)
goto end;
x = load_crl(infile, informat);
if (x == NULL)
goto end;
argc = opt_num_rest();
argv = opt_rest();
argc = opt_num_rest();
argv = opt_rest();
- if (!app_load_modules(NULL))
- goto end;
-
if (!nocrl) {
in = bio_open_default(infile, 'r', informat);
if (in == NULL)
if (!nocrl) {
in = bio_open_default(infile, 'r', informat);
if (in == NULL)
argc = opt_num_rest();
argv = opt_rest();
argc = opt_num_rest();
argv = opt_rest();
- if (!app_load_modules(NULL))
- goto end;
-
if (do_verify && !sigfile) {
BIO_printf(bio_err,
"No signature to verify: use the -signature option\n");
if (do_verify && !sigfile) {
BIO_printf(bio_err,
"No signature to verify: use the -signature option\n");
argc = opt_num_rest();
argv = opt_rest();
argc = opt_num_rest();
argv = opt_rest();
- if (!app_load_modules(NULL))
- goto end;
-
if (argv[0] && (!opt_int(argv[0], &num) || num <= 0))
goto end;
if (argv[0] && (!opt_int(argv[0], &num) || num <= 0))
goto end;
- if (!app_load_modules(NULL))
- goto end;
-
BIO_printf(bio_err, "read DSA key\n");
{
EVP_PKEY *pkey;
BIO_printf(bio_err, "read DSA key\n");
{
EVP_PKEY *pkey;
argc = opt_num_rest();
argv = opt_rest();
argc = opt_num_rest();
argv = opt_rest();
- if (!app_load_modules(NULL))
- goto end;
-
if (argc == 1) {
if (!opt_int(argv[0], &num))
goto end;
if (argc == 1) {
if (!opt_int(argv[0], &num))
goto end;
- if (!app_load_modules(NULL))
- goto end;
-
in = bio_open_default(infile, 'r', informat);
if (in == NULL)
goto end;
in = bio_open_default(infile, 'r', informat);
if (in == NULL)
goto end;
argv = opt_rest();
private = genkey ? 1 : 0;
argv = opt_rest();
private = genkey ? 1 : 0;
- if (!app_load_modules(NULL))
- goto end;
-
in = bio_open_default(infile, 'r', informat);
if (in == NULL)
goto end;
in = bio_open_default(infile, 'r', informat);
if (in == NULL)
goto end;
argc = opt_num_rest();
argv = opt_rest();
argc = opt_num_rest();
argv = opt_rest();
- if (!app_load_modules(NULL))
- goto end;
-
if (cipher && EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER) {
BIO_printf(bio_err, "%s: AEAD ciphers not supported\n", prog);
goto end;
if (cipher && EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER) {
BIO_printf(bio_err, "%s: AEAD ciphers not supported\n", prog);
goto end;
- if (!app_load_modules(NULL))
- goto end;
-
for (i = 0; i < sk_OPENSSL_STRING_num(engines); i++) {
const char *id = sk_OPENSSL_STRING_value(engines, i);
if ((e = ENGINE_by_id(id)) != NULL) {
for (i = 0; i < sk_OPENSSL_STRING_num(engines); i++) {
const char *id = sk_OPENSSL_STRING_value(engines, i);
if ((e = ENGINE_by_id(id)) != NULL) {
- if (!app_load_modules(NULL))
- goto end;
-
in = bio_open_default(dsaparams, 'r', FORMAT_PEM);
if (in == NULL)
goto end2;
in = bio_open_default(dsaparams, 'r', FORMAT_PEM);
if (in == NULL)
goto end2;
- if (!app_load_modules(NULL))
- goto end;
-
out = bio_open_owner(outfile, outformat, private);
if (out == NULL)
goto end;
out = bio_open_owner(outfile, outformat, private);
if (out == NULL)
goto end;
- if (!app_load_modules(NULL))
- goto end;
-
out = bio_open_owner(outfile, FORMAT_PEM, private);
if (out == NULL)
goto end;
out = bio_open_owner(outfile, FORMAT_PEM, private);
if (out == NULL)
goto end;
argc = opt_num_rest();
argv = opt_rest();
argc = opt_num_rest();
argv = opt_rest();
- if (!app_load_modules(NULL))
- goto end;
-
in = bio_open_default(infile, 'r', FORMAT_PEM);
if (in == NULL)
goto end;
in = bio_open_default(infile, 'r', FORMAT_PEM);
if (in == NULL)
goto end;
if (!req && !reqin && !respin && !(port && ridx_filename))
goto opthelp;
if (!req && !reqin && !respin && !(port && ridx_filename))
goto opthelp;
- if (!app_load_modules(NULL))
- goto end;
-
out = bio_open_default(outfile, 'w', FORMAT_TEXT);
if (out == NULL)
goto end;
out = bio_open_default(outfile, 'w', FORMAT_TEXT);
if (out == NULL)
goto end;
BIO *bio_out = NULL;
BIO *bio_err = NULL;
BIO *bio_out = NULL;
BIO *bio_err = NULL;
-static void apps_startup()
+static int apps_startup()
{
#ifdef SIGPIPE
signal(SIGPIPE, SIG_IGN);
{
#ifdef SIGPIPE
signal(SIGPIPE, SIG_IGN);
CRYPTO_malloc_init();
ERR_load_crypto_strings();
ERR_load_SSL_strings();
CRYPTO_malloc_init();
ERR_load_crypto_strings();
ERR_load_SSL_strings();
+
+ if (!app_load_modules(NULL)) {
+ ERR_print_errors(bio_err);
+ BIO_printf(bio_err, "Error loading default configuration\n");
+ return 0;
+ }
+
OpenSSL_add_all_algorithms();
OpenSSL_add_ssl_algorithms();
OPENSSL_load_builtin_modules();
OpenSSL_add_all_algorithms();
OpenSSL_add_ssl_algorithms();
OPENSSL_load_builtin_modules();
#ifndef OPENSSL_NO_ENGINE
ENGINE_load_builtin_engines();
#endif
#ifndef OPENSSL_NO_ENGINE
ENGINE_load_builtin_engines();
#endif
}
static void apps_shutdown()
}
static void apps_shutdown()
+ if (!apps_startup())
+ goto end;
+
prog = prog_init();
pname = opt_progname(argv[0]);
prog = prog_init();
pname = opt_progname(argv[0]);
- if (!app_load_modules(NULL))
- goto end;
-
if (infile && in_stdin) {
BIO_printf(bio_err, "%s: Can't combine -in and -stdin\n", prog);
goto end;
if (infile && in_stdin) {
BIO_printf(bio_err, "%s: Can't combine -in and -stdin\n", prog);
goto end;
- if (!app_load_modules(NULL))
- goto end;
-
if (export_cert || inrand) {
app_RAND_load_file(NULL, (inrand != NULL));
if (inrand != NULL)
if (export_cert || inrand) {
app_RAND_load_file(NULL, (inrand != NULL));
if (inrand != NULL)
argc = opt_num_rest();
argv = opt_rest();
argc = opt_num_rest();
argv = opt_rest();
- if (!app_load_modules(NULL))
- goto end;
-
in = bio_open_default(infile, 'r', informat);
if (in == NULL)
goto end;
in = bio_open_default(infile, 'r', informat);
if (in == NULL)
goto end;
- if (!app_load_modules(NULL))
- goto end;
-
if ((pbe_nid == -1) && !cipher)
pbe_nid = NID_pbeWithMD5AndDES_CBC;
if ((pbe_nid == -1) && !cipher)
pbe_nid = NID_pbeWithMD5AndDES_CBC;
- if (!app_load_modules(NULL))
- goto end;
-
out = bio_open_owner(outfile, outformat, private);
if (out == NULL)
goto end;
out = bio_open_owner(outfile, outformat, private);
if (out == NULL)
goto end;
argc = opt_num_rest();
argv = opt_rest();
argc = opt_num_rest();
argv = opt_rest();
- if (!app_load_modules(NULL))
- goto end;
-
in = bio_open_default(infile, 'r', FORMAT_PEM);
if (in == NULL)
goto end;
in = bio_open_default(infile, 'r', FORMAT_PEM);
if (in == NULL)
goto end;
if (ctx == NULL)
goto opthelp;
if (ctx == NULL)
goto opthelp;
- if (!app_load_modules(NULL))
- goto end;
-
if (sigfile && (pkey_op != EVP_PKEY_OP_VERIFY)) {
BIO_printf(bio_err,
"%s: Signature file specified for non verify\n", prog);
if (sigfile && (pkey_op != EVP_PKEY_OP_VERIFY)) {
BIO_printf(bio_err,
"%s: Signature file specified for non verify\n", prog);
argc = opt_num_rest();
argv = opt_rest();
argc = opt_num_rest();
argv = opt_rest();
- if (!app_load_modules(NULL))
- goto end;
-
if (argc == 0 && !generate) {
BIO_printf(bio_err, "%s: No prime specified\n", prog);
goto end;
if (argc == 0 && !generate) {
BIO_printf(bio_err, "%s: No prime specified\n", prog);
goto end;
if (sscanf(argv[0], "%d", &num) != 1 || num < 0)
goto opthelp;
if (sscanf(argv[0], "%d", &num) != 1 || num < 0)
goto opthelp;
- if (!app_load_modules(NULL))
- goto end;
-
app_RAND_load_file(NULL, (inrand != NULL));
if (inrand != NULL)
BIO_printf(bio_err, "%ld semi-random bytes loaded\n",
app_RAND_load_file(NULL, (inrand != NULL));
if (inrand != NULL)
BIO_printf(bio_err, "%ld semi-random bytes loaded\n",
BIO_printf(bio_err, "Error getting passwords\n");
goto end;
}
BIO_printf(bio_err, "Error getting passwords\n");
goto end;
}
-
- if (!app_load_modules(NULL))
- goto end;
-
if (check && pubin) {
BIO_printf(bio_err, "Only private keys can be checked\n");
goto end;
if (check && pubin) {
BIO_printf(bio_err, "Only private keys can be checked\n");
goto end;
- if (!app_load_modules(NULL))
- goto end;
-
/* FIXME: seed PRNG only if needed */
app_RAND_load_file(NULL, 0);
/* FIXME: seed PRNG only if needed */
app_RAND_load_file(NULL, 0);
argc = opt_num_rest();
argv = opt_rest();
argc = opt_num_rest();
argv = opt_rest();
- if (!app_load_modules(NULL))
- goto end;
-
if (proxystr) {
if (connectstr == NULL) {
BIO_printf(bio_err, "%s: -proxy requires use of -connect\n", prog);
if (proxystr) {
if (connectstr == NULL) {
BIO_printf(bio_err, "%s: -proxy requires use of -connect\n", prog);
- if (!app_load_modules(NULL))
- goto end;
-
if (s_key_file == NULL)
s_key_file = s_cert_file;
if (s_key_file == NULL)
s_key_file = s_cert_file;
- if (!app_load_modules(NULL))
- goto end;
-
if (need_rand) {
app_RAND_load_file(NULL, (inrand != NULL));
if (inrand != NULL)
if (need_rand) {
app_RAND_load_file(NULL, (inrand != NULL));
if (inrand != NULL)
argc = opt_num_rest();
argv = opt_rest();
argc = opt_num_rest();
argv = opt_rest();
- if (!app_load_modules(NULL))
- goto end;
-
/* Remaining arguments are algorithms. */
for ( ; *argv; argv++) {
if (found(*argv, doit_choices, &i)) {
/* Remaining arguments are algorithms. */
for ( ; *argv; argv++) {
if (found(*argv, doit_choices, &i)) {
if ((conf = app_load_config(infile)) == NULL)
goto end;
if ((conf = app_load_config(infile)) == NULL)
goto end;
- if (!app_load_modules(conf))
- goto end;
spkstr = NCONF_get_string(conf, spksect, spkac);
spkstr = NCONF_get_string(conf, spksect, spkac);
- if (!app_load_modules(NULL))
- goto end;
-
if ((store = setup_verify(CAfile, CApath, noCAfile, noCApath)) == NULL)
goto end;
X509_STORE_set_verify_cb(store, cb);
if ((store = setup_verify(CAfile, CApath, noCAfile, noCApath)) == NULL)
goto end;
X509_STORE_set_verify_cb(store, cb);
if (!nmflag_set)
nmflag = XN_FLAG_ONELINE;
if (!nmflag_set)
nmflag = XN_FLAG_ONELINE;
- if (!app_load_modules(NULL))
- goto end;
-
out = bio_open_default(outfile, 'w', outformat);
if (out == NULL)
goto end;
out = bio_open_default(outfile, 'w', outformat);
if (out == NULL)
goto end;