364c57c2928991cbad76714e46a757638229bcd7
[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; this can
51 be enforced with the B<abspath> and B<includedir> pragmas, described below.
52 The environment variable B<OPENSSL_CONF_INCLUDE>, if it exists,
53 is prepended to all relative pathnames.
54 If the pathname is still relative, it is interpreted based on the
55 current working directory.
56
57 To require all file inclusions to name absolute paths, use the following
58 directive:
59
60  .pragma [=] abspath:value
61
62 The default behavior, where the B<value> is B<false> or B<off>, is to allow
63 relative paths. To require all B<.include> pathnames to be absolute paths,
64 use a B<value> of B<true> or B<on>.
65
66 In these files, the dollar sign, B<$>, is used to reference a variable, as
67 described below.  On some platforms, however, it is common to treat B<$>
68 as a regular character in symbol names.  Supporting this behavior can be
69 done with the following directive:
70
71  .pragma [=] dollarid:value
72
73 The default behavior, where the B<value> is B<false> or B<off>, is to treat
74 the dollarsign as indicating a variable name; C<foo$bar> is interpreted as
75 C<foo> followed by the expansion of the variable C<bar>. If B<value> is
76 B<true> or B<on>, then C<foo$bar> is a single seven-character name and
77 variable expansions must be specified using braces or parentheses.
78
79  .pragma [=] includedir:value
80
81 If a relative pathname is specified in the B<.include> directive, and
82 the B<OPENSSL_CONF_INCLUDE> environment variable doesn't exist, then
83 the value of the B<includedir> pragma, if it exists, is prepended to the
84 pathname.
85
86 =head2 Settings
87
88 A configuration file is divided into a number of I<sections>.  A section
89 begins with the section name in square brackets, and ends when a new
90 section starts, or at the end of the file.  The section name can consist
91 of alphanumeric characters and underscores.
92 Whitespace between the name and the brackets is removed.
93
94 The first section of a configuration file is special and is referred to
95 as the B<default> section. This section is usually unnamed and spans from
96 the start of file until the first named section. When a name is being
97 looked up, it is first looked up in the current or named section,
98 and then the default section if necessary.
99
100 The environment is mapped onto a section called B<ENV>.
101
102 Within a section are a series of name/value assignments, described in more
103 detail below.  As a reminder, the square brackets shown in this example
104 are required, not optional:
105
106  [ section ]
107  name1 = This is value1
108  name2 = Another value
109  ...
110  [ newsection ]
111  name1 = New value1
112  name3 = Value 3
113
114 The B<name> can contain any alphanumeric characters as well as a few
115 punctuation symbols such as B<.> B<,> B<;> and B<_>.
116 Whitespace after the name and before the equal sign is ignored.
117
118 If a name is repeated in the same section, then all but the last
119 value are ignored. In certain circumstances, such as with
120 Certificate DNs, the same field may occur multiple times.
121 In order to support this, commands like L<openssl-req(1)> ignore any
122 leading text that is preceded with a period. For example:
123
124  1.OU = First OU
125  2.OU = Second OU
126
127 The B<value> consists of the string following the B<=> character until end
128 of line with any leading and trailing whitespace removed.
129
130 The value string undergoes variable expansion. The text C<$var> or C<${var}>
131 inserts the value of the named variable from the current section.
132 To use a value from another section use C<$section::name>
133 or C<${section::name}>.
134 By using C<$ENV::name>, the value of the specified environment
135 variable will be substituted.
136
137 Variables must be defined before their value is referenced, otherwise
138 an error is flagged and the file will not load.
139 This can be worked around by specifying a default value in the B<default>
140 section before the variable is used.
141
142 Any name/value settings in an B<ENV> section are available
143 to the configuration file, but are not propagated to the environment.
144
145 It is an error if the value ends up longer than 64k.
146
147 It is possible to escape certain characters by using a single B<'> or
148 double B<"> quote around the value, or using a backslash B<\> before the
149 character,
150 By making the last character of a line a B<\>
151 a B<value> string can be spread across multiple lines. In addition
152 the sequences B<\n>, B<\r>, B<\b> and B<\t> are recognized.
153
154 The expansion and escape rules as described above that apply to B<value>
155 also apply to the pathname of the B<.include> directive.
156
157 =head1 OPENSSL LIBRARY CONFIGURATION
158
159 The sections below use the informal term I<module> to refer to a part
160 of the OpenSSL functionality. This is not the same as the formal term
161 I<FIPS module>, for example.
162
163 The OpenSSL configuration looks up the value of B<openssl_conf>
164 in the default section and takes that as the name of a section that specifies
165 how to configure any modules in the library. It is not an error to leave
166 any module in its default configuration. An application can specify a
167 different name by calling CONF_modules_load_file(), for example, directly.
168
169 OpenSSL also looks up the value of B<config_diagnostics>.
170 If this exists and has a nonzero numeric value, any error suppressing flags
171 passed to CONF_modules_load() will be ignored.
172 This is useful for diagnosing misconfigurations but its use in
173 production requires additional consideration.  With this option enabled,
174 a configuration error will completely prevent access to a service.
175 Without this option and in the presence of a configuration error, access
176 will be allowed but the desired configuration will B<not> be used.
177
178  # These must be in the default section
179  config_diagnostics = 1
180  openssl_conf = openssl_init
181
182  [openssl_init]
183  oid_section = oids
184  providers = providers
185  alg_section = evp_properties
186  ssl_conf = ssl_configuration
187  engines = engines
188  random = random
189
190  [oids]
191  ... new oids here ...
192
193  [providers]
194  ... provider stuff here ...
195
196  [evp_properties]
197  ... EVP properties here ...
198
199  [ssl_configuration]
200  ... SSL/TLS configuration properties here ...
201
202  [engines]
203  ... engine properties here ...
204
205  [random]
206  ... random properties here ...
207
208 The semantics of each module are described below. The phrase "in the
209 initialization section" refers to the section identified by the
210 B<openssl_conf> or other name (given as B<openssl_init> in the
211 example above).  The examples below assume the configuration above
212 is used to specify the individual sections.
213
214 =head2 ASN.1 Object Identifier Configuration
215
216 The name B<oid_section> in the initialization section names the section
217 containing name/value pairs of OID's.
218 The name is the short name; the value is an optional long name followed
219 by a comma, and the numeric value.
220 While some OpenSSL commands have their own section for specifying OID's,
221 this section makes them available to all commands and applications.
222
223  [oids]
224  shortName = a very long OID name, 1.2.3.4
225  newoid1 = 1.2.3.4.1
226  some_other_oid = 1.2.3.5
227
228 If a full configuration with the above fragment is in the file
229 F<example.cnf>, then the following command line:
230
231  OPENSSL_CONF=example.cnf openssl asn1parse -genstr OID:1.2.3.4.1
232
233 will output:
234
235  0:d=0  hl=2 l=   4 prim: OBJECT            :newoid1
236
237 showing that the OID "newoid1" has been added as "1.2.3.4.1".
238
239 =head2 Provider Configuration
240
241 The name B<providers> in the initialization section names the section
242 containing cryptographic provider configuration. The name/value assignments
243 in this section each name a provider, and point to the configuration section
244 for that provider. The provider-specific section is used to specify how
245 to load the module, activate it, and set other parameters.
246
247 Within a provider section, the following names have meaning:
248
249 =over 4
250
251 =item B<identity>
252
253 This is used to specify an alternate name, overriding the default name
254 specified in the list of providers.  For example:
255
256  [providers]
257  foo = foo_provider
258
259  [foo_provider]
260  identity = my_fips_module
261
262 =item B<module>
263
264 Specifies the pathname of the module (typically a shared library) to load.
265
266 =item B<activate>
267
268 If present, the module is activated. The value assigned to this name is not
269 significant.
270
271 =back
272
273 All parameters in the section as well as sub-sections are made
274 available to the provider.
275
276 =head3 Default provider and its activation
277
278 If no providers are activated explicitly, the default one is activated implicitly.
279 See L<OSSL_PROVIDER-default(7)> for more details.
280
281 If you add a section explicitly activating any other provider(s),
282 you most probably need to explicitly activate the default provider,
283 otherwise it becomes unavailable in openssl. It may make the system remotely unavailable.
284
285 =head2 EVP Configuration
286
287 The name B<alg_section> in the initialization section names the section
288 containing algorithmic properties when using the B<EVP> API.
289
290 Within the algorithm properties section, the following names have meaning:
291
292 =over 4
293
294 =item B<default_properties>
295
296 The value may be anything that is acceptable as a property query
297 string for EVP_set_default_properties().
298
299 =item B<fips_mode> (deprecated)
300
301 The value is a boolean that can be B<yes> or B<no>.  If the value is
302 B<yes>, this is exactly equivalent to:
303
304  default_properties = fips=yes
305
306 If the value is B<no>, nothing happens. Using this name is deprecated, and
307 if used, it must be the only name in the section.
308
309 =back
310
311 =head2 SSL Configuration
312
313 The name B<ssl_conf> in the initialization section names the section
314 containing the list of SSL/TLS configurations.
315 As with the providers, each name in this section identifies a
316 section with the configuration for that name. For example:
317
318  [ssl_configuration]
319  server = server_tls_config
320  client = client_tls_config
321  system_default = tls_system_default
322
323  [server_tls_config]
324  ... configuration for SSL/TLS servers ...
325
326  [client_tls_config]
327  ... configuration for SSL/TLS clients ...
328
329 The configuration name B<system_default> has a special meaning.  If it
330 exists, it is applied whenever an B<SSL_CTX> object is created.  For example,
331 to impose system-wide minimum TLS and DTLS protocol versions:
332
333  [tls_system_default]
334  MinProtocol = TLSv1.2
335  MinProtocol = DTLSv1.2
336
337 The minimum TLS protocol is applied to B<SSL_CTX> objects that are TLS-based,
338 and the minimum DTLS protocol to those are DTLS-based.
339 The same applies also to maximum versions set with B<MaxProtocol>.
340
341 Each configuration section consists of name/value pairs that are parsed
342 by B<SSL_CONF_cmd(3)>, which will be called by SSL_CTX_config() or
343 SSL_config(), appropriately.  Note that any characters before an initial
344 dot in the configuration section are ignored, so that the same command can
345 be used multiple times. This probably is most useful for loading different
346 key types, as shown here:
347
348  [server_tls_config]
349  RSA.Certificate = server-rsa.pem
350  ECDSA.Certificate = server-ecdsa.pem
351
352 =head2 Engine Configuration
353
354 The name B<engines> in the initialization section names the section
355 containing the list of ENGINE configurations.
356 As with the providers, each name in this section identifies an engine
357 with the configuration for that engine.
358 The engine-specific section is used to specify how to load the engine,
359 activate it, and set other parameters.
360
361 Within an engine section, the following names have meaning:
362
363 =over 4
364
365 =item B<engine_id>
366
367 This is used to specify an alternate name, overriding the default name
368 specified in the list of engines. If present, it must be first.
369 For example:
370
371  [engines]
372  foo = foo_engine
373
374  [foo_engine]
375  engine_id = myfoo
376
377 =item B<dynamic_path>
378
379 This loads and adds an ENGINE from the given path. It is equivalent to
380 sending the ctrls B<SO_PATH> with the path argument followed by B<LIST_ADD>
381 with value B<2> and B<LOAD> to the dynamic ENGINE.  If this is not the
382 required behaviour then alternative ctrls can be sent directly to the
383 dynamic ENGINE using ctrl commands.
384
385 =item B<init>
386
387 This specifies whether to initialize the ENGINE. If the value is B<0> the
388 ENGINE will not be initialized, if the value is B<1> an attempt is made
389 to initialize
390 the ENGINE immediately. If the B<init> command is not present then an
391 attempt will be made to initialize the ENGINE after all commands in its
392 section have been processed.
393
394 =item B<default_algorithms>
395
396 This sets the default algorithms an ENGINE will supply using the function
397 ENGINE_set_default_string().
398
399 =back
400
401 All other names are taken to be the name of a ctrl command that is
402 sent to the ENGINE, and the value is the argument passed with the command.
403 The special value B<EMPTY> means no value is sent with the command.
404 For example:
405
406  [engines]
407  foo = foo_engine
408
409  [foo_engine]
410  dynamic_path = /some/path/fooengine.so
411  some_ctrl = some_value
412  default_algorithms = ALL
413  other_ctrl = EMPTY
414
415 =head2 Random Configuration
416
417 The name B<random> in the initialization section names the section
418 containing the random number generator settings.
419
420 Within the random section, the following names have meaning:
421
422 =over 4
423
424 =item B<random>
425
426 This is used to specify the random bit generator.
427 For example:
428
429  [random]
430  random = CTR-DRBG
431
432 The available random bit generators are:
433
434 =over 4
435
436 =item B<CTR-DRBG>
437
438 =item B<HASH-DRBG>
439
440 =item B<HMAC-DRBG>
441
442 =back
443
444 =item B<cipher>
445
446 This specifies what cipher a B<CTR-DRBG> random bit generator will use.
447 Other random bit generators ignore this name.
448 The default value is B<AES-256-CTR>.
449
450 =item B<digest>
451
452 This specifies what digest the B<HASH-DRBG> or B<HMAC-DRBG> random bit
453 generators will use.  Other random bit generators ignore this name.
454
455 =item B<properties>
456
457 This sets the property query used when fetching the random bit generator and
458 any underlying algorithms.
459
460 =item B<seed>
461
462 This sets the randomness source that should be used.  By default B<SEED-SRC>
463 will be used outside of the FIPS provider.  The FIPS provider uses call backs
464 to access the same randomness sources from outside the validated boundary.
465
466 =item B<seed_properties>
467
468 This sets the property query used when fetching the randomness source.
469
470 =back
471
472 =head1 EXAMPLES
473
474 This example shows how to use quoting and escaping.
475
476  # This is the default section.
477  HOME = /temp
478  configdir = $ENV::HOME/config
479
480  [ section_one ]
481  # Quotes permit leading and trailing whitespace
482  any = " any variable name "
483  other = A string that can \
484  cover several lines \
485  by including \\ characters
486  message = Hello World\n
487
488  [ section_two ]
489  greeting = $section_one::message
490
491 This example shows how to expand environment variables safely.
492 In this example, the variable B<tempfile> is intended to refer
493 to a temporary file, and the environment variable B<TEMP> or
494 B<TMP>, if present, specify the directory where the file
495 should be put.
496 Since the default section is checked if a variable does not
497 exist, it is possible to set B<TMP> to default to F</tmp>, and
498 B<TEMP> to default to B<TMP>.
499
500  # These two lines must be in the default section.
501  TMP = /tmp
502  TEMP = $ENV::TMP
503
504  # This can be used anywhere
505  tmpfile = ${ENV::TEMP}/tmp.filename
506
507 This example shows how to enforce FIPS mode for the application
508 F<sample>.
509
510  sample = fips_config
511
512  [fips_config]
513  alg_section = evp_properties
514
515  [evp_properties]
516  default_properties = "fips=yes"
517
518 =head1 ENVIRONMENT
519
520 =over 4
521
522 =item B<OPENSSL_CONF>
523
524 The path to the config file, or the empty string for none.
525 Ignored in set-user-ID and set-group-ID programs.
526
527 =item B<OPENSSL_ENGINES>
528
529 The path to the engines directory.
530 Ignored in set-user-ID and set-group-ID programs.
531
532 =item B<OPENSSL_MODULES>
533
534 The path to the directory with OpenSSL modules, such as providers.
535 Ignored in set-user-ID and set-group-ID programs.
536
537 =item B<OPENSSL_CONF_INCLUDE>
538
539 The optional path to prepend to all B<.include> paths.
540
541 =back
542
543 =head1 BUGS
544
545 There is no way to include characters using the octal B<\nnn> form. Strings
546 are all null terminated so nulls cannot form part of the value.
547
548 The escaping isn't quite right: if you want to use sequences like B<\n>
549 you can't use any quote escaping on the same line.
550
551 The limit that only one directory can be opened and read at a time
552 can be considered a bug and should be fixed.
553
554 =head1 HISTORY
555
556 An undocumented API, NCONF_WIN32(), used a slightly different set
557 of parsing rules there were intended to be tailored to
558 the Microsoft Windows platform.
559 Specifically, the backslash character was not an escape character and
560 could be used in pathnames, only the double-quote character was recognized,
561 and comments began with a semi-colon.
562 This function was deprecated in OpenSSL 3.0; applications with
563 configuration files using that syntax will have to be modified.
564
565 =head1 SEE ALSO
566
567 L<openssl-x509(1)>, L<openssl-req(1)>, L<openssl-ca(1)>,
568 L<openssl-fipsinstall(1)>,
569 L<ASN1_generate_nconf(3)>,
570 L<EVP_set_default_properties(3)>,
571 L<CONF_modules_load(3)>,
572 L<CONF_modules_load_file(3)>,
573 L<fips_config(5)>, and
574 L<x509v3_config(5)>.
575
576 =head1 COPYRIGHT
577
578 Copyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved.
579
580 Licensed under the Apache License 2.0 (the "License").  You may not use
581 this file except in compliance with the License.  You can obtain a copy
582 in the file LICENSE in the source distribution or at
583 L<https://www.openssl.org/source/license.html>.
584
585 =cut