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 |
| 18 /* global console */ |
17 | 19 |
18 "use strict"; | 20 "use strict"; |
19 | 21 |
20 /** | 22 /** |
21 * This is a specialized RSA library meant only to verify SHA1-based signatures. | 23 * This is a specialized RSA library meant only to verify SHA1-based signatures. |
22 */ | 24 */ |
23 | 25 |
24 const {BigInteger} = require("jsbn"); | 26 const {BigInteger} = require("jsbn"); |
25 const Rusha = require("rusha"); | 27 const Rusha = require("rusha"); |
26 | 28 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 readNode(templ); | 137 readNode(templ); |
136 if (pos != data.length) | 138 if (pos != data.length) |
137 throw "Too much data"; | 139 throw "Too much data"; |
138 return out; | 140 return out; |
139 } | 141 } |
140 | 142 |
141 /** | 143 /** |
142 * Reads a BER-encoded RSA public key. On success returns an object with the | 144 * Reads a BER-encoded RSA public key. On success returns an object with the |
143 * properties n and e (the components of the key), otherwise null. | 145 * properties n and e (the components of the key), otherwise null. |
144 * @param {string} key | 146 * @param {string} key |
145 * @return {Object|null} | 147 * @return {?Object} |
146 */ | 148 */ |
147 function readPublicKey(key) | 149 function readPublicKey(key) |
148 { | 150 { |
149 try | 151 try |
150 { | 152 { |
151 return readASN1(atob(key), publicKeyTemplate); | 153 return readASN1(atob(key), publicKeyTemplate); |
152 } | 154 } |
153 catch (e) | 155 catch (e) |
154 { | 156 { |
155 console.warn("Invalid RSA public key: " + e); | 157 console.warn("Invalid RSA public key: " + e); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 let expected = new BigInteger(rusha.digest(data), 16); | 197 let expected = new BigInteger(rusha.digest(data), 16); |
196 return (sha1.compareTo(expected) == 0); | 198 return (sha1.compareTo(expected) == 0); |
197 } | 199 } |
198 catch (e) | 200 catch (e) |
199 { | 201 { |
200 console.warn("Invalid encrypted signature: " + e); | 202 console.warn("Invalid encrypted signature: " + e); |
201 return false; | 203 return false; |
202 } | 204 } |
203 } | 205 } |
204 exports.verifySignature = verifySignature; | 206 exports.verifySignature = verifySignature; |
LEFT | RIGHT |