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

Delta Between Two Patch Sets: qunit/tests/signatures.js

Issue 29354778: Issue 4466 - Remove rsa.js, update core + buildtools (Closed)
Left Patch Set: Created Sept. 23, 2016, 12:41 p.m.
Right Patch Set: Removed signature tests, they are tested in adblockpluscore Created Sept. 23, 2016, 1:51 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « metadata.common ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 let {verifySignature} = require("rsa");
Wladimir Palant 2016/09/23 12:50:38 Please don't just update this test - it belongs in
kzar 2016/09/23 13:52:22 Done.
19
20 (function()
21 {
22 module("RSA signature validation");
23
24 test("512 bit signing key", 6, function()
25 {
26 /*
27 -----BEGIN RSA PRIVATE KEY-----
28 MIIBOQIBAAJBALZc50pEXnz9TSRozwM04rryuaXl/wgUFqV9FHq8HDlkdKvRU0hX
29 hb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQJBALRxYs5irhgAz2b6afOj
30 TcFr0PRtipckwW/IPw5euZKyvswEJt/tWDv4OdmDnRe8FSy6FG2Got3zxvaxYdc3
31 AXkCIQDfFGcytIVq3sbdF3lmhzcXf29R4Hrxg/eoByAKabxknwIhANFGSNMOGPt6
32 JRajfB9XmsltQJzbkr2sfHgjMN2FLM49AiAH6tt2yz1o+5snQawHXYkxBk7XIxZ5
33 9+sURZx3giUzlQIfXF+pxX9zh41i0ZtYLn181WxkGNjS7OY2CtF9wEoIfQIgcHuf
34 shh1qrvuKiXnD9b72PF676laKdzxzX5rX6cZZLA=
35 -----END RSA PRIVATE KEY-----
36 */
37
38 var data = "test";
39 var publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALZc50pEXnz9TSRozwM04rryuaX l/wgUFqV9FHq8HDlkdKvRU0hXhb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQ==";
40 var signature = "LzKJE1BOsZDfwD/hncHq+MN5ZygIemb1Pyzx40rm3CoTL4CVPAicS1mOiTv 6s9Li9Vw1ds9HwFWVMFVEwHwfIw==";
41 ok(verifySignature(publicKey, signature, data), "Correct signature");
42
43 ok(!verifySignature(publicKey, signature, data + "1"), "Wrong data");
44 ok(!verifySignature(publicKey, signature, data.substr(0, 3)), "Wrong data");
45 ok(!verifySignature(publicKey, signature.substr(0, 5) + "0" + signature.subs tr(6), data), "Wrong signature");
46 ok(!verifySignature(publicKey.substr(0, 5) + "R" + publicKey.substr(6), sign ature, data), "Wrong public key");
47 ok(!verifySignature(publicKey.substr(0, 70) + "8" + publicKey.substr(71), si gnature, data), "Wrong public key");
48 });
49
50 test("2048 bit signing key", 6, function()
51 {
52 /*
53 -----BEGIN RSA PRIVATE KEY-----
54 MIIEowIBAAKCAQEAy45IKQw0R5YBiIFyfKftx3F/6WsvtdNMnCKodkDemXuJOcFu
55 Of/KeIjED/wW2DFG8qq72FAByUUFoTLcmawQZPd2htmHIk8ZkBRsaQ8HzNoK+vg4
56 wnI6yN/2lhSP27D4XpedG3mtbG8aYtMuqyQaxWHInSqiM4tqW/8coAPXrRTKYmsF
57 fAwPB1LCg5QI3vCy7Vdbbp907xOXON1+2seF9j8m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17wn0WM5vOuAII+bTJ+D/
74 OzY4nFjMfcJwvp25w/P9tGoR2sVMYZVnlgki4bxTFcf0CUDyxX4ma3I+p41P/ugS
75 aZ9th4N1nMK5dLRp/sT66zD9WCnc2R4RNI1yRTTLvIn1+7oTxpicuR82rNH0iMrO
76 /GKkkQKBgF1Vh1ydmW6v5bd5Oyt8uYy/dI3ajZ+j0hcNuMO6qUdAXHfB1ZWLTnNL
77 yTHyMCVckB22+GdZKhrvLDy3XTTWx+JF5fVVIpiewuNRfLhEjh0uvbKzERQ7xPDB
78 T/YKqjp7uRICikPwvySruukdXDrxZpykOsusG0QbP2qemjfmM025
79 -----END RSA PRIVATE KEY-----
80 */
81
82 var data = "test";
83 var publicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAy45IKQw0R5YBiIF yfKftx3F/6WsvtdNMnCKodkDemXuJOcFuOf/KeIjED/wW2DFG8qq72FAByUUFoTLcmawQZPd2htmHIk8 ZkBRsaQ8HzNoK+vg4wnI6yN/2lhSP27D4XpedG3mtbG8aYtMuqyQaxWHInSqiM4tqW/8coAPXrRTKYms FfAwPB1LCg5QI3vCy7Vdbbp907xOXON1+2seF9j8m9rh0sufXgGNWcvTNUvlf/TidSVjqxe6O3hG9jTO swC8/hez7rbiLroVNnCtIDrdX6OSM/je/XSMMnS5xpZBuqZGZtZm1Mr42omgst+KE+5dE6kyx76ra8Lw sCEShawIDAQAB";
84 var signature = "UYTQmygOICKi4ozlMbLSYFZ1olovZZFYT0nZygPrGoA+6+ta+wzKnPnghK4 j35QSucrf3yN8DSXa/kXBX0LcTmEaSwoNRuM7QPjT6v9hNsVjwNexOUk6pR3DotYuD1yV36sITNjx59M cG8/q6qLyj2A8KVlUbtnz/IiLzzw+wgy6WRjU1meYP8oiQGVIkB21ICqqaJ5kCvM0YrAqzQKAya513O5 1ADA6aC/EMz6B62XGgZ+AywUMcH2Wvx7cyCvPVLfAbXcgex1JtpPS6vGcdpigaVQkoyl4cIQmX1ppasg Jj2MiYl2htXvFXjYoWniEmspteNu3UybB0nMHnYjKdQ==";
85 ok(verifySignature(publicKey, signature, data), "Correct signature");
86
87 ok(!verifySignature(publicKey, signature, data + "1"), "Wrong data");
88 ok(!verifySignature(publicKey, signature, data.substr(0, 3)), "Wrong data");
89 ok(!verifySignature(publicKey, signature.substr(0, 5) + "0" + signature.subs tr(6), data), "Wrong signature");
90 ok(!verifySignature(publicKey.substr(0, 5) + "R" + publicKey.substr(6), sign ature, data), "Wrong public key");
91 ok(!verifySignature(publicKey.substr(0, 70) + "8" + publicKey.substr(71), si gnature, data), "Wrong public key");
92 });
93
94 test("Very long data", 6, function()
95 {
96 /*
97 -----BEGIN RSA PRIVATE KEY-----
98 MIIBOQIBAAJBALZc50pEXnz9TSRozwM04rryuaXl/wgUFqV9FHq8HDlkdKvRU0hX
99 hb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQJBALRxYs5irhgAz2b6afOj
100 TcFr0PRtipckwW/IPw5euZKyvswEJt/tWDv4OdmDnRe8FSy6FG2Got3zxvaxYdc3
101 AXkCIQDfFGcytIVq3sbdF3lmhzcXf29R4Hrxg/eoByAKabxknwIhANFGSNMOGPt6
102 JRajfB9XmsltQJzbkr2sfHgjMN2FLM49AiAH6tt2yz1o+5snQawHXYkxBk7XIxZ5
103 9+sURZx3giUzlQIfXF+pxX9zh41i0ZtYLn181WxkGNjS7OY2CtF9wEoIfQIgcHuf
104 shh1qrvuKiXnD9b72PF676laKdzxzX5rX6cZZLA=
105 -----END RSA PRIVATE KEY-----
106 */
107
108 var data = "foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar foobarfoobar";
109 var publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALZc50pEXnz9TSRozwM04rryuaX l/wgUFqV9FHq8HDlkdKvRU0hXhb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQ==";
110 var signature = "L1LtPxp9VwL/ij8tuIxJqtx6mD3qoFhcEmPl8A1RlNeOP34A25nzyzRWuP2 wEbHcKKXnAQESdIXaTaEuymXviQ==";
111 ok(verifySignature(publicKey, signature, data), "Correct signature");
112
113 ok(!verifySignature(publicKey, signature, data + "1"), "Wrong data");
114 ok(!verifySignature(publicKey, signature, data.substr(0, 3)), "Wrong data");
115 ok(!verifySignature(publicKey, signature.substr(0, 5) + "0" + signature.subs tr(6), data), "Wrong signature");
116 ok(!verifySignature(publicKey.substr(0, 5) + "R" + publicKey.substr(6), sign ature, data), "Wrong public key");
117 ok(!verifySignature(publicKey.substr(0, 70) + "8" + publicKey.substr(71), si gnature, data), "Wrong public key");
118 });
119
120 test("Real-life signature", 1, function()
121 {
122 var data = [
123 "/info/Liquidit%C3%A4t.html?ses=Y3JlPTEzNTUyNDE2OTImdGNpZD13d3cuYWZmaWxpbm V0LXZlcnplaWNobmlzLmRlNTBjNjAwNzIyNTlkNjQuNDA2MjE2MTImZmtpPTcyOTU2NiZ0YXNrPXNlYX JjaCZkb21haW49YWZmaWxpbmV0LXZlcnplaWNobmlzLmRlJnM9ZGZmM2U5MTEzZGNhMWYyMWEwNDcmbG FuZ3VhZ2U9ZGUmYV9pZD0yJmtleXdvcmQ9TGlxdWlkaXQlQzMlQTR0JnBvcz0yJmt3cz03Jmt3c2k9OA ==&token=AG06ipCV1LptGtY_9gFnr0vBTPy4O0YTvwoTCObJ3N3ckrQCFYIA3wod2TwAjxgAIABQv5W iAlCH8qgOUJGr9g9QmuuEG1CDnK0pUPbRrk5QhqDgkQNxP4Qqhz9xZe4",
124 "www.affilinet-verzeichnis.de",
125 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.21 (KHTML, like Gecko) Ch rome/25.0.1349.2 Safari/537.21"
126 ];
127 var publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANnylWw2vLY4hUn9w06zQKbhKBf vjFUCsdFlb6TdQhxb9RXWXuI4t31c+o8fYOv/s8q1LGPga3DE1L/tHU4LENMCAwEAAQ==";
128 var signature = "nLH8Vbc1rzmy0Q+Xg+bvm43IEO42h8rq5D9C0WCn/Y3ykgAoV4npzm7eMlq BSwZBLA/0DuuVsfTJT9MOVaurcA==";
129 ok(verifySignature(publicKey, signature, data.join("\0")), "Correct signatur e");
130 });
131 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld