1.\" $OpenBSD: openssl.cnf.5,v 1.7 2020/02/17 12:52:42 inoguchi Exp $ 2.\" full merge up to: OpenSSL man5/config b53338cb Feb 28 12:30:28 2017 +0100 3.\" selective merge up to: OpenSSL a8c5ed81 Jul 18 13:57:25 2017 -0400 4.\" 5.\" This file was written by Dr. Stephen Henson <steve@openssl.org>. 6.\" Copyright (c) 1999, 2000, 2004, 2013, 2015, 2016, 2017 The OpenSSL Project. 7.\" All rights reserved. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 13.\" 1. Redistributions of source code must retain the above copyright 14.\" notice, this list of conditions and the following disclaimer. 15.\" 16.\" 2. Redistributions in binary form must reproduce the above copyright 17.\" notice, this list of conditions and the following disclaimer in 18.\" the documentation and/or other materials provided with the 19.\" distribution. 20.\" 21.\" 3. All advertising materials mentioning features or use of this 22.\" software must display the following acknowledgment: 23.\" "This product includes software developed by the OpenSSL Project 24.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 25.\" 26.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 27.\" endorse or promote products derived from this software without 28.\" prior written permission. For written permission, please contact 29.\" openssl-core@openssl.org. 30.\" 31.\" 5. Products derived from this software may not be called "OpenSSL" 32.\" nor may "OpenSSL" appear in their names without prior written 33.\" permission of the OpenSSL Project. 34.\" 35.\" 6. Redistributions of any form whatsoever must retain the following 36.\" acknowledgment: 37.\" "This product includes software developed by the OpenSSL Project 38.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" 39.\" 40.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 41.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 43.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 44.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 46.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 47.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 49.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 50.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 51.\" OF THE POSSIBILITY OF SUCH DAMAGE. 52.\" 53.Dd $Mdocdate: February 17 2020 $ 54.Dt OPENSSL.CNF 5 55.Os 56.Sh NAME 57.Nm openssl.cnf 58.Nd OpenSSL configuration files 59.Sh DESCRIPTION 60The OpenSSL CONF library can be used to read configuration files; see 61.Xr CONF_modules_load_file 3 . 62It is used for the OpenSSL master configuration file 63.Pa /etc/ssl/openssl.cnf 64and in a few other places like 65.Sy SPKAC 66files and certificate extension files for the 67.Xr openssl 1 68.Cm x509 69utility. 70OpenSSL applications can also use the CONF library for their own 71purposes. 72.Pp 73A configuration file is divided into a number of sections. 74Each section starts with a line 75.Bq Ar section_name 76and ends when a new section is started or the end of the file is reached. 77A section name can consist of alphanumeric characters and underscores. 78.Pp 79The first section of a configuration file is special and is referred to 80as the 81.Dq default section . 82It is usually unnamed and extends from the start of file to the 83first named section. 84When a name is being looked up, it is first looked up in a named 85section (if any) and then in the default section. 86.Pp 87The environment is mapped onto a section called 88.Ic ENV . 89.Pp 90Comments can be included by preceding them with the 91.Ql # 92character. 93.Pp 94Each section in a configuration file consists of a number of name and 95value pairs of the form 96.Ar name Ns = Ns Ar value . 97.Pp 98The 99.Ar name 100string can contain any alphanumeric characters as well as a few 101punctuation symbols such as 102.Ql \&. 103.Ql \&, 104.Ql \&; 105and 106.Ql _ . 107.Pp 108The 109.Ar value 110string consists of the string following the 111.Ql = 112character until the end of the line with any leading and trailing 113whitespace removed. 114.Pp 115The value string undergoes variable expansion. 116This can be done by including substrings of the form 117.Pf $ Ar name 118or 119.Pf $ Brq Ar name : 120this will substitute the value of the named variable in the current 121section. 122It is also possible to substitute a value from another section using the 123syntax 124.Pf $ Ar section Ns :: Ns Ar name 125or 126.Pf $ Brq Ar section Ns :: Ns Ar name . 127By using the form 128.Pf $ Ic ENV Ns :: Ns Ar name , 129environment variables can be substituted. 130It is also possible to assign values to environment variables by using 131the name 132.Ic ENV Ns :: Ns Ar name . 133This will work if the program looks up environment variables using 134the CONF library instead of calling 135.Xr getenv 3 136directly. 137The value string must not exceed 64k in length after variable expansion or an 138error will occur. 139.Pp 140It is possible to escape certain characters by using any kind of quote 141or the 142.Ql \e 143character. 144By making the last character of a line a 145.Ql \e , 146a 147.Ar value 148string can be spread across multiple lines. 149In addition the sequences 150.Ql \en , 151.Ql \er , 152.Ql \eb , 153and 154.Ql \et 155are recognized. 156.Sh OPENSSL LIBRARY CONFIGURATION 157Applications can automatically configure certain aspects of OpenSSL 158using the master OpenSSL configuration file, or optionally an 159alternative configuration file. 160The 161.Xr openssl 1 162utility includes this functionality: any sub command uses the master 163OpenSSL configuration file unless an option is used in the sub command 164to use an alternative configuration file. 165.Pp 166To enable library configuration, the default section needs to contain 167an appropriate line which points to the main configuration section. 168The default name is 169.Ic openssl_conf , 170which is used by the 171.Xr openssl 1 172utility. 173Other applications may use an alternative name such as 174.Sy myapplication_conf . 175All library configuration lines appear in the default section 176at the start of the configuration file. 177.Pp 178The configuration section should consist of a set of name value pairs 179which contain specific module configuration information. 180The 181.Ar name 182represents the name of the configuration module. 183The meaning of the 184.Ar value 185is module specific: it may, for example, represent a further 186configuration section containing configuration module specific 187information. 188For example: 189.Bd -literal -offset indent 190# The following line must be in the default section. 191openssl_conf = openssl_init 192 193[openssl_init] 194oid_section = new_oids 195engines = engine_section 196 197[new_oids] 198\&... new oids here ... 199 200[engine_section] 201\&... engine stuff here ... 202.Ed 203.Pp 204The features of each configuration module are described below. 205.Ss ASN1 Object Configuration Module 206This module has the name 207.Ic oid_section . 208The value of this variable points to a section containing name value 209pairs of OIDs: the name is the OID short and long name, and the value is the 210numerical form of the OID. 211Although some of the 212.Xr openssl 1 213utility subcommands already have their own ASN1 OBJECT section 214functionality, not all do. 215By using the ASN1 OBJECT configuration module, all the 216.Xr openssl 1 217utility subcommands can see the new objects as well as any compliant 218applications. 219For example: 220.Bd -literal -offset indent 221[new_oids] 222some_new_oid = 1.2.3.4 223some_other_oid = 1.2.3.5 224.Ed 225.Pp 226It is also possible to set the value to the long name followed by a 227comma and the numerical OID form. 228For example: 229.Pp 230.Dl shortName = some object long name, 1.2.3.4 231.Ss Engine Configuration Module 232This ENGINE configuration module has the name 233.Ic engines . 234The value of this variable points to a section containing further ENGINE 235configuration information. 236.Pp 237The section pointed to by 238.Ic engines 239is a table of engine names (though see 240.Ic engine_id 241below) and further sections containing configuration information 242specific to each ENGINE. 243.Pp 244Each ENGINE specific section is used to set default algorithms, load 245dynamic ENGINEs, perform initialization and send ctrls. 246The actual operation performed depends on the command 247name which is the name of the name value pair. 248The currently supported commands are listed below. 249.Pp 250For example: 251.Bd -literal -offset indent 252[engine_section] 253# Configure ENGINE named "foo" 254foo = foo_section 255# Configure ENGINE named "bar" 256bar = bar_section 257 258[foo_section] 259\&... foo ENGINE specific commands ... 260 261[bar_section] 262\&... "bar" ENGINE specific commands ... 263.Ed 264.Pp 265The command 266.Ic engine_id 267is used to give the ENGINE name. 268If used this command must be first. 269For example: 270.Bd -literal -offset indent 271[engine_section] 272# This would normally handle an ENGINE named "foo" 273foo = foo_section 274 275[foo_section] 276# Override default name and use "myfoo" instead. 277engine_id = myfoo 278.Ed 279.Pp 280The command 281.Ic dynamic_path 282loads and adds an ENGINE from the given path. 283It is equivalent to sending the ctrls 284.Sy SO_PATH 285with the path argument followed by 286.Sy LIST_ADD 287with value 2 and 288.Sy LOAD 289to the dynamic ENGINE. 290If this is not the required behaviour then alternative ctrls can be sent 291directly to the dynamic ENGINE using ctrl commands. 292.Pp 293The command 294.Ic init 295determines whether to initialize the ENGINE. 296If the value is 0, the ENGINE will not be initialized. 297If it is 1, an attempt is made to initialized the ENGINE immediately. 298If the 299.Ic init 300command is not present, then an attempt will be made to initialize 301the ENGINE after all commands in its section have been processed. 302.Pp 303The command 304.Ic default_algorithms 305sets the default algorithms an ENGINE will supply using the functions 306.Xr ENGINE_set_default_string 3 . 307.Pp 308If the name matches none of the above command names it is assumed 309to be a ctrl command which is sent to the ENGINE. 310The value of the command is the argument to the ctrl command. 311If the value is the string 312.Cm EMPTY , 313then no value is sent to the command. 314.Pp 315For example: 316.Bd -literal -offset indent 317[engine_section] 318# Configure ENGINE named "foo" 319foo = foo_section 320 321[foo_section] 322# Load engine from DSO 323dynamic_path = /some/path/fooengine.so 324# A foo specific ctrl. 325some_ctrl = some_value 326# Another ctrl that doesn't take a value. 327other_ctrl = EMPTY 328# Supply all default algorithms 329default_algorithms = ALL 330.Ed 331.Sh FILES 332.Bl -tag -width /etc/ssl/openssl.cnf -compact 333.It Pa /etc/ssl/openssl.cnf 334standard configuration file 335.El 336.Sh EXAMPLES 337Here is a sample configuration file using some of the features 338mentioned above: 339.Bd -literal -offset indent 340# This is the default section. 341HOME=/temp 342RANDFILE= ${ENV::HOME}/.rnd 343configdir=$ENV::HOME/config 344 345[ section_one ] 346# We are now in section one. 347 348# Quotes permit leading and trailing whitespace 349any = " any variable name " 350 351other = A string that can \e 352cover several lines \e 353by including \e\e characters 354 355message = Hello World\en 356 357[ section_two ] 358greeting = $section_one::message 359.Ed 360.Pp 361This next example shows how to expand environment variables safely. 362.Pp 363Suppose you want a variable called 364.Sy tmpfile 365to refer to a temporary filename. 366The directory it is placed in can determined by the 367.Ev TEMP 368or 369.Ev TMP 370environment variables but they may not be set to any value at all. 371If you just include the environment variable names and the variable 372doesn't exist then this will cause an error when an attempt is made to 373load the configuration file. 374By making use of the default section both values can be looked up with 375.Ev TEMP 376taking priority and 377.Pa /tmp 378used if neither is defined: 379.Bd -literal -offset indent 380TMP=/tmp 381# The above value is used if TMP isn't in the environment 382TEMP=$ENV::TMP 383# The above value is used if TEMP isn't in the environment 384tmpfile=${ENV::TEMP}/tmp.filename 385.Ed 386.Pp 387More complex OpenSSL library configuration. 388Add OID: 389.Bd -literal -offset indent 390# Default appname: should match "appname" parameter (if any) 391# supplied to CONF_modules_load_file et al. 392openssl_conf = openssl_conf_section 393 394[openssl_conf_section] 395# Configuration module list 396alg_section = evp_sect 397oid_section = new_oids 398 399[new_oids] 400# New OID, just short name 401newoid1 = 1.2.3.4.1 402# New OID shortname and long name 403newoid2 = New OID 2 long name, 1.2.3.4.2 404.Ed 405.Pp 406The above examples can be used with any application supporting library 407configuration if "openssl_conf" is modified to match the appropriate 408"appname". 409.Pp 410For example if the second sample file above is saved to "example.cnf" 411then the command line: 412.Pp 413.Dl OPENSSL_CONF=example.cnf openssl asn1parse -genstr OID:1.2.3.4.1 414.Pp 415will output: 416.Dl 0:d=0 hl=2 l= 4 prim: OBJECT :newoid1 417.Pp 418showing that the OID "newoid1" has been added as "1.2.3.4.1". 419.Sh SEE ALSO 420.Xr openssl 1 , 421.Xr CONF_modules_load_file 3 , 422.Xr OPENSSL_config 3 , 423.Xr x509v3.cnf 5 424.Sh CAVEATS 425If a configuration file attempts to expand a variable that doesn't 426exist, then an error is flagged and the file will not load. 427This can also happen if an attempt is made to expand an environment 428variable that doesn't exist. 429For example, in a previous version of OpenSSL the default OpenSSL 430master configuration file used the value of 431.Ev HOME 432which may not be defined on non Unix systems and would cause an error. 433.Pp 434This can be worked around by including a default section to provide 435a default value: then if the environment lookup fails, the default 436value will be used instead. 437For this to work properly, the default value must be defined earlier 438in the configuration file than the expansion. 439See the 440.Sx EXAMPLES 441section for an example of how to do this. 442.Pp 443If the same variable is defined more than once in the same section, 444then all but the last value will be silently ignored. 445In certain circumstances such as with DNs, the same field may occur 446multiple times. 447This is usually worked around by ignoring any characters before an 448initial 449.Ql \&. , 450for example: 451.Bd -literal -offset indent 4521.OU="My first OU" 4532.OU="My Second OU" 454.Ed 455.Sh BUGS 456Currently there is no way to include characters using the octal 457.Pf \e Ar nnn 458form. 459Strings are all NUL terminated, so NUL bytes cannot form part of 460the value. 461.Pp 462The escaping isn't quite right: if you want to use sequences like 463.Ql \en , 464you can't use any quote escaping on the same line. 465.Pp 466Files are loaded in a single pass. 467This means that a variable expansion will only work if the variables 468referenced are defined earlier in the file. 469