From 004da827ce1ef8a044ddd59b32eaeefc11c92482 Mon Sep 17 00:00:00 2001
From: cgeek <cem.moreau@gmail.com>
Date: Fri, 3 Jun 2016 16:29:41 +0200
Subject: [PATCH] Fixing #471 Blockchain generation is no more stuck by wrongly
 signed identities

---
 app/lib/blockGenerator.js | 8 ++++++++
 app/lib/constants.js      | 3 ++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/app/lib/blockGenerator.js b/app/lib/blockGenerator.js
index 790f1d26d..aff6f30b0 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 a3a3a5b3a..bc8c2e77f 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: {
-- 
GitLab