Index: LayoutTests/crypto/clone-rsaHashedKey-public.html |
diff --git a/LayoutTests/crypto/clone-rsaHashedKey-public.html b/LayoutTests/crypto/clone-rsaHashedKey-public.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6662aa1a305eca7605865da8503aca937f5451d9 |
--- /dev/null |
+++ b/LayoutTests/crypto/clone-rsaHashedKey-public.html |
@@ -0,0 +1,112 @@ |
+<!DOCTYPE html> |
+<html> |
+<head> |
+<script src="../resources/js-test.js"></script> |
+<script src="resources/common.js"></script> |
+</head> |
+<body> |
+<p id="description"></p> |
+<div id="console"></div> |
+ |
+<script> |
+description("Tests structured cloning of RSA keys (with a hash)"); |
+ |
+jsTestIsAsync = true; |
+ |
+// Tests the 48 permutations of keys generated by: |
+// kPossibleAlgorithms x kPossibleExtractable x kPossibleKeyUsages x kPossibleKeyData x kPossibleHashAlgorithms |
+// |
+// For practical reasons these tests are not exhaustive. |
+ |
+var kPossibleAlgorithms = ['RSASSA-PKCS1-v1_5']; |
+var kPossibleExtractable = [true, false]; |
+var kPossibleKeyUsages = [[], ['sign'], ['verify'], ['sign', 'verify']]; |
+var kPossibleHashAlgorithms = ['SHA-1', 'SHA-256', 'SHA-512']; |
+ |
+var kPossibleKeyData = [ |
+ { |
+ modululusLengthBits: 1024, |
+ publicExponent: "010001", |
+ |
+ spkiData: "30819f300d06092a864886f70d010101050003818d0030818902818100b2" + |
+ "89c62ecc3ddf64154817203439eaa0dc07a65954429a7b6098a77235673d" + |
+ "96df1f06bd3c1ae73990867199e678bf95b3728fcd4686136e6ee9dd4c09" + |
+ "eb490eb7cb953c388668b759263f61d6a7dfcabf27b5c9d6972455b12b66" + |
+ "d483843286d6b871f35f912a773c97c1932255fcee05ce7b8af213879f01" + |
+ "7de4232a306a410203010001" |
+ }, |
+ { |
+ modululusLengthBits: 2048, |
+ publicExponent: "010001", |
+ |
+ spkiData: "30820122300d06092a864886f70d01010105000382010f003082010a0282" + |
+ "010100b4c8b631194aef0154b1479ab7a534b60ca878981108680f0ae6b7" + |
+ "c88cb6010f6dbf9f665646208410575cb923b26bf874a24b4cd801c9bba9" + |
+ "67062ae506cdcf307add4380d0d93077a4c1f0fc06d498dc729f811335c5" + |
+ "30b90fe9bf9f3979ccec050a48e8923045b19368e1e89ea4157538e8059e" + |
+ "53320f47c155f1741310a93ed153a7f3af2d46c388b95d82518527a02b7b" + |
+ "d9ab7edc4bcb737677f679c5c6de5e1ebed3a29d6b99b8eace2d59ceb533" + |
+ "e001cf39c5671495d51d3ee34406ea4fdb0c626dee68da256b8a12f9f650" + |
+ "59ccc85a2190ce1385152d62785e00cae702e77c4c597b86a6268adbf043" + |
+ "dda68881c790f1517671fb7d198fca5ba97bef0203010001" |
+ } |
+]; |
+ |
+function runTest(algorithmName, hashName, extractable, keyUsages, keyData) |
+{ |
+ return crypto.subtle.importKey('spki', hexStringToUint8Array(keyData.spkiData), { name: algorithmName, hash: {name: hashName} }, |
+ extractable, keyUsages).then(function(result) { |
+ importedKey = result; |
+ |
+ shouldBe("importedKey.type", evalWrap("public")); |
+ shouldBe("importedKey.extractable", evalWrap(extractable)); |
+ shouldBe("importedKey.algorithm.name", evalWrap(algorithmName)); |
+ shouldBe("importedKey.algorithm.modulusLength", evalWrap(keyData.modululusLengthBits)); |
+ bytesShouldMatchHexString("importedKey.algorithm.publicExponent", keyData.publicExponent, importedKey.algorithm.publicExponent); |
+ shouldBe("importedKey.algorithm.hash.name", evalWrap(hashName)); |
+ shouldBe("importedKey.usages.join(',')", evalWrap(keyUsages.join(","))); |
+ |
+ clonedKey = cloneKeyAndLog(importedKey); |
+ |
+ shouldBe("clonedKey.type", evalWrap("public")); |
+ shouldBe("clonedKey.extractable", evalWrap(extractable)); |
+ shouldBe("clonedKey.algorithm.name", evalWrap(algorithmName)); |
+ shouldBe("clonedKey.algorithm.modulusLength", evalWrap(keyData.modululusLengthBits)); |
+ shouldBe("clonedKey.algorithm.modulusLength", evalWrap(keyData.modululusLengthBits)); |
+ bytesShouldMatchHexString("clonedKey.algorithm.publicExponent", keyData.publicExponent, clonedKey.algorithm.publicExponent); |
+ shouldBe("clonedKey.algorithm.hash.name", evalWrap(hashName)); |
+ shouldBe("clonedKey.usages.join(',')", evalWrap(keyUsages.join(","))); |
+ |
+ // Check the key bytes. |
+ if (extractable) { |
+ return crypto.subtle.exportKey('spki', clonedKey).then(function(result) { |
+ bytesShouldMatchHexString("cloned key data", keyData.spkiData, result); |
+ }); |
+ } |
+ }); |
+} |
+ |
+for (var algorithmIndex = 0; algorithmIndex < kPossibleAlgorithms.length; ++algorithmIndex) { |
+ for (var extractableIndex = 0; extractableIndex < kPossibleExtractable.length; ++extractableIndex) { |
+ for (var usagesIndex = 0; usagesIndex < kPossibleKeyUsages.length; ++usagesIndex) { |
+ for (var dataIndex = 0; dataIndex < kPossibleKeyData.length; ++dataIndex) { |
+ for (var hashIndex = 0; hashIndex < kPossibleHashAlgorithms.length; ++hashIndex) { |
+ var algorithmName = kPossibleAlgorithms[algorithmIndex]; |
+ var extractable = kPossibleExtractable[extractableIndex]; |
+ var keyUsages = kPossibleKeyUsages[usagesIndex]; |
+ var keyData = kPossibleKeyData[dataIndex]; |
+ var hashName = kPossibleHashAlgorithms[hashIndex]; |
+ |
+ addTask(runTest(algorithmName, hashName, extractable, keyUsages, keyData)); |
+ } |
+ } |
+ } |
+ } |
+} |
+ |
+completeTestWhenAllTasksDone(); |
+ |
+</script> |
+ |
+</body> |
+</html> |