CONF_MODULES_LOAD_FILE(3)
π CONF_MODULES_LOAD_FILE(3) β the OpenSSL config glow-up page π
okay so bestie, this is page CONF_MODULES_LOAD_FILE(3) from the Library Functions Manual, and it's literally all about the OpenSSL configuration functions: CONF_modules_load_file, CONF_modules_load, and X509_get_default_cert_area. sit down, hydrate, and let's get into it β¨
πΈ NAME πΈ
CONF_modules_load_file, CONF_modules_load, X509_get_default_cert_area β the OpenSSL configuration functions, aka the girlies that actually read your config π«Ά
β¨ SYNOPSIS β¨
#include <openssl/conf.h>
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);
#include <openssl/x509.h>
const char *
X509_get_default_cert_area(void);
π DESCRIPTION π
CONF_modules_load_file() sets up OpenSSL for you using the file filename β which has to be in openssl.cnf(5) format β plus the application name appname. π
So here's the tea on defaults, iykyk:
- if filename is
NULL, it uses the standard OpenSSL config file/etc/ssl/openssl.cnf - if appname is
NULL, it uses the standard OpenSSL application name"openssl_conf" - and you can customize the behaviour with flags, obviously π
fr fr, check the βEXAMPLESβ section (down below, bestie, keep scrolling) for the extra functions you might need to call. calling config functions in the right order to get what you actually want is lowkey tricky, because so many config functions internally call each other β it's giving tangled earphones π
CONF_modules_load() is literally identical to CONF_modules_load_file() except it reads the config info from cnf instead. same energy, different source π
these are the flags that are currently recognized:
CONF_MFLAGS_IGNORE_ERRORSβ ignore the errors that individual configuration modules return. by default, the first module error is considered fatal and no further modules get loaded. πCONF_MFLAGS_SILENTβ don't add any error information. by default, all module errors add error information to the error queue.CONF_MFLAGS_NO_DSOβ disables loading of configuration modules from DSOs. this flag only exists for compatibility and has no effect, so it's giving decorative πCONF_MFLAGS_IGNORE_MISSING_FILEβ letsCONF_modules_load_file()ignore missing configuration files. by default, a missing config file returns an error. πCONF_MFLAGS_DEFAULT_SECTIONβ if appname is notNULLbut doesn't exist, it falls back to the default section"openssl_conf". slay, backup plan β¨
by using CONF_modules_load_file() with the right flags, an app can customize its application configuration to best suit its needs. in some cases the config file is optional and its absence isn't an error at all β in that case you'd set CONF_MFLAGS_IGNORE_MISSING_FILE. easy π
errors during configuration can also be handled differently by different applications. for example, in some cases an error may simply print out a warning message and the app just continues. in other cases an app might treat a config file error as fatal and exit immediately. both are valid, no judgement π«Ά
applications can use CONF_modules_load() if they want to load a config file themselves and have finer control over how errors are treated. main character energy: doing it yourself π
π₯ RETURN VALUES π₯
CONF_modules_load_file() and CONF_modules_load() return 1 for success, and zero or a negative value for failure. π
if module errors are not ignored, the return code will reflect the return value of the failing module (and that will always be zero or negative, no cap).
X509_get_default_cert_area() returns a pointer to the constant string "/etc/ssl". that's it, that's the whole function π
π¦ FILES π¦
/etc/sslβ standard configuration directory/etc/ssl/openssl.cnfβ standard configuration file
π EXAMPLES π
Load a configuration file and print out any errors and exit (missing file is considered fatal):
if (CONF_modules_load_file(NULL, NULL, 0) <= 0) {
fprintf(stderr, "FATAL: error loading configuration file\n");
ERR_print_errors_fp(stderr);
exit(1);
}
Load the default configuration file using the section indicated by "myapp", tolerate missing files, but exit on other errors:
if (CONF_modules_load_file(NULL, "myapp",
CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
fprintf(stderr, "FATAL: error loading configuration file\n");
ERR_print_errors_fp(stderr);
exit(1);
}
Load a custom configuration file and section instead of the standard one, only print warnings on error, missing configuration file ignored:
OPENSSL_no_config();
OPENSSL_load_builtin_modules();
if (CONF_modules_load_file("/something/app.cnf", "myapp",
CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
fprintf(stderr, "WARNING: error loading configuration file\n");
ERR_print_errors_fp(stderr);
}
okay so about that last example π the call to OPENSSL_no_config(3) is required first to suppress automatic loading of the standard configuration file, and the call to OPENSSL_load_builtin_modules(3) is needed so the configuration of builtin modules gets loaded in addition to the configuration of "myapp". don't skip these, bestie, they're the whole vibe check β
Load and parse the configuration file manually, with 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(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);
}
π SEE ALSO π
CONF_modules_free(3), ERR(3), OPENSSL_config(3), OPENSSL_load_builtin_modules(3) β go read those too, bestie, they're all connected π§
π HISTORY π
X509_get_default_cert_area() first appeared in SSLeay 0.4.1 and has been available since OpenBSD 2.4. vintage π
CONF_modules_load_file() and CONF_modules_load() first appeared in OpenSSL 0.9.7 and have been available since OpenBSD 3.2. icons only β¨
and that's the page, bestie!! π this cutie came from Debian, dated November 19, 2023, and the source/version line was CONF_MODULES_LOAD_FILE(3) β now go configure something iconic πππ¦
π¦ where this page comes from
- opensuse-leap 16.0: libressl-devel-doc 4.1.0-bp160.1.1 Β· OpenSSL
- Copyright (c) 2021 Ingo Schwarze <schwarze@openbsd.org>
- Copyright (c) 2000, 2015 The OpenSSL Project. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms