CONF_MODULES_LOAD_FILE(3ossl)
π CONF_MODULES_LOAD_FILE π
okay bestie, welcome to the OpenSSL configuration corner of the group chat π this is the 3ossl manual page for the functions that make OpenSSL read its lil config file and load up its modules. it's giving "settings app but make it cryptography" β¨
β¨ NAME β¨
CONF_get1_default_config_file, CONF_modules_load_file_ex, CONF_modules_load_file, CONF_modules_load β OpenSSL configuration functions πΈ
fr fr, that's the whole squad.
π¦ 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);
look at them, so iconic, so consistent π
πΈ DESCRIPTION πΈ
so CONF_get1_default_config_file() is the one that figures out where your default config file even lives. here's the vibe check, in order:
- if the
OPENSSL_CONFenvironment variable is set, its value is returned π - otherwise it returns the path you get from
X509_get_default_cert_area(3)with the filename"openssl.cnf"appended to it
heads up bestie β the caller is responsible for freeing any string returned. that memory is yours now, no take-backs π
CONF_modules_load_file_ex() is the main character here. it configures OpenSSL using:
- library context
libctx - file
filename - application name
appname
if filename is NULL, the standard OpenSSL configuration file gets used, as determined by calling CONF_get1_default_config_file(). if appname is NULL, the standard OpenSSL application name openssl_conf is used. and you can customize the whole behaviour using flags π
ngl, the error suppressing can be overridden byconfig_diagnosticsas described inconfig(5). iykyk.
CONF_modules_load_file() is literally the same as CONF_modules_load_file_ex() except it has a NULL library context. same energy, just less to pass β¨
CONF_modules_load() is identical to CONF_modules_load_file() except it reads configuration information from cnf. that's the whole difference, no cap π«Ά
π NOTES π
these are the flags currently recognized, bestie. memorize them, they're the whole tea:
CONF_MFLAGS_IGNORE_ERRORSβ if set, errors returned by individual configuration modules are ignored. if 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 flag is set, no error information is added π€«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 just too risky π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 returns an error πCONF_MFLAGS_DEFAULT_SECTIONβ if set andappnameis notNULL, it will use the default section pointed to byopenssl_confifappnamedoes not exist π
ok important vibe check: applications callingCONF_modules_load_file_exexplicitly should not generally setCONF_MFLAGS_IGNORE_RETURN_CODES. that one is for the system-wide default file situation, not for you personally setting it and then acting shocked when nothing errors π₯
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 that case, CONF_MFLAGS_IGNORE_MISSING_FILE would be set. lowkey elegant π
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 continues. in other cases, an application might consider a configuration file error as fatal and exit immediately. choose 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. that's for the control freaks (affectionate) π
β 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 β and that will always be zero or negative. so like, don't go expecting a positive number, bestie π«Ά
π₯ EXAMPLES π₯
load a config file, print any errors, and exit (missing file is 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 the 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 a 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 a 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_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);
}
π SEE ALSO π
go read those too, bestie, they're all connected π¦
π 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>.
ok that's the whole page, and if you made it to the end you're literally a scholar ππ this was OpenSSL 3.5.9, dated 2026-09-29, and it's the CONF_MODULES_LOAD_FILE(3ossl) manual page signing off. go forth and load your configs responsibly, bestie β mwah π
β¨
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms