Unverified Commit 4b956280 authored by kladko's avatar kladko

enhancement/SKALE-3636-SGX-Server-anti-dos

parent 83d6a406
...@@ -58,6 +58,7 @@ std::shared_timed_mutex sgxInitMutex; ...@@ -58,6 +58,7 @@ std::shared_timed_mutex sgxInitMutex;
uint64_t initTime; uint64_t initTime;
void setFullOptions(uint64_t _logLevel, int _useHTTPS, int _autoconfirm, int _enterBackupKey) { void setFullOptions(uint64_t _logLevel, int _useHTTPS, int _autoconfirm, int _enterBackupKey) {
COUNT_STATISTICS
spdlog::info("Entering {}", __FUNCTION__); spdlog::info("Entering {}", __FUNCTION__);
CHECK_STATE(_logLevel <= 2) CHECK_STATE(_logLevel <= 2)
...@@ -79,6 +80,7 @@ void setFullOptions(uint64_t _logLevel, int _useHTTPS, int _autoconfirm, int _en ...@@ -79,6 +80,7 @@ void setFullOptions(uint64_t _logLevel, int _useHTTPS, int _autoconfirm, int _en
} }
void setOptions(uint64_t _logLevel, int _useHTTPS, int _autoconfirm) { void setOptions(uint64_t _logLevel, int _useHTTPS, int _autoconfirm) {
COUNT_STATISTICS
spdlog::info("Entering {}", __FUNCTION__); spdlog::info("Entering {}", __FUNCTION__);
setFullOptions(_logLevel, _useHTTPS, _autoconfirm, false); setFullOptions(_logLevel, _useHTTPS, _autoconfirm, false);
} }
...@@ -120,6 +122,7 @@ void SGXWalletServer::printDB() { ...@@ -120,6 +122,7 @@ void SGXWalletServer::printDB() {
int SGXWalletServer::initHttpsServer(bool _checkCerts) { int SGXWalletServer::initHttpsServer(bool _checkCerts) {
COUNT_STATISTICS
spdlog::info("Entering {}", __FUNCTION__); spdlog::info("Entering {}", __FUNCTION__);
spdlog::info("Initing server, number of threads: {}", NUM_THREADS); spdlog::info("Initing server, number of threads: {}", NUM_THREADS);
...@@ -174,6 +177,7 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) { ...@@ -174,6 +177,7 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) {
} }
int SGXWalletServer::initHttpServer() { //without ssl int SGXWalletServer::initHttpServer() { //without ssl
COUNT_STATISTICS
spdlog::info("Entering {}", __FUNCTION__); spdlog::info("Entering {}", __FUNCTION__);
httpServer = make_shared<HttpServer>(BASE_PORT + 3, "", "", "", false, httpServer = make_shared<HttpServer>(BASE_PORT + 3, "", "", "", false,
NUM_THREADS); NUM_THREADS);
...@@ -188,6 +192,7 @@ int SGXWalletServer::initHttpServer() { //without ssl ...@@ -188,6 +192,7 @@ int SGXWalletServer::initHttpServer() { //without ssl
Json::Value Json::Value
SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName) { SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName) {
COUNT_STATISTICS
spdlog::info("Entering {}", __FUNCTION__); spdlog::info("Entering {}", __FUNCTION__);
INIT_RESULT(result); INIT_RESULT(result);
...@@ -240,7 +245,7 @@ void SGXWalletServer::checkForDuplicate(map <string, string> &_map, recursive_mu ...@@ -240,7 +245,7 @@ void SGXWalletServer::checkForDuplicate(map <string, string> &_map, recursive_mu
LOCK(_m); LOCK(_m);
if (_map.count(_key) && _map.at(_key) == _value) { if (_map.count(_key) && _map.at(_key) == _value) {
sleep(100); usleep(100);
spdlog::warn(string("Received an identical request from the client:") + __FUNCTION__); spdlog::warn(string("Received an identical request from the client:") + __FUNCTION__);
} }
_map[_key] = _value; _map[_key] = _value;
...@@ -304,6 +309,7 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin ...@@ -304,6 +309,7 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin
Json::Value SGXWalletServer::importECDSAKeyImpl(const string &_keyShare, Json::Value SGXWalletServer::importECDSAKeyImpl(const string &_keyShare,
const string &_keyShareName) { const string &_keyShareName) {
COUNT_STATISTICS
spdlog::info("Entering {}", __FUNCTION__); spdlog::info("Entering {}", __FUNCTION__);
INIT_RESULT(result) INIT_RESULT(result)
result["encryptedKey"] = ""; result["encryptedKey"] = "";
...@@ -334,6 +340,7 @@ Json::Value SGXWalletServer::importECDSAKeyImpl(const string &_keyShare, ...@@ -334,6 +340,7 @@ Json::Value SGXWalletServer::importECDSAKeyImpl(const string &_keyShare,
} }
Json::Value SGXWalletServer::generateECDSAKeyImpl() { Json::Value SGXWalletServer::generateECDSAKeyImpl() {
COUNT_STATISTICS
spdlog::info("Entering {}", __FUNCTION__); spdlog::info("Entering {}", __FUNCTION__);
INIT_RESULT(result) INIT_RESULT(result)
result["encryptedKey"] = ""; result["encryptedKey"] = "";
...@@ -361,6 +368,7 @@ Json::Value SGXWalletServer::generateECDSAKeyImpl() { ...@@ -361,6 +368,7 @@ Json::Value SGXWalletServer::generateECDSAKeyImpl() {
} }
Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_keyName, const string &_messageHash) { Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_keyName, const string &_messageHash) {
COUNT_STATISTICS
spdlog::trace("Entering {}", __FUNCTION__); spdlog::trace("Entering {}", __FUNCTION__);
INIT_RESULT(result) INIT_RESULT(result)
...@@ -408,6 +416,7 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_ ...@@ -408,6 +416,7 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_
} }
Json::Value SGXWalletServer::getPublicECDSAKeyImpl(const string &_keyName) { Json::Value SGXWalletServer::getPublicECDSAKeyImpl(const string &_keyName) {
COUNT_STATISTICS
spdlog::debug("Entering {}", __FUNCTION__); spdlog::debug("Entering {}", __FUNCTION__);
INIT_RESULT(result) INIT_RESULT(result)
...@@ -430,6 +439,7 @@ Json::Value SGXWalletServer::getPublicECDSAKeyImpl(const string &_keyName) { ...@@ -430,6 +439,7 @@ Json::Value SGXWalletServer::getPublicECDSAKeyImpl(const string &_keyName) {
} }
Json::Value SGXWalletServer::generateDKGPolyImpl(const string &_polyName, int _t) { Json::Value SGXWalletServer::generateDKGPolyImpl(const string &_polyName, int _t) {
COUNT_STATISTICS
spdlog::info("Entering {}", __FUNCTION__); spdlog::info("Entering {}", __FUNCTION__);
INIT_RESULT(result) INIT_RESULT(result)
...@@ -451,6 +461,7 @@ Json::Value SGXWalletServer::generateDKGPolyImpl(const string &_polyName, int _t ...@@ -451,6 +461,7 @@ Json::Value SGXWalletServer::generateDKGPolyImpl(const string &_polyName, int _t
} }
Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName, int _t, int _n) { Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName, int _t, int _n) {
COUNT_STATISTICS
spdlog::info("Entering {}", __FUNCTION__); spdlog::info("Entering {}", __FUNCTION__);
INIT_RESULT(result) INIT_RESULT(result)
...@@ -480,6 +491,7 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName, ...@@ -480,6 +491,7 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName,
} }
Json::Value SGXWalletServer::getSecretShareImpl(const string &_polyName, const Json::Value &_pubKeys, int _t, int _n) { Json::Value SGXWalletServer::getSecretShareImpl(const string &_polyName, const Json::Value &_pubKeys, int _t, int _n) {
COUNT_STATISTICS
spdlog::info("Entering {}", __FUNCTION__); spdlog::info("Entering {}", __FUNCTION__);
INIT_RESULT(result); INIT_RESULT(result);
result["secretShare"] = ""; result["secretShare"] = "";
...@@ -521,6 +533,7 @@ Json::Value SGXWalletServer::getSecretShareImpl(const string &_polyName, const J ...@@ -521,6 +533,7 @@ Json::Value SGXWalletServer::getSecretShareImpl(const string &_polyName, const J
Json::Value SGXWalletServer::dkgVerificationImpl(const string &_publicShares, const string &_ethKeyName, Json::Value SGXWalletServer::dkgVerificationImpl(const string &_publicShares, const string &_ethKeyName,
const string &_secretShare, int _t, int _n, int _index) { const string &_secretShare, int _t, int _n, int _index) {
COUNT_STATISTICS
spdlog::info("Entering {}", __FUNCTION__); spdlog::info("Entering {}", __FUNCTION__);
INIT_RESULT(result) INIT_RESULT(result)
result["result"] = false; result["result"] = false;
...@@ -552,6 +565,7 @@ Json::Value SGXWalletServer::dkgVerificationImpl(const string &_publicShares, co ...@@ -552,6 +565,7 @@ Json::Value SGXWalletServer::dkgVerificationImpl(const string &_publicShares, co
Json::Value Json::Value
SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string &_ethKeyName, const string &_polyName, SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string &_ethKeyName, const string &_polyName,
const string &_secretShare, int _t, int _n) { const string &_secretShare, int _t, int _n) {
COUNT_STATISTICS
spdlog::info("Entering {}", __FUNCTION__); spdlog::info("Entering {}", __FUNCTION__);
INIT_RESULT(result) INIT_RESULT(result)
...@@ -603,6 +617,7 @@ SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string ...@@ -603,6 +617,7 @@ SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string
} }
Json::Value SGXWalletServer::getBLSPublicKeyShareImpl(const string &_blsKeyName) { Json::Value SGXWalletServer::getBLSPublicKeyShareImpl(const string &_blsKeyName) {
COUNT_STATISTICS
spdlog::info("Entering {}", __FUNCTION__); spdlog::info("Entering {}", __FUNCTION__);
INIT_RESULT(result) INIT_RESULT(result)
...@@ -622,6 +637,7 @@ Json::Value SGXWalletServer::getBLSPublicKeyShareImpl(const string &_blsKeyName) ...@@ -622,6 +637,7 @@ Json::Value SGXWalletServer::getBLSPublicKeyShareImpl(const string &_blsKeyName)
} }
Json::Value SGXWalletServer::calculateAllBLSPublicKeysImpl(const Json::Value &publicShares, int t, int n) { Json::Value SGXWalletServer::calculateAllBLSPublicKeysImpl(const Json::Value &publicShares, int t, int n) {
COUNT_STATISTICS
spdlog::info("Entering {}", __FUNCTION__); spdlog::info("Entering {}", __FUNCTION__);
INIT_RESULT(result) INIT_RESULT(result)
...@@ -668,6 +684,7 @@ Json::Value SGXWalletServer::calculateAllBLSPublicKeysImpl(const Json::Value &pu ...@@ -668,6 +684,7 @@ Json::Value SGXWalletServer::calculateAllBLSPublicKeysImpl(const Json::Value &pu
} }
Json::Value SGXWalletServer::complaintResponseImpl(const string &_polyName, int _t, int _n, int _ind) { Json::Value SGXWalletServer::complaintResponseImpl(const string &_polyName, int _t, int _n, int _ind) {
COUNT_STATISTICS
spdlog::info("Entering {}", __FUNCTION__); spdlog::info("Entering {}", __FUNCTION__);
INIT_RESULT(result) INIT_RESULT(result)
...@@ -711,6 +728,7 @@ Json::Value SGXWalletServer::complaintResponseImpl(const string &_polyName, int ...@@ -711,6 +728,7 @@ Json::Value SGXWalletServer::complaintResponseImpl(const string &_polyName, int
} }
Json::Value SGXWalletServer::multG2Impl(const string &_x) { Json::Value SGXWalletServer::multG2Impl(const string &_x) {
COUNT_STATISTICS
INIT_RESULT(result) INIT_RESULT(result)
try { try {
...@@ -724,6 +742,7 @@ Json::Value SGXWalletServer::multG2Impl(const string &_x) { ...@@ -724,6 +742,7 @@ Json::Value SGXWalletServer::multG2Impl(const string &_x) {
} }
Json::Value SGXWalletServer::isPolyExistsImpl(const string &_polyName) { Json::Value SGXWalletServer::isPolyExistsImpl(const string &_polyName) {
COUNT_STATISTICS
spdlog::info("Entering {}", __FUNCTION__); spdlog::info("Entering {}", __FUNCTION__);
INIT_RESULT(result) INIT_RESULT(result)
...@@ -741,17 +760,20 @@ Json::Value SGXWalletServer::isPolyExistsImpl(const string &_polyName) { ...@@ -741,17 +760,20 @@ Json::Value SGXWalletServer::isPolyExistsImpl(const string &_polyName) {
} }
Json::Value SGXWalletServer::getServerStatusImpl() { Json::Value SGXWalletServer::getServerStatusImpl() {
COUNT_STATISTICS
INIT_RESULT(result) INIT_RESULT(result)
RETURN_SUCCESS(result) RETURN_SUCCESS(result)
} }
Json::Value SGXWalletServer::getServerVersionImpl() { Json::Value SGXWalletServer::getServerVersionImpl() {
COUNT_STATISTICS
INIT_RESULT(result) INIT_RESULT(result)
result["version"] = TOSTRING(SGXWALLET_VERSION); result["version"] = TOSTRING(SGXWALLET_VERSION);
RETURN_SUCCESS(result) RETURN_SUCCESS(result)
} }
Json::Value SGXWalletServer::deleteBlsKeyImpl(const string &name) { Json::Value SGXWalletServer::deleteBlsKeyImpl(const string &name) {
COUNT_STATISTICS
spdlog::info("Entering {}", __FUNCTION__); spdlog::info("Entering {}", __FUNCTION__);
INIT_RESULT(result) INIT_RESULT(result)
...@@ -776,6 +798,7 @@ Json::Value SGXWalletServer::deleteBlsKeyImpl(const string &name) { ...@@ -776,6 +798,7 @@ Json::Value SGXWalletServer::deleteBlsKeyImpl(const string &name) {
Json::Value Json::Value
SGXWalletServer::getSecretShareV2Impl(const string &_polyName, const Json::Value &_pubKeys, int _t, int _n) { SGXWalletServer::getSecretShareV2Impl(const string &_polyName, const Json::Value &_pubKeys, int _t, int _n) {
COUNT_STATISTICS
spdlog::info("Entering {}", __FUNCTION__); spdlog::info("Entering {}", __FUNCTION__);
INIT_RESULT(result); INIT_RESULT(result);
result["secretShare"] = ""; result["secretShare"] = "";
...@@ -817,6 +840,7 @@ SGXWalletServer::getSecretShareV2Impl(const string &_polyName, const Json::Value ...@@ -817,6 +840,7 @@ SGXWalletServer::getSecretShareV2Impl(const string &_polyName, const Json::Value
Json::Value SGXWalletServer::dkgVerificationV2Impl(const string &_publicShares, const string &_ethKeyName, Json::Value SGXWalletServer::dkgVerificationV2Impl(const string &_publicShares, const string &_ethKeyName,
const string &_secretShare, int _t, int _n, int _index) { const string &_secretShare, int _t, int _n, int _index) {
COUNT_STATISTICS
spdlog::info("Entering {}", __FUNCTION__); spdlog::info("Entering {}", __FUNCTION__);
INIT_RESULT(result) INIT_RESULT(result)
result["result"] = false; result["result"] = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment