Turn on/off FIPS programmatically
Details
Hi
I am new to Node and testing out the FIPS provider in OpenSSL 3 and some of the APIs exposed in the crypto module: https://nodejs.org/docs/latest-v18.x/api/crypto.html
I am reading about setting up FIPS here: https://github.com/nodejs/node/blob/main/BUILDING.md#enabling-fips-using-openssl-config
I understand there are two methods to enable fips, one is by the openssl.cnf file and other is --enable-fips option.
I want to understand if its possible to override the openssl.cnf file. If my openssl.cnf file looks like this:
openssl_conf = openssl_init
.include /usr/local/openssl/fipsmodule.cnf
[openssl_init]
providers = prov
alg_section = algorithm_sect
[prov]
fips = fips_sect
base = base_sect
[base_sect]
activate = 1
[algorithm_sect]
default_properties = fips=yes
is it possible to override this and still use the default provider for non-FIPS supported algorithms like ChaCha20?
I was looking at the APIs provided by the crypto module, https://nodejs.org/docs/latest-v18.x/api/crypto.html and did find https://nodejs.org/api/crypto.html#cryptosetfipsbool which enables/disables FIPS provider, will this override my openssl.cnf file?
I am asking this because OpenSSL provides an API: OSSL_PROVIDER_load which can load and initialize a provider in the given context, so you can load and initialize the default provider even though your openssl.cnf file is using FIPS provider and then use non-FIPS crypto operations.
Is openssl.cnf the absolute truth and there is no way to use non-crypto operations if the cnf file is using the FIPS provider?
Node.js version
v18.13.0
Example code
const crypto = require('crypto');
const algorithm = 'ChaCha20';
const key = crypto.randomBytes(32);
const iv = crypto.randomBytes(16);
function encrypt(text) {
let cipher = crypto.createCipheriv(
'ChaCha20', Buffer.from(key), iv);
let encrypted = cipher.update(text);
encrypted = Buffer.concat([encrypted, cipher.final()]);
return { iv: iv.toString('hex'),
encryptedData: encrypted.toString('hex') };
}
var output = encrypt("Test");
console.log(output);
Operating system
Linux
Scope
runtime
Module and version
Not applicable.
crypto.setFips(bool)# Added in: v10.0.0 bool
true to enable FIPS mode. Enables the FIPS compliant crypto provider in a FIPS-enabled Node.js build. Throws an error if FIPS mode is not available.
guess you can turn off with this API
Details
Hi
I am new to Node and testing out the FIPS provider in OpenSSL 3 and some of the APIs exposed in the crypto module: https://nodejs.org/docs/latest-v18.x/api/crypto.html
I am reading about setting up FIPS here: https://github.com/nodejs/node/blob/main/BUILDING.md#enabling-fips-using-openssl-config
I understand there are two methods to enable fips, one is by the
openssl.cnffile and other is--enable-fipsoption.I want to understand if its possible to override the
openssl.cnffile. If myopenssl.cnffile looks like this:openssl_conf = openssl_init .include /usr/local/openssl/fipsmodule.cnf [openssl_init] providers = prov alg_section = algorithm_sect [prov] fips = fips_sect base = base_sect [base_sect] activate = 1 [algorithm_sect] default_properties = fips=yesis it possible to override this and still use the default provider for non-FIPS supported algorithms like ChaCha20?
I was looking at the APIs provided by the crypto module, https://nodejs.org/docs/latest-v18.x/api/crypto.html and did find https://nodejs.org/api/crypto.html#cryptosetfipsbool which enables/disables FIPS provider, will this override my
openssl.cnffile?
For this given conf file, crypto.setFips(0) (and the equivalent command line --no-enable-fips) will override the default_properties = fips=yes line. However the default provider will not be used because the conf file doesn't load it (it loads base and fips). Node.js does not provide an API to load (or unload) a provider at runtime. If you tweak the config to also load the default provider (i.e. activate fips and default (default implies base)) then the default_properties = fips=yes would restrict to FIPS supported algorithms in the default case, and using crypto.setFips(0) or --no-enable-fips would turn off that filter. See "Loading the FIPS module at the same time as other providers" in https://www.openssl.org/docs/man3.0/man7/fips_module.html for an example config.
FWIW https://github.com/nodejs/node/blob/main/BUILDING.md#enabling-fips-using-openssl-config needs to be updated. I'll try to get round to that. You don't need to rebuild Node.js for FIPS support if it is using OpenSSL 3 (e.g. Node.js 18) but you do need the FIPS module and OpenSSL configuration pointing at the FIPS module.
It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.
It seems there has been no activity on this issue for a while, and it is being closed. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.