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
......@@ -208,7 +208,7 @@ SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_k
try {
if (!checkName(_keyShareName, "BLS_KEY")) {
throw SGXException(INVALID_BLS_NAME, "Invalid BLS key name");
throw SGXException(INVALID_BLS_NAME, string(__FUNCTION__) + ":Invalid BLS key name");
}
string hashTmp = _keyShare;
......@@ -217,17 +217,18 @@ SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_k
}
if (!checkHex(hashTmp)) {
throw SGXException(INVALID_BLS_KEY_SHARE, "Invalid BLS key share, please use hex");
throw SGXException(INVALID_BLS_KEY_SHARE, string(__FUNCTION__) + ":Invalid BLS key share, please use hex");
}
encryptedKeyShareHex = encryptBLSKeyShare2Hex(&errStatus, (char *) errMsg.data(), hashTmp.c_str());
if (errStatus != 0) {
throw SGXException(errStatus, errMsg.data());
throw SGXException(errStatus, string(__FUNCTION__) + ":" +errMsg.data());
}
if (encryptedKeyShareHex.empty()) {
throw SGXException(EMPTY_ENCRYPTED_KEY_SHARE, "");
throw SGXException(EMPTY_ENCRYPTED_KEY_SHARE,string(__FUNCTION__) +
":Empty encrypted key share");
}
result["encryptedKeyShare"] = encryptedKeyShareHex;
......@@ -280,11 +281,11 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin
try {
if (!checkName(_keyShareName, "BLS_KEY")) {
throw SGXException(INVALID_POLY_NAME, "Invalid BLSKey name");
throw SGXException(INVALID_POLY_NAME, string(__FUNCTION__) + ":Invalid BLSKey name");
}
if (!check_n_t(t, n)) {
throw SGXException(INVALID_DKG_PARAMS, "Invalid t/n parameters");
throw SGXException(INVALID_DKG_PARAMS, string(__FUNCTION__) + ":Invalid t/n parameters");
}
string hashTmp = _messageHash;
......@@ -296,14 +297,14 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin
}
if (!checkHex(hashTmp)) {
throw SGXException(INVALID_BLS_HEX, "Invalid bls hex");
throw SGXException(INVALID_BLS_HEX, string(__FUNCTION__) + ":Invalid bls hex");
}
value = readFromDb(_keyShareName);
if (!bls_sign(value->c_str(), _messageHash.c_str(), t, n, signature.data())) {
throw SGXException(COULD_NOT_BLS_SIGN, "Could not bls sign data ");
throw SGXException(COULD_NOT_BLS_SIGN, ":Could not bls sign data ");
}
} HANDLE_SGX_EXCEPTION(result)
......@@ -324,7 +325,7 @@ Json::Value SGXWalletServer::importECDSAKeyImpl(const string &_keyShare,
try {
if (!checkECDSAKeyName(_keyShareName)) {
throw SGXException(INVALID_ECDSA_IMPORT_KEY_NAME, "Invalid ECDSA import key name");
throw SGXException(INVALID_ECDSA_IMPORT_KEY_NAME, string(__FUNCTION__) + ":Invalid ECDSA import key name");
}
string hashTmp = _keyShare;
......@@ -333,7 +334,8 @@ Json::Value SGXWalletServer::importECDSAKeyImpl(const string &_keyShare,
}
if (!checkHex(hashTmp)) {
throw SGXException(INVALID_ECDSA_IMPORT_HEX, "Invalid ECDSA key share, please use hex");
throw SGXException(INVALID_ECDSA_IMPORT_HEX,
string(__FUNCTION__) + ":Invalid ECDSA key share, please use hex");
}
string encryptedKey = encryptECDSAKey(hashTmp);
......@@ -359,7 +361,7 @@ Json::Value SGXWalletServer::generateECDSAKeyImpl() {
keys = genECDSAKey();
if (keys.size() == 0) {
throw SGXException(ECDSA_GEN_EMPTY_KEY, "key was not generated");
throw SGXException(ECDSA_GEN_EMPTY_KEY, string(__FUNCTION__) + ":key was not generated");
}
string keyName = "NEK:" + keys.at(2);
......@@ -398,20 +400,20 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_
}
if (!checkECDSAKeyName(_keyName)) {
throw SGXException(INVALID_ECDSA_SIGN_KEY_NAME, "Invalid ECDSA sign key name");
throw SGXException(INVALID_ECDSA_SIGN_KEY_NAME, string(__FUNCTION__) + ":Invalid ECDSA sign key name");
}
if (!checkHex(hashTmp)) {
throw SGXException(INVALID_ECDSA_SIGN_HASH, "Invalid ECDSA sign hash");
throw SGXException(INVALID_ECDSA_SIGN_HASH, ":Invalid ECDSA sign hash");
}
if (_base <= 0 || _base > 32) {
throw SGXException(INVALID_ECDSA_SIGN_BASE, "Invalid ECDSA sign base");
throw SGXException(INVALID_ECDSA_SIGN_BASE, ":Invalid ECDSA sign base");
}
shared_ptr <string> encryptedKey = readFromDb(_keyName, "");
signatureVector = ecdsaSignHash(encryptedKey->c_str(), hashTmp.c_str(), _base);
if (signatureVector.size() != 3) {
throw SGXException(INVALID_ECSDA_SIGN_SIGNATURE, "Invalid ecdsa signature");
throw SGXException(INVALID_ECSDA_SIGN_SIGNATURE, string(__FUNCTION__) + ":Invalid ecdsa signature");
}
result["signature_v"] = signatureVector.at(0);
......@@ -434,7 +436,8 @@ Json::Value SGXWalletServer::getPublicECDSAKeyImpl(const string &_keyName) {
try {
if (!checkECDSAKeyName(_keyName)) {
throw SGXException(INVALID_ECDSA_GETPKEY_KEY_NAME, "Invalid ECDSA import key name");
throw SGXException(INVALID_ECDSA_GETPKEY_KEY_NAME, string(__FUNCTION__) +
":Invalid ECDSA import key name");
}
shared_ptr <string> keyStr = readFromDb(_keyName);
publicKey = getECDSAPubKey(keyStr->c_str());
......@@ -455,10 +458,10 @@ Json::Value SGXWalletServer::generateDKGPolyImpl(const string &_polyName, int _t
try {
if (!checkName(_polyName, "POLY")) {
throw SGXException(INVALID_GEN_DKG_POLY_NAME,
"Invalid gen DKG polynomial name.");
string(__FUNCTION__) + ":Invalid gen DKG polynomial name.");
}
if (_t <= 0 || _t > 32) {
throw SGXException(INVALID_DKG_PARAMS, "Invalid gen dkg param t ");
throw SGXException(INVALID_DKG_PARAMS, string(__FUNCTION__) + ":Invalid gen dkg param t ");
}
encrPolyHex = gen_dkg_poly(_t);
writeDataToDB(_polyName, encrPolyHex);
......@@ -475,10 +478,10 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName,
vector <vector<string>> verifVector;
try {
if (!checkName(_polyName, "POLY")) {
throw SGXException(INVALID_DKG_GETVV_POLY_NAME, "Invalid polynomial name");
throw SGXException(INVALID_DKG_GETVV_POLY_NAME, string(__FUNCTION__) + ":Invalid polynomial name");
}
if (!check_n_t(_t, _n)) {
throw SGXException(INVALID_DKG_GETVV_PARAMS, "Invalid parameters n or t ");
throw SGXException(INVALID_DKG_GETVV_PARAMS, string(__FUNCTION__) + ":Invalid parameters n or t ");
}
shared_ptr <string> encrPoly = readFromDb(_polyName);
......@@ -505,13 +508,13 @@ Json::Value SGXWalletServer::getSecretShareImpl(const string &_polyName, const J
try {
if (_pubKeys.size() != (uint64_t) _n) {
throw SGXException(INVALID_DKG_GETSS_PUB_KEY_COUNT, "invalid pubkey count");
throw SGXException(INVALID_DKG_GETSS_PUB_KEY_COUNT, string(__FUNCTION__) + ":Invalid pubkey count");
}
if (!checkName(_polyName, "POLY")) {
throw SGXException(INVALID_DKG_GETSS_POLY_NAME, "Invalid polynomial name");
throw SGXException(INVALID_DKG_GETSS_POLY_NAME, string(__FUNCTION__) + ":Invalid polynomial name");
}
if (!check_n_t(_t, _n)) {
throw SGXException(INVALID_DKG_GETSS_POLY_NAME, "Invalid DKG parameters: n or t ");
throw SGXException(INVALID_DKG_GETSS_POLY_NAME, string(__FUNCTION__) + ":Invalid DKG parameters: n or t ");
}
shared_ptr <string> encrPoly = readFromDb(_polyName);
......@@ -519,7 +522,7 @@ Json::Value SGXWalletServer::getSecretShareImpl(const string &_polyName, const J
vector <string> pubKeysStrs;
for (int i = 0; i < _n; i++) {
if (!checkHex(_pubKeys[i].asString(), 64)) {
throw SGXException(INVALID_DKG_GETSS_KEY_HEX, "Invalid public key");
throw SGXException(INVALID_DKG_GETSS_KEY_HEX, string(__FUNCTION__) + ":Invalid public key");
}
pubKeysStrs.push_back(_pubKeys[i].asString());
}
......@@ -530,8 +533,7 @@ Json::Value SGXWalletServer::getSecretShareImpl(const string &_polyName, const J
if (encryptedSecretShare != nullptr) {
result["secretShare"] = *encryptedSecretShare.get();
} else {
string s = getSecretShares(_polyName, encrPoly->c_str(), pubKeysStrs, _t, _n);
result["secretShare"] = s;
result["secretShare"] = getSecretShares(_polyName, encrPoly->c_str(), pubKeysStrs, _t, _n);
}
} HANDLE_SGX_EXCEPTION(result)
......@@ -547,16 +549,20 @@ Json::Value SGXWalletServer::dkgVerificationImpl(const string &_publicShares, co
try {
if (!checkECDSAKeyName(_ethKeyName)) {
throw SGXException(INVALID_DKG_VERIFY_ECDSA_KEY_NAME, "Invalid ECDSA key name");
throw SGXException(INVALID_DKG_VERIFY_ECDSA_KEY_NAME,
string(__FUNCTION__) + ":Invalid ECDSA key name");
}
if (!check_n_t(_t, _n) || _index >= _n || _index < 0) {
throw SGXException(INVALID_DKG_VERIFY_PARAMS, "Invalid DKG parameters: n or t ");
throw SGXException(INVALID_DKG_VERIFY_PARAMS,
string(__FUNCTION__) + ":Invalid DKG parameters: n or t ");
}
if (!checkHex(_secretShare, SECRET_SHARE_NUM_BYTES)) {
throw SGXException(INVALID_DKG_VERIFY_SS_HEX, "Invalid Secret share");
throw SGXException(INVALID_DKG_VERIFY_SS_HEX,
string(__FUNCTION__) + ":Invalid Secret share");
}
if (_publicShares.length() != (uint64_t) 256 * _t) {
throw SGXException(INVALID_DKG_VERIFY_PUBSHARES_LENGTH, "Invalid length of public shares");
throw SGXException(INVALID_DKG_VERIFY_PUBSHARES_LENGTH,
string(__FUNCTION__) + ":Invalid length of public shares");
}
shared_ptr <string> encryptedKeyHex_ptr = readFromDb(_ethKeyName);
......@@ -578,19 +584,24 @@ SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string
try {
if (_secretShare.length() != (uint64_t) _n * 192) {
throw SGXException(INVALID_CREATE_BLS_KEY_SECRET_SHARES_LENGTH, "Invalid secret share length");
throw SGXException(INVALID_CREATE_BLS_KEY_SECRET_SHARES_LENGTH,
string(__FUNCTION__) + ":Invalid secret share length");
}
if (!checkECDSAKeyName(_ethKeyName)) {
throw SGXException(INVALID_CREATE_BLS_ECDSA_KEY_NAME, "Invalid ECDSA key name");
throw SGXException(INVALID_CREATE_BLS_ECDSA_KEY_NAME,
string(__FUNCTION__) + ":Invalid ECDSA key name");
}
if (!checkName(_polyName, "POLY")) {
throw SGXException(INVALID_CREATE_BLS_POLY_NAME, "Invalid polynomial name");
throw SGXException(INVALID_CREATE_BLS_POLY_NAME, string(__FUNCTION__) +
":Invalid polynomial name");
}
if (!checkName(_blsKeyName, "BLS_KEY")) {
throw SGXException(INVALID_CREATE_BLS_KEY_NAME, "Invalid BLS key name");
throw SGXException(INVALID_CREATE_BLS_KEY_NAME, string(__FUNCTION__) +
":Invalid BLS key name");
}
if (!check_n_t(_t, _n)) {
throw SGXException(INVALID_CREATE_BLS_DKG_PARAMS, "Invalid DKG parameters: n or t ");
throw SGXException(INVALID_CREATE_BLS_DKG_PARAMS,
string(__FUNCTION__) + ":Invalid DKG parameters: n or t ");
}
vector <string> sshares_vect;
......@@ -602,7 +613,8 @@ SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string
if (res) {
spdlog::info("BLS KEY SHARE CREATED ");
} else {
throw SGXException(INVALID_CREATE_BLS_SHARE, "Error while creating BLS key share");
throw SGXException(INVALID_CREATE_BLS_SHARE,
string(__FUNCTION__) + ":Error while creating BLS key share");
}
......@@ -630,7 +642,8 @@ Json::Value SGXWalletServer::getBLSPublicKeyShareImpl(const string &_blsKeyName)
try {
if (!checkName(_blsKeyName, "BLS_KEY")) {
throw SGXException(INVALID_GET_BLS_PUBKEY_NAME, "Invalid BLSKey name");
throw SGXException(INVALID_GET_BLS_PUBKEY_NAME,
string(__FUNCTION__) + ":Invalid BLSKey name");
}
shared_ptr <string> encryptedKeyHex_ptr = readFromDb(_blsKeyName);
......@@ -650,24 +663,29 @@ Json::Value SGXWalletServer::calculateAllBLSPublicKeysImpl(const Json::Value &pu
try {
if (!check_n_t(t, n)) {
throw SGXException(INVALID_DKG_CALCULATE_ALL_PARAMS, "Invalid DKG parameters: n or t ");
throw SGXException(INVALID_DKG_CALCULATE_ALL_PARAMS,
string(__FUNCTION__) + ":Invalid DKG parameters: n or t ");
}
if (!publicShares.isArray()) {
throw SGXException(INVALID_DKG_CALCULATE_ALL_PUBSHARES, "Invalid public shares format");
throw SGXException(INVALID_DKG_CALCULATE_ALL_PUBSHARES,
string(__FUNCTION__) + ":Invalid public shares format");
}
if (publicShares.size() != (uint64_t) n) {
throw SGXException(INVALID_DKG_CALCULATE_ALL_PUBSHARES_SIZE, "Invalid length of public shares");
throw SGXException(INVALID_DKG_CALCULATE_ALL_PUBSHARES_SIZE,
string(__FUNCTION__) + ":Invalid length of public shares");
}
for (int i = 0; i < n; ++i) {
if (!publicShares[i].isString()) {
throw SGXException(INVALID_DKG_CALCULATE_ALL_PUBSHARES_STRING, "Invalid public shares string");
throw SGXException(INVALID_DKG_CALCULATE_ALL_PUBSHARES_STRING,
string(__FUNCTION__) + ":Invalid public shares string");
}
if (publicShares[i].asString().length() != (uint64_t) 256 * t) {
throw SGXException(INVALID_DKG_CALCULATE_ALL_STRING_PUBSHARES_SLENGTH, "Invalid length of public shares parts");
throw SGXException(INVALID_DKG_CALCULATE_ALL_STRING_PUBSHARES_SLENGTH,
string(__FUNCTION__) + ";Invalid length of public shares parts");
}
}
......@@ -680,7 +698,7 @@ Json::Value SGXWalletServer::calculateAllBLSPublicKeysImpl(const Json::Value &pu
if (public_keys.size() != (uint64_t) n) {
throw SGXException(INVALID_DKG_CALCULATE_ALL_STRING_PUBKEYS_SIZE,
"Invalid pubkeys array size");
string(__FUNCTION__) + ":Invalid pubkeys array size");
}
for (int i = 0; i < n; ++i) {
......@@ -698,14 +716,15 @@ Json::Value SGXWalletServer::complaintResponseImpl(const string &_polyName, int
try {
if (!checkName(_polyName, "POLY")) {
throw SGXException(INVALID_COMPLAINT_RESPONSE_POLY_NAME, "Invalid polynomial name");
throw SGXException(INVALID_COMPLAINT_RESPONSE_POLY_NAME,
string(__FUNCTION__) + ":Invalid polynomial name");
}
string shareG2_name = "shareG2_" + _polyName + "_" + to_string(_ind) + ":";
shared_ptr <string> shareG2_ptr = readFromDb(shareG2_name);
string DHKey = decryptDHKey(_polyName, _ind);
shared_ptr <string> shareG2_ptr = readFromDb(shareG2_name);
CHECK_STATE(shareG2_ptr);
result["share*G2"] = *shareG2_ptr;
result["dhKey"] = DHKey;
......@@ -788,7 +807,7 @@ Json::Value SGXWalletServer::deleteBlsKeyImpl(const string &name) {
result["deleted"] = false;
try {
if (!checkName(name, "BLS_KEY")) {
throw SGXException(INVALID_BLS_NAME, "Invalid BLSKey name format");
throw SGXException(INVALID_BLS_NAME, string(__FUNCTION__) + ":Invalid BLSKey name format");
}
shared_ptr <string> bls_ptr = LevelDB::getLevelDb()->readString(name);
......@@ -797,7 +816,7 @@ Json::Value SGXWalletServer::deleteBlsKeyImpl(const string &name) {
result["deleted"] = true;
} else {
auto error_msg = "BLS key not found: " + name;
throw SGXException(INVALID_BLS_NAME, error_msg.c_str());
throw SGXException(INVALID_BLS_NAME, string(__FUNCTION__)+ ":" + error_msg.c_str());
}
} HANDLE_SGX_EXCEPTION(result)
......@@ -813,13 +832,16 @@ SGXWalletServer::getSecretShareV2Impl(const string &_polyName, const Json::Value
try {
if (_pubKeys.size() != (uint64_t) _n) {
throw SGXException(INVALID_DKG_GETSS_V2_PUBKEY_COUNT, "invalid number of public keys");
throw SGXException(INVALID_DKG_GETSS_V2_PUBKEY_COUNT,
string(__FUNCTION__) + ":Invalid number of public keys");
}
if (!checkName(_polyName, "POLY")) {
throw SGXException(INVALID_DKG_GETSS_V2_POLY_NAME, "Invalid polynomial name");
throw SGXException(INVALID_DKG_GETSS_V2_POLY_NAME,
string(__FUNCTION__) + ":Invalid polynomial name");
}
if (!check_n_t(_t, _n)) {
throw SGXException(INVALID_DKG_GETSS_V2_PUBKEY_COUNT, "Invalid DKG parameters: n or t ");
throw SGXException(INVALID_DKG_GETSS_V2_PUBKEY_COUNT,
string(__FUNCTION__) + ":Invalid DKG parameters: n or t ");
}
shared_ptr <string> encrPoly = readFromDb(_polyName);
......@@ -827,7 +849,8 @@ SGXWalletServer::getSecretShareV2Impl(const string &_polyName, const Json::Value
vector <string> pubKeysStrs;
for (int i = 0; i < _n; i++) {
if (!checkHex(_pubKeys[i].asString(), 64)) {
throw SGXException(INVALID_DKG_GETSS_V2_PUBKEY_HEX, "Invalid public key");
throw SGXException(INVALID_DKG_GETSS_V2_PUBKEY_HEX,
string(__FUNCTION__) + ":Invalid public key");
}
pubKeysStrs.push_back(_pubKeys[i].asString());
}
......@@ -855,16 +878,20 @@ Json::Value SGXWalletServer::dkgVerificationV2Impl(const string &_publicShares,
try {
if (!checkECDSAKeyName(_ethKeyName)) {
throw SGXException(INVALID_DKG_VV_V2_ECDSA_KEY_NAME, "Invalid ECDSA key name");
throw SGXException(INVALID_DKG_VV_V2_ECDSA_KEY_NAME,
string(__FUNCTION__) + ":Invalid ECDSA key name");
}
if (!check_n_t(_t, _n) || _index >= _n || _index < 0) {
throw SGXException(INVALID_DKG_VV_V2_PARAMS, "Invalid DKG parameters: n or t ");
throw SGXException(INVALID_DKG_VV_V2_PARAMS,
string(__FUNCTION__) + ":Invalid DKG parameters: n or t ");
}
if (!checkHex(_secretShare, SECRET_SHARE_NUM_BYTES)) {
throw SGXException(INVALID_DKG_VV_V2_SS_HEX, "Invalid Secret share");
throw SGXException(INVALID_DKG_VV_V2_SS_HEX,
string(__FUNCTION__) + ":Invalid Secret share");
}
if (_publicShares.length() != (uint64_t) 256 * _t) {
throw SGXException(INVALID_DKG_VV_V2_SS_COUNT, "Invalid count of public shares");
throw SGXException(INVALID_DKG_VV_V2_SS_COUNT,
string(__FUNCTION__) + ":Invalid count of public shares");
}
shared_ptr <string> encryptedKeyHex_ptr = readFromDb(_ethKeyName);
......@@ -975,7 +1002,7 @@ shared_ptr <string> SGXWalletServer::readFromDb(const string &name, const string
auto dataStr = checkDataFromDb(prefix + name);
if (dataStr == nullptr) {
throw SGXException(KEY_SHARE_DOES_NOT_EXIST, "Data with this name does not exist");
throw SGXException(KEY_SHARE_DOES_NOT_EXIST, string(__FUNCTION__) + ":Data with this name does not exist");
}
return dataStr;
......@@ -989,7 +1016,7 @@ shared_ptr <string> SGXWalletServer::checkDataFromDb(const string &name, const s
void SGXWalletServer::writeKeyShare(const string &_keyShareName, const string &_value) {
if (LevelDB::getLevelDb()->readString(_keyShareName) != nullptr) {
throw SGXException(KEY_SHARE_ALREADY_EXISTS, "Key share with this name already exists");
throw SGXException(KEY_SHARE_ALREADY_EXISTS, string(__FUNCTION__) + ":Key share with this name already exists");
}
LevelDB::getLevelDb()->writeString(_keyShareName, _value);
......@@ -998,7 +1025,7 @@ void SGXWalletServer::writeKeyShare(const string &_keyShareName, const string &_
void SGXWalletServer::writeDataToDB(const string &name, const string &value) {
if (LevelDB::getLevelDb()->readString(name) != nullptr) {
throw SGXException(KEY_NAME_ALREADY_EXISTS, "Name already exists");
throw SGXException(KEY_NAME_ALREADY_EXISTS, string(__FUNCTION__) + ":Name already exists");
}
LevelDB::getLevelDb()->writeString(name, value);
}
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