Unverified Commit b7ffbd6a authored by kladko's avatar kladko

bug/SKALE-3654-SGX-errors

parent 551b80ab
......@@ -170,7 +170,7 @@ vector <vector<string>> get_verif_vect(const string& encryptedPolyHex, int t, in
vector <uint8_t> encrDKGPoly(2 * BUF_LEN, 0);
if (!hex2carray(encryptedPolyHexPtr, &encLen, encrDKGPoly.data(), 6100)) {
throw SGXException(INVALID_HEX, "Invalid encryptedPolyHex");
throw SGXException(INVALID_HEX, ":Invalid encryptedPolyHex");
}
......@@ -233,7 +233,7 @@ getSecretShares(const string &_polyName, const char *_encryptedPolyHex, const ve
if (!hex2carray(_encryptedPolyHex, &encLen, encrDKGPoly.data(), BUF_LEN)) {
throw SGXException(INVALID_HEX, "Invalid encryptedPolyHex");
throw SGXException(INVALID_HEX, ":Invalid encryptedPolyHex");
}
......@@ -294,7 +294,8 @@ string getSecretSharesV2(const string& _polyName, const char* _encryptedPolyHex,
if (!hex2carray(_encryptedPolyHex, &encLen, encrDKGPoly.data(), BUF_LEN)) {
throw SGXException(GET_SS_V2_INVALID_HEX, "Invalid encrypted poly Hex");
throw SGXException(GET_SS_V2_INVALID_HEX,
string(__FUNCTION__) + ":Invalid encrypted poly Hex");
}
......@@ -358,7 +359,7 @@ verifyShares(const char *publicShares, const char *encr_sshare, const char *encr
SAFE_UINT8_BUF(encr_key, BUF_LEN);
if (!hex2carray(encryptedKeyHex, &decKeyLen, encr_key, BUF_LEN)) {
throw SGXException(INVALID_HEX, "Invalid encryptedPolyHex");
throw SGXException(INVALID_HEX, string(__FUNCTION__) + ":Invalid encryptedPolyHex");
}
SAFE_CHAR_BUF(pshares, 8193);
......@@ -374,7 +375,8 @@ verifyShares(const char *publicShares, const char *encr_sshare, const char *encr
HANDLE_TRUSTED_FUNCTION_ERROR(status, errStatus, errMsg.data());
if (result == 2) {
throw SGXException(INVALID_HEX, "Invalid public shares");
throw SGXException(INVALID_HEX,
string(__FUNCTION__) + + ":Invalid public shares");
}
return result;
......@@ -394,7 +396,7 @@ verifySharesV2(const char *publicShares, const char *encr_sshare, const char *en
SAFE_UINT8_BUF(encr_key, BUF_LEN);
if (!hex2carray(encryptedKeyHex, &decKeyLen, encr_key, BUF_LEN)) {
throw SGXException(INVALID_HEX, "Invalid encryptedPolyHex");
throw SGXException(INVALID_HEX, string(__FUNCTION__) + ":Invalid encryptedPolyHex");
}
SAFE_CHAR_BUF(pshares, 8193);
......@@ -410,7 +412,7 @@ verifySharesV2(const char *publicShares, const char *encr_sshare, const char *en
HANDLE_TRUSTED_FUNCTION_ERROR(status, errStatus, errMsg.data());
if (result == 2) {
throw SGXException(INVALID_HEX, "Invalid public shares");
throw SGXException(INVALID_HEX, string(__FUNCTION__) + ":Invalid public shares");
}
return result;
......@@ -426,7 +428,7 @@ bool createBLSShare(const string &blsKeyName, const char *s_shares, const char *
uint64_t decKeyLen;SAFE_UINT8_BUF(encr_bls_key, BUF_LEN);SAFE_UINT8_BUF(encr_key, BUF_LEN);
if (!hex2carray(encryptedKeyHex, &decKeyLen, encr_key, BUF_LEN)) {
throw SGXException(INVALID_HEX, "Invalid encryptedKeyHex");
throw SGXException(INVALID_HEX, string(__FUNCTION__) + ":Invalid encryptedKeyHex");
}
uint64_t enc_bls_len = 0;
......@@ -459,7 +461,7 @@ vector <string> getBLSPubKey(const char *encryptedKeyHex) {
SAFE_UINT8_BUF(encrKey, BUF_LEN);
if (!hex2carray(encryptedKeyHex, &decKeyLen, encrKey, BUF_LEN)) {
throw SGXException(INVALID_HEX, "Invalid encryptedKeyHex");
throw SGXException(INVALID_HEX, string(__FUNCTION__) + ":Invalid encryptedKeyHex");
}
SAFE_CHAR_BUF(pubKey, 320)
......@@ -546,7 +548,7 @@ string decryptDHKey(const string &polyName, int ind) {
uint64_t dhEncLen = 0;
SAFE_UINT8_BUF(encryptedDHKey, BUF_LEN)
if (!hex2carray(hexEncrKeyPtr->c_str(), &dhEncLen, encryptedDHKey, BUF_LEN)) {
throw SGXException(INVALID_HEX, "Invalid hexEncrKey");
throw SGXException(INVALID_HEX, string(__FUNCTION__) + ":Invalid hexEncrKey");
}
spdlog::debug("encr DH key length is {}", dhEncLen);
......
......@@ -52,7 +52,7 @@ level_enum Log::logLevelFromString(string &_s) {
}
void Log::handleSGXException(Json::Value& _result, SGXException& _e ) {
spdlog::error("Responding with JSON error:" + _e.errString);
_result["status"] = _e.status;
_result["errorMessage"] = _e.errString;
spdlog::error("Responding with JSON error:" + _e.getErrString());
_result["status"] = _e.getStatus();
_result["errorMessage"] = _e.getErrString();
}
......@@ -94,9 +94,9 @@ string(__FUNCTION__) + ": server error. Please see server log.";
#define HANDLE_SGX_EXCEPTION(__RESULT__) \
catch (const SGXException& _e) { \
if (_e.status != 0) {__RESULT__["status"] = _e.status;} else { __RESULT__["status"] = -1 * (10000 + __LINE__);}; \
__RESULT__["errorMessage"] = _e.errString; \
if (_e.errString.size() == 0) {__RESULT__["errorMessage"] = string(__FUNCTION__);}; \
if (_e.getStatus() != 0) {__RESULT__["status"] = _e.getStatus();} else { __RESULT__["status"] = -1 * (10000 + __LINE__);}; \
__RESULT__["errorMessage"] = _e.getErrString(); \
if (_e.getErrString().size() == 0) {__RESULT__["errorMessage"] = string(__FUNCTION__);}; \
spdlog::error("JSON call failed {}", __FUNCTION__); \
return __RESULT__; \
} catch (const exception& _e) { \
......
......@@ -27,19 +27,30 @@
#include <string>
#include <exception>
class SGXException : public std::exception {
using namespace std;
class SGXException : public exception {
const int32_t status;
const string errString;
public:
int32_t status;
std::string errString;
SGXException(int32_t _status, const string& _errString) : status(_status), errString(_errString) {}
const string getMessage() const {
return "SGXException:status:" + to_string(status) + ":" + errString;
}
SGXException(int32_t _status, const char* _errString) : status(_status), errString(_errString) {}
const string& getErrString() const {
return errString;
}
std::string getMessage() {
return "SGXException:status:" + std::to_string(status) + ":" + errString;
const int32_t getStatus() const {
return status;
}
};
#endif //SGXD_RPCEXCEPTION_H
This diff is collapsed.
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