Unverified Commit 3a73a043 authored by kladko's avatar kladko

bug/SKALE-3751-enable-zeromq

parent dbf340bd
...@@ -173,7 +173,6 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) { ...@@ -173,7 +173,6 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) {
exit(-12); exit(-12);
} }
httpServer = make_shared<HttpServer>(BASE_PORT, certPath, keyPath, rootCAPath, _checkCerts, httpServer = make_shared<HttpServer>(BASE_PORT, certPath, keyPath, rootCAPath, _checkCerts,
NUM_THREADS); NUM_THREADS);
......
...@@ -116,7 +116,21 @@ string ZMQClient::doZmqRequestReply(string &_req) { ...@@ -116,7 +116,21 @@ string ZMQClient::doZmqRequestReply(string &_req) {
} }
ZMQClient::ZMQClient(string &ip, uint16_t port) : ctx(1) { ZMQClient::ZMQClient(const string &ip, uint16_t port, bool _sign, const string& _certFileName,
const string& _certKeyName) : ctx(1) {
if (_sign) {
CHECK_STATE(!_certFileName.empty());
CHECK_STATE(!_certKeyName.empty());
} else {
CHECK_STATE(_certFileName.empty());
CHECK_STATE(_certKeyName.empty());
}
certFileName = _certFileName;
certKeyName = _certKeyName;
url = "tcp://" + ip + ":" + to_string(port); url = "tcp://" + ip + ":" + to_string(port);
} }
......
...@@ -45,6 +45,9 @@ class ZMQClient { ...@@ -45,6 +45,9 @@ class ZMQClient {
private: private:
bool sign;
string certFileName;
string certKeyName;
recursive_mutex mutex; recursive_mutex mutex;
...@@ -66,7 +69,9 @@ private: ...@@ -66,7 +69,9 @@ private:
public: public:
ZMQClient(string &ip, uint16_t port); ZMQClient(const string &ip, uint16_t port, bool _sign, const string& _certPathName,
const string& _certKeyName);
void reconnect() ; void reconnect() ;
string blsSignMessageHash(const std::string &keyShareName, const std::string &messageHash, int t, int n); string blsSignMessageHash(const std::string &keyShareName, const std::string &messageHash, int t, int n);
......
...@@ -34,11 +34,15 @@ using namespace std; ...@@ -34,11 +34,15 @@ using namespace std;
ZMQServer *ZMQServer::zmqServer = nullptr; ZMQServer *ZMQServer::zmqServer = nullptr;
ZMQServer::ZMQServer() ZMQServer::ZMQServer(bool _checkSignature, const string& _caCertFile)
: isExitRequested(false), ctx_(make_shared<zmq::context_t>(1)), : checkSignature(_checkSignature),
caCertFile(_caCertFile), isExitRequested(false), ctx_(make_shared<zmq::context_t>(1)),
frontend_(*ctx_, ZMQ_ROUTER), frontend_(*ctx_, ZMQ_ROUTER),
backend_(*ctx_, ZMQ_DEALER) { backend_(*ctx_, ZMQ_DEALER) {
if (_checkSignature) {
CHECK_STATE(!_caCertFile.empty());
}
int linger = 0; int linger = 0;
zmq_setsockopt (frontend_, ZMQ_LINGER, &linger, sizeof (linger)); zmq_setsockopt (frontend_, ZMQ_LINGER, &linger, sizeof (linger));
...@@ -151,23 +155,26 @@ void ZMQServer::exitZMQServer() { ...@@ -151,23 +155,26 @@ void ZMQServer::exitZMQServer() {
zmqServer = nullptr; zmqServer = nullptr;
} }
void ZMQServer::initZMQServer(bool _useClientCert) { void ZMQServer::initZMQServer(bool _checkSignature) {
static bool initedServer = false; static bool initedServer = false;
CHECK_STATE(!initedServer) CHECK_STATE(!initedServer)
initedServer = true; initedServer = true;
spdlog::info("Initing zmq server ..."); spdlog::info("Initing zmq server ...");
zmqServer = new ZMQServer();
serverThread =make_shared<thread> (std::bind(&ZMQServer::run, ZMQServer::zmqServer));
string rootCAPath = "";
serverThread->detach(); if (_checkSignature) {
if (_useClientCert) {
string rootCAPath = string(SGXDATA_FOLDER) + "cert_data/rootCA.pem"; string rootCAPath = string(SGXDATA_FOLDER) + "cert_data/rootCA.pem";
CHECK_STATE(access(rootCAPath.c_str(), F_OK) == 0); CHECK_STATE(access(rootCAPath.c_str(), F_OK) == 0);
}; };
zmqServer = new ZMQServer(_checkSignature, rootCAPath);
serverThread =make_shared<thread> (std::bind(&ZMQServer::run, ZMQServer::zmqServer));
serverThread->detach();
spdlog::info("Inited zmq server ..."); spdlog::info("Inited zmq server ...");
} }
......
...@@ -44,11 +44,14 @@ using namespace std; ...@@ -44,11 +44,14 @@ using namespace std;
class ZMQServer { class ZMQServer {
public: public:
bool checkSignature = false;
string caCertFile = "";
static ZMQServer *zmqServer; static ZMQServer *zmqServer;
static shared_ptr<std::thread> serverThread; static shared_ptr<std::thread> serverThread;
ZMQServer(); ZMQServer(bool _checkSignature, const string& _caCertFile);
enum { enum {
kMaxThread = 1 kMaxThread = 1
...@@ -58,7 +61,7 @@ public: ...@@ -58,7 +61,7 @@ public:
void exitWorkers(); void exitWorkers();
static void initZMQServer(bool _useClientCert); static void initZMQServer(bool _checkSignature);
static void exitZMQServer(); static void exitZMQServer();
......
...@@ -492,7 +492,9 @@ TEST_CASE_METHOD(TestFixture, "DKG_BLS ZMQ test", "[dkgblszmq]") { ...@@ -492,7 +492,9 @@ TEST_CASE_METHOD(TestFixture, "DKG_BLS ZMQ test", "[dkgblszmq]") {
StubClient c(client, JSONRPC_CLIENT_V2); StubClient c(client, JSONRPC_CLIENT_V2);
string ip = ZMQ_IP; string ip = ZMQ_IP;
auto zmqClient = make_shared<ZMQClient>(ip, ZMQ_PORT);
string empty = "";
auto zmqClient = make_shared<ZMQClient>(ip, ZMQ_PORT, false, empty, empty);
vector <string> ecdsaKeyNames; vector <string> ecdsaKeyNames;
vector <string> blsKeyNames; vector <string> blsKeyNames;
...@@ -935,7 +937,7 @@ TEST_CASE_METHOD(TestFixture, "ZMQ-ecdsa", "[zmq-ecdsa]") { ...@@ -935,7 +937,7 @@ TEST_CASE_METHOD(TestFixture, "ZMQ-ecdsa", "[zmq-ecdsa]") {
string ip = ZMQ_IP; string ip = ZMQ_IP;
auto client = make_shared<ZMQClient>(ip, ZMQ_PORT); auto client = make_shared<ZMQClient>(ip, ZMQ_PORT, false, "", "");
string keyName = ""; string keyName = "";
......
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