Skip to content

Commit d01574f

Browse files
committed
Merge pull request #4277
4a09e1d key.cpp: fail with a friendlier message on missing ssl EC support (Andrew Poelstra)
2 parents 4e45932 + 4a09e1d commit d01574f

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"
@@ -394,6 +395,23 @@ void ThreadImport(std::vector<boost::filesystem::path> vImportFiles)
394395
}
395396
}
396397

398+
/** Sanity checks
399+
* Ensure that Bitcoin is running in a usable environment with all
400+
* necessary library support.
401+
*/
402+
bool InitSanityCheck(void)
403+
{
404+
if(!ECC_InitSanityCheck()) {
405+
InitError("OpenSSL appears to lack support for elliptic curve cryptography. For more "
406+
"information, visit https://en.bitcoin.it/wiki/OpenSSL_and_EC_Libraries");
407+
return false;
408+
}
409+
410+
// TODO: remaining sanity checks, see #4081
411+
412+
return true;
413+
}
414+
397415
/** Initialize bitcoin.
398416
* @pre Parameters should be parsed and config file should be read.
399417
*/
@@ -598,6 +616,9 @@ bool AppInit2(boost::thread_group& threadGroup)
598616
std::string strWalletFile = GetArg("-wallet", "wallet.dat");
599617
#endif
600618
// ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log
619+
// Sanity check
620+
if (!InitSanityCheck())
621+
return InitError(_("Initialization sanity check failed. Bitcoin Core is shutting down."));
601622

602623
std::string strDataDir = GetDataDir().string();
603624
#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)