From d164e537bf85925fc9850ef19050d5e848cb404a Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Fri, 6 Oct 2023 16:59:35 +0200 Subject: [PATCH] test,crypto: update WebCryptoAPI WPT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/50039 Reviewed-By: Tobias Nießen Reviewed-By: Yagiz Nizipli Reviewed-By: Matthew Aitken --- test/fixtures/wpt/README.md | 2 +- .../import_export/okp_importKey.https.any.js | 32 +++++++++++++++++++ .../wpt/WebCryptoAPI/sign_verify/eddsa.js | 1 + .../wpt/WebCryptoAPI/sign_verify/hmac.js | 1 + test/fixtures/wpt/versions.json | 2 +- 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/test/fixtures/wpt/README.md b/test/fixtures/wpt/README.md index 6bcd1e51efd83b..6404571a498200 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/5ae85bf826/user-timing - wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/cde25e7e3c/wasm/jsapi - wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi -- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/f4e7e32fd0/WebCryptoAPI +- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/d4e14d714c/WebCryptoAPI - webidl/ecmascript-binding/es-exceptions: https://github.com/web-platform-tests/wpt/tree/a370aad338/webidl/ecmascript-binding/es-exceptions - webmessaging/broadcastchannel: https://github.com/web-platform-tests/wpt/tree/e97fac4791/webmessaging/broadcastchannel diff --git a/test/fixtures/wpt/WebCryptoAPI/import_export/okp_importKey.https.any.js b/test/fixtures/wpt/WebCryptoAPI/import_export/okp_importKey.https.any.js index a0ec3e81c877e1..a56bd31cbe14b1 100644 --- a/test/fixtures/wpt/WebCryptoAPI/import_export/okp_importKey.https.any.js +++ b/test/fixtures/wpt/WebCryptoAPI/import_export/okp_importKey.https.any.js @@ -81,6 +81,11 @@ } testFormat(format, algorithm, data, vector.name, usages, extractable); + + // Test for https://github.com/WICG/webcrypto-secure-curves/pull/24 + if (format === "jwk" && extractable) { + testJwkAlgBehaviours(algorithm, data.jwk, vector.name, usages); + } }); }); @@ -92,6 +97,11 @@ var data = keyData[vector.name]; testFormat(format, algorithm, data, vector.name, usages, extractable); + + // Test for https://github.com/WICG/webcrypto-secure-curves/pull/24 + if (format === "jwk" && extractable) { + testJwkAlgBehaviours(algorithm, data.jwk, vector.name, usages); + } }); }); }); @@ -126,6 +136,28 @@ }, "Good parameters: " + keySize.toString() + " bits " + parameterString(format, keyData[format], algorithm, extractable, usages)); } + // Test importKey/exportKey "alg" behaviours, alg is ignored upon import and alg is missing for Ed25519 and Ed448 JWK export + // https://github.com/WICG/webcrypto-secure-curves/pull/24 + function testJwkAlgBehaviours(algorithm, keyData, crv, usages) { + promise_test(function(test) { + return subtle.importKey('jwk', { ...keyData, alg: 'this is ignored' }, algorithm, true, usages). + then(function(key) { + assert_equals(key.constructor, CryptoKey, "Imported a CryptoKey object"); + + return subtle.exportKey('jwk', key). + then(function(result) { + assert_equals(Object.keys(result).length, keyData.d ? 6 : 5, "Correct number of JWK members"); + assert_equals(result.alg, undefined, 'No JWK "alg" member is present'); + assert_true(equalJwk(keyData, result), "Round trip works"); + }, function(err) { + assert_unreached("Threw an unexpected error: " + err.toString()); + }); + }, function(err) { + assert_unreached("Threw an unexpected error: " + err.toString()); + }); + }, "Good parameters with ignored JWK alg: " + crv.toString() + " " + parameterString('jwk', keyData, algorithm, true, usages)); + } + // Helper methods follow: diff --git a/test/fixtures/wpt/WebCryptoAPI/sign_verify/eddsa.js b/test/fixtures/wpt/WebCryptoAPI/sign_verify/eddsa.js index d425fec2dc343e..d77a8808831176 100644 --- a/test/fixtures/wpt/WebCryptoAPI/sign_verify/eddsa.js +++ b/test/fixtures/wpt/WebCryptoAPI/sign_verify/eddsa.js @@ -167,6 +167,7 @@ function run_test() { promise_test(function(test) { return subtle.sign(algorithm, vector.privateKey, vector.data) .then(function(signature) { + assert_true(equalBuffers(signature, vector.signature), "Signing did not give the expected output"); // Can we verify the signature? return subtle.verify(algorithm, vector.publicKey, signature, vector.data) .then(function(is_verified) { diff --git a/test/fixtures/wpt/WebCryptoAPI/sign_verify/hmac.js b/test/fixtures/wpt/WebCryptoAPI/sign_verify/hmac.js index 8df4b042f54cf6..f5e2ad2769cdd8 100644 --- a/test/fixtures/wpt/WebCryptoAPI/sign_verify/hmac.js +++ b/test/fixtures/wpt/WebCryptoAPI/sign_verify/hmac.js @@ -117,6 +117,7 @@ function run_test() { promise_test(function(test) { return subtle.sign({name: "HMAC", hash: vector.hash}, vector.key, vector.plaintext) .then(function(signature) { + assert_true(equalBuffers(signature, vector.signature), "Signing did not give the expected output"); // Can we get the verify the new signature? return subtle.verify({name: "HMAC", hash: vector.hash}, vector.key, signature, vector.plaintext) .then(function(is_verified) { diff --git a/test/fixtures/wpt/versions.json b/test/fixtures/wpt/versions.json index 27daee082506fb..4b28c06e6c40df 100644 --- a/test/fixtures/wpt/versions.json +++ b/test/fixtures/wpt/versions.json @@ -84,7 +84,7 @@ "path": "wasm/webapi" }, "WebCryptoAPI": { - "commit": "f4e7e32fd0d4937f5b024602c6bf665ebeb1fa17", + "commit": "d4e14d714c5242e174ba9aec43caf5eb514d0f09", "path": "WebCryptoAPI" }, "webidl/ecmascript-binding/es-exceptions": {