Skip to content

Commit 9669633

Browse files
committed
Merge bitcoin#599: Fix bad masternode IPv6 signature
0ec1fd5 �make use of getnameinfo() optional (default: true) (gpdionisio) Tree-SHA512: 42f254d2c20464a21c6c5d76ced41fb8769213b68efef294e5d2fa7fa30bb6412162f4c8b0541a34cf7969bd176e8f68359f6ed07314343eebdd5c781914a804
2 parents 779d8d5 + 0ec1fd5 commit 9669633

File tree

4 files changed

+28
-21
lines changed

4 files changed

+28
-21
lines changed

src/masternode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ std::string CMasternodeBroadcast::GetOldStrMessage()
693693

694694
std::string vchPubKey(pubKeyCollateralAddress.begin(), pubKeyCollateralAddress.end());
695695
std::string vchPubKey2(pubKeyMasternode.begin(), pubKeyMasternode.end());
696-
strMessage = addr.ToString() + boost::lexical_cast<std::string>(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(protocolVersion);
696+
strMessage = addr.ToString(false) + boost::lexical_cast<std::string>(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(protocolVersion);
697697

698698
return strMessage;
699699
}
@@ -702,7 +702,7 @@ std:: string CMasternodeBroadcast::GetNewStrMessage()
702702
{
703703
std::string strMessage;
704704

705-
strMessage = addr.ToString() + boost::lexical_cast<std::string>(sigTime) + pubKeyCollateralAddress.GetID().ToString() + pubKeyMasternode.GetID().ToString() + boost::lexical_cast<std::string>(protocolVersion);
705+
strMessage = addr.ToString(false) + boost::lexical_cast<std::string>(sigTime) + pubKeyCollateralAddress.GetID().ToString() + pubKeyMasternode.GetID().ToString() + boost::lexical_cast<std::string>(protocolVersion);
706706

707707
return strMessage;
708708
}

src/netbase.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -874,17 +874,20 @@ enum Network CNetAddr::GetNetwork() const
874874
return NET_IPV6;
875875
}
876876

877-
std::string CNetAddr::ToStringIP() const
877+
std::string CNetAddr::ToStringIP(bool fUseGetnameinfo) const
878878
{
879879
if (IsTor())
880880
return EncodeBase32(&ip[6], 10) + ".onion";
881-
CService serv(*this, 0);
882-
struct sockaddr_storage sockaddr;
883-
socklen_t socklen = sizeof(sockaddr);
884-
if (serv.GetSockAddr((struct sockaddr*)&sockaddr, &socklen)) {
885-
char name[1025] = "";
886-
if (!getnameinfo((const struct sockaddr*)&sockaddr, socklen, name, sizeof(name), NULL, 0, NI_NUMERICHOST))
887-
return std::string(name);
881+
if (fUseGetnameinfo)
882+
{
883+
CService serv(*this, 0);
884+
struct sockaddr_storage sockaddr;
885+
socklen_t socklen = sizeof(sockaddr);
886+
if (serv.GetSockAddr((struct sockaddr*)&sockaddr, &socklen)) {
887+
char name[1025] = "";
888+
if (!getnameinfo((const struct sockaddr*)&sockaddr, socklen, name, sizeof(name), NULL, 0, NI_NUMERICHOST))
889+
return std::string(name);
890+
}
888891
}
889892
if (IsIPv4())
890893
return strprintf("%u.%u.%u.%u", GetByte(3), GetByte(2), GetByte(1), GetByte(0));
@@ -1231,18 +1234,18 @@ std::string CService::ToStringPort() const
12311234
return strprintf("%u", port);
12321235
}
12331236

1234-
std::string CService::ToStringIPPort() const
1237+
std::string CService::ToStringIPPort(bool fUseGetnameinfo) const
12351238
{
12361239
if (IsIPv4() || IsTor()) {
1237-
return ToStringIP() + ":" + ToStringPort();
1240+
return ToStringIP(fUseGetnameinfo) + ":" + ToStringPort();
12381241
} else {
1239-
return "[" + ToStringIP() + "]:" + ToStringPort();
1242+
return "[" + ToStringIP(fUseGetnameinfo) + "]:" + ToStringPort();
12401243
}
12411244
}
12421245

1243-
std::string CService::ToString() const
1246+
std::string CService::ToString(bool fUseGetnameinfo) const
12441247
{
1245-
return ToStringIPPort();
1248+
return ToStringIPPort(fUseGetnameinfo);
12461249
}
12471250

12481251
void CService::SetPort(unsigned short portIn)

src/netbase.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class CNetAddr
8282
bool IsMulticast() const;
8383
enum Network GetNetwork() const;
8484
std::string ToString() const;
85-
std::string ToStringIP() const;
85+
std::string ToStringIP(bool fUseGetnameinfo = true) const;
8686
unsigned int GetByte(int n) const;
8787
uint64_t GetHash() const;
8888
bool GetInAddr(struct in_addr* pipv4Addr) const;
@@ -167,9 +167,9 @@ class CService : public CNetAddr
167167
friend bool operator!=(const CService& a, const CService& b);
168168
friend bool operator<(const CService& a, const CService& b);
169169
std::vector<unsigned char> GetKey() const;
170-
std::string ToString() const;
170+
std::string ToString(bool fUseGetnameinfo = true) const;
171171
std::string ToStringPort() const;
172-
std::string ToStringIPPort() const;
172+
std::string ToStringIPPort(bool fUseGetnameinfo = true) const;
173173

174174
CService(const struct in6_addr& ipv6Addr, unsigned short port);
175175
CService(const struct sockaddr_in6& addr);

src/obfuscation.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,10 +2174,14 @@ bool CObfuScationSigner::VerifyMessage(CPubKey pubkey, vector<unsigned char>& vc
21742174
return false;
21752175
}
21762176

2177-
if (fDebug && pubkey2.GetID() != pubkey.GetID())
2178-
LogPrintf("CObfuScationSigner::VerifyMessage -- keys don't match: %s %s\n", pubkey2.GetID().ToString(), pubkey.GetID().ToString());
2177+
if (pubkey2.GetID() != pubkey.GetID()) {
2178+
errorMessage = strprintf("keys don't match - input: %s, recovered: %s, message: %s, sig: %s\n",
2179+
pubkey.GetID().ToString(), pubkey2.GetID().ToString(), strMessage,
2180+
EncodeBase64(&vchSig[0], vchSig.size()));
2181+
return false;
2182+
}
21792183

2180-
return (pubkey2.GetID() == pubkey.GetID());
2184+
return true;
21812185
}
21822186

21832187
bool CObfuscationQueue::Sign()

0 commit comments

Comments
 (0)