More compatibility for old ipv6 - try old format ipv6 if new format failed, sanitize log strings

This commit is contained in:
UdjinM6 2016-06-03 01:19:49 +03:00
parent 00540c868f
commit 6ef9f5dd84

View File

@ -339,6 +339,8 @@ CMasternodeBroadcast::CMasternodeBroadcast(const CMasternode& mn)
bool CMasternodeBroadcast::CheckAndUpdate(int& nDos) bool CMasternodeBroadcast::CheckAndUpdate(int& nDos)
{ {
nDos = 0;
// make sure signature isn't in the future (past is OK) // make sure signature isn't in the future (past is OK)
if (sigTime > GetAdjustedTime() + 60 * 60) { if (sigTime > GetAdjustedTime() + 60 * 60) {
LogPrintf("mnb - Signature rejected, too far into the future %s\n", vin.ToString()); LogPrintf("mnb - Signature rejected, too far into the future %s\n", vin.ToString());
@ -375,23 +377,55 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos)
} }
std::string strMessage; std::string strMessage;
std::string errorMessage = "";
if(protocolVersion < 70201) { 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(false) + boost::lexical_cast<std::string>(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(protocolVersion); strMessage = addr.ToString(false) + boost::lexical_cast<std::string>(sigTime) +
vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(protocolVersion);
LogPrint("masternode", "mnb - sanitized strMessage: %s, pubkey address: %s, sig: %s\n",
SanitizeString(strMessage), CBitcoinAddress(pubkey.GetID()).ToString(),
EncodeBase64(&sig[0], sig.size()));
if(!darkSendSigner.VerifyMessage(pubkey, sig, strMessage, errorMessage)){
if (addr.ToString() != addr.ToString(false))
{
// maybe it's wrong format, try again with the old one
strMessage = addr.ToString() + boost::lexical_cast<std::string>(sigTime) +
vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(protocolVersion);
LogPrint("masternode", "mnb - sanitized strMessage: %s, pubkey address: %s, sig: %s\n",
SanitizeString(strMessage), CBitcoinAddress(pubkey.GetID()).ToString(),
EncodeBase64(&sig[0], sig.size()));
if(!darkSendSigner.VerifyMessage(pubkey, sig, strMessage, errorMessage)){
// didn't work either
LogPrintf("mnb - Got bad Masternode address signature, sanitized error: %s\n", SanitizeString(errorMessage));
// there is a bug in old MN signatures, ignore such MN but do not ban the peer we got this from
return false;
}
} else {
// nope, sig is actually wrong
LogPrintf("mnb - Got bad Masternode address signature, sanitized error: %s\n", SanitizeString(errorMessage));
// there is a bug in old MN signatures, ignore such MN but do not ban the peer we got this from
return false;
}
}
} else { } else {
strMessage = addr.ToString(false) + boost::lexical_cast<std::string>(sigTime) + strMessage = addr.ToString(false) + boost::lexical_cast<std::string>(sigTime) +
pubkey.GetID().ToString() + pubkey2.GetID().ToString() + pubkey.GetID().ToString() + pubkey2.GetID().ToString() +
boost::lexical_cast<std::string>(protocolVersion); boost::lexical_cast<std::string>(protocolVersion);
}
std::string errorMessage = ""; LogPrint("masternode", "mnb - strMessage: %s, pubkey address: %s, sig: %s\n",
LogPrint("masternode", "mnb - strMessage: %s, pubkey address: %s, sig: %s\n", strMessage, CBitcoinAddress(pubkey.GetID()).ToString(), EncodeBase64(&sig[0], sig.size())); strMessage, CBitcoinAddress(pubkey.GetID()).ToString(), EncodeBase64(&sig[0], sig.size()));
if(!darkSendSigner.VerifyMessage(pubkey, sig, strMessage, errorMessage)){
LogPrintf("mnb - Got bad Masternode address signature, error: %s\n", errorMessage); if(!darkSendSigner.VerifyMessage(pubkey, sig, strMessage, errorMessage)){
// There is a bug in old MN signatures, ignore such MN but do not ban the peer we got this from LogPrintf("mnb - Got bad Masternode address signature, error: %s\n", errorMessage);
nDos = protocolVersion < 70201 ? 0 : 100; nDos = 100;
return false; return false;
}
} }
if(Params().NetworkID() == CBaseChainParams::MAIN) { if(Params().NetworkID() == CBaseChainParams::MAIN) {