| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -279,6 +279,14 @@ function cfrgImportKey( | |||
| 279 | 279 | 'DataError'); | |
| 280 | 280 | } | |
| 281 | 281 | ||
| 282 | + if (keyData.alg !== undefined && (name === 'Ed25519' || name === 'Ed448')) { | ||
| 283 | + if (keyData.alg !== name && keyData.alg !== 'EdDSA') { | ||
| 284 | + throw lazyDOMException( | ||
| 285 | + 'JWK "alg" does not match the requested algorithm', | ||
| 286 | + 'DataError'); | ||
| 287 | + } | ||
| 288 | + } | ||
| 289 | + | ||
| 282 | 290 | if (!isPublic && typeof keyData.x !== 'string') { | |
| 283 | 291 | throw lazyDOMException('Invalid JWK', 'DataError'); | |
| 284 | 292 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -467,6 +467,7 @@ async function exportKeyJWK(key) { | |||
| 467 | 467 | // Fall through | |
| 468 | 468 | case 'Ed448': | |
| 469 | 469 | jwk.crv ||= key.algorithm.name; | |
| 470 | + jwk.alg = key.algorithm.name; | ||
| 470 | 471 | return jwk; | |
| 471 | 472 | case 'AES-CTR': | |
| 472 | 473 | // Fall through | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,7 +33,7 @@ Last update: | |||
| 33 | 33 | - user-timing: https://github.com/web-platform-tests/wpt/tree/5ae85bf826/user-timing | |
| 34 | 34 | - wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/cde25e7e3c/wasm/jsapi | |
| 35 | 35 | - wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi | |
| 36 | - - WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/3e3374efde/WebCryptoAPI | ||
| 36 | + - WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/edd42c005c/WebCryptoAPI | ||
| 37 | 37 | - webidl/ecmascript-binding/es-exceptions: https://github.com/web-platform-tests/wpt/tree/a370aad338/webidl/ecmascript-binding/es-exceptions | |
| 38 | 38 | - webmessaging/broadcastchannel: https://github.com/web-platform-tests/wpt/tree/6495c91853/webmessaging/broadcastchannel | |
| 39 | 39 | - webstorage: https://github.com/web-platform-tests/wpt/tree/1291340aaa/webstorage | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,7 +11,7 @@ function runTests(algorithmName) { | |||
| 11 | 11 | ['spki', 'jwk', 'raw'].forEach(function(format) { | |
| 12 | 12 | if (format === "jwk") { // Not all fields used for public keys | |
| 13 | 13 | testFormat(format, algorithm, jwkData, algorithmName, usages, extractable); | |
| 14 | - // Test for https://github.com/WICG/webcrypto-secure-curves/pull/24 | ||
| 14 | + // Test for https://github.com/w3c/webcrypto/pull/401 | ||
| 15 | 15 | if (extractable) { | |
| 16 | 16 | testJwkAlgBehaviours(algorithm, jwkData.jwk, algorithmName, usages); | |
| 17 | 17 | } | |
@@ -27,7 +27,7 @@ function runTests(algorithmName) { | |||
| 27 | 27 | ['pkcs8', 'jwk'].forEach(function(format) { | |
| 28 | 28 | testFormat(format, algorithm, data, algorithmName, usages, extractable); | |
| 29 | 29 | ||
| 30 | - // Test for https://github.com/WICG/webcrypto-secure-curves/pull/24 | ||
| 30 | + // Test for https://github.com/w3c/webcrypto/pull/401 | ||
| 31 | 31 | if (format === "jwk" && extractable) { | |
| 32 | 32 | testJwkAlgBehaviours(algorithm, data.jwk, algorithmName, usages); | |
| 33 | 33 | } | |
@@ -67,27 +67,34 @@ function testFormat(format, algorithm, keyData, keySize, usages, extractable) { | |||
| 67 | 67 | }); | |
| 68 | 68 | } | |
| 69 | 69 | ||
| 70 | - // Test importKey/exportKey "alg" behaviours, alg is ignored upon import and alg is missing for Ed25519 and Ed448 JWK export | ||
| 71 | - // https://github.com/WICG/webcrypto-secure-curves/pull/24 | ||
| 70 | + // Test importKey/exportKey "alg" behaviours (https://github.com/w3c/webcrypto/pull/401) | ||
| 71 | + // - alg is ignored for ECDH import | ||
| 72 | + // - TODO: alg is checked to be the algorithm.name or EdDSA for Ed25519 and Ed448 import | ||
| 73 | + // - alg is missing for ECDH export | ||
| 74 | + // - alg is the algorithm name for Ed25519 and Ed448 export | ||
| 72 | 75 | function testJwkAlgBehaviours(algorithm, keyData, crv, usages) { | |
| 73 | 76 | [algorithm, algorithm.name].forEach((alg) => { | |
| 74 | - promise_test(function(test) { | ||
| 75 | - return subtle.importKey('jwk', { ...keyData, alg: 'this is ignored' }, alg, true, usages). | ||
| 76 | - then(function(key) { | ||
| 77 | - assert_equals(key.constructor, CryptoKey, "Imported a CryptoKey object"); | ||
| 78 | - | ||
| 79 | - return subtle.exportKey('jwk', key). | ||
| 80 | - then(function(result) { | ||
| 81 | - assert_equals(Object.keys(result).length, keyData.d ? 6 : 5, "Correct number of JWK members"); | ||
| 82 | - assert_equals(result.alg, undefined, 'No JWK "alg" member is present'); | ||
| 83 | - assert_true(equalJwk(keyData, result), "Round trip works"); | ||
| 84 | - }, function(err) { | ||
| 77 | + (crv.startsWith('Ed') ? [algorithm.name, 'EdDSA'] : ['this is ignored']).forEach((jwkAlg) => { | ||
| 78 | + promise_test(function(test) { | ||
| 79 | + return subtle.importKey('jwk', { ...keyData, alg: jwkAlg }, alg, true, usages). | ||
| 80 | + then(function(key) { | ||
| 81 | + assert_equals(key.constructor, CryptoKey, "Imported a CryptoKey object"); | ||
| 82 | + | ||
| 83 | + return subtle.exportKey('jwk', key). | ||
| 84 | + then(function(result) { | ||
| 85 | + let expectedKeys = crv.startsWith('Ed') ? 6 : 5 | ||
| 86 | + if (keyData.d) expectedKeys++ | ||
| 87 | + assert_equals(Object.keys(result).length, expectedKeys, "Correct number of JWK members"); | ||
| 88 | + assert_equals(result.alg, crv.startsWith('Ed') ? algorithm.name : undefined, 'Expected JWK "alg" member'); | ||
| 89 | + assert_true(equalJwk(keyData, result), "Round trip works"); | ||
| 90 | + }, function(err) { | ||
| 91 | + assert_unreached("Threw an unexpected error: " + err.toString()); | ||
| 92 | + }); | ||
| 93 | + }, function(err) { | ||
| 85 | 94 | assert_unreached("Threw an unexpected error: " + err.toString()); | |
| 86 | - }); | ||
| 87 | - }, function(err) { | ||
| 88 | - assert_unreached("Threw an unexpected error: " + err.toString()); | ||
| 89 | - }); | ||
| 90 | - }, "Good parameters with ignored JWK alg: " + crv.toString() + " " + parameterString('jwk', keyData, alg, true, usages)); | ||
| 95 | + }); | ||
| 96 | + }, 'Good parameters with JWK alg' + (crv.startsWith('Ed') ? ` ${jwkAlg}: ` : ': ') + crv.toString() + " " + parameterString('jwk', keyData, alg, true, usages, jwkAlg)); | ||
| 97 | + }); | ||
| 91 | 98 | }); | |
| 92 | 99 | } | |
| 93 | 100 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -92,7 +92,7 @@ | |||
| 92 | 92 | "path": "wasm/webapi" | |
| 93 | 93 | }, | |
| 94 | 94 | "WebCryptoAPI": { | |
| 95 | - "commit": "3e3374efde7ce73d551ea908d52d0afab046971a", | ||
| 95 | + "commit": "edd42c005cf8192fbae41ec061c14342e7bcac15", | ||
| 96 | 96 | "path": "WebCryptoAPI" | |
| 97 | 97 | }, | |
| 98 | 98 | "webidl/ecmascript-binding/es-exceptions": { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,7 +12,7 @@ const { subtle } = globalThis.crypto; | |||
| 12 | 12 | ||
| 13 | 13 | const keyData = { | |
| 14 | 14 | 'Ed25519': { | |
| 15 | - jwsAlg: 'EdDSA', | ||
| 15 | + jwsAlg: 'Ed25519', | ||
| 16 | 16 | spki: Buffer.from( | |
| 17 | 17 | '302a300506032b6570032100a054b618c12b26c8d43595a5c38dd2b0140b944a' + | |
| 18 | 18 | '151f75003278c2b6c58ec08f', 'hex'), | |
@@ -27,7 +27,7 @@ const keyData = { | |||
| 27 | 27 | } | |
| 28 | 28 | }, | |
| 29 | 29 | 'Ed448': { | |
| 30 | - jwsAlg: 'EdDSA', | ||
| 30 | + jwsAlg: 'Ed448', | ||
| 31 | 31 | spki: Buffer.from( | |
| 32 | 32 | '3043300506032b6571033a0008cc38160c85bca5656ac4924af7ea97a9161b20' + | |
| 33 | 33 | '2528273dcb84afd2eeb99ac912a401b34ef15ef4d9486406a6eecc31e5909219' + | |
@@ -183,10 +183,7 @@ async function testImportJwk({ name, publicUsages, privateUsages }, extractable) | |||
| 183 | 183 | ||
| 184 | 184 | const jwk = keyData[name].jwk; | |
| 185 | 185 | ||
| 186 | - const [ | ||
| 187 | - publicKey, | ||
| 188 | - privateKey, | ||
| 189 | - ] = await Promise.all([ | ||
| 186 | + const tests = [ | ||
| 190 | 187 | subtle.importKey( | |
| 191 | 188 | 'jwk', | |
| 192 | 189 | { | |
@@ -221,7 +218,37 @@ async function testImportJwk({ name, publicUsages, privateUsages }, extractable) | |||
| 221 | 218 | { name }, | |
| 222 | 219 | extractable, | |
| 223 | 220 | privateUsages), | |
| 224 | - ]); | ||
| 221 | + ]; | ||
| 222 | + | ||
| 223 | + // Test the deprecated "alg" value | ||
| 224 | + if (keyData[name].jwsAlg?.startsWith('Ed')) { | ||
| 225 | + tests.push( | ||
| 226 | + subtle.importKey( | ||
| 227 | + 'jwk', | ||
| 228 | + { | ||
| 229 | + alg: 'EdDSA', | ||
| 230 | + kty: jwk.kty, | ||
| 231 | + crv: jwk.crv, | ||
| 232 | + x: jwk.x, | ||
| 233 | + }, | ||
| 234 | + { name }, | ||
| 235 | + extractable, publicUsages), | ||
| 236 | + subtle.importKey( | ||
| 237 | + 'jwk', | ||
| 238 | + { | ||
| 239 | + ...jwk, | ||
| 240 | + alg: 'EdDSA', | ||
| 241 | + }, | ||
| 242 | + { name }, | ||
| 243 | + extractable, | ||
| 244 | + privateUsages), | ||
| 245 | + ); | ||
| 246 | + } | ||
| 247 | + | ||
| 248 | + const [ | ||
| 249 | + publicKey, | ||
| 250 | + privateKey, | ||
| 251 | + ] = await Promise.all(tests); | ||
| 225 | 252 | ||
| 226 | 253 | assert.strictEqual(publicKey.type, 'public'); | |
| 227 | 254 | assert.strictEqual(privateKey.type, 'private'); | |
@@ -259,8 +286,13 @@ async function testImportJwk({ name, publicUsages, privateUsages }, extractable) | |||
| 259 | 286 | assert.strictEqual(pvtJwk.crv, jwk.crv); | |
| 260 | 287 | assert.strictEqual(pvtJwk.d, jwk.d); | |
| 261 | 288 | ||
| 262 | - assert.strictEqual(pubJwk.alg, undefined); | ||
| 263 | - assert.strictEqual(pvtJwk.alg, undefined); | ||
| 289 | + if (jwk.crv.startsWith('Ed')) { | ||
| 290 | + assert.strictEqual(pubJwk.alg, jwk.crv); | ||
| 291 | + assert.strictEqual(pvtJwk.alg, jwk.crv); | ||
| 292 | + } else { | ||
| 293 | + assert.strictEqual(pubJwk.alg, undefined); | ||
| 294 | + assert.strictEqual(pvtJwk.alg, undefined); | ||
| 295 | + } | ||
| 264 | 296 | } else { | |
| 265 | 297 | await assert.rejects( | |
| 266 | 298 | subtle.exportKey('jwk', publicKey), { | |
@@ -284,22 +316,24 @@ async function testImportJwk({ name, publicUsages, privateUsages }, extractable) | |||
| 284 | 316 | { message: 'Invalid JWK "use" Parameter' }); | |
| 285 | 317 | } | |
| 286 | 318 | ||
| 287 | - // The JWK alg member is ignored | ||
| 288 | - // https://github.com/WICG/webcrypto-secure-curves/pull/24 | ||
| 289 | 319 | if (name.startsWith('Ed')) { | |
| 290 | - await subtle.importKey( | ||
| 291 | - 'jwk', | ||
| 292 | - { kty: jwk.kty, x: jwk.x, crv: jwk.crv, alg: 'foo' }, | ||
| 293 | - { name }, | ||
| 294 | - extractable, | ||
| 295 | - publicUsages); | ||
| 320 | + await assert.rejects( | ||
| 321 | + subtle.importKey( | ||
| 322 | + 'jwk', | ||
| 323 | + { kty: jwk.kty, x: jwk.x, crv: jwk.crv, alg: 'foo' }, | ||
| 324 | + { name }, | ||
| 325 | + extractable, | ||
| 326 | + publicUsages), | ||
| 327 | + { message: 'JWK "alg" does not match the requested algorithm' }); | ||
| 296 | 328 | ||
| 297 | - await subtle.importKey( | ||
| 298 | - 'jwk', | ||
| 299 | - { ...jwk, alg: 'foo' }, | ||
| 300 | - { name }, | ||
| 301 | - extractable, | ||
| 302 | - privateUsages); | ||
| 329 | + await assert.rejects( | ||
| 330 | + subtle.importKey( | ||
| 331 | + 'jwk', | ||
| 332 | + { ...jwk, alg: 'foo' }, | ||
| 333 | + { name }, | ||
| 334 | + extractable, | ||
| 335 | + privateUsages), | ||
| 336 | + { message: 'JWK "alg" does not match the requested algorithm' }); | ||
| 303 | 337 | } | |
| 304 | 338 | ||
| 305 | 339 | for (const crv of [undefined, name === 'Ed25519' ? 'Ed448' : 'Ed25519']) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments