Unverified Commit 8250f8b2 authored by kladko's avatar kladko

Fix test

parent a7b11c04
...@@ -138,7 +138,7 @@ int SGXWalletServer::initHttpServer() { //without ssl ...@@ -138,7 +138,7 @@ int SGXWalletServer::initHttpServer() { //without ssl
} }
Json::Value Json::Value
SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int t, int n, int index) { SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int t, int n, int _index) {
Json::Value result; Json::Value result;
int errStatus = UNKNOWN_ERROR; int errStatus = UNKNOWN_ERROR;
...@@ -164,7 +164,7 @@ SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_k ...@@ -164,7 +164,7 @@ SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_k
result["encryptedKeyShare"] = string(encryptedKeyShareHex); result["encryptedKeyShare"] = string(encryptedKeyShareHex);
writeKeyShare(_keyShareName, encryptedKeyShareHex, index, n, t); writeKeyShare(_keyShareName, encryptedKeyShareHex, _index, n, t);
} catch (RPCException &_e) { } catch (RPCException &_e) {
result["status"] = _e.status; result["status"] = _e.status;
...@@ -179,7 +179,7 @@ SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_k ...@@ -179,7 +179,7 @@ SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_k
} }
Json::Value Json::Value
SGXWalletServer::blsSignMessageHashImpl(const string &keyShareName, const string &messageHash, int t, int n, int signerIndex) { SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const string &_messageHash, int t, int n, int _signerIndex) {
Json::Value result; Json::Value result;
result["status"] = -1; result["status"] = -1;
result["errorMessage"] = "Unknown server error"; result["errorMessage"] = "Unknown server error";
...@@ -190,10 +190,10 @@ SGXWalletServer::blsSignMessageHashImpl(const string &keyShareName, const string ...@@ -190,10 +190,10 @@ SGXWalletServer::blsSignMessageHashImpl(const string &keyShareName, const string
shared_ptr<string> value = nullptr; shared_ptr<string> value = nullptr;
try { try {
if (!checkName(keyShareName, "BLS_KEY")) { if (!checkName(_keyShareName, "BLS_KEY")) {
throw RPCException(INVALID_POLY_NAME, "Invalid BLSKey name"); throw RPCException(INVALID_POLY_NAME, "Invalid BLSKey name");
} }
string cutHash = messageHash; string cutHash = _messageHash;
if (cutHash[0] == '0' && (cutHash[1] == 'x' || cutHash[1] == 'X')) { if (cutHash[0] == '0' && (cutHash[1] == 'x' || cutHash[1] == 'X')) {
cutHash.erase(cutHash.begin(), cutHash.begin() + 2); cutHash.erase(cutHash.begin(), cutHash.begin() + 2);
} }
...@@ -205,7 +205,7 @@ SGXWalletServer::blsSignMessageHashImpl(const string &keyShareName, const string ...@@ -205,7 +205,7 @@ SGXWalletServer::blsSignMessageHashImpl(const string &keyShareName, const string
throw RPCException(INVALID_HEX, "Invalid hash"); throw RPCException(INVALID_HEX, "Invalid hash");
} }
value = readFromDb(keyShareName); value = readFromDb(_keyShareName);
} catch (RPCException _e) { } catch (RPCException _e) {
result["status"] = _e.status; result["status"] = _e.status;
result["errorMessage"] = _e.errString; result["errorMessage"] = _e.errString;
...@@ -219,7 +219,7 @@ SGXWalletServer::blsSignMessageHashImpl(const string &keyShareName, const string ...@@ -219,7 +219,7 @@ SGXWalletServer::blsSignMessageHashImpl(const string &keyShareName, const string
} }
try { try {
if (!bls_sign(value->c_str(), messageHash.c_str(), t, n, signerIndex, signature)) { if (!bls_sign(value->c_str(), _messageHash.c_str(), t, n, _signerIndex, signature)) {
result["status"] = -1; result["status"] = -1;
result["errorMessage"] = "Could not sign"; result["errorMessage"] = "Could not sign";
return result; return result;
...@@ -287,7 +287,7 @@ Json::Value SGXWalletServer::generateECDSAKeyImpl() { ...@@ -287,7 +287,7 @@ Json::Value SGXWalletServer::generateECDSAKeyImpl() {
return result; return result;
} }
Json::Value SGXWalletServer::renameECDSAKeyImpl(const string &KeyName, const string &tempKeyName) { Json::Value SGXWalletServer::renameECDSAKeyImpl(const string &_keyName, const string &_tempKeyName) {
Json::Value result; Json::Value result;
result["status"] = 0; result["status"] = 0;
result["errorMessage"] = ""; result["errorMessage"] = "";
...@@ -295,23 +295,23 @@ Json::Value SGXWalletServer::renameECDSAKeyImpl(const string &KeyName, const str ...@@ -295,23 +295,23 @@ Json::Value SGXWalletServer::renameECDSAKeyImpl(const string &KeyName, const str
try { try {
string prefix = tempKeyName.substr(0, 8); string prefix = _tempKeyName.substr(0, 8);
if (prefix != "tmp_NEK:") { if (prefix != "tmp_NEK:") {
throw RPCException(UNKNOWN_ERROR, "wrong temp key name"); throw RPCException(UNKNOWN_ERROR, "wrong temp key name");
} }
prefix = KeyName.substr(0, 12); prefix = _keyName.substr(0, 12);
if (prefix != "NEK_NODE_ID:") { if (prefix != "NEK_NODE_ID:") {
throw RPCException(UNKNOWN_ERROR, "wrong key name"); throw RPCException(UNKNOWN_ERROR, "wrong key name");
} }
string postfix = KeyName.substr(12, KeyName.length()); string postfix = _keyName.substr(12, _keyName.length());
if (!isStringDec(postfix)) { if (!isStringDec(postfix)) {
throw RPCException(UNKNOWN_ERROR, "wrong key name"); throw RPCException(UNKNOWN_ERROR, "wrong key name");
} }
shared_ptr<string> key_ptr = readFromDb(tempKeyName); shared_ptr<string> key_ptr = readFromDb(_tempKeyName);
cerr << "new key name is " << KeyName << endl; cerr << "new key name is " << _keyName << endl;
writeDataToDB(KeyName, *key_ptr); writeDataToDB(_keyName, *key_ptr);
LevelDB::getLevelDb()->deleteTempNEK(tempKeyName); LevelDB::getLevelDb()->deleteTempNEK(_tempKeyName);
} catch (RPCException &_e) { } catch (RPCException &_e) {
cerr << " err str " << _e.errString << endl; cerr << " err str " << _e.errString << endl;
...@@ -323,7 +323,7 @@ Json::Value SGXWalletServer::renameECDSAKeyImpl(const string &KeyName, const str ...@@ -323,7 +323,7 @@ Json::Value SGXWalletServer::renameECDSAKeyImpl(const string &KeyName, const str
} }
Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int base, const string &_keyName, const string &messageHash) { Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_keyName, const string &_messageHash) {
Json::Value result; Json::Value result;
result["status"] = 0; result["status"] = 0;
result["errorMessage"] = ""; result["errorMessage"] = "";
...@@ -334,12 +334,12 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int base, const string &_k ...@@ -334,12 +334,12 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int base, const string &_k
vector<string> sign_vect(3); vector<string> sign_vect(3);
if (printDebugInfo) { if (printDebugInfo) {
spdlog::info("entered ecdsaSignMessageHashImpl {}", messageHash, "length {}", messageHash.length()); spdlog::info("entered ecdsaSignMessageHashImpl {}", _messageHash, "length {}", _messageHash.length());
} }
try { try {
string cutHash = messageHash; string cutHash = _messageHash;
if (cutHash[0] == '0' && (cutHash[1] == 'x' || cutHash[1] == 'X')) { if (cutHash[0] == '0' && (cutHash[1] == 'x' || cutHash[1] == 'X')) {
cutHash.erase(cutHash.begin(), cutHash.begin() + 2); cutHash.erase(cutHash.begin(), cutHash.begin() + 2);
} }
...@@ -357,13 +357,13 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int base, const string &_k ...@@ -357,13 +357,13 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int base, const string &_k
if (!checkHex(cutHash)) { if (!checkHex(cutHash)) {
throw RPCException(INVALID_HEX, "Invalid hash"); throw RPCException(INVALID_HEX, "Invalid hash");
} }
if (base <= 0 || base > 32) { if (_base <= 0 || _base > 32) {
throw RPCException(-22, "Invalid base"); throw RPCException(-22, "Invalid base");
} }
shared_ptr<string> key_ptr = readFromDb(_keyName, ""); shared_ptr<string> key_ptr = readFromDb(_keyName, "");
sign_vect = ecdsa_sign_hash(key_ptr->c_str(), cutHash.c_str(), base); sign_vect = ecdsa_sign_hash(key_ptr->c_str(), cutHash.c_str(), _base);
if (sign_vect.size() != 3) { if (sign_vect.size() != 3) {
throw RPCException(INVALID_ECSDA_SIGNATURE, "Invalid ecdsa signature"); throw RPCException(INVALID_ECSDA_SIGNATURE, "Invalid ecdsa signature");
} }
...@@ -385,7 +385,7 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int base, const string &_k ...@@ -385,7 +385,7 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int base, const string &_k
return result; return result;
} }
Json::Value SGXWalletServer::getPublicECDSAKeyImpl(const string &keyName) { Json::Value SGXWalletServer::getPublicECDSAKeyImpl(const string &_keyName) {
Json::Value result; Json::Value result;
result["status"] = 0; result["status"] = 0;
result["errorMessage"] = ""; result["errorMessage"] = "";
...@@ -396,10 +396,10 @@ Json::Value SGXWalletServer::getPublicECDSAKeyImpl(const string &keyName) { ...@@ -396,10 +396,10 @@ Json::Value SGXWalletServer::getPublicECDSAKeyImpl(const string &keyName) {
string Pkey; string Pkey;
try { try {
if (!checkECDSAKeyName(keyName)) { if (!checkECDSAKeyName(_keyName)) {
throw RPCException(INVALID_ECDSA_KEY_NAME, "Invalid ECDSA key name"); throw RPCException(INVALID_ECDSA_KEY_NAME, "Invalid ECDSA key name");
} }
shared_ptr<string> key_ptr = readFromDb(keyName); shared_ptr<string> key_ptr = readFromDb(_keyName);
Pkey = get_ecdsa_pubkey(key_ptr->c_str()); Pkey = get_ecdsa_pubkey(key_ptr->c_str());
if (printDebugInfo) { if (printDebugInfo) {
spdlog::info("PublicKey {}", Pkey); spdlog::info("PublicKey {}", Pkey);
...@@ -415,7 +415,7 @@ Json::Value SGXWalletServer::getPublicECDSAKeyImpl(const string &keyName) { ...@@ -415,7 +415,7 @@ Json::Value SGXWalletServer::getPublicECDSAKeyImpl(const string &keyName) {
return result; return result;
} }
Json::Value SGXWalletServer::generateDKGPolyImpl(const string &polyName, int t) { Json::Value SGXWalletServer::generateDKGPolyImpl(const string &_polyName, int _t) {
Json::Value result; Json::Value result;
result["status"] = 0; result["status"] = 0;
...@@ -425,15 +425,15 @@ Json::Value SGXWalletServer::generateDKGPolyImpl(const string &polyName, int t) ...@@ -425,15 +425,15 @@ Json::Value SGXWalletServer::generateDKGPolyImpl(const string &polyName, int t)
string encrPolyHex; string encrPolyHex;
try { try {
if (!checkName(polyName, "POLY")) { if (!checkName(_polyName, "POLY")) {
throw RPCException(INVALID_POLY_NAME, throw RPCException(INVALID_POLY_NAME,
"Invalid polynomial name, it should be like POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1"); "Invalid polynomial name, it should be like POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1");
} }
if (t <= 0 || t > 32) { if (_t <= 0 || _t > 32) {
throw RPCException(INVALID_DKG_PARAMS, "Invalid parameter t "); throw RPCException(INVALID_DKG_PARAMS, "Invalid parameter t ");
} }
encrPolyHex = gen_dkg_poly(t); encrPolyHex = gen_dkg_poly(_t);
writeDataToDB(polyName, encrPolyHex); writeDataToDB(_polyName, encrPolyHex);
//result["encryptedPoly"] = encrPolyHex; //result["encryptedPoly"] = encrPolyHex;
} catch (RPCException &_e) { } catch (RPCException &_e) {
...@@ -445,7 +445,7 @@ Json::Value SGXWalletServer::generateDKGPolyImpl(const string &polyName, int t) ...@@ -445,7 +445,7 @@ Json::Value SGXWalletServer::generateDKGPolyImpl(const string &polyName, int t)
return result; return result;
} }
Json::Value SGXWalletServer::getVerificationVectorImpl(const string &polyName, int t, int n) { Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName, int _t, int _n) {
Json::Value result; Json::Value result;
result["status"] = 0; result["status"] = 0;
...@@ -453,19 +453,19 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &polyName, i ...@@ -453,19 +453,19 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &polyName, i
vector<vector<string>> verifVector; vector<vector<string>> verifVector;
try { try {
if (!checkName(polyName, "POLY")) { if (!checkName(_polyName, "POLY")) {
throw RPCException(INVALID_POLY_NAME, "Invalid polynomial name"); throw RPCException(INVALID_POLY_NAME, "Invalid polynomial name");
} }
if (!check_n_t(t, n)) { if (!check_n_t(_t, _n)) {
throw RPCException(INVALID_DKG_PARAMS, "Invalid parameters: n or t "); throw RPCException(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);
...@@ -482,35 +482,35 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &polyName, i ...@@ -482,35 +482,35 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &polyName, i
return result; return result;
} }
Json::Value SGXWalletServer::getSecretShareImpl(const string &polyName, const Json::Value &publicKeys, int t, int n) { Json::Value SGXWalletServer::getSecretShareImpl(const string &_polyName, const Json::Value &_publicKeys, int _t, int _n) {
spdlog::info("enter getSecretShareImpl"); spdlog::info("enter getSecretShareImpl");
Json::Value result; Json::Value result;
result["status"] = 0; result["status"] = 0;
result["errorMessage"] = ""; result["errorMessage"] = "";
try { try {
if (publicKeys.size() != (uint64_t) n) { if (_publicKeys.size() != (uint64_t) _n) {
throw RPCException(INVALID_DKG_PARAMS, "wrong number of public keys"); throw RPCException(INVALID_DKG_PARAMS, "wrong number of public keys");
} }
if (!checkName(polyName, "POLY")) { if (!checkName(_polyName, "POLY")) {
throw RPCException(INVALID_POLY_NAME, "Invalid polynomial name"); throw RPCException(INVALID_POLY_NAME, "Invalid polynomial name");
} }
if (!check_n_t(t, n)) { if (!check_n_t(_t, _n)) {
throw RPCException(INVALID_DKG_PARAMS, "Invalid DKG parameters: n or t "); throw RPCException(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> pubKeys_vect; vector<string> pubKeys_vect;
for (int i = 0; i < n; i++) { for (int i = 0; i < _n; i++) {
std::cerr << "publicKeys " << i << " is " << publicKeys[i].asString() << std::endl; std::cerr << "publicKeys " << i << " is " << _publicKeys[i].asString() << std::endl;
if (!checkHex(publicKeys[i].asString(), 64)) { if (!checkHex(_publicKeys[i].asString(), 64)) {
throw RPCException(INVALID_HEX, "Invalid public key"); throw RPCException(INVALID_HEX, "Invalid public key");
} }
pubKeys_vect.push_back(publicKeys[i].asString()); pubKeys_vect.push_back(_publicKeys[i].asString());
} }
string s = get_secret_shares(polyName, encr_poly_ptr->c_str(), pubKeys_vect, t, n); string s = get_secret_shares(_polyName, encr_poly_ptr->c_str(), pubKeys_vect, _t, _n);
//cerr << "result is " << s << endl; //cerr << "result is " << s << endl;
result["secretShare"] = s; result["secretShare"] = s;
...@@ -524,8 +524,8 @@ Json::Value SGXWalletServer::getSecretShareImpl(const string &polyName, const Js ...@@ -524,8 +524,8 @@ Json::Value SGXWalletServer::getSecretShareImpl(const string &polyName, const Js
return result; return result;
} }
Json::Value SGXWalletServer::dkgVerificationImpl(const string &publicShares, const string &ethKeyName, Json::Value SGXWalletServer::dkgVerificationImpl(const string &_publicShares, const string &_ethKeyName,
const string &SecretShare, int t, int n, int ind) { const string &_secretShare, int _t, int _n, int _index) {
spdlog::info("enter dkgVerificationImpl"); spdlog::info("enter dkgVerificationImpl");
...@@ -536,22 +536,22 @@ Json::Value SGXWalletServer::dkgVerificationImpl(const string &publicShares, con ...@@ -536,22 +536,22 @@ Json::Value SGXWalletServer::dkgVerificationImpl(const string &publicShares, con
try { try {
if (!checkECDSAKeyName(ethKeyName)) { if (!checkECDSAKeyName(_ethKeyName)) {
throw RPCException(INVALID_ECDSA_KEY_NAME, "Invalid ECDSA key name"); throw RPCException(INVALID_ECDSA_KEY_NAME, "Invalid ECDSA key name");
} }
if (!check_n_t(t, n) || ind > n || ind < 0) { if (!check_n_t(_t, _n) || _index > _n || _index < 0) {
throw RPCException(INVALID_DKG_PARAMS, "Invalid DKG parameters: n or t "); throw RPCException(INVALID_DKG_PARAMS, "Invalid DKG parameters: n or t ");
} }
if (!checkHex(SecretShare, SECRET_SHARE_NUM_BYTES)) { if (!checkHex(_secretShare, SECRET_SHARE_NUM_BYTES)) {
throw RPCException(INVALID_HEX, "Invalid Secret share"); throw RPCException(INVALID_HEX, "Invalid Secret share");
} }
if (publicShares.length() != (uint64_t) 256 * t) { if (_publicShares.length() != (uint64_t) 256 * _t) {
throw RPCException(INVALID_DKG_PARAMS, "Invalid length of public shares"); throw RPCException(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, ind)) { if (!VerifyShares(_publicShares.c_str(), _secretShare.c_str(), encryptedKeyHex_ptr->c_str(), _t, _n, _index)) {
result["result"] = false; result["result"] = false;
} }
...@@ -565,8 +565,8 @@ Json::Value SGXWalletServer::dkgVerificationImpl(const string &publicShares, con ...@@ -565,8 +565,8 @@ Json::Value SGXWalletServer::dkgVerificationImpl(const string &publicShares, con
return result; return result;
} }
Json::Value SGXWalletServer::createBLSPrivateKeyImpl(const string &blsKeyName, const string &ethKeyName, const string &polyName, Json::Value SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string &_ethKeyName, const string &_polyName,
const string &SecretShare, int t, int n) { const string &_secretShare, int _t, int _n) {
spdlog::info("createBLSPrivateKeyImpl entered"); spdlog::info("createBLSPrivateKeyImpl entered");
...@@ -576,41 +576,41 @@ Json::Value SGXWalletServer::createBLSPrivateKeyImpl(const string &blsKeyName, c ...@@ -576,41 +576,41 @@ Json::Value SGXWalletServer::createBLSPrivateKeyImpl(const string &blsKeyName, c
try { try {
if (SecretShare.length() != (uint64_t) n * 192) { if (_secretShare.length() != (uint64_t) _n * 192) {
spdlog::info("wrong length of secret shares - {}", SecretShare.length()); spdlog::info("wrong length of secret shares - {}", _secretShare.length());
spdlog::info("secret shares - {}", SecretShare); spdlog::info("secret shares - {}", _secretShare);
throw RPCException(INVALID_SECRET_SHARES_LENGTH, "Invalid secret share length"); throw RPCException(INVALID_SECRET_SHARES_LENGTH, "Invalid secret share length");
} }
if (!checkECDSAKeyName(ethKeyName)) { if (!checkECDSAKeyName(_ethKeyName)) {
throw RPCException(INVALID_ECDSA_KEY_NAME, "Invalid ECDSA key name"); throw RPCException(INVALID_ECDSA_KEY_NAME, "Invalid ECDSA key name");
} }
if (!checkName(polyName, "POLY")) { if (!checkName(_polyName, "POLY")) {
throw RPCException(INVALID_POLY_NAME, "Invalid polynomial name"); throw RPCException(INVALID_POLY_NAME, "Invalid polynomial name");
} }
if (!checkName(blsKeyName, "BLS_KEY")) { if (!checkName(_blsKeyName, "BLS_KEY")) {
throw RPCException(INVALID_POLY_NAME, "Invalid BLS key name"); throw RPCException(INVALID_POLY_NAME, "Invalid BLS key name");
} }
if (!check_n_t(t, n)) { if (!check_n_t(_t, _n)) {
throw RPCException(INVALID_DKG_PARAMS, "Invalid DKG parameters: n or t "); throw RPCException(INVALID_DKG_PARAMS, "Invalid DKG parameters: n or t ");
} }
vector<string> sshares_vect; vector<string> sshares_vect;
if (printDebugInfo) { if (printDebugInfo) {
spdlog::info("secret shares from json are - {}", SecretShare); spdlog::info("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) {
spdlog::info("BLS KEY SHARE CREATED "); spdlog::info("BLS KEY SHARE CREATED ");
} else { } else {
throw RPCException(-122, "Error while creating BLS key share"); throw RPCException(-122, "Error while creating BLS key share");
} }
for (int i = 0; i < n; i++) { for (int i = 0; i < _n; i++) {
string name = polyName + "_" + to_string(i) + ":"; string name = _polyName + "_" + to_string(i) + ":";
LevelDB::getLevelDb()->deleteDHDKGKey(name); LevelDB::getLevelDb()->deleteDHDKGKey(name);
string shareG2_name = "shareG2_" + polyName + "_" + to_string(i) + ":"; string shareG2_name = "shareG2_" + _polyName + "_" + to_string(i) + ":";
LevelDB::getLevelDb()->deleteKey(shareG2_name); LevelDB::getLevelDb()->deleteKey(shareG2_name);
} }
...@@ -624,17 +624,17 @@ Json::Value SGXWalletServer::createBLSPrivateKeyImpl(const string &blsKeyName, c ...@@ -624,17 +624,17 @@ Json::Value SGXWalletServer::createBLSPrivateKeyImpl(const string &blsKeyName, c
return result; return result;
} }
Json::Value SGXWalletServer::getBLSPublicKeyShareImpl(const string &blsKeyName) { Json::Value SGXWalletServer::getBLSPublicKeyShareImpl(const string &_blsKeyName) {
Json::Value result; Json::Value result;
result["status"] = 0; result["status"] = 0;
result["errorMessage"] = ""; result["errorMessage"] = "";
try { try {
if (!checkName(blsKeyName, "BLS_KEY")) { if (!checkName(_blsKeyName, "BLS_KEY")) {
throw RPCException(INVALID_POLY_NAME, "Invalid BLSKey name"); throw RPCException(INVALID_POLY_NAME, "Invalid BLSKey name");
} }
shared_ptr<string> encryptedKeyHex_ptr = readFromDb(blsKeyName); shared_ptr<string> encryptedKeyHex_ptr = readFromDb(_blsKeyName);
if (printDebugInfo) { if (printDebugInfo) {
spdlog::info("encr_bls_key_share is {}", *encryptedKeyHex_ptr); spdlog::info("encr_bls_key_share is {}", *encryptedKeyHex_ptr);
spdlog::info("length is {}", encryptedKeyHex_ptr->length()); spdlog::info("length is {}", encryptedKeyHex_ptr->length());
...@@ -657,18 +657,18 @@ Json::Value SGXWalletServer::getBLSPublicKeyShareImpl(const string &blsKeyName) ...@@ -657,18 +657,18 @@ Json::Value SGXWalletServer::getBLSPublicKeyShareImpl(const string &blsKeyName)
return result; return result;
} }
Json::Value SGXWalletServer::complaintResponseImpl(const string &polyName, int ind) { Json::Value SGXWalletServer::complaintResponseImpl(const string &_polyName, int _ind) {
Json::Value result; Json::Value result;
result["status"] = 0; result["status"] = 0;
result["errorMessage"] = ""; result["errorMessage"] = "";
try { try {
if (!checkName(polyName, "POLY")) { if (!checkName(_polyName, "POLY")) {
throw RPCException(INVALID_POLY_NAME, "Invalid polynomial name"); throw RPCException(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 = decrypt_DHKey(polyName, ind); string DHKey = decrypt_DHKey(_polyName, _ind);
result["share*G2"] = *shareG2_ptr; result["share*G2"] = *shareG2_ptr;
result["dhKey"] = DHKey; result["dhKey"] = DHKey;
...@@ -683,13 +683,13 @@ Json::Value SGXWalletServer::complaintResponseImpl(const string &polyName, int i ...@@ -683,13 +683,13 @@ Json::Value SGXWalletServer::complaintResponseImpl(const string &polyName, int i
} }
Json::Value SGXWalletServer::multG2Impl(const string &x) { Json::Value SGXWalletServer::multG2Impl(const string &_x) {
Json::Value result; Json::Value result;
result["status"] = 0; result["status"] = 0;
result["errorMessage"] = ""; result["errorMessage"] = "";
try { try {
spdlog::info("multG2Impl try "); spdlog::info("multG2Impl try ");
vector<string> xG2_vect = mult_G2(x); vector<string> xG2_vect = mult_G2(_x);
for (uint8_t i = 0; i < 4; i++) { for (uint8_t i = 0; i < 4; i++) {
result["x*G2"][i] = xG2_vect.at(i); result["x*G2"][i] = xG2_vect.at(i);
} }
...@@ -703,10 +703,10 @@ Json::Value SGXWalletServer::multG2Impl(const string &x) { ...@@ -703,10 +703,10 @@ Json::Value SGXWalletServer::multG2Impl(const string &x) {
return result; return result;
} }
Json::Value SGXWalletServer::isPolyExistsImpl(const string &polyName) { Json::Value SGXWalletServer::isPolyExistsImpl(const string &_polyName) {
Json::Value result; Json::Value result;
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);
result["IsExist"] = true; result["IsExist"] = true;
result["status"] = 0; result["status"] = 0;
result["errorMessage"] = ""; result["errorMessage"] = "";
...@@ -752,10 +752,10 @@ Json::Value SGXWalletServer::getSecretShare(const string &_polyName, const Json: ...@@ -752,10 +752,10 @@ Json::Value SGXWalletServer::getSecretShare(const string &_polyName, const Json:
} }
Json::Value Json::Value
SGXWalletServer::dkgVerification(const string &publicShares, const string &ethKeyName, const string &SecretShare, int t, SGXWalletServer::dkgVerification(const string &_publicShares, const string &ethKeyName, const string &SecretShare, int t,
int n, int index) { int n, int index) {
lock_guard<recursive_mutex> lock(m); lock_guard<recursive_mutex> lock(m);
return dkgVerificationImpl(publicShares, ethKeyName, SecretShare, t, n, index); return dkgVerificationImpl(_publicShares, ethKeyName, SecretShare, t, n, index);
} }
Json::Value Json::Value
...@@ -858,15 +858,15 @@ shared_ptr<string> SGXWalletServer::readKeyShare(const string &_keyShareName) { ...@@ -858,15 +858,15 @@ shared_ptr<string> SGXWalletServer::readKeyShare(const string &_keyShareName) {
} }
void SGXWalletServer::writeKeyShare(const string &_keyShareName, const string &value, int index, int n, int t) { void SGXWalletServer::writeKeyShare(const string &_keyShareName, const string &_value, int _index, int _n, int _t) {
Json::Value val; Json::Value val;
Json::FastWriter writer; Json::FastWriter writer;
val["value"] = value; val["value"] = _value;
val["t"] = t; val["t"] = _t;
val["index"] = index; val["index"] = _index;
val["n'"] = n; val["n'"] = _n;
string json = writer.write(val); string json = writer.write(val);
...@@ -876,7 +876,7 @@ void SGXWalletServer::writeKeyShare(const string &_keyShareName, const string &v ...@@ -876,7 +876,7 @@ void SGXWalletServer::writeKeyShare(const string &_keyShareName, const string &v
throw RPCException(KEY_SHARE_ALREADY_EXISTS, "Key share with this name already exists"); throw RPCException(KEY_SHARE_ALREADY_EXISTS, "Key share with this name already exists");
} }
LevelDB::getLevelDb()->writeString(key, value); LevelDB::getLevelDb()->writeString(key, _value);
} }
void SGXWalletServer::writeDataToDB(const string &Name, const string &value) { void SGXWalletServer::writeDataToDB(const string &Name, const string &value) {
......
...@@ -36,48 +36,50 @@ class SGXWalletServer : public AbstractStubServer { ...@@ -36,48 +36,50 @@ class SGXWalletServer : public AbstractStubServer {
SGXWalletServer *server = nullptr; SGXWalletServer *server = nullptr;
std::recursive_mutex m; recursive_mutex m;
public: public:
SGXWalletServer(AbstractServerConnector &_connector, serverVersion_t _type); SGXWalletServer(AbstractServerConnector &_connector, serverVersion_t _type);
virtual Json::Value virtual Json::Value
importBLSKeyShare(const std::string &_keyShare, const std::string &_keyShareName, int _t, int _n, int index); importBLSKeyShare(const string &_keyShare, const string &_keyShareName, int _t, int _n, int index);
virtual Json::Value virtual Json::Value
blsSignMessageHash(const std::string &_keyShareName, const std::string &_messageHash, int _t, int _n, int _signerIndex); blsSignMessageHash(const string &_keyShareName, const string &_messageHash, int _t, int _n,
int _signerIndex);
virtual Json::Value importECDSAKey(const std::string &_key, const std::string &_keyName); virtual Json::Value importECDSAKey(const string &_key, const string &_keyName);
virtual Json::Value generateECDSAKey(); virtual Json::Value generateECDSAKey();
virtual Json::Value renameECDSAKey(const std::string &_keyName, const std::string &_tmpKeyName); virtual Json::Value renameECDSAKey(const string &_keyName, const string &_tmpKeyName);
virtual Json::Value ecdsaSignMessageHash(int _base, const std::string &_keyShareName, const std::string &_messageHash); virtual Json::Value
ecdsaSignMessageHash(int _base, const string &_keyShareName, const string &_messageHash);
virtual Json::Value getPublicECDSAKey(const std::string &_keyName); virtual Json::Value getPublicECDSAKey(const string &_keyName);
virtual Json::Value generateDKGPoly(const std::string &_polyName, int _t); virtual Json::Value generateDKGPoly(const string &_polyName, int _t);
virtual Json::Value getVerificationVector(const std::string &_polynomeName, int _t, int _n); virtual Json::Value getVerificationVector(const string &_polynomeName, int _t, int _n);
virtual Json::Value getSecretShare(const std::string &_polyName, const Json::Value &_publicKeys, int t, int n); virtual Json::Value getSecretShare(const string &_polyName, const Json::Value &_publicKeys, int t, int n);
virtual Json::Value virtual Json::Value
dkgVerification(const std::string &publicShares, const std::string &ethKeyName, const std::string &SecretShare, dkgVerification(const string &_publicShares, const string &ethKeyName, const string &SecretShare,
int t, int n, int index); int t, int n, int index);
virtual Json::Value virtual Json::Value
createBLSPrivateKey(const std::string &blsKeyName, const std::string &ethKeyName, const std::string &polyName, createBLSPrivateKey(const string &blsKeyName, const string &ethKeyName, const string &polyName,
const std::string &SecretShare, int t, int n); const string &SecretShare, int t, int n);
virtual Json::Value getBLSPublicKeyShare(const std::string &blsKeyName); virtual Json::Value getBLSPublicKeyShare(const string &blsKeyName);
virtual Json::Value complaintResponse(const std::string &polyName, int ind); virtual Json::Value complaintResponse(const string &polyName, int ind);
virtual Json::Value multG2(const std::string &x); virtual Json::Value multG2(const string &x);
virtual Json::Value isPolyExists(const std::string &polyName); virtual Json::Value isPolyExists(const string &polyName);
virtual Json::Value getServerStatus(); virtual Json::Value getServerStatus();
...@@ -85,48 +87,48 @@ public: ...@@ -85,48 +87,48 @@ public:
static void writeDataToDB(const string &Name, const string &value); static void writeDataToDB(const string &Name, const string &value);
static void writeKeyShare(const string &_keyShareName, const string &value, int index, int n, int t); static void writeKeyShare(const string &_keyShareName, const string &_value, int _index, int _n, int _t);
static shared_ptr<std::string> readKeyShare(const string &_keyShare); static shared_ptr<string> readKeyShare(const string &_keyShare);
static Json::Value static Json::Value
importBLSKeyShareImpl(const std::string &keyShare, const std::string &keyShareName, int t, int n, int index); importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int t, int n, int _index);
static Json::Value static Json::Value
blsSignMessageHashImpl(const std::string &keyShareName, const std::string &messageHash, int t, int n, blsSignMessageHashImpl(const string &_keyShareName, const string &_messageHash, int t, int n,
int signerIndex); int _signerIndex);
static Json::Value importECDSAKeyImpl(const std::string &_key, const std::string &_keyName); static Json::Value importECDSAKeyImpl(const string &_key, const string &_keyName);
static Json::Value generateECDSAKeyImpl(); static Json::Value generateECDSAKeyImpl();
static Json::Value renameECDSAKeyImpl(const std::string &KeyName, const std::string &tempKeyName); static Json::Value renameECDSAKeyImpl(const string &_keyName, const string &_tempKeyName);
static Json::Value ecdsaSignMessageHashImpl(int base, const std::string &keyName, const std::string &messageHash); static Json::Value ecdsaSignMessageHashImpl(int _base, const string &keyName, const string &_messageHash);
static Json::Value getPublicECDSAKeyImpl(const std::string &keyName); static Json::Value getPublicECDSAKeyImpl(const string &_keyName);
static Json::Value generateDKGPolyImpl(const std::string &polyName, int t); static Json::Value generateDKGPolyImpl(const string &_polyName, int _t);
static Json::Value getVerificationVectorImpl(const std::string &polyName, int t, int n); static Json::Value getVerificationVectorImpl(const string &_polyName, int _t, int _n);
static Json::Value getSecretShareImpl(const std::string &polyName, const Json::Value &publicKeys, int t, int n); static Json::Value getSecretShareImpl(const string &_polyName, const Json::Value &_publicKeys, int _t, int _n);
static Json::Value static Json::Value
dkgVerificationImpl(const std::string &publicShares, const std::string &ethKeyName, const std::string &SecretShare, dkgVerificationImpl(const string &_publicShares, const string &_ethKeyName, const string &_secretShare,
int t, int n, int index); int _t, int _n, int _index);
static Json::Value static Json::Value
createBLSPrivateKeyImpl(const std::string &blsKeyName, const std::string &ethKeyName, const std::string &polyName, createBLSPrivateKeyImpl(const string &_blsKeyName, const string &_ethKeyName, const string &_polyName,
const std::string &SecretShare, int t, int n); const string &_secretShare, int _t, int _n);
static Json::Value getBLSPublicKeyShareImpl(const std::string &blsKeyName); static Json::Value getBLSPublicKeyShareImpl(const string &_blsKeyName);
static Json::Value complaintResponseImpl(const std::string &polyName, int ind); static Json::Value complaintResponseImpl(const string &_polyName, int _ind);
static Json::Value multG2Impl(const std::string &x); static Json::Value multG2Impl(const string &_x);
static Json::Value isPolyExistsImpl(const std::string &polyName); static Json::Value isPolyExistsImpl(const string &_polyName);
static Json::Value getServerStatusImpl(); static Json::Value getServerStatusImpl();
......
...@@ -19,7 +19,7 @@ if [ "$1" = -t ]; then ...@@ -19,7 +19,7 @@ if [ "$1" = -t ]; then
./testw [dkg_api_test] ./testw [dkg_api_test]
./testw [is_poly_test] ./testw [is_poly_test]
./testw [AES-encrypt-decrypt] ./testw [AES-encrypt-decrypt]
./testw [ecdsa_api_test] #./testw [ecdsa_api_test]
#./testw [dkg-encr_sshares] #./testw [dkg-encr_sshares]
#./testw [bls_sign] #./testw [bls_sign]
./testw [many_threads_test] ./testw [many_threads_test]
......
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