Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: LayoutTests/crypto/hmac-legacy-empty-key.html

Issue 806913006: [WebCrypto] Move LayoutTests from crypto to crypto/subtle (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Update path for deserialize legacy tests Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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("Tests structured de-cloning of empty HMAC keys");
13
14 jsTestIsAsync = true;
15
16 // It used to be possible to import empty HMAC keys, so it is possible that
17 // such keys were persisted to storage. This test verifies that such keys can
18 // still be successfully de-serialized and used.
19 //
20 // The version number of the serialized format used is 7.
21
22 function deserializeTestKeys()
23 {
24 function createKeyFromSerialized(serializedBytesHex)
25 {
26 return internals.deserializeBuffer(hexStringToUint8Array(serializedBytes Hex).buffer);
27 }
28
29 debug("\nDeserializing empty HMAC SHA-1 key...");
30 var sha1Key = createKeyFromSerialized("ff073f004b0200051900");
31
32 key = sha1Key;
33 shouldEvaluateAs("key.type", "secret");
34 shouldEvaluateAs("key.extractable", true);
35 shouldEvaluateAs("key.algorithm.name", "HMAC");
36 shouldEvaluateAs("key.algorithm.length", 0);
37 shouldEvaluateAs("key.algorithm.hash.name", "SHA-1");
38 shouldBe("key.usages", '["sign", "verify"]');
39
40 debug("\nDeserializing empty HMAC SHA-256 key...");
41 var sha256Key = createKeyFromSerialized("ff073f004b0200061900");
42
43 key = sha256Key;
44 shouldEvaluateAs("key.type", "secret");
45 shouldEvaluateAs("key.extractable", true);
46 shouldEvaluateAs("key.algorithm.name", "HMAC");
47 shouldEvaluateAs("key.algorithm.length", 0);
48 shouldEvaluateAs("key.algorithm.hash.name", "SHA-256");
49 shouldBe("key.usages", '["sign", "verify"]');
50
51 return {
52 sha1: sha1Key,
53 sha256: sha256Key
54 };
55 }
56
57
58 Promise.resolve(deserializeTestKeys()).then(function(result) {
59 keys = result;
60
61 debug("\ncalling verify() with a valid signature (SHA-1) ...");
62 return crypto.subtle.verify("HMAC", keys.sha1, hexStringToUint8Array("fbdb1d 1b18aa6c08324b7d64b71fb76370690e1d"), hexStringToUint8Array(""));
63 }).then(function(result) {
64 verifyResult = result;
65 shouldEvaluateAs("verifyResult", true);
66
67 debug("\ncalling verify() with an invalid signature (SHA-1) ...");
68 return crypto.subtle.verify("HMAC", keys.sha1, hexStringToUint8Array("fbdb1d 1b18aa6c08324b7d64b71fb76370690e1e"), hexStringToUint8Array(""));
69 }).then(function(result) {
70 verifyResult = result;
71 shouldEvaluateAs("verifyResult", false);
72
73 debug("\ncalling sign() (SHA-1) over empty input...");
74 return crypto.subtle.sign("HMAC", keys.sha1, hexStringToUint8Array(""));
75 }).then(function(result) {
76 bytesShouldMatchHexString("signature", "fbdb1d1b18aa6c08324b7d64b71fb7637069 0e1d", result);
77
78 debug("\ncalling verify() with a valid signature (SHA-256) ...");
79 return crypto.subtle.verify("HMAC", keys.sha256, hexStringToUint8Array("b613 679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad"), hexStringToUint8 Array(""));
80 }).then(function(result) {
81 verifyResult = result;
82 shouldEvaluateAs("verifyResult", true);
83
84 debug("\ncalling verify() with an invalid signature (SHA-256) ...");
85 return crypto.subtle.verify("HMAC", keys.sha256, hexStringToUint8Array("0000 "), hexStringToUint8Array(""));
86 }).then(function(result) {
87 verifyResult = result;
88 shouldEvaluateAs("verifyResult", false);
89
90 debug("\ncalling sign() (SHA-256) over empty input...");
91 return crypto.subtle.sign("HMAC", keys.sha256, hexStringToUint8Array(""));
92 }).then(function(result) {
93 bytesShouldMatchHexString("signature", "b613679a0814d9ec772f95d778c35fc5ff16 97c493715653c6c712144292c5ad", result);
94 }).then(finishJSTest, failAndFinishJSTest);
95
96 </script>
97
98 </body>
99 </html>
OLDNEW
« no previous file with comments | « LayoutTests/crypto/hmac-import-jwk-expected.txt ('k') | LayoutTests/crypto/hmac-legacy-empty-key-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698