From d705da741cbd971c44d1a61ef3e2121349984cd8 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Mon, 30 May 2016 10:31:57 +0300 Subject: [PATCH] fix masternode signatures, bump PROTOCOL_VERSION MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit strMessage for masternode broadcast (which we sign and verify) looks like this currently: [2001:1608:45:3::242:ac11:6]:199991464464536 ?~}&?Q?S?Ǚ?q ?0??????O?I/Y?( ?f?jJF??m??bssknN??9鲜JXVs?ә?5T?8??????~70200 which I believe in some cases leads to "Got bad Masternode ping signature" errors and banning. I propose to change the way strMessage is composed so that it looks like this: [2002:82ff:c04:2:a90f:2261:43c4:2745]:1999514645552319591ec70225aacadfafa4ab5d21e87cdce641fd4030d029485434533c5e481578a9d471089fb5ec170200 Further more nDos for old masternodes is set to 0 to stop false positives (message still gets rejected though). --- src/masternode.cpp | 44 ++++++++++++++++++++++++++++++++------------ src/version.h | 2 +- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/masternode.cpp b/src/masternode.cpp index d281593e74..e17cf90fdb 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -370,9 +370,16 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos) if(lastPing == CMasternodePing() || !lastPing.CheckAndUpdate(nDos, false, true)) return false; - std::string vchPubKey(pubkey.begin(), pubkey.end()); - std::string vchPubKey2(pubkey2.begin(), pubkey2.end()); - std::string strMessage = addr.ToString() + boost::lexical_cast(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast(protocolVersion); + std::string strMessage; + if(protocolVersion < 70201) { + std::string vchPubKey(pubkey.begin(), pubkey.end()); + std::string vchPubKey2(pubkey2.begin(), pubkey2.end()); + strMessage = addr.ToString() + boost::lexical_cast(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast(protocolVersion); + } else { + strMessage = addr.ToString() + boost::lexical_cast(sigTime) + + pubkey.GetID().ToString() + pubkey2.GetID().ToString() + + boost::lexical_cast(protocolVersion); + } if(protocolVersion < mnpayments.GetMinMasternodePaymentsProto()) { LogPrintf("CMasternodeBroadcast::CheckAndUpdate - ignoring outdated Masternode %s protocol version %d\n", vin.ToString(), protocolVersion); @@ -405,7 +412,8 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos) std::string errorMessage = ""; if(!darkSendSigner.VerifyMessage(pubkey, vchSig, strMessage, errorMessage)){ LogPrintf("CMasternodeBroadcast::CheckAndUpdate - Got bad Masternode address signature\n"); - nDos = 100; + // don't ban for old masternodes, their sigs could be broken because of the bug + nDos = protocolVersion < 70201 ? 0 : 100; return false; } @@ -567,12 +575,18 @@ bool CMasternodeBroadcast::Sign(CKey& keyCollateralAddress) { std::string errorMessage; - std::string vchPubKey(pubkey.begin(), pubkey.end()); - std::string vchPubKey2(pubkey2.begin(), pubkey2.end()); - sigTime = GetAdjustedTime(); - std::string strMessage = addr.ToString() + boost::lexical_cast(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast(protocolVersion); + std::string strMessage; + if(protocolVersion < 70201) { + std::string vchPubKey(pubkey.begin(), pubkey.end()); + std::string vchPubKey2(pubkey2.begin(), pubkey2.end()); + strMessage = addr.ToString() + boost::lexical_cast(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast(protocolVersion); + } else { + strMessage = addr.ToString() + boost::lexical_cast(sigTime) + + pubkey.GetID().ToString() + pubkey2.GetID().ToString() + + boost::lexical_cast(protocolVersion); + } if(!darkSendSigner.SignMessage(strMessage, errorMessage, vchSig, keyCollateralAddress)) { LogPrintf("CMasternodeBroadcast::Sign() - Error: %s\n", errorMessage); @@ -586,10 +600,16 @@ bool CMasternodeBroadcast::VerifySignature() { std::string errorMessage; - std::string vchPubKey(pubkey.begin(), pubkey.end()); - std::string vchPubKey2(pubkey2.begin(), pubkey2.end()); - - std::string strMessage = addr.ToString() + boost::lexical_cast(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast(protocolVersion); + std::string strMessage; + if(protocolVersion < 70201) { + std::string vchPubKey(pubkey.begin(), pubkey.end()); + std::string vchPubKey2(pubkey2.begin(), pubkey2.end()); + strMessage = addr.ToString() + boost::lexical_cast(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast(protocolVersion); + } else { + strMessage = addr.ToString() + boost::lexical_cast(sigTime) + + pubkey.GetID().ToString() + pubkey2.GetID().ToString() + + boost::lexical_cast(protocolVersion); + } if(!darkSendSigner.VerifyMessage(pubkey, vchSig, strMessage, errorMessage)) { LogPrintf("CMasternodeBroadcast::VerifySignature() - Error: %s\n", errorMessage); diff --git a/src/version.h b/src/version.h index 266b0f6d6e..99cfee0d82 100644 --- a/src/version.h +++ b/src/version.h @@ -10,7 +10,7 @@ * network protocol versioning */ -static const int PROTOCOL_VERSION = 70200; +static const int PROTOCOL_VERSION = 70201; //! initial proto version, to be increased after version/verack negotiation static const int INIT_PROTO_VERSION = 209;