Unverified Commit 5f6a68f7 authored by Oleh Nikolaiev's avatar Oleh Nikolaiev Committed by GitHub

Merge pull request #326 from skalenetwork/feature/SKALE-3951-add-zeromq

Feature/skale 3951 add zeromq
parents 152e6db8 b02835f1
//
// Created by kladko on 15.12.20.
//
#include "BLSSignReqMessage.h"
#include "SGXWalletServer.hpp"
Json::Value BLSSignReqMessage::process() {
auto keyName = getStringRapid("keyShareName");
auto hash = getStringRapid("messageHash");
auto t = getUint64Rapid("t");
auto n = getUint64Rapid("n");
auto result = SGXWalletServer::blsSignMessageHashImpl(keyName, hash, t, n);
result["type"] = ZMQMessage::BLS_SIGN_RSP;
return result;
}
\ No newline at end of file
/*
Copyright (C) 2018-2019 SKALE Labs
This file is part of libBLS.
libBLS 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.
libBLS 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 libBLS. If not, see <https://www.gnu.org/licenses/>.
@file BLSReqSignMessage.h
@author Stan Kladko
@date 2020
*/
#ifndef SGXWALLET_BLSSIGNREQMSG_H
#define SGXWALLET_BLSSIGNREQMSG_H
#include "ZMQMessage.h"
class BLSSignReqMessage : public ZMQMessage {
public:
BLSSignReqMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
#endif //SGXWALLET_BLSSIGNREQMSG_H
......@@ -150,7 +150,7 @@ string gen_dkg_poly(int _t) {
return result;
}
vector <vector<string>> get_verif_vect(const string &encryptedPolyHex, int t, int n) {
vector <vector<string>> get_verif_vect(const string &encryptedPolyHex, int t) {
auto encryptedPolyHexPtr = encryptedPolyHex.c_str();
......@@ -174,7 +174,7 @@ vector <vector<string>> get_verif_vect(const string &encryptedPolyHex, int t, in
sgx_status_t status = SGX_SUCCESS;
status = trustedGetPublicShares(eid, &errStatus, errMsg.data(), encrDKGPoly.data(), encLen,
pubShares.data(), t, n);
pubShares.data(), t);
HANDLE_TRUSTED_FUNCTION_ERROR(status, errStatus, errMsg.data());
......@@ -189,7 +189,7 @@ vector <vector<string>> get_verif_vect(const string &encryptedPolyHex, int t, in
}
vector <vector<string>> getVerificationVectorMult(const std::string &encryptedPolyHex, int t, int n, size_t ind) {
auto verificationVector = get_verif_vect(encryptedPolyHex, t, n);
auto verificationVector = get_verif_vect(encryptedPolyHex, t);
vector <vector<string>> result(t);
......
......@@ -33,7 +33,7 @@ using namespace std;
string gen_dkg_poly( int _t);
vector <vector<string>> get_verif_vect(const string& encryptedPolyHex, int t, int n);
vector <vector<string>> get_verif_vect(const string& encryptedPolyHex, int t);
vector <vector<string>> getVerificationVectorMult(const std::string& encryptedPolyHex, int t, int n, size_t ind);
......
/*
Copyright (C) 2018-2019 SKALE Labs
This file is part of libBLS.
libBLS 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.
libBLS 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 libBLS. If not, see <https://www.gnu.org/licenses/>.
@file ECDSASignReqMessage.cpp
@author Stan Kladko
@date 2020
*/
#include "SGXWalletServer.hpp"
#include "ECDSASignReqMessage.h"
Json::Value ECDSASignReqMessage::process() {
auto base = getUint64Rapid("base");
auto keyName = getStringRapid("keyName");
auto hash = getStringRapid("messageHash");
auto result = SGXWalletServer::ecdsaSignMessageHashImpl(base, keyName, hash);
result["type"] = ZMQMessage::ECDSA_SIGN_RSP;
return result;
}
\ No newline at end of file
/*
Copyright (C) 2018- SKALE Labs
This file is part of libBLS.
libBLS 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.
libBLS 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 libBLS. If not, see <https://www.gnu.org/licenses/>.
@file ECDSAReqSignMessage.h
@author Stan Kladko
@date 2020
*/
#ifndef SGXWALLET_ECDSASIGNREQMESSAGE_H
#define SGXWALLET_ECDSASIGNREQMESSAGE_H
#include "ZMQMessage.h"
class ECDSASignReqMessage : public ZMQMessage {
public:
ECDSASignReqMessage(shared_ptr <rapidjson::Document> &_d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
#endif //SGXWALLET_ECDSASIGNREQMESSAGE_H
......@@ -70,11 +70,13 @@ bin_PROGRAMS = sgxwallet testw sgx_util
## have to be explicitly listed
COMMON_SRC = SGXException.cpp ExitHandler.cpp ZMQClient.cpp BLSSignRspMessage.cpp ECDSASignRspMessage.cpp ECDSASignReqMessage.cpp BLSSignReqMessage.cpp ZMQMessage.cpp ZMQServer.cpp InvalidStateException.cpp Exception.cpp InvalidArgumentException.cpp Log.cpp \
COMMON_SRC = SGXException.cpp ExitHandler.cpp zmq_src/ZMQClient.cpp zmq_src/RspMessage.cpp zmq_src/ReqMessage.cpp \
zmq_src/ZMQMessage.cpp zmq_src/ZMQServer.cpp \
InvalidStateException.cpp Exception.cpp InvalidArgumentException.cpp Log.cpp \
SGXWalletServer.cpp SGXRegistrationServer.cpp CSRManagerServer.cpp BLSCrypto.cpp \
DKGCrypto.cpp ServerInit.cpp BLSPrivateKeyShareSGX.cpp LevelDB.cpp ServerDataChecker.cpp SEKManager.cpp \
third_party/intel/sgx_stub.c third_party/intel/sgx_detect_linux.c third_party/intel/create_enclave.c third_party/intel/oc_alloc.c \
ECDSAImpl.c TestUtils.cpp sgxwallet.c SGXInfoServer.cpp ECDSACrypto.cpp
third_party/intel/sgx_stub.c third_party/intel/sgx_detect_linux.c third_party/intel/create_enclave.c \
third_party/intel/oc_alloc.c ECDSAImpl.c TestUtils.cpp sgxwallet.c SGXInfoServer.cpp ECDSACrypto.cpp
COMMON_ENCLAVE_SRC = secure_enclave_u.c secure_enclave_u.h
sgxwallet_SOURCES = sgxwall.cpp $(COMMON_SRC)
......@@ -110,18 +112,20 @@ sgxwallet_LDADD=-l$(SGX_URTS_LIB) -l$(SGX_UAE_SERVICE_LIB) -LlibBLS/deps/deps_in
-ljsonrpccpp-stub -ljsonrpccpp-server -ljsonrpccpp-client -ljsonrpccpp-common -ljsoncpp -lmicrohttpd \
-lboost_system -lboost_thread -lgnutls -lgcrypt -lidn2 -lcurl -lssl -lcrypto -lz -lpthread -lstdc++fs
testw_SOURCES=testw.cpp $(COMMON_SRC)
nodist_testw_SOURCES=${nodist_sgxwallet_SOURCES}
EXTRA_testw_DEPENDENCIES=${EXTRA_sgxwallet_DEPENDENCIES}
testw_LDADD= ${sgxwallet_LDADD}
testw_LDADD=${sgxwallet_LDADD}
sgx_util_SOURCES= SGXException.cpp ExitHandler.cpp InvalidStateException.cpp Exception.cpp InvalidArgumentException.cpp Log.cpp sgx_util.cpp stubclient.cpp LevelDB.cpp SGXRegistrationServer.cpp CSRManagerServer.cpp
sgx_util_SOURCES=SGXException.cpp ExitHandler.cpp InvalidStateException.cpp Exception.cpp \
InvalidArgumentException.cpp Log.cpp sgx_util.cpp stubclient.cpp LevelDB.cpp \
SGXRegistrationServer.cpp CSRManagerServer.cpp
sgx_util_LDADD=-LlibBLS/deps/deps_inst/x86_or_x64/lib -Lleveldb/build -LlibBLS/build \
-LlibBLS/build/libff/libff \
-Llibzmq/build/lib/ \
-l:libzmq.a \
-l:libbls.a -l:libleveldb.a \
-l:libff.a -lgmp -ljsonrpccpp-stub -ljsonrpccpp-server -ljsonrpccpp-client -ljsonrpccpp-common -ljsoncpp -lmicrohttpd -lgnutls -lgcrypt -lidn2 -lcurl -lssl -lcrypto -lz -lpthread -ldl
-l:libff.a -lgmp -ljsonrpccpp-stub -ljsonrpccpp-server -ljsonrpccpp-client -ljsonrpccpp-common \
-ljsoncpp -lmicrohttpd -lgnutls -lgcrypt -lidn2 -lcurl -lssl -lcrypto -lz -lpthread -ldl
......@@ -154,7 +154,6 @@ Json::Value SGXRegistrationServer::GetCertificate(const string &hash) {
RETURN_SUCCESS(result)
}
void SGXRegistrationServer::initRegistrationServer(bool _autoSign) {
httpServer = make_shared<HttpServer>(BASE_PORT + 1);
server = make_shared<SGXRegistrationServer>(*httpServer,
......
......@@ -49,6 +49,12 @@
#include "Log.h"
#ifdef SGX_HW_SIM
#define NUM_THREADS 16
#else
#define NUM_THREADS 200
#endif
using namespace std;
std::shared_timed_mutex sgxInitMutex;
......@@ -111,20 +117,12 @@ void SGXWalletServer::printDB() {
LevelDB::getLevelDb()->visitKeys(&v, 100000000);
}
#ifdef SGX_HW_SIM
#define NUM_THREADS 16
#else
#define NUM_THREADS 200
#endif
bool SGXWalletServer::verifyCert(string &_certFileName) {
string rootCAPath = string(SGXDATA_FOLDER) + "cert_data/rootCA.pem";
string verifyCert = "cert/verify_client_cert " + rootCAPath + " " + _certFileName;
return system(verifyCert.c_str()) == 0;
}
void SGXWalletServer::createCertsIfNeeded() {
string rootCAPath = string(SGXDATA_FOLDER) + "cert_data/rootCA.pem";
......@@ -170,7 +168,6 @@ void SGXWalletServer::createCertsIfNeeded() {
}
}
void SGXWalletServer::initHttpsServer(bool _checkCerts) {
COUNT_STATISTICS
spdlog::info("Entering {}", __FUNCTION__);
......@@ -214,15 +211,15 @@ void SGXWalletServer::initHttpServer() { //without ssl
}
int SGXWalletServer::exitServer() {
spdlog::info("Stoping sgx server");
spdlog::info("Stoping sgx server");
if (server && !server->StopListening()) {
spdlog::error("Sgx server could not be stopped. Will forcefully terminate the app");
} else {
spdlog::info("Sgx server stopped");
}
if (server && !server->StopListening()) {
spdlog::error("Sgx server could not be stopped. Will forcefully terminate the app");
} else {
spdlog::info("Sgx server stopped");
}
return 0;
return 0;
}
Json::Value
......@@ -269,7 +266,6 @@ SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_k
RETURN_SUCCESS(result);
}
map <string, string> SGXWalletServer::blsRequests;
recursive_mutex SGXWalletServer::blsRequestsLock;
......@@ -288,7 +284,6 @@ void SGXWalletServer::checkForDuplicate(map <string, string> &_map, recursive_mu
_map[_key] = _value;
}
Json::Value
SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const string &_messageHash, int t, int n) {
spdlog::trace("Entering {}", __FUNCTION__);
......@@ -305,10 +300,8 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin
shared_ptr <string> value = nullptr;
checkForDuplicate(blsRequests, blsRequestsLock, _keyShareName, _messageHash);
try {
if (!checkName(_keyShareName, "BLS_KEY")) {
throw SGXException(BLS_SIGN_INVALID_KS_NAME, string(__FUNCTION__) + ":Invalid BLSKey name");
......@@ -342,9 +335,7 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin
result["signatureShare"] = string(signature.data());
RETURN_SUCCESS(result);
}
Json::Value SGXWalletServer::importECDSAKeyImpl(const string &_keyShare,
......@@ -501,7 +492,7 @@ Json::Value SGXWalletServer::generateDKGPolyImpl(const string &_polyName, int _t
RETURN_SUCCESS(result)
}
Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName, int _t, int _n) {
Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName, int _t) {
COUNT_STATISTICS
spdlog::info("Entering {}", __FUNCTION__);
INIT_RESULT(result)
......@@ -511,13 +502,13 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName,
if (!checkName(_polyName, "POLY")) {
throw SGXException(INVALID_DKG_GETVV_POLY_NAME, string(__FUNCTION__) + ":Invalid polynomial name");
}
if (!check_n_t(_t, _n)) {
throw SGXException(INVALID_DKG_GETVV_PARAMS, string(__FUNCTION__) + ":Invalid parameters n or t ");
if (_t <= 0) {
throw SGXException(INVALID_DKG_GETVV_PARAMS, string(__FUNCTION__) + ":Invalid t ");
}
shared_ptr <string> encrPoly = readFromDb(_polyName);
verifVector = get_verif_vect(*encrPoly, _t, _n);
verifVector = get_verif_vect(*encrPoly, _t);
for (int i = 0; i < _t; i++) {
vector <string> currentCoef = verifVector.at(i);
......@@ -648,7 +639,6 @@ SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string
string(__FUNCTION__) + ":Error while creating BLS key share");
}
for (int i = 0; i < _n; i++) {
string name = _polyName + "_" + to_string(i) + ":";
LevelDB::getLevelDb()->deleteDHDKGKey(name);
......@@ -978,7 +968,6 @@ SGXWalletServer::createBLSPrivateKeyV2Impl(const string &_blsKeyName, const stri
string(__FUNCTION__) + ":Error while creating BLS key share");
}
for (int i = 0; i < _n; i++) {
string name = _polyName + "_" + to_string(i) + ":";
LevelDB::getLevelDb()->deleteDHDKGKey(name);
......@@ -987,7 +976,6 @@ SGXWalletServer::createBLSPrivateKeyV2Impl(const string &_blsKeyName, const stri
}
LevelDB::getLevelDb()->deleteKey(_polyName);
string encryptedSecretShareName = "encryptedSecretShare:" + _polyName;
LevelDB::getLevelDb()->deleteKey(encryptedSecretShareName);
......@@ -1000,8 +988,8 @@ Json::Value SGXWalletServer::generateDKGPoly(const string &_polyName, int _t) {
return generateDKGPolyImpl(_polyName, _t);
}
Json::Value SGXWalletServer::getVerificationVector(const string &_polynomeName, int _t, int _n) {
return getVerificationVectorImpl(_polynomeName, _t, _n);
Json::Value SGXWalletServer::getVerificationVector(const string &_polynomeName, int _t) {
return getVerificationVectorImpl(_polynomeName, _t);
}
Json::Value SGXWalletServer::getSecretShare(const string &_polyName, const Json::Value &_publicKeys, int t, int n) {
......
......@@ -82,7 +82,7 @@ public:
virtual Json::Value generateDKGPoly(const string &_polyName, int _t);
virtual Json::Value getVerificationVector(const string &_polynomeName, int _t, int _n);
virtual Json::Value getVerificationVector(const string &_polynomeName, int _t);
virtual Json::Value getSecretShare(const string &_polyName, const Json::Value &_publicKeys, int t, int n);
......@@ -140,7 +140,7 @@ public:
static Json::Value generateDKGPolyImpl(const string &_polyName, int _t);
static Json::Value getVerificationVectorImpl(const string &_polyName, int _t, int _n);
static Json::Value getVerificationVectorImpl(const string &_polyName, int _t);
static Json::Value getSecretShareImpl(const string &_polyName, const Json::Value &_pubKeys, int _t, int _n);
......@@ -172,7 +172,7 @@ public:
static Json::Value dkgVerificationV2Impl(const string &_publicShares, const string &_ethKeyName, const string &_secretShare, int _t, int _n, int _index);
virtual Json::Value createBLSPrivateKeyV2Impl(const std::string& blsKeyName, const std::string& ethKeyName, const std::string& polyName, const std::string & SecretShare, int t, int n);
static Json::Value createBLSPrivateKeyV2Impl(const std::string& blsKeyName, const std::string& ethKeyName, const std::string& polyName, const std::string & SecretShare, int t, int n);
static void printDB();
......
......@@ -58,7 +58,7 @@
#include "BLSCrypto.h"
#include "ServerInit.h"
#include "SGXException.h"
#include "ZMQServer.h"
#include "zmq_src/ZMQServer.h"
#include "SGXWalletServer.hpp"
uint32_t enclaveLogLevel = 0;
......@@ -103,10 +103,8 @@ void initUserSpace() {
}
uint64_t initEnclave() {
#ifndef SGX_HW_SIM
unsigned long support;
support = get_sgx_support();
......@@ -161,11 +159,9 @@ uint64_t initEnclave() {
return SGX_SUCCESS;
}
void initAll(uint32_t _logLevel, bool _checkCert,
bool _checkZMQSig, bool _autoSign, bool _generateTestKeys) {
static atomic<bool> sgxServerInited(false);
static mutex initMutex;
enclaveLogLevel = _logLevel;
......@@ -237,5 +233,4 @@ void exitAll() {
CSRManagerServer::exitServer();
SGXInfoServer::exitServer();
ZMQServer::exitZMQServer();
}
......@@ -42,7 +42,6 @@
#include "SGXWalletServer.hpp"
#include "catch.hpp"
#include "ZMQClient.h"
#include "BLSSigShare.h"
#include "BLSSigShareSet.h"
#include "BLSPublicKeyShare.h"
......@@ -73,7 +72,6 @@ string TestUtils::stringFromFr(libff::alt_bn128_Fr &el) {
return string(arr);
}
string TestUtils::convertDecToHex(string dec, int numBytes) {
mpz_t num;
mpz_init(num);
......@@ -190,7 +188,6 @@ void TestUtils::sendRPCRequest() {
CHECK_STATE(sig["status"].asInt() == 0);
}
CHECK_STATE(ethKeys[i]["status"] == 0);
string polyName =
"POLY:SCHAIN_ID:" + to_string(schainID) + ":NODE_ID:" + to_string(i) + ":DKG_ID:" + to_string(dkgID);
......@@ -199,7 +196,7 @@ void TestUtils::sendRPCRequest() {
polyNames[i] = polyName;
for (int i3 = 0; i3 <= testCount; i3++) {
verifVects[i] = c.getVerificationVector(polyName, t, n);
verifVects[i] = c.getVerificationVector(polyName, t);
CHECK_STATE(verifVects[i]["status"] == 0);
}
......@@ -250,7 +247,6 @@ void TestUtils::sendRPCRequest() {
publicShares["publicShares"][i] = pubShares[i];
}
Json::Value blsPublicKeys;
for (int i6 = 0; i6 <= testCount; i6++) {
......@@ -263,7 +259,6 @@ void TestUtils::sendRPCRequest() {
string blsName = "BLS_KEY" + polyNames[i].substr(4);
string secretShare = secretShares[i]["secretShare"].asString();
auto response = c.createBLSPrivateKey(blsName, ethKeys[i]["keyName"].asString(), polyNames[i], secShares[i],
t, n);
CHECK_STATE(response["status"] == 0);
......@@ -321,7 +316,7 @@ void TestUtils::sendRPCRequestV2() {
auto response = c.generateDKGPoly(polyName, t);
CHECK_STATE(response["status"] == 0);
polyNames[i] = polyName;
verifVects[i] = c.getVerificationVector(polyName, t, n);
verifVects[i] = c.getVerificationVector(polyName, t);
CHECK_STATE(verifVects[i]["status"] == 0);
pubEthKeys.append(ethKeys[i]["publicKey"]);
......@@ -399,47 +394,41 @@ void TestUtils::sendRPCRequestV2() {
sigShareSet.merge();
}
void TestUtils::sendRPCRequestZMQ() {
HttpClient client(RPC_ENDPOINT);
StubClient c(client, JSONRPC_CLIENT_V2);
auto client = make_shared<ZMQClient>(ZMQ_IP, ZMQ_PORT, true, "./sgx_data/cert_data/rootCA.pem",
"./sgx_data/cert_data/rootCA.key");
int n = 16, t = 16;
Json::Value ethKeys[n];
vector<string> ethKeys(n);
Json::Value verifVects[n];
Json::Value pubEthKeys;
Json::Value secretShares[n];
vector<string> secretShares(n);
Json::Value pubBLSKeys[n];
Json::Value blsSigShares[n];
vector <string> pubShares(n);
vector <string> polyNames(n);
vector<string> blsSigShares(n);
vector<string> pubShares(n);
vector<string> polyNames(n);
static atomic<int> counter(1);
int schainID = counter.fetch_add(1);
int dkgID = counter.fetch_add(1);
for (uint8_t i = 0; i < n; i++) {
ethKeys[i] = c.generateECDSAKey();
CHECK_STATE(ethKeys[i]["status"] == 0);
auto generatedKey = client->generateECDSAKey();
ethKeys[i] = generatedKey.second;
string polyName =
"POLY:SCHAIN_ID:" + to_string(schainID) + ":NODE_ID:" + to_string(i) + ":DKG_ID:" + to_string(dkgID);
auto response = c.generateDKGPoly(polyName, t);
CHECK_STATE(response["status"] == 0);
CHECK_STATE(client->generateDKGPoly(polyName, t));
polyNames[i] = polyName;
verifVects[i] = c.getVerificationVector(polyName, t, n);
CHECK_STATE(verifVects[i]["status"] == 0);
verifVects[i] = client->getVerificationVector(polyName, t);
pubEthKeys.append(ethKeys[i]["publicKey"]);
pubEthKeys.append(generatedKey.first);
}
for (uint8_t i = 0; i < n; i++) {
secretShares[i] = c.getSecretShareV2(polyNames[i], pubEthKeys, t, n);
secretShares[i] = client->getSecretShare(polyNames[i], pubEthKeys, t, n);
for (uint8_t k = 0; k < t; k++) {
for (uint8_t j = 0; j < 4; j++) {
string pubShare = verifVects[i]["verificationVector"][k][j].asString();
string pubShare = verifVects[i][k][j].asString();
pubShares[i] += convertDecToHex(pubShare);
}
}
......@@ -449,10 +438,10 @@ void TestUtils::sendRPCRequestZMQ() {
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
string secretShare = secretShares[i]["secretShare"].asString().substr(192 * j, 192);
secShares[i] += secretShares[j]["secretShare"].asString().substr(192 * i, 192);
Json::Value verif = c.dkgVerificationV2(pubShares[i], ethKeys[j]["keyName"].asString(), secretShare, t, n, j);
CHECK_STATE(verif["status"] == 0);
string secretShare = secretShares[i].substr(192 * j, 192);
secShares[i] += secretShares[j].substr(192 * i, 192);
bool verif = client->dkgVerification(pubShares[i], ethKeys[j], secretShare, t, n, j);
CHECK_STATE(verif);
}
BLSSigShareSet sigShareSet(t, n);
......@@ -471,17 +460,31 @@ void TestUtils::sendRPCRequestZMQ() {
for (int i = 0; i < n; ++i) {
publicShares["publicShares"][i] = pubShares[i];
}
Json::Value blsPublicKeys = c.calculateAllBLSPublicKeys(publicShares, t, n);
CHECK_STATE(blsPublicKeys["status"] == 0);
Json::Value blsPublicKeys = client->getAllBlsPublicKeys(publicShares, t, n);
for (int i = 0; i < t; i++) {
string blsName = "BLS_KEY" + polyNames[i].substr(4);
string secretShare = secretShares[i];
CHECK_STATE(client->createBLSPrivateKey(blsName, ethKeys[i], polyNames[i], secShares[i], t, n));
pubBLSKeys[i] = client->getBLSPublicKey(blsName);
libff::alt_bn128_G2 publicKey(libff::alt_bn128_Fq2(libff::alt_bn128_Fq(pubBLSKeys[i][0].asCString()),
libff::alt_bn128_Fq(pubBLSKeys[i][1].asCString())),
libff::alt_bn128_Fq2(libff::alt_bn128_Fq(pubBLSKeys[i][2].asCString()),
libff::alt_bn128_Fq(pubBLSKeys[i][3].asCString())),
libff::alt_bn128_Fq2::one());
string public_key_str = convertG2ToString(publicKey);
CHECK_STATE(public_key_str == blsPublicKeys[i].asString());
string hash = SAMPLE_HASH;
blsSigShares[i] = c.blsSignMessageHash(blsName, hash, t, n);
CHECK_STATE(blsSigShares[i]["status"] == 0);
blsSigShares[i] = client->blsSignMessageHash(blsName, hash, t, n);
CHECK_STATE(blsSigShares[i].length() > 0);
shared_ptr <string> sig_share_ptr = make_shared<string>(blsSigShares[i]["signatureShare"].asString());
shared_ptr <string> sig_share_ptr = make_shared<string>(blsSigShares[i]);
BLSSigShare sig(sig_share_ptr, i + 1, t, n);
sigShareSet.addSigShare(make_shared<BLSSigShare>(sig));
}
......@@ -527,7 +530,7 @@ void TestUtils::doDKG(StubClient &c, int n, int t,
Json::Value response = c.generateDKGPoly(polyName, t);
CHECK_STATE(response["status"] == 0);
polyNames[i] = polyName;
verifVects[i] = c.getVerificationVector(polyName, t, n);
verifVects[i] = c.getVerificationVector(polyName, t);
CHECK_STATE(verifVects[i]["status"] == 0);
pubEthKeys.append(ethKeys[i]["publicKey"]);
}
......@@ -668,7 +671,7 @@ void TestUtils::doDKGV2(StubClient &c, int n, int t,
Json::Value response = c.generateDKGPoly(polyName, t);
CHECK_STATE(response["status"] == 0);
polyNames[i] = polyName;
verifVects[i] = c.getVerificationVector(polyName, t, n);
verifVects[i] = c.getVerificationVector(polyName, t);
CHECK_STATE(verifVects[i]["status"] == 0);
pubEthKeys.append(ethKeys[i]["publicKey"]);
}
......@@ -810,7 +813,7 @@ void TestUtils::doZMQBLS(shared_ptr<ZMQClient> _zmqClient, StubClient &c, int n,
Json::Value response = c.generateDKGPoly(polyName, t);
CHECK_STATE(response["status"] == 0);
polyNames[i] = polyName;
verifVects[i] = c.getVerificationVector(polyName, t, n);
verifVects[i] = c.getVerificationVector(polyName, t);
CHECK_STATE(verifVects[i]["status"] == 0);
pubEthKeys.append(ethKeys[i]["publicKey"]);
}
......
......@@ -25,10 +25,7 @@
#define SGXWALLET_TESTUTILS_H
#include <dkg/dkg.h>
#include <jsonrpccpp/server/connectors/httpserver.h>
#include <libff/algebra/curves/alt_bn128/alt_bn128_pp.hpp>
// #include <libff/algebra/exponentiation/exponentiation.hpp>
// #include <libff/algebra/fields/fp.hpp>
#include <dkg/dkg.h>
#include "sgxwallet_common.h"
#include "third_party/intel/create_enclave.h"
......@@ -41,7 +38,7 @@
#include <sgx_tcrypto.h>
#include "stubclient.h"
#include <jsonrpccpp/server/connectors/httpserver.h>
#include "ZMQClient.h"
#include "zmq_src/ZMQClient.h"
#include "abstractstubserver.h"
using namespace std;
......
1.77.0
\ No newline at end of file
1.78.0
\ No newline at end of file
......@@ -45,7 +45,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
this->bindAndAddMethod(jsonrpc::Procedure("ecdsaSignMessageHash", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "base",jsonrpc::JSON_INTEGER,"keyName",jsonrpc::JSON_STRING,"messageHash",jsonrpc::JSON_STRING, NULL), &AbstractStubServer::ecdsaSignMessageHashI);
this->bindAndAddMethod(jsonrpc::Procedure("generateDKGPoly", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "polyName",jsonrpc::JSON_STRING,"t",jsonrpc::JSON_INTEGER, NULL), &AbstractStubServer::generateDKGPolyI);
this->bindAndAddMethod(jsonrpc::Procedure("getVerificationVector", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT,"polyName",jsonrpc::JSON_STRING, "t",jsonrpc::JSON_INTEGER, NULL), &AbstractStubServer::getVerificationVectorI);
this->bindAndAddMethod(jsonrpc::Procedure("getVerificationVector", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "polyName", jsonrpc::JSON_STRING, "t", jsonrpc::JSON_INTEGER, NULL), &AbstractStubServer::getVerificationVectorI);
this->bindAndAddMethod(jsonrpc::Procedure("getSecretShare", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "polyName",jsonrpc::JSON_STRING,"publicKeys",jsonrpc::JSON_ARRAY, "n",jsonrpc::JSON_INTEGER,"t",jsonrpc::JSON_INTEGER, NULL), &AbstractStubServer::getSecretShareI);
this->bindAndAddMethod(jsonrpc::Procedure("dkgVerification", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "publicShares",jsonrpc::JSON_STRING, "ethKeyName",jsonrpc::JSON_STRING, "secretShare",jsonrpc::JSON_STRING,"t",jsonrpc::JSON_INTEGER, "n",jsonrpc::JSON_INTEGER, "index",jsonrpc::JSON_INTEGER, NULL), &AbstractStubServer::dkgVerificationI);
this->bindAndAddMethod(jsonrpc::Procedure("createBLSPrivateKey", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "blsKeyName",jsonrpc::JSON_STRING, "ethKeyName",jsonrpc::JSON_STRING, "polyName", jsonrpc::JSON_STRING, "secretShare",jsonrpc::JSON_STRING,"t", jsonrpc::JSON_INTEGER,"n",jsonrpc::JSON_INTEGER, NULL), &AbstractStubServer::createBLSPrivateKeyI);
......@@ -97,7 +97,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
}
inline virtual void getVerificationVectorI(const Json::Value &request, Json::Value &response)
{
response = this->getVerificationVector(request["polyName"].asString(), request["t"].asInt(), request["n"].asInt());
response = this->getVerificationVector(request["polyName"].asString(), request["t"].asInt());
}
inline virtual void getSecretShareI(const Json::Value &request, Json::Value &response)
{
......@@ -169,7 +169,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
virtual Json::Value ecdsaSignMessageHash(int base, const std::string& keyName, const std::string& messageHash) = 0;
virtual Json::Value generateDKGPoly(const std::string& polyName, int t) = 0;
virtual Json::Value getVerificationVector(const std::string& polyName, int t, int n) = 0;
virtual Json::Value getVerificationVector(const std::string& polyName, int t) = 0;
virtual Json::Value getSecretShare(const std::string& polyName, const Json::Value& publicKeys, int t, int n) = 0;
virtual Json::Value dkgVerification( const std::string& publicShares, const std::string& ethKeyName, const std::string& SecretShare, int t, int n, int index) = 0;
virtual Json::Value createBLSPrivateKey(const std::string& blsKeyName, const std::string& ethKeyName, const std::string& polyName, const std::string& SecretShare, int t, int n) = 0;
......
......@@ -987,14 +987,14 @@ void trustedGetEncryptedSecretShareV2(int *errStatus, char *errString,
void trustedGetPublicShares(int *errStatus, char *errString, uint8_t *encrypted_dkg_secret, uint64_t enc_len,
char *public_shares,
unsigned _t, unsigned _n) {
unsigned _t) {
LOG_INFO(__FUNCTION__);
INIT_ERROR_STATE
CHECK_STATE(encrypted_dkg_secret);
CHECK_STATE(public_shares);
CHECK_STATE(_t <= _n && _n > 0)
CHECK_STATE(_t > 0)
SAFE_CHAR_BUF(decrypted_dkg_secret, DKG_MAX_SEALED_LEN);
......
......@@ -121,8 +121,7 @@ enclave {
[in, count = 3050] uint8_t* encrypted_dkg_secret,
uint64_t enc_len,
[out, count = 10000] char* public_shares,
unsigned _t,
unsigned _n);
unsigned _t);
public void trustedDkgVerify(
[out] int *errStatus,
......
......@@ -36,7 +36,7 @@
#include "TestUtils.h"
#include "ZMQServer.h"
#include "zmq_src/ZMQServer.h"
#include "testw.h"
#include "sgxwall.h"
......@@ -182,7 +182,6 @@ int main(int argc, char *argv[]) {
initAll(enclaveLogLevel, checkClientCertOption, checkClientCertOption, autoSignClientCertOption, generateTestKeys);
cerr << "Completed initAll." << endl;
//check if test keys already exist
string TEST_KEYS_4_NODE = "sgx_data/4node.json";
......@@ -194,7 +193,6 @@ int main(int argc, char *argv[]) {
cerr << "Found test keys." << endl;
}
if (generateTestKeys && !keysExist && !ExitHandler::shouldExit()) {
cerr << "Generating test keys ..." << endl;
......@@ -221,8 +219,6 @@ int main(int argc, char *argv[]) {
cerr << "Successfully completed generating test keys into sgx_data" << endl;
}
while ( !ExitHandler::shouldExit() ) {
sleep(10);
}
......
......@@ -98,11 +98,10 @@ class StubClient : public jsonrpc::Client
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value getVerificationVector(const std::string& polyName, int t, int n)
Json::Value getVerificationVector(const std::string& polyName, int t)
{
Json::Value p;
p["polyName"] = polyName;
p["n"] = n;
p["t"] = t;
Json::Value result = this->CallMethod("getVerificationVector",p);
if (result.isObject())
......
This diff is collapsed.
......@@ -29,35 +29,40 @@ username = getpass.getuser()
topDir = os.getcwd() + "/sgxwallet"
print("Top directory is:" + topDir)
testList = [ "[zmq-ecdsa]",
"[dkgzmqbls]",
"[first-run]",
"[second-run]",
"[many-threads-crypto]",
"[many-threads-crypto-v2]",
"[backup-restore]",
"[cert-sign]",
"[get-server-status]",
"[get-server-version]",
"[backup-key]",
"[delete-bls-key]",
"[import-ecdsa-key]",
"[ecdsa-aes-key-gen]",
"[ecdsa-aes-key-sig-gen]",
"[ecdsa-aes-get-pub-key]",
"[ecdsa-key-gen-api]",
"[bls-key-encrypt]",
"[dkg-aes-gen]",
"[dkg-aes-encr-sshares]",
"[dkg-aes-encr-sshares-v2]",
"[dkg-api]",
"[dkg-api-v2]",
"[dkg-bls]",
"[dkg-bls-v2]",
"[dkg-poly-exists]",
"[dkg-aes-pub-shares]",
"[aes-encrypt-decrypt]",
"[aes-dkg]",
"[aes-dkg-v2]"
"[second-run]",
"[many-threads-crypto-v2]",
"[many-threads-crypto-v2-zmq]"
"[backup-restore]",
"[cert-sign]",
"[get-server-status]",
"[get-server-status-zmq]",
"[get-server-version]",
"[get-server-version-zmq]",
"[backup-key]",
"[delete-bls-key]",
"[delete-bls-key-zmq]",
"[import-ecdsa-key]",
"[import-ecdsa-key-zmq]",
"[ecdsa-aes-key-gen]",
"[ecdsa-aes-key-sig-gen]",
"[ecdsa-aes-get-pub-key]",
"[ecdsa-key-gen-api]",
"[bls-key-encrypt]",
"[dkg-aes-gen]",
"[dkg-aes-encr-sshares]",
"[dkg-aes-encr-sshares-v2]",
"[dkg-api-v2]",
"[dkg-api-v2-zmq]",
"[dkg-bls]",
"[dkgzmqbls]",
"[dkg-bls-v2]",
"[dkg-poly-exists]",
"[dkg-poly-exists-zmq]",
"[dkg-aes-pub-shares]",
"[aes-encrypt-decrypt]",
"[aes-dkg-v2]",
"[aes-dkg-v2-zmq]"
]
......
/*
Copyright (C) 2018-2019 SKALE Labs
This file is part of libBLS.
This file is part of sgxwallet.
libBLS is free software: you can redistribute it and/or modify
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.
libBLS is distributed in the hope that it will be useful,
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 libBLS. If not, see <https://www.gnu.org/licenses/>.
along with sgxwallet. If not, see <https://www.gnu.org/licenses/>.
@file BLSRspSignMessage.h
@file BLSRspSignMessage.cpp
@author Stan Kladko
@date 2020
*/
......
/*
Copyright (C) 2018-2019 SKALE Labs
This file is part of libBLS.
This file is part of sgxwallet.
libBLS is free software: you can redistribute it and/or modify
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.
libBLS is distributed in the hope that it will be useful,
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 libBLS. If not, see <https://www.gnu.org/licenses/>.
along with sgxwallet. If not, see <https://www.gnu.org/licenses/>.
@file BLSRspSignMessage.h
@author Stan Kladko
......
/*
Copyright (C) 2018- SKALE Labs
This file is part of libBLS.
This file is part of sgxwallet.
libBLS is free software: you can redistribute it and/or modify
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.
libBLS is distributed in the hope that it will be useful,
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 libBLS. If not, see <https://www.gnu.org/licenses/>.
along with sgxwallet. If not, see <https://www.gnu.org/licenses/>.
@file ECDSARspSignMessage.cpp
@author Stan Kladko
......
/*
Copyright (C) 2018- SKALE Labs
This file is part of libBLS.
This file is part of sgxwallet.
libBLS is free software: you can redistribute it and/or modify
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.
libBLS is distributed in the hope that it will be useful,
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 libBLS. If not, see <https://www.gnu.org/licenses/>.
along with sgxwallet. If not, see <https://www.gnu.org/licenses/>.
@file ECDSARspSignMessage.h
@author Stan Kladko
......
/*
Copyright (C) 2018- 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 ReqMessage.cpp
@author Oleh Nikolaiev
@date 2021
*/
#include "SGXWalletServer.hpp"
#include "ReqMessage.h"
Json::Value ECDSASignReqMessage::process() {
auto base = getInt64Rapid("base");
auto keyName = getStringRapid("keyName");
auto hash = getStringRapid("messageHash");
auto result = SGXWalletServer::ecdsaSignMessageHashImpl(base, keyName, hash);
result["type"] = ZMQMessage::ECDSA_SIGN_RSP;
return result;
}
Json::Value BLSSignReqMessage::process() {
auto keyName = getStringRapid("keyShareName");
auto hash = getStringRapid("messageHash");
auto t = getInt64Rapid("t");
auto n = getInt64Rapid("n");
auto result = SGXWalletServer::blsSignMessageHashImpl(keyName, hash, t, n);
result["type"] = ZMQMessage::BLS_SIGN_RSP;
return result;
}
Json::Value importBLSReqMessage::process() {
auto keyName = getStringRapid("keyShareName");
auto keyShare = getStringRapid("keyShare");
auto result = SGXWalletServer::importBLSKeyShareImpl(keyShare, keyName);
result["type"] = ZMQMessage::IMPORT_BLS_RSP;
return result;
}
Json::Value importECDSAReqMessage::process() {
auto keyName = getStringRapid("keyName");
auto key = getStringRapid("key");
auto result = SGXWalletServer::importECDSAKeyImpl(key, keyName);
result["type"] = ZMQMessage::IMPORT_ECDSA_RSP;
return result;
}
Json::Value generateECDSAReqMessage::process() {
auto result = SGXWalletServer::generateECDSAKeyImpl();
result["type"] = ZMQMessage::GENERATE_ECDSA_RSP;
return result;
}
Json::Value getPublicECDSAReqMessage::process() {
auto keyName = getStringRapid("keyName");
auto result = SGXWalletServer::getPublicECDSAKeyImpl(keyName);
result["type"] = ZMQMessage::GET_PUBLIC_ECDSA_RSP;
return result;
}
Json::Value generateDKGPolyReqMessage::process() {
auto polyName = getStringRapid("polyName");
auto t = getInt64Rapid("t");
auto result = SGXWalletServer::generateDKGPolyImpl(polyName, t);
result["type"] = ZMQMessage::GENERATE_DKG_POLY_RSP;
return result;
}
Json::Value getVerificationVectorReqMessage::process() {
auto polyName = getStringRapid("polyName");
auto t = getInt64Rapid("t");
auto result = SGXWalletServer::getVerificationVectorImpl(polyName, t);
result["type"] = ZMQMessage::GET_VV_RSP;
return result;
}
Json::Value getSecretShareReqMessage::process() {
auto polyName = getStringRapid("polyName");
auto t = getInt64Rapid("t");
auto n = getInt64Rapid("n");
auto pubKeys = getJsonValueRapid("publicKeys");
auto result = SGXWalletServer::getSecretShareV2Impl(polyName, pubKeys, t, n);
result["type"] = ZMQMessage::GET_SECRET_SHARE_RSP;
return result;
}
Json::Value dkgVerificationReqMessage::process() {
auto ethKeyName = getStringRapid("ethKeyName");
auto t = getInt64Rapid("t");
auto n = getInt64Rapid("n");
auto idx = getInt64Rapid("index");
auto pubShares = getStringRapid("publicShares");
auto secretShare = getStringRapid("secretShare");
auto result = SGXWalletServer::dkgVerificationV2Impl(pubShares, ethKeyName, secretShare, t, n, idx);
result["type"] = ZMQMessage::DKG_VERIFY_RSP;
return result;
}
Json::Value createBLSPrivateKeyReqMessage::process() {
auto blsKeyName = getStringRapid("blsKeyName");
auto ethKeyName = getStringRapid("ethKeyName");
auto polyName = getStringRapid("polyName");
auto secretShare = getStringRapid("secretShare");
auto t = getInt64Rapid("t");
auto n = getInt64Rapid("n");
auto result = SGXWalletServer::createBLSPrivateKeyV2Impl(blsKeyName, ethKeyName, polyName, secretShare, t, n);
result["type"] = ZMQMessage::CREATE_BLS_PRIVATE_RSP;
return result;
}
Json::Value getBLSPublicReqMessage::process() {
auto blsKeyName = getStringRapid("blsKeyName");
auto result = SGXWalletServer::getBLSPublicKeyShareImpl(blsKeyName);
result["type"] = ZMQMessage::GET_BLS_PUBLIC_RSP;
return result;
}
Json::Value getAllBLSPublicKeysReqMessage::process() {
auto t = getInt64Rapid("t");
auto n = getInt64Rapid("n");
auto pubShares = getJsonValueRapid("publicShares");
auto result = SGXWalletServer::calculateAllBLSPublicKeysImpl(pubShares, t, n);
result["type"] = ZMQMessage::GET_ALL_BLS_PUBLIC_RSP;
return result;
}
Json::Value complaintResponseReqMessage::process() {
auto polyName = getStringRapid("polyName");
auto t = getInt64Rapid("t");
auto n = getInt64Rapid("n");
auto idx = getInt64Rapid("ind");
auto result = SGXWalletServer::complaintResponseImpl(polyName, t, n, idx);
result["type"] = ZMQMessage::COMPLAINT_RESPONSE_RSP;
return result;
}
Json::Value multG2ReqMessage::process() {
auto x = getStringRapid("x");
auto result = SGXWalletServer::multG2Impl(x);
result["type"] = ZMQMessage::MULT_G2_RSP;
return result;
}
Json::Value isPolyExistsReqMessage::process() {
auto polyName = getStringRapid("polyName");
auto result = SGXWalletServer::isPolyExistsImpl(polyName);
result["type"] = ZMQMessage::IS_POLY_EXISTS_RSP;
return result;
}
Json::Value getServerStatusReqMessage::process() {
auto result = SGXWalletServer::getServerStatusImpl();
result["type"] = ZMQMessage::GET_SERVER_STATUS_RSP;
return result;
}
Json::Value getServerVersionReqMessage::process() {
auto result = SGXWalletServer::getServerVersionImpl();
result["type"] = ZMQMessage::GET_SERVER_VERSION_RSP;
return result;
}
Json::Value deleteBLSKeyReqMessage::process() {
auto blsKeyName = getStringRapid("blsKeyName");
auto result = SGXWalletServer::deleteBlsKeyImpl(blsKeyName);
result["type"] = ZMQMessage::DELETE_BLS_KEY_RSP;
return result;
}
/*
Copyright (C) 2018- 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 ReqMessage.h
@author Oleh Nikolaiev
@date 2021
*/
#ifndef SGXWALLET_REQMESSAGE_H
#define SGXWALLET_REQMESSAGE_H
#include "ZMQMessage.h"
class ECDSASignReqMessage : public ZMQMessage {
public:
ECDSASignReqMessage(shared_ptr <rapidjson::Document> &_d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
class BLSSignReqMessage : public ZMQMessage {
public:
BLSSignReqMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
class importBLSReqMessage : public ZMQMessage {
public:
importBLSReqMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
class importECDSAReqMessage : public ZMQMessage {
public:
importECDSAReqMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
class generateECDSAReqMessage : public ZMQMessage {
public:
generateECDSAReqMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
class getPublicECDSAReqMessage : public ZMQMessage {
public:
getPublicECDSAReqMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
class generateDKGPolyReqMessage : public ZMQMessage {
public:
generateDKGPolyReqMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
class getVerificationVectorReqMessage : public ZMQMessage {
public:
getVerificationVectorReqMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
class getSecretShareReqMessage : public ZMQMessage {
public:
getSecretShareReqMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
class dkgVerificationReqMessage : public ZMQMessage {
public:
dkgVerificationReqMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
class createBLSPrivateKeyReqMessage : public ZMQMessage {
public:
createBLSPrivateKeyReqMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
class getBLSPublicReqMessage : public ZMQMessage {
public:
getBLSPublicReqMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
class getAllBLSPublicKeysReqMessage : public ZMQMessage {
public:
getAllBLSPublicKeysReqMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
class complaintResponseReqMessage : public ZMQMessage {
public:
complaintResponseReqMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
class multG2ReqMessage : public ZMQMessage {
public:
multG2ReqMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
class isPolyExistsReqMessage : public ZMQMessage {
public:
isPolyExistsReqMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
class getServerStatusReqMessage : public ZMQMessage {
public:
getServerStatusReqMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
class getServerVersionReqMessage : public ZMQMessage {
public:
getServerVersionReqMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
class deleteBLSKeyReqMessage : public ZMQMessage {
public:
deleteBLSKeyReqMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
#endif //SGXWALLET_REQMESSAGE_H
/*
Copyright (C) 2018- 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 RspMessage.cpp
@author Oleh Nikolaiev
@date 2021
*/
#include "SGXWalletServer.hpp"
#include "RspMessage.h"
Json::Value ECDSASignRspMessage::process() {
assert(false);
}
string ECDSASignRspMessage::getSignature() {
string r = getStringRapid("signature_r");
string v = getStringRapid("signature_v");
string s = getStringRapid("signature_s");
auto ret = v + ":" + r.substr( 2 ) + ":" + s.substr( 2 );
return ret;
}
Json::Value BLSSignRspMessage::process() {
assert(false);
}
Json::Value importBLSRspMessage::process() {
assert(false);
}
Json::Value importECDSARspMessage::process() {
assert(false);
}
Json::Value generateECDSARspMessage::process() {
assert(false);
}
Json::Value getPublicECDSARspMessage::process() {
assert(false);
}
Json::Value generateDKGPolyRspMessage::process() {
assert(false);
}
Json::Value getVerificationVectorRspMessage::process() {
assert(false);
}
Json::Value getSecretShareRspMessage::process() {
assert(false);
}
Json::Value dkgVerificationRspMessage::process() {
assert(false);
}
Json::Value createBLSPrivateKeyRspMessage::process() {
assert(false);
}
Json::Value getBLSPublicRspMessage::process() {
assert(false);
}
Json::Value getAllBLSPublicKeysRspMessage::process() {
assert(false);
}
Json::Value complaintResponseRspMessage::process() {
assert(false);
}
Json::Value multG2RspMessage::process() {
assert(false);
}
Json::Value isPolyExistsRspMessage::process() {
assert(false);
}
Json::Value getServerStatusRspMessage::process() {
assert(false);
}
Json::Value getServerVersionRspMessage::process() {
assert(false);
}
Json::Value deleteBLSKeyRspMessage::process() {
assert(false);
}
/*
Copyright (C) 2018- 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 RspMessage.h
@author Oleh Nikolaiev
@date 2021
*/
#ifndef SGXWALLET_RSPMESSAGE_H
#define SGXWALLET_RSPMESSAGE_H
#include "ZMQMessage.h"
class ECDSASignRspMessage : public ZMQMessage {
public:
ECDSASignRspMessage(shared_ptr <rapidjson::Document> &_d) : ZMQMessage(_d) {};
virtual Json::Value process();
string getSignature();
};
class BLSSignRspMessage : public ZMQMessage {
public:
BLSSignRspMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
string getSigShare() {
return getStringRapid("signatureShare");
}
};
class importBLSRspMessage : public ZMQMessage {
public:
importBLSRspMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
class importECDSARspMessage : public ZMQMessage {
public:
importECDSARspMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
string getECDSAPublicKey() {
return getStringRapid("publicKey");
}
};
class generateECDSARspMessage : public ZMQMessage {
public:
generateECDSARspMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
string getECDSAPublicKey() {
return getStringRapid("publicKey");
}
string getKeyName() {
return getStringRapid("keyName");
}
};
class getPublicECDSARspMessage : public ZMQMessage {
public:
getPublicECDSARspMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
string getECDSAPublicKey() {
return getStringRapid("publicKey");
}
};
class generateDKGPolyRspMessage : public ZMQMessage {
public:
generateDKGPolyRspMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
class getVerificationVectorRspMessage : public ZMQMessage {
public:
getVerificationVectorRspMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
Json::Value getVerificationVector() {
return getJsonValueRapid("verificationVector");
}
};
class getSecretShareRspMessage : public ZMQMessage {
public:
getSecretShareRspMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
string getSecretShare() {
return getStringRapid("secretShare");
}
};
class dkgVerificationRspMessage : public ZMQMessage {
public:
dkgVerificationRspMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
bool isCorrect() {
return getBoolRapid("result");
}
};
class createBLSPrivateKeyRspMessage : public ZMQMessage {
public:
createBLSPrivateKeyRspMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
class getBLSPublicRspMessage : public ZMQMessage {
public:
getBLSPublicRspMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
Json::Value getBLSPublicKey() {
return getJsonValueRapid("blsPublicKeyShare");
}
};
class getAllBLSPublicKeysRspMessage : public ZMQMessage {
public:
getAllBLSPublicKeysRspMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
Json::Value getPublicKeys() {
return getJsonValueRapid("publicKeys");
}
};
class complaintResponseRspMessage : public ZMQMessage {
public:
complaintResponseRspMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
string getDHKey() {
return getStringRapid("dhKey");
}
string getShare() {
return getStringRapid("share*G2");
}
Json::Value getVerificationVectorMult() {
return getJsonValueRapid("verificationVectorMult");
}
};
class multG2RspMessage : public ZMQMessage {
public:
multG2RspMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
Json::Value getResult() {
return getJsonValueRapid("x*G2");
}
};
class isPolyExistsRspMessage : public ZMQMessage {
public:
isPolyExistsRspMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
bool isExists() {
return getBoolRapid("IsExist");
}
};
class getServerStatusRspMessage : public ZMQMessage {
public:
getServerStatusRspMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
class getServerVersionRspMessage : public ZMQMessage {
public:
getServerVersionRspMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
string getVersion() {
return getStringRapid("version");
}
};
class deleteBLSKeyRspMessage : public ZMQMessage {
public:
deleteBLSKeyRspMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
bool isSuccessful() {
return getBoolRapid("deleted");
}
};
#endif //SGXWALLET_RSPMESSAGE_H
This diff is collapsed.
/*
Copyright (C) 2018-2019 SKALE Labs
This file is part of skale-consensus.
This file is part of sgxwallet.
skale-consensus is free software: you can redistribute it and/or modify
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.
skale-consensus is distributed in the hope that it will be useful,
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 skale-consensus. If not, see <https://www.gnu.org/licenses/>.
along with sgxwallet. If not, see <https://www.gnu.org/licenses/>.
@file ZMQClient.h
@author Stan Kladko
@date 2021
*/
#ifndef SGXWALLET_ZMQCLIENT_H
#define SGXWALLET_ZMQCLIENT_H
......@@ -40,28 +37,21 @@
#include <jsonrpccpp/client.h>
#include "ZMQMessage.h"
#define REQUEST_TIMEOUT 10000 // msecs, (> 1000!)
class ZMQClient {
private:
EVP_PKEY* pkey = 0;
EVP_PKEY* pubkey = 0;
X509* x509Cert = 0;
bool sign = true;
string certFileName = "";
string certKeyName = "";
string certificate = "";
string key = "";
recursive_mutex mutex;
zmq::context_t ctx;
......@@ -82,24 +72,57 @@ private:
public:
ZMQClient(const string &ip, uint16_t port, bool _sign, const string& _certPathName,
const string& _certKeyName);
void reconnect() ;
void reconnect();
static pair<EVP_PKEY*, X509*> readPublicKeyFromCertStr(const string& _cert);
static string signString(EVP_PKEY* _pkey, const string& _str);
static void verifySig(EVP_PKEY* _pubkey, const string& _str, const string& _sig);
static void verifySig(EVP_PKEY* _pubkey, const string& _str, const string& _sig);
string blsSignMessageHash(const std::string &keyShareName, const std::string &messageHash, int t, int n);
string ecdsaSignMessageHash(int base, const std::string &keyName, const std::string &messageHash);
};
bool importBLSKeyShare(const std::string& keyShare, const std::string& keyName);
string importECDSAKey(const std::string& keyShare, const std::string& keyName);
pair<string, string> generateECDSAKey();
string getECDSAPublicKey(const string& keyName);
bool generateDKGPoly(const string& polyName, int t);
Json::Value getVerificationVector(const string& polyName, int t);
string getSecretShare(const string& polyName, const Json::Value& pubKeys, int t, int n);
bool dkgVerification(const string& publicShares, const string& ethKeyName,
const string& secretShare, int t, int n, int idx);
bool createBLSPrivateKey(const string& blsKeyName, const string& ethKeyName, const string& polyName,
const string& secretShare, int t, int n);
Json::Value getBLSPublicKey(const string& blsKeyName);
Json::Value getAllBlsPublicKeys(const Json::Value& publicShares, int n, int t);
tuple<string, string, Json::Value> complaintResponse(const string& polyName, int t, int n, int idx);
Json::Value multG2(const string& x);
bool isPolyExists(const string& polyName);
void getServerStatus();
string getServerVersion();
bool deleteBLSKey(const string& blsKeyName);
};
#endif //SGXWALLET_ZMQCLIENT_H
This diff is collapsed.
......@@ -49,29 +49,81 @@ class ZMQMessage {
shared_ptr<rapidjson::Document> d;
static cache::lru_cache<string, pair<EVP_PKEY*, X509*>> verifiedCerts;
protected:
public:
static constexpr const char *BLS_SIGN_REQ = "BLSSignReq";
static constexpr const char *BLS_SIGN_RSP = "BLSSignRsp";
static constexpr const char *ECDSA_SIGN_REQ = "ECDSASignReq";
static constexpr const char *ECDSA_SIGN_RSP = "ECDSASignRsp";
explicit ZMQMessage(shared_ptr<rapidjson::Document> &_d) : d(_d) {
};
static constexpr const char *IMPORT_BLS_REQ = "importBLSReq";
static constexpr const char *IMPORT_BLS_RSP = "importBLSRps";
static constexpr const char *IMPORT_ECDSA_REQ = "importECDSAReq";
static constexpr const char *IMPORT_ECDSA_RSP = "importECDSARsp";
static constexpr const char *GENERATE_ECDSA_REQ = "generateECDSAReq";
static constexpr const char *GENERATE_ECDSA_RSP = "generateECDSARsp";
static constexpr const char *GET_PUBLIC_ECDSA_REQ = "getPublicECDSAReq";
static constexpr const char *GET_PUBLIC_ECDSA_RSP = "getPublicECDSARsp";
static constexpr const char *GENERATE_DKG_POLY_REQ = "generateDKGPolyReq";
static constexpr const char *GENERATE_DKG_POLY_RSP = "generateDKGPolyRsp";
static constexpr const char *GET_VV_REQ = "getVerificationVectorReq";
static constexpr const char *GET_VV_RSP = "getVerificationVectorRsp";
static constexpr const char *GET_SECRET_SHARE_REQ = "getSecretShareReq";
static constexpr const char *GET_SECRET_SHARE_RSP = "getSecretShareRsp";
static constexpr const char *DKG_VERIFY_REQ = "dkgVerificationReq";
static constexpr const char *DKG_VERIFY_RSP = "dkgVerificationRsp";
static constexpr const char *CREATE_BLS_PRIVATE_REQ = "createBLSPrivateReq";
static constexpr const char *CREATE_BLS_PRIVATE_RSP = "createBLSPrivateRsp";
static constexpr const char *GET_BLS_PUBLIC_REQ = "getBLSPublicReq";
static constexpr const char *GET_BLS_PUBLIC_RSP = "getBLSPublicRsp";
static constexpr const char *GET_ALL_BLS_PUBLIC_REQ = "getAllBLSPublicReq";
static constexpr const char *GET_ALL_BLS_PUBLIC_RSP = "getAllBLSPublicRsp";
static constexpr const char *COMPLAINT_RESPONSE_REQ = "complaintResponseReq";
static constexpr const char *COMPLAINT_RESPONSE_RSP = "complaintResponseRsp";
static constexpr const char *MULT_G2_REQ = "multG2Req";
static constexpr const char *MULT_G2_RSP = "multG2Rsp";
static constexpr const char *IS_POLY_EXISTS_REQ = "isPolyExistsReq";
static constexpr const char *IS_POLY_EXISTS_RSP = "isPolyExistsRsp";
static constexpr const char *GET_SERVER_STATUS_REQ = "getServerStatusReq";
static constexpr const char *GET_SERVER_STATUS_RSP = "getServerStatusRsp";
static constexpr const char *GET_SERVER_VERSION_REQ = "getServerVersionReq";
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_RSP = "deleteBLSKeyRsp";
static const std::map<string, int> requests;
static const std::map<string, int> responses;
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_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 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_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 };
explicit ZMQMessage(shared_ptr<rapidjson::Document> &_d) : d(_d) {};
string getStringRapid(const char *_name);
uint64_t getUint64Rapid(const char *_name);
uint64_t getInt64Rapid(const char *_name);
Json::Value getJsonValueRapid(const char *_name);
bool getBoolRapid(const char *_name);
uint64_t getStatus() {
return getUint64Rapid("status");
return getInt64Rapid("status");
}
std::string rapidToString() {
rapidjson::StringBuffer buffer;
rapidjson::Writer< rapidjson::StringBuffer > writer( buffer );
d->Accept( writer );
std::string strRequest = buffer.GetString();
return strRequest;
}
static shared_ptr <ZMQMessage> parse(const char* _msg, size_t _size, bool _isRequest,
......@@ -82,4 +134,4 @@ public:
virtual Json::Value process() = 0;
};
\ No newline at end of file
};
......@@ -42,7 +42,6 @@ ZMQServer::ZMQServer(bool _checkSignature, const string &_caCertFile)
: checkSignature(_checkSignature),
caCertFile(_caCertFile), ctx(make_shared<zmq::context_t>(1)) {
socket = make_shared<zmq::socket_t>(*ctx, ZMQ_ROUTER);
if (_checkSignature) {
......@@ -56,10 +55,8 @@ ZMQServer::ZMQServer(bool _checkSignature, const string &_caCertFile)
int linger = 0;
zmq_setsockopt(*socket, ZMQ_LINGER, &linger, sizeof(linger));
}
void ZMQServer::run() {
auto port = BASE_PORT + 5;
......@@ -85,10 +82,8 @@ void ZMQServer::run() {
}
spdlog::info("Exited zmq server loop");
}
std::atomic<bool> ZMQServer::isExitRequested(false);
void ZMQServer::exitZMQServer() {
......@@ -99,7 +94,6 @@ void ZMQServer::exitZMQServer() {
spdlog::info("Exited zmq server.");
}
void ZMQServer::initZMQServer(bool _checkSignature) {
static bool initedServer = false;
CHECK_STATE(!initedServer)
......@@ -123,15 +117,11 @@ void ZMQServer::initZMQServer(bool _checkSignature) {
serverThread->detach();
spdlog::info("Inited zmq server ...");
}
shared_ptr <std::thread> ZMQServer::serverThread = nullptr;
ZMQServer::~ZMQServer() {
}
ZMQServer::~ZMQServer() {}
void ZMQServer::doOneServerLoop() {
......@@ -142,10 +132,8 @@ void ZMQServer::doOneServerLoop() {
result["errorMessage"] = "";
zmq::message_t identity;
zmq::message_t identit2;
zmq::message_t copied_id;
string stringToParse = "";
try {
......@@ -156,7 +144,6 @@ void ZMQServer::doOneServerLoop() {
int pollResult = 0;
do {
pollResult = zmq_poll(items, 1, 1000);
if (isExitRequested) {
......@@ -164,21 +151,18 @@ void ZMQServer::doOneServerLoop() {
}
} while (pollResult == 0);
if (!socket->recv(&identity)) {
// something terrible happened
spdlog::error("Fatal error: socket->recv(&identity) returned false");
exit(-11);
}
if (!identity.more()) {
// something terrible happened
spdlog::error("Fatal error: zmq_msg_more(identity) returned false");
exit(-12);
}
copied_id.copy(&identity);
zmq::message_t reqMsg;
......@@ -189,7 +173,6 @@ void ZMQServer::doOneServerLoop() {
exit(-13);
}
stringToParse = string((char *) reqMsg.data(), reqMsg.size());
CHECK_STATE(stringToParse.front() == '{')
......@@ -201,8 +184,7 @@ void ZMQServer::doOneServerLoop() {
CHECK_STATE2(parsedMsg, ZMQ_COULD_NOT_PARSE);
result = parsedMsg->process();
}
catch (std::exception &e) {
} catch (std::exception &e) {
if (isExitRequested) {
return;
}
......@@ -245,9 +227,7 @@ void ZMQServer::doOneServerLoop() {
exit(-16);
}
} catch (
std::exception &e
) {
} catch ( std::exception &e ) {
if (isExitRequested) {
return;
}
......
......@@ -61,8 +61,6 @@ public:
static void initZMQServer(bool _checkSignature);
static void exitZMQServer();
private:
shared_ptr<zmq::context_t> ctx;
shared_ptr<zmq::socket_t> socket;
......@@ -74,5 +72,4 @@ private:
};
#endif //SGXWALLET_ZMQServer_H
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