CONF_MODULES_LOAD_FILE(3SSL)
π CONF_MODULES_LOAD_FILE(3SSL) β OpenSSL edition π
okay bestie, gather round, because this is the CONF_MODULES_LOAD_FILE(3SSL) page from the OpenSSL manuals and it's literally all about how OpenSSL finds, loads and vibes with its config files. no cap, this one's important if you've ever wondered why your app is reading some random openssl.cnf you didn't even know existed. let's get into it π«Ά
β¨ NAME β¨
CONF_get1_default_config_file, CONF_modules_load_file_ex, CONF_modules_load_file, CONF_modules_load β OpenSSL configuration functions
πΈ SYNOPSIS πΈ
#include <openssl/conf.h>
char *CONF_get1_default_config_file(void);
int CONF_modules_load_file_ex(OSSL_LIB_CTX *libctx, const char *filename,
const char *appname, unsigned long flags);
int CONF_modules_load_file(const char *filename, const char *appname,
unsigned long flags);
int CONF_modules_load(const CONF *cnf, const char *appname,
unsigned long flags);
π¦ DESCRIPTION π¦
so CONF_get1_default_config_file() figures out where your default config file lives, and the way it does that is:
- if the
OPENSSL_CONFenvironment variable is set, its value gets returned, periodt. - otherwise it returns the path you get from
X509_get_default_cert_area(3)with the filename"openssl.cnf"tacked onto the end.
π bestie heads up: the caller is responsible for freeing any string returned. don't just leave it floating there, that's not the vibe.
CONF_modules_load_file_ex() sets up OpenSSL using the library context libctx, the file filename, and the application name appname. the deets:
- if filename is
NULL, the standard OpenSSL configuration file gets used, as determined by callingCONF_get1_default_config_file(). - if appname is
NULL, the standard OpenSSL application nameopenssl_confis used. - the behaviour can be customised with flags.
and lowkey important: error handling can be customised via the configuration file's default section config_diagnostics parameter, as described in config(5).
CONF_modules_load_file() is the same as CONF_modules_load_file_ex() except it rocks a NULL library context. the global (NULL) library context is typically initialised just once at application startup. library initialisation is usually implicit, but explicit initialisation is also supported by calling OPENSSL_init_crypto(3) or OPENSSL_init_ssl(3) β and you gotta do it sufficiently early in the main program, before implicit OpenSSL library initialisation has taken place as a side-effect of other OpenSSL function calls. iykyk π
CONF_modules_load() is identical to CONF_modules_load_file() except it reads configuration information from cnf.
π₯ NOTES π₯
these are the flags currently recognized, bestie, write them down π
CONF_MFLAGS_IGNORE_ERRORSβ if set, errors returned by individual configuration modules are ignored. if it's not set, the first module error is considered fatal and no further modules are loaded. πCONF_MFLAGS_SILENTβ normally any module errors will add error information to the error queue. if this is set, no error information is added. quiet luxury β¨CONF_MFLAGS_IGNORE_RETURN_CODESβ if set, the function unconditionally returns success. this is used by default inOPENSSL_init_crypto(3)to ignore any errors in the default system-wide configuration file, because having all OpenSSL applications fail to start when there are potentially minor issues in the file is too risky. applications callingCONF_modules_load_file_exexplicitly should not generally set this flag. πCONF_MFLAGS_NO_DSOβ if set, configuration module loading from DSOs is disabled.CONF_MFLAGS_IGNORE_MISSING_FILEβ if set, will makeCONF_load_modules_file()ignore missing configuration files. normally a missing configuration file return an error.CONF_MFLAGS_DEFAULT_SECTIONβ if set and appname is notNULL, will use the default section pointed to byopenssl_confif appname does not exist.
by using CONF_modules_load_file_ex() with appropriate flags, an application can customise application configuration to best suit its needs. in some cases the use of a configuration file is optional and its absence is not an error β in this case CONF_MFLAGS_IGNORE_MISSING_FILE would be set. cute, flexible, we love that π
errors during configuration may also be handled differently by different applications. for example, in some cases an error may simply print out a warning message and the application continue. in other cases, an application might consider a configuration file error as fatal and exit immediately. main character energy vs. chill vibes, pick your fighter.
applications can use the CONF_modules_load() function if they wish to load a configuration file themselves and have finer control over how errors are treated.
β RETURN VALUES β
these functions return 1 for success and a zero or negative value for failure. if module errors are not ignored, the return code will reflect the return value of the failing module (this will always be zero or negative). ngl, zero or negative is never the vibe. π
π EXAMPLES π
load a configuration file and print out any errors and exit (missing file considered fatal):
if (CONF_modules_load_file_ex(libctx, NULL, NULL, 0) <= 0) {
fprintf(stderr, "FATAL: error loading configuration file\n");
ERR_print_errors_fp(stderr);
exit(1);
}
load default configuration file using the section indicated by "myapp", tolerate missing files, but exit on other errors:
if (CONF_modules_load_file_ex(NULL, NULL, "myapp",
CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
fprintf(stderr, "FATAL: error loading configuration file\n");
ERR_print_errors_fp(stderr);
exit(1);
}
load custom configuration file and section, only print warnings on error, missing configuration file ignored:
if (CONF_modules_load_file_ex(NULL, "/something/app.cnf", "myapp",
CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
fprintf(stderr, "WARNING: error loading configuration file\n");
ERR_print_errors_fp(stderr);
}
load and parse configuration file manually, custom error handling:
FILE *fp;
CONF *cnf = NULL;
long eline;
fp = fopen("/somepath/app.cnf", "r");
if (fp == NULL) {
fprintf(stderr, "Error opening configuration file\n");
/* Other missing configuration file behaviour */
} else {
cnf = NCONF_new_ex(libctx, NULL);
if (NCONF_load_fp(cnf, fp, &eline) == 0) {
fprintf(stderr, "Error on line %ld of configuration file\n", eline);
ERR_print_errors_fp(stderr);
/* Other malformed configuration file behaviour */
} else if (CONF_modules_load(cnf, "appname", 0) <= 0) {
fprintf(stderr, "Error configuring application\n");
ERR_print_errors_fp(stderr);
/* Other configuration error behaviour */
}
fclose(fp);
NCONF_free(cnf);
}
π BUGS π
okay this part is giving red flags, pay attention:
in OpenSSL 3.x the CONF_modules_load_file_ex() and CONF_modules_load_file() functions affect some shared global state other than the specified library context. therefore, even if used with a freshly created library context, the function is not thread safe, and should not be used except as part of early application initialisation. no cap, do not come for me when it breaks, i warned you. π
the SSL_CTX_config(3) and SSL_config(3) functions can be used to perform late customisation of SSL contexts and connection handles. here late means that the chosen section's settings are applied in addition to any initial settings from the ssl module's system_default section that are used during initial construction of the SSL context. this sort of fine-tuning does not involve a separate configuration file or library context. chef's kiss, actually. π
π«Ά SEE ALSO π«Ά
config(5), OPENSSL_config(3), NCONF_new_ex(3)
π COPYRIGHT π
Copyright 2004-2022 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
and that's the whole page bestie, you ate that π
this was OpenSSL 4.0.3, dated 2026-09-29, and it's the CONF_MODULES_LOAD_FILE(3SSL) manual β go forth and configure responsibly, mwah πβ¨
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms