From a92256749df9742a69dfaab8c55c49a3d4f4d77b 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/46252 --- 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 | 16 +- 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 | 518 +++++++++++++ .../test-webcrypto-derivebits-pbkdf2.js | 22 +- test/wpt/status/WebCryptoAPI.json | 13 + 33 files changed, 2041 insertions(+), 420 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 8cf4bad3f823d5..8a9c70c2583e60 100644 --- a/doc/api/webcrypto.md +++ b/doc/api/webcrypto.md @@ -2,6 +2,10 @@