| 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 EC public keys"); | |
| 13 | |
| 14 jsTestIsAsync = true; | |
| 15 | |
| 16 // Tests the 12 permutations of keys generated by: | |
| 17 // kPossibleAlgorithms x kPossibleExtractable x kPossibleKeyUsages x kPossible
Curves | |
| 18 // | |
| 19 // For practical reasons these tests are not exhaustive. | |
| 20 | |
| 21 var kPossibleAlgorithms = ['ECDSA']; | |
| 22 var kPossibleExtractable = [true, false]; | |
| 23 var kPossibleKeyUsages = [[], ['verify']]; | |
| 24 var kPossibleNamedCurves = ['P-256', 'P-384', 'P-521']; | |
| 25 | |
| 26 // A mapping from curve name, to SPKI data (hex-encoded) for a valid public key. | |
| 27 var kKeyDataForCurve = { | |
| 28 "P-256": "3059301306072A8648CE3D020106082A8648CE3D030107034200049CB0CF69303D
AFC761D4E4687B4ECF039E6D34AB964AF80810D8D558A4A8D6F72D51233A1788920A86EE08A1962C
79EFA317FB7879E297DAD2146DB995FA1C78", | |
| 29 "P-384": "3076301006072A8648CE3D020106052B81040022036200040874A2E0B8FF448F0E
54321E27F4F1E64D064CDEB7D26F458C32E930120F4E57DC85C2693F977EED4A8ECC8DB981B4D91F
69446DF4F4C6F5DE19003F45F891D0EBCD2FFFDB5C81C040E8D6994C43C7FEEDB98A4A31EDFB35E8
9A30013C3B9267", | |
| 30 "P-521": "30819B301006072A8648CE3D020106052B81040023038186000400F50A08703250
C15F043C8C46E99783435245CF98F4F2694B0E2F8D029A514DD6F0B086D4ED892000CD5590107AAE
69C4C0A7A95F7CF74E5770A07D5DB55BCE4AB400F2C770BAB8B9BE4CDB6ECD3DC26C698DA0D2599C
EBF3D904F7F9CA3A55E64731810D73CD317264E50BABA4BC2860857E16D6CBB79501BC9E3A32BD17
2EA8A71DEE" | |
| 31 }; | |
| 32 | |
| 33 function runTest(algorithmName, namedCurve, extractable, keyUsages) | |
| 34 { | |
| 35 var keyDataHex = kKeyDataForCurve[namedCurve]; | |
| 36 var importData = hexStringToUint8Array(keyDataHex); | |
| 37 var importAlgorithm = { name: algorithmName, namedCurve: namedCurve }; | |
| 38 | |
| 39 var results = {}; | |
| 40 | |
| 41 return crypto.subtle.importKey('spki', importData, importAlgorithm, extracta
ble, keyUsages).then(function(importedKey) { | |
| 42 results.importedKey = importedKey; | |
| 43 importedKey.extraProperty = 'hi'; | |
| 44 return cloneKey(importedKey); | |
| 45 }).then(function(clonedKey) { | |
| 46 results.clonedKey = clonedKey; | |
| 47 if (extractable) | |
| 48 return crypto.subtle.exportKey('spki', clonedKey); | |
| 49 return null; | |
| 50 }).then(function(clonedKeyData) { | |
| 51 importedKey = results.importedKey; | |
| 52 clonedKey = results.clonedKey; | |
| 53 | |
| 54 shouldEvaluateAs("importedKey.extraProperty", "hi"); | |
| 55 shouldEvaluateAs("importedKey.type", "public"); | |
| 56 shouldEvaluateAs("importedKey.extractable", extractable); | |
| 57 shouldEvaluateAs("importedKey.algorithm.name", algorithmName); | |
| 58 shouldEvaluateAs("importedKey.algorithm.namedCurve", namedCurve); | |
| 59 shouldEvaluateAs("importedKey.usages.join(',')", keyUsages.join(",")); | |
| 60 | |
| 61 shouldNotBe("importedKey", "clonedKey"); | |
| 62 | |
| 63 shouldBeUndefined("clonedKey.extraProperty"); | |
| 64 shouldEvaluateAs("clonedKey.type", "public"); | |
| 65 shouldEvaluateAs("clonedKey.extractable", extractable); | |
| 66 shouldEvaluateAs("clonedKey.algorithm.name", algorithmName); | |
| 67 shouldEvaluateAs("clonedKey.algorithm.namedCurve", namedCurve); | |
| 68 shouldEvaluateAs("clonedKey.usages.join(',')", keyUsages.join(",")); | |
| 69 | |
| 70 logSerializedKey(importedKey); | |
| 71 | |
| 72 if (extractable) | |
| 73 bytesShouldMatchHexString("Cloned key exported data", keyDataHex, cl
onedKeyData); | |
| 74 | |
| 75 debug(""); | |
| 76 }); | |
| 77 } | |
| 78 | |
| 79 var lastPromise = Promise.resolve(null); | |
| 80 | |
| 81 kPossibleAlgorithms.forEach(function(algorithmName) { | |
| 82 kPossibleExtractable.forEach(function(extractable) { | |
| 83 kPossibleKeyUsages.forEach(function(keyUsages) { | |
| 84 kPossibleNamedCurves.forEach(function(namedCurve) { | |
| 85 lastPromise = lastPromise.then(runTest.bind(null, algorithmNam
e, namedCurve, extractable, keyUsages)); | |
| 86 }); | |
| 87 }); | |
| 88 }); | |
| 89 }); | |
| 90 | |
| 91 lastPromise.then(finishJSTest, failAndFinishJSTest); | |
| 92 | |
| 93 </script> | |
| 94 | |
| 95 </body> | |
| 96 </html> | |
| OLD | NEW |