Rewrite man5/config.pod and related conf code cleanup
[openssl.git] / doc / man5 / config.pod
1 =pod
2
3 =head1 NAME
4
5 config - OpenSSL CONF library configuration files
6
7 =head1 DESCRIPTION
8
9 This page documents the syntax of OpenSSL configuration files,
10 as parsed by L<NCONF_load(3)> and related functions.
11 This format is used by many of the OpenSSL commands, and to
12 initialize the libraries when used by any application.
13
14 The first part describes the general syntax of the configuration
15 files, and subsequent sections describe the semantics of individual
16 modules. Other modules are described in L<fips_config(5)> and
17 L<x509v3_config(5)>.
18 The syntax for defining ASN.1 values is described in
19 L<ASN1_generate_nconf(3)>.
20
21 =head1 SYNTAX
22
23 A configuration file is a series of lines.  Blank lines, and whitespace
24 between the elements of a line, have no significance. A comment starts
25 with a B<#> character; the rest of the line is ignored. If the B<#>
26 is the first non-space character in a line, the entire line is ignored.
27
28 =head2 Directives
29
30 Two directives can be used to control the parsing of configuration files:
31 B<.include> and B<.pragma>.
32
33 For compatibility with older versions of OpenSSL, an equal sign after the
34 directive will be ignored.  Older versions will treat it as an assignment,
35 so care should be taken if the difference in semantics is important.
36
37 A file can include other files using the include syntax:
38
39   .include [=] pathname
40
41 If B<pathname> is a simple filename, that file is included directly at
42 that point.  Included files can have B<.include> statements that specify
43 other files.  If B<pathname> is a directory, all files within that directory
44 that have a C<.cnf> or C<.conf> extension will be included.  (This is only
45 available on systems with POSIX IO support.)  Any sub-directories found
46 inside the B<pathname> are B<ignored>.  Similarly, if a file is opened
47 while scanning a directory, and that file has an B<.include> directive
48 that specifies a directory, that is also ignored.
49
50 As a general rule, the B<pathname> should be an absolute path.  Relative
51 paths are evaluated based on the current working directory, so unless the
52 file with the B<.include> directive is application-specific, the inclusion
53 will not work as expected.  The environment variable B<OPENSSL_CONF_INCLUDE>,
54 if it exists, will be prepended to all B<.include> B<pathname>'s.
55
56 In these files, the dollar sign, B<$>, is used to reference a variable, as
57 described below.  On some platforms, however, it is common to treat B<$>
58 as a regular character in symbol names.  Supporting this behavior can be
59 done with the following directive:
60
61  .pragma [=] dollarid:value
62
63 Where B<value> is one of the following:
64
65 =over 4
66
67 =item B<off> or B<false>
68
69 This is the default behavior. For example, C<foo$bar> is interpreted as
70 C<foo> followed by the expansion of the variable C<bar>.
71
72 =item B<on> or B<true>
73
74 This specifies that dollar signs are part of the symbol name and
75 variable expansions must be specified using braces or parentheses.
76 For example, C<foo$bar> is treated as a single seven-character name.
77
78 =back
79
80 =head2 Settings
81
82 A configuration file is divided into a number of I<sections>.  A section
83 begins with the section name in square brackets, and ends when a new
84 section starts, or at the end of the file.  The section name can consist
85 of alphanumeric characters and underscores.
86 Whitespace between the name and the brackets is removed.
87
88 The first section of a configuration file is special and is referred to
89 as the B<default> section. This section is usually unnamed and spans from
90 the start of file until the first named section. When a name is being
91 looked up, it is first looked up in the current or named section,
92 and then the default section if necessary.
93
94 The environment is mapped onto a section called B<ENV>.
95
96 Within a section are a series of name/value assignments, described in more
97 detail below.  As a reminder, the square brackets shown in this example
98 are required, not optional:
99
100  [ section ]
101  name1 = This is value1
102  name2 = Another value
103  ...
104  [ newsection ]
105  name1 = New value1
106  name3 = Value 3
107
108 The B<name> can contain any alphanumeric characters as well as a few
109 punctuation symbols such as B<.> B<,> B<;> and B<_>.
110 Whitespace after the name and before the equal sign is ignored.
111
112 If a name is repeated in the same section, then all but the last
113 value are ignored. In certain circumstances, such as with
114 Certificate DNs, the same field may occur multiple times.
115 In order to support this, commands like L<openssl-req(1)> ignore any
116 leading text that is preceeded with a period. For example:
117
118  1.OU = First OU
119  2.OU = Second OU
120
121 The B<value> consists of the string following the B<=> character until end
122 of line with any leading and trailing white space removed.
123
124 The value string undergoes variable expansion. The text C<$var> or C<${var}>
125 inserts the value of the named variable from the current section.
126 To use a value from another section use C<$section::name>
127 or C<${section::name}>.
128 By using C<$ENV::name>, the value of the specified environment
129 variable will be substituted.
130
131 Variables must be defined before their value is referenced, otherwise
132 an error is flagged and the file will not load.
133 This can be worked around by specifying a default value in the B<default>
134 section before the variable is used.
135
136 Any name/value settings in an B<ENV> section are available
137 to the configuration file, but are not propagated to the environment.
138
139 It is an error if the value ends up longer than 64k.
140
141 It is possible to escape certain characters by using a single B<'> or
142 double B<"> quote around the value, or using a backslash B<\> before the
143 character,
144 By making the last character of a line a B<\>
145 a B<value> string can be spread across multiple lines. In addition
146 the sequences B<\n>, B<\r>, B<\b> and B<\t> are recognized.
147
148 The expansion and escape rules as described above that apply to B<value>
149 also apply to the pathname of the B<.include> directive.
150
151 =head1 OPENSSL LIBRARY CONFIGURATION
152
153 The sections below use the informal term I<module> to refer to a part
154 of the OpenSSL functionality. This is not the same as the formal term
155 I<FIPS module>, for example.
156
157 The OpenSSL configuration looks up the value of B<openssl_conf>
158 in the default section and takes that as the name of a section that specifies
159 how to configure any modules in the library. It is not an error to leave
160 any module in its default configuration. An application can specify a
161 different name by calling CONF_modules_load_file(), for example, directly.
162
163  # This must be in the default section
164  openssl_conf = openssl_init
165
166  [openssl_init]
167  oid_section = oids
168  providers = providers
169  alg_section = evp_properties
170  ssl_conf = ssl_configuration
171  engines = engines
172
173  [oids]
174  ... new oids here ...
175
176  [providers]
177  ... provider stuff here ...
178
179  [evp_properties]
180  ... EVP properties here ...
181
182  [ssl_configuration]
183  ... SSL/TLS configuration properties here ...
184
185  [engines]
186  ... engine properties here ...
187
188 The semantics of each module are described below. The phrase "in the
189 initialization section" refers to the section identified by the
190 B<openssl_conf> or other name (given as B<openssl_init> in the
191 example above).  The examples below assume the configuration above
192 is used to specify the individual sections.
193
194 =head2 ASN.1 Object Identifier Configuration
195
196 The name B<oid_section> in the initialization section names the section
197 containing name/value pairs of OID's.
198 The name is the short name; the value is an optional long name followed
199 by a comma, and the numeric value.
200 While some OpenSSL commands have their own section for specifying OID's,
201 this section makes them avilable to all commands and applications.
202
203  [oids]
204  shortName = a very long OID name, 1.2.3.4
205  newoid1 = 1.2.3.4.1
206  some_other_oid = 1.2.3.5
207
208 If a full configuration with the above fragment is in the file
209 F<example.cnf>, then the following command line:
210
211  OPENSSL_CONF=example.cnf openssl asn1parse -genstr OID:1.2.3.4.1
212
213 will output:
214
215  0:d=0  hl=2 l=   4 prim: OBJECT            :newoid1
216
217 showing that the OID "newoid1" has been added as "1.2.3.4.1".
218
219 =head2 Provider Configuration
220
221 The name B<providers> in the initialization section names the section
222 containing cryptographic provider configuration. The name/value assignments
223 in this section each name a provider, and point to the configuration section
224 for that provider. The provider-specific section is used to specify how
225 to load the module, activate it, and set other parameters.
226
227 Within a provider section, the following names have meaning:
228
229 =over 4
230
231 =item B<identity>
232
233 This is used to specify an alternate name, overriding the default name
234 specified in the list of providers.  For example:
235
236  [providers]
237  foo = foo_provider
238
239  [foo_provider]
240  identity = my_fips_module
241
242 =item B<module>
243
244 Specifies the pathname of the module (typically a shared library) to load.
245
246 =item B<activate>
247
248 If present, the module is activated. The value assigned to this name is not
249 significant.
250
251 =back
252
253 All parameters in the section as well as sub-sections are made
254 available to the provider.
255
256 =head2 EVP Configuration
257
258 The name B<alg_section> in the initialization section names the section
259 containing algorithmic properties when using the B<EVP> API.
260
261 Within the algorithm properties section, the following names have meaning:
262
263 =over 4
264
265 =item B<default_properties>
266
267 The value may be anything that is acceptable as a property query
268 string for EVP_set_default_properties().
269
270 =item B<fips_mode> (deprecated)
271
272 The value is a boolean that can be B<yes> or B<no>.  If the value is
273 B<yes>, this is exactly equivalent to:
274
275  default_properties = fips=yes
276
277 If the value is B<no>, nothing happens. Using this name is deprecated, and
278 if used, it must be the only name in the section.
279
280 =back
281
282 =head2 SSL Configuration
283
284 The name B<ssl_conf> in the initialization section names the section
285 containing the list of SSL/TLS configurations.
286 As with the providers, each name in this section identifies a
287 section with the configuration for that name. For example:
288
289  [ssl_configuration]
290  server = server_tls_config
291  client = client_tls_config
292  system_default = tls_system_default
293
294  [server_tls_config]
295  ... configuration for SSL/TLS servers ...
296
297  [client_tls_config]
298  ... configuration for SSL/TLS clients ...
299
300 The configuration name B<system_default> has a special meaning.  If it
301 exists, it is applied whenever an B<SSL_CTX> object is created.  For example,
302 to impose a system-wide minimum on protocol version:
303
304  [tls_system_default]
305  MinProtocol = TLSv1.2
306
307 Each configuration section consists of name/value pairs that are parsed
308 by B<SSL_CONF_cmd(3)>, which will be called by SSL_CTX_config() or
309 SSL_config(), appropriately.  Note that any characters before an initial
310 dot in the configuration section are ignored, so that the same command can
311 be used multiple times. This probably is most useful for loading different
312 key types, as shown here:
313
314  [server_tls_config]
315  RSA.Certificate = server-rsa.pem
316  ECDSA.Certificate = server-ecdsa.pem
317
318 =head2 Engine Configuration
319
320 The name B<engines> in the initialization section names the section
321 containing the list of ENGINE configurations.
322 As with the providers, each name in this section identifies an engine
323 with the configuration for that engine.
324 The engine-specific section is used to specify how to load the engine,
325 activate it, and set other parameters.
326
327 Within an engine section, the following names have meaning:
328
329 =over 4
330
331 =item B<engine_id>
332
333 This is used to specify an alternate name, overriding the default name
334 specified in the list of engines. If present, it must be first.
335 For example:
336
337  [engines]
338  foo = foo_engine
339
340  [foo_engine]
341  engine_id = myfoo
342
343 =item B<dynamic_path>
344
345 This loads and adds an ENGINE from the given path. It is equivalent to
346 sending the ctrls B<SO_PATH> with the path argument followed by B<LIST_ADD>
347 with value B<2> and B<LOAD> to the dynamic ENGINE.  If this is not the
348 required behaviour then alternative ctrls can be sent directly to the
349 dynamic ENGINE using ctrl commands.
350
351 =item B<init>
352
353 This specifies whether to initialize the ENGINE. If the value is B<0> the
354 ENGINE will not be initialized, if the value is B<1> an attempt is made
355 to initialize
356 the ENGINE immediately. If the B<init> command is not present then an
357 attempt will be made to initialize the ENGINE after all commands in its
358 section have been processed.
359
360 =item B<default_algorithms>
361
362 This sets the default algorithms an ENGINE will supply using the function
363 ENGINE_set_default_string().
364
365 =back
366
367 All other names are taken to be the name of a ctrl command that is
368 sent to the ENGINE, and the value is the argument passed with the command.
369 The special value B<EMPTY> means no value is sent with the command.
370 For example:
371
372  [engines]
373  foo = foo_engine
374
375  [foo_engine]
376  dynamic_path = /some/path/fooengine.so
377  some_ctrl = some_value
378  default_algorithms = ALL
379  other_ctrl = EMPTY
380
381 =head1 EXAMPLES
382
383 This example shows how to use quoting and escaping.
384
385  # This is the default section.
386  HOME = /temp
387  configdir = $ENV::HOME/config
388
389  [ section_one ]
390  # Quotes permit leading and trailing whitespace
391  any = " any variable name "
392  other = A string that can \
393  cover several lines \
394  by including \\ characters
395  message = Hello World\n
396
397  [ section_two ]
398  greeting = $section_one::message
399
400 This example shows how to expand environment variables safely.
401 In this example, the variable B<tempfile> is intended to refer
402 to a temporary file, and the environment variable B<TEMP> or
403 B<TMP>, if present, specify the directory where the file
404 should be put.
405 Since the default section is checked if a variable does not
406 exist, it is possible to set B<TMP> to default to F</tmp>, and
407 B<TEMP> to default to B<TMP>.
408
409  # These two lines must be in the default section.
410  TMP = /tmp
411  TEMP = $ENV::TMP
412
413  # This can be used anywhere
414  tmpfile = ${ENV::TEMP}/tmp.filename
415
416 This example shows how to enforce FIPS mode for the application
417 F<sample>.
418
419  sample = fips_config
420
421  [fips_config]
422  alg_section = evp_properties
423
424  [evp_properties]
425  default_properties = "fips=yes"
426
427 =head1 ENVIRONMENT
428
429 =over 4
430
431 =item B<OPENSSL_CONF>
432
433 The path to the config file.
434 Ignored in set-user-ID and set-group-ID programs.
435
436 =item B<OPENSSL_ENGINES>
437
438 The path to the engines directory.
439 Ignored in set-user-ID and set-group-ID programs.
440
441 =item B<OPENSSL_MODULES>
442
443 The path to the directory with OpenSSL modules, such as providers.
444 Ignored in set-user-ID and set-group-ID programs.
445
446 =item B<OPENSSL_CONF_INCLUDE>
447
448 The optional path to prepend to all B<.include> paths.
449
450 =back
451
452 =head1 BUGS
453
454 There is no way to include characters using the octal B<\nnn> form. Strings
455 are all null terminated so nulls cannot form part of the value.
456
457 The escaping isn't quite right: if you want to use sequences like B<\n>
458 you can't use any quote escaping on the same line.
459
460 The limit that only one directory can be opened and read at a time
461 can be considered a bug and should be fixed.
462
463 =head1 HISTORY
464
465 An undocumented API, NCONF_WIN32(), used a slightly different set
466 of parsing rules there were intended to be tailored to
467 the Microsoft Windows platform.
468 Specifically, the backslash character was not an escape character and
469 could be used in pathnames, only the double-quote character was recognized,
470 and comments began with a semi-colon.
471 This function was deprecated in OpenSSL 3.0; applications with
472 configuration files using that syntax will have to be modified.
473
474 =head1 SEE ALSO
475
476 L<openssl-x509(1)>, L<openssl-req(1)>, L<openssl-ca(1)>,
477 L<ASN1_generate_nconf(3)>,
478 L<EVP_set_default_properties(3)>,
479 L<CONF_modules_load_file(3)>,
480 L<fips_config(5)>, and
481 L<x509v3_config(5)>.
482
483 =head1 COPYRIGHT
484
485 Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
486
487 Licensed under the Apache License 2.0 (the "License").  You may not use
488 this file except in compliance with the License.  You can obtain a copy
489 in the file LICENSE in the source distribution or at
490 L<https://www.openssl.org/source/license.html>.
491
492 =cut