From fe61ea5ebeaf2f0fe447d382299c2c2d86a0faa7 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Tue, 25 Oct 2022 13:08:51 +0200 Subject: [PATCH] test,crypto: update WebCryptoAPI WPT --- test/fixtures/wpt/README.md | 2 +- .../derive_bits_keys/cfrg_curves_bits.js | 8 ++++- .../derive_bits_keys/cfrg_curves_keys.js | 8 ++++- .../derive_bits_keys/ecdh_bits.js | 10 +++++- .../derive_bits_keys/ecdh_keys.js | 10 +++++- .../fixtures/wpt/WebCryptoAPI/util/helpers.js | 31 +++++++++++++++---- test/fixtures/wpt/versions.json | 2 +- 7 files changed, 59 insertions(+), 12 deletions(-) diff --git a/test/fixtures/wpt/README.md b/test/fixtures/wpt/README.md index d459f8fb99a02c..4894d0fdea6ce6 100644 --- a/test/fixtures/wpt/README.md +++ b/test/fixtures/wpt/README.md @@ -31,7 +31,7 @@ Last update: - user-timing: https://github.com/web-platform-tests/wpt/tree/df24fb604e/user-timing - wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/d8dbe6990b/wasm/jsapi - wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi -- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/edca84af42/WebCryptoAPI +- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/0042d42ee6/WebCryptoAPI - webidl/ecmascript-binding/es-exceptions: https://github.com/web-platform-tests/wpt/tree/a370aad338/webidl/ecmascript-binding/es-exceptions [Web Platform Tests]: https://github.com/web-platform-tests/wpt diff --git a/test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/cfrg_curves_bits.js b/test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/cfrg_curves_bits.js index f467bc858cbba9..9a824ce9514b60 100644 --- a/test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/cfrg_curves_bits.js +++ b/test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/cfrg_curves_bits.js @@ -150,7 +150,7 @@ function define_tests() { promise_test(function(test) { return subtle.generateKey({name: "AES-CBC", length: 128}, true, ["encrypt", "decrypt"]) .then(function(secretKey) { - subtle.deriveBits({name: algorithmName, public: secretKey}, privateKeys[algorithmName], 8 * sizes[algorithmName]) + return subtle.deriveBits({name: algorithmName, public: secretKey}, privateKeys[algorithmName], 8 * sizes[algorithmName]) .then(function(derivation) { assert_unreached("deriveBits succeeded but should have failed with InvalidAccessError"); }, function(err) { @@ -183,6 +183,8 @@ function define_tests() { false, ["deriveBits", "deriveKey"]) .then(function(key) { privateKeys[algorithmName] = key; + }, function (err) { + privateKeys[algorithmName] = null; }); promises.push(operation); }); @@ -192,6 +194,8 @@ function define_tests() { false, ["deriveKey"]) .then(function(key) { noDeriveBitsKeys[algorithmName] = key; + }, function (err) { + noDeriveBitsKeys[algorithmName] = null; }); promises.push(operation); }); @@ -201,6 +205,8 @@ function define_tests() { false, []) .then(function(key) { publicKeys[algorithmName] = key; + }, function (err) { + publicKeys[algorithmName] = null; }); promises.push(operation); }); diff --git a/test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/cfrg_curves_keys.js b/test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/cfrg_curves_keys.js index 7819ae0bf83b64..1e8e9d48d394ad 100644 --- a/test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/cfrg_curves_keys.js +++ b/test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/cfrg_curves_keys.js @@ -127,7 +127,7 @@ function define_tests() { promise_test(function(test) { return subtle.generateKey({name: "HMAC", hash: "SHA-256", length: 256}, true, ["sign", "verify"]) .then(function(secretKey) { - subtle.deriveKey({name: algorithmName, public: secretKey}, privateKeys[algorithmName], {name: "AES-CBC", length: 256}, true, ["sign", "verify"]) + return subtle.deriveKey({name: algorithmName, public: secretKey}, privateKeys[algorithmName], {name: "AES-CBC", length: 256}, true, ["sign", "verify"]) .then(function(key) {return crypto.subtle.exportKey("raw", key);}) .then(function(exportedKey) { assert_unreached("deriveKey succeeded but should have failed with InvalidAccessError"); @@ -151,6 +151,8 @@ function define_tests() { false, ["deriveBits", "deriveKey"]) .then(function(key) { privateKeys[algorithmName] = key; + }, function (err) { + privateKeys[algorithmName] = null; }); promises.push(operation); }); @@ -160,6 +162,8 @@ function define_tests() { false, ["deriveBits"]) .then(function(key) { noDeriveKeyKeys[algorithmName] = key; + }, function (err) { + noDeriveKeyKeys[algorithmName] = null; }); promises.push(operation); }); @@ -169,6 +173,8 @@ function define_tests() { false, []) .then(function(key) { publicKeys[algorithmName] = key; + }, function (err) { + publicKeys[algorithmName] = null; }); promises.push(operation); }); diff --git a/test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/ecdh_bits.js b/test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/ecdh_bits.js index 5cc7193aebd794..e52ffc6bfdb6f6 100644 --- a/test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/ecdh_bits.js +++ b/test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/ecdh_bits.js @@ -165,7 +165,7 @@ function define_tests() { promise_test(function(test) { return subtle.generateKey({name: "AES-CBC", length: 128}, true, ["encrypt", "decrypt"]) .then(function(secretKey) { - subtle.deriveBits({name: "ECDH", public: secretKey}, privateKeys[namedCurve], 8 * sizes[namedCurve]) + return subtle.deriveBits({name: "ECDH", public: secretKey}, privateKeys[namedCurve], 8 * sizes[namedCurve]) .then(function(derivation) { assert_unreached("deriveBits succeeded but should have failed with InvalidAccessError"); }, function(err) { @@ -199,6 +199,8 @@ function define_tests() { false, ["deriveBits", "deriveKey"]) .then(function(key) { privateKeys[namedCurve] = key; + }, function (err) { + privateKeys[namedCurve] = null; }); promises.push(operation); }); @@ -208,6 +210,8 @@ function define_tests() { false, ["deriveKey"]) .then(function(key) { noDeriveBitsKeys[namedCurve] = key; + }, function (err) { + noDeriveBitsKeys[namedCurve] = null; }); promises.push(operation); }); @@ -217,6 +221,8 @@ function define_tests() { false, []) .then(function(key) { publicKeys[namedCurve] = key; + }, function (err) { + publicKeys[namedCurve] = null; }); promises.push(operation); }); @@ -224,6 +230,8 @@ function define_tests() { var operation = subtle.generateKey({name: "ECDSA", namedCurve: namedCurve}, false, ["sign", "verify"]) .then(function(keyPair) { ecdsaKeyPairs[namedCurve] = keyPair; + }, function (err) { + ecdsaKeyPairs[namedCurve] = null; }); promises.push(operation); }); diff --git a/test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/ecdh_keys.js b/test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/ecdh_keys.js index 99008e0cbbe09e..fce76f185530ac 100644 --- a/test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/ecdh_keys.js +++ b/test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/ecdh_keys.js @@ -143,7 +143,7 @@ function define_tests() { promise_test(function(test) { return subtle.generateKey({name: "HMAC", hash: "SHA-256", length: 256}, true, ["sign", "verify"]) .then(function(secretKey) { - subtle.deriveKey({name: "ECDH", public: secretKey}, privateKeys[namedCurve], {name: "AES-CBC", length: 256}, true, ["sign", "verify"]) + return subtle.deriveKey({name: "ECDH", public: secretKey}, privateKeys[namedCurve], {name: "AES-CBC", length: 256}, true, ["sign", "verify"]) .then(function(key) {return crypto.subtle.exportKey("raw", key);}) .then(function(exportedKey) { assert_unreached("deriveKey succeeded but should have failed with InvalidAccessError"); @@ -168,6 +168,8 @@ function define_tests() { false, ["deriveBits", "deriveKey"]) .then(function(key) { privateKeys[namedCurve] = key; + }, function (err) { + privateKeys[namedCurve] = null; }); promises.push(operation); }); @@ -177,6 +179,8 @@ function define_tests() { false, ["deriveBits"]) .then(function(key) { noDeriveKeyKeys[namedCurve] = key; + }, function (err) { + noDeriveKeyKeys[namedCurve] = null; }); promises.push(operation); }); @@ -186,6 +190,8 @@ function define_tests() { false, []) .then(function(key) { publicKeys[namedCurve] = key; + }, function (err) { + publicKeys[namedCurve] = null; }); promises.push(operation); }); @@ -193,6 +199,8 @@ function define_tests() { var operation = subtle.generateKey({name: "ECDSA", namedCurve: namedCurve}, false, ["sign", "verify"]) .then(function(keyPair) { ecdsaKeyPairs[namedCurve] = keyPair; + }, function (err) { + ecdsaKeyPairs[namedCurve] = null; }); promises.push(operation); }); diff --git a/test/fixtures/wpt/WebCryptoAPI/util/helpers.js b/test/fixtures/wpt/WebCryptoAPI/util/helpers.js index b6aa6ed0c10cfd..8874f731f8bbcf 100644 --- a/test/fixtures/wpt/WebCryptoAPI/util/helpers.js +++ b/test/fixtures/wpt/WebCryptoAPI/util/helpers.js @@ -110,7 +110,22 @@ function assert_goodCryptoKey(key, algorithm, extractable, usages, kind) { assert_equals(key.extractable, extractable, "Extractability is correct"); assert_equals(key.algorithm.name, registeredAlgorithmName, "Correct algorithm name"); - assert_equals(key.algorithm.length, algorithm.length, "Correct length"); + if (key.algorithm.name.toUpperCase() === "HMAC" && algorithm.length === undefined) { + switch (key.algorithm.hash.name.toUpperCase()) { + case 'SHA-1': + case 'SHA-256': + assert_equals(key.algorithm.length, 512, "Correct length"); + break; + case 'SHA-384': + case 'SHA-512': + assert_equals(key.algorithm.length, 1024, "Correct length"); + break; + default: + assert_unreached("Unrecognized hash"); + } + } else { + assert_equals(key.algorithm.length, algorithm.length, "Correct length"); + } if (["HMAC", "RSASSA-PKCS1-v1_5", "RSA-PSS"].includes(registeredAlgorithmName)) { assert_equals(key.algorithm.hash.name.toUpperCase(), algorithm.hash.toUpperCase(), "Correct hash function"); } @@ -166,12 +181,16 @@ function allAlgorithmSpecifiersFor(algorithmName) { }); } else if (algorithmName.toUpperCase() === "HMAC") { [ - {name: "SHA-1", length: 160}, - {name: "SHA-256", length: 256}, - {name: "SHA-384", length: 384}, - {name: "SHA-512", length: 512} + {hash: "SHA-1", length: 160}, + {hash: "SHA-256", length: 256}, + {hash: "SHA-384", length: 384}, + {hash: "SHA-512", length: 512}, + {hash: "SHA-1"}, + {hash: "SHA-256"}, + {hash: "SHA-384"}, + {hash: "SHA-512"}, ].forEach(function(hashAlgorithm) { - results.push({name: algorithmName, hash: hashAlgorithm.name, length: hashAlgorithm.length}); + results.push({name: algorithmName, ...hashAlgorithm}); }); } else if (algorithmName.toUpperCase().substring(0, 3) === "RSA") { hashes.forEach(function(hashName) { diff --git a/test/fixtures/wpt/versions.json b/test/fixtures/wpt/versions.json index 16590579217df5..ca7fb89b26c79f 100644 --- a/test/fixtures/wpt/versions.json +++ b/test/fixtures/wpt/versions.json @@ -84,7 +84,7 @@ "path": "wasm/webapi" }, "WebCryptoAPI": { - "commit": "edca84af42bd7e84da94e63b322fe343191842d2", + "commit": "0042d42ee69baf05a4ac4f5745be9c3b92c04e25", "path": "WebCryptoAPI" }, "webidl/ecmascript-binding/es-exceptions": {