Unverified Commit 0479b4f9 authored by kladko's avatar kladko

bug/SKALE-3751-enable-zeromq

parent e63a90f2
//
// Created by kladko on 14.12.20.
//
/*
Copyright (C) 2019-Present 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 ServerWorker.cpp
@author Stan Kladko
@date 2021
*/
#include "common.h"
#include <json/writer.h>
......
//
// Created by kladko on 14.12.20.
//
/*
Copyright (C) 2019-Present 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 ServerWorker.h
@author Stan Kladko
@date 2021
*/
#ifndef SGXWALLET_SERVERWORKER_H
#define SGXWALLET_SERVERWORKER_H
......
......@@ -40,11 +40,16 @@
shared_ptr <ZMQMessage> ZMQClient::doRequestReply(Json::Value &_req) {
Json::FastWriter fastWriter;
string reqStr = fastWriter.write(_req);
//if (sign) {
if (sign) {
CHECK_STATE(!certificate.empty());
_req["cert"] = certificate;
//}
_req["msgSig"] = "haha";
}
string reqStr = fastWriter.write(_req);
reqStr = reqStr.substr(0, reqStr.size() - 1);
CHECK_STATE(reqStr.front() == '{');
CHECK_STATE(reqStr.at(reqStr.size() - 1) == '}');
......@@ -118,16 +123,18 @@ string ZMQClient::doZmqRequestReply(string &_req) {
ZMQClient::ZMQClient(const string &ip, uint16_t port, bool _sign, const string &_certFileName,
const string &_certKeyName) : ctx(1) {
const string &_certKeyName) : ctx(1), sign(_sign),
certKeyName(_certKeyName), certFileName(_certFileName) {
if (_sign) {
spdlog::info("Initing ZMQClient. Sign:{} ", _sign);
if (sign) {
CHECK_STATE(!_certFileName.empty());
CHECK_STATE(!_certKeyName.empty());
ifstream t(_certFileName);
string str((istreambuf_iterator<char>(t)), istreambuf_iterator<char>());
certificate = str;
CHECK_STATE(!certificate.empty());
} else {
......
......@@ -45,10 +45,10 @@ class ZMQClient {
private:
bool sign;
bool sign = true;
string certFileName = "";
string certificate = "";
string certKeyName = "";
string certificate = "";
recursive_mutex mutex;
......
......@@ -22,7 +22,11 @@
*/
#include "common.h"
#include <third_party/cryptlite/sha256.h>
#include <iostream>
#include <fstream>
#include "SGXWalletServer.hpp"
#include "BLSSignReqMessage.h"
#include "BLSSignRspMessage.h"
#include "ECDSASignReqMessage.h"
......@@ -61,6 +65,7 @@ shared_ptr <ZMQMessage> ZMQMessage::parse(const char* _msg,
auto d = make_shared<rapidjson::Document>();
cerr << _msg << endl;
d->Parse(_msg);
CHECK_STATE(!d->HasParseError());
......@@ -73,7 +78,18 @@ shared_ptr <ZMQMessage> ZMQMessage::parse(const char* _msg,
if (d->HasMember("cert")) {
CHECK_STATE((*d)["cert"].IsString());
auto cert = make_shared<string>((*d)["cert"].GetString());
cerr << "Got cert:" << cert << endl;
string hash = cryptlite::sha256::hash_hex(*cert);
auto filepath = "/tmp/sgx_wallet_cert_hash_" + hash;
std::ofstream outFile(filepath);
outFile << *cert;
outFile.close();
CHECK_STATE(SGXWalletServer::verifyCert(filepath));
}
if (d->HasMember("msgSig")) {
......@@ -84,8 +100,6 @@ shared_ptr <ZMQMessage> ZMQMessage::parse(const char* _msg,
shared_ptr <ZMQMessage> result;
if (_isRequest) {
return buildRequest(type, d);
} else {
......
......@@ -953,7 +953,8 @@ TEST_CASE_METHOD(TestFixtureZMQSign, "ZMQ-ecdsa", "[zmq-ecdsa]") {
string ip = ZMQ_IP;
auto client = make_shared<ZMQClient>(ip, ZMQ_PORT, false, "", "");
auto client = make_shared<ZMQClient>(ip, ZMQ_PORT, true, "./sgx_data/cert_data/rootCA.pem",
"./sgx_data/cert_data/rootCA.key");
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