Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: qunit/tests/signatures.js

Issue 29375851: [safari] Issue 4902 - Partially revert d5be57b68f91 for Safari compatibility (Closed)
Patch Set: Created Feb. 17, 2017, 9:31 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« metadata.common ('K') | « metadata.common ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18
19 (function()
20 {
21 module("RSA signature validation");
22
23 test("512 bit signing key", 6, function()
24 {
25 /*
26 -----BEGIN RSA PRIVATE KEY-----
27 MIIBOQIBAAJBALZc50pEXnz9TSRozwM04rryuaXl/wgUFqV9FHq8HDlkdKvRU0hX
28 hb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQJBALRxYs5irhgAz2b6afOj
29 TcFr0PRtipckwW/IPw5euZKyvswEJt/tWDv4OdmDnRe8FSy6FG2Got3zxvaxYdc3
30 AXkCIQDfFGcytIVq3sbdF3lmhzcXf29R4Hrxg/eoByAKabxknwIhANFGSNMOGPt6
31 JRajfB9XmsltQJzbkr2sfHgjMN2FLM49AiAH6tt2yz1o+5snQawHXYkxBk7XIxZ5
32 9+sURZx3giUzlQIfXF+pxX9zh41i0ZtYLn181WxkGNjS7OY2CtF9wEoIfQIgcHuf
33 shh1qrvuKiXnD9b72PF676laKdzxzX5rX6cZZLA=
34 -----END RSA PRIVATE KEY-----
35 */
36
37 var data = "test";
38 var publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALZc50pEXnz9TSRozwM04rryuaX l/wgUFqV9FHq8HDlkdKvRU0hXhb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQ==";
39 var signature = "LzKJE1BOsZDfwD/hncHq+MN5ZygIemb1Pyzx40rm3CoTL4CVPAicS1mOiTv 6s9Li9Vw1ds9HwFWVMFVEwHwfIw==";
40 ok(verifySignature(publicKey, signature, data), "Correct signature");
41
42 ok(!verifySignature(publicKey, signature, data + "1"), "Wrong data");
43 ok(!verifySignature(publicKey, signature, data.substr(0, 3)), "Wrong data");
44 ok(!verifySignature(publicKey, signature.substr(0, 5) + "0" + signature.subs tr(6), data), "Wrong signature");
45 ok(!verifySignature(publicKey.substr(0, 5) + "R" + publicKey.substr(6), sign ature, data), "Wrong public key");
46 ok(!verifySignature(publicKey.substr(0, 70) + "8" + publicKey.substr(71), si gnature, data), "Wrong public key");
47 });
48
49 test("2048 bit signing key", 6, function()
50 {
51 /*
52 -----BEGIN RSA PRIVATE KEY-----
53 MIIEowIBAAKCAQEAy45IKQw0R5YBiIFyfKftx3F/6WsvtdNMnCKodkDemXuJOcFu
54 Of/KeIjED/wW2DFG8qq72FAByUUFoTLcmawQZPd2htmHIk8ZkBRsaQ8HzNoK+vg4
55 wnI6yN/2lhSP27D4XpedG3mtbG8aYtMuqyQaxWHInSqiM4tqW/8coAPXrRTKYmsF
56 fAwPB1LCg5QI3vCy7Vdbbp907xOXON1+2seF9j8m9rh0sufXgGNWcvTNUvlf/Tid
57 SVjqxe6O3hG9jTOswC8/hez7rbiLroVNnCtIDrdX6OSM/je/XSMMnS5xpZBuqZGZ
58 tZm1Mr42omgst+KE+5dE6kyx76ra8LwsCEShawIDAQABAoIBAQCqJ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R82rNH0iMrO
75 /GKkkQKBgF1Vh1ydmW6v5bd5Oyt8uYy/dI3ajZ+j0hcNuMO6qUdAXHfB1ZWLTnNL
76 yTHyMCVckB22+GdZKhrvLDy3XTTWx+JF5fVVIpiewuNRfLhEjh0uvbKzERQ7xPDB
77 T/YKqjp7uRICikPwvySruukdXDrxZpykOsusG0QbP2qemjfmM025
78 -----END RSA PRIVATE KEY-----
79 */
80
81 var data = "test";
82 var publicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAy45IKQw0R5YBiIF yfKftx3F/6WsvtdNMnCKodkDemXuJOcFuOf/KeIjED/wW2DFG8qq72FAByUUFoTLcmawQZPd2htmHIk8 ZkBRsaQ8HzNoK+vg4wnI6yN/2lhSP27D4XpedG3mtbG8aYtMuqyQaxWHInSqiM4tqW/8coAPXrRTKYms FfAwPB1LCg5QI3vCy7Vdbbp907xOXON1+2seF9j8m9rh0sufXgGNWcvTNUvlf/TidSVjqxe6O3hG9jTO swC8/hez7rbiLroVNnCtIDrdX6OSM/je/XSMMnS5xpZBuqZGZtZm1Mr42omgst+KE+5dE6kyx76ra8Lw sCEShawIDAQAB";
83 var signature = "UYTQmygOICKi4ozlMbLSYFZ1olovZZFYT0nZygPrGoA+6+ta+wzKnPnghK4 j35QSucrf3yN8DSXa/kXBX0LcTmEaSwoNRuM7QPjT6v9hNsVjwNexOUk6pR3DotYuD1yV36sITNjx59M cG8/q6qLyj2A8KVlUbtnz/IiLzzw+wgy6WRjU1meYP8oiQGVIkB21ICqqaJ5kCvM0YrAqzQKAya513O5 1ADA6aC/EMz6B62XGgZ+AywUMcH2Wvx7cyCvPVLfAbXcgex1JtpPS6vGcdpigaVQkoyl4cIQmX1ppasg Jj2MiYl2htXvFXjYoWniEmspteNu3UybB0nMHnYjKdQ==";
84 ok(verifySignature(publicKey, signature, data), "Correct signature");
85
86 ok(!verifySignature(publicKey, signature, data + "1"), "Wrong data");
87 ok(!verifySignature(publicKey, signature, data.substr(0, 3)), "Wrong data");
88 ok(!verifySignature(publicKey, signature.substr(0, 5) + "0" + signature.subs tr(6), data), "Wrong signature");
89 ok(!verifySignature(publicKey.substr(0, 5) + "R" + publicKey.substr(6), sign ature, data), "Wrong public key");
90 ok(!verifySignature(publicKey.substr(0, 70) + "8" + publicKey.substr(71), si gnature, data), "Wrong public key");
91 });
92
93 test("Very long data", 6, function()
94 {
95 /*
96 -----BEGIN RSA PRIVATE KEY-----
97 MIIBOQIBAAJBALZc50pEXnz9TSRozwM04rryuaXl/wgUFqV9FHq8HDlkdKvRU0hX
98 hb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQJBALRxYs5irhgAz2b6afOj
99 TcFr0PRtipckwW/IPw5euZKyvswEJt/tWDv4OdmDnRe8FSy6FG2Got3zxvaxYdc3
100 AXkCIQDfFGcytIVq3sbdF3lmhzcXf29R4Hrxg/eoByAKabxknwIhANFGSNMOGPt6
101 JRajfB9XmsltQJzbkr2sfHgjMN2FLM49AiAH6tt2yz1o+5snQawHXYkxBk7XIxZ5
102 9+sURZx3giUzlQIfXF+pxX9zh41i0ZtYLn181WxkGNjS7OY2CtF9wEoIfQIgcHuf
103 shh1qrvuKiXnD9b72PF676laKdzxzX5rX6cZZLA=
104 -----END RSA PRIVATE KEY-----
105 */
106
107 var data = "foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar foobarfoobar";
108 var publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALZc50pEXnz9TSRozwM04rryuaX l/wgUFqV9FHq8HDlkdKvRU0hXhb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQ==";
109 var signature = "L1LtPxp9VwL/ij8tuIxJqtx6mD3qoFhcEmPl8A1RlNeOP34A25nzyzRWuP2 wEbHcKKXnAQESdIXaTaEuymXviQ==";
110 ok(verifySignature(publicKey, signature, data), "Correct signature");
111
112 ok(!verifySignature(publicKey, signature, data + "1"), "Wrong data");
113 ok(!verifySignature(publicKey, signature, data.substr(0, 3)), "Wrong data");
114 ok(!verifySignature(publicKey, signature.substr(0, 5) + "0" + signature.subs tr(6), data), "Wrong signature");
115 ok(!verifySignature(publicKey.substr(0, 5) + "R" + publicKey.substr(6), sign ature, data), "Wrong public key");
116 ok(!verifySignature(publicKey.substr(0, 70) + "8" + publicKey.substr(71), si gnature, data), "Wrong public key");
117 });
118
119 test("Real-life signature", 1, function()
120 {
121 var data = [
122 "/info/Liquidit%C3%A4t.html?ses=Y3JlPTEzNTUyNDE2OTImdGNpZD13d3cuYWZmaWxpbm V0LXZlcnplaWNobmlzLmRlNTBjNjAwNzIyNTlkNjQuNDA2MjE2MTImZmtpPTcyOTU2NiZ0YXNrPXNlYX JjaCZkb21haW49YWZmaWxpbmV0LXZlcnplaWNobmlzLmRlJnM9ZGZmM2U5MTEzZGNhMWYyMWEwNDcmbG FuZ3VhZ2U9ZGUmYV9pZD0yJmtleXdvcmQ9TGlxdWlkaXQlQzMlQTR0JnBvcz0yJmt3cz03Jmt3c2k9OA ==&token=AG06ipCV1LptGtY_9gFnr0vBTPy4O0YTvwoTCObJ3N3ckrQCFYIA3wod2TwAjxgAIABQv5W iAlCH8qgOUJGr9g9QmuuEG1CDnK0pUPbRrk5QhqDgkQNxP4Qqhz9xZe4",
123 "www.affilinet-verzeichnis.de",
124 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.21 (KHTML, like Gecko) Ch rome/25.0.1349.2 Safari/537.21"
125 ];
126 var publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANnylWw2vLY4hUn9w06zQKbhKBf vjFUCsdFlb6TdQhxb9RXWXuI4t31c+o8fYOv/s8q1LGPga3DE1L/tHU4LENMCAwEAAQ==";
127 var signature = "nLH8Vbc1rzmy0Q+Xg+bvm43IEO42h8rq5D9C0WCn/Y3ykgAoV4npzm7eMlq BSwZBLA/0DuuVsfTJT9MOVaurcA==";
128 ok(verifySignature(publicKey, signature, data.join("\0")), "Correct signatur e");
129 });
130 })();
OLDNEW
« metadata.common ('K') | « metadata.common ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld