Skip to content

Commit b7fd92d

Browse files
UdjinM6schinzelh
authored andcommitted
Merge #860: More compatibility for old ipv6 format
6ef9f5d More compatibility for old ipv6 - try old format ipv6 if new format failed, sanitize log strings
1 parent 00540c8 commit b7fd92d

File tree

1 file changed

+43
-9
lines changed

1 file changed

+43
-9
lines changed

src/masternode.cpp

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ CMasternodeBroadcast::CMasternodeBroadcast(const CMasternode& mn)
339339

340340
bool CMasternodeBroadcast::CheckAndUpdate(int& nDos)
341341
{
342+
nDos = 0;
343+
342344
// make sure signature isn't in the future (past is OK)
343345
if (sigTime > GetAdjustedTime() + 60 * 60) {
344346
LogPrintf("mnb - Signature rejected, too far into the future %s\n", vin.ToString());
@@ -375,23 +377,55 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos)
375377
}
376378

377379
std::string strMessage;
380+
std::string errorMessage = "";
381+
378382
if(protocolVersion < 70201) {
379383
std::string vchPubKey(pubkey.begin(), pubkey.end());
380384
std::string vchPubKey2(pubkey2.begin(), pubkey2.end());
381-
strMessage = addr.ToString(false) + boost::lexical_cast<std::string>(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(protocolVersion);
385+
strMessage = addr.ToString(false) + boost::lexical_cast<std::string>(sigTime) +
386+
vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(protocolVersion);
387+
388+
LogPrint("masternode", "mnb - sanitized strMessage: %s, pubkey address: %s, sig: %s\n",
389+
SanitizeString(strMessage), CBitcoinAddress(pubkey.GetID()).ToString(),
390+
EncodeBase64(&sig[0], sig.size()));
391+
392+
if(!darkSendSigner.VerifyMessage(pubkey, sig, strMessage, errorMessage)){
393+
if (addr.ToString() != addr.ToString(false))
394+
{
395+
// maybe it's wrong format, try again with the old one
396+
strMessage = addr.ToString() + boost::lexical_cast<std::string>(sigTime) +
397+
vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(protocolVersion);
398+
399+
LogPrint("masternode", "mnb - sanitized strMessage: %s, pubkey address: %s, sig: %s\n",
400+
SanitizeString(strMessage), CBitcoinAddress(pubkey.GetID()).ToString(),
401+
EncodeBase64(&sig[0], sig.size()));
402+
403+
if(!darkSendSigner.VerifyMessage(pubkey, sig, strMessage, errorMessage)){
404+
// didn't work either
405+
LogPrintf("mnb - Got bad Masternode address signature, sanitized error: %s\n", SanitizeString(errorMessage));
406+
// there is a bug in old MN signatures, ignore such MN but do not ban the peer we got this from
407+
return false;
408+
}
409+
} else {
410+
// nope, sig is actually wrong
411+
LogPrintf("mnb - Got bad Masternode address signature, sanitized error: %s\n", SanitizeString(errorMessage));
412+
// there is a bug in old MN signatures, ignore such MN but do not ban the peer we got this from
413+
return false;
414+
}
415+
}
382416
} else {
383417
strMessage = addr.ToString(false) + boost::lexical_cast<std::string>(sigTime) +
384418
pubkey.GetID().ToString() + pubkey2.GetID().ToString() +
385419
boost::lexical_cast<std::string>(protocolVersion);
386-
}
387420

388-
std::string errorMessage = "";
389-
LogPrint("masternode", "mnb - strMessage: %s, pubkey address: %s, sig: %s\n", strMessage, CBitcoinAddress(pubkey.GetID()).ToString(), EncodeBase64(&sig[0], sig.size()));
390-
if(!darkSendSigner.VerifyMessage(pubkey, sig, strMessage, errorMessage)){
391-
LogPrintf("mnb - Got bad Masternode address signature, error: %s\n", errorMessage);
392-
// There is a bug in old MN signatures, ignore such MN but do not ban the peer we got this from
393-
nDos = protocolVersion < 70201 ? 0 : 100;
394-
return false;
421+
LogPrint("masternode", "mnb - strMessage: %s, pubkey address: %s, sig: %s\n",
422+
strMessage, CBitcoinAddress(pubkey.GetID()).ToString(), EncodeBase64(&sig[0], sig.size()));
423+
424+
if(!darkSendSigner.VerifyMessage(pubkey, sig, strMessage, errorMessage)){
425+
LogPrintf("mnb - Got bad Masternode address signature, error: %s\n", errorMessage);
426+
nDos = 100;
427+
return false;
428+
}
395429
}
396430

397431
if(Params().NetworkID() == CBaseChainParams::MAIN) {

0 commit comments

Comments
 (0)