Merge #948 Refactor CDarkSendSigner
f0ed400 darkSendSigner.SignMessage() should not return error message 154f1b6 darkSendSigner.VerifyMessage() should return non-localized message, its callers should populate error to debug.log b130c32 darkSendSigner.GetKeysFromSecret() should not return error message, its callers should handle it
This commit is contained in:
parent
66de5b082a
commit
67def9ef2e
@ -36,25 +36,24 @@ std::string CDarkSendRelay::ToString()
|
|||||||
|
|
||||||
bool CDarkSendRelay::Sign(std::string strSharedKey)
|
bool CDarkSendRelay::Sign(std::string strSharedKey)
|
||||||
{
|
{
|
||||||
|
std::string strError = "";
|
||||||
std::string strMessage = in.ToString() + out.ToString();
|
std::string strMessage = in.ToString() + out.ToString();
|
||||||
|
|
||||||
CKey key2;
|
CKey key2;
|
||||||
CPubKey pubkey2;
|
CPubKey pubkey2;
|
||||||
std::string errorMessage = "";
|
|
||||||
|
|
||||||
if(!darkSendSigner.GetKeysFromSecret(strSharedKey, errorMessage, key2, pubkey2))
|
if(!darkSendSigner.GetKeysFromSecret(strSharedKey, key2, pubkey2)) {
|
||||||
{
|
LogPrintf("CDarkSendRelay::Sign -- GetKeysFromSecret() failed, invalid shared key %s\n", strSharedKey);
|
||||||
LogPrintf("CDarkSendRelay():Sign - ERROR: Invalid shared key: '%s'\n", errorMessage);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!darkSendSigner.SignMessage(strMessage, errorMessage, vchSig2, key2)) {
|
if(!darkSendSigner.SignMessage(strMessage, vchSig2, key2)) {
|
||||||
LogPrintf("CDarkSendRelay():Sign - Sign message failed\n");
|
LogPrintf("CDarkSendRelay::Sign -- SignMessage() failed\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!darkSendSigner.VerifyMessage(pubkey2, vchSig2, strMessage, errorMessage)) {
|
if(!darkSendSigner.VerifyMessage(pubkey2, vchSig2, strMessage, strError)) {
|
||||||
LogPrintf("CDarkSendRelay():Sign - Verify message failed\n");
|
LogPrintf("CDarkSendRelay::Sign -- VerifyMessage() failed, error: %s\n", strError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,20 +62,19 @@ bool CDarkSendRelay::Sign(std::string strSharedKey)
|
|||||||
|
|
||||||
bool CDarkSendRelay::VerifyMessage(std::string strSharedKey)
|
bool CDarkSendRelay::VerifyMessage(std::string strSharedKey)
|
||||||
{
|
{
|
||||||
|
std::string strError = "";
|
||||||
std::string strMessage = in.ToString() + out.ToString();
|
std::string strMessage = in.ToString() + out.ToString();
|
||||||
|
|
||||||
CKey key2;
|
CKey key2;
|
||||||
CPubKey pubkey2;
|
CPubKey pubkey2;
|
||||||
std::string errorMessage = "";
|
|
||||||
|
|
||||||
if(!darkSendSigner.GetKeysFromSecret(strSharedKey, errorMessage, key2, pubkey2))
|
if(!darkSendSigner.GetKeysFromSecret(strSharedKey, key2, pubkey2)) {
|
||||||
{
|
LogPrintf("CDarkSendRelay::VerifyMessage -- GetKeysFromSecret() failed, invalid shared key %s\n", strSharedKey);
|
||||||
LogPrintf("CDarkSendRelay()::VerifyMessage - ERROR: Invalid shared key: '%s'\n", errorMessage);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!darkSendSigner.VerifyMessage(pubkey2, vchSig2, strMessage, errorMessage)) {
|
if(!darkSendSigner.VerifyMessage(pubkey2, vchSig2, strMessage, strError)) {
|
||||||
LogPrintf("CDarkSendRelay()::VerifyMessage - Verify message failed\n");
|
LogPrintf("CDarkSendRelay::VerifyMessage -- VerifyMessage() failed, error: %s\n", strError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2084,15 +2084,11 @@ bool CDarkSendSigner::IsVinAssociatedWithPubkey(const CTxIn& txin, const CPubKey
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CDarkSendSigner::GetKeysFromSecret(std::string strSecret, std::string& strErrorRet, CKey& keyRet, CPubKey& pubkeyRet)
|
bool CDarkSendSigner::GetKeysFromSecret(std::string strSecret, CKey& keyRet, CPubKey& pubkeyRet)
|
||||||
{
|
{
|
||||||
CBitcoinSecret vchSecret;
|
CBitcoinSecret vchSecret;
|
||||||
bool fGood = vchSecret.SetString(strSecret);
|
|
||||||
|
|
||||||
if(!fGood) {
|
if(!vchSecret.SetString(strSecret)) return false;
|
||||||
strErrorRet = _("Invalid secret.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
keyRet = vchSecret.GetKey();
|
keyRet = vchSecret.GetKey();
|
||||||
pubkeyRet = keyRet.GetPubKey();
|
pubkeyRet = keyRet.GetPubKey();
|
||||||
@ -2100,18 +2096,13 @@ bool CDarkSendSigner::GetKeysFromSecret(std::string strSecret, std::string& strE
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CDarkSendSigner::SignMessage(std::string strMessage, std::string& strErrorRet, std::vector<unsigned char>& vchSigRet, CKey key)
|
bool CDarkSendSigner::SignMessage(std::string strMessage, std::vector<unsigned char>& vchSigRet, CKey key)
|
||||||
{
|
{
|
||||||
CHashWriter ss(SER_GETHASH, 0);
|
CHashWriter ss(SER_GETHASH, 0);
|
||||||
ss << strMessageMagic;
|
ss << strMessageMagic;
|
||||||
ss << strMessage;
|
ss << strMessage;
|
||||||
|
|
||||||
if(!key.SignCompact(ss.GetHash(), vchSigRet)) {
|
return key.SignCompact(ss.GetHash(), vchSigRet);
|
||||||
strErrorRet = _("Signing failed.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CDarkSendSigner::VerifyMessage(CPubKey pubkey, const std::vector<unsigned char>& vchSig, std::string strMessage, std::string& strErrorRet)
|
bool CDarkSendSigner::VerifyMessage(CPubKey pubkey, const std::vector<unsigned char>& vchSig, std::string strMessage, std::string& strErrorRet)
|
||||||
@ -2122,12 +2113,12 @@ bool CDarkSendSigner::VerifyMessage(CPubKey pubkey, const std::vector<unsigned c
|
|||||||
|
|
||||||
CPubKey pubkeyFromSig;
|
CPubKey pubkeyFromSig;
|
||||||
if(!pubkeyFromSig.RecoverCompact(ss.GetHash(), vchSig)) {
|
if(!pubkeyFromSig.RecoverCompact(ss.GetHash(), vchSig)) {
|
||||||
strErrorRet = _("Error recovering public key.");
|
strErrorRet = "Error recovering public key.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pubkeyFromSig.GetID() != pubkey.GetID()) {
|
if(pubkeyFromSig.GetID() != pubkey.GetID()) {
|
||||||
strErrorRet = strprintf("keys don't match: pubkey=%s, pubkeyFromSig=%s, strMessage=%s, vchSig=%s",
|
strErrorRet = strprintf("Keys don't match: pubkey=%s, pubkeyFromSig=%s, strMessage=%s, vchSig=%s",
|
||||||
pubkey.GetID().ToString(), pubkeyFromSig.GetID().ToString(), strMessage,
|
pubkey.GetID().ToString(), pubkeyFromSig.GetID().ToString(), strMessage,
|
||||||
EncodeBase64(&vchSig[0], vchSig.size()));
|
EncodeBase64(&vchSig[0], vchSig.size()));
|
||||||
return false;
|
return false;
|
||||||
@ -2177,9 +2168,8 @@ bool CDarksendQueue::Sign()
|
|||||||
if(!fMasterNode) return false;
|
if(!fMasterNode) return false;
|
||||||
|
|
||||||
std::string strMessage = vin.ToString() + boost::lexical_cast<std::string>(nDenom) + boost::lexical_cast<std::string>(nTime) + boost::lexical_cast<std::string>(fReady);
|
std::string strMessage = vin.ToString() + boost::lexical_cast<std::string>(nDenom) + boost::lexical_cast<std::string>(nTime) + boost::lexical_cast<std::string>(fReady);
|
||||||
std::string strError = "";
|
|
||||||
|
|
||||||
if(!darkSendSigner.SignMessage(strMessage, strError, vchSig, activeMasternode.keyMasternode)) {
|
if(!darkSendSigner.SignMessage(strMessage, vchSig, activeMasternode.keyMasternode)) {
|
||||||
LogPrintf("CDarksendQueue::Sign -- SignMessage() failed\n");
|
LogPrintf("CDarksendQueue::Sign -- SignMessage() failed\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -2196,7 +2186,7 @@ bool CDarksendQueue::CheckSignature()
|
|||||||
std::string strError = "";
|
std::string strError = "";
|
||||||
|
|
||||||
if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchSig, strMessage, strError)) {
|
if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchSig, strMessage, strError)) {
|
||||||
LogPrintf("CDarksendQueue::CheckSignature -- Got bad Masternode queue signature, vin=%s\n", vin.ToString());
|
LogPrintf("CDarksendQueue::CheckSignature -- Got bad Masternode queue signature, vin=%s, error: %s\n", vin.ToString(), strError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2235,9 +2225,8 @@ bool CDarksendBroadcastTx::Sign()
|
|||||||
if(!fMasterNode) return false;
|
if(!fMasterNode) return false;
|
||||||
|
|
||||||
std::string strMessage = tx.GetHash().ToString() + boost::lexical_cast<std::string>(sigTime);
|
std::string strMessage = tx.GetHash().ToString() + boost::lexical_cast<std::string>(sigTime);
|
||||||
std::string strError = "";
|
|
||||||
|
|
||||||
if(!darkSendSigner.SignMessage(strMessage, strError, vchSig, activeMasternode.keyMasternode)) {
|
if(!darkSendSigner.SignMessage(strMessage, vchSig, activeMasternode.keyMasternode)) {
|
||||||
LogPrintf("CDarksendBroadcastTx::Sign -- SignMessage() failed\n");
|
LogPrintf("CDarksendBroadcastTx::Sign -- SignMessage() failed\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -2254,7 +2243,7 @@ bool CDarksendBroadcastTx::CheckSignature()
|
|||||||
std::string strError = "";
|
std::string strError = "";
|
||||||
|
|
||||||
if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchSig, strMessage, strError)) {
|
if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchSig, strMessage, strError)) {
|
||||||
LogPrintf("CDarksendBroadcastTx::CheckSignature -- Got bad dstx signature\n");
|
LogPrintf("CDarksendBroadcastTx::CheckSignature -- Got bad dstx signature, error: %s\n", strError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,9 +226,9 @@ public:
|
|||||||
/// Is the input associated with this public key? (and there is 1000 DASH - checking if valid masternode)
|
/// Is the input associated with this public key? (and there is 1000 DASH - checking if valid masternode)
|
||||||
bool IsVinAssociatedWithPubkey(const CTxIn& vin, const CPubKey& pubkey);
|
bool IsVinAssociatedWithPubkey(const CTxIn& vin, const CPubKey& pubkey);
|
||||||
/// Set the private/public key values, returns true if successful
|
/// Set the private/public key values, returns true if successful
|
||||||
bool GetKeysFromSecret(std::string strSecret, std::string& strErrorRet, CKey& keyRet, CPubKey& pubkeyRet);
|
bool GetKeysFromSecret(std::string strSecret, CKey& keyRet, CPubKey& pubkeyRet);
|
||||||
/// Sign the message, returns true if successful
|
/// Sign the message, returns true if successful
|
||||||
bool SignMessage(std::string strMessage, std::string& strErrorRet, std::vector<unsigned char>& vchSigRet, CKey key);
|
bool SignMessage(std::string strMessage, std::vector<unsigned char>& vchSigRet, CKey key);
|
||||||
/// Verify the message, returns true if succcessful
|
/// Verify the message, returns true if succcessful
|
||||||
bool VerifyMessage(CPubKey pubkey, const std::vector<unsigned char>& vchSig, std::string strMessage, std::string& strErrorRet);
|
bool VerifyMessage(CPubKey pubkey, const std::vector<unsigned char>& vchSig, std::string strMessage, std::string& strErrorRet);
|
||||||
};
|
};
|
||||||
|
@ -150,17 +150,17 @@ bool CGovernanceVote::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode)
|
|||||||
CPubKey pubKeyCollateralAddress;
|
CPubKey pubKeyCollateralAddress;
|
||||||
CKey keyCollateralAddress;
|
CKey keyCollateralAddress;
|
||||||
|
|
||||||
std::string errorMessage;
|
std::string strError;
|
||||||
std::string strMessage = vinMasternode.prevout.ToStringShort() + "|" + nParentHash.ToString() + "|" +
|
std::string strMessage = vinMasternode.prevout.ToStringShort() + "|" + nParentHash.ToString() + "|" +
|
||||||
boost::lexical_cast<std::string>(nVoteSignal) + "|" + boost::lexical_cast<std::string>(nVoteOutcome) + "|" + boost::lexical_cast<std::string>(nTime);
|
boost::lexical_cast<std::string>(nVoteSignal) + "|" + boost::lexical_cast<std::string>(nVoteOutcome) + "|" + boost::lexical_cast<std::string>(nTime);
|
||||||
|
|
||||||
if(!darkSendSigner.SignMessage(strMessage, errorMessage, vchSig, keyMasternode)) {
|
if(!darkSendSigner.SignMessage(strMessage, vchSig, keyMasternode)) {
|
||||||
LogPrintf("CGovernanceVote::Sign - Error upon calling SignMessage");
|
LogPrintf("CGovernanceVote::Sign -- SignMessage() failed\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!darkSendSigner.VerifyMessage(pubKeyMasternode, vchSig, strMessage, errorMessage)) {
|
if(!darkSendSigner.VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) {
|
||||||
LogPrintf("CGovernanceVote::Sign - Error upon calling VerifyMessage");
|
LogPrintf("CGovernanceVote::Sign -- VerifyMessage() failed, error: %s\n", strError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,12 +197,12 @@ bool CGovernanceVote::IsValid(bool fSignatureCheck)
|
|||||||
|
|
||||||
if(!fSignatureCheck) return true;
|
if(!fSignatureCheck) return true;
|
||||||
|
|
||||||
std::string errorMessage;
|
std::string strError;
|
||||||
std::string strMessage = vinMasternode.prevout.ToStringShort() + "|" + nParentHash.ToString() + "|" +
|
std::string strMessage = vinMasternode.prevout.ToStringShort() + "|" + nParentHash.ToString() + "|" +
|
||||||
boost::lexical_cast<std::string>(nVoteSignal) + "|" + boost::lexical_cast<std::string>(nVoteOutcome) + "|" + boost::lexical_cast<std::string>(nTime);
|
boost::lexical_cast<std::string>(nVoteSignal) + "|" + boost::lexical_cast<std::string>(nVoteOutcome) + "|" + boost::lexical_cast<std::string>(nTime);
|
||||||
|
|
||||||
if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchSig, strMessage, errorMessage)) {
|
if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchSig, strMessage, strError)) {
|
||||||
LogPrintf("CGovernanceVote::IsValid() - Verify message failed - Error: %s\n", errorMessage);
|
LogPrintf("CGovernanceVote::IsValid -- VerifyMessage() failed, error: %s\n", strError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1798,9 +1798,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
|||||||
|
|
||||||
std::string strMasterNodePrivKey = GetArg("-masternodeprivkey", "");
|
std::string strMasterNodePrivKey = GetArg("-masternodeprivkey", "");
|
||||||
if(!strMasterNodePrivKey.empty()) {
|
if(!strMasterNodePrivKey.empty()) {
|
||||||
std::string strErrorMessage;
|
if(!darkSendSigner.GetKeysFromSecret(strMasterNodePrivKey, activeMasternode.keyMasternode, activeMasternode.pubKeyMasternode))
|
||||||
|
|
||||||
if(!darkSendSigner.GetKeysFromSecret(strMasterNodePrivKey, strErrorMessage, activeMasternode.keyMasternode, activeMasternode.pubKeyMasternode))
|
|
||||||
return InitError(_("Invalid masternodeprivkey. Please see documenation."));
|
return InitError(_("Invalid masternodeprivkey. Please see documenation."));
|
||||||
|
|
||||||
LogPrintf(" pubKeyMasternode: %s\n", CBitcoinAddress(activeMasternode.pubKeyMasternode.GetID()).ToString());
|
LogPrintf(" pubKeyMasternode: %s\n", CBitcoinAddress(activeMasternode.pubKeyMasternode.GetID()).ToString());
|
||||||
|
@ -560,7 +560,7 @@ bool CConsensusVote::CheckSignature()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchMasterNodeSignature, strMessage, strError)) {
|
if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchMasterNodeSignature, strMessage, strError)) {
|
||||||
LogPrintf("CConsensusVote::CheckSignature -- VerifyMessage() failed\n");
|
LogPrintf("CConsensusVote::CheckSignature -- VerifyMessage() failed, error: %s\n", strError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -573,13 +573,13 @@ bool CConsensusVote::Sign()
|
|||||||
|
|
||||||
std::string strMessage = txHash.ToString().c_str() + boost::lexical_cast<std::string>(nBlockHeight);
|
std::string strMessage = txHash.ToString().c_str() + boost::lexical_cast<std::string>(nBlockHeight);
|
||||||
|
|
||||||
if(!darkSendSigner.SignMessage(strMessage, strError, vchMasterNodeSignature, activeMasternode.keyMasternode)) {
|
if(!darkSendSigner.SignMessage(strMessage, vchMasterNodeSignature, activeMasternode.keyMasternode)) {
|
||||||
LogPrintf("CConsensusVote::Sign -- SignMessage() failed");
|
LogPrintf("CConsensusVote::Sign -- SignMessage() failed\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!darkSendSigner.VerifyMessage(activeMasternode.pubKeyMasternode, vchMasterNodeSignature, strMessage, strError)) {
|
if(!darkSendSigner.VerifyMessage(activeMasternode.pubKeyMasternode, vchMasterNodeSignature, strMessage, strError)) {
|
||||||
LogPrintf("CConsensusVote::Sign -- VerifyMessage() failed");
|
LogPrintf("CConsensusVote::Sign -- VerifyMessage() failed, error: %s\n", strError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,20 +316,20 @@ void CMasternodePayments::ProcessMessage(CNode* pfrom, std::string& strCommand,
|
|||||||
|
|
||||||
bool CMasternodePaymentWinner::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode)
|
bool CMasternodePaymentWinner::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode)
|
||||||
{
|
{
|
||||||
std::string errorMessage;
|
std::string strError;
|
||||||
std::string strMasterNodeSignMessage;
|
std::string strMasterNodeSignMessage;
|
||||||
|
|
||||||
std::string strMessage = vinMasternode.prevout.ToStringShort() +
|
std::string strMessage = vinMasternode.prevout.ToStringShort() +
|
||||||
boost::lexical_cast<std::string>(nBlockHeight) +
|
boost::lexical_cast<std::string>(nBlockHeight) +
|
||||||
ScriptToAsmStr(payee);
|
ScriptToAsmStr(payee);
|
||||||
|
|
||||||
if(!darkSendSigner.SignMessage(strMessage, errorMessage, vchSig, keyMasternode)) {
|
if(!darkSendSigner.SignMessage(strMessage, vchSig, keyMasternode)) {
|
||||||
LogPrintf("CMasternodePing::Sign() - Error: %s\n", errorMessage);
|
LogPrintf("CMasternodePaymentWinner::Sign -- SignMessage() failed\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!darkSendSigner.VerifyMessage(pubKeyMasternode, vchSig, strMessage, errorMessage)) {
|
if(!darkSendSigner.VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) {
|
||||||
LogPrintf("CMasternodePing::Sign() - Error: %s\n", errorMessage);
|
LogPrintf("CMasternodePing::Sign() -- VerifyMessage() failed, error: %s\n", strError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -628,13 +628,13 @@ bool CMasternodePaymentWinner::SignatureValid()
|
|||||||
|
|
||||||
if(pmn != NULL)
|
if(pmn != NULL)
|
||||||
{
|
{
|
||||||
|
std::string strError = "";
|
||||||
std::string strMessage = vinMasternode.prevout.ToStringShort() +
|
std::string strMessage = vinMasternode.prevout.ToStringShort() +
|
||||||
boost::lexical_cast<std::string>(nBlockHeight) +
|
boost::lexical_cast<std::string>(nBlockHeight) +
|
||||||
ScriptToAsmStr(payee);
|
ScriptToAsmStr(payee);
|
||||||
|
|
||||||
std::string errorMessage = "";
|
if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchSig, strMessage, strError)) {
|
||||||
if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchSig, strMessage, errorMessage)){
|
return error("CMasternodePaymentWinner::CheckSignature -- Got bad Masternode payment signature: vin=%s, error: %s", vinMasternode.ToString().c_str(), strError);
|
||||||
return error("CMasternodePaymentWinner::SignatureValid() - Got bad Masternode payment signature %s", vinMasternode.ToString().c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -337,8 +337,8 @@ bool CMasternodeBroadcast::Create(std::string strService, std::string strKeyMast
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!darkSendSigner.GetKeysFromSecret(strKeyMasternode, strErrorMessage, keyMasternodeNew, pubKeyMasternodeNew)) {
|
if(!darkSendSigner.GetKeysFromSecret(strKeyMasternode, keyMasternodeNew, pubKeyMasternodeNew)) {
|
||||||
strErrorMessage = strprintf("Can't find keys for masternode %s, error: %s", strService, strErrorMessage);
|
strErrorMessage = strprintf("Invalid masternode key %s", strKeyMasternode);
|
||||||
LogPrintf("CMasternodeBroadcast::Create -- %s\n", strErrorMessage);
|
LogPrintf("CMasternodeBroadcast::Create -- %s\n", strErrorMessage);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -595,7 +595,7 @@ void CMasternodeBroadcast::Relay()
|
|||||||
|
|
||||||
bool CMasternodeBroadcast::Sign(CKey& keyCollateralAddress)
|
bool CMasternodeBroadcast::Sign(CKey& keyCollateralAddress)
|
||||||
{
|
{
|
||||||
std::string errorMessage;
|
std::string strError;
|
||||||
std::string strMessage;
|
std::string strMessage;
|
||||||
|
|
||||||
sigTime = GetAdjustedTime();
|
sigTime = GetAdjustedTime();
|
||||||
@ -604,13 +604,13 @@ bool CMasternodeBroadcast::Sign(CKey& keyCollateralAddress)
|
|||||||
pubkey.GetID().ToString() + pubkey2.GetID().ToString() +
|
pubkey.GetID().ToString() + pubkey2.GetID().ToString() +
|
||||||
boost::lexical_cast<std::string>(protocolVersion);
|
boost::lexical_cast<std::string>(protocolVersion);
|
||||||
|
|
||||||
if(!darkSendSigner.SignMessage(strMessage, errorMessage, vchSig, keyCollateralAddress)) {
|
if(!darkSendSigner.SignMessage(strMessage, vchSig, keyCollateralAddress)) {
|
||||||
LogPrintf("CMasternodeBroadcast::Sign() - Error: %s\n", errorMessage);
|
LogPrintf("CMasternodeBroadcast::Sign -- SignMessage() failed\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!darkSendSigner.VerifyMessage(pubkey, vchSig, strMessage, errorMessage)) {
|
if(!darkSendSigner.VerifyMessage(pubkey, vchSig, strMessage, strError)) {
|
||||||
LogPrintf("CMasternodeBroadcast::Sign() - Error: %s\n", errorMessage);
|
LogPrintf("CMasternodeBroadcast::Sign -- VerifyMessage() failed, error: %s\n", strError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -620,7 +620,7 @@ bool CMasternodeBroadcast::Sign(CKey& keyCollateralAddress)
|
|||||||
bool CMasternodeBroadcast::VerifySignature(int& nDos)
|
bool CMasternodeBroadcast::VerifySignature(int& nDos)
|
||||||
{
|
{
|
||||||
std::string strMessage;
|
std::string strMessage;
|
||||||
std::string errorMessage = "";
|
std::string strError = "";
|
||||||
nDos = 0;
|
nDos = 0;
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -636,7 +636,7 @@ bool CMasternodeBroadcast::VerifySignature(int& nDos)
|
|||||||
SanitizeString(strMessage), CBitcoinAddress(pubkey.GetID()).ToString(),
|
SanitizeString(strMessage), CBitcoinAddress(pubkey.GetID()).ToString(),
|
||||||
EncodeBase64(&vchSig[0], vchSig.size()));
|
EncodeBase64(&vchSig[0], vchSig.size()));
|
||||||
|
|
||||||
if(!darkSendSigner.VerifyMessage(pubkey, vchSig, strMessage, errorMessage)){
|
if(!darkSendSigner.VerifyMessage(pubkey, vchSig, strMessage, strError)) {
|
||||||
if (addr.ToString() != addr.ToString(false))
|
if (addr.ToString() != addr.ToString(false))
|
||||||
{
|
{
|
||||||
// maybe it's wrong format, try again with the old one
|
// maybe it's wrong format, try again with the old one
|
||||||
@ -647,17 +647,17 @@ bool CMasternodeBroadcast::VerifySignature(int& nDos)
|
|||||||
SanitizeString(strMessage), CBitcoinAddress(pubkey.GetID()).ToString(),
|
SanitizeString(strMessage), CBitcoinAddress(pubkey.GetID()).ToString(),
|
||||||
EncodeBase64(&vchSig[0], vchSig.size()));
|
EncodeBase64(&vchSig[0], vchSig.size()));
|
||||||
|
|
||||||
if(!darkSendSigner.VerifyMessage(pubkey, vchSig, strMessage, errorMessage)){
|
if(!darkSendSigner.VerifyMessage(pubkey, vchSig, strMessage, strError)) {
|
||||||
// didn't work either
|
// didn't work either
|
||||||
LogPrintf("CMasternodeBroadcast::VerifySignature - Got bad Masternode address signature, second try, sanitized error: %s\n",
|
LogPrintf("CMasternodeBroadcast::VerifySignature -- Got bad Masternode announce signature, second try, sanitized error: %s\n",
|
||||||
SanitizeString(errorMessage));
|
SanitizeString(strError));
|
||||||
// don't ban for old masternodes, their sigs could be broken because of the bug
|
// don't ban for old masternodes, their sigs could be broken because of the bug
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// nope, sig is actually wrong
|
// nope, sig is actually wrong
|
||||||
LogPrintf("CMasternodeBroadcast::VerifySignature - Got bad Masternode address signature, sanitized error: %s\n",
|
LogPrintf("CMasternodeBroadcast::VerifySignature -- Got bad Masternode announce signature, sanitized error: %s\n",
|
||||||
SanitizeString(errorMessage));
|
SanitizeString(strError));
|
||||||
// don't ban for old masternodes, their sigs could be broken because of the bug
|
// don't ban for old masternodes, their sigs could be broken because of the bug
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -672,8 +672,8 @@ bool CMasternodeBroadcast::VerifySignature(int& nDos)
|
|||||||
|
|
||||||
LogPrint("masternode", "CMasternodeBroadcast::VerifySignature - strMessage: %s, pubkey address: %s, sig: %s\n", strMessage, CBitcoinAddress(pubkey.GetID()).ToString(), EncodeBase64(&vchSig[0], vchSig.size()));
|
LogPrint("masternode", "CMasternodeBroadcast::VerifySignature - 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)){
|
if(!darkSendSigner.VerifyMessage(pubkey, vchSig, strMessage, strError)){
|
||||||
LogPrintf("CMasternodeBroadcast::VerifySignature - Got bad Masternode address signature, error: %s\n", errorMessage);
|
LogPrintf("CMasternodeBroadcast::VerifySignature -- Got bad Masternode announce signature, error: %s\n", strError);
|
||||||
nDos = 100;
|
nDos = 100;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -710,19 +710,19 @@ CMasternodePing::CMasternodePing(CTxIn& newVin)
|
|||||||
|
|
||||||
bool CMasternodePing::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode)
|
bool CMasternodePing::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode)
|
||||||
{
|
{
|
||||||
std::string errorMessage;
|
std::string strError;
|
||||||
std::string strMasterNodeSignMessage;
|
std::string strMasterNodeSignMessage;
|
||||||
|
|
||||||
sigTime = GetAdjustedTime();
|
sigTime = GetAdjustedTime();
|
||||||
std::string strMessage = vin.ToString() + blockHash.ToString() + boost::lexical_cast<std::string>(sigTime);
|
std::string strMessage = vin.ToString() + blockHash.ToString() + boost::lexical_cast<std::string>(sigTime);
|
||||||
|
|
||||||
if(!darkSendSigner.SignMessage(strMessage, errorMessage, vchSig, keyMasternode)) {
|
if(!darkSendSigner.SignMessage(strMessage, vchSig, keyMasternode)) {
|
||||||
LogPrintf("CMasternodePing::Sign() - Error: %s\n", errorMessage);
|
LogPrintf("CMasternodePing::Sign -- SignMessage() failed\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!darkSendSigner.VerifyMessage(pubKeyMasternode, vchSig, strMessage, errorMessage)) {
|
if(!darkSendSigner.VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) {
|
||||||
LogPrintf("CMasternodePing::Sign() - Error: %s\n", errorMessage);
|
LogPrintf("CMasternodePing::Sign -- VerifyMessage() failed, error: %s\n", strError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -731,12 +731,11 @@ bool CMasternodePing::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode)
|
|||||||
|
|
||||||
bool CMasternodePing::VerifySignature(CPubKey& pubKeyMasternode, int &nDos) {
|
bool CMasternodePing::VerifySignature(CPubKey& pubKeyMasternode, int &nDos) {
|
||||||
std::string strMessage = vin.ToString() + blockHash.ToString() + boost::lexical_cast<std::string>(sigTime);
|
std::string strMessage = vin.ToString() + blockHash.ToString() + boost::lexical_cast<std::string>(sigTime);
|
||||||
std::string errorMessage = "";
|
std::string strError = "";
|
||||||
nDos = 0;
|
nDos = 0;
|
||||||
|
|
||||||
if(!darkSendSigner.VerifyMessage(pubKeyMasternode, vchSig, strMessage, errorMessage))
|
if(!darkSendSigner.VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) {
|
||||||
{
|
LogPrintf("CMasternodePing::VerifySignature -- Got bad Masternode ping signature: %s error: %s\n", vin.ToString(), strError);
|
||||||
LogPrintf("CMasternodePing::VerifySignature - Got bad Masternode ping signature %s Error: %s\n", vin.ToString(), errorMessage);
|
|
||||||
nDos = 33;
|
nDos = 33;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -312,10 +312,10 @@ UniValue gobject(const UniValue& params, bool fHelp)
|
|||||||
|
|
||||||
UniValue statusObj(UniValue::VOBJ);
|
UniValue statusObj(UniValue::VOBJ);
|
||||||
|
|
||||||
if(!darkSendSigner.GetKeysFromSecret(mne.getPrivKey(), errorMessage, keyMasternode, pubKeyMasternode)){
|
if(!darkSendSigner.GetKeysFromSecret(mne.getPrivKey(), keyMasternode, pubKeyMasternode)) {
|
||||||
failed++;
|
failed++;
|
||||||
statusObj.push_back(Pair("result", "failed"));
|
statusObj.push_back(Pair("result", "failed"));
|
||||||
statusObj.push_back(Pair("errorMessage", "Masternode signing error, could not set key correctly: " + errorMessage));
|
statusObj.push_back(Pair("errorMessage", strprintf("Invalid masternode key %s.", mne.getPrivKey())));
|
||||||
resultsObj.push_back(Pair(mne.getAlias(), statusObj));
|
resultsObj.push_back(Pair(mne.getAlias(), statusObj));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -196,24 +196,23 @@ bool CSporkManager::SetPrivKey(std::string strPrivKey)
|
|||||||
|
|
||||||
bool CSporkMessage::Sign(std::string strSignKey)
|
bool CSporkMessage::Sign(std::string strSignKey)
|
||||||
{
|
{
|
||||||
std::string strMessage = boost::lexical_cast<std::string>(nSporkID) + boost::lexical_cast<std::string>(nValue) + boost::lexical_cast<std::string>(nTimeSigned);
|
|
||||||
|
|
||||||
CKey key;
|
CKey key;
|
||||||
CPubKey pubkey;
|
CPubKey pubkey;
|
||||||
std::string errorMessage = "";
|
std::string strError = "";
|
||||||
|
std::string strMessage = boost::lexical_cast<std::string>(nSporkID) + boost::lexical_cast<std::string>(nValue) + boost::lexical_cast<std::string>(nTimeSigned);
|
||||||
|
|
||||||
if(!darkSendSigner.GetKeysFromSecret(strSignKey, errorMessage, key, pubkey)) {
|
if(!darkSendSigner.GetKeysFromSecret(strSignKey, key, pubkey)) {
|
||||||
LogPrintf("CSporkMessage::Sign -- ERROR: '%s'\n", errorMessage);
|
LogPrintf("CSporkMessage::Sign -- GetKeysFromSecret() failed, invalid spork key %s\n", strSignKey);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!darkSendSigner.SignMessage(strMessage, errorMessage, vchSig, key)) {
|
if(!darkSendSigner.SignMessage(strMessage, vchSig, key)) {
|
||||||
LogPrintf("CSporkMessage::Sign -- SignMessage() failed");
|
LogPrintf("CSporkMessage::Sign -- SignMessage() failed\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!darkSendSigner.VerifyMessage(pubkey, vchSig, strMessage, errorMessage)) {
|
if(!darkSendSigner.VerifyMessage(pubkey, vchSig, strMessage, strError)) {
|
||||||
LogPrintf("CSporkMessage::Sign -- VerifyMessage() failed");
|
LogPrintf("CSporkMessage::Sign -- VerifyMessage() failed, error: %s\n", strError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,12 +222,12 @@ bool CSporkMessage::Sign(std::string strSignKey)
|
|||||||
bool CSporkMessage::CheckSignature()
|
bool CSporkMessage::CheckSignature()
|
||||||
{
|
{
|
||||||
//note: need to investigate why this is failing
|
//note: need to investigate why this is failing
|
||||||
|
std::string strError = "";
|
||||||
std::string strMessage = boost::lexical_cast<std::string>(nSporkID) + boost::lexical_cast<std::string>(nValue) + boost::lexical_cast<std::string>(nTimeSigned);
|
std::string strMessage = boost::lexical_cast<std::string>(nSporkID) + boost::lexical_cast<std::string>(nValue) + boost::lexical_cast<std::string>(nTimeSigned);
|
||||||
CPubKey pubkey(ParseHex(Params().SporkPubKey()));
|
CPubKey pubkey(ParseHex(Params().SporkPubKey()));
|
||||||
|
|
||||||
std::string errorMessage = "";
|
if(!darkSendSigner.VerifyMessage(pubkey, vchSig, strMessage, strError)) {
|
||||||
if(!darkSendSigner.VerifyMessage(pubkey, vchSig, strMessage, errorMessage)){
|
LogPrintf("CSporkMessage::CheckSignature -- VerifyMessage() failed, error: %s\n", strError);
|
||||||
LogPrintf("CSporkMessage::CheckSignature -- VerifyMessage() failed");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user