merge #855: Fix bad mn sig ipv6

51696ac make use of getnameinfo() optional (default: true)
bec39b8 fix mnb sig bug for ipv6 addresses: use pure byte to hex conversion for construction of masternode broadcast signature, better logging
This commit is contained in:
UdjinM6 2016-06-02 10:11:56 +04:00 committed by Holger Schinzel
parent b5924a2451
commit 284e2c41cc
4 changed files with 34 additions and 26 deletions

View File

@ -2115,10 +2115,14 @@ bool CDarkSendSigner::VerifyMessage(CPubKey pubkey, vector<unsigned char>& vchSi
return false;
}
if (fDebug && pubkey2.GetID() != pubkey.GetID())
LogPrintf("CDarkSendSigner::VerifyMessage -- keys don't match: %s %s\n", pubkey2.GetID().ToString(), pubkey.GetID().ToString());
if (pubkey2.GetID() != pubkey.GetID()) {
errorMessage = strprintf("keys don't match - input: %s, recovered: %s, message: %s, sig: %s\n",
pubkey.GetID().ToString(), pubkey2.GetID().ToString(), strMessage,
EncodeBase64(&vchSig[0], vchSig.size()));
return false;
}
return (pubkey2.GetID() == pubkey.GetID());
return true;
}
bool CDarksendQueue::Sign()

View File

@ -374,9 +374,9 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos)
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);
strMessage = addr.ToString(false) + boost::lexical_cast<std::string>(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(protocolVersion);
} else {
strMessage = addr.ToString() + boost::lexical_cast<std::string>(sigTime) +
strMessage = addr.ToString(false) + boost::lexical_cast<std::string>(sigTime) +
pubkey.GetID().ToString() + pubkey2.GetID().ToString() +
boost::lexical_cast<std::string>(protocolVersion);
}
@ -410,8 +410,9 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos)
}
std::string errorMessage = "";
LogPrint("masternode", "CMasternodeBroadcast::CheckAndUpdate - strMessage: %s, pubkey address: %s, sig: %s\n", strMessage, CBitcoinAddress(pubkey.GetID()).ToString(), EncodeBase64(&vchSig[0], vchSig.size()));
if(!darkSendSigner.VerifyMessage(pubkey, vchSig, strMessage, errorMessage)){
LogPrintf("CMasternodeBroadcast::CheckAndUpdate - Got bad Masternode address signature\n");
LogPrintf("CMasternodeBroadcast::CheckAndUpdate - Got bad Masternode address signature, error: %s\n", errorMessage);
// don't ban for old masternodes, their sigs could be broken because of the bug
nDos = protocolVersion < 70201 ? 0 : 100;
return false;
@ -581,9 +582,9 @@ bool CMasternodeBroadcast::Sign(CKey& keyCollateralAddress)
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);
strMessage = addr.ToString(false) + boost::lexical_cast<std::string>(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(protocolVersion);
} else {
strMessage = addr.ToString() + boost::lexical_cast<std::string>(sigTime) +
strMessage = addr.ToString(false) + boost::lexical_cast<std::string>(sigTime) +
pubkey.GetID().ToString() + pubkey2.GetID().ToString() +
boost::lexical_cast<std::string>(protocolVersion);
}
@ -604,9 +605,9 @@ bool CMasternodeBroadcast::VerifySignature()
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);
strMessage = addr.ToString(false) + boost::lexical_cast<std::string>(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(protocolVersion);
} else {
strMessage = addr.ToString() + boost::lexical_cast<std::string>(sigTime) +
strMessage = addr.ToString(false) + boost::lexical_cast<std::string>(sigTime) +
pubkey.GetID().ToString() + pubkey2.GetID().ToString() +
boost::lexical_cast<std::string>(protocolVersion);
}

View File

@ -867,10 +867,12 @@ enum Network CNetAddr::GetNetwork() const
return NET_IPV6;
}
std::string CNetAddr::ToStringIP() const
std::string CNetAddr::ToStringIP(bool fUseGetnameinfo) const
{
if (IsTor())
return EncodeBase32(&ip[6], 10) + ".onion";
if (fUseGetnameinfo)
{
CService serv(*this, 0);
struct sockaddr_storage sockaddr;
socklen_t socklen = sizeof(sockaddr);
@ -879,6 +881,7 @@ std::string CNetAddr::ToStringIP() const
if (!getnameinfo((const struct sockaddr*)&sockaddr, socklen, name, sizeof(name), NULL, 0, NI_NUMERICHOST))
return std::string(name);
}
}
if (IsIPv4())
return strprintf("%u.%u.%u.%u", GetByte(3), GetByte(2), GetByte(1), GetByte(0));
else
@ -1214,18 +1217,18 @@ std::string CService::ToStringPort() const
return strprintf("%u", port);
}
std::string CService::ToStringIPPort() const
std::string CService::ToStringIPPort(bool fUseGetnameinfo) const
{
if (IsIPv4() || IsTor()) {
return ToStringIP() + ":" + ToStringPort();
return ToStringIP(fUseGetnameinfo) + ":" + ToStringPort();
} else {
return "[" + ToStringIP() + "]:" + ToStringPort();
return "[" + ToStringIP(fUseGetnameinfo) + "]:" + ToStringPort();
}
}
std::string CService::ToString() const
std::string CService::ToString(bool fUseGetnameinfo) const
{
return ToStringIPPort();
return ToStringIPPort(fUseGetnameinfo);
}
void CService::SetPort(unsigned short portIn)

View File

@ -82,7 +82,7 @@ class CNetAddr
bool IsMulticast() const;
enum Network GetNetwork() const;
std::string ToString() const;
std::string ToStringIP() const;
std::string ToStringIP(bool fUseGetnameinfo = true) const;
unsigned int GetByte(int n) const;
uint64_t GetHash() const;
bool GetInAddr(struct in_addr* pipv4Addr) const;
@ -166,9 +166,9 @@ class CService : public CNetAddr
friend bool operator!=(const CService& a, const CService& b);
friend bool operator<(const CService& a, const CService& b);
std::vector<unsigned char> GetKey() const;
std::string ToString() const;
std::string ToString(bool fUseGetnameinfo = true) const;
std::string ToStringPort() const;
std::string ToStringIPPort() const;
std::string ToStringIPPort(bool fUseGetnameinfo = true) const;
CService(const struct in6_addr& ipv6Addr, unsigned short port);
CService(const struct sockaddr_in6& addr);