Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.12.0.x] More compatibility for old ipv6 format #860

Merged
merged 1 commit into from
Jun 3, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 43 additions & 9 deletions src/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ CMasternodeBroadcast::CMasternodeBroadcast(const CMasternode& mn)

bool CMasternodeBroadcast::CheckAndUpdate(int& nDos)
{
nDos = 0;

// make sure signature isn't in the future (past is OK)
if (sigTime > GetAdjustedTime() + 60 * 60) {
LogPrintf("mnb - Signature rejected, too far into the future %s\n", vin.ToString());
Expand Down Expand Up @@ -375,23 +377,55 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos)
}

std::string strMessage;
std::string errorMessage = "";

if(protocolVersion < 70201) {
std::string vchPubKey(pubkey.begin(), pubkey.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 {
strMessage = addr.ToString(false) + boost::lexical_cast<std::string>(sigTime) +
pubkey.GetID().ToString() + pubkey2.GetID().ToString() +
boost::lexical_cast<std::string>(protocolVersion);
}

std::string errorMessage = "";
LogPrint("masternode", "mnb - strMessage: %s, pubkey address: %s, sig: %s\n", 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);
// There is a bug in old MN signatures, ignore such MN but do not ban the peer we got this from
nDos = protocolVersion < 70201 ? 0 : 100;
return false;
LogPrint("masternode", "mnb - strMessage: %s, pubkey address: %s, sig: %s\n",
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);
nDos = 100;
return false;
}
}

if(Params().NetworkID() == CBaseChainParams::MAIN) {
Expand Down