Standard preamble:
========================================================================
..
.... Set up some character translations and predefined strings. \*(-- will
give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
double quote, and \*(R" will give a right double quote. \*(C+ will
give a nicer C++. Capital omega is used to do unbreakable dashes and
therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
nothing in troff, for use with C<>.
.tr \(*W- . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\}
Escape single quotes in literal strings from groff's Unicode transform.
If the F register is >0, we'll generate index entries on stderr for
titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
entries marked with X<> in POD. Of course, you'll have to process the
output yourself in some meaningful fashion.
Avoid warning from groff about undefined register 'F'.
.. .nr rF 0 . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] .\} . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents . \" corrections for vroff . \" for low resolution devices (crt and lpr) \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} ========================================================================
Title "FIPS_MODULE 7ossl"
way too many mistakes in technical documents.
For information related to installing the \s-1FIPS\s0 module see <https://github.com/openssl/openssl/blob/master/README-FIPS.md>.
Note that the old functions FIPS_mode() and FIPS_mode_set() are no longer present so you must remove them from your application if you use them.
Applications written to use the OpenSSL 3.0 \s-1FIPS\s0 module should not use any legacy APIs or features that avoid the \s-1FIPS\s0 module. Specifically this includes:
All of the above APIs are deprecated in OpenSSL 3.0 - so a simple rule is to avoid using all deprecated functions. See migration_guide\|(7) for a list of deprecated functions.
This approach can be done purely via configuration. As long as applications are built and linked against OpenSSL 3.0 and do not override the loading of the default config file or its settings then they can automatically start using the \s-1FIPS\s0 module without the need for any further code changes.
To do this the default OpenSSL config file will have to be modified. The location of this config file will depend on the platform, and any options that were given during the build process. You can check the location of the config file by running this command:
.Vb 2 $ openssl version -d OPENSSLDIR: "/etc/ssl" .Ve
Caution: Many Operating Systems install OpenSSL by default. It is a common error to not have the correct version of OpenSSL in your $PATH. Check that you are running an OpenSSL 3.0 version like this:
.Vb 2 $ openssl version -v OpenSSL 3.0.0-dev xx XXX xxxx (Library: OpenSSL 3.0.0-dev xx XXX xxxx) .Ve
The \s-1OPENSSLDIR\s0 value above gives the directory name for where the default config file is stored. So in this case the default config file will be called \fI/etc/ssl/openssl.cnf.
Edit the config file to add the following lines near the beginning:
.Vb 2 config_diagnostics = 1 openssl_conf = openssl_init \& .include /etc/ssl/fipsmodule.cnf \& [openssl_init] providers = provider_sect \& [provider_sect] fips = fips_sect base = base_sect \& [base_sect] activate = 1 .Ve
Obviously the include file location above should match the path and name of the \s-1FIPS\s0 module config file that you installed earlier. See <https://github.com/openssl/openssl/blob/master/README-FIPS.md>.
For \s-1FIPS\s0 usage, it is recommended that the config_diagnostics option is enabled to prevent accidental use of non-FIPS validated algorithms via broken or mistaken configuration. See config\|(5).
Any applications that use OpenSSL 3.0 and are started after these changes are made will start using only the \s-1FIPS\s0 module unless those applications take explicit steps to avoid this default behaviour. Note that this configuration also activates the \*(L"base\*(R" provider. The base provider does not include any cryptographic algorithms (and therefore does not impact the validation status of any cryptographic operations), but does include other supporting algorithms that may be required. It is designed to be used in conjunction with the \s-1FIPS\s0 module.
This approach has the primary advantage that it is simple, and no code changes are required in applications in order to benefit from the \s-1FIPS\s0 module. There are some disadvantages to this approach:
.Vb 1 $ OPENSSL_CONF=/my/nondefault/openssl.cnf myapplication .Ve
Using this mechanism you can control which config file is loaded (and hence whether the \s-1FIPS\s0 module is loaded) on an application by application basis.
This removes the disadvantage listed above that you may not want all applications to use the \s-1FIPS\s0 module. All the other advantages and disadvantages still apply.
To do things this way configure as per \*(L"Making all applications use the \s-1FIPS\s0 module by default\*(R" above, but edit the \fIfipsmodule.cnf file to remove or comment out the line which says \f(CW\*(C`activate = 1\*(C' (note that setting this value to 0 is not sufficient). This means all the required config information will be available to load the \s-1FIPS\s0 module, but it is not automatically loaded when the application starts. The \s-1FIPS\s0 provider can then be loaded programmatically like this:
.Vb 1 #include <openssl/provider.h> \& int main(void) { OSSL_PROVIDER *fips; OSSL_PROVIDER *base; \& fips = OSSL_PROVIDER_load(NULL, "fips"); if (fips == NULL) { printf("Failed to load FIPS provider\en"); exit(EXIT_FAILURE); } base = OSSL_PROVIDER_load(NULL, "base"); if (base == NULL) { OSSL_PROVIDER_unload(fips); printf("Failed to load base provider\en"); exit(EXIT_FAILURE); } \& /* Rest of application */ \& OSSL_PROVIDER_unload(base); OSSL_PROVIDER_unload(fips); exit(EXIT_SUCCESS); } .Ve
Note that this should be one of the first things that you do in your application. If any OpenSSL functions get called that require the use of cryptographic functions before this occurs then, if no provider has yet been loaded, then the default provider will be automatically loaded. If you then later explicitly load the \s-1FIPS\s0 provider then you will have both the \s-1FIPS\s0 and the default provider loaded at the same time. It is undefined which implementation of an algorithm will be used if multiple implementations are available and you have not explicitly specified via a property query (see below) which one should be used.
Also note that in this example we have additionally loaded the \*(L"base\*(R" provider. This loads a sub-set of algorithms that are also available in the default provider - specifically non cryptographic ones which may be used in conjunction with the \s-1FIPS\s0 provider. For example this contains algorithms for encoding and decoding keys. If you decide not to load the default provider then you will usually want to load the base provider instead.
In this example we are using the \*(L"default\*(R" library context. OpenSSL functions operate within the scope of a library context. If no library context is explicitly specified then the default library context is used. For further details about library contexts see the \s-1OSSL_LIB_CTX\s0\|(3) man page.
For example to fetch an implementation of \s-1SHA256\s0 which conforms to \s-1FIPS\s0 standards you can specify the property query \*(C`fips=yes\*(C' like this:
.Vb 1 EVP_MD *sha256; \& sha256 = EVP_MD_fetch(NULL, "SHA2-256", "fips=yes"); .Ve
If no property query is specified, or more than one implementation matches the property query then it is undefined which implementation of a particular algorithm will be returned.
This example shows an explicit request for an implementation of \s-1SHA256\s0 from the default provider:
.Vb 1 EVP_MD *sha256; \& sha256 = EVP_MD_fetch(NULL, "SHA2-256", "provider=default"); .Ve
It is also possible to set a default property query string. The following example sets the default property query of \*(C`fips=yes\*(C' for all fetches within the default library context:
.Vb 1 EVP_set_default_properties(NULL, "fips=yes"); .Ve
If a fetch function has both an explicit property query specified, and a default property query is defined then the two queries are merged together and both apply. The local property query overrides the default properties if the same property name is specified in both.
There are two important built-in properties that you should be aware of:
The \*(L"provider\*(R" property enables you to specify which provider you want an implementation to be fetched from, e.g. \*(C`provider=default\*(C' or \*(C`provider=fips\*(C'. All algorithms implemented in a provider have this property set on them.
There is also the \*(C`fips\*(C' property. All \s-1FIPS\s0 algorithms match against the property query \*(C`fips=yes\*(C'. There are also some non-cryptographic algorithms available in the default and base providers that also have the \*(C`fips=yes\*(C' property defined for them. These are the encoder and decoder algorithms that can (for example) be used to write out a key generated in the \s-1FIPS\s0 provider to a file. The encoder and decoder algorithms are not in the \s-1FIPS\s0 module itself but are allowed to be used in conjunction with the \s-1FIPS\s0 algorithms.
It is possible to specify default properties within a config file. For example the following config file automatically loads the default and \s-1FIPS\s0 providers and sets the default property value to be \*(C`fips=yes\*(C'. Note that this config file does not load the \*(L"base\*(R" provider. All supporting algorithms that are in \*(L"base\*(R" are also in \*(L"default\*(R", so it is unnecessary in this case:
.Vb 2 config_diagnostics = 1 openssl_conf = openssl_init \& .include /etc/ssl/fipsmodule.cnf \& [openssl_init] providers = provider_sect alg_section = algorithm_sect \& [provider_sect] fips = fips_sect default = default_sect \& [default_sect] activate = 1 \& [algorithm_sect] default_properties = fips=yes .Ve
.Vb 4 OSSL_LIB_CTX *fips_libctx, *nonfips_libctx; OSSL_PROVIDER *defctxnull = NULL; EVP_MD *fipssha256 = NULL, *nonfipssha256 = NULL; int ret = 1; \& /* * Create two nondefault library contexts. One for fips usage and * one for non-fips usage */ fips_libctx = OSSL_LIB_CTX_new(); nonfips_libctx = OSSL_LIB_CTX_new(); if (fips_libctx == NULL || nonfips_libctx == NULL) goto err; \& /* Prevent anything from using the default library context */ defctxnull = OSSL_PROVIDER_load(NULL, "null"); \& /* * Load config file for the FIPS library context. We assume that * this config file will automatically activate the FIPS and base * providers so we don\*(Aqt need to explicitly load them here. */ if (!OSSL_LIB_CTX_load_config(fips_libctx, "openssl-fips.cnf")) goto err; \& /* * We don\*(Aqt need to do anything special to load the default * provider into nonfips_libctx. This happens automatically if no * other providers are loaded. * Because we don\*(Aqt call OSSL_LIB_CTX_load_config() explicitly for * nonfips_libctx it will just use the default config file. */ \& /* As an example get some digests */ \& /* Get a FIPS validated digest */ fipssha256 = EVP_MD_fetch(fips_libctx, "SHA2-256", NULL); if (fipssha256 == NULL) goto err; \& /* Get a non-FIPS validated digest */ nonfipssha256 = EVP_MD_fetch(nonfips_libctx, "SHA2-256", NULL); if (nonfipssha256 == NULL) goto err; \& /* Use the digests */ \& printf("Success\en"); ret = 0; \& err: EVP_MD_free(fipssha256); EVP_MD_free(nonfipssha256); OSSL_LIB_CTX_free(fips_libctx); OSSL_LIB_CTX_free(nonfips_libctx); OSSL_PROVIDER_unload(defctxnull); \& return ret; .Ve
Note that we have made use of the special \*(L"null\*(R" provider here which we load into the default library context. We could have chosen to use the default library context for \s-1FIPS\s0 usage, and just create one additional library context for other usages - or vice versa. However if code has not been converted to use library contexts then the default library context will be automatically used. This could be the case for your own existing applications as well as certain parts of OpenSSL itself. Not all parts of OpenSSL are library context aware. If this happens then you could \*(L"accidentally\*(R" use the wrong library context for a particular operation. To be sure this doesn't happen you can load the \*(L"null\*(R" provider into the default library context. Because a provider has been explicitly loaded, the default provider will not automatically load. This means code using the default context by accident will fail because no algorithms will be available.
See \*(L"Library Context\*(R" in migration_guide\|(7) for additional information about the Library Context.
In this first example we create two \s-1SSL_CTX\s0 objects using two different library contexts.
.Vb 11 /* * We assume that a nondefault library context with the FIPS * provider loaded has been created called fips_libctx. */ SSL_CTX *fips_ssl_ctx = SSL_CTX_new_ex(fips_libctx, NULL, TLS_method()); /* * We assume that a nondefault library context with the default * provider loaded has been created called non_fips_libctx. */ SSL_CTX *non_fips_ssl_ctx = SSL_CTX_new_ex(non_fips_libctx, NULL, TLS_method()); .Ve
In this second example we create two \s-1SSL_CTX\s0 objects using different properties to specify \s-1FIPS\s0 usage:
.Vb 10 /* * The "fips=yes" property includes all FIPS approved algorithms * as well as encoders from the default provider that are allowed * to be used. The NULL below indicates that we are using the * default library context. */ SSL_CTX *fips_ssl_ctx = SSL_CTX_new_ex(NULL, "fips=yes", TLS_method()); /* * The "provider!=fips" property allows algorithms from any * provider except the FIPS provider */ SSL_CTX *non_fips_ssl_ctx = SSL_CTX_new_ex(NULL, "provider!=fips", TLS_method()); .Ve
To go from an \s-1EVP_MD_CTX\s0 to an \s-1EVP_MD\s0, use EVP_MD_CTX_md\|(3) . To go from the \s-1EVP_MD\s0 to its \s-1OSSL_PROVIDER\s0, use EVP_MD_get0_provider\|(3). To extract the name from the \s-1OSSL_PROVIDER\s0, use \fBOSSL_PROVIDER_get0_name\|(3).
Licensed under the Apache License 2.0 (the \*(L"License\*(R"). You may not use this file except in compliance with the License. You can obtain a copy in the file \s-1LICENSE\s0 in the source distribution or at <https://www.openssl.org/source/license.html>.