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("Test exporting an AES key."); |
| 13 |
| 14 jsTestIsAsync = true; |
| 15 |
| 16 var extractable = true; |
| 17 var nonExtractable = false; |
| 18 |
| 19 var jwkKey = { |
| 20 kty: "oct", |
| 21 k: "jnOw99oOZFLIEPMrgJB55WL46tJSLGt7" |
| 22 }; |
| 23 |
| 24 var jwkKeyAsArrayBuffer = asciiToUint8Array(JSON.stringify(jwkKey)); |
| 25 |
| 26 Promise.resolve(null).then(function(result) { |
| 27 return crypto.subtle.exportKey("raw"); |
| 28 }).then(failAndFinishJSTest, function(result) { |
| 29 logError(result); |
| 30 return crypto.subtle.exportKey("raw", null) |
| 31 }).then(failAndFinishJSTest, function(result) { |
| 32 logError(result); |
| 33 return crypto.subtle.exportKey("raw", undefined); |
| 34 }).then(failAndFinishJSTest, function(result) { |
| 35 logError(result); |
| 36 return crypto.subtle.exportKey("raw", {}); |
| 37 }).then(failAndFinishJSTest, function(result) { |
| 38 logError(result); |
| 39 return crypto.subtle.exportKey("raw", 1); |
| 40 }).then(failAndFinishJSTest, function(result) { |
| 41 logError(result); |
| 42 debug("\nImporting a JWK key..."); |
| 43 |
| 44 return crypto.subtle.importKey("jwk", jwkKeyAsArrayBuffer, {name: "AES-CBC"}
, extractable, ['encrypt', 'decrypt', 'wrapKey', 'unwrapKey']); |
| 45 }).then(function(result) { |
| 46 key = result; |
| 47 |
| 48 return crypto.subtle.exportKey(null, key); |
| 49 }).then(failAndFinishJSTest, function(result) { |
| 50 logError(result); |
| 51 return crypto.subtle.exportKey(undefined, key); |
| 52 }).then(failAndFinishJSTest, function(result) { |
| 53 logError(result); |
| 54 return crypto.subtle.exportKey({}, key); |
| 55 }).then(failAndFinishJSTest, function(result) { |
| 56 logError(result); |
| 57 return crypto.subtle.exportKey("", key); |
| 58 }).then(failAndFinishJSTest, function(result) { |
| 59 logError(result); |
| 60 return crypto.subtle.exportKey("foobar", key); |
| 61 }).then(failAndFinishJSTest, function(result) { |
| 62 logError(result); |
| 63 |
| 64 debug("\nExporting the key as raw data..."); |
| 65 return crypto.subtle.exportKey("raw", key); |
| 66 }).then(function(result) { |
| 67 exportedData = result; |
| 68 shouldBe("bytesToHexString(new Uint8Array(exportedData))", "'8e73b0f7da0e645
2c810f32b809079e562f8ead2522c6b7b'"); |
| 69 |
| 70 debug("Exporting the key as JWK..."); |
| 71 return crypto.subtle.exportKey("jwk", key); |
| 72 }).then(function(result) { |
| 73 exportedJWK = JSON.parse(bytesToASCIIString(result)); |
| 74 shouldBe("exportedJWK.kty", "'oct'"); |
| 75 shouldBe("exportedJWK.k", "'jnOw99oOZFLIEPMrgJB55WL46tJSLGt7'"); |
| 76 shouldBe("exportedJWK.alg", "'A192CBC'"); |
| 77 shouldBe("exportedJWK.ext", "true"); |
| 78 shouldBe("exportedJWK.use", "undefined"); |
| 79 shouldBe("exportedJWK.key_ops", "['encrypt', 'decrypt', 'wrapKey', 'unwrapKe
y']"); |
| 80 |
| 81 debug("\nImporting a key that's not extractable..."); |
| 82 return crypto.subtle.importKey("jwk", jwkKeyAsArrayBuffer, {name: "AES-CBC"}
, nonExtractable, ['encrypt', 'decrypt', 'wrapKey', 'unwrapKey']) |
| 83 }).then(function(result) { |
| 84 key = result; |
| 85 |
| 86 debug("\nTrying to export as raw..."); |
| 87 return crypto.subtle.exportKey("raw", key); |
| 88 }, failAndFinishJSTest).then(function(result) { |
| 89 testFailed("Promise wasn't rejected"); |
| 90 finishJSTest(); |
| 91 }, function(result) { |
| 92 testPassed("Rejected, as expected"); |
| 93 logError(result); |
| 94 |
| 95 debug("Trying to export as jwk..."); |
| 96 return crypto.subtle.exportKey("jwk", key); |
| 97 }).then(function(result) { |
| 98 testFailed("Promise wasn't rejected"); |
| 99 finishJSTest(); |
| 100 }, function(result) { |
| 101 testPassed("Rejected, as expected"); |
| 102 logError(result); |
| 103 |
| 104 finishJSTest(); |
| 105 }); |
| 106 </script> |
| 107 |
| 108 </body> |
| 109 </html> |
OLD | NEW |