Repository navigation
fix(ext/node): throw OpenSSL-shaped error from tls.createSecureContext when clientCertEngine is set - #33691
Conversation
…t when clientCertEngine is set Enables tests/node_compat/runner/suite/test/parallel/test-tls-error-stack.js Co-authored-by: Divy Srivastava <me@littledivy.com>
fibibot
left a comment
There was a problem hiding this comment.
Substance is right. The upstream test-tls-error-stack.js checks two paths:
if (err.code === 'ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED')
common.skip('OpenSSL dropped engine support');
return err.name === 'Error' &&
/could not load the shared library/.test(err.message) &&
Array.isArray(err.opensslErrorStack) &&
err.opensslErrorStack.length > 0;The PR opts for the second path — synthesize an OpenSSL-shaped error so the test exercises the actual assertions instead of skipping. The synthesized error correctly has:
err.name === 'Error'(defaultErrorconstructor) ✓- Message contains
"could not load the shared library"✓ err.opensslErrorStackis a 2-entry array ✓- Plus
library/function/reason/codefor completeness — matches the shape Node produces when wrapping an OpenSSLERR_get_error()chain.
Test enrollment alphabetically positioned correctly (test-tls-enable-trace < test-tls-error-stack < test-tls-env-extra-ca-no-crypto). ✓
One non-blocking design call
Deno already exports ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED (defined at ext/node/polyfills/internal/errors.ts:975 and exported at line 3142). Throwing that instead would let the test take its common.skip(...) path — which is the path modern Node takes after dropping engine support. Both choices land green; the PR's choice exercises more of the test, but at the cost of synthesizing OpenSSL error metadata that no Deno code path could otherwise produce. If user code in the wild branches on err.opensslErrorStack, the synthetic shape helps; if it branches on err.code === 'ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED', the synthetic shape misses. Worth a moment's thought, not blocking.
CI
130 success, 0 failure, 2 skipped, 2 still pending. Substance is straightforward; happy to flip to APPROVE once test node_compat debug × 6 platforms (the shard that runs test-tls-error-stack) lands green. Holding to COMMENT per the CI-must-complete rule.
3988c67 to
f1aa42c
Compare
|
@littledivy heads-up: the bot's analysis of this PR's CI failures says they look unrelated/flaky and not addressable from this PR's diff. Verdict:
Please verify and either rerun the failing checks (admin needed), waive them, or merge if the green checks are sufficient. Pinged once; the bot won't re-engage on the same signals. |
fibibot
left a comment
There was a problem hiding this comment.
Substance walks correctly against parallel/test-tls-error-stack.js — all 4 assertions match. Holding at COMMENT pending the 11 in-progress shards.
What I verified
Node's test-tls-error-stack.js checks:
assert.throws(() => {
tls.createSecureContext({ clientCertEngine: 'x' });
}, (err) => {
return err.name === 'Error' &&
/could not load the shared library/.test(err.message) &&
Array.isArray(err.opensslErrorStack) &&
err.opensslErrorStack.length > 0;
});Maps to the PR's error construction at _tls_common.ts:336-348:
new Error(...)—err.name === 'Error'✓- Message:
"error:25066067:DSO support routines:dlfcn_load:could not load the shared library"— matches/could not load the shared library/✓ err.opensslErrorStack = [...]is an array of 2 —Array.isArray(...)andlength > 0✓
The error codes are real OpenSSL codes (25066067 = DSO support routines / dlfcn_load, 25070067 = DSO_load, 260B6084 = engine routines / dynamic_load / dso not found), so the shape is faithful to what Node produces against a stock OpenSSL build that can't dlopen the named engine.
Why this is the right scope
Deno uses rustls, not OpenSSL — the clientCertEngine option is fundamentally unsupported (it's an OpenSSL-specific feature that asks libssl to dynamically load a hardware token / TPM / HSM driver). The PR doesn't try to fake engine support; it just throws the same error shape Node produces when the engine can't be loaded. That's the correct compatibility posture — code that handles err.opensslErrorStack (e.g. test runners, error reporters) keeps working, and code that genuinely needs HSM-backed TLS gets a clear failure rather than silent insecurity. ✓
The privateKeyEngine branch right below is unchanged — only validates as string but doesn't throw. That asymmetry matches Node's actual behavior (Node only throws on clientCertEngine because that's what gets passed to EVP_PKEY_set1_engine immediately; privateKeyEngine is consumed later when the key is loaded). The PR doesn't claim to fix privateKeyEngine and doesn't need to.
CI
110 success | 11 in_progress | 0 fail
The 11 in-progress are mostly slow Windows-aarch64 + node_compat (3/3) shards. Substance is APPROVE-quality modulo CI completion.
…t when clientCertEngine is set (denoland#33691) ## Summary Enables `test-tls-error-stack` in node_compat suite. ## Test plan - [x] `cargo test --test node_compat -- test-tls-error-stack` Co-authored-by: Divy Srivastava <me@littledivy.com>
Summary
Enables
test-tls-error-stackin node_compat suite.Test plan
cargo test --test node_compat -- test-tls-error-stack