From 2206d0ef654754de75ae498f1946a97267fb8bca Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Wed, 1 Jun 2016 17:56:00 -0700 Subject: [PATCH] Remove unused functions & cleanup code: * Remove superseded ECDSA key functions * Remove unused string helper functions * Remove beast::FatalError * Cleanup SSL context generation * Improve parsing of RPC commands during startup --- Builds/VisualStudio2015/RippleD.vcxproj | 15 --- .../VisualStudio2015/RippleD.vcxproj.filters | 18 ---- src/ripple/app/main/Application.cpp | 79 ++++++++++---- src/ripple/app/main/Application.h | 2 +- src/ripple/app/main/Main.cpp | 56 +++------- src/ripple/app/misc/Validations.cpp | 62 +---------- src/ripple/app/misc/Validations.h | 9 -- src/ripple/basics/StringUtilities.h | 2 - src/ripple/basics/impl/StringUtilities.cpp | 32 ------ src/ripple/basics/impl/make_SSLContext.cpp | 101 ++++++++---------- src/ripple/beast/core/FatalError.cpp | 65 ----------- src/ripple/beast/core/FatalError.h | 45 -------- src/ripple/beast/core/core.unity.cpp | 2 - src/ripple/core/Config.h | 4 - src/ripple/core/impl/Config.cpp | 19 ---- src/ripple/crypto/impl/ECDSAKey.cpp | 91 ---------------- src/ripple/crypto/impl/ECDSAKey.h | 36 ------- .../crypto/impl/GenerateDeterministicKey.cpp | 4 +- src/ripple/crypto/tests/CKey.test.cpp | 58 ---------- src/ripple/protocol/impl/BuildInfo.cpp | 44 +++----- src/ripple/unity/crypto.cpp | 3 - 21 files changed, 135 insertions(+), 612 deletions(-) delete mode 100644 src/ripple/beast/core/FatalError.cpp delete mode 100644 src/ripple/beast/core/FatalError.h delete mode 100644 src/ripple/crypto/impl/ECDSAKey.cpp delete mode 100644 src/ripple/crypto/impl/ECDSAKey.h delete mode 100644 src/ripple/crypto/tests/CKey.test.cpp diff --git a/Builds/VisualStudio2015/RippleD.vcxproj b/Builds/VisualStudio2015/RippleD.vcxproj index 90267b318d..4413ed27be 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj +++ b/Builds/VisualStudio2015/RippleD.vcxproj @@ -1551,11 +1551,6 @@ True - - True - - - @@ -2099,12 +2094,6 @@ True True - - True - True - - - True True @@ -2135,10 +2124,6 @@ - - True - True - True True diff --git a/Builds/VisualStudio2015/RippleD.vcxproj.filters b/Builds/VisualStudio2015/RippleD.vcxproj.filters index 2949e6b0ec..d436b05cf3 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2015/RippleD.vcxproj.filters @@ -235,9 +235,6 @@ {8EF07519-1C32-2E82-D707-702EB0157733} - - {ACAAFBB2-022D-2EAB-80CD-FBE3D9432F17} - {BEDCC703-A2C8-FF25-7E1E-3471BD39ED98} @@ -2049,12 +2046,6 @@ ripple\beast\core - - ripple\beast\core - - - ripple\beast\core - ripple\beast\core @@ -2631,12 +2622,6 @@ ripple\crypto\impl - - ripple\crypto\impl - - - ripple\crypto\impl - ripple\crypto\impl @@ -2667,9 +2652,6 @@ ripple\crypto - - ripple\crypto\tests - ripple\json\impl diff --git a/src/ripple/app/main/Application.cpp b/src/ripple/app/main/Application.cpp index e777877997..e1d6be53a1 100644 --- a/src/ripple/app/main/Application.cpp +++ b/src/ripple/app/main/Application.cpp @@ -67,6 +67,11 @@ #include #include #include +#include +#include +#include +#include +#include #include #include #include @@ -527,7 +532,7 @@ public: //-------------------------------------------------------------------------- - void setup() override; + bool setup() override; void doStart() override; void run() override; bool isShutdown() override; @@ -861,14 +866,6 @@ public: //------------------------------------------------------------------------------ - void exitWithCode(int code) - { - StopSustain(); - // VFALCO This breaks invariants: automatic objects - // will not have destructors called. - std::exit(code); - } - void onDeadlineTimer (DeadlineTimer& timer) override { if (timer == m_entropyTimer) @@ -925,7 +922,7 @@ public: private: void addTxnSeqField(); void addValidationSeqFields(); - void updateTables (); + bool updateTables (); void startGenesisLedger (); std::shared_ptr @@ -947,7 +944,7 @@ private: // Or better yet refactor these initializations into RAII classes // which are members of the Application object. // -void ApplicationImp::setup() +bool ApplicationImp::setup() { // VFALCO NOTE: 0 means use heuristics to determine the thread count. m_jobQueue->setThreadCount (0, config_->standalone()); @@ -983,7 +980,7 @@ void ApplicationImp::setup() if (!initSqliteDbs ()) { JLOG(m_journal.fatal()) << "Cannot create database connections!"; - exitWithCode(3); + return false; } getLedgerDB ().getSession () @@ -997,7 +994,8 @@ void ApplicationImp::setup() mTxnDB->setupCheckpointing (m_jobQueue.get(), logs()); mLedgerDB->setupCheckpointing (m_jobQueue.get(), logs()); - updateTables (); + if (!updateTables ()) + return false; // Configure the amendments the server supports { @@ -1041,7 +1039,7 @@ void ApplicationImp::setup() { JLOG(m_journal.error()) << "The specified ledger could not be loaded."; - exitWithCode(-1); + return false; } } else if (startUp == Config::NETWORK) @@ -1064,13 +1062,13 @@ void ApplicationImp::setup() if (!cluster_->load (config().section(SECTION_CLUSTER_NODES))) { JLOG(m_journal.fatal()) << "Invalid entry in cluster configuration."; - Throw(); + return false; } if (!validators_->load (config().section (SECTION_VALIDATORS))) { JLOG(m_journal.fatal()) << "Invalid entry in validator configuration."; - Throw(); + return false; } if (validators_->size () == 0 && !config_->standalone()) @@ -1102,7 +1100,8 @@ void ApplicationImp::setup() // start first consensus round if (! m_networkOPs->beginConsensus(m_ledgerMaster->getClosedLedger()->info().hash)) { - LogicError ("Unable to start consensus"); + JLOG(m_journal.fatal()) << "Unable to start consensus"; + return false; } m_overlay->setupValidatorKeyManifests (*config_, getWalletDB ()); @@ -1125,7 +1124,7 @@ void ApplicationImp::setup() { JLOG(m_journal.fatal()) << "Could not create Websocket for [" << port.name << "]"; - Throw (); + return false; } websocketServers_.emplace_back (std::move (server)); } @@ -1153,6 +1152,42 @@ void ApplicationImp::setup() m_networkOPs->setStandAlone (); } + + // + // Execute start up rpc commands. + // + for (auto cmd : config_->section(SECTION_RPC_STARTUP).lines()) + { + Json::Reader jrReader; + Json::Value jvCommand; + + if (! jrReader.parse (cmd, jvCommand)) + { + JLOG(m_journal.fatal()) << + "Couldn't parse entry in [" << SECTION_RPC_STARTUP << + "]: '" << cmd; + } + + if (!config_->quiet()) + { + JLOG(m_journal.fatal()) << "Startup RPC: " << jvCommand << std::endl; + } + + Resource::Charge loadType = Resource::feeReferenceRPC; + Resource::Consumer c; + RPC::Context context { journal ("RPCHandler"), jvCommand, *this, + loadType, getOPs (), getLedgerMaster(), c, Role::ADMIN }; + + Json::Value jvResult; + RPC::doCommand (context, jvResult); + + if (!config_->quiet()) + { + JLOG(m_journal.fatal()) << "Result: " << jvResult << std::endl; + } + } + + return true; } void @@ -1812,12 +1847,12 @@ void ApplicationImp::addValidationSeqFields () tr.commit(); } -void ApplicationImp::updateTables () +bool ApplicationImp::updateTables () { if (config_->section (ConfigSection::nodeDatabase ()).empty ()) { JLOG (m_journal.fatal()) << "The [node_db] configuration setting has been updated and must be set"; - exitWithCode(1); + return false; } // perform any needed table updates @@ -1828,7 +1863,7 @@ void ApplicationImp::updateTables () if (schemaHas (getTxnDB (), "AccountTransactions", 0, "PRIMARY", m_journal)) { JLOG (m_journal.fatal()) << "AccountTransactions database should not have a primary key"; - exitWithCode(1); + return false; } addValidationSeqFields (); @@ -1848,6 +1883,8 @@ void ApplicationImp::updateTables () getNodeStore().import (*source); } + + return true; } //------------------------------------------------------------------------------ diff --git a/src/ripple/app/main/Application.h b/src/ripple/app/main/Application.h index 815ed41ae6..551457cf11 100644 --- a/src/ripple/app/main/Application.h +++ b/src/ripple/app/main/Application.h @@ -92,7 +92,7 @@ public: virtual ~Application () = default; - virtual void setup() = 0; + virtual bool setup() = 0; virtual void doStart() = 0; virtual void run() = 0; virtual bool isShutdown () = 0; diff --git a/src/ripple/app/main/Main.cpp b/src/ripple/app/main/Main.cpp index e11068c093..fcd048394a 100644 --- a/src/ripple/app/main/Main.cpp +++ b/src/ripple/app/main/Main.cpp @@ -110,43 +110,6 @@ adjustDescriptorLimit(int needed, beast::Journal j) return true; } -void startServer (Application& app) -{ - // - // Execute start up rpc commands. - // - if (app.config().RPC_STARTUP.isArray ()) - { - for (int i = 0; i != app.config().RPC_STARTUP.size (); ++i) - { - Json::Value const& jvCommand = app.config().RPC_STARTUP[i]; - - if (!app.config().quiet()) - std::cerr << "Startup RPC: " << jvCommand << std::endl; - - Resource::Charge loadType = Resource::feeReferenceRPC; - Resource::Consumer c; - RPC::Context context {app.journal ("RPCHandler"), jvCommand, app, - loadType, app.getOPs (), app.getLedgerMaster(), c, Role::ADMIN}; - - Json::Value jvResult; - RPC::doCommand (context, jvResult); - - if (!app.config().quiet()) - std::cerr << "Result: " << jvResult << std::endl; - } - } - - app.doStart(); - // Block until we get a stop RPC. - app.run(); - - // Try to write out some entropy to use the next time we start. - auto entropy = getEntropyFile (app.config()); - if (!entropy.empty ()) - crypto_prng().save_state(entropy.string ()); -} - void printHelp (const po::options_description& desc) { std::cerr @@ -468,7 +431,12 @@ int run (int argc, char** argv) std::move(config), std::move(logs), std::move(timeKeeper)); - app->setup (); + + if (!app->setup ()) + { + StopSustain(); + return -1; + } // With our configuration parsed, ensure we have // enough file descriptors available: @@ -480,7 +448,17 @@ int run (int argc, char** argv) return -1; } - startServer (*app); + // Start the server + app->doStart(); + + // Block until we get a stop RPC. + app->run(); + + // Try to write out some entropy to use the next time we start. + auto entropy = getEntropyFile (app->config()); + if (!entropy.empty ()) + crypto_prng().save_state(entropy.string ()); + return 0; } diff --git a/src/ripple/app/misc/Validations.cpp b/src/ripple/app/misc/Validations.cpp index f3354f5c24..7eb172a93b 100644 --- a/src/ripple/app/misc/Validations.cpp +++ b/src/ripple/app/misc/Validations.cpp @@ -48,7 +48,7 @@ private: TaggedCache mValidations; ValidationSet mCurrentValidations; - ValidationVector mStaleValidations; + std::vector mStaleValidations; bool mWriting; beast::Journal j_; @@ -156,12 +156,6 @@ private: return false; } - void tune (int size, int age) override - { - mValidations.setTargetSize (size); - mValidations.setTargetAge (age); - } - ValidationSet getValidations (uint256 const& ledger) override { { @@ -191,58 +185,6 @@ private: (val->getSeenTime() < (now + VALIDATION_VALID_LOCAL))); } - void getValidationCount (uint256 const& ledger, bool currentOnly, - int& trusted, int& untrusted) override - { - trusted = untrusted = 0; - ScopedLockType sl (mLock); - auto set = findSet (ledger); - - if (set) - { - for (auto& it: *set) - { - bool isTrusted = it.second->isTrusted (); - - if (isTrusted && currentOnly && ! current (it.second)) - { - JLOG (j_.trace()) << "VC: Untrusted due to time " << ledger; - isTrusted = false; - } - - if (isTrusted) - ++trusted; - else - ++untrusted; - } - } - - JLOG (j_.trace()) << "VC: " << ledger << "t:" << trusted << " u:" << untrusted; - } - - void getValidationTypes (uint256 const& ledger, int& full, int& partial) override - { - full = partial = 0; - ScopedLockType sl (mLock); - auto set = findSet (ledger); - - if (set) - { - for (auto& it:*set) - { - if (it.second->isTrusted ()) - { - if (it.second->isFull ()) - ++full; - else - ++partial; - } - } - } - - JLOG (j_.trace()) << "VC: " << ledger << "f:" << full << " p:" << partial; - } - int getTrustedValidationCount (uint256 const& ledger) override { int trusted = 0; @@ -470,7 +412,7 @@ private: while (!mStaleValidations.empty ()) { - ValidationVector vector; + std::vector vector; vector.reserve (512); mStaleValidations.swap (vector); diff --git a/src/ripple/app/misc/Validations.h b/src/ripple/app/misc/Validations.h index 075e606b73..47af858b58 100644 --- a/src/ripple/app/misc/Validations.h +++ b/src/ripple/app/misc/Validations.h @@ -35,7 +35,6 @@ using ValidationSet = hash_map; using ValidationCounter = std::pair; using LedgerToValidationCounter = hash_map; -using ValidationVector = std::vector; class Validations { @@ -48,12 +47,6 @@ public: virtual ValidationSet getValidations (uint256 const& ledger) = 0; - virtual void getValidationCount ( - uint256 const& ledger, bool currentOnly, int& trusted, - int& untrusted) = 0; - virtual void getValidationTypes ( - uint256 const& ledger, int& full, int& partial) = 0; - virtual int getTrustedValidationCount (uint256 const& ledger) = 0; /** Returns fees reported by trusted validators in the given ledger. */ @@ -76,8 +69,6 @@ public: virtual std::list getCurrentTrustedValidations () = 0; - virtual void tune (int size, int age) = 0; - virtual void flush () = 0; virtual void sweep () = 0; diff --git a/src/ripple/basics/StringUtilities.h b/src/ripple/basics/StringUtilities.h index 258336f3a1..44cb597f2b 100644 --- a/src/ripple/basics/StringUtilities.h +++ b/src/ripple/basics/StringUtilities.h @@ -88,8 +88,6 @@ std::pair strUnHex (std::string const& strSrc); Blob strCopy (std::string const& strSrc); std::string strCopy (Blob const& vucSrc); -bool parseIpPort (std::string const& strSource, std::string& strIP, int& iPort); - bool parseUrl (std::string const& strUrl, std::string& strScheme, std::string& strDomain, int& iPort, std::string& strPath); diff --git a/src/ripple/basics/impl/StringUtilities.cpp b/src/ripple/basics/impl/StringUtilities.cpp index df7a20666a..17b8072da8 100644 --- a/src/ripple/basics/impl/StringUtilities.cpp +++ b/src/ripple/basics/impl/StringUtilities.cpp @@ -132,38 +132,6 @@ std::string strCopy (Blob const& vucSrc) } -// -// IP Port parsing -// -// <-- iPort: "" = -1 -// VFALCO TODO Make this not require boost... and especially boost::asio -bool parseIpPort (std::string const& strSource, std::string& strIP, int& iPort) -{ - boost::smatch smMatch; - bool bValid = false; - - static boost::regex reEndpoint ("\\`\\s*(\\S+)(?:\\s+(\\d+))?\\s*\\'"); - - if (boost::regex_match (strSource, smMatch, reEndpoint)) - { - boost::system::error_code err; - std::string strIPRaw = smMatch[1]; - std::string strPortRaw = smMatch[2]; - - boost::asio::ip::address addrIP = boost::asio::ip::address::from_string (strIPRaw, err); - - bValid = !err; - - if (bValid) - { - strIP = addrIP.to_string (); - iPort = strPortRaw.empty () ? -1 : beast::lexicalCastThrow (strPortRaw); - } - } - - return bValid; -} - // TODO Callers should be using beast::URL and beast::parse_URL instead. bool parseUrl (std::string const& strUrl, std::string& strScheme, std::string& strDomain, int& iPort, std::string& strPath) { diff --git a/src/ripple/basics/impl/make_SSLContext.cpp b/src/ripple/basics/impl/make_SSLContext.cpp index dcd83bd18a..fffbe5d8c6 100644 --- a/src/ripple/basics/impl/make_SSLContext.cpp +++ b/src/ripple/basics/impl/make_SSLContext.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -82,7 +81,7 @@ static rsa_ptr rsa_generate_key (int n_bits) RSA* rsa = RSA_generate_key (n_bits, RSA_F4, nullptr, nullptr); if (rsa == nullptr) - Throw ("RSA_generate_key failed"); + LogicError ("RSA_generate_key failed"); return rsa_ptr (rsa); } @@ -96,7 +95,7 @@ static evp_pkey_ptr evp_pkey_new() EVP_PKEY* evp_pkey = EVP_PKEY_new(); if (evp_pkey == nullptr) - Throw ("EVP_PKEY_new failed"); + LogicError ("EVP_PKEY_new failed"); return evp_pkey_ptr (evp_pkey); } @@ -104,7 +103,7 @@ static evp_pkey_ptr evp_pkey_new() static void evp_pkey_assign_rsa (EVP_PKEY* evp_pkey, rsa_ptr&& rsa) { if (! EVP_PKEY_assign_RSA (evp_pkey, rsa.get())) - Throw ("EVP_PKEY_assign_RSA failed"); + LogicError ("EVP_PKEY_assign_RSA failed"); rsa.release(); } @@ -118,7 +117,7 @@ static x509_ptr x509_new() X509* x509 = X509_new(); if (x509 == nullptr) - Throw ("X509_new failed"); + LogicError ("X509_new failed"); X509_set_version (x509, NID_X509); @@ -139,19 +138,19 @@ static void x509_set_pubkey (X509* x509, EVP_PKEY* evp_pkey) static void x509_sign (X509* x509, EVP_PKEY* evp_pkey) { if (! X509_sign (x509, evp_pkey, EVP_sha1())) - Throw ("X509_sign failed"); + LogicError ("X509_sign failed"); } static void ssl_ctx_use_certificate (SSL_CTX* const ctx, x509_ptr& cert) { if (SSL_CTX_use_certificate (ctx, cert.release()) <= 0) - Throw ("SSL_CTX_use_certificate failed"); + LogicError ("SSL_CTX_use_certificate failed"); } static void ssl_ctx_use_privatekey (SSL_CTX* const ctx, evp_pkey_ptr& key) { if (SSL_CTX_use_PrivateKey (ctx, key.release()) <= 0) - Throw ("SSL_CTX_use_PrivateKey failed"); + LogicError ("SSL_CTX_use_PrivateKey failed"); } // track when SSL connections have last negotiated @@ -174,9 +173,8 @@ make_DH(std::string const& params) auto const* p ( reinterpret_cast (¶ms [0])); DH* const dh = d2i_DHparams (nullptr, &p, params.size ()); - if (p == nullptr) - beast::FatalError ("d2i_DHparams returned nullptr.", - __FILE__, __LINE__); + if (dh == nullptr) + LogicError ("d2i_DHparams returned nullptr."); return dh_ptr(dh); } @@ -289,7 +287,7 @@ getDH (int keyLength) } else { - beast::FatalError ("unsupported key length", __FILE__, __LINE__); + LogicError ("unsupported key length."); } return nullptr; @@ -364,36 +362,16 @@ error_message (std::string const& what, return ss.str(); } -static -void -initCommon (boost::asio::ssl::context& context) -{ - context.set_options ( - boost::asio::ssl::context::default_workarounds | - boost::asio::ssl::context::no_sslv2 | - boost::asio::ssl::context::no_sslv3 | - boost::asio::ssl::context::single_dh_use); - - SSL_CTX_set_tmp_dh_callback ( - context.native_handle (), - tmp_dh_handler); - - SSL_CTX_set_info_callback ( - context.native_handle (), - info_handler); -} - static void initAnonymous ( boost::asio::ssl::context& context, std::string const& cipherList) { - initCommon(context); int const result = SSL_CTX_set_cipher_list ( context.native_handle (), cipherList.c_str ()); if (result != 1) - Throw ("SSL_CTX_set_cipher_list failed"); + LogicError ("SSL_CTX_set_cipher_list failed"); using namespace openssl; @@ -414,8 +392,6 @@ void initAuthenticated (boost::asio::ssl::context& context, std::string key_file, std::string cert_file, std::string chain_file) { - initCommon (context); - SSL_CTX* const ssl = context.native_handle (); bool cert_set = false; @@ -429,9 +405,8 @@ initAuthenticated (boost::asio::ssl::context& context, if (ec) { - beast::FatalError (error_message ( - "Problem with SSL certificate file.", ec).c_str(), - __FILE__, __LINE__); + LogicError (error_message ( + "Problem with SSL certificate file.", ec).c_str()); } cert_set = true; @@ -444,10 +419,9 @@ initAuthenticated (boost::asio::ssl::context& context, if (!f) { - beast::FatalError (error_message ( + LogicError (error_message ( "Problem opening SSL chain file.", boost::system::error_code (errno, - boost::system::generic_category())).c_str(), - __FILE__, __LINE__); + boost::system::generic_category())).c_str()); } try @@ -462,16 +436,14 @@ initAuthenticated (boost::asio::ssl::context& context, if (! cert_set) { if (SSL_CTX_use_certificate (ssl, x) != 1) - beast::FatalError ("Problem retrieving SSL certificate from chain file.", - __FILE__, __LINE__); + LogicError ("Problem retrieving SSL certificate from chain file."); cert_set = true; } else if (SSL_CTX_add_extra_chain_cert (ssl, x) != 1) { X509_free (x); - beast::FatalError ("Problem adding SSL chain certificate.", - __FILE__, __LINE__); + LogicError ("Problem adding SSL chain certificate."); } } @@ -480,8 +452,7 @@ initAuthenticated (boost::asio::ssl::context& context, catch (std::exception const&) { fclose (f); - beast::FatalError ("Reading the SSL chain file generated an exception.", - __FILE__, __LINE__); + LogicError ("Reading the SSL chain file generated an exception."); } } @@ -494,19 +465,37 @@ initAuthenticated (boost::asio::ssl::context& context, if (ec) { - beast::FatalError (error_message ( - "Problem using the SSL private key file.", ec).c_str(), - __FILE__, __LINE__); + LogicError (error_message ( + "Problem using the SSL private key file.", ec).c_str()); } } if (SSL_CTX_check_private_key (ssl) != 1) { - beast::FatalError ("Invalid key in SSL private key file.", - __FILE__, __LINE__); + LogicError ("Invalid key in SSL private key file."); } } +std::shared_ptr +get_context () +{ + auto c = std::make_shared ( + boost::asio::ssl::context::sslv23); + + c->set_options ( + boost::asio::ssl::context::default_workarounds | + boost::asio::ssl::context::no_sslv2 | + boost::asio::ssl::context::no_sslv3 | + boost::asio::ssl::context::single_dh_use); + + SSL_CTX_set_tmp_dh_callback ( + c->native_handle (), tmp_dh_handler); + SSL_CTX_set_info_callback ( + c->native_handle (), info_handler); + + return c; +} + } // detail } // openssl @@ -517,9 +506,7 @@ make_SSLContext() static auto const context = []() { - auto const context = std::make_shared< - boost::asio::ssl::context>( - boost::asio::ssl::context::sslv23); + auto const context = openssl::detail::get_context(); // By default, allow anonymous DH. openssl::detail::initAnonymous( *context, "ALL:!LOW:!EXP:!MD5:@STRENGTH"); @@ -535,9 +522,7 @@ std::shared_ptr make_SSLContextAuthed (std::string const& key_file, std::string const& cert_file, std::string const& chain_file) { - std::shared_ptr context = - std::make_shared ( - boost::asio::ssl::context::sslv23); + auto const context = openssl::detail::get_context(); openssl::detail::initAuthenticated(*context, key_file, cert_file, chain_file); return context; diff --git a/src/ripple/beast/core/FatalError.cpp b/src/ripple/beast/core/FatalError.cpp deleted file mode 100644 index 8e1e8854a9..0000000000 --- a/src/ripple/beast/core/FatalError.cpp +++ /dev/null @@ -1,65 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#include - -#include -#include -#include -#include -#include - -namespace beast { - -//------------------------------------------------------------------------------ -[[noreturn]] -void -FatalError ( - char const* message, - char const* file, - int line) noexcept -{ - static std::mutex gate; - - // We only allow one thread to report a fatal error. Other threads that - // encounter fatal errors while we are reporting get blocked here. - std::lock_guard lock(gate); - - std::cerr << "An error has occurred. The application will terminate.\n"; - - if (message != nullptr && message [0] != 0) - std::cerr << "Message: " << message << '\n'; - - if (file != nullptr && file [0] != 0) - std::cerr << " File: " << file << ":" << line << '\n'; - - auto const backtrace = getStackBacktrace (); - - if (!backtrace.empty ()) - { - std::cerr << " Stack:" << std::endl; - - for (auto const& frame : backtrace) - std::cerr << " " << frame << '\n'; - } - - std::abort (); -} - -} // beast diff --git a/src/ripple/beast/core/FatalError.h b/src/ripple/beast/core/FatalError.h deleted file mode 100644 index 3d08ec6ee9..0000000000 --- a/src/ripple/beast/core/FatalError.h +++ /dev/null @@ -1,45 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#ifndef BEAST_MODULE_CORE_DIAGNOSTIC_FATALERROR_H_INCLUDED -#define BEAST_MODULE_CORE_DIAGNOSTIC_FATALERROR_H_INCLUDED - -namespace beast -{ - -/** Signal a fatal error. - - A fatal error indicates that the program has encountered an unexpected - situation and cannot continue safely. Reasons for raising a fatal error - would be to protect data integrity, prevent valuable resources from being - wasted, or to ensure that the user does not experience undefined behavior. - - If multiple threads raise an error, only one will succeed while the others - will be blocked before the process terminates. -*/ -[[noreturn]] -void -FatalError ( - char const* message, - char const* file = nullptr, - int line = 0) noexcept; - -} // beast - -#endif diff --git a/src/ripple/beast/core/core.unity.cpp b/src/ripple/beast/core/core.unity.cpp index e354e528c7..2c0aed3853 100644 --- a/src/ripple/beast/core/core.unity.cpp +++ b/src/ripple/beast/core/core.unity.cpp @@ -51,7 +51,6 @@ // Order matters, since headers don't have their own #include lines. // Add new includes to the bottom. -#include #include #include @@ -193,7 +192,6 @@ #endif -#include #include #include #include diff --git a/src/ripple/core/Config.h b/src/ripple/core/Config.h index d13c4f8a05..d55e8eab1d 100644 --- a/src/ripple/core/Config.h +++ b/src/ripple/core/Config.h @@ -25,7 +25,6 @@ #include // VFALCO Breaks levelization #include // NIKB Breaks levelization (TEMP) #include // NIKB Breaks levelization (TEMP) -#include #include #include #include @@ -148,9 +147,6 @@ public: std::chrono::seconds WEBSOCKET_PING_FREQ = 5min; - // RPC parameters - Json::Value RPC_STARTUP; - // Path searching int PATH_SEARCH_OLD = 7; int PATH_SEARCH = 7; diff --git a/src/ripple/core/impl/Config.cpp b/src/ripple/core/impl/Config.cpp index 4d2ebf3a4c..9aabce2998 100644 --- a/src/ripple/core/impl/Config.cpp +++ b/src/ripple/core/impl/Config.cpp @@ -302,25 +302,6 @@ void Config::loadFromString (std::string const& fileContents) if (auto s = getIniFileSection (secConfig, SECTION_SNTP)) SNTP_SERVERS = *s; - if (auto s = getIniFileSection (secConfig, SECTION_RPC_STARTUP)) - { - RPC_STARTUP = Json::arrayValue; - - for (auto const& strJson : *s) - { - Json::Reader jrReader; - Json::Value jvCommand; - - if (! jrReader.parse (strJson, jvCommand)) - Throw ( - boost::str (boost::format ( - "Couldn't parse [" SECTION_RPC_STARTUP "] command: %s") - % strJson)); - - RPC_STARTUP.append (jvCommand); - } - } - { std::string dbPath; if (getSingleSection (secConfig, "database_path", dbPath, j_)) diff --git a/src/ripple/crypto/impl/ECDSAKey.cpp b/src/ripple/crypto/impl/ECDSAKey.cpp deleted file mode 100644 index c94fcfd162..0000000000 --- a/src/ripple/crypto/impl/ECDSAKey.cpp +++ /dev/null @@ -1,91 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2012, 2013 Ripple Labs Inc. - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -// Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2011 The Bitcoin developers -// Distributed under the MIT/X11 software license, see the accompanying -// file license.txt or http://www.opensource.org/licenses/mit-license.php. - -#include -#include -#include -#include -#include - -namespace ripple { - -using openssl::ec_key; - -static EC_KEY* new_initialized_EC_KEY() -{ - EC_KEY* key = EC_KEY_new_by_curve_name (NID_secp256k1); - - if (key == nullptr) - Throw ( - "new_initialized_EC_KEY() : EC_KEY_new_by_curve_name failed"); - - EC_KEY_set_conv_form (key, POINT_CONVERSION_COMPRESSED); - - return key; -} - -ec_key ECDSAPrivateKey (uint256 const& serialized) -{ - BIGNUM* bn = BN_bin2bn (serialized.begin(), serialized.size(), nullptr); - - if (bn == nullptr) - Throw ("ec_key::ec_key: BN_bin2bn failed"); - - EC_KEY* key = new_initialized_EC_KEY(); - ec_key::pointer_t ptr = nullptr; - - const bool ok = EC_KEY_set_private_key (key, bn); - - BN_clear_free (bn); - - if (ok) - ptr = (ec_key::pointer_t) key; - else - EC_KEY_free (key); - - return ec_key(ptr); -} - -ec_key ECDSAPublicKey (std::uint8_t const* data, std::size_t size) -{ - EC_KEY* key = new_initialized_EC_KEY(); - ec_key::pointer_t ptr = nullptr; - - if (o2i_ECPublicKey (&key, &data, size) != nullptr) - { - EC_KEY_set_conv_form (key, POINT_CONVERSION_COMPRESSED); - ptr = (ec_key::pointer_t) key; - } - else - EC_KEY_free (key); - - return ec_key(ptr); -} - -ec_key ECDSAPublicKey (Blob const& serialized) -{ - return ECDSAPublicKey (&serialized[0], serialized.size()); -} - -} // ripple diff --git a/src/ripple/crypto/impl/ECDSAKey.h b/src/ripple/crypto/impl/ECDSAKey.h deleted file mode 100644 index 78b8070261..0000000000 --- a/src/ripple/crypto/impl/ECDSAKey.h +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2014 Ripple Labs Inc. - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#ifndef RIPPLE_ECDSAKEY_H -#define RIPPLE_ECDSAKEY_H - -#include -#include -#include - -namespace ripple { - -openssl::ec_key ECDSAPrivateKey (uint256 const& serialized); -openssl::ec_key ECDSAPublicKey (Blob const& serialized); - -openssl::ec_key ECDSAPublicKey (std::uint8_t const* data, std::size_t size); - -} // ripple - -#endif diff --git a/src/ripple/crypto/impl/GenerateDeterministicKey.cpp b/src/ripple/crypto/impl/GenerateDeterministicKey.cpp index cf0d0281b8..a2265af38f 100644 --- a/src/ripple/crypto/impl/GenerateDeterministicKey.cpp +++ b/src/ripple/crypto/impl/GenerateDeterministicKey.cpp @@ -18,11 +18,11 @@ //============================================================================== #include +#include #include #include #include #include -#include #include #include #include @@ -42,7 +42,7 @@ struct secp256k1_data group = EC_GROUP_new_by_curve_name (NID_secp256k1); if (!group) - beast::FatalError ("The OpenSSL library on this system lacks elliptic curve support."); + LogicError ("The OpenSSL library on this system lacks elliptic curve support."); bn_ctx ctx; order = get_order (group, ctx); diff --git a/src/ripple/crypto/tests/CKey.test.cpp b/src/ripple/crypto/tests/CKey.test.cpp deleted file mode 100644 index c949da0d65..0000000000 --- a/src/ripple/crypto/tests/CKey.test.cpp +++ /dev/null @@ -1,58 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2012, 2013 Ripple Labs Inc. - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#include -#include -#include -#include - -namespace ripple { - -// Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2011 The Bitcoin developers -// Distributed under the MIT/X11 software license, see the accompanying -// file license.txt or http://www.opensource.org/licenses/mit-license.php. - - -class CKey_test : public beast::unit_test::suite -{ -public: - void - run () - { - uint128 seed1, seed2; - seed1.SetHex ("71ED064155FFADFA38782C5E0158CB26"); - seed2.SetHex ("CF0C3BE4485961858C4198515AE5B965"); - - uint256 const priv1 = generateRootDeterministicPrivateKey (seed1); - uint256 const priv2 = generateRootDeterministicPrivateKey (seed2); - - unexpected (to_string (priv1) != "7CFBA64F771E93E817E15039215430B53F74" - "01C34931D111EAB3510B22DBB0D8", - "Incorrect private key for generator"); - - unexpected (to_string (priv2) != "98BC2EACB26EB021D1A6293C044D88BA2F0B" - "6729A2772DEEBF2E21A263C1740B", - "Incorrect private key for generator"); - } -}; - -BEAST_DEFINE_TESTSUITE(CKey,ripple_data,ripple); - -} // ripple diff --git a/src/ripple/protocol/impl/BuildInfo.cpp b/src/ripple/protocol/impl/BuildInfo.cpp index 97064abd41..b0440910a2 100644 --- a/src/ripple/protocol/impl/BuildInfo.cpp +++ b/src/ripple/protocol/impl/BuildInfo.cpp @@ -18,10 +18,10 @@ //============================================================================== #include -#include +#include #include -#include #include +#include namespace ripple { @@ -107,40 +107,20 @@ getMinimumProtocol () std::string const& getVersionString () { - struct SanityChecker - { - SanityChecker () - { - beast::SemanticVersion v; - - char const* const rawText = getRawVersionString (); - - if (! v.parse (rawText) || v.print () != rawText) - beast::FatalError ("Bad server version string", __FILE__, __LINE__); - - versionString = rawText; - } - - std::string versionString; - }; - - static SanityChecker const value; - - return value.versionString; + static std::string const value = [] { + std::string const versionString = getRawVersionString (); + beast::SemanticVersion v; + if (!v.parse (versionString) || v.print () != versionString) + LogicError (versionString + ": Bad server version string"); + return versionString; + }(); + return value; } std::string const& getFullVersionString () { - struct PrettyPrinter - { - PrettyPrinter () : fullVersionString ("rippled-" + getVersionString ()){} - - std::string fullVersionString; - }; - - static PrettyPrinter const value; - - return value.fullVersionString; + static std::string const value = "rippled-" + getVersionString (); + return value; } ProtocolVersion diff --git a/src/ripple/unity/crypto.cpp b/src/ripple/unity/crypto.cpp index 744878b40f..6e3c13a4fa 100644 --- a/src/ripple/unity/crypto.cpp +++ b/src/ripple/unity/crypto.cpp @@ -20,15 +20,12 @@ #include #include -#include #include #include #include #include #include -#include - #if DOXYGEN #include #endif