diff --git a/app/lib/blockGenerator.js b/app/lib/blockGenerator.js index 790f1d26d6658f53fd9d74383179f43e1878ddd7..aff6f30b032e90243ea7e1c4aec95aaa802b3b9b 100644 --- a/app/lib/blockGenerator.js +++ b/app/lib/blockGenerator.js @@ -11,6 +11,7 @@ var constants = require('./constants'); var base58 = require('./base58'); var rules = require('./rules'); var signature = require('./signature'); +var crypto = require('./crypto'); var Identity = require('./entity/identity'); var Certification = require('./entity/certification'); var Membership = require('./entity/membership'); @@ -461,6 +462,13 @@ function BlockGenerator(mainContext, prover) { throw 'Too old identity'; } } + let idty = new Identity(identity); + idty.currency = conf.currency; + let selfCert = idty.rawWithoutSig(); + let verified = crypto.verify(selfCert, idty.sig, idty.pubkey); + if (!verified) { + throw constants.ERRORS.IDENTITY_WRONGLY_SIGNED; + } if (!identity.leaving) { if (!current) { // Look for certifications from initial joiners diff --git a/app/lib/constants.js b/app/lib/constants.js index a3a3a5b3a4c2bd7da67669d7ccc7e37c3f1e9539..bc8c2e77f30aedb119b8a87e025d76aefa671c6d 100644 --- a/app/lib/constants.js +++ b/app/lib/constants.js @@ -84,7 +84,8 @@ module.exports = { SOURCE_ALREADY_CONSUMED: { httpCode: 400, uerr: { ucode: 2015, message: "Source already consumed" }}, WRONG_AMOUNTS: { httpCode: 400, uerr: { ucode: 2016, message: "Sum of inputs must equal sum of outputs" }}, WRONG_OUTPUT_BASE: { httpCode: 400, uerr: { ucode: 2017, message: "Wrong unit base for outputs" }}, - CANNOT_ROOT_BLOCK_NO_MEMBERS: { httpCode: 400, uerr: { ucode: 2018, message: "Wrong new block: cannot make a root block without members" }} + CANNOT_ROOT_BLOCK_NO_MEMBERS: { httpCode: 400, uerr: { ucode: 2018, message: "Wrong new block: cannot make a root block without members" }}, + IDENTITY_WRONGLY_SIGNED: { httpCode: 400, uerr: { ucode: 2019, message: "Weird, the signature is wrong and in the database." }} }, DEBUG: {