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

Delta Between Two Patch Sets: lib/rsa.js

Issue 29354773: Issue 4465 - Move rsa module from adblockpluschrome (Closed)
Left Patch Set: Add unit tests Created Sept. 23, 2016, 1:45 p.m.
Right Patch Set: Add btoa and navigator stub Created Sept. 25, 2016, 1:17 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 | « lib/jsbn.js ('k') | lib/rusha.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
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;
LEFTRIGHT

Powered by Google App Engine
This is Rietveld