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

Side by Side Diff: third_party/WebKit/LayoutTests/crypto/subtle/modify-verify-data-during-normalization.html

Issue 2316633003: Copy data bytes in Web Crypto's importKey() and verify() operations (Closed)
Patch Set: add layout tests Created 4 years, 3 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
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 crypto.subtle.verify() using a BufferSource that is modified during algorithm normalization");
13
14 jsTestIsAsync = true;
15
16 var publicKeyJSON = {
17 kty: "RSA",
18 alg: "RS256",
19 n: Base64URL.stringify(hexStringToUint8Array("ADC0940AFECE7351D56A6D432210B3 AA49D38566B03A9F102E4F198B2DA9D740728D01426A3A058B2B805A5F91D565D969FE318AD2D1AD A713F5A829CC8CDCF8C6CB4872068164063B6D651A2226CB97ED67E0FC6C702A473DB2D79A730F87 38084A2EED74922C3A119D1D101B932C0E10FAB36815F66C0792BB640B1B4C59D062FBBEDAB3CC06 9A535195D70E4A06432CAF149C24A00353A0B99F7CF5B17273CB4E38421BD315127CF4B3DCB3D20A 7C98CFAF1A0E398A55E347FA283CE7B39273259B1B2132DC18B0EB8AAE9F78EE525356B09DF39E09 0E76D7985B2B71E50AF85CA36CE91F8CCB2ABBD8A529D369890D98A2CA2825C4C2FF8B7FBF09E79C 0B")),
20 e: Base64URL.stringify(hexStringToUint8Array("010001")),
21 };
22
23 var data = asciiToUint8Array("Hello, world!");
24
25 var signature = hexStringToUint8Array("0fd9a8aef4cc1876c0b762545336c6d1fb315ae16 ae4b5e4bf34d384d8585ea7a01e76ea09ee7f7ee8d1c122e7dd15b7c94a573b2aa07203e8d13bc6f d16156cd8e5f0c15a15dccb62d152127fca09882fb53bc3e60ab586d15b95cf411e3aab4a1c231a7 e91aab09ee3d4b13d11e97505ddff77683470da510ee76e8bd530c56a85f901626a5a710f716f113 dfe9cf6c473ee16fa248aea3480a1033abe30f4c1243289a661e64d7818b55698280688097135968 c6d4b029496d85cab2a67e4696737781f70e4392c7df71bbd6c92465947f029a1de48160aced11b5 721b1cd25039fe2c16c2b38de73df3b9a83e3ea755fd0cfe51ca06b61fadf6d84677f95");
26
27 var publicKey = null;
28
29 function corruptData()
30 {
31 debug("Corrupting data...");
32 data[0] = 0;
33 data[1] = 0;
34 }
35
36 var extractable = true;
37
38 debug("Importing RSA public key...");
39 crypto.subtle.importKey("jwk", publicKeyJSON, { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" }, extractable, ["verify"]).then(function(result) {
40 publicKey = result;
41
42 // This algorithm has a custom getter that modifies |data|.
43 var algorithm = {
44 get name() {
45 debug("Accessed name property");
46 corruptData();
47 return "RSASSA-PKCS1-v1_5";
48 }
49 };
50
51 debug("\nVerifying the signature...");
52 return crypto.subtle.verify(algorithm, publicKey, signature, data);
53 }).then(function(result) {
54 // Despite modifying the data, verification should succeed.
55 verificationResult = result;
56 shouldBe("verificationResult", "true");
57
58 debug("\nVerifying the signature (again)...");
59 return crypto.subtle.verify("RSASSA-PKCS1-v1_5", publicKey, signature, data) ;
60 }).then(function(result) {
61 // This time around expect verification to have failed.
62 verificationResult = result;
63 shouldBe("verificationResult", "false");
64 }).then(finishJSTest, failAndFinishJSTest);
65 </script>
66
67 </body>
68 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698