| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8237346 commit f56e628
42 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | 3 | const { | |
| 4 | + ArrayBuffer, | ||
| 4 | 5 | FunctionPrototypeCall, | |
| 5 | 6 | } = primordials; | |
| 6 | 7 | ||
@@ -141,7 +142,7 @@ async function hkdfDeriveBits(algorithm, baseKey, length) { | |||
| 141 | 142 | const { hash, salt, info } = algorithm; | |
| 142 | 143 | ||
| 143 | 144 | if (length === 0) | |
| 144 | - throw lazyDOMException('length cannot be zero', 'OperationError'); | ||
| 145 | + return new ArrayBuffer(0); | ||
| 145 | 146 | if (length === null) | |
| 146 | 147 | throw lazyDOMException('length cannot be null', 'OperationError'); | |
| 147 | 148 | if (length % 8) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | 3 | const { | |
| 4 | + ArrayBuffer, | ||
| 4 | 5 | FunctionPrototypeCall, | |
| 5 | 6 | } = primordials; | |
| 6 | 7 | ||
@@ -98,10 +99,8 @@ async function pbkdf2DeriveBits(algorithm, baseKey, length) { | |||
| 98 | 99 | 'iterations cannot be zero', | |
| 99 | 100 | 'OperationError'); | |
| 100 | 101 | ||
| 101 | - const raw = baseKey[kKeyObject].export(); | ||
| 102 | - | ||
| 103 | 102 | if (length === 0) | |
| 104 | - throw lazyDOMException('length cannot be zero', 'OperationError'); | ||
| 103 | + return new ArrayBuffer(0); | ||
| 105 | 104 | if (length === null) | |
| 106 | 105 | throw lazyDOMException('length cannot be null', 'OperationError'); | |
| 107 | 106 | if (length % 8) { | |
@@ -113,7 +112,7 @@ async function pbkdf2DeriveBits(algorithm, baseKey, length) { | |||
| 113 | 112 | let result; | |
| 114 | 113 | try { | |
| 115 | 114 | result = await pbkdf2Promise( | |
| 116 | - raw, salt, iterations, length / 8, normalizeHashName(hash.name), | ||
| 115 | + baseKey[kKeyObject].export(), salt, iterations, length / 8, normalizeHashName(hash.name), | ||
| 117 | 116 | ); | |
| 118 | 117 | } catch (err) { | |
| 119 | 118 | throw lazyDOMException( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,15 +25,15 @@ Last update: | |||
| 25 | 25 | - interfaces: https://github.com/web-platform-tests/wpt/tree/df731dab88/interfaces | |
| 26 | 26 | - performance-timeline: https://github.com/web-platform-tests/wpt/tree/17ebc3aea0/performance-timeline | |
| 27 | 27 | - resource-timing: https://github.com/web-platform-tests/wpt/tree/22d38586d0/resource-timing | |
| 28 | - - resources: https://github.com/web-platform-tests/wpt/tree/1e140d63ec/resources | ||
| 28 | + - resources: https://github.com/web-platform-tests/wpt/tree/919874f84f/resources | ||
| 29 | 29 | - streams: https://github.com/web-platform-tests/wpt/tree/2bd26e124c/streams | |
| 30 | 30 | - url: https://github.com/web-platform-tests/wpt/tree/67880a4eb8/url | |
| 31 | 31 | - user-timing: https://github.com/web-platform-tests/wpt/tree/5ae85bf826/user-timing | |
| 32 | 32 | - wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/cde25e7e3c/wasm/jsapi | |
| 33 | 33 | - wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi | |
| 34 | - - WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/6748a0a246/WebCryptoAPI | ||
| 34 | + - WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/b81831169b/WebCryptoAPI | ||
| 35 | 35 | - webidl/ecmascript-binding/es-exceptions: https://github.com/web-platform-tests/wpt/tree/a370aad338/webidl/ecmascript-binding/es-exceptions | |
| 36 | 36 | - webmessaging/broadcastchannel: https://github.com/web-platform-tests/wpt/tree/e97fac4791/webmessaging/broadcastchannel | |
| 37 | 37 | ||
| 38 | 38 | [Web Platform Tests]: https://github.com/web-platform-tests/wpt | |
| 39 | - [`git node wpt`]: https://github.com/nodejs/node-core-utils/blob/main/docs/git-node.md#git-node-wpt | ||
| 39 | + [`git node wpt`]: https://github.com/nodejs/node-core-utils/blob/main/docs/git-node.md#git-node-wpt | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,24 @@ | |||
| 1 | + // META: title=WebCryptoAPI: CryptoKey.algorithm getter returns cached object | ||
| 2 | + | ||
| 3 | + // https://w3c.github.io/webcrypto/#dom-cryptokey-algorithm | ||
| 4 | + // https://github.com/servo/servo/issues/33908 | ||
| 5 | + | ||
| 6 | + promise_test(function() { | ||
| 7 | + return self.crypto.subtle.generateKey( | ||
| 8 | + { | ||
| 9 | + name: "AES-CTR", | ||
| 10 | + length: 256, | ||
| 11 | + }, | ||
| 12 | + true, | ||
| 13 | + ["encrypt"], | ||
| 14 | + ).then( | ||
| 15 | + function(key) { | ||
| 16 | + let a = key.algorithm; | ||
| 17 | + let b = key.algorithm; | ||
| 18 | + assert_true(a === b); | ||
| 19 | + }, | ||
| 20 | + function(err) { | ||
| 21 | + assert_unreached("generateKey threw an unexpected error: " + err.toString()); | ||
| 22 | + } | ||
| 23 | + ); | ||
| 24 | + }, "CryptoKey.algorithm getter returns cached object"); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,12 +1,19 @@ | |||
| 1 | + function define_tests_25519() { | ||
| 2 | + return define_tests("X25519"); | ||
| 3 | + } | ||
| 4 | + | ||
| 5 | + function define_tests_448() { | ||
| 6 | + return define_tests("X448"); | ||
| 7 | + } | ||
| 1 | 8 | ||
| 2 | - function define_tests() { | ||
| 9 | + function define_tests(algorithmName) { | ||
| 3 | 10 | // May want to test prefixed implementations. | |
| 4 | 11 | var subtle = self.crypto.subtle; | |
| 5 | 12 | ||
| 6 | 13 | // Verify the derive functions perform checks against the all-zero value results, | |
| 7 | 14 | // ensuring small-order points are rejected. | |
| 8 | 15 | // https://www.rfc-editor.org/rfc/rfc7748#section-6.1 | |
| 9 | - Object.keys(kSmallOrderPoint).forEach(function(algorithmName) { | ||
| 16 | + { | ||
| 10 | 17 | kSmallOrderPoint[algorithmName].forEach(function(test) { | |
| 11 | 18 | promise_test(async() => { | |
| 12 | 19 | let derived; | |
@@ -28,15 +35,16 @@ function define_tests() { | |||
| 28 | 35 | assert_equals(derived, undefined, "Operation succeeded, but should not have."); | |
| 29 | 36 | }, algorithmName + " key derivation checks for all-zero value result with a key of order " + test.order); | |
| 30 | 37 | }); | |
| 31 | - }); | ||
| 38 | + } | ||
| 32 | 39 | ||
| 33 | 40 | return importKeys(pkcs8, spki, sizes) | |
| 34 | 41 | .then(function(results) { | |
| 35 | 42 | publicKeys = results.publicKeys; | |
| 36 | 43 | privateKeys = results.privateKeys; | |
| 37 | 44 | noDeriveBitsKeys = results.noDeriveBitsKeys; | |
| 45 | + ecdhKeys = results.ecdhKeys; | ||
| 38 | 46 | ||
| 39 | - Object.keys(sizes).forEach(function(algorithmName) { | ||
| 47 | + { | ||
| 40 | 48 | // Basic success case | |
| 41 | 49 | promise_test(function(test) { | |
| 42 | 50 | return subtle.deriveBits({name: algorithmName, public: publicKeys[algorithmName]}, privateKeys[algorithmName], 8 * sizes[algorithmName]) | |
@@ -101,11 +109,7 @@ function define_tests() { | |||
| 101 | 109 | ||
| 102 | 110 | // - wrong algorithm | |
| 103 | 111 | promise_test(function(test) { | |
| 104 | - publicKey = publicKeys["X25519"]; | ||
| 105 | - if (algorithmName === "X25519") { | ||
| 106 | - publicKey = publicKeys["X448"]; | ||
| 107 | - } | ||
| 108 | - return subtle.deriveBits({name: algorithmName, public: publicKey}, privateKeys[algorithmName], 8 * sizes[algorithmName]) | ||
| 112 | + return subtle.deriveBits({name: algorithmName, public: ecdhKeys[algorithmName]}, privateKeys[algorithmName], 8 * sizes[algorithmName]) | ||
| 109 | 113 | .then(function(derivation) { | |
| 110 | 114 | assert_unreached("deriveBits succeeded but should have failed with InvalidAccessError"); | |
| 111 | 115 | }, function(err) { | |
@@ -165,16 +169,17 @@ function define_tests() { | |||
| 165 | 169 | assert_equals(err.name, "OperationError", "Should throw correct error, not " + err.name + ": " + err.message); | |
| 166 | 170 | }); | |
| 167 | 171 | }, algorithmName + " asking for too many bits"); | |
| 168 | - }); | ||
| 172 | + } | ||
| 169 | 173 | }); | |
| 170 | 174 | ||
| 171 | 175 | function importKeys(pkcs8, spki, sizes) { | |
| 172 | 176 | var privateKeys = {}; | |
| 173 | 177 | var publicKeys = {}; | |
| 174 | 178 | var noDeriveBitsKeys = {}; | |
| 179 | + var ecdhPublicKeys = {}; | ||
| 175 | 180 | ||
| 176 | 181 | var promises = []; | |
| 177 | - Object.keys(pkcs8).forEach(function(algorithmName) { | ||
| 182 | + { | ||
| 178 | 183 | var operation = subtle.importKey("pkcs8", pkcs8[algorithmName], | |
| 179 | 184 | {name: algorithmName}, | |
| 180 | 185 | false, ["deriveBits", "deriveKey"]) | |
@@ -184,8 +189,8 @@ function define_tests() { | |||
| 184 | 189 | privateKeys[algorithmName] = null; | |
| 185 | 190 | }); | |
| 186 | 191 | promises.push(operation); | |
| 187 | - }); | ||
| 188 | - Object.keys(pkcs8).forEach(function(algorithmName) { | ||
| 192 | + } | ||
| 193 | + { | ||
| 189 | 194 | var operation = subtle.importKey("pkcs8", pkcs8[algorithmName], | |
| 190 | 195 | {name: algorithmName}, | |
| 191 | 196 | false, ["deriveKey"]) | |
@@ -195,8 +200,8 @@ function define_tests() { | |||
| 195 | 200 | noDeriveBitsKeys[algorithmName] = null; | |
| 196 | 201 | }); | |
| 197 | 202 | promises.push(operation); | |
| 198 | - }); | ||
| 199 | - Object.keys(spki).forEach(function(algorithmName) { | ||
| 203 | + } | ||
| 204 | + { | ||
| 200 | 205 | var operation = subtle.importKey("spki", spki[algorithmName], | |
| 201 | 206 | {name: algorithmName}, | |
| 202 | 207 | false, []) | |
@@ -206,10 +211,17 @@ function define_tests() { | |||
| 206 | 211 | publicKeys[algorithmName] = null; | |
| 207 | 212 | }); | |
| 208 | 213 | promises.push(operation); | |
| 209 | - }); | ||
| 210 | - | ||
| 214 | + } | ||
| 215 | + { | ||
| 216 | + var operation = subtle.importKey("spki", ecSPKI, | ||
| 217 | + {name: "ECDH", namedCurve: "P-256"}, | ||
| 218 | + false, []) | ||
| 219 | + .then(function(key) { | ||
| 220 | + ecdhPublicKeys[algorithmName] = key; | ||
| 221 | + }); | ||
| 222 | + } | ||
| 211 | 223 | return Promise.all(promises) | |
| 212 | - .then(function(results) {return {privateKeys: privateKeys, publicKeys: publicKeys, noDeriveBitsKeys: noDeriveBitsKeys}}); | ||
| 224 | + .then(function(results) {return {privateKeys: privateKeys, publicKeys: publicKeys, noDeriveBitsKeys: noDeriveBitsKeys, ecdhKeys: ecdhPublicKeys}}); | ||
| 213 | 225 | } | |
| 214 | 226 | ||
| 215 | 227 | // Compares two ArrayBuffer or ArrayBufferView objects. If bitCount is | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,10 @@ | |||
| 1 | + // META: title=WebCryptoAPI: deriveKey() Using ECDH with CFRG Elliptic Curves | ||
| 2 | + // META: script=cfrg_curves_bits_fixtures.js | ||
| 3 | + // META: script=cfrg_curves_bits.js | ||
| 4 | + | ||
| 5 | + // Define subtests from a `promise_test` to ensure the harness does not | ||
| 6 | + // complete before the subtests are available. `explicit_done` cannot be used | ||
| 7 | + // for this purpose because the global `done` function is automatically invoked | ||
| 8 | + // by the WPT infrastructure in dedicated worker tests defined using the | ||
| 9 | + // "multi-global" pattern. | ||
| 10 | + promise_test(define_tests_25519, 'setup - define tests'); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,4 @@ | |||
| 1 | - // META: title=WebCryptoAPI: deriveBits() Using ECDH with CFRG Elliptic Curves | ||
| 1 | + // META: title=WebCryptoAPI: deriveKey() Using ECDH with CFRG Elliptic Curves | ||
| 2 | 2 | // META: script=cfrg_curves_bits_fixtures.js | |
| 3 | 3 | // META: script=cfrg_curves_bits.js | |
| 4 | 4 | ||
@@ -7,4 +7,4 @@ | |||
| 7 | 7 | // for this purpose because the global `done` function is automatically invoked | |
| 8 | 8 | // by the WPT infrastructure in dedicated worker tests defined using the | |
| 9 | 9 | // "multi-global" pattern. | |
| 10 | - promise_test(define_tests, 'setup - define tests'); | ||
| 10 | + promise_test(define_tests_448, 'setup - define tests'); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,12 @@ | |||
| 1 | + function define_tests_25519() { | ||
| 2 | + return define_tests("X25519"); | ||
| 3 | + } | ||
| 4 | + | ||
| 5 | + function define_tests_448() { | ||
| 6 | + return define_tests("X448"); | ||
| 7 | + } | ||
| 1 | 8 | ||
| 2 | - function define_tests() { | ||
| 9 | + function define_tests(algorithmName) { | ||
| 3 | 10 | // May want to test prefixed implementations. | |
| 4 | 11 | var subtle = self.crypto.subtle; | |
| 5 | 12 | ||
@@ -8,7 +15,7 @@ function define_tests() { | |||
| 8 | 15 | // https://www.rfc-editor.org/rfc/rfc7748#section-6.1 | |
| 9 | 16 | // TODO: The spec states that the check must be done on use, but there is discussion about doing it on import. | |
| 10 | 17 | // https://github.com/WICG/webcrypto-secure-curves/pull/13 | |
| 11 | - Object.keys(kSmallOrderPoint).forEach(function(algorithmName) { | ||
| 18 | + { | ||
| 12 | 19 | kSmallOrderPoint[algorithmName].forEach(function(test) { | |
| 13 | 20 | promise_test(async() => { | |
| 14 | 21 | let derived; | |
@@ -32,10 +39,10 @@ function define_tests() { | |||
| 32 | 39 | assert_equals(derived, undefined, "Operation succeeded, but should not have."); | |
| 33 | 40 | }, algorithmName + " deriveBits checks for all-zero value result with a key of order " + test.order); | |
| 34 | 41 | }); | |
| 35 | - }); | ||
| 42 | + } | ||
| 36 | 43 | ||
| 37 | 44 | // Ensure the keys generated by each algorithm are valid for key derivation. | |
| 38 | - Object.keys(sizes).forEach(function(algorithmName) { | ||
| 45 | + { | ||
| 39 | 46 | promise_test(async() => { | |
| 40 | 47 | let derived; | |
| 41 | 48 | try { | |
@@ -46,15 +53,16 @@ function define_tests() { | |||
| 46 | 53 | } | |
| 47 | 54 | assert_false (derived === undefined, "Key derivation failed."); | |
| 48 | 55 | }, "Key derivation using a " + algorithmName + " generated keys."); | |
| 49 | - }); | ||
| 56 | + } | ||
| 50 | 57 | ||
| 51 | 58 | return importKeys(pkcs8, spki, sizes) | |
| 52 | 59 | .then(function(results) { | |
| 53 | 60 | publicKeys = results.publicKeys; | |
| 54 | 61 | privateKeys = results.privateKeys; | |
| 55 | 62 | noDeriveKeyKeys = results.noDeriveKeyKeys; | |
| 63 | + ecdhKeys = results.ecdhKeys; | ||
| 56 | 64 | ||
| 57 | - Object.keys(sizes).forEach(function(algorithmName) { | ||
| 65 | + { | ||
| 58 | 66 | // Basic success case | |
| 59 | 67 | promise_test(function(test) { | |
| 60 | 68 | return subtle.deriveKey({name: algorithmName, public: publicKeys[algorithmName]}, privateKeys[algorithmName], {name: "HMAC", hash: "SHA-256", length: 256}, true, ["sign", "verify"]) | |
@@ -102,11 +110,7 @@ function define_tests() { | |||
| 102 | 110 | ||
| 103 | 111 | // - wrong algorithm | |
| 104 | 112 | promise_test(function(test) { | |
| 105 | - publicKey = publicKeys["X25519"]; | ||
| 106 | - if (algorithmName === "X25519") { | ||
| 107 | - publicKey = publicKeys["X448"]; | ||
| 108 | - } | ||
| 109 | - return subtle.deriveKey({name: algorithmName, public: publicKey}, privateKeys[algorithmName], {name: "HMAC", hash: "SHA-256", length: 256}, true, ["sign", "verify"]) | ||
| 113 | + return subtle.deriveKey({name: algorithmName, public: ecdhKeys[algorithmName]}, privateKeys[algorithmName], {name: "HMAC", hash: "SHA-256", length: 256}, true, ["sign", "verify"]) | ||
| 110 | 114 | .then(function(key) {return crypto.subtle.exportKey("raw", key);}) | |
| 111 | 115 | .then(function(exportedKey) { | |
| 112 | 116 | assert_unreached("deriveKey succeeded but should have failed with InvalidAccessError"); | |
@@ -161,16 +165,17 @@ function define_tests() { | |||
| 161 | 165 | }); | |
| 162 | 166 | }); | |
| 163 | 167 | }, algorithmName + " public property value is a secret key"); | |
| 164 | - }); | ||
| 168 | + } | ||
| 165 | 169 | }); | |
| 166 | 170 | ||
| 167 | 171 | function importKeys(pkcs8, spki, sizes) { | |
| 168 | 172 | var privateKeys = {}; | |
| 169 | 173 | var publicKeys = {}; | |
| 170 | 174 | var noDeriveKeyKeys = {}; | |
| 175 | + var ecdhPublicKeys = {}; | ||
| 171 | 176 | ||
| 172 | 177 | var promises = []; | |
| 173 | - Object.keys(pkcs8).forEach(function(algorithmName) { | ||
| 178 | + { | ||
| 174 | 179 | var operation = subtle.importKey("pkcs8", pkcs8[algorithmName], | |
| 175 | 180 | {name: algorithmName}, | |
| 176 | 181 | false, ["deriveBits", "deriveKey"]) | |
@@ -180,8 +185,8 @@ function define_tests() { | |||
| 180 | 185 | privateKeys[algorithmName] = null; | |
| 181 | 186 | }); | |
| 182 | 187 | promises.push(operation); | |
| 183 | - }); | ||
| 184 | - Object.keys(pkcs8).forEach(function(algorithmName) { | ||
| 188 | + } | ||
| 189 | + { | ||
| 185 | 190 | var operation = subtle.importKey("pkcs8", pkcs8[algorithmName], | |
| 186 | 191 | {name: algorithmName}, | |
| 187 | 192 | false, ["deriveBits"]) | |
@@ -191,8 +196,8 @@ function define_tests() { | |||
| 191 | 196 | noDeriveKeyKeys[algorithmName] = null; | |
| 192 | 197 | }); | |
| 193 | 198 | promises.push(operation); | |
| 194 | - }); | ||
| 195 | - Object.keys(spki).forEach(function(algorithmName) { | ||
| 199 | + } | ||
| 200 | + { | ||
| 196 | 201 | var operation = subtle.importKey("spki", spki[algorithmName], | |
| 197 | 202 | {name: algorithmName}, | |
| 198 | 203 | false, []) | |
@@ -202,10 +207,18 @@ function define_tests() { | |||
| 202 | 207 | publicKeys[algorithmName] = null; | |
| 203 | 208 | }); | |
| 204 | 209 | promises.push(operation); | |
| 205 | - }); | ||
| 210 | + } | ||
| 211 | + { | ||
| 212 | + var operation = subtle.importKey("spki", ecSPKI, | ||
| 213 | + {name: "ECDH", namedCurve: "P-256"}, | ||
| 214 | + false, []) | ||
| 215 | + .then(function(key) { | ||
| 216 | + ecdhPublicKeys[algorithmName] = key; | ||
| 217 | + }); | ||
| 218 | + } | ||
| 206 | 219 | ||
| 207 | 220 | return Promise.all(promises) | |
| 208 | - .then(function(results) {return {privateKeys: privateKeys, publicKeys: publicKeys, noDeriveKeyKeys: noDeriveKeyKeys}}); | ||
| 221 | + .then(function(results) {return {privateKeys: privateKeys, publicKeys: publicKeys, noDeriveKeyKeys: noDeriveKeyKeys, ecdhKeys: ecdhPublicKeys}}); | ||
| 209 | 222 | } | |
| 210 | 223 | ||
| 211 | 224 | // Compares two ArrayBuffer or ArrayBufferView objects. If bitCount is | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,10 @@ | |||
| 1 | + // META: title=WebCryptoAPI: deriveKey() Using ECDH with CFRG Elliptic Curves | ||
| 2 | + // META: script=cfrg_curves_bits_fixtures.js | ||
| 3 | + // META: script=cfrg_curves_keys.js | ||
| 4 | + | ||
| 5 | + // Define subtests from a `promise_test` to ensure the harness does not | ||
| 6 | + // complete before the subtests are available. `explicit_done` cannot be used | ||
| 7 | + // for this purpose because the global `done` function is automatically invoked | ||
| 8 | + // by the WPT infrastructure in dedicated worker tests defined using the | ||
| 9 | + // "multi-global" pattern. | ||
| 10 | + promise_test(define_tests_25519, 'setup - define tests'); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments