SKALE-4411 add new function to zmq server

parent 63f34987
...@@ -1184,15 +1184,12 @@ TEST_CASE_METHOD(TestFixtureNoReset, "Second run", "[second-run]") { ...@@ -1184,15 +1184,12 @@ TEST_CASE_METHOD(TestFixtureNoReset, "Second run", "[second-run]") {
} }
TEST_CASE_METHOD(TestFixture, "Test decryption share for threshold encryption", "[te-decryption-share]") { TEST_CASE_METHOD(TestFixture, "Test decryption share for threshold encryption", "[te-decryption-share]") {
// auto client = make_shared<ZMQClient>(ZMQ_IP, ZMQ_PORT, true, "./sgx_data/cert_data/rootCA.pem",
// "./sgx_data/cert_data/rootCA.key");
HttpClient client(RPC_ENDPOINT); HttpClient client(RPC_ENDPOINT);
StubClient c(client, JSONRPC_CLIENT_V2); StubClient c(client, JSONRPC_CLIENT_V2);
std::string key_str = "0xe632f7fde2c90a073ec43eaa90dca7b82476bf28815450a11191484934b9c3f"; std::string key_str = "0xe632f7fde2c90a073ec43eaa90dca7b82476bf28815450a11191484934b9c3f";
std::string name = "BLS_KEY:SCHAIN_ID:123456789:NODE_ID:0:DKG_ID:0"; std::string name = "BLS_KEY:SCHAIN_ID:123456789:NODE_ID:0:DKG_ID:0";
auto response = c.importBLSKeyShare(key_str, name); c.importBLSKeyShare(key_str, name);
// the same key writtn in decimal // the same key writtn in decimal
libff::alt_bn128_Fr key = libff::alt_bn128_Fr( libff::alt_bn128_Fr key = libff::alt_bn128_Fr(
...@@ -1215,8 +1212,36 @@ TEST_CASE_METHOD(TestFixture, "Test decryption share for threshold encryption", ...@@ -1215,8 +1212,36 @@ TEST_CASE_METHOD(TestFixture, "Test decryption share for threshold encryption",
REQUIRE( share == key * decryption_value ); REQUIRE( share == key * decryption_value );
} }
TEST_CASE_METHOD(TestFixtureZMQSign, "ZMQ-ecdsa", "[zmq-ecdsa]") { TEST_CASE_METHOD(TestFixture, "Test decryption share for threshold encryption via zmq", "[te-decryption-share-zmq]") {
auto client = make_shared<ZMQClient>(ZMQ_IP, ZMQ_PORT, true, "./sgx_data/cert_data/rootCA.pem",
"./sgx_data/cert_data/rootCA.key");
std::string key_str = "0xe632f7fde2c90a073ec43eaa90dca7b82476bf28815450a11191484934b9c3f";
std::string name = "BLS_KEY:SCHAIN_ID:123456789:NODE_ID:0:DKG_ID:0";
client->importBLSKeyShare(key_str, name);
// the same key writtn in decimal
libff::alt_bn128_Fr key = libff::alt_bn128_Fr(
"6507625568967977077291849236396320012317305261598035438182864059942098934847");
libff::alt_bn128_G2 decryption_value = libff::alt_bn128_G2::random_element();
decryption_value.to_affine_coordinates();
auto decrytion_value_str = convertG2ToString( decryption_value, ':' );
auto decryption_share = client->getDecryptionShare( name, decrytion_value_str );
libff::alt_bn128_G2 share;
share.Z = libff::alt_bn128_Fq2::one();
share.X.c0 = libff::alt_bn128_Fq( decryption_share[0].asCString() );
share.X.c1 = libff::alt_bn128_Fq( decryption_share[1].asCString() );
share.Y.c0 = libff::alt_bn128_Fq( decryption_share[2].asCString() );
share.Y.c1 = libff::alt_bn128_Fq( decryption_share[3].asCString() );
REQUIRE( share == key * decryption_value );
}
TEST_CASE_METHOD(TestFixtureZMQSign, "ZMQ-ecdsa", "[zmq-ecdsa]") {
HttpClient htp(RPC_ENDPOINT); HttpClient htp(RPC_ENDPOINT);
StubClient c(htp, JSONRPC_CLIENT_V2); StubClient c(htp, JSONRPC_CLIENT_V2);
......
...@@ -63,7 +63,8 @@ testList = [ "[zmq-ecdsa]", ...@@ -63,7 +63,8 @@ testList = [ "[zmq-ecdsa]",
"[aes-encrypt-decrypt]", "[aes-encrypt-decrypt]",
"[aes-dkg-v2]", "[aes-dkg-v2]",
"[aes-dkg-v2-zmq]", "[aes-dkg-v2-zmq]",
"[te-decryption-share]" "[te-decryption-share]",
"[te-decryption-share-zmq]"
] ]
......
...@@ -183,3 +183,11 @@ Json::Value deleteBLSKeyReqMessage::process() { ...@@ -183,3 +183,11 @@ Json::Value deleteBLSKeyReqMessage::process() {
result["type"] = ZMQMessage::DELETE_BLS_KEY_RSP; result["type"] = ZMQMessage::DELETE_BLS_KEY_RSP;
return result; return result;
} }
Json::Value GetDecryptionShareReqMessage::process() {
auto blsKeyName = getStringRapid("blsKeyName");
auto publicDecryptionValue = getStringRapid("publicDecryptionValue");
auto result = SGXWalletServer::getDecryptionShareImpl(blsKeyName, publicDecryptionValue);
result["type"] = ZMQMessage::GET_DECRYPTION_SHARE_RSP;
return result;
}
...@@ -178,4 +178,11 @@ public: ...@@ -178,4 +178,11 @@ public:
virtual Json::Value process(); virtual Json::Value process();
}; };
class GetDecryptionShareReqMessage : public ZMQMessage {
public:
GetDecryptionShareReqMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
#endif //SGXWALLET_REQMESSAGE_H #endif //SGXWALLET_REQMESSAGE_H
...@@ -110,3 +110,7 @@ Json::Value getServerVersionRspMessage::process() { ...@@ -110,3 +110,7 @@ Json::Value getServerVersionRspMessage::process() {
Json::Value deleteBLSKeyRspMessage::process() { Json::Value deleteBLSKeyRspMessage::process() {
assert(false); assert(false);
} }
Json::Value GetDecryptionShareRspMessage::process() {
assert(false);
}
...@@ -248,4 +248,16 @@ public: ...@@ -248,4 +248,16 @@ public:
}; };
class GetDecryptionShareRspMessage : public ZMQMessage {
public:
GetDecryptionShareRspMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
Json::Value getShare() {
return getJsonValueRapid("decryptionShare");
}
};
#endif //SGXWALLET_RSPMESSAGE_H #endif //SGXWALLET_RSPMESSAGE_H
...@@ -496,6 +496,17 @@ bool ZMQClient::deleteBLSKey(const string& blsKeyName) { ...@@ -496,6 +496,17 @@ bool ZMQClient::deleteBLSKey(const string& blsKeyName) {
return result->isSuccessful(); return result->isSuccessful();
} }
Json::Value ZMQClient::getDecryptionShare(const string& blsKeyName, const string& publicDecryptionValue) {
Json::Value p;
p["type"] = ZMQMessage::GET_DECRYPTION_SHARE_REQ;
p["blsKeyName"] = blsKeyName;
p["publicDecryptionValue"] = publicDecryptionValue;
auto result = dynamic_pointer_cast<GetDecryptionShareRspMessage>(doRequestReply(p));
CHECK_STATE(result);
CHECK_STATE(result->getStatus() == 0);
return result->getShare();
}
uint64_t ZMQClient::getProcessID() { uint64_t ZMQClient::getProcessID() {
return syscall(__NR_gettid); return syscall(__NR_gettid);
} }
...@@ -122,6 +122,8 @@ public: ...@@ -122,6 +122,8 @@ public:
string getServerVersion(); string getServerVersion();
bool deleteBLSKey(const string& blsKeyName); bool deleteBLSKey(const string& blsKeyName);
Json::Value getDecryptionShare(const string& blsKeyName, const string& publicDecryptionValue);
}; };
......
...@@ -227,6 +227,9 @@ shared_ptr <ZMQMessage> ZMQMessage::buildRequest(string &_type, shared_ptr <rapi ...@@ -227,6 +227,9 @@ shared_ptr <ZMQMessage> ZMQMessage::buildRequest(string &_type, shared_ptr <rapi
case ENUM_DELETE_BLS_KEY_REQ: case ENUM_DELETE_BLS_KEY_REQ:
ret = make_shared<deleteBLSKeyReqMessage>(_d); ret = make_shared<deleteBLSKeyReqMessage>(_d);
break; break;
case ENUM_GET_DECRYPTION_SHARE_REQ:
ret = make_shared<GetDecryptionShareReqMessage>(_d);
break;
default: default:
break; break;
} }
...@@ -305,6 +308,9 @@ shared_ptr <ZMQMessage> ZMQMessage::buildResponse(string &_type, shared_ptr <rap ...@@ -305,6 +308,9 @@ shared_ptr <ZMQMessage> ZMQMessage::buildResponse(string &_type, shared_ptr <rap
case ENUM_DELETE_BLS_KEY_RSP: case ENUM_DELETE_BLS_KEY_RSP:
ret = make_shared<deleteBLSKeyRspMessage>(_d); ret = make_shared<deleteBLSKeyRspMessage>(_d);
break; break;
case ENUM_GET_DECRYPTION_SHARE_RSP:
ret = make_shared<GetDecryptionShareRspMessage>(_d);
break;
default: default:
break; break;
} }
...@@ -320,7 +326,8 @@ const std::map<string, int> ZMQMessage::requests{ ...@@ -320,7 +326,8 @@ const std::map<string, int> ZMQMessage::requests{
{GET_VV_REQ, 7}, {GET_SECRET_SHARE_REQ, 8}, {DKG_VERIFY_REQ, 9}, {GET_VV_REQ, 7}, {GET_SECRET_SHARE_REQ, 8}, {DKG_VERIFY_REQ, 9},
{CREATE_BLS_PRIVATE_REQ, 10}, {GET_BLS_PUBLIC_REQ, 11}, {GET_ALL_BLS_PUBLIC_REQ, 12}, {CREATE_BLS_PRIVATE_REQ, 10}, {GET_BLS_PUBLIC_REQ, 11}, {GET_ALL_BLS_PUBLIC_REQ, 12},
{COMPLAINT_RESPONSE_REQ, 13}, {MULT_G2_REQ, 14}, {IS_POLY_EXISTS_REQ, 15}, {COMPLAINT_RESPONSE_REQ, 13}, {MULT_G2_REQ, 14}, {IS_POLY_EXISTS_REQ, 15},
{GET_SERVER_STATUS_REQ, 16}, {GET_SERVER_VERSION_REQ, 17}, {DELETE_BLS_KEY_REQ, 18} {GET_SERVER_STATUS_REQ, 16}, {GET_SERVER_VERSION_REQ, 17}, {DELETE_BLS_KEY_REQ, 18},
{GET_DECRYPTION_SHARE_REQ, 19}
}; };
const std::map<string, int> ZMQMessage::responses { const std::map<string, int> ZMQMessage::responses {
...@@ -329,5 +336,6 @@ const std::map<string, int> ZMQMessage::responses { ...@@ -329,5 +336,6 @@ const std::map<string, int> ZMQMessage::responses {
{GET_VV_RSP, 7}, {GET_SECRET_SHARE_RSP, 8}, {DKG_VERIFY_RSP, 9}, {GET_VV_RSP, 7}, {GET_SECRET_SHARE_RSP, 8}, {DKG_VERIFY_RSP, 9},
{CREATE_BLS_PRIVATE_RSP, 10}, {GET_BLS_PUBLIC_RSP, 11}, {GET_ALL_BLS_PUBLIC_RSP, 12}, {CREATE_BLS_PRIVATE_RSP, 10}, {GET_BLS_PUBLIC_RSP, 11}, {GET_ALL_BLS_PUBLIC_RSP, 12},
{COMPLAINT_RESPONSE_RSP, 13}, {MULT_G2_RSP, 14}, {IS_POLY_EXISTS_RSP, 15}, {COMPLAINT_RESPONSE_RSP, 13}, {MULT_G2_RSP, 14}, {IS_POLY_EXISTS_RSP, 15},
{GET_SERVER_STATUS_RSP, 16}, {GET_SERVER_VERSION_RSP, 17}, {DELETE_BLS_KEY_RSP, 18} {GET_SERVER_STATUS_RSP, 16}, {GET_SERVER_VERSION_RSP, 17}, {DELETE_BLS_KEY_RSP, 18},
{GET_DECRYPTION_SHARE_RSP, 19}
}; };
...@@ -91,6 +91,8 @@ public: ...@@ -91,6 +91,8 @@ public:
static constexpr const char *GET_SERVER_VERSION_RSP = "getServerVersionRsp"; static constexpr const char *GET_SERVER_VERSION_RSP = "getServerVersionRsp";
static constexpr const char *DELETE_BLS_KEY_REQ = "deleteBLSKeyReq"; static constexpr const char *DELETE_BLS_KEY_REQ = "deleteBLSKeyReq";
static constexpr const char *DELETE_BLS_KEY_RSP = "deleteBLSKeyRsp"; static constexpr const char *DELETE_BLS_KEY_RSP = "deleteBLSKeyRsp";
static constexpr const char *GET_DECRYPTION_SHARE_REQ = "getDecryptionShareReq";
static constexpr const char *GET_DECRYPTION_SHARE_RSP = "getDecryptionShareRsp";
static const std::map<string, int> requests; static const std::map<string, int> requests;
static const std::map<string, int> responses; static const std::map<string, int> responses;
...@@ -98,11 +100,11 @@ public: ...@@ -98,11 +100,11 @@ public:
enum Requests { ENUM_BLS_SIGN_REQ, ENUM_ECDSA_SIGN_REQ, ENUM_IMPORT_BLS_REQ, ENUM_IMPORT_ECDSA_REQ, ENUM_GENERATE_ECDSA_REQ, ENUM_GET_PUBLIC_ECDSA_REQ, enum Requests { ENUM_BLS_SIGN_REQ, ENUM_ECDSA_SIGN_REQ, ENUM_IMPORT_BLS_REQ, ENUM_IMPORT_ECDSA_REQ, ENUM_GENERATE_ECDSA_REQ, ENUM_GET_PUBLIC_ECDSA_REQ,
ENUM_GENERATE_DKG_POLY_REQ, ENUM_GET_VV_REQ, ENUM_GET_SECRET_SHARE_REQ, ENUM_DKG_VERIFY_REQ, ENUM_CREATE_BLS_PRIVATE_REQ, ENUM_GENERATE_DKG_POLY_REQ, ENUM_GET_VV_REQ, ENUM_GET_SECRET_SHARE_REQ, ENUM_DKG_VERIFY_REQ, ENUM_CREATE_BLS_PRIVATE_REQ,
ENUM_GET_BLS_PUBLIC_REQ, ENUM_GET_ALL_BLS_PUBLIC_REQ, ENUM_COMPLAINT_RESPONSE_REQ, ENUM_MULT_G2_REQ, ENUM_IS_POLY_EXISTS_REQ, ENUM_GET_BLS_PUBLIC_REQ, ENUM_GET_ALL_BLS_PUBLIC_REQ, ENUM_COMPLAINT_RESPONSE_REQ, ENUM_MULT_G2_REQ, ENUM_IS_POLY_EXISTS_REQ,
ENUM_GET_SERVER_STATUS_REQ, ENUM_GET_SERVER_VERSION_REQ, ENUM_DELETE_BLS_KEY_REQ }; ENUM_GET_SERVER_STATUS_REQ, ENUM_GET_SERVER_VERSION_REQ, ENUM_DELETE_BLS_KEY_REQ, ENUM_GET_DECRYPTION_SHARE_REQ };
enum Responses { ENUM_BLS_SIGN_RSP, ENUM_ECDSA_SIGN_RSP, ENUM_IMPORT_BLS_RSP, ENUM_IMPORT_ECDSA_RSP, ENUM_GENERATE_ECDSA_RSP, ENUM_GET_PUBLIC_ECDSA_RSP, enum Responses { ENUM_BLS_SIGN_RSP, ENUM_ECDSA_SIGN_RSP, ENUM_IMPORT_BLS_RSP, ENUM_IMPORT_ECDSA_RSP, ENUM_GENERATE_ECDSA_RSP, ENUM_GET_PUBLIC_ECDSA_RSP,
ENUM_GENERATE_DKG_POLY_RSP, ENUM_GET_VV_RSP, ENUM_GET_SECRET_SHARE_RSP, ENUM_DKG_VERIFY_RSP, ENUM_CREATE_BLS_PRIVATE_RSP, ENUM_GENERATE_DKG_POLY_RSP, ENUM_GET_VV_RSP, ENUM_GET_SECRET_SHARE_RSP, ENUM_DKG_VERIFY_RSP, ENUM_CREATE_BLS_PRIVATE_RSP,
ENUM_GET_BLS_PUBLIC_RSP, ENUM_GET_ALL_BLS_PUBLIC_RSP, ENUM_COMPLAINT_RESPONSE_RSP, ENUM_MULT_G2_RSP, ENUM_IS_POLY_EXISTS_RSP, ENUM_GET_BLS_PUBLIC_RSP, ENUM_GET_ALL_BLS_PUBLIC_RSP, ENUM_COMPLAINT_RESPONSE_RSP, ENUM_MULT_G2_RSP, ENUM_IS_POLY_EXISTS_RSP,
ENUM_GET_SERVER_STATUS_RSP, ENUM_GET_SERVER_VERSION_RSP, ENUM_DELETE_BLS_KEY_RSP }; ENUM_GET_SERVER_STATUS_RSP, ENUM_GET_SERVER_VERSION_RSP, ENUM_DELETE_BLS_KEY_RSP, ENUM_GET_DECRYPTION_SHARE_RSP };
explicit ZMQMessage(shared_ptr<rapidjson::Document> &_d) : d(_d) {}; explicit ZMQMessage(shared_ptr<rapidjson::Document> &_d) : d(_d) {};
......
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