| <!DOCTYPE html> |
| <html> |
| <head> |
| <meta charset="utf-8"> |
| <script src="../../../resources/js-test-pre.js"></script> |
| <script src="../../resources/common.js"></script> |
| </head> |
| <body> |
| <script> |
| |
| description("Test sending aes crypto keys via postMessage to a worker."); |
| |
| jsTestIsAsync = true; |
| var rawKeyAscii = "16 bytes of key!"; |
| var rawKey = asciiToUint8Array(rawKeyAscii); |
| |
| crypto.subtle.importKey("raw", rawKey, {name: "aes-cbc", length: 128}, true, ["encrypt", "decrypt"]).then(function(localKey) { |
| var worker = new Worker("resources/aes-postMessage-worker.js"); |
| worker.onmessage = function(evt) { |
| if (!evt.data.result) { |
| testFailed("Check failed in worker: " + evt.data.message); |
| } else { |
| testPassed("All checks passed in worker"); |
| key = evt.data.key; |
| shouldBe("key.type", "'secret'"); |
| shouldBe("key.extractable", "true"); |
| shouldBe("key.algorithm.name", "'AES-CBC'"); |
| shouldBe("key.algorithm.length", "128"); |
| shouldBe("key.usages", "['decrypt', 'encrypt']"); |
| |
| crypto.subtle.exportKey("raw", key).then(function(result) { |
| exportedKey = result; |
| |
| shouldBe("bytesToASCIIString(exportedKey)", "rawKeyAscii"); |
| |
| finishJSTest(); |
| }); |
| } |
| } |
| worker.postMessage(localKey); |
| }); |
| </script> |
| <script src="../../../resources/js-test-post.js"></script> |
| </body> |
| </html> |