@@ -339,6 +339,8 @@ CMasternodeBroadcast::CMasternodeBroadcast(const CMasternode& mn)
339
339
340
340
bool CMasternodeBroadcast::CheckAndUpdate (int & nDos)
341
341
{
342
+ nDos = 0 ;
343
+
342
344
// make sure signature isn't in the future (past is OK)
343
345
if (sigTime > GetAdjustedTime () + 60 * 60 ) {
344
346
LogPrintf (" mnb - Signature rejected, too far into the future %s\n " , vin.ToString ());
@@ -375,23 +377,55 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos)
375
377
}
376
378
377
379
std::string strMessage;
380
+ std::string errorMessage = " " ;
381
+
378
382
if (protocolVersion < 70201 ) {
379
383
std::string vchPubKey (pubkey.begin (), pubkey.end ());
380
384
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
+ }
382
416
} else {
383
417
strMessage = addr.ToString (false ) + boost::lexical_cast<std::string>(sigTime) +
384
418
pubkey.GetID ().ToString () + pubkey2.GetID ().ToString () +
385
419
boost::lexical_cast<std::string>(protocolVersion);
386
- }
387
420
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
+ }
395
429
}
396
430
397
431
if (Params ().NetworkID () == CBaseChainParams::MAIN) {
0 commit comments