Unverified Commit f5c170c9 authored by kladko's avatar kladko

Adding ZMQ

parent de0b34bb
...@@ -3,3 +3,13 @@ ...@@ -3,3 +3,13 @@
// //
#include "BLSSignReqMessage.h" #include "BLSSignReqMessage.h"
#include "SGXWalletServer.hpp"
Json::Value BLSSignReqMessage::process() {
auto keyName = getStringRapid("kn");
auto hash = getStringRapid("mh");
auto t = getUint64Rapid("t");
auto n = getUint64Rapid("n");
return SGXWalletServer::blsSignMessageHashImpl(keyName, hash, t, n);
}
\ No newline at end of file
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
class BLSSignReqMessage : public ZMQMessage { class BLSSignReqMessage : public ZMQMessage {
public: public:
BLSSignReqMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {}; BLSSignReqMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
}; };
......
...@@ -2,4 +2,17 @@ ...@@ -2,4 +2,17 @@
// Created by kladko on 15.12.20. // Created by kladko on 15.12.20.
// //
#include <json/value.h>
#include "SGXWalletServer.hpp"
#include "ECDSASignReqMessage.h" #include "ECDSASignReqMessage.h"
Json::Value ECDSASignReqMessage::process() {
auto base = getUint64Rapid("bs");
auto keyName = getStringRapid("kn");
auto hash = getStringRapid("mh");
return SGXWalletServer::ecdsaSignMessageHashImpl(base, keyName, hash);
}
\ No newline at end of file
...@@ -9,7 +9,11 @@ ...@@ -9,7 +9,11 @@
class ECDSASignReqMessage : public ZMQMessage { class ECDSASignReqMessage : public ZMQMessage {
public: public:
ECDSASignReqMessage(shared_ptr <rapidjson::Document> &_d) : ZMQMessage(_d) {}; ECDSASignReqMessage(shared_ptr <rapidjson::Document> &_d) : ZMQMessage(_d) {};
virtual Json::Value process();
}; };
......
...@@ -69,7 +69,7 @@ bin_PROGRAMS = sgxwallet testw cert_util ...@@ -69,7 +69,7 @@ bin_PROGRAMS = sgxwallet testw cert_util
## have to be explicitly listed. ## have to be explicitly listed.
## have to be explicitly listed ## have to be explicitly listed
COMMON_SRC = ZMQMessage.cpp ZMQServer.cpp ServerWorker.cpp InvalidStateException.cpp Exception.cpp InvalidArgumentException.cpp Log.cpp \ COMMON_SRC = ECDSASignReqMessage.cpp BLSSignReqMessage.cpp ZMQMessage.cpp ZMQServer.cpp ServerWorker.cpp InvalidStateException.cpp Exception.cpp InvalidArgumentException.cpp Log.cpp \
SGXWalletServer.cpp SGXRegistrationServer.cpp CSRManagerServer.cpp BLSCrypto.cpp \ SGXWalletServer.cpp SGXRegistrationServer.cpp CSRManagerServer.cpp BLSCrypto.cpp \
ECDSACrypto.cpp \ ECDSACrypto.cpp \
DKGCrypto.cpp ServerInit.cpp BLSPrivateKeyShareSGX.cpp LevelDB.cpp ServerDataChecker.cpp SEKManager.cpp \ DKGCrypto.cpp ServerInit.cpp BLSPrivateKeyShareSGX.cpp LevelDB.cpp ServerDataChecker.cpp SEKManager.cpp \
......
...@@ -25,8 +25,11 @@ ...@@ -25,8 +25,11 @@
#include "abstractstubserver.h" #include "abstractstubserver.h"
#include <jsonrpccpp/server/connectors/httpserver.h> #include <jsonrpccpp/server/connectors/httpserver.h>
#include <stdio.h> #include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <unistd.h>
#include "sgxwallet_common.h" #include "sgxwallet_common.h"
#include "sgxwallet.h" #include "sgxwallet.h"
...@@ -42,13 +45,6 @@ ...@@ -42,13 +45,6 @@
#include "SGXWalletServer.hpp" #include "SGXWalletServer.hpp"
#include "ServerDataChecker.h" #include "ServerDataChecker.h"
#include <algorithm>
#include <stdlib.h>
#include <unistd.h>
#include "ServerInit.h" #include "ServerInit.h"
#include "Log.h" #include "Log.h"
...@@ -312,6 +308,8 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin ...@@ -312,6 +308,8 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin
result["signatureShare"] = string(signature.data()); result["signatureShare"] = string(signature.data());
RETURN_SUCCESS(result); RETURN_SUCCESS(result);
} }
......
...@@ -25,7 +25,8 @@ ...@@ -25,7 +25,8 @@
#define SGXWALLET_SGXWALLETSERVER_HPP #define SGXWALLET_SGXWALLETSERVER_HPP
#include "mutex"
#include "memory"
#include <jsonrpccpp/server/connectors/httpserver.h> #include <jsonrpccpp/server/connectors/httpserver.h>
......
...@@ -122,11 +122,14 @@ void initUserSpace() { ...@@ -122,11 +122,14 @@ void initUserSpace() {
systemHealthCheck(); systemHealthCheck();
#endif #endif
#ifdef EXPERIMENTAL_ZMQ_SERVER
zmqServer = new ZMQServer(); zmqServer = new ZMQServer();
static std::thread serverThread(std::bind(&ZMQServer::run, zmqServer)); static std::thread serverThread(std::bind(&ZMQServer::run, zmqServer));
#endif
} }
void exitZMQServer() { void exitZMQServer() {
#ifdef EXPERIMENTAL_ZMQ_SERVER
auto doExit = !exiting.exchange(true); auto doExit = !exiting.exchange(true);
...@@ -137,6 +140,7 @@ void exitZMQServer() { ...@@ -137,6 +140,7 @@ void exitZMQServer() {
zmqServer = nullptr; zmqServer = nullptr;
} }
#endif
} }
uint64_t initEnclave() { uint64_t initEnclave() {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Created by kladko on 14.12.20. // Created by kladko on 14.12.20.
// //
#include "common.h" #include "common.h"
#include <json/writer.h>
#include "ZMQMessage.h" #include "ZMQMessage.h"
#include "ServerWorker.h" #include "ServerWorker.h"
...@@ -21,10 +22,17 @@ void ServerWorker::work() { ...@@ -21,10 +22,17 @@ void ServerWorker::work() {
memcpy(msgData.data(), msg.data(), msg.size()); memcpy(msgData.data(), msg.data(), msg.size());
auto parseMsg = ZMQMessage::parse(msgData); auto parsedMsg = ZMQMessage::parse(msgData);
copied_msg.copy(&msg); CHECK_STATE(parsedMsg);
worker_.send(copied_msg);
auto reply = parsedMsg->process();
Json::FastWriter fastWriter;
std::string replyStr = fastWriter.write(reply);
zmq::message_t replyMsg(replyStr.c_str(),replyStr.size() + 1);
worker_.send(replyMsg);
} }
} }
catch (std::exception &e) { catch (std::exception &e) {
......
...@@ -9,10 +9,10 @@ ...@@ -9,10 +9,10 @@
#include <thread> #include <thread>
#include <memory> #include <memory>
#include <functional> #include <functional>
#include <json/value.h>
#include <zmq.hpp> #include <zmq.hpp>
#include "zhelpers.hpp" #include "zhelpers.hpp"
#include "third_party/spdlog/spdlog.h" #include "third_party/spdlog/spdlog.h"
#include "document.h" #include "document.h"
......
...@@ -69,6 +69,6 @@ shared_ptr<ZMQMessage> ZMQMessage::parse(vector<uint8_t>& _msg) { ...@@ -69,6 +69,6 @@ shared_ptr<ZMQMessage> ZMQMessage::parse(vector<uint8_t>& _msg) {
throw SGXException(-301, "Incorrect zmq message type: " + string(type)); throw SGXException(-301, "Incorrect zmq message type: " + string(type));
} }
return make_shared<ZMQMessage>(d); return result;
} }
...@@ -24,16 +24,19 @@ ...@@ -24,16 +24,19 @@
#pragma once #pragma once
#include <memory>
#include <vector>
#include <json/value.h>
#include "document.h" #include "document.h"
#include "SGXException.h" #include "SGXException.h"
using namespace std; using namespace std;
class ZMQMessage { class ZMQMessage {
shared_ptr <rapidjson::Document> d; shared_ptr<rapidjson::Document> d;
static constexpr const char *BLS_SIGN_REQ = "BLSSignReq"; static constexpr const char *BLS_SIGN_REQ = "BLSSignReq";
static constexpr const char *BLS_SIGN_RSP = "BLSSignRsp"; static constexpr const char *BLS_SIGN_RSP = "BLSSignRsp";
...@@ -45,13 +48,15 @@ protected: ...@@ -45,13 +48,15 @@ protected:
public: public:
explicit ZMQMessage(shared_ptr <rapidjson::Document> &_d) : d(_d) { explicit ZMQMessage(shared_ptr<rapidjson::Document> &_d) : d(_d) {
}; };
string getStringRapid(const char *_name); string getStringRapid(const char *_name);
uint64_t getUint64Rapid(const char *_name); uint64_t getUint64Rapid(const char *_name);
static shared_ptr <ZMQMessage> parse(vector <uint8_t> &_msg); static shared_ptr<ZMQMessage> parse(vector<uint8_t> &_msg);
virtual Json::Value process() = 0;
}; };
\ No newline at end of file
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