Index: test/signatures.js |
=================================================================== |
--- a/test/signatures.js |
+++ b/test/signatures.js |
@@ -12,17 +12,17 @@ |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
*/ |
"use strict"; |
-const {createSandbox} = require("./_common"); |
+const {createSandbox, silenceWarnOutput} = require("./_common"); |
let verifySignature = null; |
exports.setUp = function(callback) |
{ |
let sandboxedRequire = createSandbox(); |
( |
{verifySignature} = sandboxedRequire("../lib/rsa") |
@@ -47,19 +47,28 @@ |
let data = "test"; |
let publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALZc50pEXnz9TSRozwM04rryuaXl/wgUFqV9FHq8HDlkdKvRU0hXhb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQ=="; |
let signature = "LzKJE1BOsZDfwD/hncHq+MN5ZygIemb1Pyzx40rm3CoTL4CVPAicS1mOiTv6s9Li9Vw1ds9HwFWVMFVEwHwfIw=="; |
test.ok(verifySignature(publicKey, signature, data), "Correct signature"); |
test.ok(!verifySignature(publicKey, signature, data + "1"), "Wrong data"); |
test.ok(!verifySignature(publicKey, signature, data.substr(0, 3)), "Wrong data"); |
- test.ok(!verifySignature(publicKey, signature.substr(0, 5) + "0" + signature.substr(6), data), "Wrong signature"); |
- test.ok(!verifySignature(publicKey.substr(0, 5) + "R" + publicKey.substr(6), signature, data), "Wrong public key"); |
- test.ok(!verifySignature(publicKey.substr(0, 70) + "8" + publicKey.substr(71), signature, data), "Wrong public key"); |
+ test.ok(!silenceWarnOutput( |
+ () => verifySignature(publicKey, signature.substr(0, 5) + "0" + signature.substr(6), data), |
+ "Invalid encrypted signature: Wrong padding in signature digest" |
+ ), "Wrong signature"); |
+ test.ok(!silenceWarnOutput( |
+ () => verifySignature(publicKey.substr(0, 5) + "R" + publicKey.substr(6), signature, data), |
+ "Invalid RSA public key: Unexpected type" |
+ ), "Wrong public key"); |
+ test.ok(!silenceWarnOutput( |
+ () => verifySignature(publicKey.substr(0, 70) + "8" + publicKey.substr(71), signature, data), |
+ "Invalid encrypted signature: Wrong padding in signature digest" |
+ ), "Wrong public key"); |
test.done(); |
}; |
exports.test2048bitSigningKey = function(test) |
{ |
/* |
-----BEGIN RSA PRIVATE KEY----- |
@@ -93,19 +102,28 @@ |
let data = "test"; |
let publicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAy45IKQw0R5YBiIFyfKftx3F/6WsvtdNMnCKodkDemXuJOcFuOf/KeIjED/wW2DFG8qq72FAByUUFoTLcmawQZPd2htmHIk8ZkBRsaQ8HzNoK+vg4wnI6yN/2lhSP27D4XpedG3mtbG8aYtMuqyQaxWHInSqiM4tqW/8coAPXrRTKYmsFfAwPB1LCg5QI3vCy7Vdbbp907xOXON1+2seF9j8m9rh0sufXgGNWcvTNUvlf/TidSVjqxe6O3hG9jTOswC8/hez7rbiLroVNnCtIDrdX6OSM/je/XSMMnS5xpZBuqZGZtZm1Mr42omgst+KE+5dE6kyx76ra8LwsCEShawIDAQAB"; |
let signature = "UYTQmygOICKi4ozlMbLSYFZ1olovZZFYT0nZygPrGoA+6+ta+wzKnPnghK4j35QSucrf3yN8DSXa/kXBX0LcTmEaSwoNRuM7QPjT6v9hNsVjwNexOUk6pR3DotYuD1yV36sITNjx59McG8/q6qLyj2A8KVlUbtnz/IiLzzw+wgy6WRjU1meYP8oiQGVIkB21ICqqaJ5kCvM0YrAqzQKAya513O51ADA6aC/EMz6B62XGgZ+AywUMcH2Wvx7cyCvPVLfAbXcgex1JtpPS6vGcdpigaVQkoyl4cIQmX1ppasgJj2MiYl2htXvFXjYoWniEmspteNu3UybB0nMHnYjKdQ=="; |
test.ok(verifySignature(publicKey, signature, data), "Correct signature"); |
test.ok(!verifySignature(publicKey, signature, data + "1"), "Wrong data"); |
test.ok(!verifySignature(publicKey, signature, data.substr(0, 3)), "Wrong data"); |
- test.ok(!verifySignature(publicKey, signature.substr(0, 5) + "0" + signature.substr(6), data), "Wrong signature"); |
- test.ok(!verifySignature(publicKey.substr(0, 5) + "R" + publicKey.substr(6), signature, data), "Wrong public key"); |
- test.ok(!verifySignature(publicKey.substr(0, 70) + "8" + publicKey.substr(71), signature, data), "Wrong public key"); |
+ test.ok(!silenceWarnOutput( |
+ () => verifySignature(publicKey, signature.substr(0, 5) + "0" + signature.substr(6), data), |
+ "Invalid encrypted signature: Wrong padding in signature digest" |
+ ), "Wrong signature"); |
+ test.ok(!silenceWarnOutput( |
+ () => verifySignature(publicKey.substr(0, 5) + "R" + publicKey.substr(6), signature, data), |
+ "Invalid RSA public key: Unexpected type" |
+ ), "Wrong public key"); |
+ test.ok(!silenceWarnOutput( |
+ () => verifySignature(publicKey.substr(0, 70) + "8" + publicKey.substr(71), signature, data), |
+ "Invalid encrypted signature: Wrong padding in signature digest" |
+ ), "Wrong public key"); |
test.done(); |
}; |
exports.testVeryLongData = function(test) |
{ |
/* |
-----BEGIN RSA PRIVATE KEY----- |
@@ -121,19 +139,28 @@ |
let data = "foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar"; |
let publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALZc50pEXnz9TSRozwM04rryuaXl/wgUFqV9FHq8HDlkdKvRU0hXhb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQ=="; |
let signature = "L1LtPxp9VwL/ij8tuIxJqtx6mD3qoFhcEmPl8A1RlNeOP34A25nzyzRWuP2wEbHcKKXnAQESdIXaTaEuymXviQ=="; |
test.ok(verifySignature(publicKey, signature, data), "Correct signature"); |
test.ok(!verifySignature(publicKey, signature, data + "1"), "Wrong data"); |
test.ok(!verifySignature(publicKey, signature, data.substr(0, 3)), "Wrong data"); |
- test.ok(!verifySignature(publicKey, signature.substr(0, 5) + "0" + signature.substr(6), data), "Wrong signature"); |
- test.ok(!verifySignature(publicKey.substr(0, 5) + "R" + publicKey.substr(6), signature, data), "Wrong public key"); |
- test.ok(!verifySignature(publicKey.substr(0, 70) + "8" + publicKey.substr(71), signature, data), "Wrong public key"); |
+ test.ok(!silenceWarnOutput( |
+ () => verifySignature(publicKey, signature.substr(0, 5) + "0" + signature.substr(6), data), |
+ "Invalid encrypted signature: Wrong padding in signature digest" |
+ ), "Wrong signature"); |
+ test.ok(!silenceWarnOutput( |
+ () => verifySignature(publicKey.substr(0, 5) + "R" + publicKey.substr(6), signature, data), |
+ "Invalid RSA public key: Unexpected type" |
+ ), "Wrong public key"); |
+ test.ok(!silenceWarnOutput( |
+ () => verifySignature(publicKey.substr(0, 70) + "8" + publicKey.substr(71), signature, data), |
+ "Invalid encrypted signature: Wrong padding in signature digest" |
+ ), "Wrong public key"); |
test.done(); |
}; |
exports.testRealLifeSignature = function(test) |
{ |
let data = [ |
"/info/Liquidit%C3%A4t.html?ses=Y3JlPTEzNTUyNDE2OTImdGNpZD13d3cuYWZmaWxpbmV0LXZlcnplaWNobmlzLmRlNTBjNjAwNzIyNTlkNjQuNDA2MjE2MTImZmtpPTcyOTU2NiZ0YXNrPXNlYXJjaCZkb21haW49YWZmaWxpbmV0LXZlcnplaWNobmlzLmRlJnM9ZGZmM2U5MTEzZGNhMWYyMWEwNDcmbGFuZ3VhZ2U9ZGUmYV9pZD0yJmtleXdvcmQ9TGlxdWlkaXQlQzMlQTR0JnBvcz0yJmt3cz03Jmt3c2k9OA==&token=AG06ipCV1LptGtY_9gFnr0vBTPy4O0YTvwoTCObJ3N3ckrQCFYIA3wod2TwAjxgAIABQv5WiAlCH8qgOUJGr9g9QmuuEG1CDnK0pUPbRrk5QhqDgkQNxP4Qqhz9xZe4", |