Skip to content

Match Node 26 crypto error contracts - #219

Merged
noise64 merged 8 commits into
node-26-targetfrom
node-26-crypto-errors
Nov 23, 2026
Merged

noise64 merged 8 commits into
node-26-targetfrom
node-26-crypto-errors

Conversation

@noise64

@noise64 noise64 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor
  • relates to GOL-1947 (NJ-02); first crypto/WebCrypto baseline repair from Switch node_compat to Node 26.13.1 #218, not NJ-02 completion
  • sibling repair draft on Switch node_compat to Node 26.13.1 #218 (node-26-target); no dependency on other repair drafts
  • Decipheriv#final reports a missing or mismatched AEAD tag (GCM, OCB, CCM, ChaCha20-Poly1305) the way Node 26.13.1 does: Error: Unsupported state or unable to authenticate data without a code. The 22.14.0 test matched / auth/, which the old message also satisfied; 26.13.1 asserts the exact message from top-level code, so all 16 test-crypto-authenticated cases failed
  • KeyObject#export and generateKeyPair share one parser that mirrors Node's parseKeyEncoding:
    • format and type are required; an invalid format or type throws ERR_INVALID_ARG_VALUE;
    • pkcs1/sec1 on the wrong key type throws ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS;
    • cipher/passphrase are checked, public keys ignore them, and unknown ciphers throw ERR_CRYPTO_UNKNOWN_CIPHER;
    • createPrivateKey names its input option key.type (Node 26)
  • util.isDeepStrictEqual passes explicit DER options when it exports keys to compare them
  • raw key formats (raw-public, raw-private, raw-seed) are unchanged and still unsupported
  • WebCrypto errors match Node 26.13.1:
    • crypto.getRandomValues throws WebIDL TypeErrors for a missing argument (ERR_MISSING_ARGS) or a non-ArrayBufferView (ERR_INVALID_ARG_TYPE), and uses Node's TypeMismatchError/QuotaExceededError messages;
    • encrypt/decrypt check the key algorithm before its usages; usage failures say Unable to use this key to <operation> and algorithm mismatches say Key algorithm mismatch (sign, verify, wrapKey, unwrapKey use the same usage message);
    • HMAC import checks a zero length (HmacImportParams.length cannot be 0) and usages (Unsupported key usage for HMAC key) before the key length;
    • HMAC JWKs export the registered alg (HS1–HS512, none for SHA-3), and import rejects a mismatched alg;
    • WebCrypto DataError/SyntaxError failures are DOMExceptions with codes 0/12, as in Node, not plain Errors
  • the web_crypto_lite getRandomValues (builds without crypto-full) is unchanged
  • crypto argument validation matches Node 26.13.1:
    • without authTagLength, GCM setAuthTag accepts only a 16-byte tag (Node 26 removed implicit short tags, DEP0182); an explicit authTagLength still allows 4, 8 and 12–16;
    • hkdf/hkdfSync read the info view's intrinsic byte range, so a user-defined byteLength cannot bypass the 1024-byte limit;
    • changing a cipher's output encoding throws ERR_INVALID_ARG_VALUE The argument 'outputEncoding' cannot be changed from '<encoding>';
    • generateKeyPair rejects unsupported key types (Ed25519, toString, …) synchronously, as generateKeyPairSync already did

Node compatibility

#218 this PR
passing (runnable) 2864 2900
known gap 1588 1552
other classifications and total unchanged unchanged (10787)

Restored to their 22.14.0 classification and removed from the record's baselineGaps (343 → 307):

  • 16 test-crypto-authenticated entries; block_13 carries 22.14.0 block_12
  • 14 WebCrypto entries: test-webcrypto-encrypt-decrypt (3), test-webcrypto-encrypt-decrypt-aes (3), test-webcrypto-export-import (5) and test-webcrypto-random (3)
  • 6 validation entries: test-crypto-gcm-implicit-short-tag, test-crypto-hkdf, test-crypto-encoding-validation-error (2), test-crypto-keygen-eddsa and test-crypto-keygen block_01

test-webcrypto-random block_02 stays a recorded gap: it now fails only because the Node 26 QuotaExceededError global is not implemented.

Evidence

  • host Node.js 26.13.1 probes gave the expected results; the runtime now matches them for every export and AEAD case, except encrypted PKCS#8 DER length (cipher name ignored natively, see TODO)
  • node_compat crypto/WebCrypto filter at 5ef6e6e: 180 passed, 0 failed, 406 ignored (164 before, plus the 16 restored); at 950b9c0: 194 passed, 0 failed, 392 ignored
  • the 82 recorded crypto/WebCrypto gap cases with --include-ignored before the AEAD restore: the 16 test-crypto-authenticated cases passed, 66 still failed; WebCrypto files with --include-ignored before the WebCrypto restore: the 14 restored cases passed, test-webcrypto-random block_02 failed as above
  • new runtime test crypto::crypto_error_contracts, with 16 expected lines taken from Node 26.13.1, fails on Switch node_compat to Node 26.13.1 #218's runtime (14 lines differ) and passes here
  • new runtime test crypto::webcrypto_error_contracts, with 16 expected lines taken from Node 26.13.1, fails with 5ef6e6e's web-crypto.js (14 lines differ) and passes here; crypto:: runtime module: 41 passed

