diff --git a/crates/wasm-rquickjs/skeleton/src/builtin/util.js b/crates/wasm-rquickjs/skeleton/src/builtin/util.js index 40de160ac..da659cfb1 100644 --- a/crates/wasm-rquickjs/skeleton/src/builtin/util.js +++ b/crates/wasm-rquickjs/skeleton/src/builtin/util.js @@ -418,10 +418,10 @@ function _exportKeyForCompare(key, keyType) { // Try a more explicit export signature. } + const formatType = keyType === 'public' ? 'spki' : 'pkcs8'; try { - return key.export('der'); + return key.export({ format: 'der', type: formatType }); } catch (_) { - const formatType = keyType === 'public' ? 'spki' : 'pkcs8'; try { return key.export('der', formatType, undefined); } catch (_) { diff --git a/crates/wasm-rquickjs/skeleton/src/builtin/web-crypto.js b/crates/wasm-rquickjs/skeleton/src/builtin/web-crypto.js index 6bba105fc..64023d91f 100644 --- a/crates/wasm-rquickjs/skeleton/src/builtin/web-crypto.js +++ b/crates/wasm-rquickjs/skeleton/src/builtin/web-crypto.js @@ -166,13 +166,31 @@ function isAnyArrayBuffer(data) { return data instanceof ArrayBuffer || data instanceof SharedArrayBuffer; } +const intrinsicGetter = (proto, name) => Function.prototype.call.bind(Object.getOwnPropertyDescriptor(proto, name).get); +const TypedArrayPrototype = Object.getPrototypeOf(Uint8Array.prototype); +const typedArrayBuffer = intrinsicGetter(TypedArrayPrototype, 'buffer'); +const typedArrayByteOffset = intrinsicGetter(TypedArrayPrototype, 'byteOffset'); +const typedArrayByteLength = intrinsicGetter(TypedArrayPrototype, 'byteLength'); +const dataViewBuffer = intrinsicGetter(DataView.prototype, 'buffer'); +const dataViewByteOffset = intrinsicGetter(DataView.prototype, 'byteOffset'); +const dataViewByteLength = intrinsicGetter(DataView.prototype, 'byteLength'); + +// Read the view's real backing range, as Node does, so user-defined +// `buffer`/`byteOffset`/`byteLength` properties cannot change it. +function viewBytes(view) { + if (view instanceof DataView) { + return new Uint8Array(dataViewBuffer(view), dataViewByteOffset(view), dataViewByteLength(view)); + } + return new Uint8Array(typedArrayBuffer(view), typedArrayByteOffset(view), typedArrayByteLength(view)); +} + function toHkdfByteSource(data, name) { if (typeof data === 'string') { return toBytes(data); } if (ArrayBuffer.isView(data)) { - return new Uint8Array(data.buffer, data.byteOffset, data.byteLength); + return viewBytes(data); } if (isAnyArrayBuffer(data)) { @@ -461,7 +479,7 @@ function trackCipherOutputEncoding(currentEncoding, outputEncoding) { throw new ERR_UNKNOWN_ENCODING(outputEncoding); } if (currentEncoding !== null && currentEncoding !== normalizedEncoding) { - throw new Error('Cannot change encoding'); + throw new ERR_INVALID_ARG_VALUE('outputEncoding', outputEncoding, `cannot be changed from '${currentEncoding}'`); } return normalizedEncoding; } @@ -656,12 +674,23 @@ function isIntegerTypedArray(value) { value instanceof BigUint64Array; } +const kGetRandomValuesPrefix = "Failed to execute 'getRandomValues' on 'Crypto'"; + +function codedTypeError(message, code) { + const err = new TypeError(message); + err.code = code; + return err; +} + export function getRandomValues(typedArray) { + if (!ArrayBuffer.isView(typedArray)) { + throw codedTypeError(`${kGetRandomValuesPrefix}: 1st argument is not an ArrayBufferView.`, 'ERR_INVALID_ARG_TYPE'); + } if (!isIntegerTypedArray(typedArray)) { - throw new DOMException('The provided value is not of type \'(Int8Array or Int16Array or Int32Array or Uint8Array or Uint16Array or Uint32Array or Uint8ClampedArray or Float32Array or Float64Array or DataView or BigInt64Array or BigUint64Array)\'', 'TypeMismatchError'); + throw new DOMException('The data argument must be an integer-type TypedArray', 'TypeMismatchError'); } if (typedArray.byteLength > 65536) { - throw new DOMException('The ArrayBufferView\'s byte length (' + typedArray.byteLength + ') exceeds the number of bytes of entropy available via this API (65536)', 'QuotaExceededError'); + throw new DOMException('The requested length exceeds 65,536 bytes', 'QuotaExceededError'); } // Use a plain Uint8Array view to randomize the underlying buffer, // which works for all integer typed array types including Buffer subclasses @@ -1968,7 +1997,9 @@ function validateDecipherAuthTagLength(decipher, actualLength) { if (actualLength !== decipher._authTagLength) { throwInvalidAuthTagLength(actualLength); } - } else if (!isValidGcmAuthTagLength(actualLength)) { + } else if (actualLength !== 16) { + // Node 26 removed implicit short GCM tags (DEP0182): without + // authTagLength, only a full 16-byte tag is accepted. throwInvalidAuthTagLength(actualLength); } return; @@ -2072,11 +2103,11 @@ Decipheriv.prototype.final = function(outputEncoding) { } throw createWrongFinalBlockLengthError(); } - const err = new Error( - isMissingTag - ? 'Unsupported state or unable to authenticate data' - : 'Decipher final failed (possibly wrong key, IV, or auth tag)' - ); + if (this._aeadConfig.mode !== null) { + // Node reports a missing or mismatched AEAD tag with OpenSSL's generic message and no code. + throw new Error('Unsupported state or unable to authenticate data'); + } + const err = new Error('Decipher final failed (possibly wrong key, IV, or auth tag)'); err.code = 'ERR_CRYPTO_INVALID_STATE'; throw err; } @@ -2347,9 +2378,12 @@ DiffieHellman.prototype.computeSecret = function(otherPublicKey, inputEncoding, const pubBytes = toBytes(otherPublicKey, inputEncoding); const result = webCryptoNative.dh_compute_secret_err(this._handle, pubBytes); if (result[0] === 'error') { - const err = new Error(result[1]); - err.message = result[1]; - throw err; + if (result[1] === 'Supplied key is too small' || result[1] === 'Supplied key is too large') { + const err = new RangeError(result[1]); + err.code = 'ERR_CRYPTO_INVALID_KEYLEN'; + throw err; + } + throw new Error(result[1]); } const hexStr = result[1]; const bytes = new Uint8Array(hexStr.length / 2); @@ -2855,6 +2889,51 @@ function createInvalidKeyObjectTypeError(type_) { return err; } +// Output encoding of KeyObject#export and generateKeyPair, as Node's parseKeyEncoding validates it +// (lib/internal/crypto/keys.js). `objName` prefixes the option names in errors. The raw key formats +// are not parsed here; callers handle them before calling this. +function parseKeyOutputEncoding(enc, asymmetricKeyType, isPublic, objName) { + const { format, type } = enc; + if (format !== 'pem' && format !== 'der' && format !== 'jwk') { + throw new ERR_INVALID_ARG_VALUE(`${objName}.format`, format); + } + if (type !== undefined || format !== 'jwk') { + if (type === 'pkcs1') { + if (asymmetricKeyType !== 'rsa') { + throw new ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS(type, 'can only be used for RSA keys'); + } + } else if (type === 'sec1' && !isPublic) { + if (asymmetricKeyType !== 'ec') { + throw new ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS(type, 'can only be used for EC keys'); + } + } else if (!(type === 'spki' && isPublic) && !(type === 'pkcs8' && !isPublic)) { + throw new ERR_INVALID_ARG_VALUE(`${objName}.type`, type); + } + } + if (isPublic) { + return { format, type }; + } + const { cipher, passphrase } = enc; + if (cipher != null) { + if (typeof cipher !== 'string') { + throw new ERR_INVALID_ARG_VALUE(`${objName}.cipher`, cipher); + } + if (format === 'der' && (type === 'pkcs1' || type === 'sec1')) { + throw new ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS(type, 'does not support encryption'); + } + if (!isStringOrBufferLike(passphrase)) { + throw new ERR_INVALID_ARG_VALUE(`${objName}.passphrase`, passphrase); + } + } else if (passphrase !== undefined) { + throw new ERR_INVALID_ARG_VALUE(`${objName}.cipher`, cipher, 'is required when a passphrase is specified'); + } + return { format, type, cipher, passphrase }; +} + +function isRawKeyFormat(format) { + return format === 'raw-public' || format === 'raw-private' || format === 'raw-seed'; +} + // ===== KeyObject ===== class KeyObject { @@ -2974,17 +3053,18 @@ class KeyObject { throw new ERR_INVALID_ARG_TYPE('options', 'object', options); } - const format = options.format || (options.type ? 'pem' : 'der'); - const type_ = options.type || null; - - if (format === 'jwk' && (options.passphrase !== undefined || options.cipher !== undefined)) { - throw new ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS('jwk', 'does not support encryption'); + const isPublic = this._type === 'public'; + let format = options.format; + if (!isPublic && options.passphrase !== undefined && format !== 'pem' && format !== 'der') { + throw new ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS(format, 'does not support encryption'); } - - if (options.passphrase !== undefined && options.cipher === undefined) { - const err = new TypeError("The property 'options.cipher' is invalid. Received undefined"); - err.code = 'ERR_INVALID_ARG_VALUE'; - throw err; + // Raw formats keep the native path; they are not implemented, and fail there. + let type_ = options.type || null; + let cipher; + let passphrase; + if (!isRawKeyFormat(format) && format !== 'jwk') { + ({ format, type: type_, cipher, passphrase } = + parseKeyOutputEncoding(options, this.asymmetricKeyType, isPublic, 'options')); } // JWK export @@ -3005,10 +3085,11 @@ class KeyObject { throw new Error('Failed to export key as JWK'); } - // Encrypted PEM export - if (options.cipher && options.passphrase !== undefined) { - const passBytes = toBytes(options.passphrase); - const result = webCryptoNative.key_export_encrypted(this._handle, format, type_ || 'pkcs8', options.cipher, passBytes); + // Encrypted private key export + if (cipher != null) { + const cipherName = normalizeCipherAlgorithm(cipher); + const passBytes = toBytes(passphrase); + const result = webCryptoNative.key_export_encrypted(this._handle, format, type_, cipherName, passBytes); if (result === null || result === undefined) { throw new Error('Failed to export encrypted key'); } @@ -3101,7 +3182,15 @@ class KeyObject { cryptoAlgorithm = { name: 'HKDF' }; } else if (normalizedAlgorithm.upperName === 'HMAC') { const requestedLength = getRequestedHmacLength(algorithm, keyLengthBits); - if (requestedLength === 0 || keyLengthBits === 0) { + if (requestedLength === 0 && typeof algorithm === 'object' && algorithm.length !== undefined) { + throw createDataError('HmacImportParams.length cannot be 0'); + } + ensureAllowedCryptoKeyUsages( + usages, + new Set(['sign', 'verify']), + 'Unsupported key usage for HMAC key', + ); + if (keyLengthBits === 0) { throw createDataError('Zero-length key is not supported'); } if (requestedLength !== keyLengthBits) { @@ -3114,11 +3203,6 @@ class KeyObject { if (usages.length === 0) { throw createSyntaxError('Usages cannot be empty when importing a secret key.'); } - ensureAllowedCryptoKeyUsages( - usages, - new Set(['sign', 'verify']), - 'Unsupported key usage for an HMAC key', - ); cryptoAlgorithm = { name: 'HMAC', hash: { name: normalizeToCryptoKeyHash(algorithm) }, @@ -3238,15 +3322,11 @@ Object.defineProperty(KeyObject.prototype, Symbol.toStringTag, { export { KeyObject }; function createDataError(message) { - const err = new Error(message); - err.name = 'DataError'; - return err; + return new DOMException(message, 'DataError'); } function createSyntaxError(message) { - const err = new Error(message); - err.name = 'SyntaxError'; - return err; + return new DOMException(message, 'SyntaxError'); } function normalizeToCryptoKeyAlgorithm(algorithm) { @@ -5741,9 +5821,8 @@ export function createPrivateKey(key) { } const format = key.format || 'pem'; if (format === 'der' && key.type !== undefined && key.type !== 'pkcs1' && key.type !== 'pkcs8' && key.type !== 'sec1') { - const err = new TypeError("The property 'options.type' is invalid. Received '" + key.type + "'"); - err.code = 'ERR_INVALID_ARG_VALUE'; - throw err; + // Node 26 names input encoding options after the `key` argument. + throw new ERR_INVALID_ARG_VALUE('key.type', key.type); } const normalizedKeyData = normalizeAsymmetricKeyDataForEncoding(innerKey, format, key.encoding); const normalizedPassphrase = normalizeAsymmetricPassphraseForEncoding(key.passphrase, key.encoding); @@ -6282,6 +6361,8 @@ function createInvalidKeygenPropertyError(propertyName, value) { return err; } +const KEY_PAIR_TYPES = new Set(['rsa', 'rsa-pss', 'dsa', 'ec', 'ed25519', 'ed448', 'x25519', 'x448', 'dh']); + function createUnsupportedKeyTypeError(type_) { const err = new TypeError(`The argument 'type' must be a supported key type. Received ${formatInvalidArgValue(type_)}`); err.code = 'ERR_INVALID_ARG_VALUE'; @@ -6420,41 +6501,6 @@ function isStringOrBufferLike(value) { return typeof value === 'string' || ArrayBuffer.isView(value) || isAnyArrayBuffer(value); } -function validateGeneratedKeyEncodingFormat(optionName, encodingOptions) { - const format = encodingOptions.format; - if (format !== 'pem' && format !== 'der' && format !== 'jwk') { - throw createInvalidKeygenPropertyError(`${optionName}.format`, format); - } - return format; -} - -function validateGeneratedPublicKeyEncodingType(type_, encodingOptions, format) { - const keyType = encodingOptions.type; - if ((format !== 'jwk' && keyType === undefined) || - (keyType !== undefined && keyType !== 'pkcs1' && keyType !== 'spki')) { - throw createInvalidKeygenPropertyError('publicKeyEncoding.type', keyType); - } - - if (keyType === 'pkcs1' && type_ !== 'rsa') { - throw new ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS('pkcs1', 'can only be used for RSA keys'); - } -} - -function validateGeneratedPrivateKeyEncodingType(type_, encodingOptions, format) { - const keyType = encodingOptions.type; - if ((format !== 'jwk' && keyType === undefined) || - (keyType !== undefined && keyType !== 'pkcs1' && keyType !== 'pkcs8' && keyType !== 'sec1')) { - throw createInvalidKeygenPropertyError('privateKeyEncoding.type', keyType); - } - - if (keyType === 'pkcs1' && type_ !== 'rsa') { - throw new ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS('pkcs1', 'can only be used for RSA keys'); - } - if (keyType === 'sec1' && type_ !== 'ec') { - throw new ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS('sec1', 'can only be used for EC keys'); - } -} - function validateGeneratedPublicKeyEncoding(type_, publicKeyEncoding) { if (publicKeyEncoding == null) { return; @@ -6462,9 +6508,7 @@ function validateGeneratedPublicKeyEncoding(type_, publicKeyEncoding) { if (typeof publicKeyEncoding !== 'object' || Array.isArray(publicKeyEncoding)) { throw createInvalidKeygenPropertyError('publicKeyEncoding', publicKeyEncoding); } - - const format = validateGeneratedKeyEncodingFormat('publicKeyEncoding', publicKeyEncoding); - validateGeneratedPublicKeyEncodingType(type_, publicKeyEncoding, format); + parseKeyOutputEncoding(publicKeyEncoding, type_, true, 'options.publicKeyEncoding'); } function validateGeneratedPrivateKeyEncoding(type_, privateKeyEncoding) { @@ -6474,28 +6518,7 @@ function validateGeneratedPrivateKeyEncoding(type_, privateKeyEncoding) { if (typeof privateKeyEncoding !== 'object' || Array.isArray(privateKeyEncoding)) { throw createInvalidKeygenPropertyError('privateKeyEncoding', privateKeyEncoding); } - - const format = validateGeneratedKeyEncodingFormat('privateKeyEncoding', privateKeyEncoding); - validateGeneratedPrivateKeyEncodingType(type_, privateKeyEncoding, format); - - const cipher = privateKeyEncoding.cipher; - const passphrase = privateKeyEncoding.passphrase; - if (format === 'jwk' && (cipher !== undefined || passphrase !== undefined)) { - throw new ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS('jwk', 'does not support encryption'); - } - if (cipher != null && typeof cipher !== 'string') { - throw createInvalidKeygenPropertyError('privateKeyEncoding.cipher', cipher); - } - if (cipher == null && passphrase !== undefined) { - throw createInvalidKeygenPropertyError('privateKeyEncoding.cipher', cipher); - } - if (cipher != null && !isStringOrBufferLike(passphrase)) { - throw createInvalidKeygenPropertyError('privateKeyEncoding.passphrase', passphrase); - } - if (cipher != null && format === 'der' && - (privateKeyEncoding.type === 'pkcs1' || privateKeyEncoding.type === 'sec1')) { - throw new ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS(privateKeyEncoding.type, 'does not support encryption'); - } + const { cipher } = parseKeyOutputEncoding(privateKeyEncoding, type_, false, 'options.privateKeyEncoding'); if (cipher != null) { privateKeyEncoding.cipher = normalizeCipherAlgorithm(cipher); } @@ -6638,6 +6661,10 @@ export function generateKeyPair(type_, options, callback) { } options = normalizeGenerateKeyPairOptions(type_, options); + // Node validates the key type synchronously; only generation failures reach the callback. + if (!KEY_PAIR_TYPES.has(type_)) { + throw createUnsupportedKeyTypeError(type_); + } if (type_ === 'rsa' || type_ === 'rsa-pss') { if (type_ === 'rsa-pss') { validateRsaPssKeyPairOptions(options); @@ -7280,12 +7307,12 @@ export function sign(algorithm, data, key, callback) { const normalizedData = toBytes(data); const s = new Sign(algo); s.update(normalizedData); - const result = s.sign(key); - if (callback) { - process.nextTick(() => callback(null, result)); - return; + // A missing key fails synchronously, as in Node.js. + if (!callback || key === null || key === undefined) { + return s.sign(key); } - return result; + const preparedKey = prepareOneShotKey(key, createPrivateKey, createPrivateKey, ['private'], 'private'); + runOneShotJob(() => s.sign(preparedKey), callback); } export function verify(algorithm, data, key, signature, callback) { @@ -7300,12 +7327,49 @@ export function verify(algorithm, data, key, signature, callback) { throw new ERR_INVALID_ARG_TYPE('signature', ['Buffer', 'TypedArray', 'DataView'], signature); } - const result = v.verify(key, signature); - if (callback) { - process.nextTick(() => callback(null, result)); - return; + if (!callback || key === null || key === undefined) { + return v.verify(key, signature); } - return result; + const preparedKey = prepareOneShotKey( + key, + createPublicKey, + (k) => (k.passphrase !== undefined ? createPublicKey(createPrivateKey(k)) : createPublicKey(k)), + ['public', 'private'], + 'private or public'); + runOneShotJob(() => v.verify(preparedKey, signature), callback); +} + +// Node.js validates one-shot sign()/verify() options, parses the key and +// checks its type synchronously; only errors of the signing job itself reach +// the callback. The job gets the options read here, including inherited ones. +function prepareOneShotKey(key, fromKey, fromKeyOptions, allowedTypes, expectedType) { + let keyObject; + let padding; + let saltLength; + if (key instanceof KeyObject) { + keyObject = key; + } else if (typeof key === 'object' && key.key !== undefined) { + padding = getSignVerifyIntOption('padding', key); + saltLength = getSignVerifyIntOption('saltLength', key); + keyObject = key.key instanceof KeyObject ? key.key : fromKeyOptions(key); + } else { + keyObject = fromKey(key); + } + if (!allowedTypes.includes(keyObject.type)) { + throw new ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE(keyObject.type, expectedType); + } + return { key: keyObject, padding, saltLength }; +} + +function runOneShotJob(job, callback) { + let error = null; + let result; + try { + result = job(); + } catch (err) { + error = err; + } + process.nextTick(() => (error ? callback(error) : callback(null, result))); } function rsaCacheKey(bytes, padding) { @@ -7830,23 +7894,30 @@ function concatBytesParts(...parts) { return result; } -function throwInvalidAccessError() { - throw new DOMException('The requested operation is not valid for the provided key', 'InvalidAccessError'); -} - function throwOperationError() { throw new DOMException('The operation failed for an operation-specific reason', 'OperationError'); } +const HMAC_JWK_ALGS = { 'SHA-1': 'HS1', 'SHA-256': 'HS256', 'SHA-384': 'HS384', 'SHA-512': 'HS512' }; + +// JWK "alg" for an HMAC hash; undefined for hashes without a registered value, such as SHA-3. +function getHmacJwkAlg(algorithm) { + return HMAC_JWK_ALGS[normalizeToCryptoKeyHash(algorithm)]; +} + +function throwUnusableKeyError(usage) { + throw new DOMException(`Unable to use this key to ${usage}`, 'InvalidAccessError'); +} + function validateKeyUsage(key, usage) { if (!key || !key._usages || !key._usages.includes(usage)) { - throwInvalidAccessError(); + throwUnusableKeyError(usage); } } function validateKeyAlgorithm(key, algorithmName) { if (!key || !key._algorithm || key._algorithm.name.toUpperCase() !== algorithmName.toUpperCase()) { - throwInvalidAccessError(); + throw new DOMException('Key algorithm mismatch', 'InvalidAccessError'); } } @@ -8008,7 +8079,7 @@ class SubtleCrypto { } for (const u of keyUsages) { if (u !== 'sign' && u !== 'verify') { - throw new DOMException('Unsupported key usage for an HMAC key', 'SyntaxError'); + throw new DOMException('Unsupported key usage for HMAC key', 'SyntaxError'); } } if (keyUsages.length === 0) { @@ -8273,6 +8344,12 @@ class SubtleCrypto { throw createDataError('Invalid keyData'); } if (keyData.kty === 'oct') { + if (name === 'HMAC' && keyData.alg !== undefined) { + const expected = getHmacJwkAlg(algorithm); + if (expected !== undefined && keyData.alg !== expected) { + throw createDataError('JWK "alg" does not match the requested algorithm'); + } + } const raw = base64UrlToBytes(keyData.k); const secretKey = createSecretKey(raw); return secretKey.toCryptoKey(algorithm, extractable, keyUsages); @@ -8324,6 +8401,10 @@ class SubtleCrypto { } jwk.key_ops = [...key._usages]; jwk.ext = key._extractable; + if (key._algorithm.name === 'HMAC') { + const alg = getHmacJwkAlg(key._algorithm); + if (alg !== undefined) jwk.alg = alg; + } return jwk; } if (format === 'spki') { @@ -8349,14 +8430,14 @@ class SubtleCrypto { } const name = algoName.toUpperCase(); + validateKeyAlgorithm(key, algoName); if (name === 'AES-KW') { if (!key._usages.includes('wrapKey') && !key._usages.includes('encrypt')) { - throwInvalidAccessError(); + throwUnusableKeyError('encrypt'); } } else { validateKeyUsage(key, 'encrypt'); } - validateKeyAlgorithm(key, algoName); const dataBytes = toBytes(data); if (name === 'AES-KW') { @@ -8429,14 +8510,14 @@ class SubtleCrypto { } const name = algoName.toUpperCase(); + validateKeyAlgorithm(key, algoName); if (name === 'AES-KW') { if (!key._usages.includes('unwrapKey') && !key._usages.includes('decrypt')) { - throwInvalidAccessError(); + throwUnusableKeyError('decrypt'); } } else { validateKeyUsage(key, 'decrypt'); } - validateKeyAlgorithm(key, algoName); const dataBytes = toBytes(data); try { @@ -8663,6 +8744,9 @@ class Crypto { getRandomValues(array) { assertCrypto(this); + if (arguments.length < 1) { + throw codedTypeError(`${kGetRandomValuesPrefix}: 1 argument required, but only 0 present.`, 'ERR_MISSING_ARGS'); + } return getRandomValues(array); } diff --git a/crates/wasm-rquickjs/skeleton/src/builtin/web_crypto.rs b/crates/wasm-rquickjs/skeleton/src/builtin/web_crypto.rs index cdd188f10..0e2106b1a 100644 --- a/crates/wasm-rquickjs/skeleton/src/builtin/web_crypto.rs +++ b/crates/wasm-rquickjs/skeleton/src/builtin/web_crypto.rs @@ -4978,7 +4978,8 @@ fn dh_compute_secret_impl(id: u32, other_pub_bytes: &[u8]) -> Result, St if other_pub.is_zero() || other_pub.is_one() { return Err("Supplied key is too small".to_string()); } - if other_pub >= state.p { + // DH_check_pub_key: a valid peer key lies in [2, p - 2]. + if other_pub >= &state.p - BigUint::one() { return Err("Supplied key is too large".to_string()); } let priv_key = state.priv_key.as_ref().ok_or("No private key set")?; diff --git a/examples/runtime/crypto/src/crypto.js b/examples/runtime/crypto/src/crypto.js index 0911bbb27..774780561 100644 --- a/examples/runtime/crypto/src/crypto.js +++ b/examples/runtime/crypto/src/crypto.js @@ -1,4 +1,4 @@ -import { createHash, createHmac, hash, getHashes, getCiphers, getCurves, constants, randomBytes, randomInt, timingSafeEqual, pbkdf2Sync, scryptSync, hkdfSync, createCipheriv, createDecipheriv, generateKeyPairSync, createSign, createVerify, createPublicKey, sign, verify } from 'node:crypto'; +import { createHash, createHmac, hash, getHashes, getCiphers, getCurves, constants, randomBytes, randomInt, timingSafeEqual, pbkdf2Sync, scryptSync, hkdfSync, createCipheriv, createDecipheriv, generateKeyPair, generateKeyPairSync, createSign, createVerify, createPublicKey, createPrivateKey, sign, verify, getDiffieHellman, createDiffieHellman, createSecretKey } from 'node:crypto'; export function newUuids() { const uuid1 = crypto.randomUUID() @@ -275,3 +275,160 @@ export async function subtleSignVerifyRsaPss(message) { const signature = await crypto.subtle.sign(pss, keyPair.privateKey, data); return await crypto.subtle.verify(pss, keyPair.publicKey, signature, data); } + +export async function cryptoErrorContracts() { + const lines = []; + const check = (name, fn) => { + try { + const value = fn(); + lines.push(`${name}: ok ${typeof value === 'string' ? value.split('\n')[0] : typeof value}`); + } catch (e) { + lines.push(`${name}: ${e.name} ${e.code} ${e.message}`); + } + }; + const aeadFinal = (algorithm, tamper) => { + const key = Buffer.alloc(32, 1); + const iv = Buffer.alloc(12, 2); + const cipher = createCipheriv(algorithm, key, iv); + const ciphertext = Buffer.concat([cipher.update('payload'), cipher.final()]); + const tag = cipher.getAuthTag(); + const decipher = createDecipheriv(algorithm, key, iv); + if (tamper !== 'no-tag') { + tag[0] ^= 1; + decipher.setAuthTag(tag); + } + decipher.update(ciphertext); + return decipher.final(); + }; + check('gcm tampered tag', () => aeadFinal('aes-256-gcm', 'tag')); + check('gcm missing tag', () => aeadFinal('aes-256-gcm', 'no-tag')); + check('chacha20-poly1305 tampered tag', () => aeadFinal('chacha20-poly1305', 'tag')); + + const rsa = generateKeyPairSync('rsa', { modulusLength: 512 }); + const ed = generateKeyPairSync('ed25519'); + check('public pkcs8', () => rsa.publicKey.export({ format: 'pem', type: 'pkcs8' })); + check('public without format', () => rsa.publicKey.export({ type: 'spki' })); + check('public spki ignores cipher', () => rsa.publicKey.export({ format: 'pem', type: 'spki', cipher: 'aes-128-cbc', passphrase: 'x' })); + check('private without type', () => rsa.privateKey.export({ format: 'pem' })); + check('private passphrase without cipher', () => rsa.privateKey.export({ format: 'pem', type: 'pkcs8', passphrase: 'x' })); + check('private der pkcs1 encrypted', () => rsa.privateKey.export({ format: 'der', type: 'pkcs1', cipher: 'aes-128-cbc', passphrase: 'x' })); + check('private unknown cipher', () => rsa.privateKey.export({ format: 'pem', type: 'pkcs8', cipher: 'nope', passphrase: 'x' })); + check('private pem pkcs8 encrypted', () => rsa.privateKey.export({ format: 'pem', type: 'pkcs8', cipher: 'aes-128-cbc', passphrase: 'x' })); + check('ed25519 public pkcs1', () => ed.publicKey.export({ format: 'pem', type: 'pkcs1' })); + check('ed25519 private sec1', () => ed.privateKey.export({ format: 'pem', type: 'sec1' })); + check('keygen passphrase without cipher', () => generateKeyPairSync('ed25519', { privateKeyEncoding: { format: 'jwk', passphrase: 'x' } })); + check('keygen public pkcs8', () => generateKeyPairSync('ed25519', { publicKeyEncoding: { format: 'pem', type: 'pkcs8' } })); + check('createPrivateKey der spki', () => createPrivateKey({ key: Buffer.alloc(0), format: 'der', type: 'spki' })); + const shortTag = createDecipheriv('aes-256-gcm', Buffer.alloc(32), Buffer.alloc(12)); + check('gcm implicit 12-byte tag', () => shortTag.setAuthTag(Buffer.alloc(12))); + check('gcm authTagLength 12-byte tag', () => createDecipheriv('aes-256-gcm', Buffer.alloc(32), Buffer.alloc(12), { authTagLength: 12 }).setAuthTag(Buffer.alloc(12)) && 'set'); + const info = new Uint8Array(2048); + Object.defineProperty(info, 'byteLength', { get() { return 1; } }); + check('hkdfSync info with fake byteLength', () => hkdfSync('sha256', 'a', '', info, 10)); + check('cipher output encoding change', () => { + const cipher = createCipheriv('aes-256-cbc', Buffer.alloc(32), Buffer.alloc(16)); + cipher.update('test', 'utf-8', 'utf-8'); + return cipher.final('hex'); + }); + check('generateKeyPair Ed25519', () => generateKeyPair('Ed25519', () => {})); + check('generateKeyPair toString', () => generateKeyPair('toString', () => {})); + + // One-shot sign()/verify() validate synchronously but deliver errors of the + // signing job to the callback, after returning. + const viaCallback = (name, fn, show = (value) => value) => new Promise((resolve) => { + let returned = false; + const done = (outcome) => { + lines.push(`${name}: ${returned ? '' : 'before return '}${outcome}`); + resolve(); + }; + try { + fn((err, value) => done(err ? `callback ${err.name} ${err.code}` : `callback ok ${show(value)}`)); + returned = true; + } catch (e) { + lines.push(`${name}: throws ${e.name} ${e.code}`); + resolve(); + } + }); + const x25519 = generateKeyPairSync('x25519'); + await viaCallback('sign digest too big for key', (cb) => sign('sha512', Buffer.from('message'), rsa.privateKey, cb)); + await viaCallback('verify with x25519 key', (cb) => verify(undefined, Buffer.from('message'), x25519.publicKey, Buffer.alloc(16), cb)); + await viaCallback('sign invalid padding', (cb) => sign('sha256', Buffer.from('message'), { key: rsa.privateKey, padding: 'x' }, cb)); + await viaCallback('verify mismatching signature', (cb) => verify('sha256', Buffer.from('message'), rsa.publicKey, Buffer.alloc(64), cb)); + + // A key of the wrong type is rejected synchronously and never reaches the callback. + const secretKey = createSecretKey(Buffer.alloc(32, 1)); + const message = Buffer.from('message'); + await viaCallback('sign with public KeyObject', (cb) => sign('sha256', message, rsa.publicKey, cb)); + await viaCallback('sign with nested secret KeyObject', (cb) => sign('sha256', message, { key: secretKey }, cb)); + await viaCallback('verify with secret KeyObject', (cb) => verify('sha256', message, secretKey, Buffer.alloc(64), cb)); + await viaCallback('verify with nested private KeyObject', (cb) => verify('sha256', message, { key: rsa.privateKey }, sign('sha256', message, rsa.privateKey), cb)); + + // Inherited and non-enumerable padding/saltLength options reach the job. + const pss = { padding: constants.RSA_PKCS1_PSS_PADDING, saltLength: 20 }; + const privatePem = rsa.privateKey.export({ format: 'pem', type: 'pkcs8' }); + const signatureKind = (signature) => `pkcs1=${verify('sha256', message, rsa.publicKey, signature)} pss=${verify('sha256', message, { key: rsa.publicKey, ...pss }, signature)}`; + await viaCallback('sign inherited PSS options', (cb) => sign('sha256', message, Object.assign(Object.create(pss), { key: privatePem }), cb), signatureKind); + await viaCallback('sign non-enumerable PSS options', (cb) => sign('sha256', message, Object.defineProperties({ key: privatePem }, { padding: { value: pss.padding }, saltLength: { value: pss.saltLength } }), cb), signatureKind); + await viaCallback('sign default padding', (cb) => sign('sha256', message, { key: privatePem }, cb), signatureKind); + const pssSignature = sign('sha256', message, { key: rsa.privateKey, ...pss }); + await viaCallback('verify inherited PSS options', (cb) => verify('sha256', message, Object.assign(Object.create(pss), { key: rsa.publicKey.export({ format: 'pem', type: 'spki' }) }), pssSignature, cb)); + await viaCallback('verify PSS signature with default padding', (cb) => verify('sha256', message, { key: rsa.publicKey }, pssSignature, cb)); + + const modp14 = getDiffieHellman('modp14'); + const alice = createDiffieHellman(modp14.getPrime(), modp14.getGenerator()); + alice.generateKeys(); + const pMinus1 = Buffer.from(modp14.getPrime()); + pMinus1[pMinus1.length - 1] -= 1; + check('DH computeSecret(1)', () => alice.computeSecret(Buffer.from([1]))); + check('DH computeSecret(p - 1)', () => alice.computeSecret(pMinus1)); + return lines; +} + +export async function webcryptoErrorContracts() { + const lines = []; + const describe = (e) => `${e.name} ${e.code} ${e.message}`; + const check = (name, fn) => { + try { + fn(); + lines.push(`${name}: ok`); + } catch (e) { + lines.push(`${name}: ${describe(e)}`); + } + }; + const checkAsync = async (name, fn) => { + try { + const value = await fn(); + lines.push(`${name}: ok ${value}`); + } catch (e) { + lines.push(`${name}: ${describe(e)}`); + } + }; + const { subtle } = crypto; + check('getRandomValues()', () => crypto.getRandomValues()); + check('getRandomValues(ArrayBuffer)', () => crypto.getRandomValues(new ArrayBuffer(1))); + check('getRandomValues(Float32Array)', () => crypto.getRandomValues(new Float32Array(1))); + check('getRandomValues(65537 bytes)', () => crypto.getRandomValues(new Uint8Array(65537))); + + const iv = new Uint8Array(16); + const cbcDecrypt = await subtle.importKey('raw', new Uint8Array(16), { name: 'AES-CBC' }, false, ['decrypt']); + const cbcEncrypt = await subtle.importKey('raw', new Uint8Array(16), { name: 'AES-CBC' }, false, ['encrypt']); + await checkAsync('encrypt without usage', () => subtle.encrypt({ name: 'AES-CBC', iv }, cbcDecrypt, new Uint8Array(1))); + await checkAsync('decrypt without usage', () => subtle.decrypt({ name: 'AES-CBC', iv }, cbcEncrypt, new Uint8Array(16))); + await checkAsync('decrypt wrong algorithm without usage', () => subtle.decrypt({ name: 'AES-CTR', counter: iv, length: 64 }, cbcEncrypt, new Uint8Array(16))); + const hmacSign = await subtle.importKey('raw', new Uint8Array(32), { name: 'HMAC', hash: 'SHA-256' }, true, ['sign']); + await checkAsync('verify without usage', () => subtle.verify('HMAC', hmacSign, new Uint8Array(32), new Uint8Array(1))); + const kw = await subtle.importKey('raw', new Uint8Array(16), { name: 'AES-KW' }, false, ['unwrapKey']); + await checkAsync('wrapKey without usage', () => subtle.wrapKey('raw', hmacSign, kw, 'AES-KW')); + + const hmac = (length, usages) => subtle.importKey('raw', new Uint8Array(32), { name: 'HMAC', hash: 'SHA-256', length }, false, usages); + await checkAsync('HMAC usage deriveBits', () => hmac(undefined, ['deriveBits'])); + await checkAsync('HMAC length 0', () => hmac(0, ['sign'])); + await checkAsync('HMAC length 384', () => hmac(384, ['sign'])); + const jwk = await subtle.exportKey('jwk', hmacSign); + lines.push(`HMAC SHA-256 jwk alg: ${jwk.alg}`); + await checkAsync('HMAC jwk alg HS384', () => subtle.importKey('jwk', { ...jwk, alg: 'HS384' }, { name: 'HMAC', hash: 'SHA-256' }, true, ['sign'])); + await checkAsync('HMAC jwk without alg', async () => (await subtle.importKey('jwk', { ...jwk, alg: undefined }, { name: 'HMAC', hash: 'SHA-256' }, true, ['sign'])).algorithm.length); + const sha3 = await subtle.importKey('raw', new Uint8Array(32), { name: 'HMAC', hash: 'SHA3-256' }, true, ['sign']); + lines.push(`HMAC SHA3-256 jwk alg: ${(await subtle.exportKey('jwk', sha3)).alg}`); + return lines; +} diff --git a/examples/runtime/crypto/wit/crypto.wit b/examples/runtime/crypto/wit/crypto.wit index f23230197..5e49286d1 100644 --- a/examples/runtime/crypto/wit/crypto.wit +++ b/examples/runtime/crypto/wit/crypto.wit @@ -35,4 +35,6 @@ world crypto { export subtle-sign-verify-hmac: func(message: string) -> bool; export subtle-sign-verify-ed25519: func(message: string) -> bool; export subtle-sign-verify-rsa-pss: func(message: string) -> bool; + export crypto-error-contracts: func() -> list; + export webcrypto-error-contracts: func() -> list; } diff --git a/tests/goldenfiles/generated_types_crypto_exports.d.ts b/tests/goldenfiles/generated_types_crypto_exports.d.ts index 52cf1e7cd..76e25a1c5 100644 --- a/tests/goldenfiles/generated_types_crypto_exports.d.ts +++ b/tests/goldenfiles/generated_types_crypto_exports.d.ts @@ -33,4 +33,6 @@ declare module 'crypto' { export function subtleSignVerifyHmac(message: string): boolean; export function subtleSignVerifyEd25519(message: string): boolean; export function subtleSignVerifyRsaPss(message: string): boolean; + export function cryptoErrorContracts(): string[]; + export function webcryptoErrorContracts(): string[]; } diff --git a/tests/node_compat/config.jsonc b/tests/node_compat/config.jsonc index d37775edd..bba630fa9 100644 --- a/tests/node_compat/config.jsonc +++ b/tests/node_compat/config.jsonc @@ -1578,31 +1578,31 @@ "split": true, "subtests": { "block_00_test_parallel_execution_w_keyobject_is_threadsafe_in_openssl": {}, - "block_01_block_01": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: error:06000068:public key routines::operation not supported for this keytype" }, - "block_02_block_02": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: error:0408006C:rsa routines::digest too big for rsa key" } + "block_01_block_01": {}, + "block_02_block_02": {} } }, "parallel/test-crypto-authenticated-stream.js": {}, "parallel/test-crypto-authenticated.js": { "split": true, "subtests": { - "block_00_non_authenticating_mode": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" }, - "block_01_throw": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" }, + "block_00_non_authenticating_mode": {}, + "block_01_throw": {}, "block_02_siv_and_gcm_siv_use_fixed_16_byte_authentication_tags": { "category": "unevaluated", "reason": "newly discovered subtest, not yet evaluated" }, - "block_03_test_that_gcm_can_produce_shorter_authentication_tags_than_1": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" }, - "block_04_test_that_users_can_manually_restrict_the_gcm_tag_length_to_": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" }, - "block_05_authentication_tag_length_has_been_specified": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:; carries 22.14.0 subtest block_04_authentication_tag_length_has_been_specified" }, - "block_06_authentication_tag_length_has_been_specified": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:; carries 22.14.0 subtest block_05_authentication_tag_has_been_specified" }, - "block_07_test_that_setaad_throws_if_an_invalid_plaintext_length_has_b": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" }, - "block_08_test_that_setaad_and_update_throw_if_the_plaintext_is_too_lo": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" }, - "block_09_been_specified": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" }, - "block_10_test_that_final_throws_in_ccm_mode_when_no_authentication_ta": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" }, - "block_11_test_that_setauthtag_does_not_throw_in_gcm_mode_when_called_": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" }, - "block_12_test_that_an_iv_length_of_11_does_not_overflow_max_message_s": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" }, - "block_13_final_in_gcm_mode_ocb_mode_and_for_chacha20_poly1305": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input; carries 22.14.0 subtest block_12_final_in_gcm_or_ocb_mode" }, - "block_14_test_that_setauthtag_can_only_be_called_once": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" }, - "block_15_https_www_openssl_org_news_secadv_20190306_txt": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" }, - "block_16_block_16": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" } + "block_03_test_that_gcm_can_produce_shorter_authentication_tags_than_1": {}, + "block_04_test_that_users_can_manually_restrict_the_gcm_tag_length_to_": {}, + "block_05_authentication_tag_length_has_been_specified": { "category": "runnable", "reason": "carries 22.14.0 subtest block_04_authentication_tag_length_has_been_specified" }, + "block_06_authentication_tag_length_has_been_specified": { "category": "runnable", "reason": "carries 22.14.0 subtest block_05_authentication_tag_has_been_specified" }, + "block_07_test_that_setaad_throws_if_an_invalid_plaintext_length_has_b": {}, + "block_08_test_that_setaad_and_update_throw_if_the_plaintext_is_too_lo": {}, + "block_09_been_specified": {}, + "block_10_test_that_final_throws_in_ccm_mode_when_no_authentication_ta": {}, + "block_11_test_that_setauthtag_does_not_throw_in_gcm_mode_when_called_": {}, + "block_12_test_that_an_iv_length_of_11_does_not_overflow_max_message_s": {}, + "block_13_final_in_gcm_mode_ocb_mode_and_for_chacha20_poly1305": { "category": "runnable", "reason": "carries 22.14.0 subtest block_12_final_in_gcm_or_ocb_mode" }, + "block_14_test_that_setauthtag_can_only_be_called_once": {}, + "block_15_https_www_openssl_org_news_secadv_20190306_txt": {}, + "block_16_block_16": {} } }, "parallel/test-crypto-certificate.js": { @@ -1676,8 +1676,8 @@ "parallel/test-crypto-encoding-validation-error.js": { "split": true, "subtests": { - "block_00_block_00": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: Expected values to be strictly deep-equal:" }, - "block_01_block_01": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: Expected values to be strictly deep-equal:" }, + "block_00_block_00": {}, + "block_01_block_01": {}, "block_02_block_02": {}, "block_03_block_03": {} } @@ -1692,7 +1692,7 @@ "block_02_block_02": {} } }, - "parallel/test-crypto-gcm-implicit-short-tag.js": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: Missing expected exception." }, + "parallel/test-crypto-gcm-implicit-short-tag.js": {}, "parallel/test-crypto-getcipherinfo.js": {}, "parallel/test-crypto-hash-stream-pipe.js": {}, "parallel/test-crypto-hash.js": { @@ -1704,7 +1704,7 @@ "block_03_block_03": { "category": "unevaluated", "reason": "newly discovered subtest, not yet evaluated" } } }, - "parallel/test-crypto-hkdf.js": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: Missing expected exception." }, + "parallel/test-crypto-hkdf.js": {}, "parallel/test-crypto-hmac.js": { "split": true, "subtests": { @@ -1763,7 +1763,7 @@ "parallel/test-crypto-keygen-async-rsa.js": {}, "parallel/test-crypto-keygen-bit-length.js": {}, "parallel/test-crypto-keygen-dh-classic.js": {}, - "parallel/test-crypto-keygen-eddsa.js": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: Missing expected exception (TypeError)." }, + "parallel/test-crypto-keygen-eddsa.js": {}, "parallel/test-crypto-keygen-empty-passphrase-no-error.js": {}, "parallel/test-crypto-keygen-empty-passphrase-no-prompt.js": { "category": "known-gap", "reason": "decoding empty-passphrase encrypted PEM traps in the WASM crypto backend" }, "parallel/test-crypto-keygen-invalid-parameter-encoding-dsa.js": {}, @@ -1782,7 +1782,7 @@ "split": true, "subtests": { "block_00_test_invalid_parameter_encoding": {}, - "block_01_block_01": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: Missing expected exception (TypeError)." }, + "block_01_block_01": {}, "block_02_block_02": {}, "block_03_block_03": {}, "block_04_test_rsa_parameters": {}, @@ -9701,9 +9701,9 @@ "parallel/test-webcrypto-encrypt-decrypt-aes.js": { "split": true, "subtests": { - "block_00_test_aes_cbc_vectors": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Expected values to be strictly" }, - "block_01_test_aes_ctr_vectors": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Expected values to be strictly" }, - "block_02_test_aes_gcm_vectors": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Expected values to be strictly" }, + "block_00_test_aes_cbc_vectors": {}, + "block_01_test_aes_ctr_vectors": {}, + "block_02_test_aes_gcm_vectors": {}, "block_03_block_03": {} } }, @@ -9711,9 +9711,9 @@ "parallel/test-webcrypto-encrypt-decrypt.js": { "split": true, "subtests": { - "block_00_test_encrypt_decrypt_aes_ctr": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Expected values to be strictly" }, - "block_01_test_encrypt_decrypt_aes_cbc": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Expected values to be strictly" }, - "block_02_test_encrypt_decrypt_aes_gcm": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Expected values to be strictly" } + "block_00_test_encrypt_decrypt_aes_ctr": {}, + "block_01_test_encrypt_decrypt_aes_cbc": {}, + "block_02_test_encrypt_decrypt_aes_gcm": {} } }, "parallel/test-webcrypto-export-import-cfrg.js": { "category": "known-gap", "reason": "OKP (Ed/X) key import/export compatibility is incomplete" }, @@ -9730,12 +9730,12 @@ "parallel/test-webcrypto-export-import.js": { "split": true, "subtests": { - "block_00_block_00": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Missing expected rejection (Da" }, + "block_00_block_00": {}, "block_01_hmac_non_byte_key_lengths": { "category": "unevaluated", "reason": "newly discovered subtest, not yet evaluated" }, - "block_02_import_export_hmac_secret_key": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Missing expected rejection (Da" }, - "block_03_import_export_aes_secret_key": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Missing expected rejection (Da" }, - "block_04_import_export_rsa_key_pairs": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Missing expected rejection (Da" }, - "block_05_import_export_ec_key_pairs": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Missing expected rejection (Da" }, + "block_02_import_export_hmac_secret_key": {}, + "block_03_import_export_aes_secret_key": {}, + "block_04_import_export_rsa_key_pairs": {}, + "block_05_import_export_ec_key_pairs": {}, "block_06_block_06": { "category": "unevaluated", "reason": "newly discovered subtest, not yet evaluated" } } }, @@ -9759,10 +9759,10 @@ "parallel/test-webcrypto-random.js": { "split": true, "subtests": { - "block_00_block_00": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: The error is expected to be an instance of \"TypeError\". Received \"DOMException\"" }, - "block_01_block_01": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: The error is expected to be an instance of \"TypeError\". Received \"DOMException\"" }, - "block_02_block_02": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: The error is expected to be an instance of \"TypeError\". Received \"DOMException\"" }, - "block_03_block_03": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: The error is expected to be an instance of \"TypeError\". Received \"DOMException\"" } + "block_00_block_00": {}, + "block_01_block_01": {}, + "block_02_block_02": { "category": "known-gap", "reason": "Node 26.13.1 baseline gap: QuotaExceededError is not defined (the Node 26 QuotaExceededError global is not implemented)" }, + "block_03_block_03": {} } }, "parallel/test-webcrypto-sign-verify-ecdsa.js": { "category": "known-gap", "reason": "ECDSA key import/sign/verify compatibility for test vectors is incomplete" }, diff --git a/tests/node_compat/mapping-22.14.0-to-26.13.1.json b/tests/node_compat/mapping-22.14.0-to-26.13.1.json index 43abe1c5b..86745f368 100644 --- a/tests/node_compat/mapping-22.14.0-to-26.13.1.json +++ b/tests/node_compat/mapping-22.14.0-to-26.13.1.json @@ -39,7 +39,7 @@ "unsplit / failed": 2, "unsplit / skipped": 6 }, - "baselineGapCases": 343, + "baselineGapCases": 305, "nowNodeInternalsCases": 45 }, "missingSources": [ @@ -4005,131 +4005,6 @@ "previous": {}, "error": "Expected values to be strictly equal:" }, - { - "file": "parallel/test-crypto-async-sign-verify.js", - "subtest": "block_01_block_01", - "baseline": true, - "previous": {}, - "error": "error:06000068:public key routines::operation not supported for this keytype" - }, - { - "file": "parallel/test-crypto-async-sign-verify.js", - "subtest": "block_02_block_02", - "baseline": true, - "previous": {}, - "error": "error:0408006C:rsa routines::digest too big for rsa key" - }, - { - "file": "parallel/test-crypto-authenticated.js", - "subtest": "block_00_non_authenticating_mode", - "baseline": true, - "previous": {}, - "error": "The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" - }, - { - "file": "parallel/test-crypto-authenticated.js", - "subtest": "block_01_throw", - "baseline": true, - "previous": {}, - "error": "The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" - }, - { - "file": "parallel/test-crypto-authenticated.js", - "subtest": "block_03_test_that_gcm_can_produce_shorter_authentication_tags_than_1", - "baseline": true, - "previous": {}, - "error": "The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" - }, - { - "file": "parallel/test-crypto-authenticated.js", - "subtest": "block_04_test_that_users_can_manually_restrict_the_gcm_tag_length_to_", - "baseline": true, - "previous": {}, - "error": "The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" - }, - { - "file": "parallel/test-crypto-authenticated.js", - "subtest": "block_05_authentication_tag_length_has_been_specified", - "baseline": true, - "previous": { - "category": "runnable", - "reason": "carries 22.14.0 subtest block_04_authentication_tag_length_has_been_specified" - }, - "error": "The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" - }, - { - "file": "parallel/test-crypto-authenticated.js", - "subtest": "block_06_authentication_tag_length_has_been_specified", - "baseline": true, - "previous": { - "category": "runnable", - "reason": "carries 22.14.0 subtest block_05_authentication_tag_has_been_specified" - }, - "error": "The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" - }, - { - "file": "parallel/test-crypto-authenticated.js", - "subtest": "block_07_test_that_setaad_throws_if_an_invalid_plaintext_length_has_b", - "baseline": true, - "previous": {}, - "error": "The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" - }, - { - "file": "parallel/test-crypto-authenticated.js", - "subtest": "block_08_test_that_setaad_and_update_throw_if_the_plaintext_is_too_lo", - "baseline": true, - "previous": {}, - "error": "The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" - }, - { - "file": "parallel/test-crypto-authenticated.js", - "subtest": "block_09_been_specified", - "baseline": true, - "previous": {}, - "error": "The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" - }, - { - "file": "parallel/test-crypto-authenticated.js", - "subtest": "block_10_test_that_final_throws_in_ccm_mode_when_no_authentication_ta", - "baseline": true, - "previous": {}, - "error": "The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" - }, - { - "file": "parallel/test-crypto-authenticated.js", - "subtest": "block_11_test_that_setauthtag_does_not_throw_in_gcm_mode_when_called_", - "baseline": true, - "previous": {}, - "error": "The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" - }, - { - "file": "parallel/test-crypto-authenticated.js", - "subtest": "block_12_test_that_an_iv_length_of_11_does_not_overflow_max_message_s", - "baseline": true, - "previous": {}, - "error": "The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" - }, - { - "file": "parallel/test-crypto-authenticated.js", - "subtest": "block_14_test_that_setauthtag_can_only_be_called_once", - "baseline": true, - "previous": {}, - "error": "The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" - }, - { - "file": "parallel/test-crypto-authenticated.js", - "subtest": "block_15_https_www_openssl_org_news_secadv_20190306_txt", - "baseline": true, - "previous": {}, - "error": "The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" - }, - { - "file": "parallel/test-crypto-authenticated.js", - "subtest": "block_16_block_16", - "baseline": true, - "previous": {}, - "error": "The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:" - }, { "file": "parallel/test-crypto-cipheriv-decipheriv.js", "subtest": "block_00_block_00", @@ -4221,34 +4096,6 @@ "previous": {}, "error": "Missing expected exception (TypeError)." }, - { - "file": "parallel/test-crypto-encoding-validation-error.js", - "subtest": "block_00_block_00", - "baseline": true, - "previous": {}, - "error": "Expected values to be strictly deep-equal:" - }, - { - "file": "parallel/test-crypto-encoding-validation-error.js", - "subtest": "block_01_block_01", - "baseline": true, - "previous": {}, - "error": "Expected values to be strictly deep-equal:" - }, - { - "file": "parallel/test-crypto-gcm-implicit-short-tag.js", - "subtest": null, - "baseline": true, - "previous": {}, - "error": "Missing expected exception." - }, - { - "file": "parallel/test-crypto-hkdf.js", - "subtest": null, - "baseline": true, - "previous": {}, - "error": "Missing expected exception." - }, { "file": "parallel/test-crypto-key-objects.js", "subtest": "block_00_block_00", @@ -4360,20 +4207,6 @@ "previous": {}, "error": "Failed to export key" }, - { - "file": "parallel/test-crypto-keygen-eddsa.js", - "subtest": null, - "baseline": true, - "previous": {}, - "error": "Missing expected exception (TypeError)." - }, - { - "file": "parallel/test-crypto-keygen.js", - "subtest": "block_01_block_01", - "baseline": true, - "previous": {}, - "error": "Missing expected exception (TypeError)." - }, { "file": "parallel/test-crypto-sign-verify.js", "subtest": "block_00_block_00", @@ -6015,110 +5848,12 @@ }, "error": "Unhandled promise rejection (likely cause of mustCall failure): Error: Module status must not be unlinked or l" }, - { - "file": "parallel/test-webcrypto-encrypt-decrypt-aes.js", - "subtest": "block_00_test_aes_cbc_vectors", - "baseline": true, - "previous": {}, - "error": "Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Expected values to be strictly" - }, - { - "file": "parallel/test-webcrypto-encrypt-decrypt-aes.js", - "subtest": "block_01_test_aes_ctr_vectors", - "baseline": true, - "previous": {}, - "error": "Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Expected values to be strictly" - }, - { - "file": "parallel/test-webcrypto-encrypt-decrypt-aes.js", - "subtest": "block_02_test_aes_gcm_vectors", - "baseline": true, - "previous": {}, - "error": "Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Expected values to be strictly" - }, - { - "file": "parallel/test-webcrypto-encrypt-decrypt.js", - "subtest": "block_00_test_encrypt_decrypt_aes_ctr", - "baseline": true, - "previous": {}, - "error": "Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Expected values to be strictly" - }, - { - "file": "parallel/test-webcrypto-encrypt-decrypt.js", - "subtest": "block_01_test_encrypt_decrypt_aes_cbc", - "baseline": true, - "previous": {}, - "error": "Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Expected values to be strictly" - }, - { - "file": "parallel/test-webcrypto-encrypt-decrypt.js", - "subtest": "block_02_test_encrypt_decrypt_aes_gcm", - "baseline": true, - "previous": {}, - "error": "Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Expected values to be strictly" - }, - { - "file": "parallel/test-webcrypto-export-import.js", - "subtest": "block_00_block_00", - "baseline": true, - "previous": {}, - "error": "Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Missing expected rejection (Da" - }, - { - "file": "parallel/test-webcrypto-export-import.js", - "subtest": "block_02_import_export_hmac_secret_key", - "baseline": true, - "previous": {}, - "error": "Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Missing expected rejection (Da" - }, - { - "file": "parallel/test-webcrypto-export-import.js", - "subtest": "block_03_import_export_aes_secret_key", - "baseline": true, - "previous": {}, - "error": "Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Missing expected rejection (Da" - }, - { - "file": "parallel/test-webcrypto-export-import.js", - "subtest": "block_04_import_export_rsa_key_pairs", - "baseline": true, - "previous": {}, - "error": "Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Missing expected rejection (Da" - }, - { - "file": "parallel/test-webcrypto-export-import.js", - "subtest": "block_05_import_export_ec_key_pairs", - "baseline": true, - "previous": {}, - "error": "Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Missing expected rejection (Da" - }, - { - "file": "parallel/test-webcrypto-random.js", - "subtest": "block_00_block_00", - "baseline": true, - "previous": {}, - "error": "The error is expected to be an instance of \"TypeError\". Received \"DOMException\"" - }, - { - "file": "parallel/test-webcrypto-random.js", - "subtest": "block_01_block_01", - "baseline": true, - "previous": {}, - "error": "The error is expected to be an instance of \"TypeError\". Received \"DOMException\"" - }, { "file": "parallel/test-webcrypto-random.js", "subtest": "block_02_block_02", "baseline": true, "previous": {}, - "error": "The error is expected to be an instance of \"TypeError\". Received \"DOMException\"" - }, - { - "file": "parallel/test-webcrypto-random.js", - "subtest": "block_03_block_03", - "baseline": true, - "previous": {}, - "error": "The error is expected to be an instance of \"TypeError\". Received \"DOMException\"" + "error": "QuotaExceededError is not defined" }, { "file": "parallel/test-webstorage.js", @@ -6262,15 +5997,6 @@ }, "error": "Unhandled promise rejection: AssertionError: 'a\\rb' !== 'a\\nb'" }, - { - "file": "parallel/test-crypto-authenticated.js", - "subtest": "block_13_final_in_gcm_mode_ocb_mode_and_for_chacha20_poly1305", - "baseline": true, - "previous": { - "category": "unevaluated" - }, - "error": "The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input" - }, { "file": "parallel/test-sqlite.js", "subtest": "test_08_sql_apis_enabled_at_build_time", @@ -6315,6 +6041,198 @@ "subtest": null, "fix": "process.release.lts reports 'Lithium', the LTS codename of 26.13.1 in the official dist index" } + ], + "repaired": [ + { + "file": "parallel/test-crypto-authenticated.js", + "subtest": "block_00_non_authenticating_mode", + "fix": "Decipheriv#final reports a missing or mismatched AEAD tag as Node does: Error 'Unsupported state or unable to authenticate data' without a code" + }, + { + "file": "parallel/test-crypto-authenticated.js", + "subtest": "block_01_throw", + "fix": "Decipheriv#final reports a missing or mismatched AEAD tag as Node does: Error 'Unsupported state or unable to authenticate data' without a code" + }, + { + "file": "parallel/test-crypto-authenticated.js", + "subtest": "block_03_test_that_gcm_can_produce_shorter_authentication_tags_than_1", + "fix": "Decipheriv#final reports a missing or mismatched AEAD tag as Node does: Error 'Unsupported state or unable to authenticate data' without a code" + }, + { + "file": "parallel/test-crypto-authenticated.js", + "subtest": "block_04_test_that_users_can_manually_restrict_the_gcm_tag_length_to_", + "fix": "Decipheriv#final reports a missing or mismatched AEAD tag as Node does: Error 'Unsupported state or unable to authenticate data' without a code" + }, + { + "file": "parallel/test-crypto-authenticated.js", + "subtest": "block_05_authentication_tag_length_has_been_specified", + "fix": "Decipheriv#final reports a missing or mismatched AEAD tag as Node does: Error 'Unsupported state or unable to authenticate data' without a code" + }, + { + "file": "parallel/test-crypto-authenticated.js", + "subtest": "block_06_authentication_tag_length_has_been_specified", + "fix": "Decipheriv#final reports a missing or mismatched AEAD tag as Node does: Error 'Unsupported state or unable to authenticate data' without a code" + }, + { + "file": "parallel/test-crypto-authenticated.js", + "subtest": "block_07_test_that_setaad_throws_if_an_invalid_plaintext_length_has_b", + "fix": "Decipheriv#final reports a missing or mismatched AEAD tag as Node does: Error 'Unsupported state or unable to authenticate data' without a code" + }, + { + "file": "parallel/test-crypto-authenticated.js", + "subtest": "block_08_test_that_setaad_and_update_throw_if_the_plaintext_is_too_lo", + "fix": "Decipheriv#final reports a missing or mismatched AEAD tag as Node does: Error 'Unsupported state or unable to authenticate data' without a code" + }, + { + "file": "parallel/test-crypto-authenticated.js", + "subtest": "block_09_been_specified", + "fix": "Decipheriv#final reports a missing or mismatched AEAD tag as Node does: Error 'Unsupported state or unable to authenticate data' without a code" + }, + { + "file": "parallel/test-crypto-authenticated.js", + "subtest": "block_10_test_that_final_throws_in_ccm_mode_when_no_authentication_ta", + "fix": "Decipheriv#final reports a missing or mismatched AEAD tag as Node does: Error 'Unsupported state or unable to authenticate data' without a code" + }, + { + "file": "parallel/test-crypto-authenticated.js", + "subtest": "block_11_test_that_setauthtag_does_not_throw_in_gcm_mode_when_called_", + "fix": "Decipheriv#final reports a missing or mismatched AEAD tag as Node does: Error 'Unsupported state or unable to authenticate data' without a code" + }, + { + "file": "parallel/test-crypto-authenticated.js", + "subtest": "block_12_test_that_an_iv_length_of_11_does_not_overflow_max_message_s", + "fix": "Decipheriv#final reports a missing or mismatched AEAD tag as Node does: Error 'Unsupported state or unable to authenticate data' without a code" + }, + { + "file": "parallel/test-crypto-authenticated.js", + "subtest": "block_14_test_that_setauthtag_can_only_be_called_once", + "fix": "Decipheriv#final reports a missing or mismatched AEAD tag as Node does: Error 'Unsupported state or unable to authenticate data' without a code" + }, + { + "file": "parallel/test-crypto-authenticated.js", + "subtest": "block_15_https_www_openssl_org_news_secadv_20190306_txt", + "fix": "Decipheriv#final reports a missing or mismatched AEAD tag as Node does: Error 'Unsupported state or unable to authenticate data' without a code" + }, + { + "file": "parallel/test-crypto-authenticated.js", + "subtest": "block_16_block_16", + "fix": "Decipheriv#final reports a missing or mismatched AEAD tag as Node does: Error 'Unsupported state or unable to authenticate data' without a code" + }, + { + "file": "parallel/test-crypto-authenticated.js", + "subtest": "block_13_final_in_gcm_mode_ocb_mode_and_for_chacha20_poly1305", + "fix": "Decipheriv#final reports a missing or mismatched AEAD tag as Node does: Error 'Unsupported state or unable to authenticate data' without a code" + }, + { + "file": "parallel/test-webcrypto-random.js", + "subtest": "block_00_block_00", + "fix": "crypto.getRandomValues rejects missing and non-ArrayBufferView arguments with Node's WebIDL TypeErrors (ERR_MISSING_ARGS, ERR_INVALID_ARG_TYPE) and reports TypeMismatchError and QuotaExceededError with Node's messages" + }, + { + "file": "parallel/test-webcrypto-random.js", + "subtest": "block_01_block_01", + "fix": "crypto.getRandomValues rejects missing and non-ArrayBufferView arguments with Node's WebIDL TypeErrors (ERR_MISSING_ARGS, ERR_INVALID_ARG_TYPE) and reports TypeMismatchError and QuotaExceededError with Node's messages" + }, + { + "file": "parallel/test-webcrypto-random.js", + "subtest": "block_03_block_03", + "fix": "crypto.getRandomValues rejects missing and non-ArrayBufferView arguments with Node's WebIDL TypeErrors (ERR_MISSING_ARGS, ERR_INVALID_ARG_TYPE) and reports TypeMismatchError and QuotaExceededError with Node's messages" + }, + { + "file": "parallel/test-webcrypto-encrypt-decrypt.js", + "subtest": "block_00_test_encrypt_decrypt_aes_ctr", + "fix": "SubtleCrypto encrypt/decrypt check the key algorithm before its usages and report 'Key algorithm mismatch' or 'Unable to use this key to ' as Node does" + }, + { + "file": "parallel/test-webcrypto-encrypt-decrypt.js", + "subtest": "block_01_test_encrypt_decrypt_aes_cbc", + "fix": "SubtleCrypto encrypt/decrypt check the key algorithm before its usages and report 'Key algorithm mismatch' or 'Unable to use this key to ' as Node does" + }, + { + "file": "parallel/test-webcrypto-encrypt-decrypt.js", + "subtest": "block_02_test_encrypt_decrypt_aes_gcm", + "fix": "SubtleCrypto encrypt/decrypt check the key algorithm before its usages and report 'Key algorithm mismatch' or 'Unable to use this key to ' as Node does" + }, + { + "file": "parallel/test-webcrypto-encrypt-decrypt-aes.js", + "subtest": "block_00_test_aes_cbc_vectors", + "fix": "SubtleCrypto encrypt/decrypt check the key algorithm before its usages and report 'Key algorithm mismatch' or 'Unable to use this key to ' as Node does" + }, + { + "file": "parallel/test-webcrypto-encrypt-decrypt-aes.js", + "subtest": "block_01_test_aes_ctr_vectors", + "fix": "SubtleCrypto encrypt/decrypt check the key algorithm before its usages and report 'Key algorithm mismatch' or 'Unable to use this key to ' as Node does" + }, + { + "file": "parallel/test-webcrypto-encrypt-decrypt-aes.js", + "subtest": "block_02_test_aes_gcm_vectors", + "fix": "SubtleCrypto encrypt/decrypt check the key algorithm before its usages and report 'Key algorithm mismatch' or 'Unable to use this key to ' as Node does" + }, + { + "file": "parallel/test-webcrypto-export-import.js", + "subtest": "block_00_block_00", + "fix": "HMAC import reports Node's usage and zero-length messages, and WebCrypto HMAC JWKs export and validate the registered 'alg' value (none for SHA-3) as Node does" + }, + { + "file": "parallel/test-webcrypto-export-import.js", + "subtest": "block_02_import_export_hmac_secret_key", + "fix": "HMAC import reports Node's usage and zero-length messages, and WebCrypto HMAC JWKs export and validate the registered 'alg' value (none for SHA-3) as Node does" + }, + { + "file": "parallel/test-webcrypto-export-import.js", + "subtest": "block_03_import_export_aes_secret_key", + "fix": "HMAC import reports Node's usage and zero-length messages, and WebCrypto HMAC JWKs export and validate the registered 'alg' value (none for SHA-3) as Node does" + }, + { + "file": "parallel/test-webcrypto-export-import.js", + "subtest": "block_04_import_export_rsa_key_pairs", + "fix": "HMAC import reports Node's usage and zero-length messages, and WebCrypto HMAC JWKs export and validate the registered 'alg' value (none for SHA-3) as Node does" + }, + { + "file": "parallel/test-webcrypto-export-import.js", + "subtest": "block_05_import_export_ec_key_pairs", + "fix": "HMAC import reports Node's usage and zero-length messages, and WebCrypto HMAC JWKs export and validate the registered 'alg' value (none for SHA-3) as Node does" + }, + { + "file": "parallel/test-crypto-gcm-implicit-short-tag.js", + "subtest": null, + "fix": "Decipheriv#setAuthTag accepts only a 16-byte GCM tag when authTagLength is not set, as Node 26 does after removing implicit short tags (DEP0182)" + }, + { + "file": "parallel/test-crypto-hkdf.js", + "subtest": null, + "fix": "hkdf and hkdfSync read the info view's intrinsic byte range, so a user-defined byteLength cannot bypass the 1024-byte limit" + }, + { + "file": "parallel/test-crypto-encoding-validation-error.js", + "subtest": "block_00_block_00", + "fix": "Cipheriv/Decipheriv report an output-encoding change as ERR_INVALID_ARG_VALUE \"The argument 'outputEncoding' cannot be changed from ''\"" + }, + { + "file": "parallel/test-crypto-encoding-validation-error.js", + "subtest": "block_01_block_01", + "fix": "Cipheriv/Decipheriv report an output-encoding change as ERR_INVALID_ARG_VALUE \"The argument 'outputEncoding' cannot be changed from ''\"" + }, + { + "file": "parallel/test-crypto-keygen-eddsa.js", + "subtest": null, + "fix": "generateKeyPair rejects unsupported key types synchronously with ERR_INVALID_ARG_VALUE, as generateKeyPairSync and Node do" + }, + { + "file": "parallel/test-crypto-keygen.js", + "subtest": "block_01_block_01", + "fix": "generateKeyPair rejects unsupported key types synchronously with ERR_INVALID_ARG_VALUE, as generateKeyPairSync and Node do" + }, + { + "file": "parallel/test-crypto-async-sign-verify.js", + "subtest": "block_01_block_01", + "fix": "One-shot sign() and verify() validate options and parse the key synchronously and deliver errors of the signing job itself (such as an RSA key too small for the digest or a non-signing x25519 key) to the callback, as Node does" + }, + { + "file": "parallel/test-crypto-async-sign-verify.js", + "subtest": "block_02_block_02", + "fix": "One-shot sign() and verify() validate options and parse the key synchronously and deliver errors of the signing job itself (such as an RSA key too small for the digest or a non-signing x25519 key) to the callback, as Node does" + } ] }, "matchedByPosition": [ diff --git a/tests/node_compat/report.md b/tests/node_compat/report.md index 150058497..04985debc 100644 --- a/tests/node_compat/report.md +++ b/tests/node_compat/report.md @@ -8,21 +8,21 @@ This report is generated from `config.jsonc` and the pinned vendored Node.js sou Primary compatibility is measured over the public API surface we can provide: CI-enforced passing (`runnable`) plus `known-gap`. WASI-impossible tests, engine differences, unevaluated tests, and Node.js-internals tests are acknowledged separately and excluded from the primary percentage. -**Primary compatibility (CI-enforced):** 2864/4452 (64.3%) +**Primary compatibility (CI-enforced):** 2902/4452 (65.2%) When comparing revisions, read the runnable count and secondary full-public percentage alongside the primary percentage. Reclassifying a test into an excluded category can increase the primary percentage without increasing runnable coverage. | Classification | Count | Primary % | Public inventory % | All listed % | |----------------|-------|-----------|--------------------|--------------| -| ✅ passing (runnable) | 2864 | 64.3% | 29.8% | 26.6% | -| 🧩 known gap | 1588 | 35.7% | 16.5% | 14.7% | +| ✅ passing (runnable) | 2902 | 65.2% | 30.2% | 26.9% | +| 🧩 known gap | 1550 | 34.8% | 16.1% | 14.4% | | 🚫 WASI-impossible (excluded) | 1148 | — | 11.9% | 10.6% | | ⚙️ engine difference (excluded) | 167 | — | 1.7% | 1.5% | | ❔ unevaluated (excluded) | 3845 | — | 40.0% | 35.6% | | 🔒 Node.js internals (excluded) | 1175 | — | — | 10.9% | | **Total** | **10787** | | | **100.0%** | -Secondary full-public compatibility, including public tests that are currently excluded from primary: **2864/9612 (29.8%)**. +Secondary full-public compatibility, including public tests that are currently excluded from primary: **2902/9612 (30.2%)**. ## Inventory by Module @@ -39,7 +39,7 @@ Secondary full-public compatibility, including public tests that are currently e | common | 16 | 1 | 8 | 0 | 0 | 7 | 0 | 11.1% | 6.2% | | compile | 29 | 0 | 0 | 0 | 15 | 14 | 0 | 0.0% | 0.0% | | console | 32 | 28 | 2 | 0 | 0 | 1 | 1 | 93.3% | 90.3% | -| crypto | 398 | 137 | 76 | 7 | 0 | 171 | 7 | 64.3% | 35.0% | +| crypto | 398 | 161 | 52 | 7 | 0 | 171 | 7 | 75.6% | 41.2% | | dgram | 141 | 22 | 74 | 7 | 0 | 24 | 14 | 22.9% | 17.3% | | diagnostics_channel | 102 | 23 | 7 | 1 | 2 | 69 | 0 | 76.7% | 22.5% | | dns | 54 | 2 | 29 | 0 | 0 | 9 | 14 | 6.5% | 5.0% | @@ -84,7 +84,7 @@ Secondary full-public compatibility, including public tests that are currently e | util | 235 | 27 | 70 | 0 | 0 | 20 | 118 | 27.8% | 23.1% | | v8 | 57 | 14 | 1 | 0 | 30 | 12 | 0 | 93.3% | 24.6% | | vm | 173 | 68 | 44 | 3 | 13 | 45 | 0 | 60.7% | 39.3% | -| webcrypto | 175 | 29 | 36 | 1 | 0 | 62 | 47 | 44.6% | 22.7% | +| webcrypto | 175 | 43 | 22 | 1 | 0 | 62 | 47 | 66.2% | 33.6% | | webstreams | 89 | 65 | 2 | 0 | 0 | 21 | 1 | 97.0% | 73.9% | | whatwg | 322 | 41 | 37 | 0 | 0 | 59 | 185 | 52.6% | 29.9% | | worker_threads | 202 | 25 | 29 | 127 | 0 | 13 | 8 | 46.3% | 12.9% | @@ -200,15 +200,15 @@ Secondary full-public compatibility, including public tests that are currently e | `test-console-group.js` | 8 | 8 | 0 | 0 | 0 | 0 | 0 | | `test-console-instance.js` | 4 | 4 | 0 | 0 | 0 | 0 | 0 | | `test-crypto-argon2.js` | 2 | 0 | 0 | 0 | 0 | 2 | 0 | -| `test-crypto-async-sign-verify.js` | 3 | 1 | 2 | 0 | 0 | 0 | 0 | -| `test-crypto-authenticated.js` | 17 | 0 | 16 | 0 | 0 | 1 | 0 | +| `test-crypto-async-sign-verify.js` | 3 | 3 | 0 | 0 | 0 | 0 | 0 | +| `test-crypto-authenticated.js` | 17 | 16 | 0 | 0 | 0 | 1 | 0 | | `test-crypto-certificate.js` | 3 | 3 | 0 | 0 | 0 | 0 | 0 | | `test-crypto-cipheriv-decipheriv.js` | 4 | 0 | 4 | 0 | 0 | 0 | 0 | | `test-crypto-dh-constructor.js` | 3 | 3 | 0 | 0 | 0 | 0 | 0 | | `test-crypto-dh-stateless.js` | 8 | 0 | 8 | 0 | 0 | 0 | 0 | | `test-crypto-dh.js` | 3 | 3 | 0 | 0 | 0 | 0 | 0 | | `test-crypto-ecb.js` | 2 | 2 | 0 | 0 | 0 | 0 | 0 | -| `test-crypto-encoding-validation-error.js` | 4 | 2 | 2 | 0 | 0 | 0 | 0 | +| `test-crypto-encoding-validation-error.js` | 4 | 4 | 0 | 0 | 0 | 0 | 0 | | `test-crypto-gcm-explicit-short-tag.js` | 3 | 3 | 0 | 0 | 0 | 0 | 0 | | `test-crypto-hash.js` | 4 | 3 | 0 | 0 | 0 | 1 | 0 | | `test-crypto-hmac.js` | 10 | 7 | 0 | 0 | 0 | 3 | 0 | @@ -217,7 +217,7 @@ Secondary full-public compatibility, including public tests that are currently e | `test-crypto-key-objects.js` | 20 | 0 | 16 | 0 | 0 | 4 | 0 | | `test-crypto-key-store.js` | 10 | 0 | 0 | 0 | 0 | 10 | 0 | | `test-crypto-keygen-raw.js` | 12 | 0 | 0 | 0 | 0 | 12 | 0 | -| `test-crypto-keygen.js` | 10 | 9 | 1 | 0 | 0 | 0 | 0 | +| `test-crypto-keygen.js` | 10 | 10 | 0 | 0 | 0 | 0 | 0 | | `test-crypto-keyobject-hidden-slots.js` | 6 | 0 | 0 | 0 | 0 | 6 | 0 | | `test-crypto-negative-zero.js` | 5 | 0 | 0 | 0 | 0 | 5 | 0 | | `test-crypto-pbkdf2.js` | 2 | 2 | 0 | 0 | 0 | 0 | 0 | @@ -964,14 +964,14 @@ Secondary full-public compatibility, including public tests that are currently e | `test-webcrypto-deduplicate-usages.js` | 5 | 0 | 0 | 0 | 0 | 5 | 0 | | `test-webcrypto-derivebits.js` | 5 | 0 | 2 | 0 | 0 | 1 | 2 | | `test-webcrypto-derivekey.js` | 6 | 3 | 3 | 0 | 0 | 0 | 0 | -| `test-webcrypto-encrypt-decrypt-aes.js` | 4 | 1 | 3 | 0 | 0 | 0 | 0 | +| `test-webcrypto-encrypt-decrypt-aes.js` | 4 | 4 | 0 | 0 | 0 | 0 | 0 | | `test-webcrypto-encrypt-decrypt-chacha20-poly1305.js` | 3 | 0 | 0 | 0 | 0 | 3 | 0 | -| `test-webcrypto-encrypt-decrypt.js` | 3 | 0 | 3 | 0 | 0 | 0 | 0 | +| `test-webcrypto-encrypt-decrypt.js` | 3 | 3 | 0 | 0 | 0 | 0 | 0 | | `test-webcrypto-export-import-ec.js` | 2 | 0 | 2 | 0 | 0 | 0 | 0 | -| `test-webcrypto-export-import.js` | 7 | 0 | 5 | 0 | 0 | 2 | 0 | +| `test-webcrypto-export-import.js` | 7 | 5 | 0 | 0 | 0 | 2 | 0 | | `test-webcrypto-keygen.js` | 9 | 0 | 0 | 0 | 0 | 0 | 9 | | `test-webcrypto-prototype-pollution.mjs` | 11 | 0 | 0 | 0 | 0 | 11 | 0 | -| `test-webcrypto-random.js` | 4 | 0 | 4 | 0 | 0 | 0 | 0 | +| `test-webcrypto-random.js` | 4 | 3 | 1 | 0 | 0 | 0 | 0 | | `test-webcrypto-sign-verify.js` | 5 | 5 | 0 | 0 | 0 | 0 | 0 | | `test-webcrypto-util.js` | 5 | 0 | 0 | 0 | 0 | 0 | 5 | | `test-webcrypto-webidl.js` | 31 | 0 | 0 | 0 | 0 | 0 | 31 | @@ -1094,29 +1094,28 @@ Secondary full-public compatibility, including public tests that are currently e ## Classified Non-Runnable Tests -### known gap (1588) +### known gap (1550) | Reason | Count | Example entries | |--------|-------|-----------------| | node:http2 public API is a stub in WebAssembly runtime | 106 | `parallel/test-http2-head-request.js`, `parallel/test-http2-info-headers.js`, `parallel/test-http2-invalidargtypes-errors.js`, ... (+103) | | Node 26.13.1 baseline gap: Expected values to be strictly equal: | 65 | `es-module/test-require-module-twice.js`, `es-module/test-require-module.js#block_02_test_esm_that_import_cjs`, `parallel/test-console.js`, ... (+62) | | requires isolated process.execPath TypeScript entry execution and Node CLI flags; the direct process.features check requires a separate feature-disabled component | 30 | `es-module/test-typescript.mjs#test_00_expect_process_features_typescript_to_be_false_when_no_exper`, `es-module/test-typescript.mjs#test_01_execute_a_typescript_file`, `es-module/test-typescript.mjs#test_02_execute_a_typescript_file_with_imports`, ... (+27) | -| Node 26.13.1 baseline gap: Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Expected values to be strictly | 29 | `es-module/test-esm-import-attributes-errors.js`, `es-module/test-require-module-cached-tla.js`, `es-module/test-require-module-dynamic-import-1.js`, ... (+26) | | requires simulated process.execPath / Node CLI mode support deferred to follow-up PR | 29 | `es-module/test-esm-cjs-load-error-note.mjs`, `es-module/test-esm-detect-ambiguous.mjs#test_00_module_syntax_detection`, `es-module/test-esm-detect-ambiguous.mjs#test_01_wrapping_a_require_of_an_es_module_while_using_abort_on_unca`, ... (+26) | | Node 26.13.1 baseline gap: Failed to export key | 26 | `parallel/test-crypto-key-objects.js#block_00_block_00`, `parallel/test-crypto-key-objects.js#block_01_block_01`, `parallel/test-crypto-key-objects.js#block_02_block_02`, ... (+23) | | Node 26.13.1 baseline gap: not a function | 26 | `parallel/test-sqlite-session.js#test_00_creating_and_applying_a_changeset`, `parallel/test-sqlite-session.js#test_01_database_createsession_closed_database_results_in_exception`, `parallel/test-sqlite-session.js#test_02_session_changeset_closed_database_results_in_exception`, ... (+23) | | requires isolated process.execPath --eval execution, TypeScript input-type flags, and child warning/output/exit capture | 24 | `es-module/test-typescript-eval.mjs#test_00_eval_typescript_esm_syntax`, `es-module/test-typescript-eval.mjs#test_01_eval_typescript_esm_syntax_with_input_type_module`, `es-module/test-typescript-eval.mjs#test_02_eval_typescript_commonjs_syntax`, ... (+21) | | requires isolated process.execPath TypeScript entry execution and Node CLI default-module / require-module flag handling | 24 | `es-module/test-typescript-commonjs.mjs#test_00_require_a_ts_file_with_explicit_extension_succeeds`, `es-module/test-typescript-commonjs.mjs#test_01_eval_require_a_ts_file_with_implicit_extension_fails`, `es-module/test-typescript-commonjs.mjs#test_02_eval_require_a_cts_file_with_implicit_extension_fails`, ... (+21) | -| Node 26.13.1 baseline gap: Expected values to be strictly deep-equal: | 23 | `es-module/test-esm-import-attributes-errors.mjs`, `es-module/test-esm-import-meta.mjs`, `es-module/test-require-module-error-catching.js`, ... (+20) | +| Node 26.13.1 baseline gap: Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Expected values to be strictly | 23 | `es-module/test-esm-import-attributes-errors.js`, `es-module/test-require-module-cached-tla.js`, `es-module/test-require-module-dynamic-import-1.js`, ... (+20) | | stream edge case not yet handled | 22 | `parallel/test-stream-compose.js#block_17_block_17`, `parallel/test-stream-drop-take.js#block_01_don_t_wait_for_next_item_in_the_original_stream_when_already`, `parallel/test-stream-duplex-from.js#block_17_block_17`, ... (+19) | +| Node 26.13.1 baseline gap: Expected values to be strictly deep-equal: | 21 | `es-module/test-esm-import-attributes-errors.mjs`, `es-module/test-esm-import-meta.mjs`, `es-module/test-require-module-error-catching.js`, ... (+18) | | Node 26.13.1 baseline gap: mustCall verification failed: | 20 | `parallel/test-domain-with-abort-on-uncaught-exception.js`, `parallel/test-fs-watch-recursive-watch-file.js`, `parallel/test-http-outgoing-writableFinished.js#block_01_finish_the_end_callback_receives_the_write_error_instead`, ... (+17) | | process.permission and --permission CLI semantics are incomplete in execPath emulation | 19 | `parallel/test-cli-permission-deny-fs.js#block_00_block_00`, `parallel/test-cli-permission-deny-fs.js#block_01_block_01`, `parallel/test-cli-permission-deny-fs.js#block_02_block_02`, ... (+16) | -| Node 26.13.1 baseline gap: Missing expected exception. | 16 | `parallel/test-assert-deep.js#test_02_date`, `parallel/test-assert-deep.js#test_03_regexp`, `parallel/test-assert-deep.js#test_07_gh_14441_circular_structures_should_be_consistent`, ... (+13) | -| Node 26.13.1 baseline gap: Missing expected exception (TypeError). | 14 | `parallel/test-buffer-pool-untransferable.js`, `parallel/test-crypto-dh-stateless.js#block_00_block_00`, `parallel/test-crypto-dh-stateless.js#block_01_block_01`, ... (+11) | +| Node 26.13.1 baseline gap: Missing expected exception. | 14 | `parallel/test-assert-deep.js#test_02_date`, `parallel/test-assert-deep.js#test_03_regexp`, `parallel/test-assert-deep.js#test_07_gh_14441_circular_structures_should_be_consistent`, ... (+11) | | wasi:sockets UDP implementation crashes in wasmtime | 14 | `parallel/test-dgram-connect-send-callback-buffer.js`, `parallel/test-dgram-connect-send-callback-multi-buffer.js`, `parallel/test-dgram-connect-send-default-host.js`, ... (+11) | -| Node 26.13.1 baseline gap: The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input: | 13 | `parallel/test-crypto-authenticated.js#block_00_non_authenticating_mode`, `parallel/test-crypto-authenticated.js#block_01_throw`, `parallel/test-crypto-authenticated.js#block_03_test_that_gcm_can_produce_shorter_authentication_tags_than_1`, ... (+10) | | domain module depends on async_hooks, not fully working | 13 | `parallel/test-domain-promise.js#block_00_block_00`, `parallel/test-domain-promise.js#block_01_block_01`, `parallel/test-domain-promise.js#block_03_block_03`, ... (+10) | | the shared fixture creates rooted symlink targets that cannot be resolved inside a WASI preopen | 13 | `sequential/test-fs-opendir-recursive.js#block_00_block_00`, `sequential/test-fs-opendir-recursive.js#block_01_block_01`, `sequential/test-fs-opendir-recursive.js#block_02_block_02`, ... (+10) | +| Node 26.13.1 baseline gap: Missing expected exception (TypeError). | 12 | `parallel/test-buffer-pool-untransferable.js`, `parallel/test-crypto-dh-stateless.js#block_00_block_00`, `parallel/test-crypto-dh-stateless.js#block_01_block_01`, ... (+9) | | node:readline module is not yet supported in WebAssembly environment | 12 | `parallel/test-readline-keys.js`, `parallel/test-readline-position.js`, `parallel/test-readline-reopen.js`, ... (+9) | | inherited: dns.getServers()/setServers default-server behavior and validation are not Node-compatible | 11 | `parallel/test-dns.js#block_00_verify_that_setservers_handles_arrays_with_holes_and_other_o`, `parallel/test-dns.js#block_01_block_01`, `parallel/test-dns.js#block_02_block_02`, ... (+8) | | inherited: process.permission and --permission CLI semantics are incomplete in execPath emulation | 11 | `parallel/test-permission-allow-child-process-cli.js#block_00_guarantee_the_initial_state`, `parallel/test-permission-allow-child-process-cli.js#block_01_to_spawn_unless_allow_child_process_is_sent`, `parallel/test-permission-allow-wasi-cli.js#block_00_guarantee_the_initial_state`, ... (+8) | @@ -1144,7 +1143,6 @@ Secondary full-public compatibility, including public tests that are currently e | same-process import.meta.resolve behavior is covered by runtime tests; remaining vendored failure requires child_process execPath emulation for --input-type/--import ESM CLI modes | 6 | `es-module/test-esm-import-meta-resolve.mjs#block_00_block_00`, `es-module/test-esm-import-meta-resolve.mjs#block_01_block_01`, `es-module/test-esm-import-meta-resolve.mjs#block_02_block_02`, ... (+3) | | the test's meaningful body requires rooted symlink targets; common.canCreateSymLink skips it under the supported relative-only WASI boundary | 6 | `parallel/test-fs-options-immutable.js#block_00_block_00`, `parallel/test-fs-options-immutable.js#block_01_block_01`, `parallel/test-fs-options-immutable.js#block_02_block_02`, ... (+3) | | Node 26.13.1 baseline gap: 5 test(s) failed | 5 | `parallel/test-sqlite-database.js#test_03_database_prototype_prepare`, `parallel/test-sqlite-database.js#test_04_database_prototype_exec`, `parallel/test-sqlite-database.js#test_06_database_prototype_location`, ... (+2) | -| Node 26.13.1 baseline gap: Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Missing expected rejection (Da | 5 | `parallel/test-webcrypto-export-import.js#block_00_block_00`, `parallel/test-webcrypto-export-import.js#block_02_import_export_hmac_secret_key`, `parallel/test-webcrypto-export-import.js#block_03_import_export_aes_secret_key`, ... (+2) | | common-shim spawnPromisified child emulation does not support --experimental-webstorage/--localstorage-file flags | 5 | `parallel/test-webstorage.js#test_00_storage_instances_cannot_be_created_in_userland`, `parallel/test-webstorage.js#test_02_sessionstorage_is_not_persisted`, `parallel/test-webstorage.js#test_05_localstorage_is_not_persisted_if_it_is_unused`, ... (+2) | | inherited: buffer.transcode and ICU transcoding are not implemented | 5 | `parallel/test-icu-transcode.js#block_00_block_00`, `parallel/test-icu-transcode.js#block_01_block_01`, `parallel/test-icu-transcode.js#block_02_test_that_uint8array_arguments_are_okay`, ... (+2) | | inherited: perf_hooks PerformanceResourceTiming/markResourceTiming behavior is incomplete | 5 | `parallel/test-perf-hooks-resourcetiming.js#block_00_performanceresourcetiming_should_not_be_initialized_external`, `parallel/test-perf-hooks-resourcetiming.js#block_01_using_performance_getentries`, `parallel/test-perf-hooks-resourcetiming.js#block_02_default_values`, ... (+2) | @@ -1157,7 +1155,6 @@ Secondary full-public compatibility, including public tests that are currently e | Node 26.13.1 baseline gap: 3 test(s) failed | 4 | `parallel/test-sqlite-database.js#test_01_database_prototype_open`, `parallel/test-sqlite-database.js#test_05_database_prototype_istransaction`, `parallel/test-sqlite-named-parameters.js#test_01_statement_prototype_setallowunknownnamedparameters`, ... (+1) | | Node 26.13.1 baseline gap: 7 test(s) failed | 4 | `parallel/test-sqlite-data-types.js`, `parallel/test-sqlite-statement.js#test_01_statement_prototype_get`, `parallel/test-sqlite-statement.js#test_04_statement_prototype_run`, ... (+1) | | Node 26.13.1 baseline gap: Expected values to be strictly deep-equal:; carries 22.14.0 es-module/test-require-module-tla.js (upstream 8d10bc7b09) | 4 | `es-module/test-require-module-tla-nested.js`, `es-module/test-require-module-tla-rejected.js`, `es-module/test-require-module-tla-resolved.js`, ... (+1) | -| Node 26.13.1 baseline gap: The error is expected to be an instance of "TypeError". Received "DOMException" | 4 | `parallel/test-webcrypto-random.js#block_00_block_00`, `parallel/test-webcrypto-random.js#block_01_block_01`, `parallel/test-webcrypto-random.js#block_02_block_02`, ... (+1) | | Node 26.13.1 baseline gap: Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Missing expected exception. | 4 | `parallel/test-fs-opendir.js#block_01_check_that_passing_a_positive_integer_as_buffersize_works`, `parallel/test-fs-opendir.js#block_02_check_read_throw_exceptions_on_invalid_callback`, `parallel/test-fs-opendir.js#block_03_check_if_directory_already_closed_the_callback_should_pass_a`, ... (+1) | | WASM child emulation does not support Node.js --test CLI output behavior | 4 | `parallel/test-runner-extraneous-async-activity.js#block_00_block_00`, `parallel/test-runner-extraneous-async-activity.js#block_01_block_01`, `parallel/test-runner-extraneous-async-activity.js#block_02_block_02`, ... (+1) | | inherited: --frozen-intrinsics flag semantics are not implemented | 4 | `parallel/test-freeze-intrinsics.js#block_00_ensure_we_can_extend_console`, `parallel/test-freeze-intrinsics.js#block_01_ensure_we_can_write_override_object_prototype_properties_on_`, `parallel/test-freeze-intrinsics.js#block_02_ensure_we_can_not_override_globalthis`, ... (+1) | @@ -1367,10 +1364,8 @@ Secondary full-public compatibility, including public tests that are currently e | Node 26.13.1 baseline gap: Missing expected exception.; carries 22.14.0 subtest block_02_guarantee_dot_left_numbers_are_ignored | 1 | `parallel/test-util-getcallsites.js#block_02_framecount_must_be_an_integer` | | Node 26.13.1 baseline gap: Missing expected exception.; the runnable assertions execute, while its common.hasIntl-gated invalid-IDNA matrix is covered separately by focused runtime tests | 1 | `parallel/test-url-parse-invalid-input.js` | | Node 26.13.1 baseline gap: Only --eval/-e, --input-type, and script files are supported in WASM child emulation; carries 22.14.0 subtest test_00_disabled_without_experimental_webstorage | 1 | `parallel/test-webstorage.js#test_08_disabled_with_no_webstorage` | +| Node 26.13.1 baseline gap: QuotaExceededError is not defined (the Node 26 QuotaExceededError global is not implemented) | 1 | `parallel/test-webcrypto-random.js#block_02_block_02` | | Node 26.13.1 baseline gap: The argument 'format' must be a valid string format. Received "grey" | 1 | `parallel/test-util-styletext.js` | -| Node 26.13.1 baseline gap: The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:; carries 22.14.0 subtest block_04_authentication_tag_length_has_been_specified | 1 | `parallel/test-crypto-authenticated.js#block_05_authentication_tag_length_has_been_specified` | -| Node 26.13.1 baseline gap: The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input:; carries 22.14.0 subtest block_05_authentication_tag_has_been_specified | 1 | `parallel/test-crypto-authenticated.js#block_06_authentication_tag_length_has_been_specified` | -| Node 26.13.1 baseline gap: The input did not match the regular expression /Unsupported state or unable to authenticate data/. Input; carries 22.14.0 subtest block_12_final_in_gcm_or_ocb_mode | 1 | `parallel/test-crypto-authenticated.js#block_13_final_in_gcm_mode_ocb_mode_and_for_chacha20_poly1305` | | Node 26.13.1 baseline gap: Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Expected "actual" to be strict | 1 | `parallel/test-stream-readable-to-web-termination.js#block_01_block_01` | | Node 26.13.1 baseline gap: Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Missing expected exception (Ty | 1 | `parallel/test-vm-module-errors.js` | | Node 26.13.1 baseline gap: Unhandled promise rejection (likely cause of mustCall failure): AssertionError: Missing expected rejection (Ab | 1 | `parallel/test-fs-promises-file-handle-append-file.js` | @@ -1381,8 +1376,6 @@ Secondary full-public compatibility, including public tests that are currently e | Node 26.13.1 baseline gap: Unhandled promise rejection (likely cause of mustCall failure): TypeError: not a function | 1 | `parallel/test-fs-promises-file-handle-dispose.js` | | Node 26.13.1 baseline gap: Unhandled promise rejection: AssertionError: 'a\rb' !== 'a\nb'; carries 22.14.0 subtest block_32_block_32 | 1 | `parallel/test-blob.js#block_33_block_33` | | Node 26.13.1 baseline gap: _checkInvalidHeaderChar('\x01\x02\x03\x04\x05\x06\x07\b', true) unexpectedly failed in lenient mode | 1 | `parallel/test-http-invalidheaderfield2.js` | -| Node 26.13.1 baseline gap: error:0408006C:rsa routines::digest too big for rsa key | 1 | `parallel/test-crypto-async-sign-verify.js#block_02_block_02` | -| Node 26.13.1 baseline gap: error:06000068:public key routines::operation not supported for this keytype | 1 | `parallel/test-crypto-async-sign-verify.js#block_01_block_01` | | Node 26.13.1 baseline gap: path.win32.join resolves .. through a CON: device-name segment | 1 | `parallel/test-path-join.js` | | Node 26.13.1 baseline gap: path.win32.resolve("\\\\.\\PHYSICALDRIVE0") | 1 | `parallel/test-path-resolve.js` | | Node 26.13.1 baseline gap: util.inspect prints the symbol key of a boxed String as [Symbol(foo)]; 26.13.1 expects Symbol(foo); carries 22.14.0 subtest block_90_block_90 | 1 | `parallel/test-util-inspect.js#block_100_block_100` | diff --git a/tests/runtime/crypto.rs b/tests/runtime/crypto.rs index b15746cf2..8f2d83772 100644 --- a/tests/runtime/crypto.rs +++ b/tests/runtime/crypto.rs @@ -1054,3 +1054,106 @@ async fn crypto_subtle_sign_verify_rsa_pss( _ => Err(anyhow!("Expected bool result")), } } + +/// Error contracts of AEAD decryption, key encoding options, crypto argument validation, one-shot sign/verify +/// key type checks, option resolution, callback delivery and DH peer key limits, as Node.js 26.13.1 reports them. +#[test] +async fn crypto_error_contracts( + #[tagged_as("crypto")] compiled: &CompiledTest, +) -> anyhow::Result<()> { + let (result, _output) = + invoke_and_capture_output(compiled.wasm_path(), None, "crypto-error-contracts", &[]).await; + + let lines = match result? { + Some(Val::List(vals)) => vals + .into_iter() + .map(|v| match v { + Val::String(s) => Ok(s), + other => Err(anyhow!("Expected string, got {other:?}")), + }) + .collect::>>()?, + _ => return Err(anyhow!("Expected list result")), + }; + let expected = [ + "gcm tampered tag: Error undefined Unsupported state or unable to authenticate data", + "gcm missing tag: Error undefined Unsupported state or unable to authenticate data", + "chacha20-poly1305 tampered tag: Error undefined Unsupported state or unable to authenticate data", + "public pkcs8: TypeError ERR_INVALID_ARG_VALUE The property 'options.type' is invalid. Received 'pkcs8'", + "public without format: TypeError ERR_INVALID_ARG_VALUE The property 'options.format' is invalid. Received undefined", + "public spki ignores cipher: ok -----BEGIN PUBLIC KEY-----", + "private without type: TypeError ERR_INVALID_ARG_VALUE The property 'options.type' is invalid. Received undefined", + "private passphrase without cipher: TypeError ERR_INVALID_ARG_VALUE The property 'options.cipher' is required when a passphrase is specified. Received undefined", + "private der pkcs1 encrypted: Error ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS The selected key encoding pkcs1 does not support encryption.", + "private unknown cipher: Error ERR_CRYPTO_UNKNOWN_CIPHER Unknown cipher", + "private pem pkcs8 encrypted: ok -----BEGIN ENCRYPTED PRIVATE KEY-----", + "ed25519 public pkcs1: Error ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS The selected key encoding pkcs1 can only be used for RSA keys.", + "ed25519 private sec1: Error ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS The selected key encoding sec1 can only be used for EC keys.", + "keygen passphrase without cipher: TypeError ERR_INVALID_ARG_VALUE The property 'options.privateKeyEncoding.cipher' is required when a passphrase is specified. Received undefined", + "keygen public pkcs8: TypeError ERR_INVALID_ARG_VALUE The property 'options.publicKeyEncoding.type' is invalid. Received 'pkcs8'", + "createPrivateKey der spki: TypeError ERR_INVALID_ARG_VALUE The property 'key.type' is invalid. Received 'spki'", + "gcm implicit 12-byte tag: TypeError ERR_CRYPTO_INVALID_AUTH_TAG Invalid authentication tag length: 12", + "gcm authTagLength 12-byte tag: ok set", + "hkdfSync info with fake byteLength: RangeError ERR_OUT_OF_RANGE The value of \"info\" is out of range. It must be must not contain more than 1024 bytes. Received 2048", + "cipher output encoding change: TypeError ERR_INVALID_ARG_VALUE The argument 'outputEncoding' cannot be changed from 'utf8'. Received 'hex'", + "generateKeyPair Ed25519: TypeError ERR_INVALID_ARG_VALUE The argument 'type' must be a supported key type. Received 'Ed25519'", + "generateKeyPair toString: TypeError ERR_INVALID_ARG_VALUE The argument 'type' must be a supported key type. Received 'toString'", + "sign digest too big for key: callback Error ERR_OSSL_RSA_DIGEST_TOO_BIG_FOR_RSA_KEY", + "verify with x25519 key: callback Error ERR_OSSL_EVP_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE", + "sign invalid padding: throws TypeError ERR_INVALID_ARG_VALUE", + "verify mismatching signature: callback ok false", + "sign with public KeyObject: throws TypeError ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE", + "sign with nested secret KeyObject: throws TypeError ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE", + "verify with secret KeyObject: throws TypeError ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE", + "verify with nested private KeyObject: callback ok true", + "sign inherited PSS options: callback ok pkcs1=false pss=true", + "sign non-enumerable PSS options: callback ok pkcs1=false pss=true", + "sign default padding: callback ok pkcs1=true pss=false", + "verify inherited PSS options: callback ok true", + "verify PSS signature with default padding: callback ok false", + "DH computeSecret(1): RangeError ERR_CRYPTO_INVALID_KEYLEN Supplied key is too small", + "DH computeSecret(p - 1): RangeError ERR_CRYPTO_INVALID_KEYLEN Supplied key is too large", + ]; + assert_eq!(lines, expected); + Ok(()) +} + +/// WebCrypto getRandomValues, key usage/algorithm and HMAC import/JWK error contracts, as Node.js 26.13.1 reports them. +#[test] +async fn webcrypto_error_contracts( + #[tagged_as("crypto")] compiled: &CompiledTest, +) -> anyhow::Result<()> { + let (result, _output) = + invoke_and_capture_output(compiled.wasm_path(), None, "webcrypto-error-contracts", &[]) + .await; + + let lines = match result? { + Some(Val::List(vals)) => vals + .into_iter() + .map(|v| match v { + Val::String(s) => Ok(s), + other => Err(anyhow!("Expected string, got {other:?}")), + }) + .collect::>>()?, + _ => return Err(anyhow!("Expected list result")), + }; + let expected = [ + "getRandomValues(): TypeError ERR_MISSING_ARGS Failed to execute 'getRandomValues' on 'Crypto': 1 argument required, but only 0 present.", + "getRandomValues(ArrayBuffer): TypeError ERR_INVALID_ARG_TYPE Failed to execute 'getRandomValues' on 'Crypto': 1st argument is not an ArrayBufferView.", + "getRandomValues(Float32Array): TypeMismatchError 17 The data argument must be an integer-type TypedArray", + "getRandomValues(65537 bytes): QuotaExceededError 22 The requested length exceeds 65,536 bytes", + "encrypt without usage: InvalidAccessError 15 Unable to use this key to encrypt", + "decrypt without usage: InvalidAccessError 15 Unable to use this key to decrypt", + "decrypt wrong algorithm without usage: InvalidAccessError 15 Key algorithm mismatch", + "verify without usage: InvalidAccessError 15 Unable to use this key to verify", + "wrapKey without usage: InvalidAccessError 15 Unable to use this key to wrapKey", + "HMAC usage deriveBits: SyntaxError 12 Unsupported key usage for HMAC key", + "HMAC length 0: DataError 0 HmacImportParams.length cannot be 0", + "HMAC length 384: DataError 0 Invalid key length", + "HMAC SHA-256 jwk alg: HS256", + "HMAC jwk alg HS384: DataError 0 JWK \"alg\" does not match the requested algorithm", + "HMAC jwk without alg: ok 256", + "HMAC SHA3-256 jwk alg: undefined", + ]; + assert_eq!(lines, expected); + Ok(()) +}