Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <script src="../../resources/js-test.js"></script> | 4 <script src="../../resources/js-test.js"></script> |
| 5 <script src="resources/common.js"></script> | 5 <script src="resources/common.js"></script> |
| 6 </head> | 6 </head> |
| 7 <body> | 7 <body> |
| 8 <p id="description"></p> | 8 <p id="description"></p> |
| 9 <div id="console"></div> | 9 <div id="console"></div> |
| 10 | 10 |
| 11 <script> | 11 <script> |
| 12 description("Tests structured cloning of HMAC keys"); | 12 description("Tests structured cloning of HKDF keys"); |
| 13 | 13 |
| 14 jsTestIsAsync = true; | 14 jsTestIsAsync = true; |
| 15 | 15 |
| 16 // Tests the 48 permutations of keys generated by: | 16 // Tests the 48 permutations of keys generated by: |
|
eroman
2015/01/07 01:18:42
This comment needs to be updated. (in fact the ori
nharper
2015/01/09 22:41:46
Done. (The original comment being wrong is possibl
| |
| 17 // kPossibleHashAlgorithms x kPossibleExtractable x kPossibleKeyUsages x kPoss ibleKeyData | 17 // kPossibleHashAlgorithms x kPossibleExtractable x kPossibleKeyUsages x kPoss ibleKeyData |
| 18 // | 18 // |
| 19 // For practical reasons these tests are not exhaustive. | 19 // For practical reasons these tests are not exhaustive. |
| 20 | 20 |
| 21 var k128BitData = "30112233445566778899aabbccddeeff" | 21 var k128BitData = "30112233445566778899aabbccddeeff" |
| 22 var k256BitData = "00112233445546778899aabbccddeeff000102030405060708090a0b0c0d0 e0f"; | 22 var k256BitData = "00112233445546778899aabbccddeeff000102030405060708090a0b0c0d0 e0f"; |
| 23 | 23 |
| 24 var kPossibleHashAlgorithms = ['SHA-1', 'SHA-256', 'SHA-512']; | 24 var kPossibleHashAlgorithms = ['SHA-1', 'SHA-256', 'SHA-512']; |
| 25 var kPossibleExtractable = [true, false]; | 25 var kPossibleKeyUsages = [['deriveBits'], ['deriveKey'], ['deriveKey', 'deriveBi ts']]; |
| 26 var kPossibleKeyUsages = [['sign'], ['verify'], ['sign', 'verify']]; | |
| 27 var kPossibleKeyData = [ | 26 var kPossibleKeyData = [ |
| 28 k128BitData, | 27 k128BitData, |
| 29 k256BitData | 28 k256BitData |
| 30 ]; | 29 ]; |
| 31 | 30 |
| 32 function runTest(hashName, extractable, keyUsages, keyData) | 31 function runTest(hashName, keyUsages, keyData) |
| 33 { | 32 { |
| 34 var importData = hexStringToUint8Array(keyData); | 33 var importData = hexStringToUint8Array(keyData); |
| 35 var importAlgorithm = { name: 'HMAC', hash: {name: hashName } }; | 34 var importAlgorithm = { name: 'HKDF', hash: {name: hashName } }; |
| 36 | 35 |
| 37 var results = {}; | 36 var extractable = false; |
| 38 | |
| 39 return crypto.subtle.importKey('raw', importData, importAlgorithm, extractab le, keyUsages).then(function(importedKey) { | 37 return crypto.subtle.importKey('raw', importData, importAlgorithm, extractab le, keyUsages).then(function(importedKey) { |
| 40 results.importedKey = importedKey; | 38 window.importedKey = importedKey; |
|
eroman
2015/01/07 01:18:43
why change the code pattern from the original? Usi
nharper
2015/01/09 22:41:46
The reason for the change was because the local va
| |
| 41 importedKey.extraProperty = 'hi'; | 39 importedKey.extraProperty = 'hi'; |
| 42 return cloneKey(importedKey); | 40 return cloneKey(importedKey); |
| 43 }).then(function(clonedKey) { | 41 }).then(function(clonedKey) { |
| 44 results.clonedKey = clonedKey; | 42 window.clonedKey = clonedKey; |
| 45 if (extractable) | |
| 46 return crypto.subtle.exportKey('raw', clonedKey); | |
| 47 return null; | |
| 48 }).then(function(clonedKeyData) { | |
| 49 importedKey = results.importedKey; | |
| 50 clonedKey = results.clonedKey; | |
| 51 | 43 |
| 52 shouldEvaluateAs("importedKey.extraProperty", "hi"); | 44 shouldEvaluateAs("importedKey.extraProperty", "hi"); |
| 53 shouldEvaluateAs("importedKey.type", "secret"); | 45 shouldEvaluateAs("importedKey.type", "secret"); |
| 54 shouldEvaluateAs("importedKey.extractable", extractable); | 46 shouldEvaluateAs("importedKey.extractable", extractable); |
| 55 shouldEvaluateAs("importedKey.algorithm.name", "HMAC"); | 47 shouldEvaluateAs("importedKey.algorithm.name", "HKDF"); |
| 56 shouldEvaluateAs("importedKey.algorithm.length", importData.length * 8); | |
| 57 shouldEvaluateAs("importedKey.algorithm.hash.name", hashName); | |
| 58 shouldEvaluateAs("importedKey.usages.join(',')", keyUsages.join(",")); | 48 shouldEvaluateAs("importedKey.usages.join(',')", keyUsages.join(",")); |
| 59 | 49 |
| 60 shouldNotBe("importedKey", "clonedKey"); | 50 shouldNotBe("importedKey", "clonedKey"); |
| 61 | 51 |
| 62 shouldBeUndefined("clonedKey.extraProperty"); | 52 shouldBeUndefined("clonedKey.extraProperty"); |
| 63 shouldEvaluateAs("clonedKey.type", "secret"); | 53 shouldEvaluateAs("clonedKey.type", "secret"); |
| 64 shouldEvaluateAs("clonedKey.extractable", extractable); | 54 shouldEvaluateAs("clonedKey.extractable", extractable); |
| 65 shouldEvaluateAs("clonedKey.algorithm.name", "HMAC"); | 55 shouldEvaluateAs("clonedKey.algorithm.name", "HKDF"); |
| 66 shouldEvaluateAs("clonedKey.algorithm.length", importData.length * 8); | |
| 67 shouldEvaluateAs("clonedKey.algorithm.hash.name", hashName); | |
| 68 shouldEvaluateAs("clonedKey.usages.join(',')", keyUsages.join(",")); | 56 shouldEvaluateAs("clonedKey.usages.join(',')", keyUsages.join(",")); |
| 69 | 57 |
| 70 logSerializedKey(importedKey); | 58 logSerializedKey(importedKey); |
| 71 | 59 |
| 72 if (extractable) | |
| 73 bytesShouldMatchHexString("Cloned key exported data", keyData, clone dKeyData); | |
| 74 | |
| 75 debug(""); | 60 debug(""); |
| 76 }); | 61 }); |
| 77 } | 62 } |
| 78 | 63 |
| 79 var lastPromise = Promise.resolve(null); | 64 var lastPromise = Promise.resolve(null); |
| 80 | 65 |
| 81 kPossibleHashAlgorithms.forEach(function(hashName) { | 66 kPossibleHashAlgorithms.forEach(function(hashName) { |
| 82 kPossibleExtractable.forEach(function(extractable) { | 67 kPossibleKeyUsages.forEach(function(keyUsages) { |
| 83 kPossibleKeyUsages.forEach(function(keyUsages) { | 68 kPossibleKeyData.forEach(function(keyData) { |
| 84 kPossibleKeyData.forEach(function(keyData) { | 69 lastPromise = lastPromise.then(runTest.bind(null, hashName, keyUsage s, keyData)); |
| 85 lastPromise = lastPromise.then(runTest.bind(null, hashName, extr actable, keyUsages, keyData)); | |
| 86 }); | |
| 87 }); | 70 }); |
| 88 }); | 71 }); |
| 89 }); | 72 }); |
| 90 | 73 |
| 91 lastPromise.then(finishJSTest, failAndFinishJSTest); | 74 lastPromise.then(finishJSTest, failAndFinishJSTest); |
| 92 | 75 |
| 93 </script> | 76 </script> |
| 94 | 77 |
| 95 </body> | 78 </body> |
| 96 </html> | 79 </html> |
| OLD | NEW |