From d50a7dc9115d66395ba80259fdb7f37f66f62582 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Tue, 17 Jan 2023 09:57:58 +0100 Subject: [PATCH] crypto: use WebIDL converters in WebCryptoAPI WebCryptoAPI functions' arguments are now coersed and validated as per their WebIDL definitions like in other Web Crypto API implementations. This further improves interoperability with other implementations of Web Crypto API. PR-URL: https://github.com/nodejs/node/pull/46067 Reviewed-By: Antoine du Hamel Reviewed-By: Chengzhong Wu Backport-PR-URL: https://github.com/nodejs/node/pull/47336 --- doc/api/webcrypto.md | 4 + lib/internal/crypto/aes.js | 28 +- lib/internal/crypto/cfrg.js | 37 +- lib/internal/crypto/diffiehellman.js | 9 - lib/internal/crypto/ec.js | 39 +- lib/internal/crypto/hash.js | 12 +- lib/internal/crypto/hkdf.js | 8 +- lib/internal/crypto/mac.js | 62 +- lib/internal/crypto/pbkdf2.js | 55 +- lib/internal/crypto/rsa.js | 52 +- lib/internal/crypto/util.js | 282 +++++-- lib/internal/crypto/webcrypto.js | 347 +++++++-- lib/internal/crypto/webidl.js | 707 ++++++++++++++++++ test/fixtures/crypto/aes_gcm.js | 2 +- .../test-webcrypto-cryptokey-workers.js | 2 +- .../test-webcrypto-derivebits-cfrg.js | 2 +- .../test-webcrypto-derivebits-ecdh.js | 2 +- .../test-webcrypto-derivebits-hkdf.js | 20 +- .../parallel/test-webcrypto-derivekey-cfrg.js | 2 +- .../parallel/test-webcrypto-derivekey-ecdh.js | 2 +- test/parallel/test-webcrypto-digest.js | 20 +- .../test-webcrypto-export-import-cfrg.js | 38 +- .../test-webcrypto-export-import-ec.js | 40 +- .../test-webcrypto-export-import-rsa.js | 51 ++ test/parallel/test-webcrypto-export-import.js | 14 +- test/parallel/test-webcrypto-keygen.js | 59 +- .../test-webcrypto-sign-verify-ecdsa.js | 3 +- .../test-webcrypto-sign-verify-hmac.js | 17 +- .../test-webcrypto-sign-verify-rsa.js | 19 +- test/parallel/test-webcrypto-util.js | 12 +- test/parallel/test-webcrypto-webidl.js | 519 +++++++++++++ .../test-webcrypto-derivebits-pbkdf2.js | 22 +- test/wpt/status/WebCryptoAPI.json | 13 + 33 files changed, 2061 insertions(+), 440 deletions(-) create mode 100644 lib/internal/crypto/webidl.js create mode 100644 test/parallel/test-webcrypto-webidl.js diff --git a/doc/api/webcrypto.md b/doc/api/webcrypto.md index 2188edd8523154..9f0275a8affa90 100644 --- a/doc/api/webcrypto.md +++ b/doc/api/webcrypto.md @@ -2,6 +2,10 @@