forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
crypto: avoid hang when no algorithm available
- Loading branch information
1 parent
bcc2d58
commit def2b01
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
nodejs_conf = nodejs_init | ||
|
||
[nodejs_init] | ||
providers = provider_sect | ||
|
||
# List of providers to load | ||
[provider_sect] | ||
base = base_sect | ||
|
||
[base_sect] | ||
activate = 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Flags: --expose-internals | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
if (!common.hasOpenSSL3) | ||
common.skip('this test requires OpenSSL 3.x'); | ||
|
||
const { internalBinding } = require('node:internal/test/binding'); | ||
const { testFipsCrypto } = internalBinding('crypto'); | ||
const assert = require('node:assert/strict'); | ||
const crypto = require('node:crypto'); | ||
|
||
{ | ||
// TODO(richardlau): Decide if `crypto.setFips` should error if the | ||
// provider namd "fips" is not available. | ||
crypto.setFips(1); | ||
crypto.randomBytes(20, testFipsCrypto() ? | ||
common.mustSucceed() : | ||
common.expectsError((err) => { | ||
const expected = /digital envelope routines::unsupported/; | ||
assert(err.opensslErrorStack.some((msg) => expected.test(msg)), | ||
`did not find ${expected} in ${err.opensslErrorStack}`); | ||
return true; | ||
}) | ||
); | ||
} | ||
|
||
{ | ||
// Startup test. Should not hang. | ||
const { path } = require('../common/fixtures'); | ||
const { spawnSync } = require('node:child_process'); | ||
const baseConf = path('openssl3-conf', 'base_only.cnf'); | ||
const cp = spawnSync(process.execPath, | ||
[ `--openssl-config=${baseConf}`, '-p', '"hello"' ], | ||
{ encoding: 'utf8' }); | ||
assert(common.nodeProcessAborted(cp.status, cp.signal), | ||
`process did not abort, code:${cp.status} signal:${cp.signal}`); | ||
} |