Skip to content

FIPS mode inconsistencies #55937

Description

@etnbrd

Version

v18.20.5

Platform

Linux 0548dc7eadc2 5.15.49-linuxkit-pr #1 SMP PREEMPT Thu May 25 07:27:39 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

crypto

What steps will reproduce the bug?

The actual test:

node -p 'const crypto = require("crypto"); \
         console.log(crypto.getFips()); \
         crypto.setFips(true); \
         console.log(crypto.getFips()); \
         crypto.createHash("md5")';

Setting up the test platform, even though this fail in most platform tested:

docker run --rm -it --user root ubuntu:22.04
apt update
apt install curl
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
cd
. .nvm/nvm.sh

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

Even though fips was enabled, because the fips module is unavailable at the OS level, it should not throw, and return the md5 hash function.

What do you see instead?

node throws the error ERR_OSSL_EVP_UNSUPPORTED, as if FIPS was available.

Additional information

I'm confused by this behaviour, and I'm not sure what to make of it.

  • either it's a bug, fips is not really enabled, but node behave as if it were enabled
  • or node embed the fips module somehow, but based on this issue, I find it unlikely.

I tested this behaviour on:

  • node v18.20.5
  • node v20.18.1
  • node v22.11.0
$ for node_version in 18 20 22
> do
>   nvm install $node_version; node -p 'const crypto = require("crypto"); console.log(crypto.getFips()); crypto.setFips(true); console.log(crypto.getFips()); crypto.createHash("md5")';
> done
v18.20.5 is already installed.
Now using node v18.20.5 (npm v10.8.2)
0
1
node:internal/crypto/hash:69
  this[kHandle] = new _Hash(algorithm, xofLen);
                  ^

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:69:19)
    at Object.createHash (node:crypto:133:10)
    at [eval]:1:126
    at runScriptInThisContext (node:internal/vm:143:10)
    at node:internal/process/execution:100:14
    at [eval]-wrapper:6:24
    at runScript (node:internal/process/execution:83:62)
    at evalScript (node:internal/process/execution:114:10)
    at node:internal/main/eval_string:30:3 {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

Node.js v18.20.5
v20.18.1 is already installed.
Now using node v20.18.1 (npm v10.8.2)
0
1
node:internal/crypto/hash:79
  this[kHandle] = new _Hash(algorithm, xofLen, algorithmId, getHashCache());
                  ^

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:79:19)
    at Object.createHash (node:crypto:139:10)
    at [eval]:1:161
    at runScriptInThisContext (node:internal/vm:209:10)
    at node:internal/process/execution:118:14
    at [eval]-wrapper:6:24
    at runScript (node:internal/process/execution:101:62)
    at evalScript (node:internal/process/execution:133:3)
    at node:internal/main/eval_string:51:3 {
  opensslErrorStack: [
    'error:03000086:digital envelope routines::initialization error',
    'error:0308010C:digital envelope routines::unsupported'
  ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

Node.js v20.18.1
v22.11.0 is already installed.
Now using node v22.11.0 (npm v10.9.0)
0
1
node:internal/crypto/hash:79
  this[kHandle] = new _Hash(algorithm, xofLen, algorithmId, getHashCache());
                  ^

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:79:19)
    at Object.createHash (node:crypto:139:10)
    at [eval]:1:161
    at runScriptInThisContext (node:internal/vm:209:10)
    at node:internal/process/execution:118:14
    at [eval]-wrapper:6:24
    at runScript (node:internal/process/execution:101:62)
    at evalScript (node:internal/process/execution:136:3)
    at node:internal/main/eval_string:55:3 {
  opensslErrorStack: [
    'error:03000086:digital envelope routines::initialization error',
    'error:0308010C:digital envelope routines::unsupported'
  ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

Node.js v22.11.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    cryptoIssues and PRs related to the crypto subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions