config.pod 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. =pod
  2. =head1 NAME
  3. config - OpenSSL CONF library configuration files
  4. =head1 DESCRIPTION
  5. The OpenSSL CONF library can be used to read configuration files.
  6. It is used for the OpenSSL master configuration file B<openssl.cnf>
  7. and in a few other places like B<SPKAC> files and certificate extension
  8. files for the B<x509> utility. OpenSSL applications can also use the
  9. CONF library for their own purposes.
  10. A configuration file is divided into a number of sections. Each section
  11. starts with a line B<[ section_name ]> and ends when a new section is
  12. started or end of file is reached. A section name can consist of
  13. alphanumeric characters and underscores.
  14. The first section of a configuration file is special and is referred
  15. to as the B<default> section. This section is usually unnamed and spans from the
  16. start of file until the first named section. When a name is being looked up
  17. it is first looked up in a named section (if any) and then the
  18. default section.
  19. The environment is mapped onto a section called B<ENV>.
  20. Comments can be included by preceding them with the B<#> character
  21. Other files can be included using the B<.include> directive followed
  22. by a path. If the path points to a directory all files with
  23. names ending with B<.cnf> or B<.conf> are included from the directory.
  24. Recursive inclusion of directories from files in such directory is not
  25. supported. That means the files in the included directory can also contain
  26. B<.include> directives but only inclusion of regular files is supported
  27. there. The inclusion of directories is not supported on systems without
  28. POSIX IO support.
  29. It is strongly recommended to use absolute paths with the B<.include>
  30. directive. Relative paths are evaluated based on the application current
  31. working directory so unless the configuration file containing the
  32. B<.include> directive is application specific the inclusion will not
  33. work as expected.
  34. There can be optional B<=> character and whitespace characters between
  35. B<.include> directive and the path which can be useful in cases the
  36. configuration file needs to be loaded by old OpenSSL versions which do
  37. not support the B<.include> syntax. They would bail out with error
  38. if the B<=> character is not present but with it they just ignore
  39. the include.
  40. Each section in a configuration file consists of a number of name and
  41. value pairs of the form B<name=value>
  42. The B<name> string can contain any alphanumeric characters as well as
  43. a few punctuation symbols such as B<.> B<,> B<;> and B<_>.
  44. The B<value> string consists of the string following the B<=> character
  45. until end of line with any leading and trailing white space removed.
  46. The value string undergoes variable expansion. This can be done by
  47. including the form B<$var> or B<${var}>: this will substitute the value
  48. of the named variable in the current section. It is also possible to
  49. substitute a value from another section using the syntax B<$section::name>
  50. or B<${section::name}>. By using the form B<$ENV::name> environment
  51. variables can be substituted. It is also possible to assign values to
  52. environment variables by using the name B<ENV::name>, this will work
  53. if the program looks up environment variables using the B<CONF> library
  54. instead of calling getenv() directly. The value string must not exceed 64k in
  55. length after variable expansion. Otherwise an error will occur.
  56. It is possible to escape certain characters by using any kind of quote
  57. or the B<\> character. By making the last character of a line a B<\>
  58. a B<value> string can be spread across multiple lines. In addition
  59. the sequences B<\n>, B<\r>, B<\b> and B<\t> are recognized.
  60. All expansion and escape rules as described above that apply to B<value>
  61. also apply to the path of the B<.include> directive.
  62. =head1 OPENSSL LIBRARY CONFIGURATION
  63. Applications can automatically configure certain
  64. aspects of OpenSSL using the master OpenSSL configuration file, or optionally
  65. an alternative configuration file. The B<openssl> utility includes this
  66. functionality: any sub command uses the master OpenSSL configuration file
  67. unless an option is used in the sub command to use an alternative configuration
  68. file.
  69. To enable library configuration the default section needs to contain an
  70. appropriate line which points to the main configuration section. The default
  71. name is B<openssl_conf> which is used by the B<openssl> utility. Other
  72. applications may use an alternative name such as B<myapplication_conf>.
  73. All library configuration lines appear in the default section at the start
  74. of the configuration file.
  75. The configuration section should consist of a set of name value pairs which
  76. contain specific module configuration information. The B<name> represents
  77. the name of the I<configuration module>. The meaning of the B<value> is
  78. module specific: it may, for example, represent a further configuration
  79. section containing configuration module specific information. E.g.:
  80. # This must be in the default section
  81. openssl_conf = openssl_init
  82. [openssl_init]
  83. oid_section = new_oids
  84. engines = engine_section
  85. [new_oids]
  86. ... new oids here ...
  87. [engine_section]
  88. ... engine stuff here ...
  89. The features of each configuration module are described below.
  90. =head2 ASN1 Object Configuration Module
  91. This module has the name B<oid_section>. The value of this variable points
  92. to a section containing name value pairs of OIDs: the name is the OID short
  93. and long name, the value is the numerical form of the OID. Although some of
  94. the B<openssl> utility sub commands already have their own ASN1 OBJECT section
  95. functionality not all do. By using the ASN1 OBJECT configuration module
  96. B<all> the B<openssl> utility sub commands can see the new objects as well
  97. as any compliant applications. For example:
  98. [new_oids]
  99. some_new_oid = 1.2.3.4
  100. some_other_oid = 1.2.3.5
  101. It is also possible to set the value to the long name followed
  102. by a comma and the numerical OID form. For example:
  103. shortName = some object long name, 1.2.3.4
  104. =head2 Engine Configuration Module
  105. This ENGINE configuration module has the name B<engines>. The value of this
  106. variable points to a section containing further ENGINE configuration
  107. information.
  108. The section pointed to by B<engines> is a table of engine names (though see
  109. B<engine_id> below) and further sections containing configuration information
  110. specific to each ENGINE.
  111. Each ENGINE specific section is used to set default algorithms, load
  112. dynamic, perform initialization and send ctrls. The actual operation performed
  113. depends on the I<command> name which is the name of the name value pair. The
  114. currently supported commands are listed below.
  115. For example:
  116. [engine_section]
  117. # Configure ENGINE named "foo"
  118. foo = foo_section
  119. # Configure ENGINE named "bar"
  120. bar = bar_section
  121. [foo_section]
  122. ... foo ENGINE specific commands ...
  123. [bar_section]
  124. ... "bar" ENGINE specific commands ...
  125. The command B<engine_id> is used to give the ENGINE name. If used this
  126. command must be first. For example:
  127. [engine_section]
  128. # This would normally handle an ENGINE named "foo"
  129. foo = foo_section
  130. [foo_section]
  131. # Override default name and use "myfoo" instead.
  132. engine_id = myfoo
  133. The command B<dynamic_path> loads and adds an ENGINE from the given path. It
  134. is equivalent to sending the ctrls B<SO_PATH> with the path argument followed
  135. by B<LIST_ADD> with value 2 and B<LOAD> to the dynamic ENGINE. If this is
  136. not the required behaviour then alternative ctrls can be sent directly
  137. to the dynamic ENGINE using ctrl commands.
  138. The command B<init> determines whether to initialize the ENGINE. If the value
  139. is B<0> the ENGINE will not be initialized, if B<1> and attempt it made to
  140. initialized the ENGINE immediately. If the B<init> command is not present
  141. then an attempt will be made to initialize the ENGINE after all commands in
  142. its section have been processed.
  143. The command B<default_algorithms> sets the default algorithms an ENGINE will
  144. supply using the functions ENGINE_set_default_string().
  145. If the name matches none of the above command names it is assumed to be a
  146. ctrl command which is sent to the ENGINE. The value of the command is the
  147. argument to the ctrl command. If the value is the string B<EMPTY> then no
  148. value is sent to the command.
  149. For example:
  150. [engine_section]
  151. # Configure ENGINE named "foo"
  152. foo = foo_section
  153. [foo_section]
  154. # Load engine from DSO
  155. dynamic_path = /some/path/fooengine.so
  156. # A foo specific ctrl.
  157. some_ctrl = some_value
  158. # Another ctrl that doesn't take a value.
  159. other_ctrl = EMPTY
  160. # Supply all default algorithms
  161. default_algorithms = ALL
  162. =head2 EVP Configuration Module
  163. This modules has the name B<alg_section> which points to a section containing
  164. algorithm commands.
  165. Currently the only algorithm command supported is B<fips_mode> whose
  166. value can only be the boolean string B<off>. If B<fips_mode> is set to B<on>,
  167. an error occurs as this library version is not FIPS capable.
  168. =head2 SSL Configuration Module
  169. This module has the name B<ssl_conf> which points to a section containing
  170. SSL configurations.
  171. Each line in the SSL configuration section contains the name of the
  172. configuration and the section containing it.
  173. Each configuration section consists of command value pairs for B<SSL_CONF>.
  174. Each pair will be passed to a B<SSL_CTX> or B<SSL> structure if it calls
  175. SSL_CTX_config() or SSL_config() with the appropriate configuration name.
  176. Note: any characters before an initial dot in the configuration section are
  177. ignored so the same command can be used multiple times.
  178. For example:
  179. ssl_conf = ssl_sect
  180. [ssl_sect]
  181. server = server_section
  182. [server_section]
  183. RSA.Certificate = server-rsa.pem
  184. ECDSA.Certificate = server-ecdsa.pem
  185. Ciphers = ALL:!RC4
  186. The system default configuration with name B<system_default> if present will
  187. be applied during any creation of the B<SSL_CTX> structure.
  188. Example of a configuration with the system default:
  189. ssl_conf = ssl_sect
  190. [ssl_sect]
  191. system_default = system_default_sect
  192. [system_default_sect]
  193. MinProtocol = TLSv1.2
  194. MinProtocol = DTLSv1.2
  195. =head1 NOTES
  196. If a configuration file attempts to expand a variable that doesn't exist
  197. then an error is flagged and the file will not load. This can happen
  198. if an attempt is made to expand an environment variable that doesn't
  199. exist. For example in a previous version of OpenSSL the default OpenSSL
  200. master configuration file used the value of B<HOME> which may not be
  201. defined on non Unix systems and would cause an error.
  202. This can be worked around by including a B<default> section to provide
  203. a default value: then if the environment lookup fails the default value
  204. will be used instead. For this to work properly the default value must
  205. be defined earlier in the configuration file than the expansion. See
  206. the B<EXAMPLES> section for an example of how to do this.
  207. If the same variable exists in the same section then all but the last
  208. value will be silently ignored. In certain circumstances such as with
  209. DNs the same field may occur multiple times. This is usually worked
  210. around by ignoring any characters before an initial B<.> e.g.
  211. 1.OU="My first OU"
  212. 2.OU="My Second OU"
  213. =head1 EXAMPLES
  214. Here is a sample configuration file using some of the features
  215. mentioned above.
  216. # This is the default section.
  217. HOME=/temp
  218. RANDFILE= ${ENV::HOME}/.rnd
  219. configdir=$ENV::HOME/config
  220. [ section_one ]
  221. # We are now in section one.
  222. # Quotes permit leading and trailing whitespace
  223. any = " any variable name "
  224. other = A string that can \
  225. cover several lines \
  226. by including \\ characters
  227. message = Hello World\n
  228. [ section_two ]
  229. greeting = $section_one::message
  230. This next example shows how to expand environment variables safely.
  231. Suppose you want a variable called B<tmpfile> to refer to a
  232. temporary filename. The directory it is placed in can determined by
  233. the B<TEMP> or B<TMP> environment variables but they may not be
  234. set to any value at all. If you just include the environment variable
  235. names and the variable doesn't exist then this will cause an error when
  236. an attempt is made to load the configuration file. By making use of the
  237. default section both values can be looked up with B<TEMP> taking
  238. priority and B</tmp> used if neither is defined:
  239. TMP=/tmp
  240. # The above value is used if TMP isn't in the environment
  241. TEMP=$ENV::TMP
  242. # The above value is used if TEMP isn't in the environment
  243. tmpfile=${ENV::TEMP}/tmp.filename
  244. Simple OpenSSL library configuration example to enter FIPS mode:
  245. # Default appname: should match "appname" parameter (if any)
  246. # supplied to CONF_modules_load_file et al.
  247. openssl_conf = openssl_conf_section
  248. [openssl_conf_section]
  249. # Configuration module list
  250. alg_section = evp_sect
  251. [evp_sect]
  252. # Set to "yes" to enter FIPS mode if supported
  253. fips_mode = yes
  254. Note: in the above example you will get an error in non FIPS capable versions
  255. of OpenSSL.
  256. Simple OpenSSL library configuration to make TLS 1.2 and DTLS 1.2 the
  257. system-default minimum TLS and DTLS versions, respectively:
  258. # Toplevel section for openssl (including libssl)
  259. openssl_conf = default_conf_section
  260. [default_conf_section]
  261. # We only specify configuration for the "ssl module"
  262. ssl_conf = ssl_section
  263. [ssl_section]
  264. system_default = system_default_section
  265. [system_default_section]
  266. MinProtocol = TLSv1.2
  267. MinProtocol = DTLSv1.2
  268. The minimum TLS protocol is applied to B<SSL_CTX> objects that are TLS-based,
  269. and the minimum DTLS protocol to those are DTLS-based.
  270. The same applies also to maximum versions set with B<MaxProtocol>.
  271. More complex OpenSSL library configuration. Add OID and don't enter FIPS mode:
  272. # Default appname: should match "appname" parameter (if any)
  273. # supplied to CONF_modules_load_file et al.
  274. openssl_conf = openssl_conf_section
  275. [openssl_conf_section]
  276. # Configuration module list
  277. alg_section = evp_sect
  278. oid_section = new_oids
  279. [evp_sect]
  280. # This will have no effect as FIPS mode is off by default.
  281. # Set to "yes" to enter FIPS mode, if supported
  282. fips_mode = no
  283. [new_oids]
  284. # New OID, just short name
  285. newoid1 = 1.2.3.4.1
  286. # New OID shortname and long name
  287. newoid2 = New OID 2 long name, 1.2.3.4.2
  288. The above examples can be used with any application supporting library
  289. configuration if "openssl_conf" is modified to match the appropriate "appname".
  290. For example if the second sample file above is saved to "example.cnf" then
  291. the command line:
  292. OPENSSL_CONF=example.cnf openssl asn1parse -genstr OID:1.2.3.4.1
  293. will output:
  294. 0:d=0 hl=2 l= 4 prim: OBJECT :newoid1
  295. showing that the OID "newoid1" has been added as "1.2.3.4.1".
  296. =head1 ENVIRONMENT
  297. =over 4
  298. =item B<OPENSSL_CONF>
  299. The path to the config file.
  300. Ignored in set-user-ID and set-group-ID programs.
  301. =item B<OPENSSL_ENGINES>
  302. The path to the engines directory.
  303. Ignored in set-user-ID and set-group-ID programs.
  304. =back
  305. =head1 BUGS
  306. Currently there is no way to include characters using the octal B<\nnn>
  307. form. Strings are all null terminated so nulls cannot form part of
  308. the value.
  309. The escaping isn't quite right: if you want to use sequences like B<\n>
  310. you can't use any quote escaping on the same line.
  311. Files are loaded in a single pass. This means that a variable expansion
  312. will only work if the variables referenced are defined earlier in the
  313. file.
  314. =head1 SEE ALSO
  315. L<x509(1)>, L<req(1)>, L<ca(1)>
  316. =head1 COPYRIGHT
  317. Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
  318. Licensed under the OpenSSL license (the "License"). You may not use
  319. this file except in compliance with the License. You can obtain a copy
  320. in the file LICENSE in the source distribution or at
  321. L<https://www.openssl.org/source/license.html>.
  322. =cut