Left: | ||
Right: |
OLD | NEW |
---|---|
(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 "use strict"; | |
19 | |
20 let {verifySignature} = require("rsa"); | |
21 | |
22 exports.test512bitSigningKey = function(test) | |
23 { | |
24 /* | |
25 -----BEGIN RSA PRIVATE KEY----- | |
26 MIIBOQIBAAJBALZc50pEXnz9TSRozwM04rryuaXl/wgUFqV9FHq8HDlkdKvRU0hX | |
27 hb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQJBALRxYs5irhgAz2b6afOj | |
28 TcFr0PRtipckwW/IPw5euZKyvswEJt/tWDv4OdmDnRe8FSy6FG2Got3zxvaxYdc3 | |
29 AXkCIQDfFGcytIVq3sbdF3lmhzcXf29R4Hrxg/eoByAKabxknwIhANFGSNMOGPt6 | |
30 JRajfB9XmsltQJzbkr2sfHgjMN2FLM49AiAH6tt2yz1o+5snQawHXYkxBk7XIxZ5 | |
31 9+sURZx3giUzlQIfXF+pxX9zh41i0ZtYLn181WxkGNjS7OY2CtF9wEoIfQIgcHuf | |
32 shh1qrvuKiXnD9b72PF676laKdzxzX5rX6cZZLA= | |
33 -----END RSA PRIVATE KEY----- | |
34 */ | |
35 | |
36 var data = "test"; | |
37 var publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALZc50pEXnz9TSRozwM04rryuaXl/ wgUFqV9FHq8HDlkdKvRU0hXhb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQ=="; | |
38 var signature = "LzKJE1BOsZDfwD/hncHq+MN5ZygIemb1Pyzx40rm3CoTL4CVPAicS1mOiTv6s 9Li9Vw1ds9HwFWVMFVEwHwfIw=="; | |
39 test.ok(verifySignature(publicKey, signature, data), "Correct signature"); | |
40 | |
41 test.ok(!verifySignature(publicKey, signature, data + "1"), "Wrong data"); | |
42 test.ok(!verifySignature(publicKey, signature, data.substr(0, 3)), "Wrong data "); | |
43 test.ok(!verifySignature(publicKey, signature.substr(0, 5) + "0" + signature.s ubstr(6), data), "Wrong signature"); | |
44 test.ok(!verifySignature(publicKey.substr(0, 5) + "R" + publicKey.substr(6), s ignature, data), "Wrong public key"); | |
45 test.ok(!verifySignature(publicKey.substr(0, 70) + "8" + publicKey.substr(71), signature, data), "Wrong public key"); | |
46 | |
47 test.done(); | |
48 }; | |
49 | |
50 exports.test2048bitSigningKey = function(test) | |
51 { | |
52 /* | |
53 -----BEGIN RSA PRIVATE KEY----- | |
54 MIIEowIBAAKCAQEAy45IKQw0R5YBiIFyfKftx3F/6WsvtdNMnCKodkDemXuJOcFu | |
55 Of/KeIjED/wW2DFG8qq72FAByUUFoTLcmawQZPd2htmHIk8ZkBRsaQ8HzNoK+vg4 | |
56 wnI6yN/2lhSP27D4XpedG3mtbG8aYtMuqyQaxWHInSqiM4tqW/8coAPXrRTKYmsF | |
57 fAwPB1LCg5QI3vCy7Vdbbp907xOXON1+2seF9j8m9rh0sufXgGNWcvTNUvlf/Tid | |
58 SVjqxe6O3hG9jTOswC8/hez7rbiLroVNnCtIDrdX6OSM/je/XSMMnS5xpZBuqZGZ | |
59 tZm1Mr42omgst+KE+5dE6kyx76ra8LwsCEShawIDAQABAoIBAQCqJ3qcjW4aNQN9 | |
60 FzAbkciLAo55ETdll4afsbz+dMVeqUyRcebxJqgaT8EM155FBBQZf6zcaizEESVe | |
61 lYSgF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uYy/dI3ajZ+j0hcNuMO6qUdAXHfB1ZWLTnNL | |
77 yTHyMCVckB22+GdZKhrvLDy3XTTWx+JF5fVVIpiewuNRfLhEjh0uvbKzERQ7xPDB | |
78 T/YKqjp7uRICikPwvySruukdXDrxZpykOsusG0QbP2qemjfmM025 | |
79 -----END RSA PRIVATE KEY----- | |
80 */ | |
81 | |
82 var data = "test"; | |
83 var publicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAy45IKQw0R5YBiIFyf Kftx3F/6WsvtdNMnCKodkDemXuJOcFuOf/KeIjED/wW2DFG8qq72FAByUUFoTLcmawQZPd2htmHIk8Zk BRsaQ8HzNoK+vg4wnI6yN/2lhSP27D4XpedG3mtbG8aYtMuqyQaxWHInSqiM4tqW/8coAPXrRTKYmsFf AwPB1LCg5QI3vCy7Vdbbp907xOXON1+2seF9j8m9rh0sufXgGNWcvTNUvlf/TidSVjqxe6O3hG9jTOsw C8/hez7rbiLroVNnCtIDrdX6OSM/je/XSMMnS5xpZBuqZGZtZm1Mr42omgst+KE+5dE6kyx76ra8LwsC EShawIDAQAB"; | |
84 var signature = "UYTQmygOICKi4ozlMbLSYFZ1olovZZFYT0nZygPrGoA+6+ta+wzKnPnghK4j3 5QSucrf3yN8DSXa/kXBX0LcTmEaSwoNRuM7QPjT6v9hNsVjwNexOUk6pR3DotYuD1yV36sITNjx59McG 8/q6qLyj2A8KVlUbtnz/IiLzzw+wgy6WRjU1meYP8oiQGVIkB21ICqqaJ5kCvM0YrAqzQKAya513O51A DA6aC/EMz6B62XGgZ+AywUMcH2Wvx7cyCvPVLfAbXcgex1JtpPS6vGcdpigaVQkoyl4cIQmX1ppasgJj 2MiYl2htXvFXjYoWniEmspteNu3UybB0nMHnYjKdQ=="; | |
85 test.ok(verifySignature(publicKey, signature, data), "Correct signature"); | |
86 | |
87 test.ok(!verifySignature(publicKey, signature, data + "1"), "Wrong data"); | |
88 test.ok(!verifySignature(publicKey, signature, data.substr(0, 3)), "Wrong data "); | |
89 test.ok(!verifySignature(publicKey, signature.substr(0, 5) + "0" + signature.s ubstr(6), data), "Wrong signature"); | |
90 test.ok(!verifySignature(publicKey.substr(0, 5) + "R" + publicKey.substr(6), s ignature, data), "Wrong public key"); | |
91 test.ok(!verifySignature(publicKey.substr(0, 70) + "8" + publicKey.substr(71), signature, data), "Wrong public key"); | |
92 | |
93 test.done(); | |
94 }; | |
95 | |
96 exports.testVeryLongData = function(test) | |
97 { | |
98 /* | |
99 -----BEGIN RSA PRIVATE KEY----- | |
100 MIIBOQIBAAJBALZc50pEXnz9TSRozwM04rryuaXl/wgUFqV9FHq8HDlkdKvRU0hX | |
101 hb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQJBALRxYs5irhgAz2b6afOj | |
102 TcFr0PRtipckwW/IPw5euZKyvswEJt/tWDv4OdmDnRe8FSy6FG2Got3zxvaxYdc3 | |
103 AXkCIQDfFGcytIVq3sbdF3lmhzcXf29R4Hrxg/eoByAKabxknwIhANFGSNMOGPt6 | |
104 JRajfB9XmsltQJzbkr2sfHgjMN2FLM49AiAH6tt2yz1o+5snQawHXYkxBk7XIxZ5 | |
105 9+sURZx3giUzlQIfXF+pxX9zh41i0ZtYLn181WxkGNjS7OY2CtF9wEoIfQIgcHuf | |
106 shh1qrvuKiXnD9b72PF676laKdzxzX5rX6cZZLA= | |
107 -----END RSA PRIVATE KEY----- | |
108 */ | |
109 | |
110 var data = "foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo obarfoobar"; | |
111 var publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALZc50pEXnz9TSRozwM04rryuaXl/ wgUFqV9FHq8HDlkdKvRU0hXhb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQ=="; | |
112 var signature = "L1LtPxp9VwL/ij8tuIxJqtx6mD3qoFhcEmPl8A1RlNeOP34A25nzyzRWuP2wE bHcKKXnAQESdIXaTaEuymXviQ=="; | |
113 test.ok(verifySignature(publicKey, signature, data), "Correct signature"); | |
114 | |
115 test.ok(!verifySignature(publicKey, signature, data + "1"), "Wrong data"); | |
116 test.ok(!verifySignature(publicKey, signature, data.substr(0, 3)), "Wrong data "); | |
117 test.ok(!verifySignature(publicKey, signature.substr(0, 5) + "0" + signature.s ubstr(6), data), "Wrong signature"); | |
118 test.ok(!verifySignature(publicKey.substr(0, 5) + "R" + publicKey.substr(6), s ignature, data), "Wrong public key"); | |
119 test.ok(!verifySignature(publicKey.substr(0, 70) + "8" + publicKey.substr(71), signature, data), "Wrong public key"); | |
120 | |
121 test.done(); | |
122 }; | |
123 | |
124 exports.testRealLifeSignature = function(test) | |
125 { | |
126 var data = [ | |
127 "/info/Liquidit%C3%A4t.html?ses=Y3JlPTEzNTUyNDE2OTImdGNpZD13d3cuYWZmaWxpbmV0 LXZlcnplaWNobmlzLmRlNTBjNjAwNzIyNTlkNjQuNDA2MjE2MTImZmtpPTcyOTU2NiZ0YXNrPXNlYXJj aCZkb21haW49YWZmaWxpbmV0LXZlcnplaWNobmlzLmRlJnM9ZGZmM2U5MTEzZGNhMWYyMWEwNDcmbGFu Z3VhZ2U9ZGUmYV9pZD0yJmtleXdvcmQ9TGlxdWlkaXQlQzMlQTR0JnBvcz0yJmt3cz03Jmt3c2k9OA== &token=AG06ipCV1LptGtY_9gFnr0vBTPy4O0YTvwoTCObJ3N3ckrQCFYIA3wod2TwAjxgAIABQv5WiA lCH8qgOUJGr9g9QmuuEG1CDnK0pUPbRrk5QhqDgkQNxP4Qqhz9xZe4", | |
128 "www.affilinet-verzeichnis.de", | |
129 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.21 (KHTML, like Gecko) Chro me/25.0.1349.2 Safari/537.21" | |
130 ]; | |
131 var publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANnylWw2vLY4hUn9w06zQKbhKBfvj FUCsdFlb6TdQhxb9RXWXuI4t31c+o8fYOv/s8q1LGPga3DE1L/tHU4LENMCAwEAAQ=="; | |
132 var signature = "nLH8Vbc1rzmy0Q+Xg+bvm43IEO42h8rq5D9C0WCn/Y3ykgAoV4npzm7eMlqBS wZBLA/0DuuVsfTJT9MOVaurcA=="; | |
133 test.ok(verifySignature(publicKey, signature, data.join("\0")), "Correct signa ture"); | |
134 | |
135 test.done(); | |
136 }; | |
Wladimir Palant
2016/09/23 20:02:29
I assume that this file was taken over without any
kzar
2016/09/25 12:46:47
I made a few changes after copying this over from
| |
OLD | NEW |