| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 /** | 18 /** |
| 19 * This is a specialized RSA library meant only to verify SHA1-based signatures. | 19 * This is a specialized RSA library meant only to verify SHA1-based signatures. |
| 20 */ | 20 */ |
| 21 | 21 |
| 22 let {BigInteger} = require("jsbn"); | 22 let {BigInteger} = require("jsbn"); |
| 23 let Rusha = require("rusha"); | 23 let Rusha = require("rusha"); |
| 24 | 24 |
| 25 let rusha = new Rusha(); | 25 let rusha = new Rusha(); |
| 26 | |
| 27 // Node.Js does not include atob, but we can make use of Buffer | |
| 28 if (typeof atob == "undefined" && typeof Buffer != "undefined") | |
| 29 global.atob = data => new Buffer(data, "base64").toString("binary"); | |
|
kzar
2016/09/23 13:48:45
If I simply did `var atob = ...` here the tests br
Wladimir Palant
2016/09/23 20:02:29
atob() is defined on the window object, and Node d
kzar
2016/09/25 12:46:47
Good point. I already did a bunch of similar work[
Wladimir Palant
2016/09/25 13:02:28
sandboxed-module seems to be a cleaner solution to
| |
| 30 | 26 |
| 31 // Define ASN.1 templates for the data structures used | 27 // Define ASN.1 templates for the data structures used |
| 32 function seq() | 28 function seq() |
| 33 { | 29 { |
| 34 return {type: 0x30, children: Array.prototype.slice.call(arguments)}; | 30 return {type: 0x30, children: Array.prototype.slice.call(arguments)}; |
| 35 } | 31 } |
| 36 function obj(id) | 32 function obj(id) |
| 37 { | 33 { |
| 38 return {type: 0x06, content: id}; | 34 return {type: 0x06, content: id}; |
| 39 } | 35 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 var expected = new BigInteger(rusha.digest(data), 16); | 182 var expected = new BigInteger(rusha.digest(data), 16); |
| 187 return (sha1.compareTo(expected) == 0); | 183 return (sha1.compareTo(expected) == 0); |
| 188 } | 184 } |
| 189 catch (e) | 185 catch (e) |
| 190 { | 186 { |
| 191 console.log("Invalid encrypted signature: " + e); | 187 console.log("Invalid encrypted signature: " + e); |
| 192 return false; | 188 return false; |
| 193 } | 189 } |
| 194 } | 190 } |
| 195 exports.verifySignature = verifySignature; | 191 exports.verifySignature = verifySignature; |
| LEFT | RIGHT |