diff --git a/src/darksend.cpp b/src/darksend.cpp index ecfafc8fa..55888db80 100644 --- a/src/darksend.cpp +++ b/src/darksend.cpp @@ -2115,10 +2115,14 @@ bool CDarkSendSigner::VerifyMessage(CPubKey pubkey, vector& 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() diff --git a/src/masternode.cpp b/src/masternode.cpp index e17cf90fd..407b2c4d1 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -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(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast(protocolVersion); + strMessage = addr.ToString(false) + boost::lexical_cast(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast(protocolVersion); } else { - strMessage = addr.ToString() + boost::lexical_cast(sigTime) + + strMessage = addr.ToString(false) + boost::lexical_cast(sigTime) + pubkey.GetID().ToString() + pubkey2.GetID().ToString() + boost::lexical_cast(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(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast(protocolVersion); + strMessage = addr.ToString(false) + boost::lexical_cast(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast(protocolVersion); } else { - strMessage = addr.ToString() + boost::lexical_cast(sigTime) + + strMessage = addr.ToString(false) + boost::lexical_cast(sigTime) + pubkey.GetID().ToString() + pubkey2.GetID().ToString() + boost::lexical_cast(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(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast(protocolVersion); + strMessage = addr.ToString(false) + boost::lexical_cast(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast(protocolVersion); } else { - strMessage = addr.ToString() + boost::lexical_cast(sigTime) + + strMessage = addr.ToString(false) + boost::lexical_cast(sigTime) + pubkey.GetID().ToString() + pubkey2.GetID().ToString() + boost::lexical_cast(protocolVersion); } diff --git a/src/netbase.cpp b/src/netbase.cpp index 6627a8605..1ad75788a 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -867,17 +867,20 @@ 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"; - CService serv(*this, 0); - struct sockaddr_storage sockaddr; - socklen_t socklen = sizeof(sockaddr); - if (serv.GetSockAddr((struct sockaddr*)&sockaddr, &socklen)) { - char name[1025] = ""; - if (!getnameinfo((const struct sockaddr*)&sockaddr, socklen, name, sizeof(name), NULL, 0, NI_NUMERICHOST)) - return std::string(name); + if (fUseGetnameinfo) + { + CService serv(*this, 0); + struct sockaddr_storage sockaddr; + socklen_t socklen = sizeof(sockaddr); + if (serv.GetSockAddr((struct sockaddr*)&sockaddr, &socklen)) { + char name[1025] = ""; + 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)); @@ -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) diff --git a/src/netbase.h b/src/netbase.h index ec1df9783..0d18e5b37 100644 --- a/src/netbase.h +++ b/src/netbase.h @@ -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 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);