bool SetCheckpointPrivKey(std::string strPrivKey) { // Test signing a sync-checkpoint with genesis block CSyncCheckpoint checkpoint; checkpoint.hashCheckpoint = !fTestNet ? hashGenesisBlock : hashGenesisBlockTestNet; CDataStream sMsg(SER_NETWORK, PROTOCOL_VERSION); sMsg << (CUnsignedSyncCheckpoint)checkpoint; checkpoint.vchMsg = std::vector<unsigned char>(sMsg.begin(), sMsg.end()); std::vector<unsigned char> vchPrivKey = ParseHex(strPrivKey); CKey key; key.SetPrivKey(CPrivKey(vchPrivKey.begin(), vchPrivKey.end())); // if key is not correct openssl may crash if (!key.Sign(Hash(checkpoint.vchMsg.begin(), checkpoint.vchMsg.end()), checkpoint.vchSig)) return false; // Test signing successful, proceed CSyncCheckpoint::strMasterPrivKey = strPrivKey; return true; }
bool RippleAddress::accountPrivateSign (uint256 const& uHash, Blob& vucSig) const { CKey ckPrivate; bool bResult; if (!ckPrivate.SetPrivateKeyU (getAccountPrivate ())) { // Bad private key. WriteLog (lsWARNING, RippleAddress) << "accountPrivateSign: Bad private key."; bResult = false; } else { bResult = ckPrivate.Sign (uHash, vucSig); CondLog (!bResult, lsWARNING, RippleAddress) << "accountPrivateSign: Signing failed."; } return bResult; }
bool SetCheckpointPrivKey(std::string strPrivKey) { // Test signing a sync-checkpoint with genesis block CSyncCheckpoint checkpoint; checkpoint.hashCheckpoint = hashGenesisBlock; CDataStream sMsg(SER_NETWORK, PROTOCOL_VERSION); sMsg << (CUnsignedSyncCheckpoint)checkpoint; checkpoint.vchMsg = std::vector<unsigned char>(sMsg.begin(), sMsg.end()); CBitcoinSecret vchSecret; if (!vchSecret.SetString(strPrivKey)) return error("SendSyncCheckpoint: Checkpoint master key invalid"); CKey key = vchSecret.GetKey(); // if key is not correct openssl may crash if (!key.Sign(Hash(checkpoint.vchMsg.begin(), checkpoint.vchMsg.end()), checkpoint.vchSig)) return false; // Test signing successful, proceed CSyncCheckpoint::strMasterPrivKey = strPrivKey; return true; }
bool CAlert::Sign() { CDataStream sMsg(SER_NETWORK, CLIENT_VERSION); sMsg << *(CUnsignedAlert*)this; vchMsg = std::vector<unsigned char>(sMsg.begin(), sMsg.end()); CBitcoinSecret vchSecret; if (!vchSecret.SetString(GetArg("-alertkey", ""))) { printf("CAlert::SignAlert() : vchSecret.SetString failed\n"); return false; } CKey key = vchSecret.GetKey(); if (!key.Sign(Hash(vchMsg.begin(), vchMsg.end()), vchSig)) { printf("CAlert::SignAlert() : key.Sign failed\n"); return false; } return true; }
bool SignStakeBlock(CBlock &block, CKey &key, vector<const CWalletTx*> &StakeInputs, CWallet *pwallet, MiningCPID& BoincData) { //Append beacon signature to coinbase std::string PublicKey = GlobalCPUMiningCPID.BoincPublicKey; if (!PublicKey.empty()) { std::string sBoincSignature; std::string sError; bool bResult = SignBlockWithCPID(GlobalCPUMiningCPID.cpid, GlobalCPUMiningCPID.lastblockhash, sBoincSignature, sError); if (!bResult) { return error("SignStakeBlock: Failed to sign boinchash -> %s\n", sError); } BoincData.BoincSignature = sBoincSignature; if(fDebug2) LogPrintf("Signing BoincBlock for cpid %s and blockhash %s with sig %s\n", GlobalCPUMiningCPID.cpid, GlobalCPUMiningCPID.lastblockhash, BoincData.BoincSignature); } block.vtx[0].hashBoinc = SerializeBoincBlock(BoincData,block.nVersion); //if (fDebug2) LogPrintf("SignStakeBlock: %s\n",SerializedBoincData.c_str()); //Sign the coinstake transaction unsigned nIn = 0; for (auto const& pcoin : StakeInputs) { if (!SignSignature(*pwallet, *pcoin, block.vtx[1], nIn++)) { return error("SignStakeBlock: failed to sign coinstake"); } } //Sign the whole block block.hashMerkleRoot = block.BuildMerkleTree(); if( !key.Sign(block.GetHash(), block.vchBlockSig) ) { return error("SignStakeBlock: failed to sign block"); } return true; }
bool SendSyncCheckpoint(uint256 hashCheckpoint) { CSyncCheckpoint checkpoint; checkpoint.hashCheckpoint = hashCheckpoint; CDataStream sMsg(SER_NETWORK, PROTOCOL_VERSION); sMsg << (CUnsignedSyncCheckpoint)checkpoint; checkpoint.vchMsg = std::vector<unsigned char>(sMsg.begin(), sMsg.end()); if (CSyncCheckpoint::strMasterPrivKey.empty()) return error("SendSyncCheckpoint: Checkpoint master private key unavailable."); std::vector<unsigned char> vchPrivKey = ParseHex(CSyncCheckpoint::strMasterPrivKey); CKey key; // if key is not correct openssl may crash key.Set(vchPrivKey.begin(), vchPrivKey.end(), false); if (!key.IsValid()) return error("SendSyncCheckpoint: failed to set private key."); if (!key.Sign(Hash(checkpoint.vchMsg.begin(), checkpoint.vchMsg.end()), checkpoint.vchSig)) return error("SendSyncCheckpoint: Unable to sign checkpoint, check private key?"); if(!checkpoint.ProcessSyncCheckpoint(NULL)) { printf("WARNING: SendSyncCheckpoint: Failed to process checkpoint.\n"); return false; } printf("SendSyncCheckpoint: about to relay checkpoint.\n"); // Relay checkpoint { LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) checkpoint.RelayTo(pnode); } return true; }
bool SendSyncCheckpoint(uint256 hashCheckpoint) { printf("SendSyncCheckpoint: hashCheckpoint=%s\n", hashCheckpoint.ToString().c_str()); CSyncCheckpoint checkpoint; checkpoint.hashCheckpoint = hashCheckpoint; CDataStream sMsg(SER_NETWORK, PROTOCOL_VERSION); sMsg << (CUnsignedSyncCheckpoint)checkpoint; checkpoint.vchMsg = std::vector<unsigned char>(sMsg.begin(), sMsg.end()); if (CSyncCheckpoint::strMasterPrivKey.empty()) return error("SendSyncCheckpoint: Checkpoint master key unavailable."); CBitcoinSecret vchSecret; if (!vchSecret.SetString(CSyncCheckpoint::strMasterPrivKey)) return error("SendSyncCheckpoint: Checkpoint master key invalid"); CKey key; bool fCompressed; CSecret secret = vchSecret.GetSecret(fCompressed); key.SetSecret(secret, fCompressed); // if key is not correct openssl may crash if (!key.Sign(Hash2(checkpoint.vchMsg.begin(), checkpoint.vchMsg.end()), checkpoint.vchSig)) return error("SendSyncCheckpoint: Unable to sign checkpoint, check private key?"); if(!checkpoint.ProcessSyncCheckpoint(NULL)) { printf("WARNING: SendSyncCheckpoint: Failed to process checkpoint.\n"); return false; } // Relay checkpoint { LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) checkpoint.RelayTo(pnode); } return true; }
bool PrivateCoin::sign(const uint256& hash, vector<unsigned char>& vchSig) const { CKey key; key.SetPrivKey(privkey, true); return key.Sign(hash, vchSig); }
void ThreadSendAlert() { if (!mapArgs.count("-sendalert") && !mapArgs.count("-printalert")) return; MilliSleep(60*1000); // Wait a minute so we get connected // // Alerts are relayed around the network until nRelayUntil, flood // filling to every node. // After the relay time is past, new nodes are told about alerts // when they connect to peers, until either nExpiration or // the alert is cancelled by a newer alert. // Nodes never save alerts to disk, they are in-memory-only. // CAlert alert; alert.nRelayUntil = GetTime() + 15 * 60; alert.nExpiration = GetTime() + 365 * 60 * 60; alert.nID = 1000; // use https://github.com/zcash/zcash/wiki/specification#assigned-numbers to keep track of alert IDs alert.nCancel = 0; // cancels previous messages up to this ID number // These versions are protocol versions // 170002 : 1.0.0 alert.nMinVer = 170002; alert.nMaxVer = 170002; // // main.cpp: // 1000 for Misc warnings like out of disk space and clock is wrong // 2000 for longer invalid proof-of-work chain // Higher numbers mean higher priority // 4000 or higher will put the RPC into safe mode alert.nPriority = 5000; alert.strComment = ""; alert.strStatusBar = "URGENT: Upgrade required: see https://z.cash"; alert.strRPCError = "URGENT: Upgrade required: see https://z.cash"; // Set specific client version/versions here. If setSubVer is empty, no filtering on subver is done: // alert.setSubVer.insert(std::string("/MagicBean:0.7.2/")); // Sign const CChainParams& chainparams = Params(); std::string networkID = chainparams.NetworkIDString(); bool fIsTestNet = networkID.compare("test") == 0; std::vector<unsigned char> vchTmp(ParseHex(fIsTestNet ? pszTestNetPrivKey : pszPrivKey)); CPrivKey vchPrivKey(vchTmp.begin(), vchTmp.end()); CDataStream sMsg(SER_NETWORK, CLIENT_VERSION); sMsg << *(CUnsignedAlert*)&alert; alert.vchMsg = std::vector<unsigned char>(sMsg.begin(), sMsg.end()); CKey key; if (!key.SetPrivKey(vchPrivKey, false)) { printf("ThreadSendAlert() : key.SetPrivKey failed\n"); return; } if (!key.Sign(Hash(alert.vchMsg.begin(), alert.vchMsg.end()), alert.vchSig)) { printf("ThreadSendAlert() : key.Sign failed\n"); return; } // Test CDataStream sBuffer(SER_NETWORK, CLIENT_VERSION); sBuffer << alert; CAlert alert2; sBuffer >> alert2; if (!alert2.CheckSignature(chainparams.AlertKey())) { printf("ThreadSendAlert() : CheckSignature failed\n"); return; } assert(alert2.vchMsg == alert.vchMsg); assert(alert2.vchSig == alert.vchSig); alert.SetNull(); printf("\nThreadSendAlert:\n"); printf("hash=%s\n", alert2.GetHash().ToString().c_str()); printf("%s\n", alert2.ToString().c_str()); printf("vchMsg=%s\n", HexStr(alert2.vchMsg).c_str()); printf("vchSig=%s\n", HexStr(alert2.vchSig).c_str()); // Confirm if (!mapArgs.count("-sendalert")) return; while (vNodes.size() < 1 && !ShutdownRequested()) MilliSleep(500); if (ShutdownRequested()) return; // Send printf("ThreadSendAlert() : Sending alert\n"); int nSent = 0; { LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) { if (alert2.RelayTo(pnode)) { printf("ThreadSendAlert() : Sent alert to %s\n", pnode->addr.ToString().c_str()); nSent++; } } } printf("ThreadSendAlert() : Alert sent to %d nodes\n", nSent); }
UniValue sendalert2(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 7) throw runtime_error( // 0 1 2 3 4 5 6 "sendalert2 <privatekey> <id> <subverlist> <cancellist> <expire> <priority> <message>\n" "\n" "<privatekey> -> is hex string of alert master private key\n" "<id> ---------> is the unique alert number\n" "<subverlist> -> comma separated list of versions warning applies to\n" "<cancellist> -> comma separated ids of alerts to cancel\n" "<expire> -----> alert expiration in days\n" "<priority> ---> integer, >1000->visible\n" "<message> ---->is the alert text message\n" "\n" "Returns summary of what was done."); CAlert alert; CKey key; alert.strStatusBar = params[6].get_str(); alert.nMinVer = PROTOCOL_VERSION; alert.nMaxVer = PROTOCOL_VERSION; alert.nPriority = params[5].get_int(); alert.nID = params[1].get_int(); alert.nVersion = PROTOCOL_VERSION; alert.nRelayUntil = alert.nExpiration = GetAdjustedTime() + 24*60*60*params[4].get_int(); if(params[2].get_str().length()) { std::vector<std::string> split_subver = split(params[2].get_str(), ","); alert.setSubVer.insert(split_subver.begin(),split_subver.end()); } if(params[3].get_str().length()) { for(std::string &s : split(params[3].get_str(), ",")) { int aver = RoundFromString(s, 0); alert.setCancel.insert(aver); } } CDataStream sMsg(SER_NETWORK, PROTOCOL_VERSION); sMsg << (CUnsignedAlert)alert; alert.vchMsg = vector<unsigned char>(sMsg.begin(), sMsg.end()); vector<unsigned char> vchPrivKey = ParseHex(params[0].get_str()); key.SetPrivKey(CPrivKey(vchPrivKey.begin(), vchPrivKey.end())); // if key is not correct openssl may crash if (!key.Sign(Hash(alert.vchMsg.begin(), alert.vchMsg.end()), alert.vchSig)) throw runtime_error( "Unable to sign alert, check private key?\n"); if(!alert.ProcessAlert()) throw runtime_error( "Failed to process alert.\n"); // Relay alert { LOCK(cs_vNodes); for (auto const& pnode : vNodes) alert.RelayTo(pnode); } UniValue result(UniValue::VOBJ); result.pushKV("Content", alert.ToString()); result.pushKV("Success", true); return result; }