FIPS 模式


¥FIPS mode

使用 OpenSSL 3 时,Node.js 在与适当的 OpenSSL 3 提供程序(例如可以按照 OpenSSL 的 FIPS 自述文件 中的说明安装的 来自 OpenSSL 3 的 FIPS 提供程序)一起使用时支持 FIPS 140-2。

¥When using OpenSSL 3, Node.js supports FIPS 140-2 when used with an appropriate OpenSSL 3 provider, such as the FIPS provider from OpenSSL 3 which can be installed by following the instructions in OpenSSL's FIPS README file.

对于 Node.js 中的 FIPS 支持,你需要:

¥For FIPS support in Node.js you will need:

  • 正确安装的 OpenSSL 3 FIPS 提供程序。

    ¥A correctly installed OpenSSL 3 FIPS provider.

  • OpenSSL 3 FIPS 模块配置文件

    ¥An OpenSSL 3 FIPS module configuration file.

  • 引用 FIPS 模块配置文件的 OpenSSL 3 配置文件。

    ¥An OpenSSL 3 configuration file that references the FIPS module configuration file.

Node.js 需要使用指向 FIPS 提供程序的 OpenSSL 配置文件进行配置。示例配置文件如下所示:

¥Node.js will need to be configured with an OpenSSL configuration file that points to the FIPS provider. An example configuration file looks like this:

nodejs_conf = nodejs_init

.include /<absolute path>/fipsmodule.cnf

[nodejs_init]
providers = provider_sect

[provider_sect]
default = default_sect
# The fips section name should match the section name inside the
# included fipsmodule.cnf.
fips = fips_sect

[default_sect]
activate = 1 

其中 fipsmodule.cnf 是 FIPS 提供程序安装步骤生成的 FIPS 模块配置文件:

¥where fipsmodule.cnf is the FIPS module configuration file generated from the FIPS provider installation step:

openssl fipsinstall 

OPENSSL_CONF 环境变量设置为指向你的配置文件,并将 OPENSSL_MODULES 设置为 FIPS 提供程序动态库的位置。例如

¥Set the OPENSSL_CONF environment variable to point to your configuration file and OPENSSL_MODULES to the location of the FIPS provider dynamic library. e.g.

export OPENSSL_CONF=/<path to configuration file>/nodejs.cnf
export OPENSSL_MODULES=/<path to openssl lib>/ossl-modules 

然后可以通过以下方式在 Node.js 中启用 FIPS 模式:

¥FIPS mode can then be enabled in Node.js either by:

  • 使用 --enable-fips--force-fips 命令行标志启动 Node.js。

    ¥Starting Node.js with --enable-fips or --force-fips command line flags.

  • 以编程方式调用 crypto.setFips(true)

    ¥Programmatically calling crypto.setFips(true).

可以选择通过 OpenSSL 配置文件在 Node.js 中启用 FIPS 模式。例如

¥Optionally FIPS mode can be enabled in Node.js via the OpenSSL configuration file. e.g.

nodejs_conf = nodejs_init

.include /<absolute path>/fipsmodule.cnf

[nodejs_init]
providers = provider_sect
alg_section = algorithm_sect

[provider_sect]
default = default_sect
# The fips section name should match the section name inside the
# included fipsmodule.cnf.
fips = fips_sect

[default_sect]
activate = 1

[algorithm_sect]
default_properties = fips=yes