From dcfca257375119f3df5900702293ed32c0ac9aca Mon Sep 17 00:00:00 2001 From: "Node.js GitHub Bot" Date: Sun, 8 Nov 2026 00:20:38 +0000 Subject: [PATCH] test: update WPT for WebCryptoAPI to e87deca336 --- .../aes_cbc_invalid_length.https.any.js | 47 +++++++++++++++++++ .../encrypt_decrypt/aes_cbc_vectors.js | 2 +- test/fixtures/wpt/versions.json | 2 +- 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/wpt/WebCryptoAPI/encrypt_decrypt/aes_cbc_invalid_length.https.any.js diff --git a/test/fixtures/wpt/WebCryptoAPI/encrypt_decrypt/aes_cbc_invalid_length.https.any.js b/test/fixtures/wpt/WebCryptoAPI/encrypt_decrypt/aes_cbc_invalid_length.https.any.js new file mode 100644 index 000000000000..6f3daa4cb361 --- /dev/null +++ b/test/fixtures/wpt/WebCryptoAPI/encrypt_decrypt/aes_cbc_invalid_length.https.any.js @@ -0,0 +1,47 @@ +// META: title=WebCryptoAPI: AES-CBC decryption ciphertext lengths +// META: global=window,dedicatedworker + +/* + * Copyright (C) 2026 Jonathan Powers. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND ITS CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +// https://w3c.github.io/webcrypto/#aes-cbc-operations +// Decryption requires a nonempty ciphertext whose length is a multiple of 16 bytes. +for (const keyLength of [128, 192, 256]) { + for (const cipherTextLength of [0, 1, 15, 17, 31, 33]) { + promise_test(async t => { + const key = await crypto.subtle.importKey("raw", new Uint8Array(keyLength / 8), "AES-CBC", false, ["decrypt"]); + const parameters = { name: "AES-CBC", iv: new Uint8Array(16) }; + await promise_rejects_dom(t, "OperationError", crypto.subtle.decrypt(parameters, key, new Uint8Array(cipherTextLength))); + }, `AES-CBC with a ${keyLength}-bit key rejects ${cipherTextLength}-byte ciphertext with OperationError`); + } + + promise_test(async () => { + const key = await crypto.subtle.importKey("raw", new Uint8Array(keyLength / 8), "AES-CBC", false, ["encrypt", "decrypt"]); + const parameters = { name: "AES-CBC", iv: new Uint8Array(16) }; + const cipherText = await crypto.subtle.encrypt(parameters, key, new Uint8Array(0)); + assert_equals(cipherText.byteLength, 16, "Encrypting empty plaintext produces a full padding block"); + const plainText = await crypto.subtle.decrypt(parameters, key, cipherText); + assert_equals(plainText.byteLength, 0, "Decrypting a full padding block produces empty plaintext"); + }, `AES-CBC with a ${keyLength}-bit key decrypts a padded empty message`); +} diff --git a/test/fixtures/wpt/WebCryptoAPI/encrypt_decrypt/aes_cbc_vectors.js b/test/fixtures/wpt/WebCryptoAPI/encrypt_decrypt/aes_cbc_vectors.js index 28ef75fece62..6bc7b3bf4b7d 100644 --- a/test/fixtures/wpt/WebCryptoAPI/encrypt_decrypt/aes_cbc_vectors.js +++ b/test/fixtures/wpt/WebCryptoAPI/encrypt_decrypt/aes_cbc_vectors.js @@ -194,7 +194,7 @@ function getTestVectors() { ["zeroPadChar", "bigPadChar", "inconsistentPadChars"].forEach(function(paddingProblem) { var badCiphertext = new Uint8Array(ciphertext[keyLength].byteLength); badCiphertext.set(ciphertext[keyLength].slice(0, ciphertext[keyLength].byteLength - 16)); - badCiphertext.set(badPadding[keyLength][paddingProblem]); + badCiphertext.set(badPadding[keyLength][paddingProblem], ciphertext[keyLength].byteLength - 16); decryptionFailing.push({ name: "AES-CBC " + keyLength.toString() + "-bit key, " + paddingProblem, diff --git a/test/fixtures/wpt/versions.json b/test/fixtures/wpt/versions.json index 743a05f94f84..e87b7ac4b737 100644 --- a/test/fixtures/wpt/versions.json +++ b/test/fixtures/wpt/versions.json @@ -100,7 +100,7 @@ "path": "web-locks" }, "WebCryptoAPI": { - "commit": "e15690d276ae50728b9d557f4e04f894588d34a0", + "commit": "e87deca3369c630ca2ade57734c5a42adbbc7e48", "path": "WebCryptoAPI" }, "webidl": {