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 crypto.subtle.importKey() using a BufferSource that is modifi
ed during algorithm normalization"); |
| 13 |
| 14 jsTestIsAsync = true; |
| 15 |
| 16 var kKeyDataHex = "30112233445566778899aabbccddeeff"; |
| 17 |
| 18 keyData = hexStringToUint8Array(kKeyDataHex); |
| 19 |
| 20 function corruptKeyData() |
| 21 { |
| 22 debug("Corrupting keyData..."); |
| 23 keyData[0] = 0; |
| 24 keyData[1] = 0; |
| 25 } |
| 26 |
| 27 // This algorithm has a custom getter that modifies the key data. |
| 28 var importAlgorithm = { |
| 29 get name() { |
| 30 debug("Accessed name property"); |
| 31 corruptKeyData(); |
| 32 return 'aes-cbc'; |
| 33 } |
| 34 }; |
| 35 |
| 36 var extractable = true; |
| 37 var usages = ['encrypt', 'decrypt']; |
| 38 |
| 39 debug("Importing key..."); |
| 40 crypto.subtle.importKey('raw', keyData, importAlgorithm, extractable, usages).th
en(function(result) { |
| 41 debug("Exporting key..."); |
| 42 return crypto.subtle.exportKey('raw', result); |
| 43 }).then(function(result) { |
| 44 bytesShouldMatchHexString("Exported data", kKeyDataHex, result); |
| 45 |
| 46 debug("Importing key (again)..."); |
| 47 return crypto.subtle.importKey('raw', keyData, "AES-CBC", extractable, usage
s); |
| 48 }).then(function(result) { |
| 49 debug("Importing second key..."); |
| 50 return crypto.subtle.exportKey('raw', result); |
| 51 }).then(function(result) { |
| 52 // This time the imported key should reflect the modified version. |
| 53 bytesShouldMatchHexString("Exported data", "00002233445566778899aabbccddeeff
", result); |
| 54 }).then(finishJSTest, failAndFinishJSTest); |
| 55 |
| 56 </script> |
| 57 |
| 58 </body> |
| 59 </html> |
OLD | NEW |