xref: /openbsd-src/lib/libcrypto/man/CONF_modules_load_file.3 (revision f110de9b4e2a7d0ef7ea337f6e644e6369e9d88f)
1*f110de9bStb.\" $OpenBSD: CONF_modules_load_file.3,v 1.14 2023/11/19 20:58:07 tb Exp $
238319999Sschwarze.\" full merge up to: e9b77246 Jan 20 19:58:49 2017 +0100
338319999Sschwarze.\" selective merge up to: d090fc00 Feb 26 13:11:10 2019 +0800
48974101aSjmc.\"
538319999Sschwarze.\" This file is a derived work.
638319999Sschwarze.\" The changes are covered by the following Copyright and license:
738319999Sschwarze.\"
838319999Sschwarze.\" Copyright (c) 2021 Ingo Schwarze <schwarze@openbsd.org>
938319999Sschwarze.\"
1038319999Sschwarze.\" Permission to use, copy, modify, and distribute this software for any
1138319999Sschwarze.\" purpose with or without fee is hereby granted, provided that the above
1238319999Sschwarze.\" copyright notice and this permission notice appear in all copies.
1338319999Sschwarze.\"
1438319999Sschwarze.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1538319999Sschwarze.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1638319999Sschwarze.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1738319999Sschwarze.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1838319999Sschwarze.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1938319999Sschwarze.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
2038319999Sschwarze.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2138319999Sschwarze.\"
2238319999Sschwarze.\" The original file was written by Dr. Stephen Henson <steve@openssl.org>.
232bfa9602Sschwarze.\" Copyright (c) 2000, 2015 The OpenSSL Project.  All rights reserved.
242bfa9602Sschwarze.\"
252bfa9602Sschwarze.\" Redistribution and use in source and binary forms, with or without
262bfa9602Sschwarze.\" modification, are permitted provided that the following conditions
272bfa9602Sschwarze.\" are met:
282bfa9602Sschwarze.\"
292bfa9602Sschwarze.\" 1. Redistributions of source code must retain the above copyright
302bfa9602Sschwarze.\"    notice, this list of conditions and the following disclaimer.
312bfa9602Sschwarze.\"
322bfa9602Sschwarze.\" 2. Redistributions in binary form must reproduce the above copyright
332bfa9602Sschwarze.\"    notice, this list of conditions and the following disclaimer in
342bfa9602Sschwarze.\"    the documentation and/or other materials provided with the
352bfa9602Sschwarze.\"    distribution.
362bfa9602Sschwarze.\"
372bfa9602Sschwarze.\" 3. All advertising materials mentioning features or use of this
382bfa9602Sschwarze.\"    software must display the following acknowledgment:
392bfa9602Sschwarze.\"    "This product includes software developed by the OpenSSL Project
402bfa9602Sschwarze.\"    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
412bfa9602Sschwarze.\"
422bfa9602Sschwarze.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
432bfa9602Sschwarze.\"    endorse or promote products derived from this software without
442bfa9602Sschwarze.\"    prior written permission. For written permission, please contact
452bfa9602Sschwarze.\"    openssl-core@openssl.org.
462bfa9602Sschwarze.\"
472bfa9602Sschwarze.\" 5. Products derived from this software may not be called "OpenSSL"
482bfa9602Sschwarze.\"    nor may "OpenSSL" appear in their names without prior written
492bfa9602Sschwarze.\"    permission of the OpenSSL Project.
502bfa9602Sschwarze.\"
512bfa9602Sschwarze.\" 6. Redistributions of any form whatsoever must retain the following
522bfa9602Sschwarze.\"    acknowledgment:
532bfa9602Sschwarze.\"    "This product includes software developed by the OpenSSL Project
542bfa9602Sschwarze.\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
552bfa9602Sschwarze.\"
562bfa9602Sschwarze.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
572bfa9602Sschwarze.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
582bfa9602Sschwarze.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
592bfa9602Sschwarze.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
602bfa9602Sschwarze.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
612bfa9602Sschwarze.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
622bfa9602Sschwarze.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
632bfa9602Sschwarze.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
642bfa9602Sschwarze.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
652bfa9602Sschwarze.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
662bfa9602Sschwarze.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
672bfa9602Sschwarze.\" OF THE POSSIBILITY OF SUCH DAMAGE.
682bfa9602Sschwarze.\"
69b46e92a9Stb.Dd $Mdocdate: November 19 2023 $
70c7124953Sschwarze.Dt CONF_MODULES_LOAD_FILE 3
71c7124953Sschwarze.Os
72c7124953Sschwarze.Sh NAME
73c7124953Sschwarze.Nm CONF_modules_load_file ,
7438319999Sschwarze.Nm CONF_modules_load ,
7538319999Sschwarze.Nm X509_get_default_cert_area
76c7124953Sschwarze.Nd OpenSSL configuration functions
77c7124953Sschwarze.Sh SYNOPSIS
78c7124953Sschwarze.In openssl/conf.h
79c7124953Sschwarze.Ft int
80c7124953Sschwarze.Fo CONF_modules_load_file
81c7124953Sschwarze.Fa "const char *filename"
82c7124953Sschwarze.Fa "const char *appname"
83c7124953Sschwarze.Fa "unsigned long flags"
84c7124953Sschwarze.Fc
85c7124953Sschwarze.Ft int
86c7124953Sschwarze.Fo CONF_modules_load
87c7124953Sschwarze.Fa "const CONF *cnf"
88c7124953Sschwarze.Fa "const char *appname"
89c7124953Sschwarze.Fa "unsigned long flags"
90c7124953Sschwarze.Fc
9138319999Sschwarze.In openssl/x509.h
9238319999Sschwarze.Ft const char *
9338319999Sschwarze.Fn X509_get_default_cert_area void
94c7124953Sschwarze.Sh DESCRIPTION
95c7124953SschwarzeThe function
96c7124953Sschwarze.Fn CONF_modules_load_file
97a8f29161Sschwarzeconfigures OpenSSL using the file
98c7124953Sschwarze.Fa filename
99a8f29161Sschwarzein
100a8f29161Sschwarze.Xr openssl.cnf 5
101a8f29161Sschwarzeformat and the application name
102c7124953Sschwarze.Fa appname .
103c7124953SschwarzeIf
104c7124953Sschwarze.Fa filename
105c7124953Sschwarzeis
106c7124953Sschwarze.Dv NULL ,
107a8f29161Sschwarzethe standard OpenSSL configuration file
108a8f29161Sschwarze.Pa /etc/ssl/openssl.cnf
109a8f29161Sschwarzeis used.
110c7124953SschwarzeIf
111c7124953Sschwarze.Fa appname
112c7124953Sschwarzeis
113c7124953Sschwarze.Dv NULL ,
114c7124953Sschwarzethe standard OpenSSL application name
115c7124953Sschwarze.Qq openssl_conf
116c7124953Sschwarzeis used.
1172bfa9602SschwarzeThe behaviour can be customized using
118c7124953Sschwarze.Fa flags .
119c7124953Sschwarze.Pp
120536f31e8SschwarzeSee the
121536f31e8Sschwarze.Sx EXAMPLES
122536f31e8Sschwarzesection for additional functions that may need to be called.
123536f31e8SschwarzeCalling configuration functions in the right order for the intended
124536f31e8Sschwarzeeffect can be tricky because many configuration functions internally
125536f31e8Sschwarzecall each other.
126536f31e8Sschwarze.Pp
127c7124953Sschwarze.Fn CONF_modules_load
1282bfa9602Sschwarzeis identical to
129c7124953Sschwarze.Fn CONF_modules_load_file
130c7124953Sschwarzeexcept it reads configuration information from
131c7124953Sschwarze.Fa cnf .
132c7124953Sschwarze.Pp
133c7124953SschwarzeThe following
134c7124953Sschwarze.Fa flags
135c7124953Sschwarzeare currently recognized:
136c7124953Sschwarze.Bl -tag -width Ds
137c7124953Sschwarze.It Dv CONF_MFLAGS_IGNORE_ERRORS
138c7124953SschwarzeIgnore errors returned by individual configuration modules.
139c7124953SschwarzeBy default, the first module error is considered fatal and no further
140c7124953Sschwarzemodules are loaded.
141c7124953Sschwarze.It Dv CONF_MFLAGS_SILENT
142c7124953SschwarzeDo not add any error information.
143c7124953SschwarzeBy default, all module errors add error information to the error queue.
144c7124953Sschwarze.It Dv CONF_MFLAGS_NO_DSO
145c7124953SschwarzeDisable loading of configuration modules from DSOs.
14691d9be7dStbThis flag is provided for compatibility and has no effect.
147c7124953Sschwarze.It Dv CONF_MFLAGS_IGNORE_MISSING_FILE
148c7124953SschwarzeLet
149c7124953Sschwarze.Fn CONF_modules_load_file
150c7124953Sschwarzeignore missing configuration files.
151c7124953SschwarzeBy default, a missing configuration file returns an error.
1522bfa9602Sschwarze.It CONF_MFLAGS_DEFAULT_SECTION
1532bfa9602SschwarzeIf
1542bfa9602Sschwarze.Fa appname
1552bfa9602Sschwarzeis not
1562bfa9602Sschwarze.Dv NULL
1572bfa9602Sschwarzebut does not exist, fall back to the default section
1582bfa9602Sschwarze.Qq openssl_conf .
159c7124953Sschwarze.El
1602bfa9602Sschwarze.Pp
1612bfa9602SschwarzeBy using
1622bfa9602Sschwarze.Fn CONF_modules_load_file
1632bfa9602Sschwarzewith appropriate flags, an application can customise application
1642bfa9602Sschwarzeconfiguration to best suit its needs.
1652bfa9602SschwarzeIn some cases the use of a configuration file is optional and its
1662bfa9602Sschwarzeabsence is not an error: in this case
1672bfa9602Sschwarze.Dv CONF_MFLAGS_IGNORE_MISSING_FILE
1682bfa9602Sschwarzewould be set.
1692bfa9602Sschwarze.Pp
1702bfa9602SschwarzeErrors during configuration may also be handled differently by
1712bfa9602Sschwarzedifferent applications.
1722bfa9602SschwarzeFor example in some cases an error may simply print out a warning
1732bfa9602Sschwarzemessage and the application may continue.
1742bfa9602SschwarzeIn other cases an application might consider a configuration file
1752bfa9602Sschwarzeerror fatal and exit immediately.
1762bfa9602Sschwarze.Pp
1772bfa9602SschwarzeApplications can use the
1782bfa9602Sschwarze.Fn CONF_modules_load
1792bfa9602Sschwarzefunction if they wish to load a configuration file themselves and
1802bfa9602Sschwarzehave finer control over how errors are treated.
181c7124953Sschwarze.Sh RETURN VALUES
18238319999Sschwarze.Fn CONF_modules_load_file
18338319999Sschwarzeand
18438319999Sschwarze.Fn CONF_modules_load
18538319999Sschwarzereturn 1 for success and zero or a negative value for failure.
186c7124953SschwarzeIf module errors are not ignored, the return code will reflect the return
187c7124953Sschwarzevalue of the failing module (this will always be zero or negative).
18838319999Sschwarze.Pp
18938319999Sschwarze.Fn X509_get_default_cert_area
19038319999Sschwarzereturns a pointer to the constant string
19138319999Sschwarze.Qq "/etc/ssl" .
192a8f29161Sschwarze.Sh FILES
193a8f29161Sschwarze.Bl -tag -width /etc/ssl/openssl.cnf -compact
19438319999Sschwarze.It Pa /etc/ssl
19538319999Sschwarzestandard configuration directory
196a8f29161Sschwarze.It Pa /etc/ssl/openssl.cnf
197a8f29161Sschwarzestandard configuration file
198a8f29161Sschwarze.El
1992bfa9602Sschwarze.Sh EXAMPLES
2002bfa9602SschwarzeLoad a configuration file and print out any errors and exit (missing
2012bfa9602Sschwarzefile considered fatal):
2022bfa9602Sschwarze.Bd -literal
2032bfa9602Sschwarzeif (CONF_modules_load_file(NULL, NULL, 0) <= 0) {
20494534f40Sschwarze	fprintf(stderr, "FATAL: error loading configuration file\en");
2052bfa9602Sschwarze	ERR_print_errors_fp(stderr);
2062bfa9602Sschwarze	exit(1);
2072bfa9602Sschwarze}
2082bfa9602Sschwarze.Ed
2092bfa9602Sschwarze.Pp
2102bfa9602SschwarzeLoad default configuration file using the section indicated
2112bfa9602Sschwarzeby "myapp", tolerate missing files, but exit on other errors:
2122bfa9602Sschwarze.Bd -literal
2132bfa9602Sschwarzeif (CONF_modules_load_file(NULL, "myapp",
2142bfa9602Sschwarze    CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
21594534f40Sschwarze	fprintf(stderr, "FATAL: error loading configuration file\en");
2162bfa9602Sschwarze	ERR_print_errors_fp(stderr);
2172bfa9602Sschwarze	exit(1);
2182bfa9602Sschwarze}
2192bfa9602Sschwarze.Ed
2202bfa9602Sschwarze.Pp
221536f31e8SschwarzeLoad custom configuration file and section instead of the standard one,
222536f31e8Sschwarzeonly print warnings on error, missing configuration file ignored:
2232bfa9602Sschwarze.Bd -literal
224536f31e8SschwarzeOPENSSL_no_config();
225536f31e8SschwarzeOPENSSL_load_builtin_modules();
2262bfa9602Sschwarzeif (CONF_modules_load_file("/something/app.cnf", "myapp",
2272bfa9602Sschwarze    CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
22894534f40Sschwarze	fprintf(stderr, "WARNING: error loading configuration file\en");
2292bfa9602Sschwarze	ERR_print_errors_fp(stderr);
2302bfa9602Sschwarze}
2312bfa9602Sschwarze.Ed
2322bfa9602Sschwarze.Pp
233536f31e8SschwarzeIn the previous example, the call to
234536f31e8Sschwarze.Xr OPENSSL_no_config 3
235536f31e8Sschwarzeis required first to suppress automatic loading
236571f8132Stbof the standard configuration file, and the call to
237536f31e8Sschwarze.Xr OPENSSL_load_builtin_modules 3
238b46e92a9Stbis needed so that the configuration of builtin modules
239b46e92a9Stbis loaded in addition to the configuration of
240536f31e8Sschwarze.Qq myapp .
241536f31e8Sschwarze.Pp
2422bfa9602SschwarzeLoad and parse configuration file manually, custom error handling:
2432bfa9602Sschwarze.Bd -literal
2442bfa9602SschwarzeFILE	*fp;
2452bfa9602SschwarzeCONF	*cnf = NULL;
2462bfa9602Sschwarzelong	 eline;
2472bfa9602Sschwarze
2482bfa9602Sschwarzefp = fopen("/somepath/app.cnf", "r");
2492bfa9602Sschwarzeif (fp == NULL) {
25094534f40Sschwarze	fprintf(stderr, "Error opening configuration file\en");
2512bfa9602Sschwarze	/* Other missing configuration file behaviour */
2522bfa9602Sschwarze} else {
2532bfa9602Sschwarze	cnf = NCONF_new(NULL);
2542bfa9602Sschwarze	if (NCONF_load_fp(cnf, fp, &eline) == 0) {
25594534f40Sschwarze		fprintf(stderr, "Error on line %ld of configuration file\en",
2562bfa9602Sschwarze		    eline);
2572bfa9602Sschwarze		ERR_print_errors_fp(stderr);
2582bfa9602Sschwarze		/* Other malformed configuration file behaviour */
2592bfa9602Sschwarze	} else if (CONF_modules_load(cnf, "appname", 0) <= 0) {
26094534f40Sschwarze		fprintf(stderr, "Error configuring application\en");
2612bfa9602Sschwarze		ERR_print_errors_fp(stderr);
2622bfa9602Sschwarze		/* Other configuration error behaviour */
2632bfa9602Sschwarze	}
2642bfa9602Sschwarze	fclose(fp);
2652bfa9602Sschwarze	NCONF_free(cnf);
2662bfa9602Sschwarze}
2672bfa9602Sschwarze.Ed
268c7124953Sschwarze.Sh SEE ALSO
269efb96245Sjmc.Xr CONF_modules_free 3 ,
270c7124953Sschwarze.Xr ERR 3 ,
271595e8f71Sschwarze.Xr OPENSSL_config 3 ,
272536f31e8Sschwarze.Xr OPENSSL_load_builtin_modules 3
273c7124953Sschwarze.Sh HISTORY
27438319999Sschwarze.Fn X509_get_default_cert_area
27538319999Sschwarzefirst appeared in SSLeay 0.4.1 and has been available since
27638319999Sschwarze.Ox 2.4 .
27738319999Sschwarze.Pp
278c7124953Sschwarze.Fn CONF_modules_load_file
279c7124953Sschwarzeand
280c7124953Sschwarze.Fn CONF_modules_load
28180d1afcdSschwarzefirst appeared in OpenSSL 0.9.7 and have been available since
28280d1afcdSschwarze.Ox 3.2 .
283