crypto.setFips(bool)


  • bool <boolean> true 启用 FIPS 模式,false 关闭它。

更改 FIPS 模式。在 OpenSSL 3 中,这只是将 fips=yes 添加到或从默认属性查询中移除。它不会安装、加载、初始化或验证 FIPS 提供程序。要使用 FIPS 配置,需要安装该提供程序,并按 FIPS模式 所述配置 OpenSSL 在 Node.js 启动时加载它。

🌐 Changes FIPS mode. With OpenSSL 3, this only adds or removes fips=yes in the default property query. It does not install, load, initialize, or validate a FIPS provider. For a usable FIPS configuration, install the provider and configure OpenSSL to load it when Node.js starts, as described in FIPS mode.

如果没有已加载的提供者提供匹配 fips=yes 的请求的加密实现,调用仍然可能成功,crypto.getFips() 也可能返回 1,但获取该实现会失败。受影响的 node:crypto 操作通常会失败并返回 ERR_OSSL_EVP_UNSUPPORTED。不需要重新获取的新操作,包括使用之前获取的实现或已初始化的操作上下文的操作,可能仍然会成功。在应用初始化期间调用此方法,最好在应用代码使用其他基于 OpenSSL 的 API 之前调用。

🌐 If no loaded provider supplies a requested cryptographic implementation matching fips=yes, the call can still succeed and crypto.getFips() can still return 1, but fetching that implementation fails. Affected node:crypto operations typically fail with ERR_OSSL_EVP_UNSUPPORTED. Operations that do not require a new fetch, including those using previously fetched implementations or initialized operation contexts, may still succeed. Call this method during application initialization, before application code uses other OpenSSL-backed APIs.

这种方法只会影响之后的算法获取。Node.js 会在应用代码运行之前初始化一些 OpenSSL 状态。如果属性查询必须从进程启动时就生效,可以在 OpenSSL 配置中设置 default_properties = fips=yes,或者使用 --enable-fips 或 --force-fips。命令行标志还需要一个名为 fips 的已配置提供程序来初始化并通过自检,否则 Node.js 将无法启动。

🌐 This method only affects subsequent algorithm fetches. Node.js initializes some OpenSSL state before application code runs. When the property query must be active from process startup, set default_properties = fips=yes in the OpenSSL configuration or use --enable-fips or --force-fips. The command-line flags additionally require a configured provider named fips to initialize and pass its self-test; Node.js fails to start otherwise.

如果 OpenSSL 无法更改状态,会抛出错误。当 Node.js 是用 --force-fips 启动时,FIPS 模式无法禁用。在 OpenSSL 1.1.1 中,启用 FIPS 模式需要一个支持 FIPS 的 OpenSSL 构建。

🌐 Throws an error if OpenSSL cannot change the state. FIPS mode cannot be disabled when Node.js was started with --force-fips. With OpenSSL 1.1.1, enabling FIPS mode requires a FIPS-capable OpenSSL build.