| <!DOCTYPE html> |
| <html> |
| <head> |
| <script src="../../resources/js-test-pre.js"></script> |
| <script src="../resources/common.js"></script> |
| </head> |
| <body> |
| <p id="description"></p> |
| <div id="console"></div> |
| |
| <script> |
| description("Test HMAC sign and verify functions with an empty key."); |
| |
| jsTestIsAsync = true; |
| |
| var hmacKey = asciiToUint8Array(''); |
| var extractable = true; |
| |
| debug("Importing a raw HMAC key from string literal..."); |
| crypto.webkitSubtle.importKey("raw", hmacKey, {name: 'hmac', hash: {name: 'sha-1'}}, extractable, ["sign", "verify"]).then(function(result) { |
| key = result; |
| shouldBe("key.type", "'secret'"); |
| shouldBe("key.extractable", "true"); |
| shouldBe("key.algorithm.name", "'HMAC'"); |
| shouldBe("key.algorithm.length", "0"); // See <https://www.w3.org/Bugs/Public/show_bug.cgi?id=23098>. |
| shouldBe("key.algorithm.hash.name", "'SHA-1'"); |
| shouldBe("key.usages", "['sign', 'verify']"); |
| |
| debug("Using the key to sign 'foo'..."); |
| return crypto.webkitSubtle.sign(key.algorithm, key, asciiToUint8Array('foo')); |
| }).then(function(result) { |
| signature = result; |
| shouldBe("bytesToHexString(new Uint8Array(signature))", "'a3cc770fc033e2cb419d42b64e0081a3bd3be30e'"); |
| |
| debug("Verifying the signature..."); |
| return crypto.webkitSubtle.verify(key.algorithm, key, result, asciiToUint8Array('foo')); |
| }).then(function(result) { |
| verificationResult = result; |
| shouldBe("verificationResult", "true"); |
| finishJSTest(); |
| }); |
| </script> |
| |
| <script src="../../resources/js-test-post.js"></script> |
| </body> |
| </html> |