| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <script src="../fast/js/resources/js-test-pre.js"></script> | 4 <script src="../fast/js/resources/js-test-pre.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 cypto.subtle.importKey."); | 12 description("Tests cypto.subtle.importKey."); |
| 13 | 13 |
| 14 jsTestIsAsync = true; | 14 jsTestIsAsync = true; |
| 15 | 15 |
| 16 aesCbc = {name: 'aes-cbc'}; | 16 aesCbc = {name: 'aes-cbc'}; |
| 17 | 17 |
| 18 Promise.resolve(null).then(function() { | 18 Promise.resolve(null).then(function() { |
| 19 keyFormat = "raw"; | 19 keyFormat = "raw"; |
| 20 data = asciiToArrayBuffer("private"); | 20 data = asciiToArrayBuffer("raw bytes for key"); |
| 21 algorithm = { name: 'hmac', hash: { name: 'sha-256' } }; | 21 algorithm = { name: 'hmac', hash: { name: 'sha-256' } }; |
| 22 extractable = true; | 22 extractable = true; |
| 23 // Note there are duplicates | 23 // Note there are duplicates |
| 24 keyUsages = ['encrypt', 'encrypt', 'encrypt', 'sign']; | 24 keyUsages = ['encrypt', 'encrypt', 'encrypt', 'sign']; |
| 25 | 25 |
| 26 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU
sages); | 26 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU
sages); |
| 27 }).then(function(result) { | 27 }).then(function(result) { |
| 28 key = result; | 28 key = result; |
| 29 shouldBe("key.type", "'private'") | 29 shouldBe("key.type", "'secret'") |
| 30 shouldBe("key.extractable", "true") | 30 shouldBe("key.extractable", "true") |
| 31 shouldBe("key.algorithm.name", "'HMAC'") | 31 shouldBe("key.algorithm.name", "'HMAC'") |
| 32 shouldBe("key.algorithm.hash.name", "'SHA-256'") | 32 shouldBe("key.algorithm.hash.name", "'SHA-256'") |
| 33 shouldBe("key.usages.join(',')", "'encrypt,sign'") | 33 shouldBe("key.usages.join(',')", "'encrypt,sign'") |
| 34 | 34 |
| 35 // Same test as above, but with an keyUsages, and AES-CBC. | 35 // Same test as above, but with an keyUsages, and AES-CBC. |
| 36 keyFormat = "raw"; | 36 keyFormat = "raw"; |
| 37 data = asciiToArrayBuffer("private"); | 37 data = asciiToArrayBuffer("16 bytes of key!"); |
| 38 algorithm = aesCbc; | 38 algorithm = aesCbc; |
| 39 extractable = true; | 39 extractable = true; |
| 40 keyUsages = []; | 40 keyUsages = []; |
| 41 | 41 |
| 42 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU
sages); | 42 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU
sages); |
| 43 }).then(function(result) { | 43 }).then(function(result) { |
| 44 key = result; | 44 key = result; |
| 45 shouldBe("key.type", "'private'") | 45 shouldBe("key.type", "'secret'") |
| 46 shouldBe("key.extractable", "true") | 46 shouldBe("key.extractable", "true") |
| 47 shouldBe("key.algorithm.name", "'AES-CBC'") | 47 shouldBe("key.algorithm.name", "'AES-CBC'") |
| 48 shouldBe("key.usages.join(',')", "''") | 48 shouldBe("key.usages.join(',')", "''") |
| 49 | 49 |
| 50 // Same test as above, but with extractable = false. | 50 // Same test as above, but with extractable = false. |
| 51 keyFormat = "raw"; | 51 keyFormat = "raw"; |
| 52 data = asciiToArrayBuffer("private"); | 52 data = asciiToArrayBuffer("16 bytes of key!"); |
| 53 algorithm = aesCbc; | 53 algorithm = aesCbc; |
| 54 extractable = false; | 54 extractable = false; |
| 55 keyUsages = []; | 55 keyUsages = []; |
| 56 | 56 |
| 57 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU
sages); | 57 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU
sages); |
| 58 }).then(function(result) { | 58 }).then(function(result) { |
| 59 key = result; | 59 key = result; |
| 60 shouldBe("key.type", "'private'") | 60 shouldBe("key.type", "'secret'") |
| 61 shouldBe("key.extractable", "false") | 61 shouldBe("key.extractable", "false") |
| 62 shouldBe("key.algorithm.name", "'AES-CBC'") | 62 shouldBe("key.algorithm.name", "'AES-CBC'") |
| 63 shouldBe("key.usages.join(',')", "''") | 63 shouldBe("key.usages.join(',')", "''") |
| 64 | 64 |
| 65 // Same test as above, but with key.type of public. | 65 // Same test as above, but with key.type of public. |
| 66 keyFormat = "raw"; | 66 keyFormat = "raw"; |
| 67 data = asciiToArrayBuffer("public"); | 67 data = asciiToArrayBuffer("16 bytes of key!"); |
| 68 algorithm = aesCbc; | 68 algorithm = aesCbc; |
| 69 extractable = false; | 69 extractable = false; |
| 70 keyUsages = []; | 70 keyUsages = []; |
| 71 | 71 |
| 72 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU
sages); | 72 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU
sages); |
| 73 }).then(function(result) { | 73 }).then(function(result) { |
| 74 key = result; | 74 key = result; |
| 75 shouldBe("key.type", "'public'") | 75 shouldBe("key.type", "'secret'") |
| 76 shouldBe("key.extractable", "false") | 76 shouldBe("key.extractable", "false") |
| 77 shouldBe("key.algorithm.name", "'AES-CBC'") | 77 shouldBe("key.algorithm.name", "'AES-CBC'") |
| 78 shouldBe("key.usages.join(',')", "''") | 78 shouldBe("key.usages.join(',')", "''") |
| 79 | 79 |
| 80 // Same test as above, but with keyFormat = spki | 80 // Same test as above, but with keyFormat = spki |
| 81 keyFormat = "spki"; | 81 keyFormat = "spki"; |
| 82 data = asciiToArrayBuffer("public"); | 82 data = asciiToArrayBuffer("16 bytes of key!"); |
| 83 algorithm = aesCbc; | |
| 84 extractable = false; | |
| 85 keyUsages = []; | |
| 86 | |
| 87 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU
sages); | |
| 88 }).then(function(result) { | |
| 89 key = result; | |
| 90 shouldBe("key.type", "'public'") | |
| 91 shouldBe("key.extractable", "false") | |
| 92 shouldBe("key.algorithm.name", "'AES-CBC'") | |
| 93 shouldBe("key.usages.join(',')", "''") | |
| 94 | |
| 95 keyFormat = "spki"; | |
| 96 data = asciiToArrayBuffer("error"); | |
| 97 algorithm = aesCbc; | 83 algorithm = aesCbc; |
| 98 extractable = false; | 84 extractable = false; |
| 99 keyUsages = []; | 85 keyUsages = []; |
| 100 | 86 |
| 101 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU
sages); | 87 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU
sages); |
| 102 }).then(undefined, function(result) { | 88 }).then(undefined, function(result) { |
| 89 // TODO(eroman): Only "raw" key format is supported at the moment. |
| 103 debug("rejected with " + result); | 90 debug("rejected with " + result); |
| 104 | 91 |
| 105 keyFormat = "raw"; | 92 keyFormat = "raw"; |
| 106 data = asciiToArrayBuffer(""); | 93 data = asciiToArrayBuffer(""); |
| 107 algorithm = aesCbc; | 94 algorithm = aesCbc; |
| 108 extractable = true; | 95 extractable = true; |
| 109 keyUsages = []; | 96 keyUsages = []; |
| 110 | 97 |
| 111 // Invalid format. | 98 // Invalid format. |
| 112 shouldThrow("crypto.subtle.importKey('invalid format', data, algorithm, extr
actable, keyUsages)"); | 99 shouldThrow("crypto.subtle.importKey('invalid format', data, algorithm, extr
actable, keyUsages)"); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 131 | 118 |
| 132 // SHA-1 doesn't support the importKey operation. | 119 // SHA-1 doesn't support the importKey operation. |
| 133 shouldThrow("crypto.subtle.importKey(keyFormat, data, {name: 'sha-1'}, extra
ctable, keyUsages)"); | 120 shouldThrow("crypto.subtle.importKey(keyFormat, data, {name: 'sha-1'}, extra
ctable, keyUsages)"); |
| 134 }).then(finishJSTest, failAndFinishJSTest); | 121 }).then(finishJSTest, failAndFinishJSTest); |
| 135 | 122 |
| 136 </script> | 123 </script> |
| 137 | 124 |
| 138 <script src="../fast/js/resources/js-test-post.js"></script> | 125 <script src="../fast/js/resources/js-test-post.js"></script> |
| 139 </body> | 126 </body> |
| 140 </html> | 127 </html> |
| OLD | NEW |