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 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 } | 97 } |
98 return len; | 98 return len; |
99 } | 99 } |
100 | 100 |
101 function readNode(curTempl) | 101 function readNode(curTempl) |
102 { | 102 { |
103 let type = next(); | 103 let type = next(); |
104 let len = readLength(); | 104 let len = readLength(); |
105 if ("type" in curTempl && curTempl.type != type) | 105 if ("type" in curTempl && curTempl.type != type) |
106 throw "Unexpected type"; | 106 throw "Unexpected type"; |
107 if ("content" in curTempl && curTempl.content != data.substr(pos, len)) | 107 if ("content" in curTempl && |
| 108 curTempl.content != data.substring(pos, pos + len)) |
| 109 { |
108 throw "Unexpected content"; | 110 throw "Unexpected content"; |
| 111 } |
109 if ("out" in curTempl) | 112 if ("out" in curTempl) |
110 out[curTempl.out] = new BigInteger(data.substr(pos, len), 256); | 113 out[curTempl.out] = new BigInteger(data.substring(pos, pos + len), 256); |
111 if ("children" in curTempl) | 114 if ("children" in curTempl) |
112 { | 115 { |
113 let i; | 116 let i; |
114 let end; | 117 let end; |
115 for (i = 0, end = pos + len; pos < end; i++) | 118 for (i = 0, end = pos + len; pos < end; i++) |
116 { | 119 { |
117 if (i >= curTempl.children.length) | 120 if (i >= curTempl.children.length) |
118 throw "Too many children"; | 121 throw "Too many children"; |
119 readNode(curTempl.children[i]); | 122 readNode(curTempl.children[i]); |
120 } | 123 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 189 |
187 // Skip padding, see http://tools.ietf.org/html/rfc3447#section-9.2 step 5 | 190 // Skip padding, see http://tools.ietf.org/html/rfc3447#section-9.2 step 5 |
188 if (next() != 1) | 191 if (next() != 1) |
189 throw "Wrong padding in signature digest"; | 192 throw "Wrong padding in signature digest"; |
190 while (next() == 255) {} | 193 while (next() == 255) {} |
191 if (digest.charCodeAt(pos - 1) != 0) | 194 if (digest.charCodeAt(pos - 1) != 0) |
192 throw "Wrong padding in signature digest"; | 195 throw "Wrong padding in signature digest"; |
193 | 196 |
194 // Rest is an ASN.1 structure, get the SHA1 hash from it and compare to | 197 // Rest is an ASN.1 structure, get the SHA1 hash from it and compare to |
195 // the real one | 198 // the real one |
196 let {sha1} = readASN1(digest.substr(pos), signatureTemplate); | 199 let {sha1} = readASN1(digest.substring(pos), signatureTemplate); |
197 let expected = new BigInteger(rusha.digest(data), 16); | 200 let expected = new BigInteger(rusha.digest(data), 16); |
198 return (sha1.compareTo(expected) == 0); | 201 return (sha1.compareTo(expected) == 0); |
199 } | 202 } |
200 catch (e) | 203 catch (e) |
201 { | 204 { |
202 console.warn("Invalid encrypted signature: " + e); | 205 console.warn("Invalid encrypted signature: " + e); |
203 return false; | 206 return false; |
204 } | 207 } |
205 } | 208 } |
206 exports.verifySignature = verifySignature; | 209 exports.verifySignature = verifySignature; |
OLD | NEW |