On 2256afc:

  • host Node 26.13.1 probe of the validation cases: the runtime matches every line except the OpenSSL text of a bad-decrypt error, which this PR does not change
  • the 6 restored cases pass with --include-ignored before the restore; node_compat crypto/WebCrypto filter: 200 passed, 0 failed, 386 ignored
  • crypto::crypto_error_contracts now has 22 expected lines from Node 26.13.1; with 950b9c0's web-crypto.js 5 lines differ (the sixth new line is a positive control), and it passes here; crypto:: runtime module: 41 passed
  • report regenerated; node_compat_report (36), DTS (87), migrate_config_split (38), cargo fmt --check, cargo clippy --test runtime -- -Dwarnings
  • DTS (87), node_compat_report (36) and migrate_config_split (38) tests, cargo fmt --check, cargo clippy --test runtime -- -Dwarnings
  • not run: full node_compat lane, other runtime groups, cargo build/clippy --all-targets (disk headroom); CI not requested

TODO: the remaining 46 crypto/WebCrypto gaps; the 4 test-crypto-cipheriv-decipheriv blocks fail in top-level testSm4Xts, which needs the new Node 26 xtsStandard cipher option; 38 of them are blocked by new Node 26 APIs in top-level test code (raw key formats in test-crypto-key-objects and test-crypto-sign-verify, callback diffieHellman in test-crypto-dh-stateless); the native encrypted export ignores the cipher name for PKCS#8; a second Cipheriv#final reports ERR_CRYPTO_HASH_FINALIZED instead of ERR_CRYPTO_INVALID_STATE

1e529ff and 198a339

  • 1e529ff merges node-26-target 1359ce9, which carries the Make node_compat config migration lossless and strict #216 matchedByPosition audit fix 85600f7; it changes only tests/migrate_config_split.rs
  • one-shot sign()/verify() with a callback now validate options and parse the key synchronously and deliver errors of the signing job itself (RSA key too small for the digest, x25519 key) to the callback, as Node does. Restores test-crypto-async-sign-verify block_01 and block_02 (305 baseline gaps, 44 crypto/WebCrypto gaps)
  • DiffieHellman#computeSecret rejects a peer key of p - 1 and reports both limits as RangeError ERR_CRYPTO_INVALID_KEYLEN, as Node does
  • crypto::crypto_error_contracts has 6 more lines, all 28 equal to the host Node 26.13.1 output, and passes. node_compat in CI mode: async-sign-verify and DH files 18 passed, 9 ignored; with --include-ignored, the crypto/WebCrypto filter has no runnable regression (one --expose-internals test is ignored by the harness). Report regenerated, fmt clean
  • not changed: verifyError still follows neither OpenSSL generation, because the harness shim's hasOpenSSL() is always false (OpenSSL 1.1 test branches) and generated DH primes are not safe primes. test-crypto-dh-curves stays a gap
  • not run on 198a339: red control of the new runtime lines on the old skeleton, other runtime tests, clippy, full node_compat lane (disk headroom); CI not requested

e0772f3 (review fixes)

  • one-shot sign()/verify() with a callback check the key type before the job, also for a bare or nested KeyObject: a public or secret key for sign and a secret key for verify throw ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE synchronously and never reach the callback, as in Node 26
  • the job gets the padding/saltLength values read during validation, so inherited and non-enumerable options are kept (they were dropped by an object spread)
  • crypto::crypto_error_contracts has 9 more lines (37, all equal to the host Node 26.13.1 output): with 198a339's web-crypto.js exactly the 6 new key-type/option lines fail and the 3 controls pass; on e0772f3 it passes, and the crypto:: runtime module passes (41)
  • node_compat crypto/WebCrypto with --include-ignored: 587 results identical to the 198a339 tree, no runnable regression (the --expose-internals test the harness ignores still fails on its internal require); node_compat_config_report_is_current passes
  • not run: other runtime groups, clippy, full node_compat lane; CI not requested

On 454e7f7 (merge of node-26-target at 57656e1, which brings in #216's explicit mapping decisions): git diff 57656e13 454e7f71 equals git diff 1359ce9c e0772f33, so the crypto change is unchanged. migrate_config_split ':tag:migration_contract' 24/24, clippy -Dwarnings on that target and node_compat_config_report_is_current pass. The crypto node_compat cases were not rerun for the merge.

@noise64
noise64 merged commit 65e5330 into node-26-target Nov 23, 2026
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.

1 participant