GeezerVison is showing github.com — test,crypto: update WebCryptoAPI WPT · nodejs/node@99bfbed
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: test/fixtures/wpt/README.md +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -31,7 +31,7 @@ Last update: | 31 | 31 | - user-timing: https://github.com/web-platform-tests/wpt/tree/df24fb604e/user-timing | 32 | 32 | - wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/d8dbe6990b/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/450f829d25/WebCryptoAPI | | 34 | +- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/238d9d9bac/WebCryptoAPI | 35 | 35 | - webidl/ecmascript-binding/es-exceptions: https://github.com/web-platform-tests/wpt/tree/a370aad338/webidl/ecmascript-binding/es-exceptions | 36 | 36 |
| 37 | 37 | [Web Platform Tests]: https://github.com/web-platform-tests/wpt | |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/wpt/WebCryptoAPI/generateKey/successes.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -64,7 +64,7 @@ function run_test(algorithmNames, slowTest) { | 64 | 64 | .then(function(result) { | 65 | 65 | if (resultType === "CryptoKeyPair") { | 66 | 66 | assert_goodCryptoKey(result.privateKey, algorithm, extractable, usages, "private"); | 67 | | - assert_goodCryptoKey(result.publicKey, algorithm, extractable, usages, "public"); | | 67 | + assert_goodCryptoKey(result.publicKey, algorithm, true, usages, "public"); | 68 | 68 | } else { | 69 | 69 | assert_goodCryptoKey(result, algorithm, extractable, usages, "secret"); | 70 | 70 | } | |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/wpt/WebCryptoAPI/import_export/ec_importKey.https.any.js +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | // META: title=WebCryptoAPI: importKey() for EC keys | 2 | 2 | // META: timeout=long | | 3 | +// META: script=../util/helpers.js | 3 | 4 |
| 4 | 5 | // Test importKey and exportKey for EC algorithms. Only "happy paths" are | 5 | 6 | // currently tested - those where the operation should succeed. | | 110 | 111 | return subtle.importKey(format, keyData, algorithm, extractable, usages). | 111 | 112 | then(function(key) { | 112 | 113 | assert_equals(key.constructor, CryptoKey, "Imported a CryptoKey object"); | | 114 | + assert_goodCryptoKey(key, algorithm, extractable, usages, (format === 'pkcs8' || (format === 'jwk' && keyData.d)) ? 'private' : 'public'); | 113 | 115 | if (!extractable) { | 114 | 116 | return; | 115 | 117 | } | |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/wpt/WebCryptoAPI/import_export/okp_importKey.https.any.js +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | // META: title=WebCryptoAPI: importKey() for OKP keys | 2 | 2 | // META: timeout=long | | 3 | +// META: script=../util/helpers.js | 3 | 4 |
| 4 | 5 | // Test importKey and exportKey for OKP algorithms. Only "happy paths" are | 5 | 6 | // currently tested - those where the operation should succeed. | | 104 | 105 | return subtle.importKey(format, keyData[format], algorithm, extractable, usages). | 105 | 106 | then(function(key) { | 106 | 107 | assert_equals(key.constructor, CryptoKey, "Imported a CryptoKey object"); | | 108 | + assert_goodCryptoKey(key, algorithm, extractable, usages, (format === 'pkcs8' || (format === 'jwk' && keyData[format].d)) ? 'private' : 'public'); | 107 | 109 | if (!extractable) { | 108 | 110 | return; | 109 | 111 | } | |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/wpt/WebCryptoAPI/import_export/rsa_importKey.https.any.js +2Lines changed: 2 additions & 0 deletions Collapse file Copy file name to clipboardExpand all lines: test/fixtures/wpt/WebCryptoAPI/import_export/symmetric_importKey.https.any.js +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | // META: title=WebCryptoAPI: importKey() for symmetric keys | 2 | 2 | // META: timeout=long | | 3 | +// META: script=../util/helpers.js | 3 | 4 |
| 4 | 5 | // Test importKey and exportKey for non-PKC algorithms. Only "happy paths" are | 5 | 6 | // currently tested - those where the operation should succeed. | | 57 | 58 | }); | 58 | 59 | }); | 59 | 60 |
| | 61 | + function hasLength(algorithm) { | | 62 | + return algorithm.name === 'HMAC' || algorithm.name.startsWith('AES'); | | 63 | + } | | 64 | + | 60 | 65 | // Test importKey with a given key format and other parameters. If | 61 | 66 | // extrable is true, export the key and verify that it matches the input. | 62 | 67 | function testFormat(format, algorithm, keyData, keySize, usages, extractable) { | 63 | 68 | promise_test(function(test) { | 64 | 69 | return subtle.importKey(format, keyData, algorithm, extractable, usages). | 65 | 70 | then(function(key) { | 66 | 71 | assert_equals(key.constructor, CryptoKey, "Imported a CryptoKey object"); | | 72 | + assert_goodCryptoKey(key, hasLength(key.algorithm) ? { length: keySize, ...algorithm } : algorithm, extractable, usages, 'secret'); | 67 | 73 | if (!extractable) { | 68 | 74 | return; | 69 | 75 | } | |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/wpt/WebCryptoAPI/sign_verify/rsa.js +29Lines changed: 29 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -306,6 +306,35 @@ function run_test() { | 306 | 306 | all_promises.push(promise); | 307 | 307 | }); | 308 | 308 |
| | 309 | + // [RSA-PSS] Verification should fail with wrong saltLength | | 310 | + testVectors.forEach(function(vector) { | | 311 | + if (vector.algorithm.name === "RSA-PSS") { | | 312 | + var promise = importVectorKeys(vector, ["verify"], ["sign"]) | | 313 | + .then(function(vectors) { | | 314 | + promise_test(function(test) { | | 315 | + const saltLength = vector.algorithm.saltLength === 32 ? 48 : 32; | | 316 | + var operation = subtle.verify({ ...vector.algorithm, saltLength }, vector.publicKey, vector.signature, vector.plaintext) | | 317 | + .then(function(is_verified) { | | 318 | + assert_false(is_verified, "Signature NOT verified"); | | 319 | + }, function(err) { | | 320 | + assert_unreached("Verification should not throw error " + vector.name + ": " + err.message + "'"); | | 321 | + }); | | 322 | + | | 323 | + return operation; | | 324 | + }, vector.name + " verification failure with wrong saltLength"); | | 325 | + | | 326 | + }, function(err) { | | 327 | + // We need a failed test if the importVectorKey operation fails, so | | 328 | + // we know we never tested verification. | | 329 | + promise_test(function(test) { | | 330 | + assert_unreached("importVectorKeys failed for " + vector.name + ". Message: ''" + err.message + "''"); | | 331 | + }, "importVectorKeys step: " + vector.name + " verification failure with wrong saltLength"); | | 332 | + }); | | 333 | + | | 334 | + all_promises.push(promise); | | 335 | + } | | 336 | + }); | | 337 | + | 309 | 338 | // Verification should fail with wrong plaintext | 310 | 339 | testVectors.forEach(function(vector) { | 311 | 340 | var promise = importVectorKeys(vector, ["verify"], ["sign"]) | |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/wpt/WebCryptoAPI/util/helpers.js +5-4Lines changed: 5 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -19,7 +19,7 @@ var registeredAlgorithmNames = [ | 19 | 19 | "SHA-256", | 20 | 20 | "SHA-384", | 21 | 21 | "SHA-512", | 22 | | - "HKDF-CTR", | | 22 | + "HKDF", | 23 | 23 | "PBKDF2", | 24 | 24 | "Ed25519", | 25 | 25 | "Ed448", | @@ -104,9 +104,6 @@ function assert_goodCryptoKey(key, algorithm, extractable, usages, kind) { | 104 | 104 |
| 105 | 105 | assert_equals(key.constructor, CryptoKey, "Is a CryptoKey"); | 106 | 106 | assert_equals(key.type, kind, "Is a " + kind + " key"); | 107 | | - if (key.type === "public") { | 108 | | - extractable = true; // public keys are always extractable | 109 | | - } | 110 | 107 | assert_equals(key.extractable, extractable, "Extractability is correct"); | 111 | 108 |
| 112 | 109 | assert_equals(key.algorithm.name, registeredAlgorithmName, "Correct algorithm name"); | @@ -130,6 +127,10 @@ function assert_goodCryptoKey(key, algorithm, extractable, usages, kind) { | 130 | 127 | assert_equals(key.algorithm.hash.name.toUpperCase(), algorithm.hash.toUpperCase(), "Correct hash function"); | 131 | 128 | } | 132 | 129 |
| | 130 | + if (/^(?:Ed|X)(?:25519|448)$/.test(key.algorithm.name)) { | | 131 | + assert_false('namedCurve' in key.algorithm, "Does not have a namedCurve property"); | | 132 | + } | | 133 | + | 133 | 134 | // usages is expected to be provided for a key pair, but we are checking | 134 | 135 | // only a single key. The publicKey and privateKey portions of a key pair | 135 | 136 | // recognize only some of the usages appropriate for a key pair. | |
|