Unverified Commit 8482f666 authored by kladko's avatar kladko

Fixed docs

parent b0303b5c
...@@ -74,8 +74,8 @@ bool isStringDec(string &_str) { ...@@ -74,8 +74,8 @@ bool isStringDec(string &_str) {
} }
SGXWalletServer *s = nullptr; shared_ptr<SGXWalletServer> SGXWalletServer::server = nullptr;
HttpServer *httpServer = nullptr; shared_ptr<HttpServer> SGXWalletServer::httpServer = nullptr;
SGXWalletServer::SGXWalletServer(AbstractServerConnector &_connector, SGXWalletServer::SGXWalletServer(AbstractServerConnector &_connector,
serverVersion_t _type) serverVersion_t _type)
...@@ -130,11 +130,11 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) { ...@@ -130,11 +130,11 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) {
} }
} }
httpServer = new HttpServer(BASE_PORT, certPath, keyPath, rootCAPath, _checkCerts, 64); httpServer = make_shared<HttpServer>(BASE_PORT, certPath, keyPath, rootCAPath, _checkCerts, 64);
s = new SGXWalletServer(*httpServer, server = make_shared<SGXWalletServer>(*httpServer,
JSONRPC_SERVER_V2); // hybrid server (json-rpc 1.0 & 2.0) JSONRPC_SERVER_V2); // hybrid server (json-rpc 1.0 & 2.0)
if (!s->StartListening()) { if (!server->StartListening()) {
spdlog::error("SGX Server could not start listening"); spdlog::error("SGX Server could not start listening");
exit(-1); exit(-1);
} else { } else {
...@@ -146,10 +146,10 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) { ...@@ -146,10 +146,10 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) {
int SGXWalletServer::initHttpServer() { //without ssl int SGXWalletServer::initHttpServer() { //without ssl
httpServer = new HttpServer(BASE_PORT + 3); httpServer = make_shared<HttpServer>(BASE_PORT + 3);
s = new SGXWalletServer(*httpServer, server = make_shared<SGXWalletServer>(*httpServer,
JSONRPC_SERVER_V2); // hybrid server (json-rpc 1.0 & 2.0) JSONRPC_SERVER_V2); // hybrid server (json-rpc 1.0 & 2.0)
if (!s->StartListening()) { if (!server->StartListening()) {
spdlog::error("Server could not start listening"); spdlog::error("Server could not start listening");
exit(-1); exit(-1);
} }
...@@ -207,7 +207,7 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin ...@@ -207,7 +207,7 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin
char *signature = (char *) calloc(BUF_LEN, 1); char *signature = (char *) calloc(BUF_LEN, 1);
shared_ptr<string> value = nullptr; shared_ptr <string> value = nullptr;
try { try {
if (!checkName(_keyShareName, "BLS_KEY")) { if (!checkName(_keyShareName, "BLS_KEY")) {
...@@ -274,7 +274,7 @@ Json::Value SGXWalletServer::generateECDSAKeyImpl() { ...@@ -274,7 +274,7 @@ Json::Value SGXWalletServer::generateECDSAKeyImpl() {
result["encryptedKey"] = ""; result["encryptedKey"] = "";
vector<string> keys; vector <string> keys;
try { try {
keys = genECDSAKey(); keys = genECDSAKey();
...@@ -319,7 +319,7 @@ Json::Value SGXWalletServer::renameECDSAKeyImpl(const string &_keyName, const st ...@@ -319,7 +319,7 @@ Json::Value SGXWalletServer::renameECDSAKeyImpl(const string &_keyName, const st
throw SGXException(UNKNOWN_ERROR, "invalid key name"); throw SGXException(UNKNOWN_ERROR, "invalid key name");
} }
shared_ptr<string> key_ptr = readFromDb(_tempKeyName); shared_ptr <string> key_ptr = readFromDb(_tempKeyName);
writeDataToDB(_keyName, *key_ptr); writeDataToDB(_keyName, *key_ptr);
...@@ -340,7 +340,7 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_ ...@@ -340,7 +340,7 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_
result["signature_r"] = ""; result["signature_r"] = "";
result["signature_s"] = ""; result["signature_s"] = "";
vector<string> sign_vect(3); vector <string> sign_vect(3);
try { try {
...@@ -362,7 +362,7 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_ ...@@ -362,7 +362,7 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_
throw SGXException(-22, "Invalid base"); throw SGXException(-22, "Invalid base");
} }
shared_ptr<string> key_ptr = readFromDb(_keyName, ""); shared_ptr <string> key_ptr = readFromDb(_keyName, "");
sign_vect = ecdsaSignHash(key_ptr->c_str(), cutHash.c_str(), _base); sign_vect = ecdsaSignHash(key_ptr->c_str(), cutHash.c_str(), _base);
if (sign_vect.size() != 3) { if (sign_vect.size() != 3) {
...@@ -393,7 +393,7 @@ Json::Value SGXWalletServer::getPublicECDSAKeyImpl(const string &_keyName) { ...@@ -393,7 +393,7 @@ Json::Value SGXWalletServer::getPublicECDSAKeyImpl(const string &_keyName) {
if (!checkECDSAKeyName(_keyName)) { if (!checkECDSAKeyName(_keyName)) {
throw SGXException(INVALID_ECDSA_KEY_NAME, "Invalid ECDSA key name"); throw SGXException(INVALID_ECDSA_KEY_NAME, "Invalid ECDSA key name");
} }
shared_ptr<string> keyStr = readFromDb(_keyName); shared_ptr <string> keyStr = readFromDb(_keyName);
publicKey = getECDSAPubKey(keyStr->c_str()); publicKey = getECDSAPubKey(keyStr->c_str());
spdlog::debug("PublicKey {}", publicKey); spdlog::debug("PublicKey {}", publicKey);
spdlog::debug("PublicKey length {}", publicKey.length()); spdlog::debug("PublicKey length {}", publicKey.length());
...@@ -408,7 +408,7 @@ Json::Value SGXWalletServer::getPublicECDSAKeyImpl(const string &_keyName) { ...@@ -408,7 +408,7 @@ Json::Value SGXWalletServer::getPublicECDSAKeyImpl(const string &_keyName) {
Json::Value SGXWalletServer::generateDKGPolyImpl(const string &_polyName, int _t) { Json::Value SGXWalletServer::generateDKGPolyImpl(const string &_polyName, int _t) {
INIT_RESULT(result) INIT_RESULT(result)
string encrPolyHex; string encrPolyHex;
...@@ -435,7 +435,7 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName, ...@@ -435,7 +435,7 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName,
result["status"] = 0; result["status"] = 0;
result["errorMessage"] = ""; result["errorMessage"] = "";
vector<vector<string>> verifVector; vector <vector<string>> verifVector;
try { try {
if (!checkName(_polyName, "POLY")) { if (!checkName(_polyName, "POLY")) {
throw SGXException(INVALID_POLY_NAME, "Invalid polynomial name"); throw SGXException(INVALID_POLY_NAME, "Invalid polynomial name");
...@@ -444,13 +444,13 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName, ...@@ -444,13 +444,13 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName,
throw SGXException(INVALID_DKG_PARAMS, "Invalid parameters: n or t "); throw SGXException(INVALID_DKG_PARAMS, "Invalid parameters: n or t ");
} }
shared_ptr<string> encr_poly_ptr = readFromDb(_polyName); shared_ptr <string> encr_poly_ptr = readFromDb(_polyName);
verifVector = get_verif_vect(encr_poly_ptr->c_str(), _t, _n); verifVector = get_verif_vect(encr_poly_ptr->c_str(), _t, _n);
//cerr << "verif vect size " << verifVector.size() << endl; //cerr << "verif vect size " << verifVector.size() << endl;
for (int i = 0; i < _t; i++) { for (int i = 0; i < _t; i++) {
vector<string> cur_coef = verifVector.at(i); vector <string> cur_coef = verifVector.at(i);
for (int j = 0; j < 4; j++) { for (int j = 0; j < 4; j++) {
result["verificationVector"][i][j] = cur_coef.at(j); result["verificationVector"][i][j] = cur_coef.at(j);
result["Verification Vector"][i][j] = cur_coef.at(j); result["Verification Vector"][i][j] = cur_coef.at(j);
...@@ -484,9 +484,9 @@ Json::Value SGXWalletServer::getSecretShareImpl(const string &_polyName, const J ...@@ -484,9 +484,9 @@ Json::Value SGXWalletServer::getSecretShareImpl(const string &_polyName, const J
throw SGXException(INVALID_DKG_PARAMS, "Invalid DKG parameters: n or t "); throw SGXException(INVALID_DKG_PARAMS, "Invalid DKG parameters: n or t ");
} }
shared_ptr<string> encr_poly_ptr = readFromDb(_polyName); shared_ptr <string> encr_poly_ptr = readFromDb(_polyName);
vector<string> pubKeysStrs; vector <string> pubKeysStrs;
for (int i = 0; i < _n; i++) { for (int i = 0; i < _n; i++) {
if (!checkHex(_pubKeys[i].asString(), 64)) { if (!checkHex(_pubKeys[i].asString(), 64)) {
throw SGXException(INVALID_HEX, "Invalid public key"); throw SGXException(INVALID_HEX, "Invalid public key");
...@@ -532,7 +532,7 @@ Json::Value SGXWalletServer::dkgVerificationImpl(const string &_publicShares, co ...@@ -532,7 +532,7 @@ Json::Value SGXWalletServer::dkgVerificationImpl(const string &_publicShares, co
throw SGXException(INVALID_DKG_PARAMS, "Invalid length of public shares"); throw SGXException(INVALID_DKG_PARAMS, "Invalid length of public shares");
} }
shared_ptr<string> encryptedKeyHex_ptr = readFromDb(_ethKeyName); shared_ptr <string> encryptedKeyHex_ptr = readFromDb(_ethKeyName);
if (!verifyShares(_publicShares.c_str(), _secretShare.c_str(), encryptedKeyHex_ptr->c_str(), _t, _n, _index)) { if (!verifyShares(_publicShares.c_str(), _secretShare.c_str(), encryptedKeyHex_ptr->c_str(), _t, _n, _index)) {
result["result"] = false; result["result"] = false;
...@@ -576,11 +576,11 @@ SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string ...@@ -576,11 +576,11 @@ SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string
if (!check_n_t(_t, _n)) { if (!check_n_t(_t, _n)) {
throw SGXException(INVALID_DKG_PARAMS, "Invalid DKG parameters: n or t "); throw SGXException(INVALID_DKG_PARAMS, "Invalid DKG parameters: n or t ");
} }
vector<string> sshares_vect; vector <string> sshares_vect;
spdlog::debug("secret shares from json are - {}", _secretShare); spdlog::debug("secret shares from json are - {}", _secretShare);
shared_ptr<string> encryptedKeyHex_ptr = readFromDb(_ethKeyName); shared_ptr <string> encryptedKeyHex_ptr = readFromDb(_ethKeyName);
bool res = CreateBLSShare(_blsKeyName, _secretShare.c_str(), encryptedKeyHex_ptr->c_str()); bool res = CreateBLSShare(_blsKeyName, _secretShare.c_str(), encryptedKeyHex_ptr->c_str());
if (res) { if (res) {
...@@ -609,11 +609,11 @@ Json::Value SGXWalletServer::getBLSPublicKeyShareImpl(const string &_blsKeyName) ...@@ -609,11 +609,11 @@ Json::Value SGXWalletServer::getBLSPublicKeyShareImpl(const string &_blsKeyName)
if (!checkName(_blsKeyName, "BLS_KEY")) { if (!checkName(_blsKeyName, "BLS_KEY")) {
throw SGXException(INVALID_POLY_NAME, "Invalid BLSKey name"); throw SGXException(INVALID_POLY_NAME, "Invalid BLSKey name");
} }
shared_ptr<string> encryptedKeyHex_ptr = readFromDb(_blsKeyName); shared_ptr <string> encryptedKeyHex_ptr = readFromDb(_blsKeyName);
spdlog::debug("encr_bls_key_share is {}", *encryptedKeyHex_ptr); spdlog::debug("encr_bls_key_share is {}", *encryptedKeyHex_ptr);
spdlog::debug("length is {}", encryptedKeyHex_ptr->length()); spdlog::debug("length is {}", encryptedKeyHex_ptr->length());
vector<string> public_key_vect = GetBLSPubKey(encryptedKeyHex_ptr->c_str()); vector <string> public_key_vect = GetBLSPubKey(encryptedKeyHex_ptr->c_str());
for (uint8_t i = 0; i < 4; i++) { for (uint8_t i = 0; i < 4; i++) {
result["blsPublicKeyShare"][i] = public_key_vect.at(i); result["blsPublicKeyShare"][i] = public_key_vect.at(i);
result["BlsPublicKeyShare"][i] = public_key_vect.at(i); result["BlsPublicKeyShare"][i] = public_key_vect.at(i);
...@@ -633,7 +633,7 @@ Json::Value SGXWalletServer::complaintResponseImpl(const string &_polyName, int ...@@ -633,7 +633,7 @@ Json::Value SGXWalletServer::complaintResponseImpl(const string &_polyName, int
throw SGXException(INVALID_POLY_NAME, "Invalid polynomial name"); throw SGXException(INVALID_POLY_NAME, "Invalid polynomial name");
} }
string shareG2_name = "shareG2_" + _polyName + "_" + to_string(_ind) + ":"; string shareG2_name = "shareG2_" + _polyName + "_" + to_string(_ind) + ":";
shared_ptr<string> shareG2_ptr = readFromDb(shareG2_name); shared_ptr <string> shareG2_ptr = readFromDb(shareG2_name);
string DHKey = decryptDHKey(_polyName, _ind); string DHKey = decryptDHKey(_polyName, _ind);
...@@ -669,7 +669,7 @@ Json::Value SGXWalletServer::isPolyExistsImpl(const string &_polyName) { ...@@ -669,7 +669,7 @@ Json::Value SGXWalletServer::isPolyExistsImpl(const string &_polyName) {
result["exists"] = false; result["exists"] = false;
try { try {
std::shared_ptr<std::string> poly_str_ptr = LevelDB::getLevelDb()->readString(_polyName); std::shared_ptr <std::string> poly_str_ptr = LevelDB::getLevelDb()->readString(_polyName);
if (poly_str_ptr != nullptr) { if (poly_str_ptr != nullptr) {
result["IsExist"] = true; result["IsExist"] = true;
...@@ -785,7 +785,7 @@ Json::Value SGXWalletServer::getServerStatus() { ...@@ -785,7 +785,7 @@ Json::Value SGXWalletServer::getServerStatus() {
return getServerStatusImpl(); return getServerStatusImpl();
} }
shared_ptr<string> SGXWalletServer::readFromDb(const string &name, const string &prefix) { shared_ptr <string> SGXWalletServer::readFromDb(const string &name, const string &prefix) {
auto dataStr = LevelDB::getLevelDb()->readString(prefix + name); auto dataStr = LevelDB::getLevelDb()->readString(prefix + name);
...@@ -796,7 +796,7 @@ shared_ptr<string> SGXWalletServer::readFromDb(const string &name, const string ...@@ -796,7 +796,7 @@ shared_ptr<string> SGXWalletServer::readFromDb(const string &name, const string
return dataStr; return dataStr;
} }
shared_ptr<string> SGXWalletServer::readKeyShare(const string &_keyShareName) { shared_ptr <string> SGXWalletServer::readKeyShare(const string &_keyShareName) {
auto keyShareStr = LevelDB::getLevelDb()->readString("BLSKEYSHARE:" + _keyShareName); auto keyShareStr = LevelDB::getLevelDb()->readString("BLSKEYSHARE:" + _keyShareName);
......
...@@ -25,19 +25,22 @@ ...@@ -25,19 +25,22 @@
#define SGXWALLET_SGXWALLETSERVER_HPP #define SGXWALLET_SGXWALLETSERVER_HPP
#include "abstractstubserver.h"
#include <mutex>
#include <jsonrpccpp/server/connectors/httpserver.h>
#include <mutex>
#include "abstractstubserver.h"
using namespace jsonrpc; using namespace jsonrpc;
using namespace std; using namespace std;
class SGXWalletServer : public AbstractStubServer { class SGXWalletServer : public AbstractStubServer {
SGXWalletServer *server = nullptr;
recursive_mutex m; recursive_mutex m;
static shared_ptr<SGXWalletServer> server;
static shared_ptr<HttpServer> httpServer;
public: public:
SGXWalletServer(AbstractServerConnector &_connector, serverVersion_t _type); SGXWalletServer(AbstractServerConnector &_connector, serverVersion_t _type);
......
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