1FIPS_MODULE(7ossl)                  OpenSSL                 FIPS_MODULE(7ossl)
2
3
4

NAME

6       fips_module - OpenSSL fips module guide
7

SYNOPSIS

9       See the individual manual pages for details.
10

DESCRIPTION

12       This guide details different ways that OpenSSL can be used in
13       conjunction with the FIPS module. Which is the correct approach to use
14       will depend on your own specific circumstances and what you are
15       attempting to achieve.
16
17       Note that the old functions FIPS_mode() and FIPS_mode_set() are no
18       longer present so you must remove them from your application if you use
19       them.
20
21       Applications written to use the OpenSSL 3.0 FIPS module should not use
22       any legacy APIs or features that avoid the FIPS module. Specifically
23       this includes:
24
25       •   Low level cryptographic APIs (use the high level APIs, such as EVP,
26           instead)
27
28       •   Engines
29
30       •   Any functions that create or modify custom "METHODS" (for example
31           EVP_MD_meth_new(), EVP_CIPHER_meth_new(), EVP_PKEY_meth_new(),
32           RSA_meth_new(), EC_KEY_METHOD_new(), etc.)
33
34       All of the above APIs are deprecated in OpenSSL 3.0 - so a simple rule
35       is to avoid using all deprecated functions. See migration_guide(7) for
36       a list of deprecated functions.
37
38   Making all applications use the FIPS module by default
39       One simple approach is to cause all applications that are using OpenSSL
40       to only use the FIPS module for cryptographic algorithms by default.
41
42       This approach can be done purely via configuration. As long as
43       applications are built and linked against OpenSSL 3.0 and do not
44       override the loading of the default config file or its settings then
45       they can automatically start using the FIPS module without the need for
46       any further code changes.
47
48       To do this the default OpenSSL config file will have to be modified.
49       The location of this config file will depend on the platform, and any
50       options that were given during the build process. You can check the
51       location of the config file by running this command:
52
53           $ openssl version -d
54           OPENSSLDIR: "/usr/local/ssl"
55
56       Caution: Many Operating Systems install OpenSSL by default. It is a
57       common error to not have the correct version of OpenSSL in your $PATH.
58       Check that you are running an OpenSSL 3.0 version like this:
59
60           $ openssl version -v
61           OpenSSL 3.0.0-dev xx XXX xxxx (Library: OpenSSL 3.0.0-dev xx XXX xxxx)
62
63       The OPENSSLDIR value above gives the directory name for where the
64       default config file is stored. So in this case the default config file
65       will be called /usr/local/ssl/openssl.cnf.
66
67       Edit the config file to add the following lines near the beginning:
68
69           config_diagnostics = 1
70           openssl_conf = openssl_init
71
72           .include /usr/local/ssl/fipsmodule.cnf
73
74           [openssl_init]
75           providers = provider_sect
76
77           [provider_sect]
78           fips = fips_sect
79           base = base_sect
80
81           [base_sect]
82           activate = 1
83
84       Obviously the include file location above should match the path and
85       name of the FIPS module config file that you installed earlier.  See
86       <https://github.com/openssl/openssl/blob/master/README-FIPS.md>.
87
88       For FIPS usage, it is recommened that the config_diagnostics option is
89       enabled to prevent accidental use of non-FIPS validated algorithms via
90       broken or mistaken configuration.  See config(5).
91
92       Any applications that use OpenSSL 3.0 and are started after these
93       changes are made will start using only the FIPS module unless those
94       applications take explicit steps to avoid this default behaviour. Note
95       that this configuration also activates the "base" provider. The base
96       provider does not include any cryptographic algorithms (and therefore
97       does not impact the validation status of any cryptographic operations),
98       but does include other supporting algorithms that may be required. It
99       is designed to be used in conjunction with the FIPS module.
100
101       This approach has the primary advantage that it is simple, and no code
102       changes are required in applications in order to benefit from the FIPS
103       module. There are some disadvantages to this approach:
104
105       •   You may not want all applications to use the FIPS module.
106
107           It may be the case that some applications should and some should
108           not use the FIPS module.
109
110       •   If applications take explicit steps to not load the default config
111           file or set different settings.
112
113           This method will not work for these cases.
114
115       •   The algorithms available in the FIPS module are a subset of the
116           algorithms that are available in the default OpenSSL Provider.
117
118           If any applications attempt to use any algorithms that are not
119           present, then they will fail.
120
121       •   Usage of certain deprecated APIs avoids the use of the FIPS module.
122
123           If any applications use those APIs then the FIPS module will not be
124           used.
125
126   Selectively making applications use the FIPS module by default
127       A variation on the above approach is to do the same thing on an
128       individual application basis. The default OpenSSL config file depends
129       on the compiled in value for OPENSSLDIR as described in the section
130       above. However it is also possible to override the config file to be
131       used via the OPENSSL_CONF environment variable. For example the
132       following, on Unix, will cause the application to be executed with a
133       non-standard config file location:
134
135           $ OPENSSL_CONF=/my/nondefault/openssl.cnf myapplication
136
137       Using this mechanism you can control which config file is loaded (and
138       hence whether the FIPS module is loaded) on an application by
139       application basis.
140
141       This removes the disadvantage listed above that you may not want all
142       applications to use the FIPS module. All the other advantages and
143       disadvantages still apply.
144
145   Programmatically loading the FIPS module (default library context)
146       Applications may choose to load the FIPS provider explicitly rather
147       than relying on config to do this. The config file is still necessary
148       in order to hold the FIPS module config data (such as its self test
149       status and integrity data). But in this case we do not automatically
150       activate the FIPS provider via that config file.
151
152       To do things this way configure as per "Making all applications use the
153       FIPS module by default" above, but edit the fipsmodule.cnf file to
154       remove or comment out the line which says "activate = 1" (note that
155       setting this value to 0 is not sufficient).  This means all the
156       required config information will be available to load the FIPS module,
157       but it is not automatically loaded when the application starts. The
158       FIPS provider can then be loaded programmatically like this:
159
160           #include <openssl/provider.h>
161
162           int main(void)
163           {
164               OSSL_PROVIDER *fips;
165               OSSL_PROVIDER *base;
166
167               fips = OSSL_PROVIDER_load(NULL, "fips");
168               if (fips == NULL) {
169                   printf("Failed to load FIPS provider\n");
170                   exit(EXIT_FAILURE);
171               }
172               base = OSSL_PROVIDER_load(NULL, "base");
173               if (base == NULL) {
174                   OSSL_PROVIDER_unload(fips);
175                   printf("Failed to load base provider\n");
176                   exit(EXIT_FAILURE);
177               }
178
179               /* Rest of application */
180
181               OSSL_PROVIDER_unload(base);
182               OSSL_PROVIDER_unload(fips);
183               exit(EXIT_SUCCESS);
184           }
185
186       Note that this should be one of the first things that you do in your
187       application. If any OpenSSL functions get called that require the use
188       of cryptographic functions before this occurs then, if no provider has
189       yet been loaded, then the default provider will be automatically
190       loaded. If you then later explicitly load the FIPS provider then you
191       will have both the FIPS and the default provider loaded at the same
192       time. It is undefined which implementation of an algorithm will be used
193       if multiple implementations are available and you have not explicitly
194       specified via a property query (see below) which one should be used.
195
196       Also note that in this example we have additionally loaded the "base"
197       provider.  This loads a sub-set of algorithms that are also available
198       in the default provider - specifically non cryptographic ones which may
199       be used in conjunction with the FIPS provider. For example this
200       contains algorithms for encoding and decoding keys. If you decide not
201       to load the default provider then you will usually want to load the
202       base provider instead.
203
204       In this example we are using the "default" library context. OpenSSL
205       functions operate within the scope of a library context. If no library
206       context is explicitly specified then the default library context is
207       used. For further details about library contexts see the
208       OSSL_LIB_CTX(3) man page.
209
210   Loading the FIPS module at the same time as other providers
211       It is possible to have the FIPS provider and other providers (such as
212       the default provider) all loaded at the same time into the same library
213       context. You can use a property query string during algorithm fetches
214       to specify which implementation you would like to use.
215
216       For example to fetch an implementation of SHA256 which conforms to FIPS
217       standards you can specify the property query "fips=yes" like this:
218
219           EVP_MD *sha256;
220
221           sha256 = EVP_MD_fetch(NULL, "SHA2-256", "fips=yes");
222
223       If no property query is specified, or more than one implementation
224       matches the property query then it is undefined which implementation of
225       a particular algorithm will be returned.
226
227       This example shows an explicit request for an implementation of SHA256
228       from the default provider:
229
230           EVP_MD *sha256;
231
232           sha256 = EVP_MD_fetch(NULL, "SHA2-256", "provider=default");
233
234       It is also possible to set a default property query string. The
235       following example sets the default property query of "fips=yes" for all
236       fetches within the default library context:
237
238           EVP_set_default_properties(NULL, "fips=yes");
239
240       If a fetch function has both an explicit property query specified, and
241       a default property query is defined then the two queries are merged
242       together and both apply. The local property query overrides the default
243       properties if the same property name is specified in both.
244
245       There are two important built-in properties that you should be aware
246       of:
247
248       The "provider" property enables you to specify which provider you want
249       an implementation to be fetched from, e.g. "provider=default" or
250       "provider=fips".  All algorithms implemented in a provider have this
251       property set on them.
252
253       There is also the "fips" property. All FIPS algorithms match against
254       the property query "fips=yes". There are also some non-cryptographic
255       algorithms available in the default and base providers that also have
256       the "fips=yes" property defined for them. These are the encoder and
257       decoder algorithms that can (for example) be used to write out a key
258       generated in the FIPS provider to a file. The encoder and decoder
259       algorithms are not in the FIPS module itself but are allowed to be used
260       in conjunction with the FIPS algorithms.
261
262       It is possible to specify default properties within a config file. For
263       example the following config file automatically loads the default and
264       FIPS providers and sets the default property value to be "fips=yes".
265       Note that this config file does not load the "base" provider. All
266       supporting algorithms that are in "base" are also in "default", so it
267       is unnecessary in this case:
268
269           config_diagnostics = 1
270           openssl_conf = openssl_init
271
272           .include /usr/local/ssl/fipsmodule.cnf
273
274           [openssl_init]
275           providers = provider_sect
276           alg_section = algorithm_sect
277
278           [provider_sect]
279           fips = fips_sect
280           default = default_sect
281
282           [default_sect]
283           activate = 1
284
285           [algorithm_sect]
286           default_properties = fips=yes
287
288   Programmatically loading the FIPS module (nondefault library context)
289       In addition to using properties to separate usage of the FIPS module
290       from other usages this can also be achieved using library contexts. In
291       this example we create two library contexts. In one we assume the
292       existence of a config file called openssl-fips.cnf that automatically
293       loads and configures the FIPS and base providers. The other library
294       context will just use the default provider.
295
296           OSSL_LIB_CTX *fips_libctx, *nonfips_libctx;
297           OSSL_PROVIDER *defctxnull = NULL;
298           EVP_MD *fipssha256 = NULL, *nonfipssha256 = NULL;
299           int ret = 1;
300
301           /*
302            * Create two nondefault library contexts. One for fips usage and
303            * one for non-fips usage
304            */
305           fips_libctx = OSSL_LIB_CTX_new();
306           nonfips_libctx = OSSL_LIB_CTX_new();
307           if (fips_libctx == NULL || nonfips_libctx == NULL)
308               goto err;
309
310           /* Prevent anything from using the default library context */
311           defctxnull = OSSL_PROVIDER_load(NULL, "null");
312
313           /*
314            * Load config file for the FIPS library context. We assume that
315            * this config file will automatically activate the FIPS and base
316            * providers so we don't need to explicitly load them here.
317            */
318           if (!OSSL_LIB_CTX_load_config(fips_libctx, "openssl-fips.cnf"))
319               goto err;
320
321           /*
322            * We don't need to do anything special to load the default
323            * provider into nonfips_libctx. This happens automatically if no
324            * other providers are loaded.
325            * Because we don't call OSSL_LIB_CTX_load_config() explicitly for
326            * nonfips_libctx it will just use the default config file.
327            */
328
329           /* As an example get some digests */
330
331           /* Get a FIPS validated digest */
332           fipssha256 = EVP_MD_fetch(fips_libctx, "SHA2-256", NULL);
333           if (fipssha256 == NULL)
334               goto err;
335
336           /* Get a non-FIPS validated digest */
337           nonfipssha256 = EVP_MD_fetch(nonfips_libctx, "SHA2-256", NULL);
338           if (nonfipssha256 == NULL)
339               goto err;
340
341           /* Use the digests */
342
343           printf("Success\n");
344           ret = 0;
345
346           err:
347           EVP_MD_free(fipssha256);
348           EVP_MD_free(nonfipssha256);
349           OSSL_LIB_CTX_free(fips_libctx);
350           OSSL_LIB_CTX_free(nonfips_libctx);
351           OSSL_PROVIDER_unload(defctxnull);
352
353           return ret;
354
355       Note that we have made use of the special "null" provider here which we
356       load into the default library context. We could have chosen to use the
357       default library context for FIPS usage, and just create one additional
358       library context for other usages - or vice versa. However if code has
359       not been converted to use library contexts then the default library
360       context will be automatically used.  This could be the case for your
361       own existing applications as well as certain parts of OpenSSL itself.
362       Not all parts of OpenSSL are library context aware. If this happens
363       then you could "accidentally" use the wrong library context for a
364       particular operation. To be sure this doesn't happen you can load the
365       "null" provider into the default library context. Because a provider
366       has been explicitly loaded, the default provider will not automatically
367       load. This means code using the default context by accident will fail
368       because no algorithms will be available.
369
370       See "Library Context" in migration_guide(7) for additional information
371       about the Library Context.
372
373   Using Encoders and Decoders with the FIPS module
374       Encoders and decoders are used to read and write keys or parameters
375       from or to some external format (for example a PEM file). If your
376       application generates keys or parameters that then need to be written
377       into PEM or DER format then it is likely that you will need to use an
378       encoder to do this. Similarly you need a decoder to read previously
379       saved keys and parameters. In most cases this will be invisible to you
380       if you are using APIs that existed in OpenSSL 1.1.1 or earlier such as
381       i2d_PrivateKey(3). However the appropriate encoder/decoder will need to
382       be available in the library context associated with the key or
383       parameter object. The built-in OpenSSL encoders and decoders are
384       implemented in both the default and base providers and are not in the
385       FIPS module boundary. However since they are not cryptographic
386       algorithms themselves it is still possible to use them in conjunction
387       with the FIPS module, and therefore these encoders/decoders have the
388       "fips=yes" property against them.  You should ensure that either the
389       default or base provider is loaded into the library context in this
390       case.
391
392   Using the FIPS module in SSL/TLS
393       Writing an application that uses libssl in conjunction with the FIPS
394       module is much the same as writing a normal libssl application. If you
395       are using global properties and the default library context to specify
396       usage of FIPS validated algorithms then this will happen automatically
397       for all cryptographic algorithms in libssl. If you are using a
398       nondefault library context to load the FIPS provider then you can
399       supply this to libssl using the function SSL_CTX_new_ex(3). This works
400       as a drop in replacement for the function SSL_CTX_new(3) except it
401       provides you with the capability to specify the library context to be
402       used. You can also use the same function to specify libssl specific
403       properties to use.
404
405       In this first example we create two SSL_CTX objects using two different
406       library contexts.
407
408           /*
409            * We assume that a nondefault library context with the FIPS
410            * provider loaded has been created called fips_libctx.
411            */
412           SSL_CTX *fips_ssl_ctx = SSL_CTX_new_ex(fips_libctx, NULL, TLS_method());
413           /*
414            * We assume that a nondefault library context with the default
415            * provider loaded has been created called non_fips_libctx.
416            */
417           SSL_CTX *non_fips_ssl_ctx = SSL_CTX_new_ex(non_fips_libctx, NULL,
418                                                      TLS_method());
419
420       In this second example we create two SSL_CTX objects using different
421       properties to specify FIPS usage:
422
423           /*
424            * The "fips=yes" property includes all FIPS approved algorithms
425            * as well as encoders from the default provider that are allowed
426            * to be used. The NULL below indicates that we are using the
427            * default library context.
428            */
429           SSL_CTX *fips_ssl_ctx = SSL_CTX_new_ex(NULL, "fips=yes", TLS_method());
430           /*
431            * The "provider!=fips" property allows algorithms from any
432            * provider except the FIPS provider
433            */
434           SSL_CTX *non_fips_ssl_ctx = SSL_CTX_new_ex(NULL, "provider!=fips",
435                                                      TLS_method());
436
437   Confirming that an algorithm is being provided by the FIPS module
438       A chain of links needs to be followed to go from an algorithm instance
439       to the provider that implements it. The process is similar for all
440       algorithms. Here the example of a digest is used.
441
442       To go from an EVP_MD_CTX to an EVP_MD, use EVP_MD_CTX_md(3) .  To go
443       from the EVP_MD to its OSSL_PROVIDER, use EVP_MD_get0_provider(3).  To
444       extract the name from the OSSL_PROVIDER, use
445       OSSL_PROVIDER_get0_name(3).
446

SEE ALSO

448       migration_guide(7), crypto(7), fips_config(5)
449
451       Copyright 2021-2022 The OpenSSL Project Authors. All Rights Reserved.
452
453       Licensed under the Apache License 2.0 (the "License").  You may not use
454       this file except in compliance with the License.  You can obtain a copy
455       in the file LICENSE in the source distribution or at
456       <https://www.openssl.org/source/license.html>.
457
458
459
4603.0.5                             2022-07-05                FIPS_MODULE(7ossl)
Impressum