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