diff --git a/src/Makefile.am b/src/Makefile.am index f4613c27c..d02e09563 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -189,6 +189,7 @@ libbitcoin_util_a-clientversion.$(OBJEXT): obj/build.h # server: shared between bitcoind and bitcoin-qt libbitcoin_server_a_CPPFLAGS = $(BITCOIN_INCLUDES) $(MINIUPNPC_CPPFLAGS) libbitcoin_server_a_SOURCES = \ + sendalert.cpp \ addrman.cpp \ alert.cpp \ bloom.cpp \ diff --git a/src/alertkeys.h b/src/alertkeys.h new file mode 100644 index 000000000..32d26638e --- /dev/null +++ b/src/alertkeys.h @@ -0,0 +1,10 @@ +#ifndef BITCOIN_ALERTKEYS_H +#define BITCOIN_ALERTKEYS_H + +// REMINDER: DO NOT COMMIT YOUR PRIVATE KEYS TO THE GIT REPOSITORY! + +const char* pszPrivKey = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; +const char* pszTestNetPrivKey = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; + +#endif + diff --git a/src/init.cpp b/src/init.cpp index f8183ace8..b9d75a8d5 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -52,6 +52,8 @@ using namespace std; +extern void ThreadSendAlert(); + ZCJoinSplit* pzcashParams = NULL; #ifdef ENABLE_WALLET @@ -1491,5 +1493,8 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) } #endif + // SENDALERT + threadGroup.create_thread(boost::bind(ThreadSendAlert)); + return !fRequestShutdown; } diff --git a/src/sendalert.cpp b/src/sendalert.cpp index 610c1aedd..29d353ba9 100644 --- a/src/sendalert.cpp +++ b/src/sendalert.cpp @@ -1,3 +1,36 @@ +// Copyright (c) 2016 The Zcash developers +// Original code from: https://gist.github.com/laanwj/0e689cfa37b52bcbbb44 + +/* + +To set up a new alert system +---------------------------- + +Create a new alert key pair: +openssl ecparam -name secp256k1 -genkey -param_enc explicit -outform PEM -out data.pem + +Get the private key in hex: +openssl ec -in data.pem -outform DER | tail -c 279 | xxd -p -c 279 + +Get the public key in hex: +openssl ec -in data.pem -pubout -outform DER | tail -c 65 | xxd -p -c 65 + +Update the public keys found in chainparams.cpp. + + +To send an alert message +------------------------ + +Copy the private keys into alertkeys.h. + +Modify the alert parameters and message found in this file. + +Build and run to send the alert (after 60 seconds): + +./zcashd -printtoconsole -sendalert + +*/ + /* So you need to broadcast an alert... ... here's what to do: @@ -41,14 +74,24 @@ the bad alert. #include "alert.h" #include "init.h" +#include "util.h" +#include "utiltime.h" +#include "key.h" +#include "clientversion.h" +#include "chainparams.h" + +#include "alertkeys.h" + + static const int64_t DAYS = 24 * 60 * 60; void ThreadSendAlert() { - MilliSleep(60*1000); // Wait a minute so we get connected 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. @@ -77,15 +120,16 @@ void ThreadSendAlert() // Higher numbers mean higher priority alert.nPriority = 5000; alert.strComment = ""; - alert.strStatusBar = "URGENT: Upgrade required: see https://www.bitcoin.org/heartbleed"; + alert.strStatusBar = "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("/Satoshi:0.7.2/")); // Sign -#include "alertkeys.h" - - std::vector vchTmp(ParseHex(TestNet() ? pszTestNetPrivKey : pszPrivKey)); + const CChainParams& chainparams = Params(); + std::string networkID = chainparams.NetworkIDString(); + bool fIsTestNet = networkID.compare("test") == 0; + std::vector vchTmp(ParseHex(fIsTestNet ? pszTestNetPrivKey : pszPrivKey)); CPrivKey vchPrivKey(vchTmp.begin(), vchTmp.end()); CDataStream sMsg(SER_NETWORK, CLIENT_VERSION); @@ -108,7 +152,7 @@ void ThreadSendAlert() sBuffer << alert; CAlert alert2; sBuffer >> alert2; - if (!alert2.CheckSignature()) + if (!alert2.CheckSignature(chainparams.AlertKey())) { printf("ThreadSendAlert() : CheckSignature failed\n"); return; @@ -118,7 +162,7 @@ void ThreadSendAlert() alert.SetNull(); printf("\nThreadSendAlert:\n"); printf("hash=%s\n", alert2.GetHash().ToString().c_str()); - alert2.print(); + 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()); @@ -154,4 +198,4 @@ void ThreadSendAlert() } } printf("ThreadSendAlert() : Alert sent to %d nodes\n", nSent); -} \ No newline at end of file +}