OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 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/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 "use strict"; | 18 "use strict"; |
19 | 19 |
| 20 const assert = require("assert"); |
20 const {createSandbox} = require("./_common"); | 21 const {createSandbox} = require("./_common"); |
21 | 22 |
22 let verifySignature = null; | 23 let verifySignature = null; |
23 | 24 |
24 exports.setUp = function(callback) | 25 describe("Signatures", () => |
25 { | 26 { |
26 let sandboxedRequire = createSandbox(); | 27 beforeEach(() => |
27 ( | 28 { |
28 {verifySignature} = sandboxedRequire("../lib/rsa") | 29 let sandboxedRequire = createSandbox(); |
29 ); | 30 ( |
| 31 {verifySignature} = sandboxedRequire("../lib/rsa") |
| 32 ); |
| 33 }); |
30 | 34 |
31 callback(); | 35 it("512bits Signing Key", () => |
32 }; | 36 { |
| 37 /* |
| 38 -----BEGIN RSA PRIVATE KEY----- |
| 39 MIIBOQIBAAJBALZc50pEXnz9TSRozwM04rryuaXl/wgUFqV9FHq8HDlkdKvRU0hX |
| 40 hb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQJBALRxYs5irhgAz2b6afOj |
| 41 TcFr0PRtipckwW/IPw5euZKyvswEJt/tWDv4OdmDnRe8FSy6FG2Got3zxvaxYdc3 |
| 42 AXkCIQDfFGcytIVq3sbdF3lmhzcXf29R4Hrxg/eoByAKabxknwIhANFGSNMOGPt6 |
| 43 JRajfB9XmsltQJzbkr2sfHgjMN2FLM49AiAH6tt2yz1o+5snQawHXYkxBk7XIxZ5 |
| 44 9+sURZx3giUzlQIfXF+pxX9zh41i0ZtYLn181WxkGNjS7OY2CtF9wEoIfQIgcHuf |
| 45 shh1qrvuKiXnD9b72PF676laKdzxzX5rX6cZZLA= |
| 46 -----END RSA PRIVATE KEY----- |
| 47 */ |
33 | 48 |
34 exports.test512bitSigningKey = function(test) | 49 let data = "test"; |
35 { | 50 let publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALZc50pEXnz9TSRozwM04rryuaX
l/wgUFqV9FHq8HDlkdKvRU0hXhb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQ=="; |
36 /* | 51 let signature = "LzKJE1BOsZDfwD/hncHq+MN5ZygIemb1Pyzx40rm3CoTL4CVPAicS1mOiTv
6s9Li9Vw1ds9HwFWVMFVEwHwfIw=="; |
37 -----BEGIN RSA PRIVATE KEY----- | 52 assert.ok(verifySignature(publicKey, signature, data), "Correct signature"); |
38 MIIBOQIBAAJBALZc50pEXnz9TSRozwM04rryuaXl/wgUFqV9FHq8HDlkdKvRU0hX | |
39 hb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQJBALRxYs5irhgAz2b6afOj | |
40 TcFr0PRtipckwW/IPw5euZKyvswEJt/tWDv4OdmDnRe8FSy6FG2Got3zxvaxYdc3 | |
41 AXkCIQDfFGcytIVq3sbdF3lmhzcXf29R4Hrxg/eoByAKabxknwIhANFGSNMOGPt6 | |
42 JRajfB9XmsltQJzbkr2sfHgjMN2FLM49AiAH6tt2yz1o+5snQawHXYkxBk7XIxZ5 | |
43 9+sURZx3giUzlQIfXF+pxX9zh41i0ZtYLn181WxkGNjS7OY2CtF9wEoIfQIgcHuf | |
44 shh1qrvuKiXnD9b72PF676laKdzxzX5rX6cZZLA= | |
45 -----END RSA PRIVATE KEY----- | |
46 */ | |
47 | 53 |
48 let data = "test"; | 54 assert.ok(!verifySignature(publicKey, signature, data + "1"), "Wrong data"); |
49 let publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALZc50pEXnz9TSRozwM04rryuaXl/
wgUFqV9FHq8HDlkdKvRU0hXhb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQ=="; | 55 assert.ok(!verifySignature(publicKey, signature, data.substring(0, 3)), "Wro
ng data"); |
50 let signature = "LzKJE1BOsZDfwD/hncHq+MN5ZygIemb1Pyzx40rm3CoTL4CVPAicS1mOiTv6s
9Li9Vw1ds9HwFWVMFVEwHwfIw=="; | 56 assert.ok(!verifySignature(publicKey, signature.substring(0, 5) + "0" + sign
ature.substring(6), data), "Wrong signature"); |
51 test.ok(verifySignature(publicKey, signature, data), "Correct signature"); | 57 assert.ok(!verifySignature(publicKey.substring(0, 5) + "R" + publicKey.subst
ring(6), signature, data), "Wrong public key"); |
| 58 assert.ok(!verifySignature(publicKey.substring(0, 70) + "8" + publicKey.subs
tring(71), signature, data), "Wrong public key"); |
| 59 }); |
52 | 60 |
53 test.ok(!verifySignature(publicKey, signature, data + "1"), "Wrong data"); | 61 it("2048bits Signing Key", () => |
54 test.ok(!verifySignature(publicKey, signature, data.substring(0, 3)), "Wrong d
ata"); | 62 { |
55 test.ok(!verifySignature(publicKey, signature.substring(0, 5) + "0" + signatur
e.substring(6), data), "Wrong signature"); | 63 /* |
56 test.ok(!verifySignature(publicKey.substring(0, 5) + "R" + publicKey.substring
(6), signature, data), "Wrong public key"); | 64 -----BEGIN RSA PRIVATE KEY----- |
57 test.ok(!verifySignature(publicKey.substring(0, 70) + "8" + publicKey.substrin
g(71), signature, data), "Wrong public key"); | 65 MIIEowIBAAKCAQEAy45IKQw0R5YBiIFyfKftx3F/6WsvtdNMnCKodkDemXuJOcFu |
| 66 Of/KeIjED/wW2DFG8qq72FAByUUFoTLcmawQZPd2htmHIk8ZkBRsaQ8HzNoK+vg4 |
| 67 wnI6yN/2lhSP27D4XpedG3mtbG8aYtMuqyQaxWHInSqiM4tqW/8coAPXrRTKYmsF |
| 68 fAwPB1LCg5QI3vCy7Vdbbp907xOXON1+2seF9j8m9rh0sufXgGNWcvTNUvlf/Tid |
| 69 SVjqxe6O3hG9jTOswC8/hez7rbiLroVNnCtIDrdX6OSM/je/XSMMnS5xpZBuqZGZ |
| 70 tZm1Mr42omgst+KE+5dE6kyx76ra8LwsCEShawIDAQABAoIBAQCqJ3qcjW4aNQN9 |
| 71 FzAbkciLAo55ETdll4afsbz+dMVeqUyRcebxJqgaT8EM155FBBQZf6zcaizEESVe |
| 72 lYSgFJvzuoRivu1eOZ7VuKzSuVS84btyBRJ1QEVxav3WgMOsUmebssMKl5DnZow4 |
| 73 9e059ElIm6+16VCDI9Q5qKxF+lBMhemFdddmmI8c4byrLOqUQ+iQJAbgnBTsyxFO |
| 74 sDgkknAuiqAkzltqeQZ0fE1iZ4cY1wJNneltlGKLRhdq2hqgzu/6h9Y92sdcqARK |
| 75 i7zu2IChTJLxnx+XcJZ2Tq5rAh52klayEPYIyEcLw6DbD8dXGNLYfKjZ0+TYIyPB |
| 76 x3g+J7TRAoGBAO8hmfJuS3G9lf0JhjCIsKr9pjm0MAjZ6uUyQnh9vWbKwqHQzmuB |
| 77 XdS3YdAzO55dxoSt/lO9X7tLC5R4EehWKi4hkmdzmNJ23vgeLHkmNBzcrJ75jDKU |
| 78 vapbD15EvRGFBcWSkpjfM+a+isAt08Yr90DwUKz7SzW+fwik3iNbKfojAoGBANnq |
| 79 O+ZC2gg49ksRgxYwCqI1vLdLHs0o5wCNPulstJC1nH+xVcB1lvXF8Q2BTe50dR5w |
| 80 SbxoCMrrRghjvWd4bGnNzlT8jXSWYfGSgXpbuYQOzoAjezU8XiSL2FcR07FeTPsG |
| 81 JZ2bn8aObpd8SFAtdWUOpbSvJ8W8Pm84XHmweTwZAoGAJS9VcBRkmPBBNZLYkg1/ |
| 82 Y2eEBK8XVRkF5NQW8AOlgyl+cIk2wBLi02QcyrJcz/iHGTSxOrZU/5vg1hqBtl5H |
| 83 utqvmHSqS/f+HhkbE0+0hNRv51yox2jHwYjdb+xCdkn4JsvvDeSPfo8cplu59bP6 |
| 84 g9eaw/tjq5zOxjpU7KyNb38CgYA4oDtsfFa36EVoAGb17wn0WM5vOuAII+bTJ+D/ |
| 85 OzY4nFjMfcJwvp25w/P9tGoR2sVMYZVnlgki4bxTFcf0CUDyxX4ma3I+p41P/ugS |
| 86 aZ9th4N1nMK5dLRp/sT66zD9WCnc2R4RNI1yRTTLvIn1+7oTxpicuR82rNH0iMrO |
| 87 /GKkkQKBgF1Vh1ydmW6v5bd5Oyt8uYy/dI3ajZ+j0hcNuMO6qUdAXHfB1ZWLTnNL |
| 88 yTHyMCVckB22+GdZKhrvLDy3XTTWx+JF5fVVIpiewuNRfLhEjh0uvbKzERQ7xPDB |
| 89 T/YKqjp7uRICikPwvySruukdXDrxZpykOsusG0QbP2qemjfmM025 |
| 90 -----END RSA PRIVATE KEY----- |
| 91 */ |
58 | 92 |
59 test.done(); | 93 let data = "test"; |
60 }; | 94 let publicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAy45IKQw0R5YBiIF
yfKftx3F/6WsvtdNMnCKodkDemXuJOcFuOf/KeIjED/wW2DFG8qq72FAByUUFoTLcmawQZPd2htmHIk8
ZkBRsaQ8HzNoK+vg4wnI6yN/2lhSP27D4XpedG3mtbG8aYtMuqyQaxWHInSqiM4tqW/8coAPXrRTKYms
FfAwPB1LCg5QI3vCy7Vdbbp907xOXON1+2seF9j8m9rh0sufXgGNWcvTNUvlf/TidSVjqxe6O3hG9jTO
swC8/hez7rbiLroVNnCtIDrdX6OSM/je/XSMMnS5xpZBuqZGZtZm1Mr42omgst+KE+5dE6kyx76ra8Lw
sCEShawIDAQAB"; |
| 95 let signature = "UYTQmygOICKi4ozlMbLSYFZ1olovZZFYT0nZygPrGoA+6+ta+wzKnPnghK4
j35QSucrf3yN8DSXa/kXBX0LcTmEaSwoNRuM7QPjT6v9hNsVjwNexOUk6pR3DotYuD1yV36sITNjx59M
cG8/q6qLyj2A8KVlUbtnz/IiLzzw+wgy6WRjU1meYP8oiQGVIkB21ICqqaJ5kCvM0YrAqzQKAya513O5
1ADA6aC/EMz6B62XGgZ+AywUMcH2Wvx7cyCvPVLfAbXcgex1JtpPS6vGcdpigaVQkoyl4cIQmX1ppasg
Jj2MiYl2htXvFXjYoWniEmspteNu3UybB0nMHnYjKdQ=="; |
| 96 assert.ok(verifySignature(publicKey, signature, data), "Correct signature"); |
61 | 97 |
62 exports.test2048bitSigningKey = function(test) | 98 assert.ok(!verifySignature(publicKey, signature, data + "1"), "Wrong data"); |
63 { | 99 assert.ok(!verifySignature(publicKey, signature, data.substring(0, 3)), "Wro
ng data"); |
64 /* | 100 assert.ok(!verifySignature(publicKey, signature.substring(0, 5) + "0" + sign
ature.substring(6), data), "Wrong signature"); |
65 -----BEGIN RSA PRIVATE KEY----- | 101 assert.ok(!verifySignature(publicKey.substring(0, 5) + "R" + publicKey.subst
ring(6), signature, data), "Wrong public key"); |
66 MIIEowIBAAKCAQEAy45IKQw0R5YBiIFyfKftx3F/6WsvtdNMnCKodkDemXuJOcFu | 102 assert.ok(!verifySignature(publicKey.substring(0, 70) + "8" + publicKey.subs
tring(71), signature, data), "Wrong public key"); |
67 Of/KeIjED/wW2DFG8qq72FAByUUFoTLcmawQZPd2htmHIk8ZkBRsaQ8HzNoK+vg4 | 103 }); |
68 wnI6yN/2lhSP27D4XpedG3mtbG8aYtMuqyQaxWHInSqiM4tqW/8coAPXrRTKYmsF | |
69 fAwPB1LCg5QI3vCy7Vdbbp907xOXON1+2seF9j8m9rh0sufXgGNWcvTNUvlf/Tid | |
70 SVjqxe6O3hG9jTOswC8/hez7rbiLroVNnCtIDrdX6OSM/je/XSMMnS5xpZBuqZGZ | |
71 tZm1Mr42omgst+KE+5dE6kyx76ra8LwsCEShawIDAQABAoIBAQCqJ3qcjW4aNQN9 | |
72 FzAbkciLAo55ETdll4afsbz+dMVeqUyRcebxJqgaT8EM155FBBQZf6zcaizEESVe | |
73 lYSgFJvzuoRivu1eOZ7VuKzSuVS84btyBRJ1QEVxav3WgMOsUmebssMKl5DnZow4 | |
74 9e059ElIm6+16VCDI9Q5qKxF+lBMhemFdddmmI8c4byrLOqUQ+iQJAbgnBTsyxFO | |
75 sDgkknAuiqAkzltqeQZ0fE1iZ4cY1wJNneltlGKLRhdq2hqgzu/6h9Y92sdcqARK | |
76 i7zu2IChTJLxnx+XcJZ2Tq5rAh52klayEPYIyEcLw6DbD8dXGNLYfKjZ0+TYIyPB | |
77 x3g+J7TRAoGBAO8hmfJuS3G9lf0JhjCIsKr9pjm0MAjZ6uUyQnh9vWbKwqHQzmuB | |
78 XdS3YdAzO55dxoSt/lO9X7tLC5R4EehWKi4hkmdzmNJ23vgeLHkmNBzcrJ75jDKU | |
79 vapbD15EvRGFBcWSkpjfM+a+isAt08Yr90DwUKz7SzW+fwik3iNbKfojAoGBANnq | |
80 O+ZC2gg49ksRgxYwCqI1vLdLHs0o5wCNPulstJC1nH+xVcB1lvXF8Q2BTe50dR5w | |
81 SbxoCMrrRghjvWd4bGnNzlT8jXSWYfGSgXpbuYQOzoAjezU8XiSL2FcR07FeTPsG | |
82 JZ2bn8aObpd8SFAtdWUOpbSvJ8W8Pm84XHmweTwZAoGAJS9VcBRkmPBBNZLYkg1/ | |
83 Y2eEBK8XVRkF5NQW8AOlgyl+cIk2wBLi02QcyrJcz/iHGTSxOrZU/5vg1hqBtl5H | |
84 utqvmHSqS/f+HhkbE0+0hNRv51yox2jHwYjdb+xCdkn4JsvvDeSPfo8cplu59bP6 | |
85 g9eaw/tjq5zOxjpU7KyNb38CgYA4oDtsfFa36EVoAGb17wn0WM5vOuAII+bTJ+D/ | |
86 OzY4nFjMfcJwvp25w/P9tGoR2sVMYZVnlgki4bxTFcf0CUDyxX4ma3I+p41P/ugS | |
87 aZ9th4N1nMK5dLRp/sT66zD9WCnc2R4RNI1yRTTLvIn1+7oTxpicuR82rNH0iMrO | |
88 /GKkkQKBgF1Vh1ydmW6v5bd5Oyt8uYy/dI3ajZ+j0hcNuMO6qUdAXHfB1ZWLTnNL | |
89 yTHyMCVckB22+GdZKhrvLDy3XTTWx+JF5fVVIpiewuNRfLhEjh0uvbKzERQ7xPDB | |
90 T/YKqjp7uRICikPwvySruukdXDrxZpykOsusG0QbP2qemjfmM025 | |
91 -----END RSA PRIVATE KEY----- | |
92 */ | |
93 | 104 |
94 let data = "test"; | 105 it("Very Long Data", () => |
95 let publicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAy45IKQw0R5YBiIFyf
Kftx3F/6WsvtdNMnCKodkDemXuJOcFuOf/KeIjED/wW2DFG8qq72FAByUUFoTLcmawQZPd2htmHIk8Zk
BRsaQ8HzNoK+vg4wnI6yN/2lhSP27D4XpedG3mtbG8aYtMuqyQaxWHInSqiM4tqW/8coAPXrRTKYmsFf
AwPB1LCg5QI3vCy7Vdbbp907xOXON1+2seF9j8m9rh0sufXgGNWcvTNUvlf/TidSVjqxe6O3hG9jTOsw
C8/hez7rbiLroVNnCtIDrdX6OSM/je/XSMMnS5xpZBuqZGZtZm1Mr42omgst+KE+5dE6kyx76ra8LwsC
EShawIDAQAB"; | 106 { |
96 let signature = "UYTQmygOICKi4ozlMbLSYFZ1olovZZFYT0nZygPrGoA+6+ta+wzKnPnghK4j3
5QSucrf3yN8DSXa/kXBX0LcTmEaSwoNRuM7QPjT6v9hNsVjwNexOUk6pR3DotYuD1yV36sITNjx59McG
8/q6qLyj2A8KVlUbtnz/IiLzzw+wgy6WRjU1meYP8oiQGVIkB21ICqqaJ5kCvM0YrAqzQKAya513O51A
DA6aC/EMz6B62XGgZ+AywUMcH2Wvx7cyCvPVLfAbXcgex1JtpPS6vGcdpigaVQkoyl4cIQmX1ppasgJj
2MiYl2htXvFXjYoWniEmspteNu3UybB0nMHnYjKdQ=="; | 107 /* |
97 test.ok(verifySignature(publicKey, signature, data), "Correct signature"); | 108 -----BEGIN RSA PRIVATE KEY----- |
| 109 MIIBOQIBAAJBALZc50pEXnz9TSRozwM04rryuaXl/wgUFqV9FHq8HDlkdKvRU0hX |
| 110 hb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQJBALRxYs5irhgAz2b6afOj |
| 111 TcFr0PRtipckwW/IPw5euZKyvswEJt/tWDv4OdmDnRe8FSy6FG2Got3zxvaxYdc3 |
| 112 AXkCIQDfFGcytIVq3sbdF3lmhzcXf29R4Hrxg/eoByAKabxknwIhANFGSNMOGPt6 |
| 113 JRajfB9XmsltQJzbkr2sfHgjMN2FLM49AiAH6tt2yz1o+5snQawHXYkxBk7XIxZ5 |
| 114 9+sURZx3giUzlQIfXF+pxX9zh41i0ZtYLn181WxkGNjS7OY2CtF9wEoIfQIgcHuf |
| 115 shh1qrvuKiXnD9b72PF676laKdzxzX5rX6cZZLA= |
| 116 -----END RSA PRIVATE KEY----- |
| 117 */ |
98 | 118 |
99 test.ok(!verifySignature(publicKey, signature, data + "1"), "Wrong data"); | 119 let data = "foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob
arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar
foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo
obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob
arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar
foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo
obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob
arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar
foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo
obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob
arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar
foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo
obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob
arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar
foobarfoobar"; |
100 test.ok(!verifySignature(publicKey, signature, data.substring(0, 3)), "Wrong d
ata"); | 120 let publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALZc50pEXnz9TSRozwM04rryuaX
l/wgUFqV9FHq8HDlkdKvRU0hXhb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQ=="; |
101 test.ok(!verifySignature(publicKey, signature.substring(0, 5) + "0" + signatur
e.substring(6), data), "Wrong signature"); | 121 let signature = "L1LtPxp9VwL/ij8tuIxJqtx6mD3qoFhcEmPl8A1RlNeOP34A25nzyzRWuP2
wEbHcKKXnAQESdIXaTaEuymXviQ=="; |
102 test.ok(!verifySignature(publicKey.substring(0, 5) + "R" + publicKey.substring
(6), signature, data), "Wrong public key"); | 122 assert.ok(verifySignature(publicKey, signature, data), "Correct signature"); |
103 test.ok(!verifySignature(publicKey.substring(0, 70) + "8" + publicKey.substrin
g(71), signature, data), "Wrong public key"); | |
104 | 123 |
105 test.done(); | 124 assert.ok(!verifySignature(publicKey, signature, data + "1"), "Wrong data"); |
106 }; | 125 assert.ok(!verifySignature(publicKey, signature, data.substring(0, 3)), "Wro
ng data"); |
| 126 assert.ok(!verifySignature(publicKey, signature.substring(0, 5) + "0" + sign
ature.substring(6), data), "Wrong signature"); |
| 127 assert.ok(!verifySignature(publicKey.substring(0, 5) + "R" + publicKey.subst
ring(6), signature, data), "Wrong public key"); |
| 128 assert.ok(!verifySignature(publicKey.substring(0, 70) + "8" + publicKey.subs
tring(71), signature, data), "Wrong public key"); |
| 129 }); |
107 | 130 |
108 exports.testVeryLongData = function(test) | 131 it("Real Life Signature", () => |
109 { | 132 { |
110 /* | 133 let data = [ |
111 -----BEGIN RSA PRIVATE KEY----- | 134 "/info/Liquidit%C3%A4t.html?ses=Y3JlPTEzNTUyNDE2OTImdGNpZD13d3cuYWZmaWxpbm
V0LXZlcnplaWNobmlzLmRlNTBjNjAwNzIyNTlkNjQuNDA2MjE2MTImZmtpPTcyOTU2NiZ0YXNrPXNlYX
JjaCZkb21haW49YWZmaWxpbmV0LXZlcnplaWNobmlzLmRlJnM9ZGZmM2U5MTEzZGNhMWYyMWEwNDcmbG
FuZ3VhZ2U9ZGUmYV9pZD0yJmtleXdvcmQ9TGlxdWlkaXQlQzMlQTR0JnBvcz0yJmt3cz03Jmt3c2k9OA
==&token=AG06ipCV1LptGtY_9gFnr0vBTPy4O0YTvwoTCObJ3N3ckrQCFYIA3wod2TwAjxgAIABQv5W
iAlCH8qgOUJGr9g9QmuuEG1CDnK0pUPbRrk5QhqDgkQNxP4Qqhz9xZe4", |
112 MIIBOQIBAAJBALZc50pEXnz9TSRozwM04rryuaXl/wgUFqV9FHq8HDlkdKvRU0hX | 135 "www.affilinet-verzeichnis.de", |
113 hb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQJBALRxYs5irhgAz2b6afOj | 136 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.21 (KHTML, like Gecko) Ch
rome/25.0.1349.2 Safari/537.21" |
114 TcFr0PRtipckwW/IPw5euZKyvswEJt/tWDv4OdmDnRe8FSy6FG2Got3zxvaxYdc3 | 137 ]; |
115 AXkCIQDfFGcytIVq3sbdF3lmhzcXf29R4Hrxg/eoByAKabxknwIhANFGSNMOGPt6 | 138 let publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANnylWw2vLY4hUn9w06zQKbhKBf
vjFUCsdFlb6TdQhxb9RXWXuI4t31c+o8fYOv/s8q1LGPga3DE1L/tHU4LENMCAwEAAQ=="; |
116 JRajfB9XmsltQJzbkr2sfHgjMN2FLM49AiAH6tt2yz1o+5snQawHXYkxBk7XIxZ5 | 139 let signature = "nLH8Vbc1rzmy0Q+Xg+bvm43IEO42h8rq5D9C0WCn/Y3ykgAoV4npzm7eMlq
BSwZBLA/0DuuVsfTJT9MOVaurcA=="; |
117 9+sURZx3giUzlQIfXF+pxX9zh41i0ZtYLn181WxkGNjS7OY2CtF9wEoIfQIgcHuf | 140 assert.ok(verifySignature(publicKey, signature, data.join("\0")), "Correct s
ignature"); |
118 shh1qrvuKiXnD9b72PF676laKdzxzX5rX6cZZLA= | 141 }); |
119 -----END RSA PRIVATE KEY----- | 142 }); |
120 */ | |
121 | |
122 let data = "foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar
foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo
obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob
arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar
foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo
obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob
arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar
foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo
obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob
arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar
foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo
obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob
arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar
foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo
obarfoobar"; | |
123 let publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALZc50pEXnz9TSRozwM04rryuaXl/
wgUFqV9FHq8HDlkdKvRU0hXhb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQ=="; | |
124 let signature = "L1LtPxp9VwL/ij8tuIxJqtx6mD3qoFhcEmPl8A1RlNeOP34A25nzyzRWuP2wE
bHcKKXnAQESdIXaTaEuymXviQ=="; | |
125 test.ok(verifySignature(publicKey, signature, data), "Correct signature"); | |
126 | |
127 test.ok(!verifySignature(publicKey, signature, data + "1"), "Wrong data"); | |
128 test.ok(!verifySignature(publicKey, signature, data.substring(0, 3)), "Wrong d
ata"); | |
129 test.ok(!verifySignature(publicKey, signature.substring(0, 5) + "0" + signatur
e.substring(6), data), "Wrong signature"); | |
130 test.ok(!verifySignature(publicKey.substring(0, 5) + "R" + publicKey.substring
(6), signature, data), "Wrong public key"); | |
131 test.ok(!verifySignature(publicKey.substring(0, 70) + "8" + publicKey.substrin
g(71), signature, data), "Wrong public key"); | |
132 | |
133 test.done(); | |
134 }; | |
135 | |
136 exports.testRealLifeSignature = function(test) | |
137 { | |
138 let data = [ | |
139 "/info/Liquidit%C3%A4t.html?ses=Y3JlPTEzNTUyNDE2OTImdGNpZD13d3cuYWZmaWxpbmV0
LXZlcnplaWNobmlzLmRlNTBjNjAwNzIyNTlkNjQuNDA2MjE2MTImZmtpPTcyOTU2NiZ0YXNrPXNlYXJj
aCZkb21haW49YWZmaWxpbmV0LXZlcnplaWNobmlzLmRlJnM9ZGZmM2U5MTEzZGNhMWYyMWEwNDcmbGFu
Z3VhZ2U9ZGUmYV9pZD0yJmtleXdvcmQ9TGlxdWlkaXQlQzMlQTR0JnBvcz0yJmt3cz03Jmt3c2k9OA==
&token=AG06ipCV1LptGtY_9gFnr0vBTPy4O0YTvwoTCObJ3N3ckrQCFYIA3wod2TwAjxgAIABQv5WiA
lCH8qgOUJGr9g9QmuuEG1CDnK0pUPbRrk5QhqDgkQNxP4Qqhz9xZe4", | |
140 "www.affilinet-verzeichnis.de", | |
141 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.21 (KHTML, like Gecko) Chro
me/25.0.1349.2 Safari/537.21" | |
142 ]; | |
143 let publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANnylWw2vLY4hUn9w06zQKbhKBfvj
FUCsdFlb6TdQhxb9RXWXuI4t31c+o8fYOv/s8q1LGPga3DE1L/tHU4LENMCAwEAAQ=="; | |
144 let signature = "nLH8Vbc1rzmy0Q+Xg+bvm43IEO42h8rq5D9C0WCn/Y3ykgAoV4npzm7eMlqBS
wZBLA/0DuuVsfTJT9MOVaurcA=="; | |
145 test.ok(verifySignature(publicKey, signature, data.join("\0")), "Correct signa
ture"); | |
146 | |
147 test.done(); | |
148 }; | |
OLD | NEW |