summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/WebCryptoAPI/generateKey
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/WebCryptoAPI/generateKey')
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/failures.js220
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/failures_AES-CBC.https.any.js5
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/failures_AES-CTR.https.any.js5
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/failures_AES-GCM.https.any.js5
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/failures_AES-KW.https.any.js5
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/failures_ECDH.https.any.js5
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/failures_ECDSA.https.any.js5
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/failures_Ed25519.https.any.js5
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/failures_Ed448.https.any.js5
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/failures_HMAC.https.any.js5
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/failures_RSA-OAEP.https.any.js5
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/failures_RSA-PSS.https.any.js5
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/failures_RSASSA-PKCS1-v1_5.https.any.js5
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/failures_X25519.https.any.js5
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/failures_X448.https.any.js5
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/successes.js91
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/successes_AES-CBC.https.any.js6
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/successes_AES-CTR.https.any.js6
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/successes_AES-GCM.https.any.js6
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/successes_AES-KW.https.any.js6
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/successes_ECDH.https.any.js6
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/successes_ECDSA.https.any.js6
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/successes_Ed25519.https.any.js6
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/successes_Ed448.https.any.js6
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/successes_HMAC.https.any.js6
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/successes_RSA-OAEP.https.any.js22
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/successes_RSA-PSS.https.any.js10
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/successes_RSASSA-PKCS1-v1_5.https.any.js10
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/successes_X25519.https.any.js6
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/generateKey/successes_X448.https.any.js6
30 files changed, 489 insertions, 0 deletions
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/failures.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures.js
new file mode 100644
index 0000000000..c39e4d211c
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures.js
@@ -0,0 +1,220 @@
+function run_test(algorithmNames) {
+ var subtle = crypto.subtle; // Change to test prefixed implementations
+
+ setup({explicit_timeout: true});
+
+// These tests check that generateKey throws an error, and that
+// the error is of the right type, for a wide set of incorrect parameters.
+//
+// Error testing occurs by setting the parameter that should trigger the
+// error to an invalid value, then combining that with all valid
+// parameters that should be checked earlier by generateKey, and all
+// valid and invalid parameters that should be checked later by
+// generateKey.
+//
+// There are a lot of combinations of possible parameters for both
+// success and failure modes, resulting in a very large number of tests
+// performed.
+
+
+// Setup: define the correct behaviors that should be sought, and create
+// helper functions that generate all possible test parameters for
+// different situations.
+
+ var allTestVectors = [ // Parameters that should work for generateKey
+ {name: "AES-CTR", resultType: CryptoKey, usages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"], mandatoryUsages: []},
+ {name: "AES-CBC", resultType: CryptoKey, usages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"], mandatoryUsages: []},
+ {name: "AES-GCM", resultType: CryptoKey, usages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"], mandatoryUsages: []},
+ {name: "AES-KW", resultType: CryptoKey, usages: ["wrapKey", "unwrapKey"], mandatoryUsages: []},
+ {name: "HMAC", resultType: CryptoKey, usages: ["sign", "verify"], mandatoryUsages: []},
+ {name: "RSASSA-PKCS1-v1_5", resultType: "CryptoKeyPair", usages: ["sign", "verify"], mandatoryUsages: ["sign"]},
+ {name: "RSA-PSS", resultType: "CryptoKeyPair", usages: ["sign", "verify"], mandatoryUsages: ["sign"]},
+ {name: "RSA-OAEP", resultType: "CryptoKeyPair", usages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"], mandatoryUsages: ["decrypt", "unwrapKey"]},
+ {name: "ECDSA", resultType: "CryptoKeyPair", usages: ["sign", "verify"], mandatoryUsages: ["sign"]},
+ {name: "ECDH", resultType: "CryptoKeyPair", usages: ["deriveKey", "deriveBits"], mandatoryUsages: ["deriveKey", "deriveBits"]},
+ {name: "Ed25519", resultType: "CryptoKeyPair", usages: ["sign", "verify"], mandatoryUsages: ["sign"]},
+ {name: "Ed448", resultType: "CryptoKeyPair", usages: ["sign", "verify"], mandatoryUsages: ["sign"]},
+ {name: "X25519", resultType: "CryptoKeyPair", usages: ["deriveKey", "deriveBits"], mandatoryUsages: ["deriveKey", "deriveBits"]},
+ {name: "X448", resultType: "CryptoKeyPair", usages: ["deriveKey", "deriveBits"], mandatoryUsages: ["deriveKey", "deriveBits"]},
+ ];
+
+ var testVectors = [];
+ if (algorithmNames && !Array.isArray(algorithmNames)) {
+ algorithmNames = [algorithmNames];
+ };
+ allTestVectors.forEach(function(vector) {
+ if (!algorithmNames || algorithmNames.includes(vector.name)) {
+ testVectors.push(vector);
+ }
+ });
+
+
+ function parameterString(algorithm, extractable, usages) {
+ if (typeof algorithm !== "object" && typeof algorithm !== "string") {
+ alert(algorithm);
+ }
+
+ var result = "(" +
+ objectToString(algorithm) + ", " +
+ objectToString(extractable) + ", " +
+ objectToString(usages) +
+ ")";
+
+ return result;
+ }
+
+ // Test that a given combination of parameters results in an error,
+ // AND that it is the correct kind of error.
+ //
+ // Expected error is either a number, tested against the error code,
+ // or a string, tested against the error name.
+ function testError(algorithm, extractable, usages, expectedError, testTag) {
+ promise_test(function(test) {
+ return crypto.subtle.generateKey(algorithm, extractable, usages)
+ .then(function(result) {
+ assert_unreached("Operation succeeded, but should not have");
+ }, function(err) {
+ if (typeof expectedError === "number") {
+ assert_equals(err.code, expectedError, testTag + " not supported");
+ } else {
+ assert_equals(err.name, expectedError, testTag + " not supported");
+ }
+ });
+ }, testTag + ": generateKey" + parameterString(algorithm, extractable, usages));
+ }
+
+
+ // Given an algorithm name, create several invalid parameters.
+ function badAlgorithmPropertySpecifiersFor(algorithmName) {
+ var results = [];
+
+ if (algorithmName.toUpperCase().substring(0, 3) === "AES") {
+ // Specifier properties are name and length
+ [64, 127, 129, 255, 257, 512].forEach(function(length) {
+ results.push({name: algorithmName, length: length});
+ });
+ } else if (algorithmName.toUpperCase().substring(0, 3) === "RSA") {
+ [new Uint8Array([1]), new Uint8Array([1,0,0])].forEach(function(publicExponent) {
+ results.push({name: algorithmName, hash: "SHA-256", modulusLength: 1024, publicExponent: publicExponent});
+ });
+ } else if (algorithmName.toUpperCase().substring(0, 2) === "EC") {
+ ["P-512", "Curve25519"].forEach(function(curveName) {
+ results.push({name: algorithmName, namedCurve: curveName});
+ });
+ }
+
+ return results;
+ }
+
+
+ // Don't create an exhaustive list of all invalid usages,
+ // because there would usually be nearly 2**8 of them,
+ // way too many to test. Instead, create every singleton
+ // of an illegal usage, and "poison" every valid usage
+ // with an illegal one.
+ function invalidUsages(validUsages, mandatoryUsages) {
+ var results = [];
+
+ var illegalUsages = [];
+ ["encrypt", "decrypt", "sign", "verify", "wrapKey", "unwrapKey", "deriveKey", "deriveBits"].forEach(function(usage) {
+ if (!validUsages.includes(usage)) {
+ illegalUsages.push(usage);
+ }
+ });
+
+ var goodUsageCombinations = allValidUsages(validUsages, false, mandatoryUsages);
+
+ illegalUsages.forEach(function(illegalUsage) {
+ results.push([illegalUsage]);
+ goodUsageCombinations.forEach(function(usageCombination) {
+ results.push(usageCombination.concat([illegalUsage]));
+ });
+ });
+
+ return results;
+ }
+
+
+// Now test for properly handling errors
+// - Unsupported algorithm
+// - Bad usages for algorithm
+// - Bad key lengths
+
+ // Algorithm normalization should fail with "Not supported"
+ var badAlgorithmNames = [
+ "AES",
+ {name: "AES"},
+ {name: "AES", length: 128},
+ {name: "AES-CMAC", length: 128}, // Removed after CR
+ {name: "AES-CFB", length: 128}, // Removed after CR
+ {name: "HMAC", hash: "MD5"},
+ {name: "RSA", hash: "SHA-256", modulusLength: 2048, publicExponent: new Uint8Array([1,0,1])},
+ {name: "RSA-PSS", hash: "SHA", modulusLength: 2048, publicExponent: new Uint8Array([1,0,1])},
+ {name: "EC", namedCurve: "P521"}
+ ];
+
+
+ // Algorithm normalization failures should be found first
+ // - all other parameters can be good or bad, should fail
+ // due to NotSupportedError.
+ badAlgorithmNames.forEach(function(algorithm) {
+ allValidUsages(["decrypt", "sign", "deriveBits"], true, []) // Small search space, shouldn't matter because should fail before used
+ .forEach(function(usages) {
+ [false, true, "RED", 7].forEach(function(extractable){
+ testError(algorithm, extractable, usages, "NotSupportedError", "Bad algorithm");
+ });
+ });
+ });
+
+
+ // Algorithms normalize okay, but usages bad (though not empty).
+ // It shouldn't matter what other extractable is. Should fail
+ // due to SyntaxError
+ testVectors.forEach(function(vector) {
+ var name = vector.name;
+
+ allAlgorithmSpecifiersFor(name).forEach(function(algorithm) {
+ invalidUsages(vector.usages, vector.mandatoryUsages).forEach(function(usages) {
+ [true].forEach(function(extractable) {
+ testError(algorithm, extractable, usages, "SyntaxError", "Bad usages");
+ });
+ });
+ });
+ });
+
+
+ // Other algorithm properties should be checked next, so try good
+ // algorithm names and usages, but bad algorithm properties next.
+ // - Special case: normally bad usage [] isn't checked until after properties,
+ // so it's included in this test case. It should NOT cause an error.
+ testVectors.forEach(function(vector) {
+ var name = vector.name;
+ badAlgorithmPropertySpecifiersFor(name).forEach(function(algorithm) {
+ allValidUsages(vector.usages, true, vector.mandatoryUsages)
+ .forEach(function(usages) {
+ [false, true].forEach(function(extractable) {
+ if (name.substring(0,2) === "EC") {
+ testError(algorithm, extractable, usages, "NotSupportedError", "Bad algorithm property");
+ } else {
+ testError(algorithm, extractable, usages, "OperationError", "Bad algorithm property");
+ }
+ });
+ });
+ });
+ });
+
+
+ // The last thing that should be checked is an empty usages (for secret keys).
+ testVectors.forEach(function(vector) {
+ var name = vector.name;
+
+ allAlgorithmSpecifiersFor(name).forEach(function(algorithm) {
+ var usages = [];
+ [false, true].forEach(function(extractable) {
+ testError(algorithm, extractable, usages, "SyntaxError", "Empty usages");
+ });
+ });
+ });
+
+
+}
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_AES-CBC.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_AES-CBC.https.any.js
new file mode 100644
index 0000000000..38bed1cc70
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_AES-CBC.https.any.js
@@ -0,0 +1,5 @@
+// META: title=WebCryptoAPI: generateKey() for Failures
+// META: timeout=long
+// META: script=../util/helpers.js
+// META: script=failures.js
+run_test(["AES-CBC"]);
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_AES-CTR.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_AES-CTR.https.any.js
new file mode 100644
index 0000000000..0e7940775f
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_AES-CTR.https.any.js
@@ -0,0 +1,5 @@
+// META: title=WebCryptoAPI: generateKey() for Failures
+// META: timeout=long
+// META: script=../util/helpers.js
+// META: script=failures.js
+run_test(["AES-CTR"]);
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_AES-GCM.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_AES-GCM.https.any.js
new file mode 100644
index 0000000000..a394c8b629
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_AES-GCM.https.any.js
@@ -0,0 +1,5 @@
+// META: title=WebCryptoAPI: generateKey() for Failures
+// META: timeout=long
+// META: script=../util/helpers.js
+// META: script=failures.js
+run_test(["AES-GCM"]);
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_AES-KW.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_AES-KW.https.any.js
new file mode 100644
index 0000000000..40c199b29a
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_AES-KW.https.any.js
@@ -0,0 +1,5 @@
+// META: title=WebCryptoAPI: generateKey() for Failures
+// META: timeout=long
+// META: script=../util/helpers.js
+// META: script=failures.js
+run_test(["AES-KW"]);
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_ECDH.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_ECDH.https.any.js
new file mode 100644
index 0000000000..e522254d74
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_ECDH.https.any.js
@@ -0,0 +1,5 @@
+// META: title=WebCryptoAPI: generateKey() for Failures
+// META: timeout=long
+// META: script=../util/helpers.js
+// META: script=failures.js
+run_test(["ECDH"]);
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_ECDSA.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_ECDSA.https.any.js
new file mode 100644
index 0000000000..e19974ff48
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_ECDSA.https.any.js
@@ -0,0 +1,5 @@
+// META: title=WebCryptoAPI: generateKey() for Failures
+// META: timeout=long
+// META: script=../util/helpers.js
+// META: script=failures.js
+run_test(["ECDSA"]);
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_Ed25519.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_Ed25519.https.any.js
new file mode 100644
index 0000000000..8f18fb1efe
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_Ed25519.https.any.js
@@ -0,0 +1,5 @@
+// META: title=WebCryptoAPI: generateKey() for Failures
+// META: timeout=long
+// META: script=../util/helpers.js
+// META: script=failures.js
+run_test(["Ed25519"]);
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_Ed448.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_Ed448.https.any.js
new file mode 100644
index 0000000000..b25dcd1490
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_Ed448.https.any.js
@@ -0,0 +1,5 @@
+// META: title=WebCryptoAPI: generateKey() for Failures
+// META: timeout=long
+// META: script=../util/helpers.js
+// META: script=failures.js
+run_test(["Ed448"]);
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_HMAC.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_HMAC.https.any.js
new file mode 100644
index 0000000000..43ce1c026f
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_HMAC.https.any.js
@@ -0,0 +1,5 @@
+// META: title=WebCryptoAPI: generateKey() for Failures
+// META: timeout=long
+// META: script=../util/helpers.js
+// META: script=failures.js
+run_test(["HMAC"]);
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_RSA-OAEP.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_RSA-OAEP.https.any.js
new file mode 100644
index 0000000000..1d2bca96b1
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_RSA-OAEP.https.any.js
@@ -0,0 +1,5 @@
+// META: title=WebCryptoAPI: generateKey() for Failures
+// META: timeout=long
+// META: script=../util/helpers.js
+// META: script=failures.js
+run_test(["RSA-OAEP"]);
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_RSA-PSS.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_RSA-PSS.https.any.js
new file mode 100644
index 0000000000..562f66697c
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_RSA-PSS.https.any.js
@@ -0,0 +1,5 @@
+// META: title=WebCryptoAPI: generateKey() for Failures
+// META: timeout=long
+// META: script=../util/helpers.js
+// META: script=failures.js
+run_test(["RSA-PSS"]);
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_RSASSA-PKCS1-v1_5.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_RSASSA-PKCS1-v1_5.https.any.js
new file mode 100644
index 0000000000..fb19308de6
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_RSASSA-PKCS1-v1_5.https.any.js
@@ -0,0 +1,5 @@
+// META: title=WebCryptoAPI: generateKey() for Failures
+// META: timeout=long
+// META: script=../util/helpers.js
+// META: script=failures.js
+run_test(["RSASSA-PKCS1-v1_5"]);
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_X25519.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_X25519.https.any.js
new file mode 100644
index 0000000000..2662d8697a
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_X25519.https.any.js
@@ -0,0 +1,5 @@
+// META: title=WebCryptoAPI: generateKey() for Failures
+// META: timeout=long
+// META: script=../util/helpers.js
+// META: script=failures.js
+run_test(["X25519"]);
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_X448.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_X448.https.any.js
new file mode 100644
index 0000000000..455e260d1f
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/failures_X448.https.any.js
@@ -0,0 +1,5 @@
+// META: title=WebCryptoAPI: generateKey() for Failures
+// META: timeout=long
+// META: script=../util/helpers.js
+// META: script=failures.js
+run_test(["X448"]);
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/successes.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes.js
new file mode 100644
index 0000000000..4a047aa060
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes.js
@@ -0,0 +1,91 @@
+
+function run_test(algorithmNames, slowTest) {
+ var subtle = crypto.subtle; // Change to test prefixed implementations
+
+ setup({explicit_timeout: true});
+
+// These tests check that generateKey successfully creates keys
+// when provided any of a wide set of correct parameters.
+//
+// There are a lot of combinations of possible parameters,
+// resulting in a very large number of tests
+// performed.
+
+
+// Setup: define the correct behaviors that should be sought, and create
+// helper functions that generate all possible test parameters for
+// different situations.
+
+ var allTestVectors = [ // Parameters that should work for generateKey
+ {name: "AES-CTR", resultType: CryptoKey, usages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"], mandatoryUsages: []},
+ {name: "AES-CBC", resultType: CryptoKey, usages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"], mandatoryUsages: []},
+ {name: "AES-GCM", resultType: CryptoKey, usages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"], mandatoryUsages: []},
+ {name: "AES-KW", resultType: CryptoKey, usages: ["wrapKey", "unwrapKey"], mandatoryUsages: []},
+ {name: "HMAC", resultType: CryptoKey, usages: ["sign", "verify"], mandatoryUsages: []},
+ {name: "RSASSA-PKCS1-v1_5", resultType: "CryptoKeyPair", usages: ["sign", "verify"], mandatoryUsages: ["sign"]},
+ {name: "RSA-PSS", resultType: "CryptoKeyPair", usages: ["sign", "verify"], mandatoryUsages: ["sign"]},
+ {name: "RSA-OAEP", resultType: "CryptoKeyPair", usages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"], mandatoryUsages: ["decrypt", "unwrapKey"]},
+ {name: "ECDSA", resultType: "CryptoKeyPair", usages: ["sign", "verify"], mandatoryUsages: ["sign"]},
+ {name: "ECDH", resultType: "CryptoKeyPair", usages: ["deriveKey", "deriveBits"], mandatoryUsages: ["deriveKey", "deriveBits"]},
+ {name: "Ed25519", resultType: "CryptoKeyPair", usages: ["sign", "verify"], mandatoryUsages: ["sign"]},
+ {name: "Ed448", resultType: "CryptoKeyPair", usages: ["sign", "verify"], mandatoryUsages: ["sign"]},
+ {name: "X25519", resultType: "CryptoKeyPair", usages: ["deriveKey", "deriveBits"], mandatoryUsages: ["deriveKey", "deriveBits"]},
+ {name: "X448", resultType: "CryptoKeyPair", usages: ["deriveKey", "deriveBits"], mandatoryUsages: ["deriveKey", "deriveBits"]},
+ ];
+
+ var testVectors = [];
+ if (algorithmNames && !Array.isArray(algorithmNames)) {
+ algorithmNames = [algorithmNames];
+ };
+ allTestVectors.forEach(function(vector) {
+ if (!algorithmNames || algorithmNames.includes(vector.name)) {
+ testVectors.push(vector);
+ }
+ });
+
+ function parameterString(algorithm, extractable, usages) {
+ var result = "(" +
+ objectToString(algorithm) + ", " +
+ objectToString(extractable) + ", " +
+ objectToString(usages) +
+ ")";
+
+ return result;
+ }
+
+ // Test that a given combination of parameters is successful
+ function testSuccess(algorithm, extractable, usages, resultType, testTag) {
+ // algorithm, extractable, and usages are the generateKey parameters
+ // resultType is the expected result, either the CryptoKey object or "CryptoKeyPair"
+ // testTag is a string to prepend to the test name.
+
+ promise_test(function(test) {
+ return subtle.generateKey(algorithm, extractable, usages)
+ .then(function(result) {
+ if (resultType === "CryptoKeyPair") {
+ assert_goodCryptoKey(result.privateKey, algorithm, extractable, usages, "private");
+ assert_goodCryptoKey(result.publicKey, algorithm, extractable, usages, "public");
+ } else {
+ assert_goodCryptoKey(result, algorithm, extractable, usages, "secret");
+ }
+ }, function(err) {
+ assert_unreached("Threw an unexpected error: " + err.toString());
+ });
+ }, testTag + ": generateKey" + parameterString(algorithm, extractable, usages));
+ }
+
+ // Test all valid sets of parameters for successful
+ // key generation.
+ testVectors.forEach(function(vector) {
+ allNameVariants(vector.name, slowTest).forEach(function(name) {
+ allAlgorithmSpecifiersFor(name).forEach(function(algorithm) {
+ allValidUsages(vector.usages, false, vector.mandatoryUsages).forEach(function(usages) {
+ [false, true].forEach(function(extractable) {
+ subsetTest(testSuccess, algorithm, extractable, usages, vector.resultType, "Success");
+ });
+ });
+ });
+ });
+ });
+
+}
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_AES-CBC.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_AES-CBC.https.any.js
new file mode 100644
index 0000000000..80f92c2cb7
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_AES-CBC.https.any.js
@@ -0,0 +1,6 @@
+// META: title=WebCryptoAPI: generateKey() Successful Calls
+// META: timeout=long
+// META: script=../util/helpers.js
+// META: script=/common/subset-tests.js
+// META: script=successes.js
+run_test(["AES-CBC"]);
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_AES-CTR.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_AES-CTR.https.any.js
new file mode 100644
index 0000000000..243a104b60
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_AES-CTR.https.any.js
@@ -0,0 +1,6 @@
+// META: title=WebCryptoAPI: generateKey() Successful Calls
+// META: timeout=long
+// META: script=../util/helpers.js
+// META: script=/common/subset-tests.js
+// META: script=successes.js
+run_test(["AES-CTR"]);
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_AES-GCM.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_AES-GCM.https.any.js
new file mode 100644
index 0000000000..f0f947c816
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_AES-GCM.https.any.js
@@ -0,0 +1,6 @@
+// META: title=WebCryptoAPI: generateKey() Successful Calls
+// META: timeout=long
+// META: script=../util/helpers.js
+// META: script=/common/subset-tests.js
+// META: script=successes.js
+run_test(["AES-GCM"]);
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_AES-KW.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_AES-KW.https.any.js
new file mode 100644
index 0000000000..dbc040fdc5
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_AES-KW.https.any.js
@@ -0,0 +1,6 @@
+// META: title=WebCryptoAPI: generateKey() Successful Calls
+// META: timeout=long
+// META: script=../util/helpers.js
+// META: script=/common/subset-tests.js
+// META: script=successes.js
+run_test(["AES-KW"]);
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_ECDH.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_ECDH.https.any.js
new file mode 100644
index 0000000000..e9dee52614
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_ECDH.https.any.js
@@ -0,0 +1,6 @@
+// META: title=WebCryptoAPI: generateKey() Successful Calls
+// META: timeout=long
+// META: script=../util/helpers.js
+// META: script=/common/subset-tests.js
+// META: script=successes.js
+run_test(["ECDH"]);
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_ECDSA.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_ECDSA.https.any.js
new file mode 100644
index 0000000000..a022f31fe9
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_ECDSA.https.any.js
@@ -0,0 +1,6 @@
+// META: title=WebCryptoAPI: generateKey() Successful Calls
+// META: timeout=long
+// META: script=../util/helpers.js
+// META: script=/common/subset-tests.js
+// META: script=successes.js
+run_test(["ECDSA"]);
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_Ed25519.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_Ed25519.https.any.js
new file mode 100644
index 0000000000..6b3bc460f6
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_Ed25519.https.any.js
@@ -0,0 +1,6 @@
+// META: title=WebCryptoAPI: generateKey() Successful Calls
+// META: timeout=long
+// META: script=../util/helpers.js
+// META: script=/common/subset-tests.js
+// META: script=successes.js
+run_test(["Ed25519"]);
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_Ed448.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_Ed448.https.any.js
new file mode 100644
index 0000000000..8e37f57b24
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_Ed448.https.any.js
@@ -0,0 +1,6 @@
+// META: title=WebCryptoAPI: generateKey() Successful Calls
+// META: timeout=long
+// META: script=../util/helpers.js
+// META: script=/common/subset-tests.js
+// META: script=successes.js
+run_test(["Ed448"]);
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_HMAC.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_HMAC.https.any.js
new file mode 100644
index 0000000000..18e0b27122
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_HMAC.https.any.js
@@ -0,0 +1,6 @@
+// META: title=WebCryptoAPI: generateKey() Successful Calls
+// META: timeout=long
+// META: script=../util/helpers.js
+// META: script=/common/subset-tests.js
+// META: script=successes.js
+run_test(["HMAC"]);
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_RSA-OAEP.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_RSA-OAEP.https.any.js
new file mode 100644
index 0000000000..d933fd981d
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_RSA-OAEP.https.any.js
@@ -0,0 +1,22 @@
+// META: title=WebCryptoAPI: generateKey() Successful Calls
+// META: timeout=long
+// META: variant=?1-10
+// META: variant=?11-20
+// META: variant=?21-30
+// META: variant=?31-40
+// META: variant=?41-50
+// META: variant=?51-60
+// META: variant=?61-70
+// META: variant=?71-80
+// META: variant=?81-90
+// META: variant=?91-100
+// META: variant=?101-110
+// META: variant=?111-120
+// META: variant=?121-130
+// META: variant=?131-140
+// META: variant=?141-150
+// META: variant=?151-last
+// META: script=../util/helpers.js
+// META: script=/common/subset-tests.js
+// META: script=successes.js
+run_test(["RSA-OAEP"]);
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_RSA-PSS.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_RSA-PSS.https.any.js
new file mode 100644
index 0000000000..cb43e3de3d
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_RSA-PSS.https.any.js
@@ -0,0 +1,10 @@
+// META: title=WebCryptoAPI: generateKey() Successful Calls
+// META: timeout=long
+// META: variant=?1-10
+// META: variant=?11-20
+// META: variant=?21-30
+// META: variant=?31-last
+// META: script=../util/helpers.js
+// META: script=/common/subset-tests.js
+// META: script=successes.js
+run_test(["RSA-PSS"]);
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_RSASSA-PKCS1-v1_5.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_RSASSA-PKCS1-v1_5.https.any.js
new file mode 100644
index 0000000000..b8db597228
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_RSASSA-PKCS1-v1_5.https.any.js
@@ -0,0 +1,10 @@
+// META: title=WebCryptoAPI: generateKey() Successful Calls
+// META: timeout=long
+// META: variant=?1-10
+// META: variant=?11-20
+// META: variant=?21-30
+// META: variant=?31-last
+// META: script=../util/helpers.js
+// META: script=/common/subset-tests.js
+// META: script=successes.js
+run_test(["RSASSA-PKCS1-v1_5"]);
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_X25519.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_X25519.https.any.js
new file mode 100644
index 0000000000..0e87cf5010
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_X25519.https.any.js
@@ -0,0 +1,6 @@
+// META: title=WebCryptoAPI: generateKey() Successful Calls
+// META: timeout=long
+// META: script=../util/helpers.js
+// META: script=/common/subset-tests.js
+// META: script=successes.js
+run_test(["X25519"]);
diff --git a/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_X448.https.any.js b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_X448.https.any.js
new file mode 100644
index 0000000000..e7dbe32696
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/generateKey/successes_X448.https.any.js
@@ -0,0 +1,6 @@
+// META: title=WebCryptoAPI: generateKey() Successful Calls
+// META: timeout=long
+// META: script=../util/helpers.js
+// META: script=/common/subset-tests.js
+// META: script=successes.js
+run_test(["X448"]);