LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of the Adblock Plus extension, | 2 * This file is part of the Adblock Plus extension, |
3 * Copyright (C) 2006-2012 Eyeo GmbH | 3 * Copyright (C) 2006-2012 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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 return digest.charCodeAt(pos++); | 168 return digest.charCodeAt(pos++); |
169 } | 169 } |
170 | 170 |
171 // Skip padding, see http://tools.ietf.org/html/rfc3447#section-9.2 step 5 | 171 // Skip padding, see http://tools.ietf.org/html/rfc3447#section-9.2 step 5 |
172 if (next() != 1) | 172 if (next() != 1) |
173 throw "Wrong padding in signature digest"; | 173 throw "Wrong padding in signature digest"; |
174 while (next() == 255) {} | 174 while (next() == 255) {} |
175 if (digest.charCodeAt(pos - 1) != 0) | 175 if (digest.charCodeAt(pos - 1) != 0) |
176 throw "Wrong padding in signature digest"; | 176 throw "Wrong padding in signature digest"; |
177 | 177 |
178 // Rest is an ASN.1 structure, get the SHA1 hash from it | 178 // Rest is an ASN.1 structure, get the SHA1 hash from it and compare to |
179 var sha1 = readASN1(digest.substr(pos), signatureTemplate).sha1.toString(1
6); | 179 // the real one |
180 while (sha1.length < 40) | 180 var sha1 = readASN1(digest.substr(pos), signatureTemplate).sha1; |
181 sha1 = "0" + sha1; // Zero-pad to the right length | 181 var expected = new BigInteger(SHA1(data), 16); |
182 return (sha1 == SHA1(data)); | 182 return (sha1.compareTo(expected) == 0); |
183 } | 183 } |
184 catch (e) | 184 catch (e) |
185 { | 185 { |
186 console.log("Invalid encrypted signature: " + e); | 186 console.log("Invalid encrypted signature: " + e); |
187 return false; | 187 return false; |
188 } | 188 } |
189 } | 189 } |
190 | 190 |
191 // Export verifySignature function, everything else is private. | 191 // Export verifySignature function, everything else is private. |
192 globalObj.verifySignature = verifySignature; | 192 globalObj.verifySignature = verifySignature; |
193 })(this); | 193 })(this); |
LEFT | RIGHT |