OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <script src="../resources/js-test.js"></script> |
| 5 <script src="resources/common.js"></script> |
| 6 </head> |
| 7 <body> |
| 8 <p id="description"></p> |
| 9 <div id="console"></div> |
| 10 |
| 11 <script> |
| 12 description("Tests structured cloning of RSA keys (with a hash)"); |
| 13 |
| 14 jsTestIsAsync = true; |
| 15 |
| 16 // Tests the 48 permutations of keys generated by: |
| 17 // kPossibleAlgorithms x kPossibleExtractable x kPossibleKeyUsages x kPossible
KeyData x kPossibleHashAlgorithms |
| 18 // |
| 19 // For practical reasons these tests are not exhaustive. |
| 20 |
| 21 var kPossibleAlgorithms = ['RSASSA-PKCS1-v1_5']; |
| 22 var kPossibleExtractable = [true, false]; |
| 23 var kPossibleKeyUsages = [[], ['sign'], ['verify'], ['sign', 'verify']]; |
| 24 var kPossibleHashAlgorithms = ['SHA-1', 'SHA-256', 'SHA-512']; |
| 25 |
| 26 var kPossibleKeyData = [ |
| 27 { |
| 28 modululusLengthBits: 1024, |
| 29 publicExponent: "010001", |
| 30 |
| 31 spkiData: "30819f300d06092a864886f70d010101050003818d0030818902818100b2"
+ |
| 32 "89c62ecc3ddf64154817203439eaa0dc07a65954429a7b6098a77235673d" + |
| 33 "96df1f06bd3c1ae73990867199e678bf95b3728fcd4686136e6ee9dd4c09" + |
| 34 "eb490eb7cb953c388668b759263f61d6a7dfcabf27b5c9d6972455b12b66" + |
| 35 "d483843286d6b871f35f912a773c97c1932255fcee05ce7b8af213879f01" + |
| 36 "7de4232a306a410203010001" |
| 37 }, |
| 38 { |
| 39 modululusLengthBits: 2048, |
| 40 publicExponent: "010001", |
| 41 |
| 42 spkiData: "30820122300d06092a864886f70d01010105000382010f003082010a0282"
+ |
| 43 "010100b4c8b631194aef0154b1479ab7a534b60ca878981108680f0ae6b7" + |
| 44 "c88cb6010f6dbf9f665646208410575cb923b26bf874a24b4cd801c9bba9" + |
| 45 "67062ae506cdcf307add4380d0d93077a4c1f0fc06d498dc729f811335c5" + |
| 46 "30b90fe9bf9f3979ccec050a48e8923045b19368e1e89ea4157538e8059e" + |
| 47 "53320f47c155f1741310a93ed153a7f3af2d46c388b95d82518527a02b7b" + |
| 48 "d9ab7edc4bcb737677f679c5c6de5e1ebed3a29d6b99b8eace2d59ceb533" + |
| 49 "e001cf39c5671495d51d3ee34406ea4fdb0c626dee68da256b8a12f9f650" + |
| 50 "59ccc85a2190ce1385152d62785e00cae702e77c4c597b86a6268adbf043" + |
| 51 "dda68881c790f1517671fb7d198fca5ba97bef0203010001" |
| 52 } |
| 53 ]; |
| 54 |
| 55 function runTest(algorithmName, hashName, extractable, keyUsages, keyData) |
| 56 { |
| 57 return crypto.subtle.importKey('spki', hexStringToUint8Array(keyData.spkiDat
a), { name: algorithmName, hash: {name: hashName} }, |
| 58 extractable, keyUsages).then(function(result)
{ |
| 59 importedKey = result; |
| 60 |
| 61 shouldBe("importedKey.type", evalWrap("public")); |
| 62 shouldBe("importedKey.extractable", evalWrap(extractable)); |
| 63 shouldBe("importedKey.algorithm.name", evalWrap(algorithmName)); |
| 64 shouldBe("importedKey.algorithm.modulusLength", evalWrap(keyData.modulul
usLengthBits)); |
| 65 bytesShouldMatchHexString("importedKey.algorithm.publicExponent", keyDat
a.publicExponent, importedKey.algorithm.publicExponent); |
| 66 shouldBe("importedKey.algorithm.hash.name", evalWrap(hashName)); |
| 67 shouldBe("importedKey.usages.join(',')", evalWrap(keyUsages.join(","))); |
| 68 |
| 69 clonedKey = cloneKeyAndLog(importedKey); |
| 70 |
| 71 shouldBe("clonedKey.type", evalWrap("public")); |
| 72 shouldBe("clonedKey.extractable", evalWrap(extractable)); |
| 73 shouldBe("clonedKey.algorithm.name", evalWrap(algorithmName)); |
| 74 shouldBe("clonedKey.algorithm.modulusLength", evalWrap(keyData.modululus
LengthBits)); |
| 75 shouldBe("clonedKey.algorithm.modulusLength", evalWrap(keyData.modululus
LengthBits)); |
| 76 bytesShouldMatchHexString("clonedKey.algorithm.publicExponent", keyData.
publicExponent, clonedKey.algorithm.publicExponent); |
| 77 shouldBe("clonedKey.algorithm.hash.name", evalWrap(hashName)); |
| 78 shouldBe("clonedKey.usages.join(',')", evalWrap(keyUsages.join(","))); |
| 79 |
| 80 // Check the key bytes. |
| 81 if (extractable) { |
| 82 return crypto.subtle.exportKey('spki', clonedKey).then(function(resu
lt) { |
| 83 bytesShouldMatchHexString("cloned key data", keyData.spkiData, r
esult); |
| 84 }); |
| 85 } |
| 86 }); |
| 87 } |
| 88 |
| 89 for (var algorithmIndex = 0; algorithmIndex < kPossibleAlgorithms.length; ++algo
rithmIndex) { |
| 90 for (var extractableIndex = 0; extractableIndex < kPossibleExtractable.lengt
h; ++extractableIndex) { |
| 91 for (var usagesIndex = 0; usagesIndex < kPossibleKeyUsages.length; ++usa
gesIndex) { |
| 92 for (var dataIndex = 0; dataIndex < kPossibleKeyData.length; ++dataI
ndex) { |
| 93 for (var hashIndex = 0; hashIndex < kPossibleHashAlgorithms.leng
th; ++hashIndex) { |
| 94 var algorithmName = kPossibleAlgorithms[algorithmIndex]; |
| 95 var extractable = kPossibleExtractable[extractableIndex]; |
| 96 var keyUsages = kPossibleKeyUsages[usagesIndex]; |
| 97 var keyData = kPossibleKeyData[dataIndex]; |
| 98 var hashName = kPossibleHashAlgorithms[hashIndex]; |
| 99 |
| 100 addTask(runTest(algorithmName, hashName, extractable, keyUsa
ges, keyData)); |
| 101 } |
| 102 } |
| 103 } |
| 104 } |
| 105 } |
| 106 |
| 107 completeTestWhenAllTasksDone(); |
| 108 |
| 109 </script> |
| 110 |
| 111 </body> |
| 112 </html> |
OLD | NEW |