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

Side by Side Diff: LayoutTests/crypto/sign-verify.html

Issue 22849026: WebCrypto: Check for HmacKeyParams when seeing if a Key can be used for an Algorithm. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase onto master Created 7 years, 4 months 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 | Annotate | Revision Log
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html> 2 <html>
3 <head> 3 <head>
4 <script src="../fast/js/resources/js-test-pre.js"></script> 4 <script src="../fast/js/resources/js-test-pre.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("Tests cypto.subtle.sign and crypto.subtle.verify"); 12 description("Tests cypto.subtle.sign and crypto.subtle.verify");
13 13
14 jsTestIsAsync = true; 14 jsTestIsAsync = true;
15 15
16 hmacSha1 = {name: 'hmac', hash: {name: 'sha-1'}};
17 data = asciiToArrayBuffer("hello");
18
16 importTestKeys().then(function(importedKeys) { 19 importTestKeys().then(function(importedKeys) {
17 keys = importedKeys; 20 keys = importedKeys;
18 21
19 hmacSha1 = {name: 'hmac', hash: {name: 'sha-1'}};
20
21 data = asciiToArrayBuffer("hello");
22
23 // Pass invalid signature parameters to verify() 22 // Pass invalid signature parameters to verify()
24 shouldThrow("crypto.subtle.verify(hmacSha1, keys.hmacSha1, null, data)"); 23 shouldThrow("crypto.subtle.verify(hmacSha1, keys.hmacSha1, null, data)");
25 shouldThrow("crypto.subtle.verify(hmacSha1, keys.hmacSha1, 'a', data)"); 24 shouldThrow("crypto.subtle.verify(hmacSha1, keys.hmacSha1, 'a', data)");
26 shouldThrow("crypto.subtle.verify(hmacSha1, keys.hmacSha1, [], data)"); 25 shouldThrow("crypto.subtle.verify(hmacSha1, keys.hmacSha1, [], data)");
27 26
28 // Operation does not support signing. 27 // Operation does not support signing.
29 shouldThrow("crypto.subtle.sign({name: 'sha-1'}, keys.hmacSha1, data)"); 28 shouldThrow("crypto.subtle.sign({name: 'sha-1'}, keys.hmacSha1, data)");
30 29
31 // Key's algorithm must match. 30 // Key's algorithm must match.
32 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: {name: 'sha-256'}}, key s.hmacSha1, data)"); 31 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: {name: 'sha-256'}}, key s.hmacSha1, data)");
(...skipping 26 matching lines...) Expand all
59 expectedSignature = asciiToArrayBuffer("signed HMAC:hello"); 58 expectedSignature = asciiToArrayBuffer("signed HMAC:hello");
60 return crypto.subtle.verify(hmacSha1, keys.hmacSha1, expectedSignature, data ); 59 return crypto.subtle.verify(hmacSha1, keys.hmacSha1, expectedSignature, data );
61 }).then(function(result) { 60 }).then(function(result) {
62 verifyResult = result; 61 verifyResult = result;
63 shouldBe("verifyResult", "true"); 62 shouldBe("verifyResult", "true");
64 63
65 return crypto.subtle.verify(hmacSha1, keys.hmacSha1, asciiToArrayBuffer("bad signature"), data); 64 return crypto.subtle.verify(hmacSha1, keys.hmacSha1, asciiToArrayBuffer("bad signature"), data);
66 }).then(function(result) { 65 }).then(function(result) {
67 verifyResult = result; 66 verifyResult = result;
68 shouldBe("verifyResult", "false"); 67 shouldBe("verifyResult", "false");
68
69 return crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-1' }, leng th: 48}, false, ['sign']);
70 }).then(function(result) {
71 generatedHmacSha1Key = result;
72
73 // Cannot use an HMAC SHA-1 key for signing HMAC SHA-256
74 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: {name: 'sha-256'}}, gen eratedHmacSha1Key, data)");
75
76 // However it can be used to sign for HMAC SHA-1
77 shouldNotThrow("crypto.subtle.sign(hmacSha1, generatedHmacSha1Key, data)");
69 }).then(finishJSTest, failAndFinishJSTest); 78 }).then(finishJSTest, failAndFinishJSTest);
70 79
71 </script> 80 </script>
72 81
73 <script src="../fast/js/resources/js-test-post.js"></script> 82 <script src="../fast/js/resources/js-test-post.js"></script>
74 </body> 83 </body>
OLDNEW
« no previous file with comments | « LayoutTests/crypto/encrypt-decrypt-expected.txt ('k') | LayoutTests/crypto/sign-verify-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698