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_CONF environment 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 by config_diagnostics as described in config(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 in OPENSSL_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 make CONF_load_modules_file() ignore missing configuration files. normally a missing configuration file returns an error πŸ™ˆ
  • CONF_MFLAGS_DEFAULT_SECTION β€” if set and appname is not NULL, it will use the default section pointed to by openssl_conf if appname does not exist πŸ‘‘
ok important vibe check: applications calling CONF_modules_load_file_ex explicitly should not generally set CONF_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 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