Unverified Commit 20362fb3 authored by Oleh Nikolaiev's avatar Oleh Nikolaiev Committed by GitHub

Merge pull request #137 from skalenetwork/bug/SKALE-2977-sgx-crash

Bug/skale 2977 sgx crash
parents 4fcda5df 1df51891
...@@ -181,6 +181,7 @@ bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz ...@@ -181,6 +181,7 @@ bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz
if (yStr == nullptr) { if (yStr == nullptr) {
std::cerr << "Null yStr" << std::endl; std::cerr << "Null yStr" << std::endl;
delete xStr;
BOOST_THROW_EXCEPTION(runtime_error("Null yStr")); BOOST_THROW_EXCEPTION(runtime_error("Null yStr"));
} }
...@@ -197,6 +198,9 @@ bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz ...@@ -197,6 +198,9 @@ bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz
strncpy(xStrArg, xStr->c_str(), BUF_LEN); strncpy(xStrArg, xStr->c_str(), BUF_LEN);
strncpy(yStrArg, yStr->c_str(), BUF_LEN); strncpy(yStrArg, yStr->c_str(), BUF_LEN);
delete xStr;
delete yStr;
size_t sz = 0; size_t sz = 0;
uint8_t encryptedKey[BUF_LEN]; uint8_t encryptedKey[BUF_LEN];
...@@ -233,9 +237,6 @@ bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz ...@@ -233,9 +237,6 @@ bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz
strncpy(_sig, sig.c_str(), BUF_LEN); strncpy(_sig, sig.c_str(), BUF_LEN);
delete xStr;
delete yStr;
return true; return true;
} }
......
...@@ -117,6 +117,7 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr( ...@@ -117,6 +117,7 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr(
if (yStr == nullptr) { if (yStr == nullptr) {
std::cerr << "Null yStr" << std::endl; std::cerr << "Null yStr" << std::endl;
delete xStr;
BOOST_THROW_EXCEPTION(runtime_error("Null yStr")); BOOST_THROW_EXCEPTION(runtime_error("Null yStr"));
} }
...@@ -133,6 +134,9 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr( ...@@ -133,6 +134,9 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr(
strncpy(xStrArg, xStr->c_str(), BUF_LEN); strncpy(xStrArg, xStr->c_str(), BUF_LEN);
strncpy(yStrArg, yStr->c_str(), BUF_LEN); strncpy(yStrArg, yStr->c_str(), BUF_LEN);
delete xStr;
delete yStr;
size_t sz = 0; size_t sz = 0;
uint8_t encryptedKey[BUF_LEN]; uint8_t encryptedKey[BUF_LEN];
...@@ -159,7 +163,6 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr( ...@@ -159,7 +163,6 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr(
if (errStatus != 0) { if (errStatus != 0) {
BOOST_THROW_EXCEPTION(runtime_error("Enclave trustedBlsSignMessage failed:" + to_string(errStatus) + ":" + errMsg )); BOOST_THROW_EXCEPTION(runtime_error("Enclave trustedBlsSignMessage failed:" + to_string(errStatus) + ":" + errMsg ));
return nullptr;
} }
int sigLen; int sigLen;
...@@ -176,9 +179,6 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr( ...@@ -176,9 +179,6 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr(
sig.append(":"); sig.append(":");
sig.append(hint); sig.append(hint);
delete xStr;
delete yStr;
return sig; return sig;
} }
......
...@@ -85,7 +85,7 @@ vector <string> genECDSAKey() { ...@@ -85,7 +85,7 @@ vector <string> genECDSAKey() {
return keys; return keys;
} }
string getECDSAPubKey(const char *_encryptedKeyHex) { string getECDSAPubKey(const std::string& _encryptedKeyHex) {
vector<char> errMsg(BUF_LEN, 0); vector<char> errMsg(BUF_LEN, 0);
vector<char> pubKeyX(BUF_LEN, 0); vector<char> pubKeyX(BUF_LEN, 0);
vector<char> pubKeyY(BUF_LEN, 0); vector<char> pubKeyY(BUF_LEN, 0);
...@@ -94,7 +94,7 @@ string getECDSAPubKey(const char *_encryptedKeyHex) { ...@@ -94,7 +94,7 @@ string getECDSAPubKey(const char *_encryptedKeyHex) {
int errStatus = 0; int errStatus = 0;
uint64_t enc_len = 0; uint64_t enc_len = 0;
if (!hex2carray(_encryptedKeyHex, &enc_len, encrPrKey.data())) { if (!hex2carray(_encryptedKeyHex.c_str(), &enc_len, encrPrKey.data())) {
throw SGXException(INVALID_HEX, "Invalid encryptedKeyHex"); throw SGXException(INVALID_HEX, "Invalid encryptedKeyHex");
} }
...@@ -122,47 +122,49 @@ string getECDSAPubKey(const char *_encryptedKeyHex) { ...@@ -122,47 +122,49 @@ string getECDSAPubKey(const char *_encryptedKeyHex) {
bool verifyECDSASig(string& pubKeyStr, const char *hashHex, const char *signatureR, bool verifyECDSASig(string& pubKeyStr, const char *hashHex, const char *signatureR,
const char *signatureS, int base) { const char *signatureS, int base) {
bool result = false;
signature sig = signature_init();
auto x = pubKeyStr.substr(0, 64); auto x = pubKeyStr.substr(0, 64);
auto y = pubKeyStr.substr(64, 128); auto y = pubKeyStr.substr(64, 128);
domain_parameters curve = domain_parameters_init();
domain_parameters_load_curve(curve, secp256k1);
point publicKey = point_init();
mpz_t msgMpz; mpz_t msgMpz;
mpz_init(msgMpz); mpz_init(msgMpz);
if (mpz_set_str(msgMpz, hashHex, 16) == -1) { if (mpz_set_str(msgMpz, hashHex, 16) == -1) {
spdlog::error("invalid message hash {}", hashHex); spdlog::error("invalid message hash {}", hashHex);
goto clean; mpz_clear(msgMpz);
return false;
} }
signature sig = signature_init();
if (signature_set_str(sig, signatureR, signatureS, base) != 0) { if (signature_set_str(sig, signatureR, signatureS, base) != 0) {
spdlog::error("Failed to set str signature"); spdlog::error("Failed to set str signature");
goto clean; mpz_clear(msgMpz);
signature_free(sig);
return false;
} }
domain_parameters curve = domain_parameters_init();
domain_parameters_load_curve(curve, secp256k1);
point publicKey = point_init();
point_set_hex(publicKey, x.c_str(), y.c_str()); point_set_hex(publicKey, x.c_str(), y.c_str());
if (!signature_verify(msgMpz, sig, publicKey, curve)) { if (!signature_verify(msgMpz, sig, publicKey, curve)) {
spdlog::error("ECDSA sig not verified"); spdlog::error("ECDSA sig not verified");
goto clean; mpz_clear(msgMpz);
signature_free(sig);
domain_parameters_clear(curve);
point_clear(publicKey);
return false;
} }
result = true;
clean:
mpz_clear(msgMpz); mpz_clear(msgMpz);
signature_free(sig);
domain_parameters_clear(curve); domain_parameters_clear(curve);
point_clear(publicKey); point_clear(publicKey);
signature_free(sig);
return result; return true;
} }
vector <string> ecdsaSignHash(const char *encryptedKeyHex, const char *hashHex, int base) { vector <string> ecdsaSignHash(const std::string& encryptedKeyHex, const char *hashHex, int base) {
vector <string> signatureVector(3); vector <string> signatureVector(3);
vector<char> errMsg(1024, 0); vector<char> errMsg(1024, 0);
...@@ -175,21 +177,22 @@ vector <string> ecdsaSignHash(const char *encryptedKeyHex, const char *hashHex, ...@@ -175,21 +177,22 @@ vector <string> ecdsaSignHash(const char *encryptedKeyHex, const char *hashHex,
string pubKeyStr = ""; string pubKeyStr = "";
if (!hex2carray(encryptedKeyHex, &decLen, encryptedKey.data())) { if (!hex2carray(encryptedKeyHex.c_str(), &decLen, encryptedKey.data())) {
throw SGXException(INVALID_HEX, "Invalid encryptedKeyHex"); throw SGXException(INVALID_HEX, "Invalid encryptedKeyHex");
} }
status = trustedEcdsaSignAES(eid, &errStatus, status = trustedEcdsaSignAES(eid, &errStatus,
errMsg.data(), encryptedKey.data(), decLen, (unsigned char *) hashHex, errMsg.data(), encryptedKey.data(), decLen, hashHex,
signatureR.data(), signatureR.data(),
signatureS.data(), &signatureV, base); signatureS.data(), &signatureV, base);
if (errStatus != 0) { if (errStatus != 0) {
spdlog::error("failed to sign {}", errStatus);
throw SGXException(666, errMsg.data()); throw SGXException(666, errMsg.data());
} }
if (status != SGX_SUCCESS) { if (status != SGX_SUCCESS) {
spdlog::error("failed to sign {}", status); spdlog::error("failed to sign in enclave {}", status);
throw SGXException(666, "failed to sign"); throw SGXException(666, "failed to sign");
} }
...@@ -213,6 +216,7 @@ vector <string> ecdsaSignHash(const char *encryptedKeyHex, const char *hashHex, ...@@ -213,6 +216,7 @@ vector <string> ecdsaSignHash(const char *encryptedKeyHex, const char *hashHex,
if (i % 1000 == 0) { if (i % 1000 == 0) {
if (!verifyECDSASig(pubKeyStr, hashHex, signatureR.data(), signatureS.data(), base)) { if (!verifyECDSASig(pubKeyStr, hashHex, signatureR.data(), signatureS.data(), base)) {
spdlog::error("failed to verify ecdsa signature");
throw SGXException(667, "ECDSA did not verify"); throw SGXException(667, "ECDSA did not verify");
} }
} }
......
...@@ -31,9 +31,9 @@ using namespace std; ...@@ -31,9 +31,9 @@ using namespace std;
vector<string> genECDSAKey(); vector<string> genECDSAKey();
string getECDSAPubKey(const char* _encryptedKeyHex); string getECDSAPubKey(const std::string& _encryptedKeyHex);
vector<string> ecdsaSignHash(const char* encryptedKeyHex, const char* hashHex, int base); vector<string> ecdsaSignHash(const std::string& encryptedKeyHex, const char* hashHex, int base);
#endif //SGXD_ECDSACRYPTO_H #endif //SGXD_ECDSACRYPTO_H
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
#include "secure_enclave/DomainParameters.c" #include "secure_enclave/DomainParameters.c"
#include "secure_enclave/NumberTheory.c" #include "secure_enclave/NumberTheory.c"
#include "secure_enclave/Signature.c" #include "secure_enclave/Signature.c"
#include "secure_enclave/Curves.c" #include "secure_enclave/Curves.c"
\ No newline at end of file
...@@ -21,13 +21,11 @@ ...@@ -21,13 +21,11 @@
@date 2019 @date 2019
*/ */
#include <stdexcept> #include <stdexcept>
#include <memory> #include <memory>
#include <string> #include <string>
#include <iostream> #include <iostream>
#include "leveldb/db.h" #include "leveldb/db.h"
#include "sgxwallet_common.h" #include "sgxwallet_common.h"
...@@ -53,9 +51,9 @@ std::shared_ptr<string> LevelDB::readString(const string &_key) { ...@@ -53,9 +51,9 @@ std::shared_ptr<string> LevelDB::readString(const string &_key) {
throw SGXException(NULL_DATABASE, "Null db"); throw SGXException(NULL_DATABASE, "Null db");
} }
spdlog::debug("key to read from db: {}",_key ); spdlog::debug("key to read from db: {}", _key);
auto status = db->Get(readOptions, _key, &*result); auto status = db->Get(readOptions, _key, result.get());
throwExceptionOnError(status); throwExceptionOnError(status);
...@@ -73,7 +71,7 @@ void LevelDB::writeString(const string &_key, const string &_value) { ...@@ -73,7 +71,7 @@ void LevelDB::writeString(const string &_key, const string &_value) {
throwExceptionOnError(status); throwExceptionOnError(status);
spdlog::debug("written key: {}",_key ); spdlog::debug("written key: {}", _key);
} }
...@@ -101,7 +99,7 @@ void LevelDB::deleteTempNEK(const string &_key) { ...@@ -101,7 +99,7 @@ void LevelDB::deleteTempNEK(const string &_key) {
throwExceptionOnError(status); throwExceptionOnError(status);
std::cerr << "key deleted " << _key << std::endl; spdlog::debug("key deleted: {}", _key);
} }
void LevelDB::deleteKey(const string &_key) { void LevelDB::deleteKey(const string &_key) {
...@@ -111,7 +109,7 @@ void LevelDB::deleteKey(const string &_key) { ...@@ -111,7 +109,7 @@ void LevelDB::deleteKey(const string &_key) {
throwExceptionOnError(status); throwExceptionOnError(status);
spdlog::debug("key deleted: {}",_key ); spdlog::debug("key deleted: {}", _key);
} }
......
...@@ -54,8 +54,7 @@ AM_CPPFLAGS += -DSGXWALLET_VERSION="$(WALLET_VERSION)" -Wall -DSKALE_SGX=1 -DBIN ...@@ -54,8 +54,7 @@ AM_CPPFLAGS += -DSGXWALLET_VERSION="$(WALLET_VERSION)" -Wall -DSKALE_SGX=1 -DBIN
## Additional targets to remove with 'make clean'. You must list ## Additional targets to remove with 'make clean'. You must list
## any edger8r generated files here. ## any edger8r generated files here.
CLEANFILES = $(COMMON_ENCLAVE_SRC) secure_enclave.edl \ CLEANFILES = $(COMMON_ENCLAVE_SRC) secure_enclave.edl secure_enclave.signed.so
secure_enclave.signed.so
## The build target ## The build target
...@@ -67,7 +66,7 @@ bin_PROGRAMS = sgxwallet testw cert_util ...@@ -67,7 +66,7 @@ bin_PROGRAMS = sgxwallet testw cert_util
## have to be explicitly listed. ## have to be explicitly listed.
COMMON_SRC = InvalidStateException.cpp Exception.cpp InvalidArgumentException.cpp Log.cpp \ COMMON_SRC = InvalidStateException.cpp Exception.cpp InvalidArgumentException.cpp Log.cpp \
SGXWalletServer.cpp SGXRegistrationServer.cpp CSRManagerServer.cpp RPCException.cpp BLSCrypto.cpp \ SGXWalletServer.cpp SGXRegistrationServer.cpp CSRManagerServer.cpp BLSCrypto.cpp \
ECDSACrypto.cpp \ ECDSACrypto.cpp \
DKGCrypto.cpp ServerInit.cpp BLSPrivateKeyShareSGX.cpp LevelDB.cpp ServerDataChecker.cpp SEKManager.cpp \ DKGCrypto.cpp ServerInit.cpp BLSPrivateKeyShareSGX.cpp LevelDB.cpp ServerDataChecker.cpp SEKManager.cpp \
third_party/intel/sgx_stub.c third_party/intel/sgx_detect_linux.c third_party/intel/create_enclave.c third_party/intel/oc_alloc.c \ third_party/intel/sgx_stub.c third_party/intel/sgx_detect_linux.c third_party/intel/create_enclave.c third_party/intel/oc_alloc.c \
...@@ -113,7 +112,7 @@ nodist_testw_SOURCES=${nodist_sgxwallet_SOURCES} ...@@ -113,7 +112,7 @@ nodist_testw_SOURCES=${nodist_sgxwallet_SOURCES}
EXTRA_testw_DEPENDENCIES=${EXTRA_sgxwallet_DEPENDENCIES} EXTRA_testw_DEPENDENCIES=${EXTRA_sgxwallet_DEPENDENCIES}
testw_LDADD= ${sgxwallet_LDADD} testw_LDADD= ${sgxwallet_LDADD}
cert_util_SOURCES= InvalidStateException.cpp Exception.cpp InvalidArgumentException.cpp Log.cpp cert_util.cpp stubclient.cpp RPCException.cpp LevelDB.cpp SGXRegistrationServer.cpp CSRManagerServer.cpp cert_util_SOURCES= InvalidStateException.cpp Exception.cpp InvalidArgumentException.cpp Log.cpp cert_util.cpp stubclient.cpp LevelDB.cpp SGXRegistrationServer.cpp CSRManagerServer.cpp
cert_util_LDADD=-LlibBLS/deps/deps_inst/x86_or_x64/lib -Lleveldb/build -LlibBLS/build \ cert_util_LDADD=-LlibBLS/deps/deps_inst/x86_or_x64/lib -Lleveldb/build -LlibBLS/build \
-LlibBLS/build/libff/libff \ -LlibBLS/build/libff/libff \
-l:libbls.a -l:libleveldb.a \ -l:libbls.a -l:libleveldb.a \
......
/*
Copyright (C) 2019-Present SKALE Labs
This file is part of sgxwallet.
sgxwallet is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
sgxwallet is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with sgxwallet. If not, see <https://www.gnu.org/licenses/>.
@file RPCException.cpp
@author Stan Kladko
@date 2019
*/
#include "SGXException.h"
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#ifndef SGXD_RPCEXCEPTION_H #ifndef SGXD_RPCEXCEPTION_H
#define SGXD_RPCEXCEPTION_H #define SGXD_RPCEXCEPTION_H
#include <string> #include <string>
#include <exception> #include <exception>
...@@ -39,5 +38,4 @@ public: ...@@ -39,5 +38,4 @@ public:
}; };
#endif //SGXD_RPCEXCEPTION_H #endif //SGXD_RPCEXCEPTION_H
...@@ -236,7 +236,7 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin ...@@ -236,7 +236,7 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin
exception_ptr p = current_exception(); exception_ptr p = current_exception();
printf("Exception %s \n", p.__cxa_exception_type()->name()); printf("Exception %s \n", p.__cxa_exception_type()->name());
result["status"] = -1; result["status"] = -1;
result["errorMessage"] = "Read key share has thrown exception:"; result["errorMessage"] = "Read key share has thrown exception";
return result; return result;
} }
...@@ -252,10 +252,10 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin ...@@ -252,10 +252,10 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin
return result; return result;
} }
auto it = std::find(signature.begin(), signature.end(), '\0'); auto it = signature.find('\0');
result["status"] = 0; result["status"] = 0;
result["errorMessage"] = ""; result["errorMessage"] = "";
result["signatureShare"] = std::string(signature.begin(), it); result["signatureShare"] = std::string(signature.begin(), signature.begin() + it);
return result; return result;
} }
...@@ -332,16 +332,16 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_ ...@@ -332,16 +332,16 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_
result["signature_r"] = ""; result["signature_r"] = "";
result["signature_s"] = ""; result["signature_s"] = "";
vector <string> signatureVector(3); vector<string> signatureVector(3);
try { try {
string hashTmp = _messageHash; string hashTmp = _messageHash;
if (hashTmp[0] == '0' && (hashTmp[1] == 'x' || hashTmp[1] == 'X')) { if (hashTmp[0] == '0' && (hashTmp[1] == 'x' || hashTmp[1] == 'X')) {
hashTmp.erase(hashTmp.begin(), hashTmp.begin() + 2); hashTmp.erase(hashTmp.begin(), hashTmp.begin() + 2);
} }
while (hashTmp[0] == '0') { // while (hashTmp[0] == '0') {
hashTmp.erase(hashTmp.begin(), hashTmp.begin() + 1); // hashTmp.erase(hashTmp.begin(), hashTmp.begin() + 1);
} // }
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");
...@@ -353,9 +353,9 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_ ...@@ -353,9 +353,9 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_
throw SGXException(-22, "Invalid base"); throw SGXException(-22, "Invalid base");
} }
shared_ptr <string> encryptedKey = readFromDb(_keyName, ""); shared_ptr<string> encryptedKey = readFromDb(_keyName);
signatureVector = ecdsaSignHash(encryptedKey->c_str(), hashTmp.c_str(), _base); signatureVector = ecdsaSignHash(*encryptedKey, hashTmp.c_str(), _base);
if (signatureVector.size() != 3) { if (signatureVector.size() != 3) {
throw SGXException(INVALID_ECSDA_SIGNATURE, "Invalid ecdsa signature"); throw SGXException(INVALID_ECSDA_SIGNATURE, "Invalid ecdsa signature");
} }
...@@ -546,11 +546,11 @@ SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string ...@@ -546,11 +546,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) {
...@@ -579,11 +579,11 @@ Json::Value SGXWalletServer::getBLSPublicKeyShareImpl(const string &_blsKeyName) ...@@ -579,11 +579,11 @@ Json::Value SGXWalletServer::getBLSPublicKeyShareImpl(const string &_blsKeyName)
if (!checkName(_blsKeyName, "BLS_KEY")) { if (!checkName(_blsKeyName, "BLS_KEY")) {
throw SGXException(INVALID_BLS_NAME, "Invalid BLSKey name"); throw SGXException(INVALID_BLS_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);
} }
...@@ -776,17 +776,9 @@ void SGXWalletServer::writeKeyShare(const string &_keyShareName, const string &_ ...@@ -776,17 +776,9 @@ void SGXWalletServer::writeKeyShare(const string &_keyShareName, const string &_
LevelDB::getLevelDb()->writeString(_keyShareName, _value); LevelDB::getLevelDb()->writeString(_keyShareName, _value);
} }
void SGXWalletServer::writeDataToDB(const string &Name, const string &value) { void SGXWalletServer::writeDataToDB(const string &key, const string &value) {
Json::Value val; if (LevelDB::getLevelDb()->readString(key) != nullptr) {
Json::FastWriter writer; spdlog::info("name {}", key, " already exists");
val["value"] = value;
writer.write(val);
auto key = Name;
if (LevelDB::getLevelDb()->readString(Name) != nullptr) {
spdlog::info("name {}", Name, " already exists");
throw SGXException(KEY_SHARE_ALREADY_EXISTS, "Key share already exists"); throw SGXException(KEY_SHARE_ALREADY_EXISTS, "Key share already exists");
} }
......
...@@ -79,7 +79,7 @@ bool checkHex(const string& hex, const uint32_t sizeInBytes){ ...@@ -79,7 +79,7 @@ bool checkHex(const string& hex, const uint32_t sizeInBytes){
mpz_t num; mpz_t num;
mpz_init(num); mpz_init(num);
if ( mpz_set_str(num, hex.c_str(), 16) == -1){ if (mpz_set_str(num, hex.c_str(), 16) == -1) {
spdlog::error("key is not hex {}", hex); spdlog::error("key is not hex {}", hex);
mpz_clear(num); mpz_clear(num);
return false; return false;
...@@ -128,9 +128,9 @@ bool checkName (const string& Name, const string& prefix){ ...@@ -128,9 +128,9 @@ bool checkName (const string& Name, const string& prefix){
mpz_t num; mpz_t num;
mpz_init(num); mpz_init(num);
if ( mpz_set_str(num, parts.at(2).c_str(), 10) == -1){ if ( mpz_set_str(num, parts.at(2).c_str(), 10) == -1) {
mpz_clear(num); mpz_clear(num);
spdlog::info("parts.at(2) not num"); spdlog::info("parts.at(2) is not decimal number");
return false; return false;
} }
mpz_clear(num); mpz_clear(num);
...@@ -138,7 +138,7 @@ bool checkName (const string& Name, const string& prefix){ ...@@ -138,7 +138,7 @@ bool checkName (const string& Name, const string& prefix){
if ( mpz_set_str(num, parts.at(4).c_str(), 10) == -1){ if ( mpz_set_str(num, parts.at(4).c_str(), 10) == -1){
mpz_clear(num); mpz_clear(num);
spdlog::info("parts.at(4) not num"); spdlog::info("parts.at(4) is not decimal number");
return false; return false;
} }
mpz_clear(num); mpz_clear(num);
...@@ -146,7 +146,7 @@ bool checkName (const string& Name, const string& prefix){ ...@@ -146,7 +146,7 @@ bool checkName (const string& Name, const string& prefix){
if ( mpz_set_str(num, parts.at(6).c_str(),10) == -1){ if ( mpz_set_str(num, parts.at(6).c_str(),10) == -1){
mpz_clear(num); mpz_clear(num);
spdlog::info("parts.at(6) not num"); spdlog::info("parts.at(6) is not decimal number");
return false; return false;
} }
mpz_clear(num); mpz_clear(num);
......
1.56.0 1.56.0
\ No newline at end of file
...@@ -32,13 +32,10 @@ using namespace std; ...@@ -32,13 +32,10 @@ using namespace std;
#include <map> #include <map>
#include <memory> #include <memory>
#include <gmp.h> #include <gmp.h>
#include "secure_enclave/Verify.h" #include "secure_enclave/Verify.h"
#include "InvalidStateException.h" #include "InvalidStateException.h"
#define SAFE_FREE(__POINTER__) {if (__POINTER__) {free(__POINTER__); __POINTER__ = NULL;}} #define SAFE_FREE(__POINTER__) {if (__POINTER__) {free(__POINTER__); __POINTER__ = NULL;}}
inline std::string className(const std::string &prettyFunction) { inline std::string className(const std::string &prettyFunction) {
...@@ -51,12 +48,11 @@ inline std::string className(const std::string &prettyFunction) { ...@@ -51,12 +48,11 @@ inline std::string className(const std::string &prettyFunction) {
return prettyFunction.substr(begin, end); return prettyFunction.substr(begin, end);
} }
#define __CLASS_NAME__ className( __PRETTY_FUNCTION__ ) #define __CLASS_NAME__ className( __PRETTY_FUNCTION__ )
#define CHECK_STATE(_EXPRESSION_) \ #define CHECK_STATE(_EXPRESSION_) \
if (!(_EXPRESSION_)) { \ if (!(_EXPRESSION_)) { \
auto __msg__ = string("State check failed::") + #_EXPRESSION_ + " " + string(__FILE__) + ":" + to_string(__LINE__); \ auto __msg__ = std::string("State check failed::") + #_EXPRESSION_ + " " + std::string(__FILE__) + ":" + std::to_string(__LINE__); \
throw InvalidStateException(__msg__, __CLASS_NAME__);} throw InvalidStateException(__msg__, __CLASS_NAME__);}
......
Subproject commit 78ea56c3b5251e9d840ef65705bb2c5f8f193662 Subproject commit 6c863ecc15eb5580e469f6b7f59817fdd08da1d1
Subproject commit 95eaa6f6693cd86c35e10a22b4f8e483373c987c Subproject commit b0a445ba09e96e1d0507487e5c496485a9cf3742
...@@ -188,7 +188,7 @@ bool enclave_sign(const char *_keyString, const char *_hashXString, const char * ...@@ -188,7 +188,7 @@ bool enclave_sign(const char *_keyString, const char *_hashXString, const char *
} }
void carray2Hex(const unsigned char *d, int _len, char *_hexArray) { void carray2Hex(const unsigned char *d, int _len, char* _hexArray) {
char hexval[16] = {'0', '1', '2', '3', '4', '5', '6', '7', char hexval[16] = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
......
...@@ -48,8 +48,6 @@ EXTERNC bool hex2carray2(const char * _hex, uint64_t *_bin_len, ...@@ -48,8 +48,6 @@ EXTERNC bool hex2carray2(const char * _hex, uint64_t *_bin_len,
uint8_t* _bin, const int _max_length ); uint8_t* _bin, const int _max_length );
EXTERNC void enclave_init(); EXTERNC void enclave_init();
void get_global_random(unsigned char* _randBuff, uint64_t size); void get_global_random(unsigned char* _randBuff, uint64_t size);
EXTERNC uint8_t* getThreadLocalDecryptedDkgPoly(); EXTERNC uint8_t* getThreadLocalDecryptedDkgPoly();
......
...@@ -459,7 +459,7 @@ void trustedEncryptKey(int *errStatus, char *errString, const char *key, ...@@ -459,7 +459,7 @@ void trustedEncryptKey(int *errStatus, char *errString, const char *key,
uint64_t decryptedKeyLen = strnlen(decryptedKey, MAX_KEY_LENGTH); uint64_t decryptedKeyLen = strnlen(decryptedKey, MAX_KEY_LENGTH);
if (decryptedKeyLen == MAX_KEY_LENGTH) { if (decryptedKeyLen == MAX_KEY_LENGTH) {
snprintf(errString, BUF_LEN, "Decrypted key is not null terminated"); snprintf(errString, BUF_LEN, "Decrypted key is not null terminated");
LOG_ERROR(errString); LOG_ERROR(errString);
goto clean; goto clean;
...@@ -1116,15 +1116,11 @@ void trustedSetSEK_backup(int *errStatus, char *errString, ...@@ -1116,15 +1116,11 @@ void trustedSetSEK_backup(int *errStatus, char *errString,
snprintf(errString, BUF_LEN, "seal SEK failed with status %d", status); snprintf(errString, BUF_LEN, "seal SEK failed with status %d", status);
*errStatus = status; *errStatus = status;
LOG_ERROR(errString); LOG_ERROR(errString);
goto clean;
} }
*enc_len = sealedLen; *enc_len = sealedLen;
*errStatus = 0; *errStatus = 0;
clean:
;
} }
void trustedGenerateEcdsaKeyAES(int *errStatus, char *errString, void trustedGenerateEcdsaKeyAES(int *errStatus, char *errString,
...@@ -1291,9 +1287,8 @@ void trustedGetPublicEcdsaKeyAES(int *errStatus, char *errString, ...@@ -1291,9 +1287,8 @@ void trustedGetPublicEcdsaKeyAES(int *errStatus, char *errString,
static uint64_t sigCounter = 0; static uint64_t sigCounter = 0;
void trustedEcdsaSignAES(int *errStatus, char *errString, uint8_t *encryptedPrivateKey, uint32_t enc_len, void trustedEcdsaSignAES(int *errStatus, char *errString, uint8_t *encryptedPrivateKey, uint32_t enc_len,
unsigned char *hash, char *sigR, char *sigS, uint8_t *sig_v, int base) { const char *hash, char *sigR, char *sigS, uint8_t *sig_v, int base) {
LOG_DEBUG(__FUNCTION__); LOG_DEBUG(__FUNCTION__);
*errString = 0; *errString = 0;
......
...@@ -187,7 +187,7 @@ enclave { ...@@ -187,7 +187,7 @@ enclave {
[out, count = SMALL_BUF_SIZE] char* err_string, [out, count = SMALL_BUF_SIZE] char* err_string,
[in, count = SMALL_BUF_SIZE] uint8_t* encrypted_key, [in, count = SMALL_BUF_SIZE] uint8_t* encrypted_key,
uint32_t enc_len, uint32_t enc_len,
[in, string] unsigned char* hash, [in, string] const char* hash,
[out, count = SMALL_BUF_SIZE] char* sig_r, [out, count = SMALL_BUF_SIZE] char* sig_r,
[out, count = SMALL_BUF_SIZE] char* sig_s, [out, count = SMALL_BUF_SIZE] char* sig_s,
[out] uint8_t* sig_v, [out] uint8_t* sig_v,
......
...@@ -84,7 +84,7 @@ public: ...@@ -84,7 +84,7 @@ public:
TestFixtureHTTPS() { TestFixtureHTTPS() {
TestUtils::resetDB(); TestUtils::resetDB();
setOptions(L_INFO, true, true); setOptions(L_INFO, true, true);
initAll(0, false, true); initAll(L_INFO, false, true);
} }
~TestFixtureHTTPS() { ~TestFixtureHTTPS() {
...@@ -146,7 +146,7 @@ TEST_CASE_METHOD(TestFixture, "ECDSA AES keygen and signature test", "[ecdsa-aes ...@@ -146,7 +146,7 @@ TEST_CASE_METHOD(TestFixture, "ECDSA AES keygen and signature test", "[ecdsa-aes
for (int i=0; i < 50; i++) { for (int i=0; i < 50; i++) {
status = trustedEcdsaSignAES(eid, &errStatus, errMsg.data(), encrPrivKey.data(), encLen, status = trustedEcdsaSignAES(eid, &errStatus, errMsg.data(), encrPrivKey.data(), encLen,
(unsigned char *) hex.data(), hex.data(),
signatureR.data(), signatureR.data(),
signatureS.data(), &signatureV, 16); signatureS.data(), &signatureV, 16);
} }
...@@ -889,7 +889,7 @@ TEST_CASE_METHOD(TestFixture, "AES == NOT AES", "[aes-not-aes]") { ...@@ -889,7 +889,7 @@ TEST_CASE_METHOD(TestFixture, "AES == NOT AES", "[aes-not-aes]") {
uint8_t signatureVAES = 0; uint8_t signatureVAES = 0;
status = trustedEcdsaSignAES(eid, &errStatusAES, errMsgAES.data(), encrPrivKeyAES.data(), enc_lenAES, status = trustedEcdsaSignAES(eid, &errStatusAES, errMsgAES.data(), encrPrivKeyAES.data(), enc_lenAES,
(unsigned char *) hex.data(), hex.data(),
signatureRAES.data(), signatureRAES.data(),
signatureSAES.data(), &signatureVAES, 16); signatureSAES.data(), &signatureVAES, 16);
REQUIRE(status == SGX_SUCCESS); REQUIRE(status == SGX_SUCCESS);
......
...@@ -35,15 +35,12 @@ ...@@ -35,15 +35,12 @@
#define RPC_ENDPOINT "http://localhost:1029" #define RPC_ENDPOINT "http://localhost:1029"
#define SAMPLE_PUBLIC_KEY_B "c0152c48bf640449236036075d65898fded1e242c00acb45519ad5f788ea7cbf9a5df1559e7fc87932eee5478b1b9023de19df654395574a690843988c3ff475" #define SAMPLE_PUBLIC_KEY_B "c0152c48bf640449236036075d65898fded1e242c00acb45519ad5f788ea7cbf9a5df1559e7fc87932eee5478b1b9023de19df654395574a690843988c3ff475"
#define SAMPLE_DKG_PUB_KEY_1 "505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e2" #define SAMPLE_DKG_PUB_KEY_1 "505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e2"
#define SAMPLE_DKG_PUB_KEY_2 "378b3e6fdfe2633256ae1662fcd23466d02ead907b5d4366136341cea5e46f5a7bb67d897d6e35f619810238aa143c416f61c640ed214eb9c67a34c4a31b7d25" #define SAMPLE_DKG_PUB_KEY_2 "378b3e6fdfe2633256ae1662fcd23466d02ead907b5d4366136341cea5e46f5a7bb67d897d6e35f619810238aa143c416f61c640ed214eb9c67a34c4a31b7d25"
//openssl req -new -newkey rsa:2048 -nodes -keyout yourdomain.key -out yourdomain.csr^ //openssl req -new -newkey rsa:2048 -nodes -keyout yourdomain.key -out yourdomain.csr^
#define SAMPLE_CSR_FILE_NAME "samples/yourdomain.csr" #define SAMPLE_CSR_FILE_NAME "samples/yourdomain.csr"
#define ECDSA_KEY_NAME_SIZE 68 #define ECDSA_KEY_NAME_SIZE 68
#endif //SGXWALLET_TESTW_H #endif //SGXWALLET_TESTW_H
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