From f6f4c83382665df656f3f0d8bcb55831a354d45c Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Mon, 2 Jun 2014 16:21:03 -0700 Subject: key.cpp: fail with a friendlier message on missing ssl EC support Previously if bitcoind is linked with an OpenSSL which is compiled without EC support, this is seen as an assertion failure "pKey != NULL" at key.cpp:134, which occurs after several seconds. It is an esoteric piece of knowledge to interpret this as "oops, I linked with the wrong OpenSSL", and because of the delay it may not even be noticed. The new output is : OpenSSL appears to lack support for elliptic curve cryptography. For more information, visit https://en.bitcoin.it/wiki/OpenSSL_and_EC_Libraries : Initialization sanity check failed. Bitcoin Core is shutting down. which occurs immediately after attempted startup. This also blocks in an InitSanityCheck() function which currently only checks for EC support but should eventually do more. See #4081. Rebased-From: 4a09e1d --- src/init.cpp | 21 +++++++++++++++++++++ src/key.cpp | 12 ++++++++++++ src/key.h | 3 +++ 3 files changed, 36 insertions(+) (limited to 'src') diff --git a/src/init.cpp b/src/init.cpp index d90ff457cd..64b835c9aa 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -11,6 +11,7 @@ #include "addrman.h" #include "checkpoints.h" +#include "key.h" #include "main.h" #include "miner.h" #include "net.h" @@ -386,6 +387,23 @@ void ThreadImport(std::vector vImportFiles) } } +/** Sanity checks + * Ensure that Bitcoin is running in a usable environment with all + * necessary library support. + */ +bool InitSanityCheck(void) +{ + if(!ECC_InitSanityCheck()) { + InitError("OpenSSL appears to lack support for elliptic curve cryptography. For more " + "information, visit https://en.bitcoin.it/wiki/OpenSSL_and_EC_Libraries"); + return false; + } + + // TODO: remaining sanity checks, see #4081 + + return true; +} + /** Initialize bitcoin. * @pre Parameters should be parsed and config file should be read. */ @@ -587,6 +605,9 @@ bool AppInit2(boost::thread_group& threadGroup) strWalletFile = GetArg("-wallet", "wallet.dat"); #endif // ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log + // Sanity check + if (!InitSanityCheck()) + return InitError(_("Initialization sanity check failed. Bitcoin Core is shutting down.")); std::string strDataDir = GetDataDir().string(); #ifdef ENABLE_WALLET diff --git a/src/key.cpp b/src/key.cpp index b57b7c506c..5b261bb285 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -616,3 +616,15 @@ bool CExtPubKey::Derive(CExtPubKey &out, unsigned int nChild) const { out.nChild = nChild; return pubkey.Derive(out.pubkey, out.vchChainCode, nChild, vchChainCode); } + +bool ECC_InitSanityCheck() { + EC_KEY *pkey = EC_KEY_new_by_curve_name(NID_secp256k1); + if(pkey == NULL) + return false; + EC_KEY_free(pkey); + + // TODO Is there more EC functionality that could be missing? + return true; +} + + diff --git a/src/key.h b/src/key.h index cf1165d3d0..67206ba914 100644 --- a/src/key.h +++ b/src/key.h @@ -307,4 +307,7 @@ struct CExtKey { void SetMaster(const unsigned char *seed, unsigned int nSeedLen); }; +/** Check that required EC support is available at runtime */ +bool ECC_InitSanityCheck(void); + #endif -- cgit v1.2.3