Unverified Commit 6c340277 authored by kladko's avatar kladko

Revert "SKALE-3067-cleanup-sgx"

This reverts commit b33321c2.
parent b33321c2
......@@ -42,6 +42,7 @@ CSRManagerServer::CSRManagerServer(AbstractServerConnector &connector,
Json::Value getUnsignedCSRsImpl() {
spdlog::info(__FUNCTION__);
INIT_RESULT(result)
try {
vector<string> hashes_vect = LevelDB::getCsrDb()->writeKeysToVector1(MAX_CSR_NUM);
for (int i = 0; i < (int) hashes_vect.size(); i++) {
......@@ -49,12 +50,11 @@ Json::Value getUnsignedCSRsImpl() {
}
} HANDLE_SGX_EXCEPTION(result);
RETURN_SUCCESS(result)
return result;
}
Json::Value signByHashImpl(const string &hash, int status) {
INIT_RESULT(result)
Json::Value result;
result["errorMessage"] = "";
try {
......@@ -102,7 +102,7 @@ Json::Value signByHashImpl(const string &hash, int status) {
} HANDLE_SGX_EXCEPTION(result)
return result;
return result;
}
Json::Value CSRManagerServer::getUnsignedCSRs() {
......
......@@ -152,9 +152,9 @@ vector<vector<string>> get_verif_vect(const char *encryptedPolyHex, int t, int n
return pubSharesVect;
}
string getSecretShares(const string &_polyName, const char *_encryptedPolyHex, const vector<string> &_publicKeys,
int _t,
int _n) {
string trustedGetSecretShares(const string &_polyName, const char *_encryptedPolyHex, const vector<string> &_publicKeys,
int _t,
int _n) {
vector<char> hexEncrKey(BUF_LEN, 0);
vector<char> errMsg1(BUF_LEN, 0);
int errStatus = 0;
......
......@@ -35,7 +35,7 @@ vector <vector<string>> get_verif_vect(const char* encryptedPolyHex, int t, int
vector<string> splitString(const char* coeffs, const char symbol);
string getSecretShares(const string& _polyName, const char* _encryptedPolyHex, const vector<string>& _publicKeys, int _t, int _n);
string trustedGetSecretShares(const string& _polyName, const char* _encryptedPolyHex, const vector<string>& _publicKeys, int _t, int _n);
bool verifyShares(const char* publicShares, const char* encr_sshare, const char * encryptedKeyHex, int t, int n, int ind);
......
......@@ -74,7 +74,7 @@ public:
};
#define INIT_RESULT(__RESULT__) Json::Value __RESULT__; \
int errStatus = UNKNOWN_ERROR; string errMsg(BUF_LEN, '\0');__RESULT__["status"] = UNKNOWN_ERROR; __RESULT__["errorMessage"] = \
int errStatus = UNKNOWN_ERROR; string errMsg(BUF_LEN, '\0');__RESULT__["status"] = 0; __RESULT__["errorMessage"] = \
"Server error. Please see server log.";
#define HANDLE_SGX_EXCEPTION(__RESULT__) \
......
......@@ -112,8 +112,7 @@ Json::Value signCertificateImpl(const string &_csr, bool _autoSign = false) {
} HANDLE_SGX_EXCEPTION(result)
RETURN_SUCCESS(result)
return result;
}
Json::Value getCertificateImpl(const string &hash) {
......@@ -148,7 +147,7 @@ Json::Value getCertificateImpl(const string &hash) {
} HANDLE_SGX_EXCEPTION(result)
RETURN_SUCCESS(result)
return result;
}
......
......@@ -221,7 +221,22 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin
}
value = readFromDb(_keyShareName);
} catch (SGXException& _e) {
result["status"] = _e.status;
result["errorMessage"] = _e.errString;
return result;
} catch (exception& _e) {
result["errorMessage"] = _e.what();
return result;
}
catch (...) {
exception_ptr p = current_exception();
printf("Exception %s \n", p.__cxa_exception_type()->name());
result["errorMessage"] = "Exception in dbRead";
return result;
}
try {
if (!bls_sign(value->c_str(), _messageHash.c_str(), t, n, _signerIndex, signature.data())) {
result["status"] = -1;
result["errorMessage"] = "Could not sign";
......@@ -394,6 +409,8 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName,
INIT_RESULT(result);
result["status"] = 0;
result["errorMessage"] = "";
vector <vector<string>> verifVector;
try {
......@@ -421,14 +438,17 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName,
result["verificationVector"] = "";
}
RETURN_SUCCESS(result)
return result;
}
Json::Value SGXWalletServer::getSecretShareImpl(const string &_polyName, const Json::Value &_pubKeys, int _t, int _n) {
INIT_RESULT(result);
result["status"] = 0;
result["errorMessage"] = "";
try {
if (_pubKeys.size() != (uint64_t) _n) {
throw SGXException(INVALID_DKG_PARAMS, "invalid number of public keys");
......@@ -450,12 +470,11 @@ Json::Value SGXWalletServer::getSecretShareImpl(const string &_polyName, const J
pubKeysStrs.push_back(_pubKeys[i].asString());
}
string s = getSecretShares(_polyName, encrPoly->c_str(), pubKeysStrs, _t, _n);
string s = trustedGetSecretShares(_polyName, encrPoly->c_str(), pubKeysStrs, _t, _n);
result["secretShare"] = s;
} HANDLE_SGX_EXCEPTION(result)
RETURN_SUCCESS(result)
}
Json::Value SGXWalletServer::dkgVerificationImpl(const string &_publicShares, const string &_ethKeyName,
......@@ -498,6 +517,8 @@ SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string
INIT_RESULT(result)
result["status"] = 0;
result["errorMessage"] = "";
try {
if (_secretShare.length() != (uint64_t) _n * 192) {
......@@ -594,7 +615,9 @@ Json::Value SGXWalletServer::multG2Impl(const string &_x) {
} HANDLE_SGX_EXCEPTION(result)
RETURN_SUCCESS(result)
result["status"] = 0;
result["errorMessage"] = "";
return result;
}
Json::Value SGXWalletServer::isPolyExistsImpl(const string &_polyName) {
......@@ -610,7 +633,9 @@ Json::Value SGXWalletServer::isPolyExistsImpl(const string &_polyName) {
}
} HANDLE_SGX_EXCEPTION(result)
RETURN_SUCCESS(result)
result["status"] = 0;
result["errorMessage"] = "";
return result;
}
Json::Value SGXWalletServer::getServerStatusImpl() {
......@@ -622,7 +647,9 @@ Json::Value SGXWalletServer::getServerVersionImpl() {
INIT_RESULT(result)
result["version"] = TOSTRING(SGXWALLET_VERSION);
RETURN_SUCCESS(result)
result["status"] = 0;
result["errorMessage"] = "";
return result;
}
Json::Value SGXWalletServer::deleteBlsKeyImpl(const std::string& name) {
......
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