Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 if (self.importScripts) { | |
| 2 importScripts('common.js'); | |
| 3 } | |
| 4 | |
| 5 function runCloneECTests(format, algorithmName, namedCurve, keyType, extractable , keyUsages, keyData) | |
| 6 { | |
| 7 var importData = hexStringToUint8Array(keyData); | |
| 8 var importAlgorithm = { name: algorithmName, namedCurve: namedCurve }; | |
| 9 | |
| 10 var results = {}; | |
| 11 | |
| 12 return crypto.subtle.importKey(format, importData, importAlgorithm, extracta ble, keyUsages).then(function(importedKey) { | |
| 13 results.importedKey = importedKey; | |
| 14 importedKey.extraProperty = 'hi'; | |
| 15 return cloneKey(importedKey); | |
| 16 }).then(function(clonedKey) { | |
| 17 results.clonedKey = clonedKey; | |
| 18 if (extractable) | |
| 19 return crypto.subtle.exportKey(format, clonedKey); | |
| 20 return null; | |
| 21 }).then(function(clonedKeyData) { | |
| 22 importedKey = results.importedKey; | |
| 23 clonedKey = results.clonedKey; | |
| 24 | |
| 25 shouldEvaluateAs("importedKey.extraProperty", "hi"); | |
| 26 shouldEvaluateAs("importedKey.type", keyType); | |
| 27 shouldEvaluateAs("importedKey.extractable", extractable); | |
| 28 shouldEvaluateAs("importedKey.algorithm.name", algorithmName); | |
| 29 shouldEvaluateAs("importedKey.algorithm.namedCurve", namedCurve); | |
| 30 shouldEvaluateAs("importedKey.usages.join(',')", keyUsages.join(",")); | |
| 31 | |
| 32 shouldNotBe("importedKey", "clonedKey"); | |
| 33 | |
| 34 shouldBeUndefined("clonedKey.extraProperty"); | |
| 35 shouldEvaluateAs("clonedKey.type", keyType); | |
| 36 shouldEvaluateAs("clonedKey.extractable", extractable); | |
| 37 shouldEvaluateAs("clonedKey.algorithm.name", algorithmName); | |
| 38 shouldEvaluateAs("clonedKey.algorithm.namedCurve", namedCurve); | |
| 39 shouldEvaluateAs("clonedKey.usages.join(',')", keyUsages.join(",")); | |
| 40 | |
| 41 logSerializedKey(importedKey); | |
| 42 | |
| 43 if (extractable) | |
| 44 bytesShouldMatchHexString("Cloned key exported data", keyData, clone dKeyData); | |
| 45 | |
| 46 debug(""); | |
| 47 }); | |
| 48 } | |
| 49 | |
| 50 function testCloneEcKeys(format, algorithmName, possibleKeyUsages, keyType, keyD ataForCurve) | |
| 51 { | |
| 52 var lastPromise = Promise.resolve(null); | |
| 53 var kPossibleExtractable = [true, false]; | |
| 54 var kPossibleNamedCurves = ['P-256', 'P-384', 'P-521']; | |
| 55 | |
| 56 kPossibleNamedCurves.forEach(function(namedCurve) { | |
| 57 kPossibleExtractable.forEach(function(extractable) { | |
| 58 possibleKeyUsages.forEach(function(keyUsages) { | |
| 59 lastPromise = lastPromise.then(runCloneECTests.bind(null, format , algorithmName, namedCurve, keyType, extractable, keyUsages, keyDataForCurve[na medCurve])); | |
| 60 }); | |
| 61 }); | |
| 62 }); | |
| 63 | |
| 64 return lastPromise; | |
| 65 } | |
| 66 | |
| 67 function testCloneEcPublicKeys(algorithmName, possibleKeyUsages) | |
| 68 { | |
| 69 var kKeyDataForCurve = { | |
| 70 "P-256": "3059301306072A8648CE3D020106082A8648CE3D030107034200049CB0CF69303D AFC761D4E4687B4ECF039E6D34AB964AF80810D8D558A4A8D6F72D51233A1788920A86EE08A1962C 79EFA317FB7879E297DAD2146DB995FA1C78", | |
|
eroman
2015/03/05 19:58:50
nit: indent these a bit.
| |
| 71 "P-384": "3076301006072A8648CE3D020106052B81040022036200040874A2E0B8FF448F0E 54321E27F4F1E64D064CDEB7D26F458C32E930120F4E57DC85C2693F977EED4A8ECC8DB981B4D91F 69446DF4F4C6F5DE19003F45F891D0EBCD2FFFDB5C81C040E8D6994C43C7FEEDB98A4A31EDFB35E8 9A30013C3B9267", | |
| 72 "P-521": "30819B301006072A8648CE3D020106052B81040023038186000400F50A0870325 0C15F043C8C46E99783435245CF98F4F2694B0E2F8D029A514DD6F0B086D4ED892000CD5590107AA E69C4C0A7A95F7CF74E5770A07D5DB55BCE4AB400F2C770BAB8B9BE4CDB6ECD3DC26C698DA0D2599 CEBF3D904F7F9CA3A55E64731810D73CD317264E50BABA4BC2860857E16D6CBB79501BC9E3A32BD1 72EA8A71DEE" | |
| 73 }; | |
| 74 return testCloneEcKeys("spki", algorithmName, possibleKeyUsages, "public", k KeyDataForCurve); | |
| 75 } | |
| 76 | |
| 77 function testCloneEcPrivateKeys(algorithmName, possibleKeyUsages) | |
| 78 { | |
| 79 var kKeyDataForCurve = { | |
| 80 "P-256": "308187020100301306072A8648CE3D020106082A8648CE3D030107046D306B020 10104201FE33950C5F461124AE992C2BDFDF1C73B1615F571BD567E60D19AA1F48CDF42A14403420 0047C110C66DCFDA807F6E69E45DDB3C74F69A1484D203E8DC5ADA8E9A9DD7CB3C70DF448986E51B DE5D1576F99901F9C2C6A806A47FD907643A72B835597EFC8C6", | |
|
eroman
2015/03/05 19:58:50
indent
| |
| 81 "P-384": | |
| 82 "3081B6020100301006072A8648CE3D020106052B8104002204819E30819B0201010430A492CE8FA 90084C227E1A32F7974D39E9FF67A7E8705EC3419B35FB607582BEBD461E0B1520AC76EC2DD4E9B6 3EBAE71A16403620004E55FEE6C49D8D523F5CE7BF9C0425CE4FF650708B7DE5CFB095901523979A 7F042602DB30854735369813B5C3F5EF86828F59CC5DC509892A988D38A8E2519DE3D0C4FD0FBDB0 993E38F18506C17606C5E24249246F1CE94983A5361C5BE983E", | |
| 83 "P-521": | |
| 84 "3081EE020100301006072A8648CE3D020106052B810400230481D63081D3020101044201BD56BD1 06118EDA246155BD43B42B8E13F0A6E25DD3BB376026FAB4DC92B6157BC6DFEC2D15DD3D0CF2A39A A68494042AF48BA9601118DA82C6F2108A3A203AD74A181890381860004012FBCAEFFA6A51F3EE4D 3D2B51C5DEC6D7C726CA353FC014EA2BF7CFBB9B910D32CBFA6A00FE39B6CDB8946F22775398B2E2 33C0CF144D78C8A7742B5C7A3BB5D23009CDEF823DD7BF9A79E8CCEACD2E4527C231D0AE5967AF09 58E931D7DDCCF2805A3E618DC3039FEC9FEBBD33052FE4C0FEE98F033106064982D88F4E03549D4A 64D" // P-521 | |
|
eroman
2015/03/05 19:58:50
nit: This comment isn't needed :)
| |
| 85 }; | |
| 86 return testCloneEcKeys("pkcs8", algorithmName, possibleKeyUsages, "private", kKeyDataForCurve); | |
| 87 } | |
| OLD | NEW |