Skip to content

fix(ext/node): throw OpenSSL-shaped error from tls.createSecureContext when clientCertEngine is set - #33691

Merged
littledivy merged 2 commits into
denoland:mainfrom
divybot:claude/test-tls-error-stack
May 12, 2026
Merged

littledivy merged 2 commits into
denoland:mainfrom
divybot:claude/test-tls-error-stack

Conversation

@divybot

@divybot divybot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Enables test-tls-error-stack in node_compat suite.

Test plan

  • cargo test --test node_compat -- test-tls-error-stack

…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 fibibot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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' (default Error constructor) ✓
  • Message contains "could not load the shared library" ✓
  • err.opensslErrorStack is a 2-entry array ✓
  • Plus library / function / reason / code for completeness — matches the shape Node produces when wrapping an OpenSSL ERR_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.

@divybot
divybot force-pushed the claude/test-tls-error-stack branch from 3988c67 to f1aa42c Compare April 29, 2026 14:12
@divybot

divybot commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

@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:

CI failure is flaky network test specs::cert::ip_address_unsafe_ssl hitting external IP 1.1.1.1 (Cloudflare) which returned 403 instead of 200 — unrelated to this PR; all node_compat shards passed, reviewer comment was non-blocking

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 fibibot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(...) and length > 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.

@littledivy
littledivy merged commit 1298e48 into denoland:main May 12, 2026
136 checks passed
littledivy added a commit to crowlKats/deno that referenced this pull request Jun 10, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants