Unverified Commit 2c08c11b authored by svetaro's avatar svetaro

SKALE-1887 Add method IsPolyExists to SGXWalletServer

parent 964dac2b
...@@ -62,8 +62,8 @@ std::vector<std::string> gen_ecdsa_key(){ ...@@ -62,8 +62,8 @@ std::vector<std::string> gen_ecdsa_key(){
std::cerr << "account key is " << errMsg << std::endl; std::cerr << "account key is " << errMsg << std::endl;
std::cerr << "enc_len is " << enc_len << std::endl; std::cerr << "enc_len is " << enc_len << std::endl;
std::cerr << "enc_key is " << std::endl; std::cerr << "enc_key is " << std::endl;
for(int i = 0 ; i < 1024; i++) // for(int i = 0 ; i < 1024; i++)
std::cerr << (int)encr_pr_key[i] << " " ; // std::cerr << (int)encr_pr_key[i] << " " ;
} }
char *hexEncrKey = (char *) calloc(BUF_LEN, 1); char *hexEncrKey = (char *) calloc(BUF_LEN, 1);
carray2Hex(encr_pr_key, enc_len, hexEncrKey); carray2Hex(encr_pr_key, enc_len, hexEncrKey);
...@@ -119,13 +119,6 @@ std::string get_ecdsa_pubkey(const char* encryptedKeyHex){ ...@@ -119,13 +119,6 @@ std::string get_ecdsa_pubkey(const char* encryptedKeyHex){
throw RPCException(INVALID_HEX, "Invalid encryptedKeyHex"); throw RPCException(INVALID_HEX, "Invalid encryptedKeyHex");
} }
spdlog::info("encr_hex_key is {}", encryptedKeyHex);
std::cerr << "enc_key is " << std::endl;
for(int i = 0 ; i < BUF_LEN; i++)
std::cerr << (int)encr_pr_key[i] << " " ;
//status = get_public_ecdsa_key(eid, &err_status, errMsg, encr_pr_key, enc_len, pub_key_x, pub_key_y ); //status = get_public_ecdsa_key(eid, &err_status, errMsg, encr_pr_key, enc_len, pub_key_x, pub_key_y );
status = get_public_ecdsa_key_aes(eid, &err_status, errMsg, encr_pr_key, enc_len, pub_key_x, pub_key_y ); status = get_public_ecdsa_key_aes(eid, &err_status, errMsg, encr_pr_key, enc_len, pub_key_x, pub_key_y );
if (err_status != 0){ if (err_status != 0){
......
...@@ -704,6 +704,18 @@ Json::Value MultG2Impl(const std::string& x){ ...@@ -704,6 +704,18 @@ Json::Value MultG2Impl(const std::string& x){
return result; return result;
} }
Json::Value IsPolyExistsImpl(const std::string& polyName){
Json::Value result;
std::shared_ptr<std::string> poly_str_ptr = levelDb->readString(polyName);
result["IsExist"] = true;
if (poly_str_ptr == nullptr){
result["IsExist"] = false;
}
return result;
}
Json::Value getServerStatusImpl() { Json::Value getServerStatusImpl() {
Json::Value result; Json::Value result;
...@@ -801,6 +813,11 @@ Json::Value SGXWalletServer::MultG2(const std::string& x){ ...@@ -801,6 +813,11 @@ Json::Value SGXWalletServer::MultG2(const std::string& x){
return MultG2Impl(x); return MultG2Impl(x);
} }
Json::Value SGXWalletServer::IsPolyExists(const std::string& polyName){
lock_guard<recursive_mutex> lock(m);
return IsPolyExistsImpl(polyName);
}
Json::Value SGXWalletServer::getServerStatus() { Json::Value SGXWalletServer::getServerStatus() {
lock_guard<recursive_mutex> lock(m); lock_guard<recursive_mutex> lock(m);
return getServerStatusImpl(); return getServerStatusImpl();
......
...@@ -61,6 +61,8 @@ public: ...@@ -61,6 +61,8 @@ 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 IsPolyExists(const std::string& polyName);
virtual Json::Value getServerStatus(); virtual Json::Value getServerStatus();
}; };
...@@ -88,6 +90,8 @@ Json::Value CreateBLSPrivateKeyImpl(const std::string & BLSKeyName, const std::s ...@@ -88,6 +90,8 @@ 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 IsPolyExistsImpl(const std::string& polyName);
Json::Value getServerStatusImpl(); Json::Value getServerStatusImpl();
#endif //SGXWALLET_SGXWALLETSERVER_HPP #endif //SGXWALLET_SGXWALLETSERVER_HPP
\ No newline at end of file
...@@ -29,6 +29,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer> ...@@ -29,6 +29,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
this->bindAndAddMethod(jsonrpc::Procedure("GetBLSPublicKeyShare", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "BLSKeyName",jsonrpc::JSON_STRING, NULL), &AbstractStubServer::GetBLSPublicKeyShareI); this->bindAndAddMethod(jsonrpc::Procedure("GetBLSPublicKeyShare", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "BLSKeyName",jsonrpc::JSON_STRING, NULL), &AbstractStubServer::GetBLSPublicKeyShareI);
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("IsPolyExists", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "polyName",jsonrpc::JSON_STRING, NULL), &AbstractStubServer::IsPolyExistsI);
this->bindAndAddMethod(jsonrpc::Procedure("getServerStatus", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, NULL), &AbstractStubServer::getServerStatusI); this->bindAndAddMethod(jsonrpc::Procedure("getServerStatus", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, NULL), &AbstractStubServer::getServerStatusI);
} }
...@@ -41,6 +42,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer> ...@@ -41,6 +42,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
{ {
response = this->blsSignMessageHash(request["keyShareName"].asString(), request["messageHash"].asString(), request["t"].asInt(), request["n"].asInt(), request["signerIndex"].asInt()); response = this->blsSignMessageHash(request["keyShareName"].asString(), request["messageHash"].asString(), request["t"].asInt(), request["n"].asInt(), request["signerIndex"].asInt());
} }
inline virtual void importECDSAKeyI(const Json::Value &request, Json::Value &response) inline virtual void importECDSAKeyI(const Json::Value &request, Json::Value &response)
{ {
response = this->importECDSAKey(request["key"].asString(), request["keyName"].asString()); response = this->importECDSAKey(request["key"].asString(), request["keyName"].asString());
...@@ -62,6 +64,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer> ...@@ -62,6 +64,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
{ {
response = this->ecdsaSignMessageHash(request["base"].asInt(), request["keyName"].asString(), request["messageHash"].asString()); response = this->ecdsaSignMessageHash(request["base"].asInt(), request["keyName"].asString(), request["messageHash"].asString());
} }
inline virtual void generateDKGPolyI(const Json::Value &request, Json::Value &response) inline virtual void generateDKGPolyI(const Json::Value &request, Json::Value &response)
{ {
response = this->generateDKGPoly(request["polyName"].asString(), request["t"].asInt()); response = this->generateDKGPoly(request["polyName"].asString(), request["t"].asInt());
...@@ -94,6 +97,12 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer> ...@@ -94,6 +97,12 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
{ {
response = this->MultG2(request["x"].asString()); response = this->MultG2(request["x"].asString());
} }
inline virtual void IsPolyExistsI(const Json::Value &request, Json::Value &response)
{
response = this->IsPolyExists(request["polyName"].asString());
}
inline virtual void getServerStatusI(const Json::Value &request, Json::Value &response) inline virtual void getServerStatusI(const Json::Value &request, Json::Value &response)
{ {
(void)request; (void)request;
...@@ -116,6 +125,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer> ...@@ -116,6 +125,7 @@ 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 IsPolyExists(const std::string& polyName) = 0;
virtual Json::Value getServerStatus() = 0; virtual Json::Value getServerStatus() = 0;
}; };
......
...@@ -1281,5 +1281,3 @@ void bls_sign_message_aes(int *err_status, char *err_string, uint8_t *encrypted_ ...@@ -1281,5 +1281,3 @@ void bls_sign_message_aes(int *err_status, char *err_string, uint8_t *encrypted_
} }
/*
Copyright (C) 2019-Present SKALE Labs
This file is part of sgxwallet.
sgxwallet is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
sgxwallet is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with sgxwallet. If not, see <https://www.gnu.org/licenses/>.
@file stubclient.cpp
@author Stan Kladko
@date 2019
*/
#include <iostream>
#include "stubclient.h"
#include <jsonrpccpp/client/connectors/httpclient.h>
using namespace jsonrpc;
using namespace std;
int init_client() {
HttpClient client("http://localhost:1025");
StubClient c(client, JSONRPC_CLIENT_V2);
Json::Value params;
try {
cout << c.generateECDSAKey() << endl;
} catch (JsonRpcException &e) {
cerr << e.what() << endl;
}
return 0;
}
...@@ -208,6 +208,18 @@ class StubClient : public jsonrpc::Client ...@@ -208,6 +208,18 @@ class StubClient : public jsonrpc::Client
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
} }
Json::Value IsPolyExists(const std::string & polyName) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["polyName"] = polyName;
Json::Value result = this->CallMethod("IsPolyExists",p);
if (result.isObject())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
////CSRManagerServer ////CSRManagerServer
......
...@@ -1190,3 +1190,34 @@ TEST_CASE("dkg API test", "[dkg_api_test]") { ...@@ -1190,3 +1190,34 @@ TEST_CASE("dkg API test", "[dkg_api_test]") {
sgx_destroy_enclave(eid); sgx_destroy_enclave(eid);
} }
TEST_CASE("IsPolyExists test", "[is_poly_test]") {
DEBUG_PRINT = 1;
is_sgx_https = 0;
cerr << "is_poly_test started" << endl;
init_all(false, false);
cerr << "Server inited" << endl;
HttpClient client("http://localhost:1029");
StubClient c(client, JSONRPC_CLIENT_V2);
cerr << "Client inited" << endl;
reset_db();
std::string polyName = "POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1";
Json::Value genPoly = c.generateDKGPoly(polyName, 2);
cout << genPoly << std::endl;
Json::Value polyExists = c.IsPolyExists(polyName);
cout << polyExists << std::endl;
REQUIRE(polyExists["IsExist"].asBool());
Json::Value polyDoesNotExist = c.IsPolyExists("Vasya");
cout << polyDoesNotExist << std::endl;
REQUIRE(!polyDoesNotExist["IsExist"].asBool());
}
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