Unverified Commit 3c1111f2 authored by Oleh Nikolaiev's avatar Oleh Nikolaiev Committed by GitHub

Merge pull request #117 from skalenetwork/bug/SKALE-2835-delete-keys

SKALE-2835 add api call to delete bls key
parents 17310b56 0010867e
......@@ -30,6 +30,7 @@ jobs:
- name: build container for testing
run: python3 scripts/docker_build.py DockerfileSimulation sgxwalletsim ${GITHUB_SHA}
- name: test
if: contains(github.ref, 'develop')
run: python3 scripts/docker_test.py DockerfileSimulation sgxwalletsim
- name: deploy docker image
if: contains(github.ref, 'develop') || contains(github.ref, 'beta') || contains(github.ref, 'master') || contains(github.ref, 'stable')
......
......@@ -114,7 +114,6 @@ void LevelDB::deleteKey(const string &_key) {
}
void LevelDB::writeByteArray(const char *_key, size_t _keyLen, const char *value,
size_t _valueLen) {
std::lock_guard<std::recursive_mutex> lock(mutex);
......
......@@ -118,4 +118,4 @@ public:
#endif
\ No newline at end of file
#endif
......@@ -546,7 +546,7 @@ SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string
throw SGXException(INVALID_POLY_NAME, "Invalid polynomial name");
}
if (!checkName(_blsKeyName, "BLS_KEY")) {
throw SGXException(INVALID_POLY_NAME, "Invalid BLS key name");
throw SGXException(INVALID_BLS_NAME, "Invalid BLS key name");
}
if (!check_n_t(_t, _n)) {
throw SGXException(INVALID_DKG_PARAMS, "Invalid DKG parameters: n or t ");
......@@ -569,6 +569,7 @@ SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string
LevelDB::getLevelDb()->deleteDHDKGKey(name);
string shareG2_name = "shareG2_" + _polyName + "_" + to_string(i) + ":";
LevelDB::getLevelDb()->deleteKey(shareG2_name);
LevelDB::getLevelDb()->deleteKey(_polyName);
}
} HANDLE_SGX_EXCEPTION(result)
......@@ -581,7 +582,7 @@ Json::Value SGXWalletServer::getBLSPublicKeyShareImpl(const string &_blsKeyName)
try {
if (!checkName(_blsKeyName, "BLS_KEY")) {
throw SGXException(INVALID_POLY_NAME, "Invalid BLSKey name");
throw SGXException(INVALID_BLS_NAME, "Invalid BLSKey name");
}
shared_ptr <string> encryptedKeyHex_ptr = readFromDb(_blsKeyName);
spdlog::debug("encr_bls_key_share is {}", *encryptedKeyHex_ptr);
......@@ -660,6 +661,25 @@ Json::Value SGXWalletServer::getServerVersionImpl() {
return result;
}
Json::Value SGXWalletServer::deleteBlsKeyImpl(const std::string& name) {
INIT_RESULT(result)
result["deleted"] = false;
try {
if (!checkName(name, "BLS_KEY")) {
throw SGXException(INVALID_BLS_NAME, "Invalid BLSKey name");
}
std::shared_ptr <std::string> bls_ptr = LevelDB::getLevelDb()->readString(name);
if (bls_ptr != nullptr) {
result["deleted"] = true;
return result;
}
LevelDB::getLevelDb()->deleteKey(name);
} HANDLE_SGX_EXCEPTION(result)
return result;
}
Json::Value SGXWalletServer::generateDKGPoly(const string &_polyName, int _t) {
WRITE_LOCK(m)
......@@ -763,6 +783,11 @@ Json::Value SGXWalletServer::getServerVersion() {
return getServerVersionImpl();
}
Json::Value SGXWalletServer::deleteBlsKey(const std::string& name) {
READ_LOCK(m)
return deleteBlsKeyImpl(name);
}
shared_ptr <string> SGXWalletServer::readFromDb(const string &name, const string &prefix) {
auto dataStr = LevelDB::getLevelDb()->readString(prefix + name);
......
......@@ -103,6 +103,8 @@ public:
virtual Json::Value getServerVersion();
virtual Json::Value deleteBlsKey( const std::string& name );
static shared_ptr<string> readFromDb(const string &name, const string &prefix = "");
static void writeDataToDB(const string &Name, const string &value);
......@@ -154,6 +156,8 @@ public:
static Json::Value getServerVersionImpl();
static Json::Value deleteBlsKeyImpl(const std::string& name);
static void printDB();
static int initHttpServer();
......
......@@ -57,6 +57,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
this->bindAndAddMethod(jsonrpc::Procedure("getServerStatus", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, NULL), &AbstractStubServer::getServerStatusI);
this->bindAndAddMethod(jsonrpc::Procedure("getServerVersion", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, NULL), &AbstractStubServer::getServerVersionI);
this->bindAndAddMethod(jsonrpc::Procedure("deleteBlsKey", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "blsKeyName", jsonrpc::JSON_STRING, NULL), &AbstractStubServer::deleteBlsKeyI);
}
inline virtual void importBLSKeyShareI(const Json::Value &request, Json::Value &response)
......@@ -140,6 +141,10 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
response = this->getServerVersion();
}
inline virtual void deleteBlsKeyI(const Json::Value& request, Json::Value& response) {
response = this->deleteBlsKey(request["blsKeyName"].asString());
}
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 importECDSAKey(const std::string& key, const std::string& keyName) = 0;
......@@ -160,6 +165,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
virtual Json::Value getServerStatus() = 0;
virtual Json::Value getServerVersion() = 0;
virtual Json::Value deleteBlsKey(const std::string& name) = 0;
};
#endif //JSONRPC_CPP_STUB_ABSTRACTSTUBSERVER_H_
......@@ -80,6 +80,7 @@ extern int autoconfirm;
#define INVALID_POLY_NAME -11
#define INVALID_DKG_PARAMS -12
#define INVALID_SECRET_SHARES_LENGTH -13
#define INVALID_BLS_NAME -15
#define CERT_REQUEST_DOES_NOT_EXIST -14
......
......@@ -220,6 +220,18 @@ class StubClient : public jsonrpc::Client
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value deleteBlsKey(const std::string & polyName)
{
Json::Value p;
p["blsKeyName"] = polyName;
Json::Value result = this->CallMethod("deleteBlsKey",p);
if (result.isObject())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
////CSRManagerServer
......
......@@ -574,8 +574,11 @@ TEST_CASE_METHOD(TestFixture, "DKG_BLS test", "[dkg-bls]") {
TestUtils::doDKG(c, 16, 5, ecdsaKeyNames, blsKeyNames, schainID, dkgID);
}
for (const auto& name : blsKeyNames) {
REQUIRE(c.deleteBlsKey(name)["deleted"] == true);
}
}
TEST_CASE_METHOD(TestFixture, "Get ServerStatus", "[get-server-status]") {
HttpClient client(RPC_ENDPOINT);
......
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