Unverified Commit f5c170c9 authored by kladko's avatar kladko

Adding ZMQ

parent de0b34bb
......@@ -3,3 +3,13 @@
//
#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 @@
class BLSSignReqMessage : public ZMQMessage {
public:
BLSSignReqMessage(shared_ptr<rapidjson::Document>& _d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
......
......@@ -2,4 +2,17 @@
// Created by kladko on 15.12.20.
//
#include <json/value.h>
#include "SGXWalletServer.hpp"
#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 @@
class ECDSASignReqMessage : public ZMQMessage {
public:
ECDSASignReqMessage(shared_ptr <rapidjson::Document> &_d) : ZMQMessage(_d) {};
virtual Json::Value process();
};
......
......@@ -69,7 +69,7 @@ bin_PROGRAMS = sgxwallet testw cert_util
## 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 \
ECDSACrypto.cpp \
DKGCrypto.cpp ServerInit.cpp BLSPrivateKeyShareSGX.cpp LevelDB.cpp ServerDataChecker.cpp SEKManager.cpp \
......
......@@ -25,8 +25,11 @@
#include "abstractstubserver.h"
#include <jsonrpccpp/server/connectors/httpserver.h>
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <unistd.h>
#include "sgxwallet_common.h"
#include "sgxwallet.h"
......@@ -42,13 +45,6 @@
#include "SGXWalletServer.hpp"
#include "ServerDataChecker.h"
#include <algorithm>
#include <stdlib.h>
#include <unistd.h>
#include "ServerInit.h"
#include "Log.h"
......@@ -312,6 +308,8 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin
result["signatureShare"] = string(signature.data());
RETURN_SUCCESS(result);
}
......
......@@ -25,7 +25,8 @@
#define SGXWALLET_SGXWALLETSERVER_HPP
#include "mutex"
#include "memory"
#include <jsonrpccpp/server/connectors/httpserver.h>
......
......@@ -122,11 +122,14 @@ void initUserSpace() {
systemHealthCheck();
#endif
#ifdef EXPERIMENTAL_ZMQ_SERVER
zmqServer = new ZMQServer();
static std::thread serverThread(std::bind(&ZMQServer::run, zmqServer));
#endif
}
void exitZMQServer() {
#ifdef EXPERIMENTAL_ZMQ_SERVER
auto doExit = !exiting.exchange(true);
......@@ -137,6 +140,7 @@ void exitZMQServer() {
zmqServer = nullptr;
}
#endif
}
uint64_t initEnclave() {
......
......@@ -2,6 +2,7 @@
// Created by kladko on 14.12.20.
//
#include "common.h"
#include <json/writer.h>
#include "ZMQMessage.h"
#include "ServerWorker.h"
......@@ -21,10 +22,17 @@ void ServerWorker::work() {
memcpy(msgData.data(), msg.data(), msg.size());
auto parseMsg = ZMQMessage::parse(msgData);
auto parsedMsg = ZMQMessage::parse(msgData);
copied_msg.copy(&msg);
worker_.send(copied_msg);
CHECK_STATE(parsedMsg);
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) {
......
......@@ -9,10 +9,10 @@
#include <thread>
#include <memory>
#include <functional>
#include <json/value.h>
#include <zmq.hpp>
#include "zhelpers.hpp"
#include "third_party/spdlog/spdlog.h"
#include "document.h"
......
......@@ -69,6 +69,6 @@ shared_ptr<ZMQMessage> ZMQMessage::parse(vector<uint8_t>& _msg) {
throw SGXException(-301, "Incorrect zmq message type: " + string(type));
}
return make_shared<ZMQMessage>(d);
return result;
}
......@@ -24,16 +24,19 @@
#pragma once
#include <memory>
#include <vector>
#include <json/value.h>
#include "document.h"
#include "SGXException.h"
using namespace std;
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_RSP = "BLSSignRsp";
......@@ -45,13 +48,15 @@ protected:
public:
explicit ZMQMessage(shared_ptr <rapidjson::Document> &_d) : d(_d) {
explicit ZMQMessage(shared_ptr<rapidjson::Document> &_d) : d(_d) {
};
string getStringRapid(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