1.\" $OpenBSD: CONF_modules_load_file.3,v 1.14 2023/11/19 20:58:07 tb Exp $ 2.\" full merge up to: e9b77246 Jan 20 19:58:49 2017 +0100 3.\" selective merge up to: d090fc00 Feb 26 13:11:10 2019 +0800 4.\" 5.\" This file is a derived work. 6.\" The changes are covered by the following Copyright and license: 7.\" 8.\" Copyright (c) 2021 Ingo Schwarze <schwarze@openbsd.org> 9.\" 10.\" Permission to use, copy, modify, and distribute this software for any 11.\" purpose with or without fee is hereby granted, provided that the above 12.\" copyright notice and this permission notice appear in all copies. 13.\" 14.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 15.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 16.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 17.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 18.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 19.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 20.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 21.\" 22.\" The original file was written by Dr. Stephen Henson <steve@openssl.org>. 23.\" Copyright (c) 2000, 2015 The OpenSSL Project. All rights reserved. 24.\" 25.\" Redistribution and use in source and binary forms, with or without 26.\" modification, are permitted provided that the following conditions 27.\" are met: 28.\" 29.\" 1. Redistributions of source code must retain the above copyright 30.\" notice, this list of conditions and the following disclaimer. 31.\" 32.\" 2. Redistributions in binary form must reproduce the above copyright 33.\" notice, this list of conditions and the following disclaimer in 34.\" the documentation and/or other materials provided with the 35.\" distribution. 36.\" 37.\" 3. All advertising materials mentioning features or use of this 38.\" software must display the following acknowledgment: 39.\" "This product includes software developed by the OpenSSL Project 40.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 41.\" 42.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 43.\" endorse or promote products derived from this software without 44.\" prior written permission. For written permission, please contact 45.\" openssl-core@openssl.org. 46.\" 47.\" 5. Products derived from this software may not be called "OpenSSL" 48.\" nor may "OpenSSL" appear in their names without prior written 49.\" permission of the OpenSSL Project. 50.\" 51.\" 6. Redistributions of any form whatsoever must retain the following 52.\" acknowledgment: 53.\" "This product includes software developed by the OpenSSL Project 54.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" 55.\" 56.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 57.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 58.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 59.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 60.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 61.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 62.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 63.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 65.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 66.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 67.\" OF THE POSSIBILITY OF SUCH DAMAGE. 68.\" 69.Dd $Mdocdate: November 19 2023 $ 70.Dt CONF_MODULES_LOAD_FILE 3 71.Os 72.Sh NAME 73.Nm CONF_modules_load_file , 74.Nm CONF_modules_load , 75.Nm X509_get_default_cert_area 76.Nd OpenSSL configuration functions 77.Sh SYNOPSIS 78.In openssl/conf.h 79.Ft int 80.Fo CONF_modules_load_file 81.Fa "const char *filename" 82.Fa "const char *appname" 83.Fa "unsigned long flags" 84.Fc 85.Ft int 86.Fo CONF_modules_load 87.Fa "const CONF *cnf" 88.Fa "const char *appname" 89.Fa "unsigned long flags" 90.Fc 91.In openssl/x509.h 92.Ft const char * 93.Fn X509_get_default_cert_area void 94.Sh DESCRIPTION 95The function 96.Fn CONF_modules_load_file 97configures OpenSSL using the file 98.Fa filename 99in 100.Xr openssl.cnf 5 101format and the application name 102.Fa appname . 103If 104.Fa filename 105is 106.Dv NULL , 107the standard OpenSSL configuration file 108.Pa /etc/ssl/openssl.cnf 109is used. 110If 111.Fa appname 112is 113.Dv NULL , 114the standard OpenSSL application name 115.Qq openssl_conf 116is used. 117The behaviour can be customized using 118.Fa flags . 119.Pp 120See the 121.Sx EXAMPLES 122section for additional functions that may need to be called. 123Calling configuration functions in the right order for the intended 124effect can be tricky because many configuration functions internally 125call each other. 126.Pp 127.Fn CONF_modules_load 128is identical to 129.Fn CONF_modules_load_file 130except it reads configuration information from 131.Fa cnf . 132.Pp 133The following 134.Fa flags 135are currently recognized: 136.Bl -tag -width Ds 137.It Dv CONF_MFLAGS_IGNORE_ERRORS 138Ignore errors returned by individual configuration modules. 139By default, the first module error is considered fatal and no further 140modules are loaded. 141.It Dv CONF_MFLAGS_SILENT 142Do not add any error information. 143By default, all module errors add error information to the error queue. 144.It Dv CONF_MFLAGS_NO_DSO 145Disable loading of configuration modules from DSOs. 146This flag is provided for compatibility and has no effect. 147.It Dv CONF_MFLAGS_IGNORE_MISSING_FILE 148Let 149.Fn CONF_modules_load_file 150ignore missing configuration files. 151By default, a missing configuration file returns an error. 152.It CONF_MFLAGS_DEFAULT_SECTION 153If 154.Fa appname 155is not 156.Dv NULL 157but does not exist, fall back to the default section 158.Qq openssl_conf . 159.El 160.Pp 161By using 162.Fn CONF_modules_load_file 163with appropriate flags, an application can customise application 164configuration to best suit its needs. 165In some cases the use of a configuration file is optional and its 166absence is not an error: in this case 167.Dv CONF_MFLAGS_IGNORE_MISSING_FILE 168would be set. 169.Pp 170Errors during configuration may also be handled differently by 171different applications. 172For example in some cases an error may simply print out a warning 173message and the application may continue. 174In other cases an application might consider a configuration file 175error fatal and exit immediately. 176.Pp 177Applications can use the 178.Fn CONF_modules_load 179function if they wish to load a configuration file themselves and 180have finer control over how errors are treated. 181.Sh RETURN VALUES 182.Fn CONF_modules_load_file 183and 184.Fn CONF_modules_load 185return 1 for success and zero or a negative value for failure. 186If module errors are not ignored, the return code will reflect the return 187value of the failing module (this will always be zero or negative). 188.Pp 189.Fn X509_get_default_cert_area 190returns a pointer to the constant string 191.Qq "/etc/ssl" . 192.Sh FILES 193.Bl -tag -width /etc/ssl/openssl.cnf -compact 194.It Pa /etc/ssl 195standard configuration directory 196.It Pa /etc/ssl/openssl.cnf 197standard configuration file 198.El 199.Sh EXAMPLES 200Load a configuration file and print out any errors and exit (missing 201file considered fatal): 202.Bd -literal 203if (CONF_modules_load_file(NULL, NULL, 0) <= 0) { 204 fprintf(stderr, "FATAL: error loading configuration file\en"); 205 ERR_print_errors_fp(stderr); 206 exit(1); 207} 208.Ed 209.Pp 210Load default configuration file using the section indicated 211by "myapp", tolerate missing files, but exit on other errors: 212.Bd -literal 213if (CONF_modules_load_file(NULL, "myapp", 214 CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) { 215 fprintf(stderr, "FATAL: error loading configuration file\en"); 216 ERR_print_errors_fp(stderr); 217 exit(1); 218} 219.Ed 220.Pp 221Load custom configuration file and section instead of the standard one, 222only print warnings on error, missing configuration file ignored: 223.Bd -literal 224OPENSSL_no_config(); 225OPENSSL_load_builtin_modules(); 226if (CONF_modules_load_file("/something/app.cnf", "myapp", 227 CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) { 228 fprintf(stderr, "WARNING: error loading configuration file\en"); 229 ERR_print_errors_fp(stderr); 230} 231.Ed 232.Pp 233In the previous example, the call to 234.Xr OPENSSL_no_config 3 235is required first to suppress automatic loading 236of the standard configuration file, and the call to 237.Xr OPENSSL_load_builtin_modules 3 238is needed so that the configuration of builtin modules 239is loaded in addition to the configuration of 240.Qq myapp . 241.Pp 242Load and parse configuration file manually, custom error handling: 243.Bd -literal 244FILE *fp; 245CONF *cnf = NULL; 246long eline; 247 248fp = fopen("/somepath/app.cnf", "r"); 249if (fp == NULL) { 250 fprintf(stderr, "Error opening configuration file\en"); 251 /* Other missing configuration file behaviour */ 252} else { 253 cnf = NCONF_new(NULL); 254 if (NCONF_load_fp(cnf, fp, &eline) == 0) { 255 fprintf(stderr, "Error on line %ld of configuration file\en", 256 eline); 257 ERR_print_errors_fp(stderr); 258 /* Other malformed configuration file behaviour */ 259 } else if (CONF_modules_load(cnf, "appname", 0) <= 0) { 260 fprintf(stderr, "Error configuring application\en"); 261 ERR_print_errors_fp(stderr); 262 /* Other configuration error behaviour */ 263 } 264 fclose(fp); 265 NCONF_free(cnf); 266} 267.Ed 268.Sh SEE ALSO 269.Xr CONF_modules_free 3 , 270.Xr ERR 3 , 271.Xr OPENSSL_config 3 , 272.Xr OPENSSL_load_builtin_modules 3 273.Sh HISTORY 274.Fn X509_get_default_cert_area 275first appeared in SSLeay 0.4.1 and has been available since 276.Ox 2.4 . 277.Pp 278.Fn CONF_modules_load_file 279and 280.Fn CONF_modules_load 281first appeared in OpenSSL 0.9.7 and have been available since 282.Ox 3.2 . 283