Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f4fe58b

Browse filesBrowse files
panvaMylesBorins
authored andcommitted
test,crypto: update WebCryptoAPI WPT
PR-URL: #46575 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent e97e796 commit f4fe58b
Copy full SHA for f4fe58b

File tree

Expand file treeCollapse file tree

10 files changed

+125
-62
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

10 files changed

+125
-62
lines changed
Open diff view settings
Collapse file

‎test/fixtures/wpt/README.md‎

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 numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Last update:
3232
- user-timing: https://github.com/web-platform-tests/wpt/tree/df24fb604e/user-timing
3333
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/d8dbe6990b/wasm/jsapi
3434
- wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi
35-
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/450f829d25/WebCryptoAPI
35+
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/238d9d9bac/WebCryptoAPI
3636
- webidl/ecmascript-binding/es-exceptions: https://github.com/web-platform-tests/wpt/tree/a370aad338/webidl/ecmascript-binding/es-exceptions
3737

3838
[Web Platform Tests]: https://github.com/web-platform-tests/wpt
Collapse file

‎test/fixtures/wpt/WebCryptoAPI/generateKey/successes.js‎

Copy file name to clipboardExpand all lines: test/fixtures/wpt/WebCryptoAPI/generateKey/successes.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function run_test(algorithmNames, slowTest) {
6464
.then(function(result) {
6565
if (resultType === "CryptoKeyPair") {
6666
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");
6868
} else {
6969
assert_goodCryptoKey(result, algorithm, extractable, usages, "secret");
7070
}
Collapse file

‎test/fixtures/wpt/WebCryptoAPI/import_export/ec_importKey.https.any.js‎

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 numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// META: title=WebCryptoAPI: importKey() for EC keys
22
// META: timeout=long
3+
// META: script=../util/helpers.js
34

45
// Test importKey and exportKey for EC algorithms. Only "happy paths" are
56
// currently tested - those where the operation should succeed.
@@ -110,6 +111,7 @@
110111
return subtle.importKey(format, keyData, algorithm, extractable, usages).
111112
then(function(key) {
112113
assert_equals(key.constructor, CryptoKey, "Imported a CryptoKey object");
114+
assert_goodCryptoKey(key, algorithm, extractable, usages, (format === 'pkcs8' || (format === 'jwk' && keyData.d)) ? 'private' : 'public');
113115
if (!extractable) {
114116
return;
115117
}
Collapse file

‎test/fixtures/wpt/WebCryptoAPI/import_export/okp_importKey.https.any.js‎

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 numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// META: title=WebCryptoAPI: importKey() for OKP keys
22
// META: timeout=long
3+
// META: script=../util/helpers.js
34

45
// Test importKey and exportKey for OKP algorithms. Only "happy paths" are
56
// currently tested - those where the operation should succeed.
@@ -104,6 +105,7 @@
104105
return subtle.importKey(format, keyData[format], algorithm, extractable, usages).
105106
then(function(key) {
106107
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');
107109
if (!extractable) {
108110
return;
109111
}
Collapse file

‎test/fixtures/wpt/WebCryptoAPI/import_export/rsa_importKey.https.any.js‎

Copy file name to clipboardExpand all lines: test/fixtures/wpt/WebCryptoAPI/import_export/rsa_importKey.https.any.js
+2Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎test/fixtures/wpt/WebCryptoAPI/import_export/symmetric_importKey.https.any.js‎

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 numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// META: title=WebCryptoAPI: importKey() for symmetric keys
22
// META: timeout=long
3+
// META: script=../util/helpers.js
34

45
// Test importKey and exportKey for non-PKC algorithms. Only "happy paths" are
56
// currently tested - those where the operation should succeed.
@@ -57,13 +58,18 @@
5758
});
5859
});
5960

61+
function hasLength(algorithm) {
62+
return algorithm.name === 'HMAC' || algorithm.name.startsWith('AES');
63+
}
64+
6065
// Test importKey with a given key format and other parameters. If
6166
// extrable is true, export the key and verify that it matches the input.
6267
function testFormat(format, algorithm, keyData, keySize, usages, extractable) {
6368
promise_test(function(test) {
6469
return subtle.importKey(format, keyData, algorithm, extractable, usages).
6570
then(function(key) {
6671
assert_equals(key.constructor, CryptoKey, "Imported a CryptoKey object");
72+
assert_goodCryptoKey(key, hasLength(key.algorithm) ? { length: keySize, ...algorithm } : algorithm, extractable, usages, 'secret');
6773
if (!extractable) {
6874
return;
6975
}
Collapse file

‎test/fixtures/wpt/WebCryptoAPI/sign_verify/rsa.js‎

Copy file name to clipboardExpand all lines: test/fixtures/wpt/WebCryptoAPI/sign_verify/rsa.js
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,35 @@ function run_test() {
306306
all_promises.push(promise);
307307
});
308308

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+
309338
// Verification should fail with wrong plaintext
310339
testVectors.forEach(function(vector) {
311340
var promise = importVectorKeys(vector, ["verify"], ["sign"])
Collapse file

‎test/fixtures/wpt/WebCryptoAPI/util/helpers.js‎

Copy file name to clipboardExpand all lines: test/fixtures/wpt/WebCryptoAPI/util/helpers.js
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var registeredAlgorithmNames = [
1919
"SHA-256",
2020
"SHA-384",
2121
"SHA-512",
22-
"HKDF-CTR",
22+
"HKDF",
2323
"PBKDF2",
2424
"Ed25519",
2525
"Ed448",
@@ -104,9 +104,6 @@ function assert_goodCryptoKey(key, algorithm, extractable, usages, kind) {
104104

105105
assert_equals(key.constructor, CryptoKey, "Is a CryptoKey");
106106
assert_equals(key.type, kind, "Is a " + kind + " key");
107-
if (key.type === "public") {
108-
extractable = true; // public keys are always extractable
109-
}
110107
assert_equals(key.extractable, extractable, "Extractability is correct");
111108

112109
assert_equals(key.algorithm.name, registeredAlgorithmName, "Correct algorithm name");
@@ -130,6 +127,10 @@ function assert_goodCryptoKey(key, algorithm, extractable, usages, kind) {
130127
assert_equals(key.algorithm.hash.name.toUpperCase(), algorithm.hash.toUpperCase(), "Correct hash function");
131128
}
132129

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+
133134
// usages is expected to be provided for a key pair, but we are checking
134135
// only a single key. The publicKey and privateKey portions of a key pair
135136
// recognize only some of the usages appropriate for a key pair.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.