Skip to content

Commit 4a09e1d

Browse files
committed
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.
1 parent 52d7a54 commit 4a09e1d

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/init.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "addrman.h"
1313
#include "checkpoints.h"
14+
#include "key.h"
1415
#include "main.h"
1516
#include "miner.h"
1617
#include "net.h"
@@ -385,6 +386,23 @@ void ThreadImport(std::vector<boost::filesystem::path> vImportFiles)
385386
}
386387
}
387388

389+
/** Sanity checks
390+
* Ensure that Bitcoin is running in a usable environment with all
391+
* necessary library support.
392+
*/
393+
bool InitSanityCheck(void)
394+
{
395+
if(!ECC_InitSanityCheck()) {
396+
InitError("OpenSSL appears to lack support for elliptic curve cryptography. For more "
397+
"information, visit https://en.bitcoin.it/wiki/OpenSSL_and_EC_Libraries");
398+
return false;
399+
}
400+
401+
// TODO: remaining sanity checks, see #4081
402+
403+
return true;
404+
}
405+
388406
/** Initialize bitcoin.
389407
* @pre Parameters should be parsed and config file should be read.
390408
*/
@@ -586,6 +604,9 @@ bool AppInit2(boost::thread_group& threadGroup)
586604
strWalletFile = GetArg("-wallet", "wallet.dat");
587605
#endif
588606
// ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log
607+
// Sanity check
608+
if (!InitSanityCheck())
609+
return InitError(_("Initialization sanity check failed. Bitcoin Core is shutting down."));
589610

590611
std::string strDataDir = GetDataDir().string();
591612
#ifdef ENABLE_WALLET

src/key.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,3 +631,15 @@ bool CExtPubKey::Derive(CExtPubKey &out, unsigned int nChild) const {
631631
out.nChild = nChild;
632632
return pubkey.Derive(out.pubkey, out.vchChainCode, nChild, vchChainCode);
633633
}
634+
635+
bool ECC_InitSanityCheck() {
636+
EC_KEY *pkey = EC_KEY_new_by_curve_name(NID_secp256k1);
637+
if(pkey == NULL)
638+
return false;
639+
EC_KEY_free(pkey);
640+
641+
// TODO Is there more EC functionality that could be missing?
642+
return true;
643+
}
644+
645+

src/key.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,7 @@ struct CExtKey {
306306
void SetMaster(const unsigned char *seed, unsigned int nSeedLen);
307307
};
308308

309+
/** Check that required EC support is available at runtime */
310+
bool ECC_InitSanityCheck(void);
311+
309312
#endif

0 commit comments

Comments
 (0)