| <!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 hmac 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: 'hmac', hash: {name: 'sha-1'}}, true, ['sign', 'verify']).then(function(localKey) { |
| var worker = new Worker("resources/hmac-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", "'HMAC'"); |
| shouldBe("key.algorithm.length", "128"); |
| shouldBe("key.algorithm.hash.name", "'SHA-1'"); |
| shouldBe("key.usages", '["sign", "verify"]'); |
| |
| 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> |