Skip to content

Commit

Permalink
test,crypto: update WebCryptoAPI WPT
Browse files Browse the repository at this point in the history
PR-URL: #45165
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
panva authored and RafaelGSS committed Nov 10, 2022
1 parent 29b9f4f commit 36c5927
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 12 deletions.
2 changes: 1 addition & 1 deletion test/fixtures/wpt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Last update:
- user-timing: https://github.com/web-platform-tests/wpt/tree/df24fb604e/user-timing
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/d8dbe6990b/wasm/jsapi
- wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/edca84af42/WebCryptoAPI
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/0042d42ee6/WebCryptoAPI
- webidl/ecmascript-binding/es-exceptions: https://github.com/web-platform-tests/wpt/tree/a370aad338/webidl/ecmascript-binding/es-exceptions

[Web Platform Tests]: https://github.com/web-platform-tests/wpt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function define_tests() {
promise_test(function(test) {
return subtle.generateKey({name: "AES-CBC", length: 128}, true, ["encrypt", "decrypt"])
.then(function(secretKey) {
subtle.deriveBits({name: algorithmName, public: secretKey}, privateKeys[algorithmName], 8 * sizes[algorithmName])
return subtle.deriveBits({name: algorithmName, public: secretKey}, privateKeys[algorithmName], 8 * sizes[algorithmName])
.then(function(derivation) {
assert_unreached("deriveBits succeeded but should have failed with InvalidAccessError");
}, function(err) {
Expand Down Expand Up @@ -183,6 +183,8 @@ function define_tests() {
false, ["deriveBits", "deriveKey"])
.then(function(key) {
privateKeys[algorithmName] = key;
}, function (err) {
privateKeys[algorithmName] = null;
});
promises.push(operation);
});
Expand All @@ -192,6 +194,8 @@ function define_tests() {
false, ["deriveKey"])
.then(function(key) {
noDeriveBitsKeys[algorithmName] = key;
}, function (err) {
noDeriveBitsKeys[algorithmName] = null;
});
promises.push(operation);
});
Expand All @@ -201,6 +205,8 @@ function define_tests() {
false, [])
.then(function(key) {
publicKeys[algorithmName] = key;
}, function (err) {
publicKeys[algorithmName] = null;
});
promises.push(operation);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function define_tests() {
promise_test(function(test) {
return subtle.generateKey({name: "HMAC", hash: "SHA-256", length: 256}, true, ["sign", "verify"])
.then(function(secretKey) {
subtle.deriveKey({name: algorithmName, public: secretKey}, privateKeys[algorithmName], {name: "AES-CBC", length: 256}, true, ["sign", "verify"])
return subtle.deriveKey({name: algorithmName, public: secretKey}, privateKeys[algorithmName], {name: "AES-CBC", length: 256}, true, ["sign", "verify"])
.then(function(key) {return crypto.subtle.exportKey("raw", key);})
.then(function(exportedKey) {
assert_unreached("deriveKey succeeded but should have failed with InvalidAccessError");
Expand All @@ -151,6 +151,8 @@ function define_tests() {
false, ["deriveBits", "deriveKey"])
.then(function(key) {
privateKeys[algorithmName] = key;
}, function (err) {
privateKeys[algorithmName] = null;
});
promises.push(operation);
});
Expand All @@ -160,6 +162,8 @@ function define_tests() {
false, ["deriveBits"])
.then(function(key) {
noDeriveKeyKeys[algorithmName] = key;
}, function (err) {
noDeriveKeyKeys[algorithmName] = null;
});
promises.push(operation);
});
Expand All @@ -169,6 +173,8 @@ function define_tests() {
false, [])
.then(function(key) {
publicKeys[algorithmName] = key;
}, function (err) {
publicKeys[algorithmName] = null;
});
promises.push(operation);
});
Expand Down
10 changes: 9 additions & 1 deletion test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/ecdh_bits.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function define_tests() {
promise_test(function(test) {
return subtle.generateKey({name: "AES-CBC", length: 128}, true, ["encrypt", "decrypt"])
.then(function(secretKey) {
subtle.deriveBits({name: "ECDH", public: secretKey}, privateKeys[namedCurve], 8 * sizes[namedCurve])
return subtle.deriveBits({name: "ECDH", public: secretKey}, privateKeys[namedCurve], 8 * sizes[namedCurve])
.then(function(derivation) {
assert_unreached("deriveBits succeeded but should have failed with InvalidAccessError");
}, function(err) {
Expand Down Expand Up @@ -199,6 +199,8 @@ function define_tests() {
false, ["deriveBits", "deriveKey"])
.then(function(key) {
privateKeys[namedCurve] = key;
}, function (err) {
privateKeys[namedCurve] = null;
});
promises.push(operation);
});
Expand All @@ -208,6 +210,8 @@ function define_tests() {
false, ["deriveKey"])
.then(function(key) {
noDeriveBitsKeys[namedCurve] = key;
}, function (err) {
noDeriveBitsKeys[namedCurve] = null;
});
promises.push(operation);
});
Expand All @@ -217,13 +221,17 @@ function define_tests() {
false, [])
.then(function(key) {
publicKeys[namedCurve] = key;
}, function (err) {
publicKeys[namedCurve] = null;
});
promises.push(operation);
});
Object.keys(sizes).forEach(function(namedCurve) {
var operation = subtle.generateKey({name: "ECDSA", namedCurve: namedCurve}, false, ["sign", "verify"])
.then(function(keyPair) {
ecdsaKeyPairs[namedCurve] = keyPair;
}, function (err) {
ecdsaKeyPairs[namedCurve] = null;
});
promises.push(operation);
});
Expand Down
10 changes: 9 additions & 1 deletion test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/ecdh_keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function define_tests() {
promise_test(function(test) {
return subtle.generateKey({name: "HMAC", hash: "SHA-256", length: 256}, true, ["sign", "verify"])
.then(function(secretKey) {
subtle.deriveKey({name: "ECDH", public: secretKey}, privateKeys[namedCurve], {name: "AES-CBC", length: 256}, true, ["sign", "verify"])
return subtle.deriveKey({name: "ECDH", public: secretKey}, privateKeys[namedCurve], {name: "AES-CBC", length: 256}, true, ["sign", "verify"])
.then(function(key) {return crypto.subtle.exportKey("raw", key);})
.then(function(exportedKey) {
assert_unreached("deriveKey succeeded but should have failed with InvalidAccessError");
Expand All @@ -168,6 +168,8 @@ function define_tests() {
false, ["deriveBits", "deriveKey"])
.then(function(key) {
privateKeys[namedCurve] = key;
}, function (err) {
privateKeys[namedCurve] = null;
});
promises.push(operation);
});
Expand All @@ -177,6 +179,8 @@ function define_tests() {
false, ["deriveBits"])
.then(function(key) {
noDeriveKeyKeys[namedCurve] = key;
}, function (err) {
noDeriveKeyKeys[namedCurve] = null;
});
promises.push(operation);
});
Expand All @@ -186,13 +190,17 @@ function define_tests() {
false, [])
.then(function(key) {
publicKeys[namedCurve] = key;
}, function (err) {
publicKeys[namedCurve] = null;
});
promises.push(operation);
});
Object.keys(sizes).forEach(function(namedCurve) {
var operation = subtle.generateKey({name: "ECDSA", namedCurve: namedCurve}, false, ["sign", "verify"])
.then(function(keyPair) {
ecdsaKeyPairs[namedCurve] = keyPair;
}, function (err) {
ecdsaKeyPairs[namedCurve] = null;
});
promises.push(operation);
});
Expand Down
31 changes: 25 additions & 6 deletions test/fixtures/wpt/WebCryptoAPI/util/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,22 @@ function assert_goodCryptoKey(key, algorithm, extractable, usages, kind) {
assert_equals(key.extractable, extractable, "Extractability is correct");

assert_equals(key.algorithm.name, registeredAlgorithmName, "Correct algorithm name");
assert_equals(key.algorithm.length, algorithm.length, "Correct length");
if (key.algorithm.name.toUpperCase() === "HMAC" && algorithm.length === undefined) {
switch (key.algorithm.hash.name.toUpperCase()) {
case 'SHA-1':
case 'SHA-256':
assert_equals(key.algorithm.length, 512, "Correct length");
break;
case 'SHA-384':
case 'SHA-512':
assert_equals(key.algorithm.length, 1024, "Correct length");
break;
default:
assert_unreached("Unrecognized hash");
}
} else {
assert_equals(key.algorithm.length, algorithm.length, "Correct length");
}
if (["HMAC", "RSASSA-PKCS1-v1_5", "RSA-PSS"].includes(registeredAlgorithmName)) {
assert_equals(key.algorithm.hash.name.toUpperCase(), algorithm.hash.toUpperCase(), "Correct hash function");
}
Expand Down Expand Up @@ -166,12 +181,16 @@ function allAlgorithmSpecifiersFor(algorithmName) {
});
} else if (algorithmName.toUpperCase() === "HMAC") {
[
{name: "SHA-1", length: 160},
{name: "SHA-256", length: 256},
{name: "SHA-384", length: 384},
{name: "SHA-512", length: 512}
{hash: "SHA-1", length: 160},
{hash: "SHA-256", length: 256},
{hash: "SHA-384", length: 384},
{hash: "SHA-512", length: 512},
{hash: "SHA-1"},
{hash: "SHA-256"},
{hash: "SHA-384"},
{hash: "SHA-512"},
].forEach(function(hashAlgorithm) {
results.push({name: algorithmName, hash: hashAlgorithm.name, length: hashAlgorithm.length});
results.push({name: algorithmName, ...hashAlgorithm});
});
} else if (algorithmName.toUpperCase().substring(0, 3) === "RSA") {
hashes.forEach(function(hashName) {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/wpt/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"path": "wasm/webapi"
},
"WebCryptoAPI": {
"commit": "edca84af42bd7e84da94e63b322fe343191842d2",
"commit": "0042d42ee69baf05a4ac4f5745be9c3b92c04e25",
"path": "WebCryptoAPI"
},
"webidl/ecmascript-binding/es-exceptions": {
Expand Down

0 comments on commit 36c5927

Please sign in to comment.