Unverified Commit f0f043ad authored by kladko's avatar kladko

Fix test

parent c2dd35d5
...@@ -306,7 +306,7 @@ bool sign_aes(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, siz ...@@ -306,7 +306,7 @@ bool sign_aes(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, siz
bool bls_sign(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, size_t _n, size_t _signerIndex, bool bls_sign(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, size_t _n, size_t _signerIndex,
char* _sig) { char* _sig) {
if (!is_aes){ if (!encryptKeys){
return sign(_encryptedKeyHex, _hashHex, _t, _n, _signerIndex, _sig); return sign(_encryptedKeyHex, _hashHex, _t, _n, _signerIndex, _sig);
} }
else{ else{
...@@ -326,7 +326,7 @@ char* encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key) ...@@ -326,7 +326,7 @@ char* encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key)
//status = encrypt_key(eid, errStatus, errMsg, keyArray, encryptedKey, &encryptedLen); //status = encrypt_key(eid, errStatus, errMsg, keyArray, encryptedKey, &encryptedLen);
status = encrypt_key_aes(eid, errStatus, errMsg->data(), keyArray->data(), encryptedKey->data(), &encryptedLen); status = encrypt_key_aes(eid, errStatus, errMsg->data(), keyArray->data(), encryptedKey->data(), &encryptedLen);
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("errStatus is {}",*errStatus); spdlog::info("errStatus is {}",*errStatus);
spdlog::info(" errMsg is ", errMsg->data() ); spdlog::info(" errMsg is ", errMsg->data() );
} }
......
...@@ -83,7 +83,7 @@ string gen_dkg_poly( int _t){ ...@@ -83,7 +83,7 @@ string gen_dkg_poly( int _t){
uint32_t enc_len = 0; uint32_t enc_len = 0;
if (!is_aes) if (!encryptKeys)
status = gen_dkg_secret (eid, &err_status, errMsg.data(), encrypted_dkg_secret.data(), &enc_len, _t); status = gen_dkg_secret (eid, &err_status, errMsg.data(), encrypted_dkg_secret.data(), &enc_len, _t);
else else
status = gen_dkg_secret_aes (eid, &err_status, errMsg.data(), encrypted_dkg_secret.data(), &enc_len, _t); status = gen_dkg_secret_aes (eid, &err_status, errMsg.data(), encrypted_dkg_secret.data(), &enc_len, _t);
...@@ -91,13 +91,13 @@ string gen_dkg_poly( int _t){ ...@@ -91,13 +91,13 @@ string gen_dkg_poly( int _t){
throw RPCException(-666, errMsg.data() ) ; throw RPCException(-666, errMsg.data() ) ;
} }
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("gen_dkg_secret, status {}", err_status, " err msg ", errMsg.data()); spdlog::info("gen_dkg_secret, status {}", err_status, " err msg ", errMsg.data());
spdlog::info("in DKGCrypto encr len is {}", enc_len); spdlog::info("in DKGCrypto encr len is {}", enc_len);
} }
uint64_t length = DKG_MAX_SEALED_LEN; uint64_t length = DKG_MAX_SEALED_LEN;
if (is_aes){ if (encryptKeys){
length = enc_len; length = enc_len;
} }
...@@ -118,7 +118,7 @@ vector <vector<string>> get_verif_vect(const char* encryptedPolyHex, int t, int ...@@ -118,7 +118,7 @@ vector <vector<string>> get_verif_vect(const char* encryptedPolyHex, int t, int
//char errMsg1[BUF_LEN]; //char errMsg1[BUF_LEN];
int err_status = 0; int err_status = 0;
if (DEBUG_PRINT) { if (printDebugInfo) {
// cerr << "got encr poly " << encryptedPolyHex << endl; // cerr << "got encr poly " << encryptedPolyHex << endl;
spdlog::info("got encr poly size {}", char_traits<char>::length(encryptedPolyHex)); spdlog::info("got encr poly size {}", char_traits<char>::length(encryptedPolyHex));
} }
...@@ -137,7 +137,7 @@ vector <vector<string>> get_verif_vect(const char* encryptedPolyHex, int t, int ...@@ -137,7 +137,7 @@ vector <vector<string>> get_verif_vect(const char* encryptedPolyHex, int t, int
throw RPCException(INVALID_HEX, "Invalid encryptedPolyHex"); throw RPCException(INVALID_HEX, "Invalid encryptedPolyHex");
} }
if (DEBUG_PRINT) { if (printDebugInfo) {
//cerr << "hex_encr_poly is " << encryptedPolyHex << std::endl; //cerr << "hex_encr_poly is " << encryptedPolyHex << std::endl;
spdlog::info("hex_encr_poly length is {}", strlen(encryptedPolyHex)); spdlog::info("hex_encr_poly length is {}", strlen(encryptedPolyHex));
spdlog::info("enc len {}", enc_len); spdlog::info("enc len {}", enc_len);
...@@ -148,7 +148,7 @@ vector <vector<string>> get_verif_vect(const char* encryptedPolyHex, int t, int ...@@ -148,7 +148,7 @@ vector <vector<string>> get_verif_vect(const char* encryptedPolyHex, int t, int
uint32_t len = 0; uint32_t len = 0;
if (!is_aes) if (!encryptKeys)
status = get_public_shares(eid, &err_status, errMsg1, encr_dkg_poly, len, public_shares, t, n); status = get_public_shares(eid, &err_status, errMsg1, encr_dkg_poly, len, public_shares, t, n);
else { else {
...@@ -158,7 +158,7 @@ vector <vector<string>> get_verif_vect(const char* encryptedPolyHex, int t, int ...@@ -158,7 +158,7 @@ vector <vector<string>> get_verif_vect(const char* encryptedPolyHex, int t, int
throw RPCException(-666, errMsg1 ); throw RPCException(-666, errMsg1 );
} }
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("err msg is {}", errMsg1); spdlog::info("err msg is {}", errMsg1);
spdlog::info("public_shares:"); spdlog::info("public_shares:");
...@@ -200,7 +200,7 @@ string get_secret_shares(const string& polyName, const char* encryptedPolyHex, c ...@@ -200,7 +200,7 @@ string get_secret_shares(const string& polyName, const char* encryptedPolyHex, c
std::cerr << "enc_len is " << enc_len << std::endl; std::cerr << "enc_len is " << enc_len << std::endl;
if (!is_aes) if (!encryptKeys)
status = set_encrypted_dkg_poly(eid, &err_status, errMsg1, encr_dkg_poly); status = set_encrypted_dkg_poly(eid, &err_status, errMsg1, encr_dkg_poly);
else else
status = set_encrypted_dkg_poly_aes(eid, &err_status, errMsg1, encr_dkg_poly, &enc_len); status = set_encrypted_dkg_poly_aes(eid, &err_status, errMsg1, encr_dkg_poly, &enc_len);
...@@ -226,11 +226,11 @@ string get_secret_shares(const string& polyName, const char* encryptedPolyHex, c ...@@ -226,11 +226,11 @@ string get_secret_shares(const string& polyName, const char* encryptedPolyHex, c
char pubKeyB[129]; char pubKeyB[129];
strncpy(pubKeyB, pub_keyB.c_str(), 128); strncpy(pubKeyB, pub_keyB.c_str(), 128);
pubKeyB[128] = 0; pubKeyB[128] = 0;
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("pubKeyB is {}", pub_keyB); spdlog::info("pubKeyB is {}", pub_keyB);
} }
if (!is_aes) if (!encryptKeys)
get_encr_sshare(eid, &err_status, errMsg1, encrypted_skey, &dec_len, get_encr_sshare(eid, &err_status, errMsg1, encrypted_skey, &dec_len,
cur_share, s_shareG2, pubKeyB, t, n, i + 1 ); cur_share, s_shareG2, pubKeyB, t, n, i + 1 );
else else
...@@ -239,14 +239,14 @@ string get_secret_shares(const string& polyName, const char* encryptedPolyHex, c ...@@ -239,14 +239,14 @@ string get_secret_shares(const string& polyName, const char* encryptedPolyHex, c
if (err_status != 0){ if (err_status != 0){
throw RPCException(-666, errMsg1); throw RPCException(-666, errMsg1);
} }
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("cur_share is {}", cur_share); spdlog::info("cur_share is {}", cur_share);
} }
result += cur_share; result += cur_share;
//uint32_t enc_len = BUF_LEN; //uint32_t enc_len = BUF_LEN;
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("dec len is {}", dec_len); spdlog::info("dec len is {}", dec_len);
} }
...@@ -257,17 +257,17 @@ string get_secret_shares(const string& polyName, const char* encryptedPolyHex, c ...@@ -257,17 +257,17 @@ string get_secret_shares(const string& polyName, const char* encryptedPolyHex, c
string DHKey_name = "DKG_DH_KEY_" + polyName + "_" + to_string(i) + ":"; string DHKey_name = "DKG_DH_KEY_" + polyName + "_" + to_string(i) + ":";
cerr << "hexEncr DH Key: " << hexEncrKey << endl; cerr << "hexEncr DH Key: " << hexEncrKey << endl;
writeDataToDB(DHKey_name, hexEncrKey); SGXWalletServer::writeDataToDB(DHKey_name, hexEncrKey);
string shareG2_name = "shareG2_" + polyName + "_" + to_string(i) + ":"; string shareG2_name = "shareG2_" + polyName + "_" + to_string(i) + ":";
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("name to write to db is {}", DHKey_name); spdlog::info("name to write to db is {}", DHKey_name);
spdlog::info("name to write to db is {}", shareG2_name); spdlog::info("name to write to db is {}", shareG2_name);
spdlog::info("s_shareG2: {}", s_shareG2); spdlog::info("s_shareG2: {}", s_shareG2);
} }
writeDataToDB(shareG2_name, s_shareG2); SGXWalletServer::writeDataToDB(shareG2_name, s_shareG2);
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("errMsg: {}", errMsg1); spdlog::info("errMsg: {}", errMsg1);
// cerr << "iteration " << i <<" result length is " << result.length() << endl ; // cerr << "iteration " << i <<" result length is " << result.length() << endl ;
// cerr << "iteration " << i <<" share length is " << strlen(cur_share) << endl; // cerr << "iteration " << i <<" share length is " << strlen(cur_share) << endl;
...@@ -295,7 +295,7 @@ bool VerifyShares(const char* publicShares, const char* encr_sshare, const char ...@@ -295,7 +295,7 @@ bool VerifyShares(const char* publicShares, const char* encr_sshare, const char
throw RPCException(INVALID_HEX, "Invalid encryptedPolyHex"); throw RPCException(INVALID_HEX, "Invalid encryptedPolyHex");
} }
int result; int result;
if (DEBUG_PRINT) { if (printDebugInfo) {
cerr << "encryptedKeyHex " << encryptedKeyHex << endl; cerr << "encryptedKeyHex " << encryptedKeyHex << endl;
cerr << "dec_key_len " << dec_key_len << endl; cerr << "dec_key_len " << dec_key_len << endl;
cerr << "encr_sshare length is " << strlen(encr_sshare) << endl; cerr << "encr_sshare length is " << strlen(encr_sshare) << endl;
...@@ -307,7 +307,7 @@ bool VerifyShares(const char* publicShares, const char* encr_sshare, const char ...@@ -307,7 +307,7 @@ bool VerifyShares(const char* publicShares, const char* encr_sshare, const char
strncpy(pshares, publicShares, strlen(publicShares) ); strncpy(pshares, publicShares, strlen(publicShares) );
if (!is_aes) if (!encryptKeys)
dkg_verification(eid, &err_status, errMsg1, pshares, encr_sshare, encr_key, dec_key_len, t, ind, &result); dkg_verification(eid, &err_status, errMsg1, pshares, encr_sshare, encr_key, dec_key_len, t, ind, &result);
else else
dkg_verification_aes(eid, &err_status, errMsg1, pshares, encr_sshare, encr_key, dec_key_len, t, ind, &result); dkg_verification_aes(eid, &err_status, errMsg1, pshares, encr_sshare, encr_key, dec_key_len, t, ind, &result);
...@@ -316,7 +316,7 @@ bool VerifyShares(const char* publicShares, const char* encr_sshare, const char ...@@ -316,7 +316,7 @@ bool VerifyShares(const char* publicShares, const char* encr_sshare, const char
throw RPCException(INVALID_HEX, "Invalid public shares"); throw RPCException(INVALID_HEX, "Invalid public shares");
} }
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("errMsg1: {}", errMsg1); spdlog::info("errMsg1: {}", errMsg1);
spdlog::info("result is: {}", result); spdlog::info("result is: {}", result);
} }
...@@ -327,7 +327,7 @@ bool VerifyShares(const char* publicShares, const char* encr_sshare, const char ...@@ -327,7 +327,7 @@ bool VerifyShares(const char* publicShares, const char* encr_sshare, const char
} }
bool CreateBLSShare( const string& blsKeyName, const char * s_shares, const char * encryptedKeyHex){ bool CreateBLSShare( const string& blsKeyName, const char * s_shares, const char * encryptedKeyHex){
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("ENTER CreateBLSShare"); spdlog::info("ENTER CreateBLSShare");
} }
// char* errMsg1 = (char*) calloc(1024,1); // char* errMsg1 = (char*) calloc(1024,1);
...@@ -346,7 +346,7 @@ bool CreateBLSShare( const string& blsKeyName, const char * s_shares, const char ...@@ -346,7 +346,7 @@ bool CreateBLSShare( const string& blsKeyName, const char * s_shares, const char
uint32_t enc_bls_len = 0; uint32_t enc_bls_len = 0;
//cerr << "BEFORE create_bls_key IN ENCLAVE " << endl; //cerr << "BEFORE create_bls_key IN ENCLAVE " << endl;
if (!is_aes) if (!encryptKeys)
create_bls_key(eid, &err_status, errMsg1, s_shares, encr_key, dec_key_len, encr_bls_key, &enc_bls_len); create_bls_key(eid, &err_status, errMsg1, s_shares, encr_key, dec_key_len, encr_bls_key, &enc_bls_len);
else else
create_bls_key_aes(eid, &err_status, errMsg1, s_shares, encr_key, dec_key_len, encr_bls_key, &enc_bls_len); create_bls_key_aes(eid, &err_status, errMsg1, s_shares, encr_key, dec_key_len, encr_bls_key, &enc_bls_len);
...@@ -365,8 +365,8 @@ bool CreateBLSShare( const string& blsKeyName, const char * s_shares, const char ...@@ -365,8 +365,8 @@ bool CreateBLSShare( const string& blsKeyName, const char * s_shares, const char
//cerr << "enc_bls_len " << enc_bls_len << endl; //cerr << "enc_bls_len " << enc_bls_len << endl;
carray2Hex(encr_bls_key, enc_bls_len, hexBLSKey); carray2Hex(encr_bls_key, enc_bls_len, hexBLSKey);
// cerr << "BEFORE WRITE BLS KEY TO DB" << endl; // cerr << "BEFORE WRITE BLS KEY TO DB" << endl;
writeDataToDB(blsKeyName, hexBLSKey); SGXWalletServer::writeDataToDB(blsKeyName, hexBLSKey);
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("hexBLSKey length is {}", char_traits<char>::length(hexBLSKey)); spdlog::info("hexBLSKey length is {}", char_traits<char>::length(hexBLSKey));
spdlog::info("bls key {}", blsKeyName, " is ", hexBLSKey ); spdlog::info("bls key {}", blsKeyName, " is ", hexBLSKey );
} }
...@@ -389,11 +389,11 @@ vector<string> GetBLSPubKey(const char * encryptedKeyHex){ ...@@ -389,11 +389,11 @@ vector<string> GetBLSPubKey(const char * encryptedKeyHex){
} }
char pub_key[320]; char pub_key[320];
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("dec_key_len is {}", dec_key_len); spdlog::info("dec_key_len is {}", dec_key_len);
} }
if (!is_aes) if (!encryptKeys)
get_bls_pub_key(eid, &err_status, errMsg1, encr_key, dec_key_len, pub_key); get_bls_pub_key(eid, &err_status, errMsg1, encr_key, dec_key_len, pub_key);
else else
get_bls_pub_key_aes(eid, &err_status, errMsg1, encr_key, dec_key_len, pub_key); get_bls_pub_key_aes(eid, &err_status, errMsg1, encr_key, dec_key_len, pub_key);
...@@ -403,7 +403,7 @@ vector<string> GetBLSPubKey(const char * encryptedKeyHex){ ...@@ -403,7 +403,7 @@ vector<string> GetBLSPubKey(const char * encryptedKeyHex){
} }
vector<string> pub_key_vect = SplitString(pub_key, ':'); vector<string> pub_key_vect = SplitString(pub_key, ':');
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("errMsg1 is {}", errMsg1); spdlog::info("errMsg1 is {}", errMsg1);
spdlog::info("pub key is "); spdlog::info("pub key is ");
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
...@@ -418,8 +418,8 @@ string decrypt_DHKey(const string& polyName, int ind){ ...@@ -418,8 +418,8 @@ string decrypt_DHKey(const string& polyName, int ind){
int err_status = 0; int err_status = 0;
string DH_key_name = polyName + "_" + to_string(ind) + ":"; string DH_key_name = polyName + "_" + to_string(ind) + ":";
shared_ptr<string> hexEncrKey_ptr = readFromDb(DH_key_name, "DKG_DH_KEY_"); shared_ptr<string> hexEncrKey_ptr = SGXWalletServer::readFromDb(DH_key_name, "DKG_DH_KEY_");
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("encr DH key is {}", *hexEncrKey_ptr); spdlog::info("encr DH key is {}", *hexEncrKey_ptr);
} }
...@@ -430,14 +430,14 @@ string decrypt_DHKey(const string& polyName, int ind){ ...@@ -430,14 +430,14 @@ string decrypt_DHKey(const string& polyName, int ind){
if (!hex2carray(hexEncrKey_ptr->c_str(), &DH_enc_len, encrypted_DHkey)){ if (!hex2carray(hexEncrKey_ptr->c_str(), &DH_enc_len, encrypted_DHkey)){
throw RPCException(INVALID_HEX, "Invalid hexEncrKey"); throw RPCException(INVALID_HEX, "Invalid hexEncrKey");
} }
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("encr DH key length is {}", DH_enc_len); spdlog::info("encr DH key length is {}", DH_enc_len);
spdlog::info("hex encr DH key length is {}", hexEncrKey_ptr->length()); spdlog::info("hex encr DH key length is {}", hexEncrKey_ptr->length());
} }
char DHKey[ECDSA_SKEY_LEN]; char DHKey[ECDSA_SKEY_LEN];
if ( !is_aes) if ( !encryptKeys)
decrypt_key(eid, &err_status, errMsg1.data(), encrypted_DHkey, DH_enc_len, DHKey); decrypt_key(eid, &err_status, errMsg1.data(), encrypted_DHkey, DH_enc_len, DHKey);
else else
decrypt_key_aes(eid, &err_status, errMsg1.data(), encrypted_DHkey, DH_enc_len, DHKey); decrypt_key_aes(eid, &err_status, errMsg1.data(), encrypted_DHkey, DH_enc_len, DHKey);
......
...@@ -51,7 +51,7 @@ std::vector<std::string> gen_ecdsa_key(){ ...@@ -51,7 +51,7 @@ std::vector<std::string> gen_ecdsa_key(){
char *pub_key_y = (char *)calloc(1024, 1); char *pub_key_y = (char *)calloc(1024, 1);
uint32_t enc_len = 0; uint32_t enc_len = 0;
if ( !is_aes) if ( !encryptKeys)
status = generate_ecdsa_key(eid, &err_status, errMsg, encr_pr_key, &enc_len, pub_key_x, pub_key_y ); status = generate_ecdsa_key(eid, &err_status, errMsg, encr_pr_key, &enc_len, pub_key_x, pub_key_y );
else else
status = generate_ecdsa_key_aes(eid, &err_status, errMsg, encr_pr_key, &enc_len, pub_key_x, pub_key_y ); status = generate_ecdsa_key_aes(eid, &err_status, errMsg, encr_pr_key, &enc_len, pub_key_x, pub_key_y );
...@@ -61,7 +61,7 @@ std::vector<std::string> gen_ecdsa_key(){ ...@@ -61,7 +61,7 @@ std::vector<std::string> gen_ecdsa_key(){
throw RPCException(status, errMsg) ; throw RPCException(status, errMsg) ;
} }
std::vector<std::string> keys(3); std::vector<std::string> keys(3);
if (DEBUG_PRINT) { if (printDebugInfo) {
std::cerr << "account key is " << errMsg << std::endl; std::cerr << "account key is " << errMsg << std::endl;
std::cerr << "enc_len is " << enc_len << std::endl; std::cerr << "enc_len is " << enc_len << std::endl;
// std::cerr << "enc_key is " << std::endl; // std::cerr << "enc_key is " << std::endl;
...@@ -77,7 +77,7 @@ std::vector<std::string> gen_ecdsa_key(){ ...@@ -77,7 +77,7 @@ std::vector<std::string> gen_ecdsa_key(){
unsigned long seed = rand_gen(); unsigned long seed = rand_gen();
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("seed is {}", seed); spdlog::info("seed is {}", seed);
std::cerr << "strlen is " << strlen(hexEncrKey) << std::endl; std::cerr << "strlen is " << strlen(hexEncrKey) << std::endl;
} }
...@@ -122,7 +122,7 @@ std::string get_ecdsa_pubkey(const char* encryptedKeyHex){ ...@@ -122,7 +122,7 @@ std::string get_ecdsa_pubkey(const char* encryptedKeyHex){
throw RPCException(INVALID_HEX, "Invalid encryptedKeyHex"); throw RPCException(INVALID_HEX, "Invalid encryptedKeyHex");
} }
if ( !is_aes) if ( !encryptKeys)
status = get_public_ecdsa_key(eid, &err_status, errMsg, encr_pr_key, enc_len, pub_key_x, pub_key_y ); status = get_public_ecdsa_key(eid, &err_status, errMsg, encr_pr_key, enc_len, pub_key_x, pub_key_y );
else status = get_public_ecdsa_key_aes(eid, &err_status, errMsg, encr_pr_key, enc_len, pub_key_x, pub_key_y ); else status = get_public_ecdsa_key_aes(eid, &err_status, errMsg, encr_pr_key, enc_len, pub_key_x, pub_key_y );
if (err_status != 0){ if (err_status != 0){
...@@ -130,7 +130,7 @@ std::string get_ecdsa_pubkey(const char* encryptedKeyHex){ ...@@ -130,7 +130,7 @@ std::string get_ecdsa_pubkey(const char* encryptedKeyHex){
} }
std::string pubKey = std::string(pub_key_x) + std::string(pub_key_y);//concatPubKeyWith0x(pub_key_x, pub_key_y);// std::string pubKey = std::string(pub_key_x) + std::string(pub_key_y);//concatPubKeyWith0x(pub_key_x, pub_key_y);//
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("enc_len is {}", enc_len); spdlog::info("enc_len is {}", enc_len);
spdlog::info("pubkey is {}", pubKey); spdlog::info("pubkey is {}", pubKey);
spdlog::info("pubkey length is {}", pubKey.length()); spdlog::info("pubkey length is {}", pubKey.length());
...@@ -162,20 +162,20 @@ std::vector<std::string> ecdsa_sign_hash(const char* encryptedKeyHex, const char ...@@ -162,20 +162,20 @@ std::vector<std::string> ecdsa_sign_hash(const char* encryptedKeyHex, const char
throw RPCException(INVALID_HEX, "Invalid encryptedKeyHex"); throw RPCException(INVALID_HEX, "Invalid encryptedKeyHex");
} }
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("encryptedKeyHex: {}", encryptedKeyHex); spdlog::info("encryptedKeyHex: {}", encryptedKeyHex);
spdlog::info("HASH: {}", hashHex); spdlog::info("HASH: {}", hashHex);
spdlog::info("encrypted len: {}", dec_len); spdlog::info("encrypted len: {}", dec_len);
} }
if (!is_aes) if (!encryptKeys)
status = ecdsa_sign1(eid, &err_status, errMsg, encr_key, ECDSA_ENCR_LEN, (unsigned char*)hashHex, signature_r, signature_s, &signature_v, base ); status = ecdsa_sign1(eid, &err_status, errMsg, encr_key, ECDSA_ENCR_LEN, (unsigned char*)hashHex, signature_r, signature_s, &signature_v, base );
else status = ecdsa_sign_aes(eid, &err_status, errMsg, encr_key, dec_len, (unsigned char*)hashHex, signature_r, signature_s, &signature_v, base ); else status = ecdsa_sign_aes(eid, &err_status, errMsg, encr_key, dec_len, (unsigned char*)hashHex, signature_r, signature_s, &signature_v, base );
if ( err_status != 0){ if ( err_status != 0){
throw RPCException(-666, errMsg ) ; throw RPCException(-666, errMsg ) ;
} }
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("signature r in ecdsa_sign_hash: {}", signature_r); spdlog::info("signature r in ecdsa_sign_hash: {}", signature_r);
spdlog::info("signature s in ecdsa_sign_hash: {}", signature_s); spdlog::info("signature s in ecdsa_sign_hash: {}", signature_s);
} }
......
...@@ -62,7 +62,7 @@ std::shared_ptr<string> LevelDB::readString(const string &_key) { ...@@ -62,7 +62,7 @@ std::shared_ptr<string> LevelDB::readString(const string &_key) {
auto status = db->Get(readOptions, _key, &*result); auto status = db->Get(readOptions, _key, &*result);
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("key to read from db: {}",_key ); spdlog::info("key to read from db: {}",_key );
//std::cerr << "key to read from db: " << _key << std::endl; //std::cerr << "key to read from db: " << _key << std::endl;
} }
...@@ -83,7 +83,7 @@ void LevelDB::writeString(const string &_key, const string &_value) { ...@@ -83,7 +83,7 @@ void LevelDB::writeString(const string &_key, const string &_value) {
throwExceptionOnError(status); throwExceptionOnError(status);
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("written key: {}",_key ); spdlog::info("written key: {}",_key );
// std::cerr << "written key " << _key << std::endl; // std::cerr << "written key " << _key << std::endl;
} }
...@@ -100,7 +100,7 @@ void LevelDB::deleteDHDKGKey (const string &_key) { ...@@ -100,7 +100,7 @@ void LevelDB::deleteDHDKGKey (const string &_key) {
throwExceptionOnError(status); throwExceptionOnError(status);
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("key deleted: {}",full_key ); spdlog::info("key deleted: {}",full_key );
//std::cerr << "key deleted " << full_key << std::endl; //std::cerr << "key deleted " << full_key << std::endl;
} }
...@@ -130,7 +130,7 @@ void LevelDB::deleteKey(const string &_key){ ...@@ -130,7 +130,7 @@ void LevelDB::deleteKey(const string &_key){
throwExceptionOnError(status); throwExceptionOnError(status);
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("key deleted: {}",_key ); spdlog::info("key deleted: {}",_key );
// std::cerr << "key deleted " << _key << std::endl; // std::cerr << "key deleted " << _key << std::endl;
} }
...@@ -219,7 +219,7 @@ void LevelDB::writeDataUnique(const string & Name, const string &value) { ...@@ -219,7 +219,7 @@ void LevelDB::writeDataUnique(const string & Name, const string &value) {
} }
writeString(key, value); writeString(key, value);
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("{}",Name, " is written to db"); spdlog::info("{}",Name, " is written to db");
//std::cerr << Name << " is written to db " << std::endl; //std::cerr << Name << " is written to db " << std::endl;
} }
......
...@@ -231,7 +231,7 @@ void init_SEK(){ ...@@ -231,7 +231,7 @@ void init_SEK(){
gen_SEK(); gen_SEK();
} }
else{ else{
if (DEBUG_PRINT) if (printDebugInfo)
spdlog::info("going to set SEK from db" ); spdlog::info("going to set SEK from db" );
set_SEK(encr_SEK_ptr); set_SEK(encr_SEK_ptr);
} }
......
...@@ -46,152 +46,142 @@ ...@@ -46,152 +46,142 @@
#include "spdlog/spdlog.h" #include "spdlog/spdlog.h"
#include "common.h" #include "common.h"
int DEBUG_PRINT = 0; int printDebugInfo = 0;
int is_sgx_https = 1; int useHTTPS = 1;
int is_aes = 1; int encryptKeys = 0;
bool autoconfirm = false; bool autoconfirm = false;
SGXRegistrationServer *regs = nullptr; SGXRegistrationServer *registrationServer = nullptr;
HttpServer *hs2 = nullptr; HttpServer *httpServer2 = nullptr;
bool cert_created = false;
void set_cert_created1(bool b){
sleep(10);
cert_created = b;
}
SGXRegistrationServer::SGXRegistrationServer(AbstractServerConnector &connector, SGXRegistrationServer::SGXRegistrationServer(AbstractServerConnector &connector,
serverVersion_t type, bool auto_sign) serverVersion_t type, bool _autoSign)
: AbstractRegServer(connector, type), is_cert_created(false), cert_auto_sign(auto_sign) {} : AbstractRegServer(connector, type), isCertCreated(false), autoSign(_autoSign) {}
Json::Value signCertificateImpl(const string& csr, bool auto_sign = false){ Json::Value signCertificateImpl(const string &_csr, bool _autoSign = false) {
Json::Value result; Json::Value result;
result["status"] = 0; result["status"] = 0;
result["errorMessage"] = ""; result["errorMessage"] = "";
try{ try {
spdlog::info("enter signCertificateImpl"); spdlog::info("enter signCertificateImpl");
string status = "1"; string status = "1";
string hash = cryptlite::sha256::hash_hex(csr); string hash = cryptlite::sha256::hash_hex(_csr);
if ( !auto_sign) { if (!_autoSign) {
string db_key = "CSR:HASH:" + hash; string db_key = "CSR:HASH:" + hash;
LevelDB::getCsrStatusDb()->writeDataUnique(db_key, csr); LevelDB::getCsrStatusDb()->writeDataUnique(db_key, _csr);
} }
if (auto_sign) { if (_autoSign) {
string csr_name = "cert/" + hash + ".csr"; string csr_name = "cert/" + hash + ".csr";
ofstream outfile(csr_name); ofstream outfile(csr_name);
outfile << csr << endl; outfile << _csr << endl;
outfile.close(); outfile.close();
if (access(csr_name.c_str(), F_OK) != 0) { if (access(csr_name.c_str(), F_OK) != 0) {
throw RPCException(FILE_NOT_FOUND, "Csr does not exist"); throw RPCException(FILE_NOT_FOUND, "Csr does not exist");
} }
string genCert = "cd cert && ./create_client_cert " + hash; string genCert = "cd cert && ./create_client_cert " + hash;
if (system(genCert.c_str()) == 0){ if (system(genCert.c_str()) == 0) {
spdlog::info("CLIENT CERTIFICATE IS SUCCESSFULLY GENERATED"); spdlog::info("CLIENT CERTIFICATE IS SUCCESSFULLY GENERATED");
status = "0"; status = "0";
} } else {
else{ spdlog::info("CLIENT CERTIFICATE GENERATION FAILED");
spdlog::info("CLIENT CERTIFICATE GENERATION FAILED"); string status_db_key = "CSR:HASH:" + hash + "STATUS:";
string status_db_key = "CSR:HASH:" + hash + "STATUS:"; LevelDB::getCsrStatusDb()->writeDataUnique(status_db_key, to_string(FAIL_TO_CREATE_CERTIFICATE));
LevelDB::getCsrStatusDb()->writeDataUnique(status_db_key, to_string(FAIL_TO_CREATE_CERTIFICATE)); throw RPCException(FAIL_TO_CREATE_CERTIFICATE, "CLIENT CERTIFICATE GENERATION FAILED");
throw RPCException(FAIL_TO_CREATE_CERTIFICATE, "CLIENT CERTIFICATE GENERATION FAILED"); //exit(-1);
//exit(-1); }
} }
result["result"] = true;
result["hash"] = hash;
string db_key = "CSR:HASH:" + hash + "STATUS:";
LevelDB::getCsrStatusDb()->writeDataUnique(db_key, status);
} catch (RPCException &_e) {
cerr << " err str " << _e.errString << endl;
result["status"] = _e.status;
result["errorMessage"] = _e.errString;
result["result"] = false;
} }
result["result"] = true; return result;
result["hash"] = hash;
string db_key = "CSR:HASH:" + hash + "STATUS:";
LevelDB::getCsrStatusDb()->writeDataUnique(db_key, status);
} catch (RPCException &_e) {
cerr << " err str " << _e.errString << endl;
result["status"] = _e.status;
result["errorMessage"] = _e.errString;
result["result"] = false;
}
return result;
} }
Json::Value GetSertificateImpl(const string& hash){ Json::Value GetSertificateImpl(const string &hash) {
Json::Value result; Json::Value result;
string cert; string cert;
try{ try {
string db_key = "CSR:HASH:" + hash + "STATUS:"; string db_key = "CSR:HASH:" + hash + "STATUS:";
shared_ptr<string> status_str_ptr = LevelDB::getCsrStatusDb()->readString(db_key); shared_ptr<string> status_str_ptr = LevelDB::getCsrStatusDb()->readString(db_key);
if (status_str_ptr == nullptr){ if (status_str_ptr == nullptr) {
throw RPCException(KEY_SHARE_DOES_NOT_EXIST, "Data with this name does not exist in csr db"); throw RPCException(KEY_SHARE_DOES_NOT_EXIST, "Data with this name does not exist in csr db");
} }
int status = atoi(status_str_ptr->c_str()); int status = atoi(status_str_ptr->c_str());
if ( status == 0){ if (status == 0) {
string crt_name = "cert/" + hash + ".crt"; string crt_name = "cert/" + hash + ".crt";
//if (access(crt_name.c_str(), F_OK) == 0){ //if (access(crt_name.c_str(), F_OK) == 0){
ifstream infile(crt_name); ifstream infile(crt_name);
if (!infile.is_open()) { if (!infile.is_open()) {
string status_db_key = "CSR:HASH:" + hash + "STATUS:"; string status_db_key = "CSR:HASH:" + hash + "STATUS:";
LevelDB::getCsrStatusDb()->deleteKey(status_db_key); LevelDB::getCsrStatusDb()->deleteKey(status_db_key);
LevelDB::getCsrStatusDb()->writeDataUnique(status_db_key, to_string(FILE_NOT_FOUND)); LevelDB::getCsrStatusDb()->writeDataUnique(status_db_key, to_string(FILE_NOT_FOUND));
throw RPCException(FILE_NOT_FOUND, "Certificate does not exist"); throw RPCException(FILE_NOT_FOUND, "Certificate does not exist");
} else { } else {
ostringstream ss; ostringstream ss;
ss << infile.rdbuf(); ss << infile.rdbuf();
cert = ss.str(); cert = ss.str();
infile.close(); infile.close();
string remove_crt = "cd cert && rm -rf " + hash + ".crt && rm -rf " + hash + ".csr"; string remove_crt = "cd cert && rm -rf " + hash + ".crt && rm -rf " + hash + ".csr";
if(system(remove_crt.c_str()) == 0){ if (system(remove_crt.c_str()) == 0) {
//cerr << "cert removed" << endl; //cerr << "cert removed" << endl;
spdlog::info(" cert removed "); spdlog::info(" cert removed ");
} } else {
else{ spdlog::info(" cert was not removed ");
spdlog::info(" cert was not removed "); }
}
}
} }
result["status"] = status;
result["cert"] = cert;
} catch (RPCException &_e) {
cerr << " err str " << _e.errString << endl;
result["status"] = _e.status;
result["errorMessage"] = _e.errString;
} }
result["status"] = status; return result;
result["cert"] = cert;
} catch (RPCException &_e) {
cerr << " err str " << _e.errString << endl;
result["status"] = _e.status;
result["errorMessage"] = _e.errString;
}
return result;
} }
Json::Value SGXRegistrationServer::signCertificate(const string& csr){ Json::Value SGXRegistrationServer::signCertificate(const string &csr) {
spdlog::info("Enter signCertificate "); spdlog::info("Enter signCertificate ");
lock_guard<recursive_mutex> lock(m); lock_guard<recursive_mutex> lock(m);
return signCertificateImpl(csr, cert_auto_sign); return signCertificateImpl(csr, autoSign);
} }
Json::Value SGXRegistrationServer::getCertificate(const string& hash){ Json::Value SGXRegistrationServer::getCertificate(const string &hash) {
lock_guard<recursive_mutex> lock(m); lock_guard<recursive_mutex> lock(m);
return GetSertificateImpl(hash); return GetSertificateImpl(hash);
} }
void SGXRegistrationServer::set_cert_created(bool b){ void SGXRegistrationServer::set_cert_created(bool b) {
sleep(100); sleep(100);
is_cert_created = b; isCertCreated = b;
} }
int initRegistrationServer(bool _autoSign) {
int init_registration_server(bool sign_automatically) {
// string certPath = "cert/SGXCACertificate.crt"; // string certPath = "cert/SGXCACertificate.crt";
// string keyPath = "cert/SGXCACertificate.key"; // string keyPath = "cert/SGXCACertificate.key";
...@@ -210,20 +200,19 @@ int init_registration_server(bool sign_automatically) { ...@@ -210,20 +200,19 @@ int init_registration_server(bool sign_automatically) {
// } // }
// } // }
hs2 = new HttpServer(BASE_PORT + 1); httpServer2 = new HttpServer(BASE_PORT + 1);
regs = new SGXRegistrationServer(*hs2, registrationServer = new SGXRegistrationServer(*httpServer2,
JSONRPC_SERVER_V2, sign_automatically); // hybrid server (json-rpc 1.0 & 2.0) JSONRPC_SERVER_V2,
_autoSign); // hybrid server (json-rpc 1.0 & 2.0)
if (!regs->StartListening()) {
spdlog::info("Registration server could not start listening");
exit(-1);
}
else {
spdlog::info("Registration server started on port {}", BASE_PORT + 1);
}
if (!registrationServer->StartListening()) {
spdlog::info("Registration server could not start listening");
exit(-1);
} else {
spdlog::info("Registration server started on port {}", BASE_PORT + 1);
}
return 0; return 0;
} }
...@@ -33,14 +33,12 @@ using namespace std; ...@@ -33,14 +33,12 @@ using namespace std;
class SGXRegistrationServer: public AbstractRegServer { class SGXRegistrationServer: public AbstractRegServer {
std::recursive_mutex m; std::recursive_mutex m;
bool is_cert_created; bool isCertCreated;
bool cert_auto_sign; bool autoSign;
//std::string hash;
public: public:
SGXRegistrationServer(AbstractServerConnector &connector, serverVersion_t type, bool auto_sign = false); SGXRegistrationServer(AbstractServerConnector &connector, serverVersion_t type, bool _autoSign = false);
void set_cert_created(bool b); void set_cert_created(bool b);
...@@ -50,7 +48,7 @@ public: ...@@ -50,7 +48,7 @@ public:
}; };
extern int init_registration_server(bool sign_automatically = false); extern int initRegistrationServer(bool _autoSign = false);
......
...@@ -46,103 +46,99 @@ ...@@ -46,103 +46,99 @@
#include "common.h" #include "common.h"
bool isStringDec(string &_str) {
bool isStringDec( string & str){ auto res = find_if_not(_str.begin(), _str.end(), [](char c) -> bool {
auto res = find_if_not(str.begin(), str.end(), [](char c)->bool{ return isdigit(c);
return isdigit(c); });
}); return !_str.empty() && res == _str.end();
return !str.empty() && res == str.end();
} }
SGXWalletServer *s = nullptr; SGXWalletServer *s = nullptr;
HttpServer *hs = nullptr; HttpServer *httpServer = nullptr;
SGXWalletServer::SGXWalletServer(AbstractServerConnector &connector, SGXWalletServer::SGXWalletServer(AbstractServerConnector &_connector,
serverVersion_t type) serverVersion_t _type)
: AbstractStubServer(connector, type) {} : AbstractStubServer(_connector, _type) {}
void debug_print(){ void SGXWalletServer::printDB() {
cout << "HERE ARE YOUR KEYS: " << endl; cout << "HERE ARE YOUR KEYS: " << endl;
class MyVisitor: public LevelDB::KeyVisitor { class MyVisitor : public LevelDB::KeyVisitor {
public: public:
virtual void visitDBKey(const char* _data){ virtual void visitDBKey(const char *_data) {
cout << _data << endl; cout << _data << endl;
} }
}; };
MyVisitor v; MyVisitor v;
LevelDB::getLevelDb()->visitKeys(&v, 100000000); LevelDB::getLevelDb()->visitKeys(&v, 100000000);
} }
int init_https_server(bool check_certs) { int SGXWalletServer::initHttpsServer(bool _checkCerts) {
string rootCAPath = string(SGXDATA_FOLDER) + "cert_data/rootCA.pem"; string rootCAPath = string(SGXDATA_FOLDER) + "cert_data/rootCA.pem";
string keyCAPath = string(SGXDATA_FOLDER) + "cert_data/rootCA.key"; string keyCAPath = string(SGXDATA_FOLDER) + "cert_data/rootCA.key";
if (access(rootCAPath.c_str(), F_OK) != 0 || access(keyCAPath.c_str(), F_OK) != 0){ if (access(rootCAPath.c_str(), F_OK) != 0 || access(keyCAPath.c_str(), F_OK) != 0) {
spdlog::info("YOU DO NOT HAVE ROOT CA CERTIFICATE"); spdlog::info("YOU DO NOT HAVE ROOT CA CERTIFICATE");
spdlog::info("ROOT CA CERTIFICATE IS GOING TO BE CREATED"); spdlog::info("ROOT CA CERTIFICATE IS GOING TO BE CREATED");
string genRootCACert = "cd cert && ./create_CA"; string genRootCACert = "cd cert && ./create_CA";
if (system(genRootCACert.c_str()) == 0){ if (system(genRootCACert.c_str()) == 0) {
spdlog::info("ROOT CA CERTIFICATE IS SUCCESSFULLY GENERATED"); spdlog::info("ROOT CA CERTIFICATE IS SUCCESSFULLY GENERATED");
} } else {
else{ spdlog::info("ROOT CA CERTIFICATE GENERATION FAILED");
spdlog::info("ROOT CA CERTIFICATE GENERATION FAILED"); exit(-1);
exit(-1); }
} }
}
string certPath = string(SGXDATA_FOLDER) + "cert_data/SGXServerCert.crt"; string certPath = string(SGXDATA_FOLDER) + "cert_data/SGXServerCert.crt";
string keyPath = string(SGXDATA_FOLDER) + "cert_data/SGXServerCert.key"; string keyPath = string(SGXDATA_FOLDER) + "cert_data/SGXServerCert.key";
if (access(certPath.c_str(), F_OK) != 0 || access(certPath.c_str(), F_OK) != 0){ if (access(certPath.c_str(), F_OK) != 0 || access(certPath.c_str(), F_OK) != 0) {
spdlog::info("YOU DO NOT HAVE SERVER CERTIFICATE"); spdlog::info("YOU DO NOT HAVE SERVER CERTIFICATE");
spdlog::info("SERVER CERTIFICATE IS GOING TO BE CREATED"); spdlog::info("SERVER CERTIFICATE IS GOING TO BE CREATED");
string genCert = "cd cert && ./create_server_cert"; string genCert = "cd cert && ./create_server_cert";
if (system(genCert.c_str()) == 0){ if (system(genCert.c_str()) == 0) {
spdlog::info("SERVER CERTIFICATE IS SUCCESSFULLY GENERATED"); spdlog::info("SERVER CERTIFICATE IS SUCCESSFULLY GENERATED");
} } else {
else{ spdlog::info("SERVER CERTIFICATE GENERATION FAILED");
spdlog::info("SERVER CERTIFICATE GENERATION FAILED"); exit(-1);
exit(-1); }
} }
}
hs = new HttpServer(BASE_PORT, certPath, keyPath, rootCAPath, check_certs, 64); httpServer = new HttpServer(BASE_PORT, certPath, keyPath, rootCAPath, _checkCerts, 64);
s = new SGXWalletServer(*hs, s = new SGXWalletServer(*httpServer,
JSONRPC_SERVER_V2); // hybrid server (json-rpc 1.0 & 2.0) JSONRPC_SERVER_V2); // hybrid server (json-rpc 1.0 & 2.0)
if (!s->StartListening()) { if (!s->StartListening()) {
spdlog::info("SGX Server could not start listening"); spdlog::info("SGX Server could not start listening");
exit(-1); exit(-1);
} } else {
else{ spdlog::info("SGX Server started on port {}", BASE_PORT);
spdlog::info("SGX Server started on port {}", BASE_PORT); }
} return 0;
return 0;
} }
int init_http_server() { //without ssl int SGXWalletServer::initHttpServer() { //without ssl
hs = new HttpServer(BASE_PORT + 3); httpServer = new HttpServer(BASE_PORT + 3);
s = new SGXWalletServer(*hs, s = new SGXWalletServer(*httpServer,
JSONRPC_SERVER_V2); // hybrid server (json-rpc 1.0 & 2.0) JSONRPC_SERVER_V2); // hybrid server (json-rpc 1.0 & 2.0)
if (!s->StartListening()) { if (!s->StartListening()) {
spdlog::info("Server could not start listening"); spdlog::info("Server could not start listening");
exit(-1); exit(-1);
} }
return 0; return 0;
} }
Json::Value Json::Value
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;
...@@ -155,9 +151,7 @@ importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int ...@@ -155,9 +151,7 @@ importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int
char *encryptedKeyShareHex = nullptr; char *encryptedKeyShareHex = nullptr;
try { try {
// if ( !checkName(_keyShare, "BLS_KEY")){
// throw RPCException(INVALID_POLY_NAME, "Invalid BLSKey name");
// }
encryptedKeyShareHex = encryptBLSKeyShare2Hex(&errStatus, errMsg, _keyShare.c_str()); encryptedKeyShareHex = encryptBLSKeyShare2Hex(&errStatus, errMsg, _keyShare.c_str());
if (encryptedKeyShareHex == nullptr) { if (encryptedKeyShareHex == nullptr) {
...@@ -170,7 +164,7 @@ importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int ...@@ -170,7 +164,7 @@ importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int
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;
...@@ -184,7 +178,8 @@ importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int ...@@ -184,7 +178,8 @@ importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int
return result; return result;
} }
Json::Value blsSignMessageHashImpl(const string &keyShareName, const string &messageHash,int t, int n, int signerIndex) { Json::Value
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";
...@@ -192,25 +187,25 @@ Json::Value blsSignMessageHashImpl(const string &keyShareName, const string &mes ...@@ -192,25 +187,25 @@ Json::Value blsSignMessageHashImpl(const string &keyShareName, const string &mes
char *signature = (char *) calloc(BUF_LEN, 1); char *signature = (char *) calloc(BUF_LEN, 1);
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);
} }
while (cutHash[0] == '0'){ while (cutHash[0] == '0') {
cutHash.erase(cutHash.begin(), cutHash.begin() + 1); cutHash.erase(cutHash.begin(), cutHash.begin() + 1);
} }
if ( !checkHex(cutHash)){ if (!checkHex(cutHash)) {
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;
...@@ -242,7 +237,7 @@ Json::Value blsSignMessageHashImpl(const string &keyShareName, const string &mes ...@@ -242,7 +237,7 @@ Json::Value blsSignMessageHashImpl(const string &keyShareName, const string &mes
} }
Json::Value importECDSAKeyImpl(const string &key, const string &keyName) { Json::Value SGXWalletServer::importECDSAKeyImpl(const string &_key, const string &_keyName) {
Json::Value result; Json::Value result;
result["status"] = 0; result["status"] = 0;
result["errorMessage"] = ""; result["errorMessage"] = "";
...@@ -251,7 +246,7 @@ Json::Value importECDSAKeyImpl(const string &key, const string &keyName) { ...@@ -251,7 +246,7 @@ Json::Value importECDSAKeyImpl(const string &key, const string &keyName) {
} }
Json::Value generateECDSAKeyImpl() { Json::Value SGXWalletServer::generateECDSAKeyImpl() {
Json::Value result; Json::Value result;
result["status"] = 0; result["status"] = 0;
...@@ -260,21 +255,21 @@ Json::Value generateECDSAKeyImpl() { ...@@ -260,21 +255,21 @@ Json::Value generateECDSAKeyImpl() {
spdlog::info("Calling method generateECDSAKey"); spdlog::info("Calling method generateECDSAKey");
vector<string>keys; vector<string> keys;
try { try {
keys = gen_ecdsa_key(); keys = gen_ecdsa_key();
if (keys.size() == 0 ) { if (keys.size() == 0) {
throw RPCException(UNKNOWN_ERROR, "key was not generated"); throw RPCException(UNKNOWN_ERROR, "key was not generated");
} }
string keyName = "NEK:" + keys.at(2); string keyName = "NEK:" + keys.at(2);
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("write encr key {}", keys.at(0)); spdlog::info("write encr key {}", keys.at(0));
spdlog::info("keyname length is {}", keyName.length()); spdlog::info("keyname length is {}", keyName.length());
spdlog::info("key name generated: {}", keyName); spdlog::info("key name generated: {}", keyName);
} }
writeDataToDB(keyName, keys.at(0)); writeDataToDB(keyName, keys.at(0));
...@@ -292,43 +287,43 @@ Json::Value generateECDSAKeyImpl() { ...@@ -292,43 +287,43 @@ Json::Value generateECDSAKeyImpl() {
return result; return result;
} }
Json::Value 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"] = "";
result["encryptedKey"] = ""; result["encryptedKey"] = "";
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;
result["status"] = _e.status; result["status"] = _e.status;
result["errorMessage"] = _e.errString; result["errorMessage"] = _e.errString;
} }
return result; return result;
} }
Json::Value 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"] = "";
...@@ -338,48 +333,48 @@ Json::Value ecdsaSignMessageHashImpl(int base, const string &_keyName, const str ...@@ -338,48 +333,48 @@ Json::Value ecdsaSignMessageHashImpl(int base, const string &_keyName, const str
vector<string> sign_vect(3); vector<string> sign_vect(3);
if (DEBUG_PRINT) { 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);
} }
while (cutHash[0] == '0'){ while (cutHash[0] == '0') {
cutHash.erase(cutHash.begin(), cutHash.begin() + 1); cutHash.erase(cutHash.begin(), cutHash.begin() + 1);
} }
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("Hash handled {}", cutHash); spdlog::info("Hash handled {}", cutHash);
} }
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");
} }
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");
} }
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("got signature_s {}", sign_vect.at(2)); spdlog::info("got signature_s {}", sign_vect.at(2));
} }
result["signature_v"] = sign_vect.at(0); result["signature_v"] = sign_vect.at(0);
result["signature_r"] = sign_vect.at(1); result["signature_r"] = sign_vect.at(1);
result["signature_s"] = sign_vect.at(2); result["signature_s"] = sign_vect.at(2);
} catch (RPCException &_e) { } catch (RPCException &_e) {
cerr << "err str " << _e.errString << endl; cerr << "err str " << _e.errString << endl;
...@@ -390,7 +385,7 @@ Json::Value ecdsaSignMessageHashImpl(int base, const string &_keyName, const str ...@@ -390,7 +385,7 @@ Json::Value ecdsaSignMessageHashImpl(int base, const string &_keyName, const str
return result; return result;
} }
Json::Value 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"] = "";
...@@ -401,16 +396,16 @@ Json::Value getPublicECDSAKeyImpl(const string& keyName){ ...@@ -401,16 +396,16 @@ Json::Value 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 (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("PublicKey {}", Pkey); spdlog::info("PublicKey {}", Pkey);
spdlog::info("PublicKey length {}", Pkey.length()); spdlog::info("PublicKey length {}", Pkey.length());
} }
result["publicKey"] = Pkey; result["publicKey"] = Pkey;
} catch (RPCException &_e) { } catch (RPCException &_e) {
result["status"] = _e.status; result["status"] = _e.status;
...@@ -420,7 +415,7 @@ Json::Value getPublicECDSAKeyImpl(const string& keyName){ ...@@ -420,7 +415,7 @@ Json::Value getPublicECDSAKeyImpl(const string& keyName){
return result; return result;
} }
Json::Value 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;
...@@ -430,16 +425,17 @@ Json::Value generateDKGPolyImpl(const string& polyName, int t) { ...@@ -430,16 +425,17 @@ Json::Value 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, "Invalid polynomial name, it should be like POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1"); throw RPCException(INVALID_POLY_NAME,
} "Invalid polynomial name, it should be like POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1");
if ( t <= 0 || t > 32){ }
throw RPCException(INVALID_DKG_PARAMS, "Invalid parameter t "); if (t <= 0 || t > 32) {
} throw RPCException(INVALID_DKG_PARAMS, "Invalid parameter t ");
encrPolyHex = gen_dkg_poly(t); }
writeDataToDB(polyName, encrPolyHex); encrPolyHex = gen_dkg_poly(t);
writeDataToDB(polyName, encrPolyHex);
//result["encryptedPoly"] = encrPolyHex;
//result["encryptedPoly"] = encrPolyHex;
} catch (RPCException &_e) { } catch (RPCException &_e) {
cerr << " err str " << _e.errString << endl; cerr << " err str " << _e.errString << endl;
result["status"] = _e.status; result["status"] = _e.status;
...@@ -449,67 +445,67 @@ Json::Value generateDKGPolyImpl(const string& polyName, int t) { ...@@ -449,67 +445,67 @@ Json::Value generateDKGPolyImpl(const string& polyName, int t) {
return result; return result;
} }
Json::Value 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;
result["errorMessage"] = ""; result["errorMessage"] = "";
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);
} }
} }
} catch (RPCException &_e) { } catch (RPCException &_e) {
cerr << " err str " << _e.errString << endl; cerr << " err str " << _e.errString << endl;
result["status"] = _e.status; result["status"] = _e.status;
result["errorMessage"] = _e.errString; result["errorMessage"] = _e.errString;
result["verificationVector"] = ""; result["verificationVector"] = "";
} }
return result; return result;
} }
Json::Value 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());
} }
...@@ -528,127 +524,127 @@ Json::Value getSecretShareImpl(const string& polyName, const Json::Value& public ...@@ -528,127 +524,127 @@ Json::Value getSecretShareImpl(const string& polyName, const Json::Value& public
return result; return result;
} }
Json::Value 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 ind) {
spdlog::info("enter dkgVerificationImpl"); spdlog::info("enter dkgVerificationImpl");
Json::Value result; Json::Value result;
result["status"] = 0; result["status"] = 0;
result["errorMessage"] = ""; result["errorMessage"] = "";
result["result"] = true; result["result"] = true;
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) || ind > n || ind < 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, ind)) {
result["result"] = false; result["result"] = false;
} }
} catch (RPCException &_e) { } catch (RPCException &_e) {
//cerr << " err str " << _e.errString << endl; //cerr << " err str " << _e.errString << endl;
result["status"] = _e.status; result["status"] = _e.status;
result["errorMessage"] = _e.errString; result["errorMessage"] = _e.errString;
result["result"] = false; result["result"] = false;
} }
return result; return result;
} }
Json::Value createBLSPrivateKeyImpl(const string & blsKeyName, const string& ethKeyName, const string& polyName, const string & SecretShare, int t, int n){ Json::Value SGXWalletServer::createBLSPrivateKeyImpl(const string &blsKeyName, const string &ethKeyName, const string &polyName,
const string &SecretShare, int t, int n) {
spdlog::info("createBLSPrivateKeyImpl entered"); spdlog::info("createBLSPrivateKeyImpl entered");
Json::Value result; Json::Value result;
result["status"] = 0; result["status"] = 0;
result["errorMessage"] = ""; result["errorMessage"] = "";
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 (DEBUG_PRINT) { 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);
} }
} catch (RPCException &_e) { } catch (RPCException &_e) {
//cerr << " err str " << _e.errString << endl; //cerr << " err str " << _e.errString << endl;
result["status"] = _e.status; result["status"] = _e.status;
result["errorMessage"] = _e.errString; result["errorMessage"] = _e.errString;
} }
return result; return result;
} }
Json::Value 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 (DEBUG_PRINT) { 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());
//cerr << "encr_bls_key_share is " << *encryptedKeyHex_ptr << endl; //cerr << "encr_bls_key_share is " << *encryptedKeyHex_ptr << endl;
// cerr << "length is " << encryptedKeyHex_ptr->length() << endl; // cerr << "length is " << encryptedKeyHex_ptr->length() << endl;
} }
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);
} }
} catch (RPCException &_e) { } catch (RPCException &_e) {
cerr << " err str " << _e.errString << endl; cerr << " err str " << _e.errString << endl;
...@@ -661,40 +657,40 @@ Json::Value getBLSPublicKeyShareImpl(const string & blsKeyName){ ...@@ -661,40 +657,40 @@ Json::Value getBLSPublicKeyShareImpl(const string & blsKeyName){
return result; return result;
} }
Json::Value 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;
} catch (RPCException &_e) { } catch (RPCException &_e) {
cerr << " err str " << _e.errString << endl; cerr << " err str " << _e.errString << endl;
result["status"] = _e.status; result["status"] = _e.status;
result["errorMessage"] = _e.errString; result["errorMessage"] = _e.errString;
} }
return result; return result;
} }
Json::Value 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);
} }
...@@ -707,147 +703,150 @@ Json::Value multG2Impl(const string& x){ ...@@ -707,147 +703,150 @@ Json::Value multG2Impl(const string& x){
return result; return result;
} }
Json::Value 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["errorMessage"] = "";
if (poly_str_ptr == nullptr){
result["IsExist"] = false;
result["status"] = 0; result["status"] = 0;
result["errorMessage"] = ""; result["errorMessage"] = "";
} if (poly_str_ptr == nullptr) {
result["IsExist"] = false;
result["status"] = 0;
result["errorMessage"] = "";
}
} catch (RPCException &_e) { } catch (RPCException &_e) {
std::cerr << " err str " << _e.errString << std::endl; std::cerr << " err str " << _e.errString << std::endl;
result["status"] = _e.status; result["status"] = _e.status;
result["errorMessage"] = _e.errString; result["errorMessage"] = _e.errString;
result["IsExist"] = false; result["IsExist"] = false;
} }
return result; return result;
} }
Json::Value getServerStatusImpl() { Json::Value SGXWalletServer::getServerStatusImpl() {
Json::Value result; Json::Value result;
result["status"] = 0; result["status"] = 0;
result["errorMessage"] = ""; result["errorMessage"] = "";
return result; return result;
} }
Json::Value SGXWalletServer::generateDKGPoly(const string& polyName, int t){ Json::Value SGXWalletServer::generateDKGPoly(const string &polyName, int t) {
spdlog::info("entered generateDKGPoly"); spdlog::info("entered generateDKGPoly");
lock_guard<recursive_mutex> lock(m); lock_guard<recursive_mutex> lock(m);
return generateDKGPolyImpl(polyName, t); return generateDKGPolyImpl(polyName, t);
} }
Json::Value SGXWalletServer::getVerificationVector(const string& polyName, int t, int n){ Json::Value SGXWalletServer::getVerificationVector(const string &polyName, int t, int n) {
lock_guard<recursive_mutex> lock(m); lock_guard<recursive_mutex> lock(m);
return getVerificationVectorImpl(polyName, t, n); return getVerificationVectorImpl(polyName, t, n);
} }
Json::Value SGXWalletServer::getSecretShare(const string& polyName, const Json::Value& publicKeys, int t, int n){ Json::Value SGXWalletServer::getSecretShare(const string &polyName, const Json::Value &publicKeys, int t, int n) {
lock_guard<recursive_mutex> lock(m); lock_guard<recursive_mutex> lock(m);
return getSecretShareImpl(polyName, publicKeys, t, n); return getSecretShareImpl(polyName, publicKeys, t, n);
} }
Json::Value SGXWalletServer::dkgVerification( const string& publicShares, const string& ethKeyName, const string& SecretShare, int t, int n, int index){ Json::Value
lock_guard<recursive_mutex> lock(m); SGXWalletServer::dkgVerification(const string &publicShares, const string &ethKeyName, const string &SecretShare, int t,
return dkgVerificationImpl(publicShares, ethKeyName, SecretShare, t, n, index); int n, int index) {
lock_guard<recursive_mutex> lock(m);
return dkgVerificationImpl(publicShares, ethKeyName, SecretShare, t, n, index);
} }
Json::Value SGXWalletServer::createBLSPrivateKey(const string & blsKeyName, const string& ethKeyName, const string& polyName, const string& SecretShare, int t, int n){ Json::Value
lock_guard<recursive_mutex> lock(m); SGXWalletServer::createBLSPrivateKey(const string &blsKeyName, const string &ethKeyName, const string &polyName,
return createBLSPrivateKeyImpl(blsKeyName, ethKeyName, polyName, SecretShare, t, n); const string &SecretShare, int t, int n) {
lock_guard<recursive_mutex> lock(m);
return createBLSPrivateKeyImpl(blsKeyName, ethKeyName, polyName, SecretShare, t, n);
} }
Json::Value SGXWalletServer::getBLSPublicKeyShare(const string & blsKeyName){ Json::Value SGXWalletServer::getBLSPublicKeyShare(const string &blsKeyName) {
lock_guard<recursive_mutex> lock(m); lock_guard<recursive_mutex> lock(m);
return getBLSPublicKeyShareImpl(blsKeyName); return getBLSPublicKeyShareImpl(blsKeyName);
} }
Json::Value SGXWalletServer::generateECDSAKey() { Json::Value SGXWalletServer::generateECDSAKey() {
lock_guard<recursive_mutex> lock(m); lock_guard<recursive_mutex> lock(m);
return generateECDSAKeyImpl(); return generateECDSAKeyImpl();
} }
Json::Value SGXWalletServer::renameECDSAKey(const string& KeyName, const string& tempKeyName){ Json::Value SGXWalletServer::renameECDSAKey(const string &KeyName, const string &tempKeyName) {
lock_guard<recursive_mutex> lock(m); lock_guard<recursive_mutex> lock(m);
return renameECDSAKeyImpl(KeyName, tempKeyName); return renameECDSAKeyImpl(KeyName, tempKeyName);
} }
Json::Value SGXWalletServer::getPublicECDSAKey(const string &_keyName) { Json::Value SGXWalletServer::getPublicECDSAKey(const string &_keyName) {
lock_guard<recursive_mutex> lock(m); lock_guard<recursive_mutex> lock(m);
return getPublicECDSAKeyImpl(_keyName); return getPublicECDSAKeyImpl(_keyName);
} }
Json::Value SGXWalletServer::ecdsaSignMessageHash(int base, const string &_keyName, const string &messageHash ) { Json::Value SGXWalletServer::ecdsaSignMessageHash(int base, const string &_keyName, const string &messageHash) {
lock_guard<recursive_mutex> lock(m); lock_guard<recursive_mutex> lock(m);
spdlog::info("entered ecdsaSignMessageHash"); spdlog::info("entered ecdsaSignMessageHash");
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("MessageHash first {}", messageHash); spdlog::info("MessageHash first {}", messageHash);
} }
return ecdsaSignMessageHashImpl(base,_keyName, messageHash); return ecdsaSignMessageHashImpl(base, _keyName, messageHash);
} }
Json::Value Json::Value
SGXWalletServer::importBLSKeyShare(const string &_keyShare, const string &_keyShareName, int t, int n, SGXWalletServer::importBLSKeyShare(const string &_keyShare, const string &_keyShareName, int _t, int _n,
int index) { int index) {
lock_guard<recursive_mutex> lock(m); lock_guard<recursive_mutex> lock(m);
return importBLSKeyShareImpl(_keyShare, _keyShareName, t, n, index ); return importBLSKeyShareImpl(_keyShare, _keyShareName, _t, _n, index);
} }
Json::Value SGXWalletServer::blsSignMessageHash(const string &keyShareName, const string &messageHash, int t, int n, Json::Value SGXWalletServer::blsSignMessageHash(const string &keyShareName, const string &messageHash, int t, int n,
int signerIndex) { int signerIndex) {
lock_guard<recursive_mutex> lock(m); lock_guard<recursive_mutex> lock(m);
return blsSignMessageHashImpl(keyShareName, messageHash, t, n, signerIndex); return blsSignMessageHashImpl(keyShareName, messageHash, t, n, signerIndex);
} }
Json::Value SGXWalletServer::importECDSAKey(const string &key, const string &keyName) { Json::Value SGXWalletServer::importECDSAKey(const string &key, const string &keyName) {
lock_guard<recursive_mutex> lock(m); lock_guard<recursive_mutex> lock(m);
return importECDSAKeyImpl(key, keyName); return importECDSAKeyImpl(key, keyName);
} }
Json::Value SGXWalletServer::complaintResponse(const string& polyName, int ind){ Json::Value SGXWalletServer::complaintResponse(const string &polyName, int ind) {
lock_guard<recursive_mutex> lock(m); lock_guard<recursive_mutex> lock(m);
return complaintResponseImpl(polyName, ind); return complaintResponseImpl(polyName, ind);
} }
Json::Value SGXWalletServer::multG2(const string& x){ Json::Value SGXWalletServer::multG2(const string &x) {
lock_guard<recursive_mutex> lock(m); lock_guard<recursive_mutex> lock(m);
return multG2Impl(x); return multG2Impl(x);
} }
Json::Value SGXWalletServer::isPolyExists(const string& polyName){ Json::Value SGXWalletServer::isPolyExists(const string &polyName) {
lock_guard<recursive_mutex> lock(m); lock_guard<recursive_mutex> lock(m);
return isPolyExistsImpl(polyName); return isPolyExistsImpl(polyName);
} }
Json::Value SGXWalletServer::getServerStatus() { Json::Value SGXWalletServer::getServerStatus() {
lock_guard<recursive_mutex> lock(m); lock_guard<recursive_mutex> lock(m);
return getServerStatusImpl(); return getServerStatusImpl();
} }
shared_ptr<string> readFromDb(const string & name, const string & prefix) { shared_ptr<string> SGXWalletServer::readFromDb(const string &name, const string &prefix) {
auto dataStr = LevelDB::getLevelDb()->readString(prefix + name); auto dataStr = LevelDB::getLevelDb()->readString(prefix + name);
if (dataStr == nullptr) { if (dataStr == nullptr) {
throw RPCException(KEY_SHARE_DOES_NOT_EXIST, "Data with this name does not exist"); throw RPCException(KEY_SHARE_DOES_NOT_EXIST, "Data with this name does not exist");
} }
return dataStr; return dataStr;
} }
shared_ptr<string> readKeyShare(const string &_keyShareName) { shared_ptr<string> SGXWalletServer::readKeyShare(const string &_keyShareName) {
auto keyShareStr = LevelDB::getLevelDb()->readString("BLSKEYSHARE:" + _keyShareName); auto keyShareStr = LevelDB::getLevelDb()->readString("BLSKEYSHARE:" + _keyShareName);
...@@ -859,7 +858,7 @@ shared_ptr<string> readKeyShare(const string &_keyShareName) { ...@@ -859,7 +858,7 @@ shared_ptr<string> readKeyShare(const string &_keyShareName) {
} }
void 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;
...@@ -880,23 +879,23 @@ void writeKeyShare(const string &_keyShareName, const string &value, int index, ...@@ -880,23 +879,23 @@ void writeKeyShare(const string &_keyShareName, const string &value, int index,
LevelDB::getLevelDb()->writeString(key, value); LevelDB::getLevelDb()->writeString(key, value);
} }
void writeDataToDB(const string & Name, const string &value) { void SGXWalletServer::writeDataToDB(const string &Name, const string &value) {
Json::Value val; Json::Value val;
Json::FastWriter writer; Json::FastWriter writer;
val["value"] = value; val["value"] = value;
string json = writer.write(val); string json = writer.write(val);
auto key = Name; auto key = Name;
if (LevelDB::getLevelDb()->readString(Name) != nullptr) { if (LevelDB::getLevelDb()->readString(Name) != nullptr) {
spdlog::info("name {}", Name, " already exists"); spdlog::info("name {}", Name, " already exists");
throw RPCException(KEY_SHARE_ALREADY_EXISTS, "Data with this name already exists"); throw RPCException(KEY_SHARE_ALREADY_EXISTS, "Data with this name already exists");
} }
LevelDB::getLevelDb()->writeString(key, value); LevelDB::getLevelDb()->writeString(key, value);
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("{} ", Name, " is written to db "); spdlog::info("{} ", Name, " is written to db ");
} }
} }
...@@ -31,9 +31,6 @@ ...@@ -31,9 +31,6 @@
#endif #endif
EXTERNC int init_https_server(bool check_certs );
EXTERNC int init_http_server();
......
...@@ -25,72 +25,116 @@ ...@@ -25,72 +25,116 @@
#define SGXWALLET_SGXWALLETSERVER_HPP #define SGXWALLET_SGXWALLETSERVER_HPP
#include "abstractstubserver.h" #include "abstractstubserver.h"
#include <mutex> #include <mutex>
using namespace jsonrpc; using namespace jsonrpc;
using namespace std; using namespace std;
class SGXWalletServer : public AbstractStubServer { class SGXWalletServer : public AbstractStubServer {
SGXWalletServer* server = nullptr; SGXWalletServer *server = nullptr;
std::recursive_mutex m; std::recursive_mutex m;
public: public:
SGXWalletServer(AbstractServerConnector &connector, serverVersion_t type); SGXWalletServer(AbstractServerConnector &_connector, serverVersion_t _type);
virtual Json::Value
importBLSKeyShare(const std::string &_keyShare, const std::string &_keyShareName, int _t, int _n, int index);
virtual Json::Value
blsSignMessageHash(const std::string &keyShareName, const std::string &messageHash, int t, int n, int signerIndex);
virtual Json::Value importBLSKeyShare(const std::string& keyShare, const std::string& keyShareName, int t, int n, int index); virtual Json::Value importECDSAKey(const std::string &key, const std::string &keyName);
virtual Json::Value blsSignMessageHash(const std::string& keyShareName, const std::string& messageHash, int t, int n, int signerIndex);
virtual Json::Value importECDSAKey(const std::string& key, const std::string& keyName);
virtual Json::Value generateECDSAKey(); virtual Json::Value generateECDSAKey();
virtual Json::Value renameECDSAKey(const std::string& KeyName, const std::string& tempKeyName);
virtual Json::Value ecdsaSignMessageHash(int base, const std::string& keyShareName, const std::string& messageHash); virtual Json::Value renameECDSAKey(const std::string &KeyName, const std::string &tempKeyName);
virtual Json::Value getPublicECDSAKey(const std::string& keyName);
virtual Json::Value ecdsaSignMessageHash(int base, const std::string &keyShareName, const std::string &messageHash);
virtual Json::Value generateDKGPoly(const std::string& polyName, int t);
virtual Json::Value getVerificationVector(const std::string& polyName, int t, int n); virtual Json::Value getPublicECDSAKey(const std::string &keyName);
virtual Json::Value getSecretShare(const std::string& polyName, const Json::Value& publicKeys, int t, int n);
virtual Json::Value dkgVerification(const std::string& publicShares, const std::string& ethKeyName, const std::string& SecretShare, int t, int n, int index); virtual Json::Value generateDKGPoly(const std::string &polyName, int t);
virtual Json::Value createBLSPrivateKey(const std::string & blsKeyName, const std::string& ethKeyName, const std::string& polyName, const std::string & SecretShare, int t, int n);
virtual Json::Value getBLSPublicKeyShare(const std::string & blsKeyName); virtual Json::Value getVerificationVector(const std::string &polyName, int t, int n);
virtual Json::Value complaintResponse(const std::string& polyName, int ind);
virtual Json::Value multG2(const std::string & x); virtual Json::Value getSecretShare(const std::string &polyName, const Json::Value &publicKeys, int t, int n);
virtual Json::Value isPolyExists(const std::string& polyName);
virtual Json::Value
dkgVerification(const std::string &publicShares, const std::string &ethKeyName, const std::string &SecretShare,
int t, int n, int index);
virtual Json::Value
createBLSPrivateKey(const std::string &blsKeyName, const std::string &ethKeyName, const std::string &polyName,
const std::string &SecretShare, int t, int n);
virtual Json::Value getBLSPublicKeyShare(const std::string &blsKeyName);
virtual Json::Value complaintResponse(const std::string &polyName, int ind);
virtual Json::Value multG2(const std::string &x);
virtual Json::Value isPolyExists(const std::string &polyName);
virtual Json::Value getServerStatus(); virtual Json::Value getServerStatus();
}; static shared_ptr<string> readFromDb(const string &name, const string &prefix = "");
shared_ptr<string> readFromDb(const string & name, const string & prefix = ""); static void writeDataToDB(const string &Name, const string &value);
void writeDataToDB(const string & Name, const string &value);
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);
shared_ptr<std::string> readKeyShare(const string& _keyShare);
Json::Value importBLSKeyShareImpl(const std::string& keyShare, const std::string& keyShareName, int t, int n, int index); static shared_ptr<std::string> readKeyShare(const string &_keyShare);
Json::Value blsSignMessageHashImpl(const std::string& keyShareName, const std::string& messageHash, int t, int n, int signerIndex);
Json::Value importECDSAKeyImpl(const std::string& key, const std::string& keyName); static Json::Value
Json::Value generateECDSAKeyImpl(); importBLSKeyShareImpl(const std::string &keyShare, const std::string &keyShareName, int t, int n, int index);
Json::Value renameECDSAKeyImpl(const std::string& KeyName, const std::string& tempKeyName);
Json::Value ecdsaSignMessageHashImpl(int base, const std::string& keyName, const std::string& messageHash);
Json::Value getPublicECDSAKeyImpl(const std::string& keyName);
Json::Value generateDKGPolyImpl(const std::string& polyName, int t); static Json::Value
Json::Value getVerificationVectorImpl(const std::string& polyName, int t, int n); blsSignMessageHashImpl(const std::string &keyShareName, const std::string &messageHash, int t, int n,
Json::Value getSecretShareImpl(const std::string& polyName, const Json::Value& publicKeys, int t, int n); int signerIndex);
Json::Value dkgVerificationImpl(const std::string& publicShares, const std::string& ethKeyName, const std::string& SecretShare, int t, int n, int index);
Json::Value createBLSPrivateKeyImpl(const std::string & blsKeyName, const std::string& ethKeyName, const std::string& polyName, const std::string & SecretShare, int t, int n);
Json::Value getBLSPublicKeyShareImpl(const std::string & blsKeyName);
Json::Value complaintResponseImpl(const std::string& polyName, int ind);
Json::Value multG2Impl(const std::string & x);
Json::Value isPolyExistsImpl(const std::string& polyName);
Json::Value getServerStatusImpl(); static Json::Value importECDSAKeyImpl(const std::string &_key, const std::string &_keyName);
static Json::Value generateECDSAKeyImpl();
static Json::Value renameECDSAKeyImpl(const std::string &KeyName, const std::string &tempKeyName);
static Json::Value ecdsaSignMessageHashImpl(int base, const std::string &keyName, const std::string &messageHash);
static Json::Value getPublicECDSAKeyImpl(const std::string &keyName);
static Json::Value generateDKGPolyImpl(const std::string &polyName, int t);
static Json::Value getVerificationVectorImpl(const std::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
dkgVerificationImpl(const std::string &publicShares, const std::string &ethKeyName, const std::string &SecretShare,
int t, int n, int index);
static Json::Value
createBLSPrivateKeyImpl(const std::string &blsKeyName, const std::string &ethKeyName, const std::string &polyName,
const std::string &SecretShare, int t, int n);
static Json::Value getBLSPublicKeyShareImpl(const std::string &blsKeyName);
static Json::Value complaintResponseImpl(const std::string &polyName, int ind);
static Json::Value multG2Impl(const std::string &x);
static Json::Value isPolyExistsImpl(const std::string &polyName);
static Json::Value getServerStatusImpl();
static void printDB();
static int initHttpServer();
static int initHttpsServer(bool _checkCerts);
};
#endif //SGXWALLET_SGXWALLETSERVER_HPP #endif //SGXWALLET_SGXWALLETSERVER_HPP
\ No newline at end of file
...@@ -64,6 +64,7 @@ ...@@ -64,6 +64,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "SGXWalletServer.hpp"
#include "SGXWALLET_VERSION" #include "SGXWALLET_VERSION"
//#include <system> //#include <system>
...@@ -95,7 +96,7 @@ void init_enclave() { ...@@ -95,7 +96,7 @@ void init_enclave() {
} }
#endif #endif
if ( DEBUG_PRINT) { if ( printDebugInfo) {
spdlog::info("SGX_DEBUG_FLAG = {}", SGX_DEBUG_FLAG); spdlog::info("SGX_DEBUG_FLAG = {}", SGX_DEBUG_FLAG);
} }
...@@ -121,7 +122,7 @@ void init_enclave() { ...@@ -121,7 +122,7 @@ void init_enclave() {
exit(1); exit(1);
} }
if (DEBUG_PRINT) { if (printDebugInfo) {
spdlog::info("libtgmp initialized"); spdlog::info("libtgmp initialized");
//fprintf(stderr, "libtgmp initialized\n"); //fprintf(stderr, "libtgmp initialized\n");
} }
...@@ -144,13 +145,13 @@ void init_all(bool check_cert, bool sign_automatically, void (*SEK_func)()) { ...@@ -144,13 +145,13 @@ void init_all(bool check_cert, bool sign_automatically, void (*SEK_func)()) {
sgxServerInited = 1; sgxServerInited = 1;
if (is_sgx_https) { if (useHTTPS) {
init_https_server(check_cert); SGXWalletServer::initHttpsServer(check_cert);
init_registration_server(sign_automatically); initRegistrationServer(sign_automatically);
init_csrmanager_server(); init_csrmanager_server();
} }
else { else {
init_http_server(); SGXWalletServer::initHttpServer();
} }
//std::cerr << "enclave inited" << std::endl; //std::cerr << "enclave inited" << std::endl;
......
...@@ -20,7 +20,7 @@ if [ "$1" = -t ]; then ...@@ -20,7 +20,7 @@ if [ "$1" = -t ]; then
./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]
./testw [aes_dkg] ./testw [aes_dkg]
......
...@@ -67,7 +67,7 @@ int main(int argc, char *argv[]) { ...@@ -67,7 +67,7 @@ int main(int argc, char *argv[]) {
exit(1); exit(1);
} }
is_aes = 0; encryptKeys = 0;
while ((opt = getopt(argc, argv, "cshd0aby")) != -1) { while ((opt = getopt(argc, argv, "cshd0aby")) != -1) {
switch (opt) { switch (opt) {
...@@ -91,13 +91,13 @@ int main(int argc, char *argv[]) { ...@@ -91,13 +91,13 @@ int main(int argc, char *argv[]) {
sign_automatically = true; sign_automatically = true;
break; break;
case 'd': case 'd':
DEBUG_PRINT = 1; printDebugInfo = 1;
break; break;
case '0': case '0':
is_sgx_https = 0; useHTTPS = 0;
break; break;
case 'a': case 'a':
is_aes = 0; encryptKeys = 0;
break; break;
case 'b': case 'b':
SEK_initializer = enter_SEK; SEK_initializer = enter_SEK;
......
...@@ -35,9 +35,9 @@ ...@@ -35,9 +35,9 @@
extern int DEBUG_PRINT; extern int printDebugInfo;
extern int is_sgx_https; extern int useHTTPS;
extern int is_aes; extern int encryptKeys;
extern bool autoconfirm; extern bool autoconfirm;
#define BUF_LEN 1024 #define BUF_LEN 1024
......
...@@ -121,8 +121,8 @@ char *encryptTestKey() { ...@@ -121,8 +121,8 @@ char *encryptTestKey() {
TEST_CASE("BLS key encrypt", "[bls-key-encrypt]") { TEST_CASE("BLS key encrypt", "[bls-key-encrypt]") {
DEBUG_PRINT = 1; printDebugInfo = 1;
is_sgx_https = 0; useHTTPS = 0;
autoconfirm = true; autoconfirm = true;
init_all(false, true, init_SEK); init_all(false, true, init_SEK);
auto key = encryptTestKey(); auto key = encryptTestKey();
...@@ -134,8 +134,8 @@ TEST_CASE("BLS key encrypt", "[bls-key-encrypt]") { ...@@ -134,8 +134,8 @@ TEST_CASE("BLS key encrypt", "[bls-key-encrypt]") {
TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") { TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") {
{ {
DEBUG_PRINT = 1; printDebugInfo = 1;
is_sgx_https = 0; useHTTPS = 0;
autoconfirm = true; autoconfirm = true;
init_all(false, true, init_SEK); init_all(false, true, init_SEK);
...@@ -549,8 +549,8 @@ string ConvertDecToHex(string dec, int numBytes = 32) { ...@@ -549,8 +549,8 @@ string ConvertDecToHex(string dec, int numBytes = 32) {
TEST_CASE("BLS_DKG test", "[bls_dkg]") { TEST_CASE("BLS_DKG test", "[bls_dkg]") {
is_sgx_https = 0; useHTTPS = 0;
DEBUG_PRINT = 1; printDebugInfo = 1;
cerr << "test started" << endl; cerr << "test started" << endl;
init_all(false, true, init_SEK); init_all(false, true, init_SEK);
cerr << "Server inited" << endl; cerr << "Server inited" << endl;
...@@ -683,7 +683,7 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") { ...@@ -683,7 +683,7 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
TEST_CASE("API test", "[api_test]") { TEST_CASE("API test", "[api_test]") {
autoconfirm = true; autoconfirm = true;
//DEBUG_PRINT = 1; //DEBUG_PRINT = 1;
is_sgx_https = 0; useHTTPS = 0;
//cerr << __GNUC__ << endl; //cerr << __GNUC__ << endl;
cerr << "API test started" << endl; cerr << "API test started" << endl;
init_all(false, true, init_SEK); init_all(false, true, init_SEK);
...@@ -789,7 +789,7 @@ TEST_CASE("API test", "[api_test]") { ...@@ -789,7 +789,7 @@ TEST_CASE("API test", "[api_test]") {
TEST_CASE("getServerStatus test", "[getServerStatus_test]") { TEST_CASE("getServerStatus test", "[getServerStatus_test]") {
autoconfirm = true; autoconfirm = true;
is_sgx_https = 0; useHTTPS = 0;
init_all(false, true, init_SEK); init_all(false, true, init_SEK);
HttpClient client("http://localhost:1029"); HttpClient client("http://localhost:1029");
StubClient c(client, JSONRPC_CLIENT_V2); StubClient c(client, JSONRPC_CLIENT_V2);
...@@ -911,9 +911,9 @@ void SendRPCRequest() { ...@@ -911,9 +911,9 @@ void SendRPCRequest() {
TEST_CASE("ManySimultaneousThreads", "[many_threads_test]") { TEST_CASE("ManySimultaneousThreads", "[many_threads_test]") {
autoconfirm = true; autoconfirm = true;
is_sgx_https = 0; useHTTPS = 0;
DEBUG_PRINT = 1; printDebugInfo = 1;
is_aes = 1; encryptKeys = 1;
init_all(false, true, init_SEK); init_all(false, true, init_SEK);
...@@ -932,9 +932,9 @@ TEST_CASE("ManySimultaneousThreads", "[many_threads_test]") { ...@@ -932,9 +932,9 @@ TEST_CASE("ManySimultaneousThreads", "[many_threads_test]") {
TEST_CASE("ecdsa API test", "[ecdsa_api_test]") { TEST_CASE("ecdsa API test", "[ecdsa_api_test]") {
autoconfirm = true; autoconfirm = true;
DEBUG_PRINT = 1; printDebugInfo = 1;
is_sgx_https = 0; useHTTPS = 0;
is_aes = 1; encryptKeys = 1;
cerr << "ecdsa_api_test started" << endl; cerr << "ecdsa_api_test started" << endl;
init_all(false, true, init_SEK); init_all(false, true, init_SEK);
...@@ -984,8 +984,8 @@ TEST_CASE("ecdsa API test", "[ecdsa_api_test]") { ...@@ -984,8 +984,8 @@ TEST_CASE("ecdsa API test", "[ecdsa_api_test]") {
TEST_CASE("dkg API test", "[dkg_api_test]") { TEST_CASE("dkg API test", "[dkg_api_test]") {
autoconfirm = true; autoconfirm = true;
DEBUG_PRINT = 1; printDebugInfo = 1;
is_sgx_https = 0; useHTTPS = 0;
cerr << "dkg_api_test started" << endl; cerr << "dkg_api_test started" << endl;
init_all(false, true, init_SEK); init_all(false, true, init_SEK);
...@@ -1062,8 +1062,8 @@ TEST_CASE("dkg API test", "[dkg_api_test]") { ...@@ -1062,8 +1062,8 @@ TEST_CASE("dkg API test", "[dkg_api_test]") {
TEST_CASE("isPolyExists test", "[is_poly_test]") { TEST_CASE("isPolyExists test", "[is_poly_test]") {
autoconfirm = true; autoconfirm = true;
DEBUG_PRINT = 1; printDebugInfo = 1;
is_sgx_https = 0; useHTTPS = 0;
cerr << "is_poly_test started" << endl; cerr << "is_poly_test started" << endl;
init_all(false, true, init_SEK); init_all(false, true, init_SEK);
...@@ -1091,9 +1091,9 @@ TEST_CASE("isPolyExists test", "[is_poly_test]") { ...@@ -1091,9 +1091,9 @@ TEST_CASE("isPolyExists test", "[is_poly_test]") {
TEST_CASE("AES_DKG test", "[aes_dkg]") { TEST_CASE("AES_DKG test", "[aes_dkg]") {
autoconfirm = true; autoconfirm = true;
is_sgx_https = 0; useHTTPS = 0;
DEBUG_PRINT = 1; printDebugInfo = 1;
is_aes = 1; encryptKeys = 1;
reset_db(); reset_db();
...@@ -1223,9 +1223,9 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") { ...@@ -1223,9 +1223,9 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") {
TEST_CASE("bls_sign_api test", "[bls_sign]") { TEST_CASE("bls_sign_api test", "[bls_sign]") {
autoconfirm = true; autoconfirm = true;
is_sgx_https = 0; useHTTPS = 0;
DEBUG_PRINT = 1; printDebugInfo = 1;
is_aes = 1; encryptKeys = 1;
cerr << "test started" << endl; cerr << "test started" << endl;
init_all(false, true, init_SEK); init_all(false, true, init_SEK);
...@@ -1258,8 +1258,8 @@ TEST_CASE("bls_sign_api test", "[bls_sign]") { ...@@ -1258,8 +1258,8 @@ TEST_CASE("bls_sign_api test", "[bls_sign]") {
TEST_CASE("AES encrypt/decrypt", "[AES-encrypt-decrypt]") { TEST_CASE("AES encrypt/decrypt", "[AES-encrypt-decrypt]") {
{ {
autoconfirm = true; autoconfirm = true;
DEBUG_PRINT = 1; printDebugInfo = 1;
is_sgx_https = 0; useHTTPS = 0;
init_all(false, true, init_SEK); init_all(false, true, init_SEK);
//init_enclave(); //init_enclave();
......
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