Skip to content

Commit 99bfbed

Browse files
panvadanielleadams
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 c60816a commit 99bfbed

10 files changed

Lines changed: 125 additions & 62 deletions

File tree

‎test/fixtures/wpt/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Last update:
3131
- user-timing: https://github.com/web-platform-tests/wpt/tree/df24fb604e/user-timing
3232
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/d8dbe6990b/wasm/jsapi
3333
- 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
3535
- webidl/ecmascript-binding/es-exceptions: https://github.com/web-platform-tests/wpt/tree/a370aad338/webidl/ecmascript-binding/es-exceptions
3636

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

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

Lines 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
}

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

Lines 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
returnsubtle.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
}

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

Lines 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
returnsubtle.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
}

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

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines 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+
functionhasLength(algorithm){
62+
returnalgorithm.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
functiontestFormat(format,algorithm,keyData,keySize,usages,extractable){
6368
promise_test(function(test){
6469
returnsubtle.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
}

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

Lines 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+
varpromise=importVectorKeys(vector,["verify"],["sign"])
313+
.then(function(vectors){
314+
promise_test(function(test){
315+
constsaltLength=vector.algorithm.saltLength===32 ? 48 : 32;
316+
varoperation=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+
returnoperation;
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
varpromise=importVectorKeys(vector,["verify"],["sign"])

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

Lines 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'inkey.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)