fix masternode signatures, bump PROTOCOL_VERSION

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).
This commit is contained in:
UdjinM6 2016-05-30 10:31:57 +03:00
parent 4d55bc9666
commit d705da741c
2 changed files with 33 additions and 13 deletions

View File

@ -370,9 +370,16 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos)
if(lastPing == CMasternodePing() || !lastPing.CheckAndUpdate(nDos, false, true)) if(lastPing == CMasternodePing() || !lastPing.CheckAndUpdate(nDos, false, true))
return false; return false;
std::string strMessage;
if(protocolVersion < 70201) {
std::string vchPubKey(pubkey.begin(), pubkey.end()); std::string vchPubKey(pubkey.begin(), pubkey.end());
std::string vchPubKey2(pubkey2.begin(), pubkey2.end()); std::string vchPubKey2(pubkey2.begin(), pubkey2.end());
std::string strMessage = addr.ToString() + boost::lexical_cast<std::string>(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(protocolVersion); strMessage = addr.ToString() + boost::lexical_cast<std::string>(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(protocolVersion);
} else {
strMessage = addr.ToString() + boost::lexical_cast<std::string>(sigTime) +
pubkey.GetID().ToString() + pubkey2.GetID().ToString() +
boost::lexical_cast<std::string>(protocolVersion);
}
if(protocolVersion < mnpayments.GetMinMasternodePaymentsProto()) { if(protocolVersion < mnpayments.GetMinMasternodePaymentsProto()) {
LogPrintf("CMasternodeBroadcast::CheckAndUpdate - ignoring outdated Masternode %s protocol version %d\n", vin.ToString(), protocolVersion); 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 = ""; std::string errorMessage = "";
if(!darkSendSigner.VerifyMessage(pubkey, vchSig, strMessage, errorMessage)){ if(!darkSendSigner.VerifyMessage(pubkey, vchSig, strMessage, errorMessage)){
LogPrintf("CMasternodeBroadcast::CheckAndUpdate - Got bad Masternode address signature\n"); 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; return false;
} }
@ -567,12 +575,18 @@ bool CMasternodeBroadcast::Sign(CKey& keyCollateralAddress)
{ {
std::string errorMessage; std::string errorMessage;
std::string vchPubKey(pubkey.begin(), pubkey.end());
std::string vchPubKey2(pubkey2.begin(), pubkey2.end());
sigTime = GetAdjustedTime(); sigTime = GetAdjustedTime();
std::string strMessage = addr.ToString() + boost::lexical_cast<std::string>(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(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<std::string>(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(protocolVersion);
} else {
strMessage = addr.ToString() + boost::lexical_cast<std::string>(sigTime) +
pubkey.GetID().ToString() + pubkey2.GetID().ToString() +
boost::lexical_cast<std::string>(protocolVersion);
}
if(!darkSendSigner.SignMessage(strMessage, errorMessage, vchSig, keyCollateralAddress)) { if(!darkSendSigner.SignMessage(strMessage, errorMessage, vchSig, keyCollateralAddress)) {
LogPrintf("CMasternodeBroadcast::Sign() - Error: %s\n", errorMessage); LogPrintf("CMasternodeBroadcast::Sign() - Error: %s\n", errorMessage);
@ -586,10 +600,16 @@ bool CMasternodeBroadcast::VerifySignature()
{ {
std::string errorMessage; std::string errorMessage;
std::string strMessage;
if(protocolVersion < 70201) {
std::string vchPubKey(pubkey.begin(), pubkey.end()); std::string vchPubKey(pubkey.begin(), pubkey.end());
std::string vchPubKey2(pubkey2.begin(), pubkey2.end()); std::string vchPubKey2(pubkey2.begin(), pubkey2.end());
strMessage = addr.ToString() + boost::lexical_cast<std::string>(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(protocolVersion);
std::string strMessage = addr.ToString() + boost::lexical_cast<std::string>(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(protocolVersion); } else {
strMessage = addr.ToString() + boost::lexical_cast<std::string>(sigTime) +
pubkey.GetID().ToString() + pubkey2.GetID().ToString() +
boost::lexical_cast<std::string>(protocolVersion);
}
if(!darkSendSigner.VerifyMessage(pubkey, vchSig, strMessage, errorMessage)) { if(!darkSendSigner.VerifyMessage(pubkey, vchSig, strMessage, errorMessage)) {
LogPrintf("CMasternodeBroadcast::VerifySignature() - Error: %s\n", errorMessage); LogPrintf("CMasternodeBroadcast::VerifySignature() - Error: %s\n", errorMessage);

View File

@ -10,7 +10,7 @@
* network protocol versioning * 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 //! initial proto version, to be increased after version/verack negotiation
static const int INIT_PROTO_VERSION = 209; static const int INIT_PROTO_VERSION = 209;