Unverified Commit 8ca3a0ca authored by Stan Kladko's avatar Stan Kladko Committed by GitHub

Merge pull request #21 from skalenetwork/enhancement/SKALE-1955-add-healthcheck

Enhancement/skale 1955 add healthcheck
parents 42227253 199cd7e9
...@@ -653,6 +653,14 @@ Json::Value MultG2Impl(const std::string& x){ ...@@ -653,6 +653,14 @@ Json::Value MultG2Impl(const std::string& x){
return result; return result;
} }
Json::Value getServerStatusImpl() {
Json::Value result;
result["status"] = 0;
result["errorMessage"] = "";
return result;
}
Json::Value SGXWalletServer::generateDKGPoly(const std::string& polyName, int t){ Json::Value SGXWalletServer::generateDKGPoly(const std::string& polyName, int t){
std::cerr << "entered generateDKGPoly" << std::endl; std::cerr << "entered generateDKGPoly" << std::endl;
...@@ -735,10 +743,14 @@ Json::Value SGXWalletServer::ComplaintResponse(const std::string& polyName, int ...@@ -735,10 +743,14 @@ Json::Value SGXWalletServer::ComplaintResponse(const std::string& polyName, int
} }
Json::Value SGXWalletServer::MultG2(const std::string& x){ Json::Value SGXWalletServer::MultG2(const std::string& x){
lock_guard<recursive_mutex> lock(m); lock_guard<recursive_mutex> lock(m);
return MultG2Impl(x); return MultG2Impl(x);
} }
Json::Value SGXWalletServer::getServerStatus() {
lock_guard<recursive_mutex> lock(m);
return getServerStatusImpl();
}
shared_ptr<string> readFromDb(const string & name, const string & prefix) { shared_ptr<string> readFromDb(const string & name, const string & prefix) {
......
...@@ -60,6 +60,7 @@ public: ...@@ -60,6 +60,7 @@ public:
virtual Json::Value GetBLSPublicKeyShare(const std::string & BLSKeyName); virtual Json::Value GetBLSPublicKeyShare(const std::string & BLSKeyName);
virtual Json::Value ComplaintResponse(const std::string& polyName, int ind); virtual Json::Value ComplaintResponse(const std::string& polyName, int ind);
virtual Json::Value MultG2(const std::string & x); virtual Json::Value MultG2(const std::string & x);
virtual Json::Value getServerStatus();
}; };
...@@ -86,5 +87,6 @@ Json::Value CreateBLSPrivateKeyImpl(const std::string & BLSKeyName, const std::s ...@@ -86,5 +87,6 @@ Json::Value CreateBLSPrivateKeyImpl(const std::string & BLSKeyName, const std::s
Json::Value GetBLSPublicKeyShareImpl(const std::string & BLSKeyName); Json::Value GetBLSPublicKeyShareImpl(const std::string & BLSKeyName);
Json::Value ComplaintResponseImpl(const std::string& polyName, int ind); Json::Value ComplaintResponseImpl(const std::string& polyName, int ind);
Json::Value MultG2Impl(const std::string & x); Json::Value MultG2Impl(const std::string & x);
Json::Value getServerStatusImpl();
#endif //SGXWALLET_SGXWALLETSERVER_HPP #endif //SGXWALLET_SGXWALLETSERVER_HPP
\ No newline at end of file
...@@ -30,6 +30,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer> ...@@ -30,6 +30,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
this->bindAndAddMethod(jsonrpc::Procedure("ComplaintResponse", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "polyName",jsonrpc::JSON_STRING,"ind",jsonrpc::JSON_INTEGER, NULL), &AbstractStubServer::ComplaintResponseI); this->bindAndAddMethod(jsonrpc::Procedure("ComplaintResponse", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "polyName",jsonrpc::JSON_STRING,"ind",jsonrpc::JSON_INTEGER, NULL), &AbstractStubServer::ComplaintResponseI);
this->bindAndAddMethod(jsonrpc::Procedure("MultG2", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "x",jsonrpc::JSON_STRING, NULL), &AbstractStubServer::MultG2I); this->bindAndAddMethod(jsonrpc::Procedure("MultG2", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "x",jsonrpc::JSON_STRING, NULL), &AbstractStubServer::MultG2I);
this->bindAndAddMethod(jsonrpc::Procedure("getServerStatus", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, NULL), &AbstractStubServer::getServerStatusI);
} }
inline virtual void importBLSKeyShareI(const Json::Value &request, Json::Value &response) inline virtual void importBLSKeyShareI(const Json::Value &request, Json::Value &response)
...@@ -93,6 +94,11 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer> ...@@ -93,6 +94,11 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
{ {
response = this->MultG2(request["x"].asString()); response = this->MultG2(request["x"].asString());
} }
inline virtual void getServerStatusI(const Json::Value &request, Json::Value &response)
{
(void)request;
response = this->getServerStatus();
}
virtual Json::Value importBLSKeyShare(const std::string& keyShare, const std::string& keyShareName, int t, int n, int index) = 0; virtual Json::Value importBLSKeyShare(const std::string& keyShare, const std::string& keyShareName, int t, int n, int index) = 0;
virtual Json::Value blsSignMessageHash(const std::string& keyShareName, const std::string& messageHash, int t, int n, int signerIndex ) = 0; virtual Json::Value blsSignMessageHash(const std::string& keyShareName, const std::string& messageHash, int t, int n, int signerIndex ) = 0;
...@@ -110,6 +116,8 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer> ...@@ -110,6 +116,8 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
virtual Json::Value GetBLSPublicKeyShare(const std::string & BLSKeyName) = 0; virtual Json::Value GetBLSPublicKeyShare(const std::string & BLSKeyName) = 0;
virtual Json::Value ComplaintResponse(const std::string& polyName, int ind) = 0; virtual Json::Value ComplaintResponse(const std::string& polyName, int ind) = 0;
virtual Json::Value MultG2(const std::string & x) = 0; virtual Json::Value MultG2(const std::string & x) = 0;
virtual Json::Value getServerStatus() = 0;
}; };
#endif //JSONRPC_CPP_STUB_ABSTRACTSTUBSERVER_H_ #endif //JSONRPC_CPP_STUB_ABSTRACTSTUBSERVER_H_
...@@ -60,7 +60,7 @@ print("Top directory is:" + topDir ) ...@@ -60,7 +60,7 @@ print("Top directory is:" + topDir )
makeExecutable = subprocess.check_output(["which", "make"]) makeExecutable = subprocess.check_output(["which", "make"])
SCRIPTS_DIR = topDir + "/scripts" SCRIPTS_DIR = topDir + "/scripts"
GMP_DIR = topDir + "/sgx-gmp" GMP_DIR = topDir + "/sgx-gmp"
SSL_DIR = topDir + "/intel-sgx-ssl" SSL_DIR = topDir + "/intel-sgx-ssl"
SSL_SOURCE_DIR = SSL_DIR + "/openssl_source" SSL_SOURCE_DIR = SSL_DIR + "/openssl_source"
...@@ -115,7 +115,7 @@ assert subprocess.call(["bash","-c", "cmake -H. -Bbuild && cmake --build build - ...@@ -115,7 +115,7 @@ assert subprocess.call(["bash","-c", "cmake -H. -Bbuild && cmake --build build -
os.chdir(SCRIPTS_DIR) os.chdir(SCRIPTS_DIR)
assert subprocess.call(["bash","-c", "./sgx_linux_x64_sdk_2.5.100.49891.bin --prefix=" + topDir + "/sgx-sdk-build"]) == 0 assert subprocess.call(["bash","-c", "./sgx_linux_x64_sdk_2.5.100.49891.bin --prefix=" + topDir + "/sgx-sdk-build"]) == 0
os.chdir(GMP_DIR); os.chdir(GMP_DIR);
...@@ -141,14 +141,14 @@ assert subprocess.call(["cp", "sgx_tgmp.h", TGMP_BUILD_DIR + "/include/sgx_tgmp. ...@@ -141,14 +141,14 @@ assert subprocess.call(["cp", "sgx_tgmp.h", TGMP_BUILD_DIR + "/include/sgx_tgmp.
os.chdir(SSL_DIR); os.chdir(SSL_DIR);
print "===>>> Downloading vanilla openssl source package" print("===>>> Downloading vanilla openssl source package")
os.chdir(SSL_SOURCE_DIR); os.chdir(SSL_SOURCE_DIR);
assert subprocess.call(["wget", "https://www.openssl.org/source/openssl-1.1.1b.tar.gz"]) == 0 assert subprocess.call(["wget", "https://www.openssl.org/source/openssl-1.1.1b.tar.gz"]) == 0
print "===>>> Making SSL project" print("===>>> Making SSL project")
os.chdir(SSL_MAKE_DIR); os.chdir(SSL_MAKE_DIR);
......
...@@ -26,6 +26,7 @@ class StubClient : public jsonrpc::Client ...@@ -26,6 +26,7 @@ class StubClient : public jsonrpc::Client
else else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
} }
Json::Value blsSignMessageHash(const std::string& keyShareName, const std::string& messageHash, int t, int n, int signerIndex) throw (jsonrpc::JsonRpcException) Json::Value blsSignMessageHash(const std::string& keyShareName, const std::string& messageHash, int t, int n, int signerIndex) throw (jsonrpc::JsonRpcException)
{ {
Json::Value p; Json::Value p;
...@@ -40,6 +41,7 @@ class StubClient : public jsonrpc::Client ...@@ -40,6 +41,7 @@ class StubClient : public jsonrpc::Client
else else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
} }
Json::Value importECDSAKey(const std::string& key, const std::string& keyName) throw (jsonrpc::JsonRpcException) Json::Value importECDSAKey(const std::string& key, const std::string& keyName) throw (jsonrpc::JsonRpcException)
{ {
Json::Value p; Json::Value p;
...@@ -51,6 +53,7 @@ class StubClient : public jsonrpc::Client ...@@ -51,6 +53,7 @@ class StubClient : public jsonrpc::Client
else else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
} }
Json::Value generateECDSAKey() throw (jsonrpc::JsonRpcException) Json::Value generateECDSAKey() throw (jsonrpc::JsonRpcException)
{ {
Json::Value p; Json::Value p;
...@@ -61,6 +64,7 @@ class StubClient : public jsonrpc::Client ...@@ -61,6 +64,7 @@ class StubClient : public jsonrpc::Client
else else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
} }
Json::Value renameECDSAKey(const std::string& KeyName, const std::string& tempKeyName) throw (jsonrpc::JsonRpcException) Json::Value renameECDSAKey(const std::string& KeyName, const std::string& tempKeyName) throw (jsonrpc::JsonRpcException)
{ {
Json::Value p; Json::Value p;
...@@ -72,6 +76,7 @@ class StubClient : public jsonrpc::Client ...@@ -72,6 +76,7 @@ class StubClient : public jsonrpc::Client
else else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
} }
Json::Value getPublicECDSAKey(const std::string& keyName) throw (jsonrpc::JsonRpcException) Json::Value getPublicECDSAKey(const std::string& keyName) throw (jsonrpc::JsonRpcException)
{ {
Json::Value p; Json::Value p;
...@@ -82,6 +87,7 @@ class StubClient : public jsonrpc::Client ...@@ -82,6 +87,7 @@ class StubClient : public jsonrpc::Client
else else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
} }
Json::Value ecdsaSignMessageHash(int base, const std::string& keyName, const std::string& messageHash) throw (jsonrpc::JsonRpcException) Json::Value ecdsaSignMessageHash(int base, const std::string& keyName, const std::string& messageHash) throw (jsonrpc::JsonRpcException)
{ {
Json::Value p; Json::Value p;
...@@ -94,6 +100,7 @@ class StubClient : public jsonrpc::Client ...@@ -94,6 +100,7 @@ class StubClient : public jsonrpc::Client
else else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
} }
Json::Value generateDKGPoly(const std::string& polyName, int t) throw (jsonrpc::JsonRpcException) Json::Value generateDKGPoly(const std::string& polyName, int t) throw (jsonrpc::JsonRpcException)
{ {
Json::Value p; Json::Value p;
...@@ -105,98 +112,112 @@ class StubClient : public jsonrpc::Client ...@@ -105,98 +112,112 @@ class StubClient : public jsonrpc::Client
else else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
} }
Json::Value getVerificationVector(const std::string& polyName, int t, int n) throw (jsonrpc::JsonRpcException)
{ Json::Value getVerificationVector(const std::string& polyName, int t, int n) throw (jsonrpc::JsonRpcException)
Json::Value p; {
p["polyName"] = polyName; Json::Value p;
p["n"] = n; p["polyName"] = polyName;
p["t"] = t; p["n"] = n;
Json::Value result = this->CallMethod("getVerificationVector",p); p["t"] = t;
if (result.isObject()) Json::Value result = this->CallMethod("getVerificationVector",p);
return result; if (result.isObject())
else return result;
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); else
} throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
Json::Value getSecretShare(const std::string& polyName, const Json::Value& publicKeys, int t, int n) throw (jsonrpc::JsonRpcException) }
{
Json::Value p; Json::Value getSecretShare(const std::string& polyName, const Json::Value& publicKeys, int t, int n) throw (jsonrpc::JsonRpcException)
p["polyName"] = polyName; {
p["publicKeys"] = publicKeys; Json::Value p;
p["n"] = n; p["polyName"] = polyName;
p["t"] = t; p["publicKeys"] = publicKeys;
Json::Value result = this->CallMethod("getSecretShare",p); p["n"] = n;
if (result.isObject()) p["t"] = t;
return result; Json::Value result = this->CallMethod("getSecretShare",p);
else if (result.isObject())
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); return result;
} else
Json::Value DKGVerification(const std::string& publicShares, const std::string& EthKeyName, const std::string& SecretShare, int t, int n, int index) throw (jsonrpc::JsonRpcException) throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
{ }
Json::Value p;
p["EthKeyName"] = EthKeyName; Json::Value DKGVerification(const std::string& publicShares, const std::string& EthKeyName, const std::string& SecretShare, int t, int n, int index) throw (jsonrpc::JsonRpcException)
p["SecretShare"] = SecretShare; {
p["index"] = index; Json::Value p;
p["n"] = n; p["EthKeyName"] = EthKeyName;
p["publicShares"] = publicShares; p["SecretShare"] = SecretShare;
p["t"] = t; p["index"] = index;
Json::Value result = this->CallMethod("DKGVerification",p); p["n"] = n;
if (result.isObject()) p["publicShares"] = publicShares;
return result; p["t"] = t;
else Json::Value result = this->CallMethod("DKGVerification",p);
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); if (result.isObject())
} return result;
Json::Value CreateBLSPrivateKey(const std::string & BLSKeyName, const std::string& EthKeyName, const std::string& polyName, const std::string& SecretShare, int t, int n) throw (jsonrpc::JsonRpcException) else
{ throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
Json::Value p; }
p["BLSKeyName"] = BLSKeyName;
p["EthKeyName"] = EthKeyName; Json::Value CreateBLSPrivateKey(const std::string & BLSKeyName, const std::string& EthKeyName, const std::string& polyName, const std::string& SecretShare, int t, int n) throw (jsonrpc::JsonRpcException)
p["polyName"] = polyName; {
p["SecretShare"] = SecretShare; Json::Value p;
p["n"] = n; p["BLSKeyName"] = BLSKeyName;
p["t"] = t; p["EthKeyName"] = EthKeyName;
Json::Value result = this->CallMethod("CreateBLSPrivateKey",p); p["polyName"] = polyName;
if (result.isObject()) p["SecretShare"] = SecretShare;
return result; p["n"] = n;
else p["t"] = t;
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); Json::Value result = this->CallMethod("CreateBLSPrivateKey",p);
} if (result.isObject())
return result;
Json::Value GetBLSPublicKeyShare(const std::string & BLSKeyName) throw (jsonrpc::JsonRpcException) else
{ throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
Json::Value p; }
p["BLSKeyName"] = BLSKeyName;
Json::Value GetBLSPublicKeyShare(const std::string & BLSKeyName) throw (jsonrpc::JsonRpcException)
Json::Value result = this->CallMethod("GetBLSPublicKeyShare",p); {
if (result.isObject()) Json::Value p;
return result; p["BLSKeyName"] = BLSKeyName;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); Json::Value result = this->CallMethod("GetBLSPublicKeyShare",p);
} if (result.isObject())
return result;
Json::Value ComplaintResponse(const std::string& polyName, int ind) throw (jsonrpc::JsonRpcException) else
{ throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
Json::Value p; }
p["polyName"] = polyName;
p["ind"] = ind; Json::Value ComplaintResponse(const std::string& polyName, int ind) throw (jsonrpc::JsonRpcException)
Json::Value result = this->CallMethod("ComplaintResponse",p); {
if (result.isObject()) Json::Value p;
return result; p["polyName"] = polyName;
else p["ind"] = ind;
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); Json::Value result = this->CallMethod("ComplaintResponse",p);
} if (result.isObject())
Json::Value MultG2(const std::string & x) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["x"] = x;
Json::Value result = this->CallMethod("MultG2",p);
if (result.isObject())
return result; return result;
else else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
} }
Json::Value MultG2(const std::string & x) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["x"] = x;
Json::Value result = this->CallMethod("MultG2",p);
if (result.isObject())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value getServerStatus() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p = Json::nullValue;
Json::Value result = this->CallMethod("getServerStatus",p);
if (result.isObject())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
}; };
#endif //JSONRPC_CPP_STUB_STUBCLIENT_H_ #endif //JSONRPC_CPP_STUB_STUBCLIENT_H_
...@@ -955,4 +955,11 @@ TEST_CASE("API test", "[api_test]") { ...@@ -955,4 +955,11 @@ TEST_CASE("API test", "[api_test]") {
sgx_destroy_enclave(eid); sgx_destroy_enclave(eid);
} }
TEST_CASE("getServerStatus test", "[getServerStatus_test]") {
init_all();
HttpClient client("http://localhost:1028");
StubClient c(client, JSONRPC_CLIENT_V2);
REQUIRE(c.getServerStatus()["status"] == 0);
sgx_destroy_enclave(eid);
}
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