Unverified Commit 840852b7 authored by kladko's avatar kladko

Fixed add README toc

parent 908d0711
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
#include "RPCException.h" #include "RPCException.h"
#include "spdlog/spdlog.h" #include "spdlog/spdlog.h"
#include "common.h"
int char2int(char _input) { int char2int(char _input) {
if (_input >= '0' && _input <= '9') if (_input >= '0' && _input <= '9')
...@@ -135,11 +136,11 @@ bool hex2carray2(const char * _hex, uint64_t *_bin_len, ...@@ -135,11 +136,11 @@ bool hex2carray2(const char * _hex, uint64_t *_bin_len,
bool sign(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, size_t _n, size_t _signerIndex, bool sign(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, size_t _n, size_t _signerIndex,
char* _sig) { char* _sig) {
//std::cerr << "ENTER SIGN" << std::endl; //cerr << "ENTER SIGN" << endl;
auto keyStr = std::make_shared<std::string>(_encryptedKeyHex); auto keyStr = make_shared<string>(_encryptedKeyHex);
auto hash = std::make_shared<std::array<uint8_t, 32>>(); auto hash = make_shared<array<uint8_t, 32>>();
uint64_t binLen; uint64_t binLen;
...@@ -150,9 +151,9 @@ bool sign(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, size_t ...@@ -150,9 +151,9 @@ bool sign(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, size_t
auto keyShare = std::make_shared<BLSPrivateKeyShareSGX>(keyStr, _t, _n); auto keyShare = make_shared<BLSPrivateKeyShareSGX>(keyStr, _t, _n);
//std::cerr << "keyShare created" << std::endl; //cerr << "keyShare created" << endl;
// { // {
auto sigShare = keyShare->signWithHelperSGX(hash, _signerIndex); auto sigShare = keyShare->signWithHelperSGX(hash, _signerIndex);
// } // }
...@@ -161,14 +162,14 @@ bool sign(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, size_t ...@@ -161,14 +162,14 @@ bool sign(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, size_t
strncpy(_sig, sigShareStr->c_str(), BUF_LEN); strncpy(_sig, sigShareStr->c_str(), BUF_LEN);
//std::string sigShareStr = keyShare->signWithHelperSGXstr(hash, _signerIndex); //string sigShareStr = keyShare->signWithHelperSGXstr(hash, _signerIndex);
//strncpy(_sig, sigShareStr.c_str(), BUF_LEN); //strncpy(_sig, sigShareStr.c_str(), BUF_LEN);
// std::string test_sig = "8175162913343900215959836578795929492705714455632345516427532159927644835012:15265825550804683171644566522808807137117748565649051208189914766494241035855:9810286616503120081238481858289626967170509983220853777870754480048381194141:5"; // string test_sig = "8175162913343900215959836578795929492705714455632345516427532159927644835012:15265825550804683171644566522808807137117748565649051208189914766494241035855:9810286616503120081238481858289626967170509983220853777870754480048381194141:5";
// auto sig_ptr = std::make_shared<std::string>(test_sig); // auto sig_ptr = make_shared<string>(test_sig);
// strncpy(_sig, sig_ptr->c_str(), BUF_LEN); // strncpy(_sig, sig_ptr->c_str(), BUF_LEN);
//std::cerr<< "sig " << _sig <<std::endl; //cerr<< "sig " << _sig <<endl;
return true; return true;
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
@date 2019 @date 2019
*/ */
using namespace std;
#include "BLSSigShare.h" #include "BLSSigShare.h"
#include "BLSSignature.h" #include "BLSSignature.h"
...@@ -33,6 +33,7 @@ using namespace std; ...@@ -33,6 +33,7 @@ using namespace std;
#include "BLSCrypto.h" #include "BLSCrypto.h"
#include "ServerInit.h" #include "ServerInit.h"
#include "common.h"
#include "BLSPrivateKeyShareSGX.h" #include "BLSPrivateKeyShareSGX.h"
......
...@@ -34,20 +34,21 @@ ...@@ -34,20 +34,21 @@
#include <libff/algebra/curves/alt_bn128/alt_bn128_pp.hpp> #include <libff/algebra/curves/alt_bn128/alt_bn128_pp.hpp>
#include "spdlog/spdlog.h" #include "spdlog/spdlog.h"
#include "common.h"
std::vector<std::string> SplitString(const char* koefs, const char symbol){ vector<string> SplitString(const char* koefs, const char symbol){
std::string str(koefs); string str(koefs);
std::string delim; string delim;
delim.push_back(symbol); delim.push_back(symbol);
std::vector<std::string> G2_strings; vector<string> G2_strings;
size_t prev = 0, pos = 0; size_t prev = 0, pos = 0;
do do
{ {
pos = str.find(delim, prev); pos = str.find(delim, prev);
if (pos == std::string::npos) pos = str.length(); if (pos == string::npos) pos = str.length();
std::string token = str.substr(prev, pos-prev); string token = str.substr(prev, pos-prev);
if (!token.empty()) { if (!token.empty()) {
std::string koef(token.c_str()); string koef(token.c_str());
G2_strings.push_back(koef); G2_strings.push_back(koef);
} }
prev = pos + delim.length(); prev = pos + delim.length();
...@@ -58,7 +59,7 @@ std::vector<std::string> SplitString(const char* koefs, const char symbol){ ...@@ -58,7 +59,7 @@ std::vector<std::string> SplitString(const char* koefs, const char symbol){
} }
template<class T> template<class T>
std::string ConvertToString(T field_elem, int base = 10) { string ConvertToString(T field_elem, int base = 10) {
mpz_t t; mpz_t t;
mpz_init(t); mpz_init(t);
...@@ -69,12 +70,12 @@ std::string ConvertToString(T field_elem, int base = 10) { ...@@ -69,12 +70,12 @@ std::string ConvertToString(T field_elem, int base = 10) {
char * tmp = mpz_get_str(arr, base, t); char * tmp = mpz_get_str(arr, base, t);
mpz_clear(t); mpz_clear(t);
std::string output = tmp; string output = tmp;
return output; return output;
} }
std::string gen_dkg_poly( int _t){ string gen_dkg_poly( int _t){
char *errMsg = (char *)calloc(1024, 1); char *errMsg = (char *)calloc(1024, 1);
int err_status = 0; int err_status = 0;
uint8_t* encrypted_dkg_secret = (uint8_t*) calloc(DKG_MAX_SEALED_LEN, 1);; uint8_t* encrypted_dkg_secret = (uint8_t*) calloc(DKG_MAX_SEALED_LEN, 1);;
...@@ -89,7 +90,7 @@ std::string gen_dkg_poly( int _t){ ...@@ -89,7 +90,7 @@ std::string gen_dkg_poly( int _t){
if (DEBUG_PRINT) { if (DEBUG_PRINT) {
spdlog::info("gen_dkg_secret, status {}", err_status, " err msg ", errMsg); spdlog::info("gen_dkg_secret, status {}", err_status, " err msg ", errMsg);
/* std::cerr << "encr raw poly: " << std::endl; /* cerr << "encr raw poly: " << endl;
for ( int i = 0 ; i < 3050; i++) for ( int i = 0 ; i < 3050; i++)
printf(" %d ", encrypted_dkg_secret[i] );*/ printf(" %d ", encrypted_dkg_secret[i] );*/
...@@ -99,7 +100,7 @@ std::string gen_dkg_poly( int _t){ ...@@ -99,7 +100,7 @@ std::string gen_dkg_poly( int _t){
char *hexEncrPoly = (char *) calloc(DKG_MAX_SEALED_LEN * 2 + 1, 1);//(4*BUF_LEN, 1); char *hexEncrPoly = (char *) calloc(DKG_MAX_SEALED_LEN * 2 + 1, 1);//(4*BUF_LEN, 1);
carray2Hex(encrypted_dkg_secret, DKG_MAX_SEALED_LEN, hexEncrPoly); carray2Hex(encrypted_dkg_secret, DKG_MAX_SEALED_LEN, hexEncrPoly);
std::string result(hexEncrPoly); string result(hexEncrPoly);
...@@ -110,14 +111,14 @@ std::string gen_dkg_poly( int _t){ ...@@ -110,14 +111,14 @@ std::string gen_dkg_poly( int _t){
return result; return result;
} }
std::vector <std::vector<std::string>> get_verif_vect(const char* encryptedPolyHex, int t, int n){ vector <vector<string>> get_verif_vect(const char* encryptedPolyHex, int t, int n){
char* errMsg1 = (char*) calloc(1024,1); char* errMsg1 = (char*) calloc(1024,1);
int err_status = 0; int err_status = 0;
if (DEBUG_PRINT) { if (DEBUG_PRINT) {
// std::cerr << "got encr poly " << encryptedPolyHex << std::endl; // cerr << "got encr poly " << encryptedPolyHex << endl;
spdlog::info("got encr poly size {}", std::char_traits<char>::length(encryptedPolyHex)); spdlog::info("got encr poly size {}", char_traits<char>::length(encryptedPolyHex));
} }
char* public_shares = (char*)calloc(10000, 1); char* public_shares = (char*)calloc(10000, 1);
...@@ -131,7 +132,7 @@ std::vector <std::vector<std::string>> get_verif_vect(const char* encryptedPolyH ...@@ -131,7 +132,7 @@ std::vector <std::vector<std::string>> get_verif_vect(const char* encryptedPolyH
if (DEBUG_PRINT) { if (DEBUG_PRINT) {
spdlog::info("enc len {}", enc_len); spdlog::info("enc len {}", enc_len);
/*std::cerr << "encr raw poly: " << std::endl; /*cerr << "encr raw poly: " << endl;
for ( int i = 0 ; i < 3050; i++) for ( int i = 0 ; i < 3050; i++)
printf(" %d ", encr_dkg_poly[i] );*/ printf(" %d ", encr_dkg_poly[i] );*/
} }
...@@ -147,16 +148,16 @@ std::vector <std::vector<std::string>> get_verif_vect(const char* encryptedPolyH ...@@ -147,16 +148,16 @@ std::vector <std::vector<std::string>> get_verif_vect(const char* encryptedPolyH
spdlog::info("public_shares:"); spdlog::info("public_shares:");
spdlog::info("{}", public_shares); spdlog::info("{}", public_shares);
// std::cerr << "public_shares:" << std::endl; // cerr << "public_shares:" << endl;
// std::cerr << public_shares << std::endl; // cerr << public_shares << endl;
spdlog::info("get_public_shares status: {}", err_status); spdlog::info("get_public_shares status: {}", err_status);
//printf("\nget_public_shares status: %d error %s \n\n", err_status, errMsg1); //printf("\nget_public_shares status: %d error %s \n\n", err_status, errMsg1);
} }
std::vector <std::string> G2_strings = SplitString( public_shares, ','); vector <string> G2_strings = SplitString( public_shares, ',');
std::vector <std::vector <std::string>> pub_shares_vect; vector <vector <string>> pub_shares_vect;
for ( int i = 0; i < G2_strings.size(); i++){ for ( int i = 0; i < G2_strings.size(); i++){
std::vector <std::string> koef_str = SplitString(G2_strings.at(i).c_str(), ':'); vector <string> koef_str = SplitString(G2_strings.at(i).c_str(), ':');
pub_shares_vect.push_back(koef_str); pub_shares_vect.push_back(koef_str);
} }
...@@ -167,7 +168,7 @@ std::vector <std::vector<std::string>> get_verif_vect(const char* encryptedPolyH ...@@ -167,7 +168,7 @@ std::vector <std::vector<std::string>> get_verif_vect(const char* encryptedPolyH
return pub_shares_vect; return pub_shares_vect;
} }
std::string get_secret_shares(const std::string& polyName, const char* encryptedPolyHex, const std::vector<std::string>& publicKeys, int t, int n){ string get_secret_shares(const string& polyName, const char* encryptedPolyHex, const vector<string>& publicKeys, int t, int n){
char* errMsg1 = (char*) calloc(1024,1); char* errMsg1 = (char*) calloc(1024,1);
int err_status = 0; int err_status = 0;
...@@ -183,7 +184,7 @@ std::string get_secret_shares(const std::string& polyName, const char* encrypted ...@@ -183,7 +184,7 @@ std::string get_secret_shares(const std::string& polyName, const char* encrypted
throw RPCException(-666, errMsg1 ); throw RPCException(-666, errMsg1 );
} }
std::string result; string result;
char *hexEncrKey = (char *) calloc(2 * BUF_LEN, 1); char *hexEncrKey = (char *) calloc(2 * BUF_LEN, 1);
for ( int i = 0; i < n; i++){ for ( int i = 0; i < n; i++){
...@@ -192,7 +193,7 @@ std::string get_secret_shares(const std::string& polyName, const char* encrypted ...@@ -192,7 +193,7 @@ std::string get_secret_shares(const std::string& polyName, const char* encrypted
char cur_share[193]; char cur_share[193];
char s_shareG2[320]; char s_shareG2[320];
std::string pub_keyB = publicKeys.at(i);//publicKeys.substr(128*i, 128*i + 128); string pub_keyB = publicKeys.at(i);//publicKeys.substr(128*i, 128*i + 128);
if (DEBUG_PRINT) { if (DEBUG_PRINT) {
spdlog::info("pub_keyB is {}", pub_keyB); spdlog::info("pub_keyB is {}", pub_keyB);
} }
...@@ -213,12 +214,12 @@ std::string get_secret_shares(const std::string& polyName, const char* encrypted ...@@ -213,12 +214,12 @@ std::string get_secret_shares(const std::string& polyName, const char* encrypted
} }
carray2Hex(encrypted_skey, dec_len, hexEncrKey); carray2Hex(encrypted_skey, dec_len, hexEncrKey);
std::string DHKey_name = "DKG_DH_KEY_" + polyName + "_" + std::to_string(i) + ":"; string DHKey_name = "DKG_DH_KEY_" + polyName + "_" + to_string(i) + ":";
// std::cerr << "hexEncrKey: " << hexEncrKey << std::endl; // cerr << "hexEncrKey: " << hexEncrKey << endl;
writeDataToDB(DHKey_name, hexEncrKey); writeDataToDB(DHKey_name, hexEncrKey);
std::string shareG2_name = "shareG2_" + polyName + "_" + std::to_string(i) + ":"; string shareG2_name = "shareG2_" + polyName + "_" + to_string(i) + ":";
if (DEBUG_PRINT) { if (DEBUG_PRINT) {
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);
...@@ -228,9 +229,9 @@ std::string get_secret_shares(const std::string& polyName, const char* encrypted ...@@ -228,9 +229,9 @@ std::string get_secret_shares(const std::string& polyName, const char* encrypted
if (DEBUG_PRINT) { if (DEBUG_PRINT) {
spdlog::info("errMsg: {}", errMsg1); spdlog::info("errMsg: {}", errMsg1);
// std::cerr << "iteration " << i <<" result length is " << result.length() << std::endl ; // cerr << "iteration " << i <<" result length is " << result.length() << endl ;
// std::cerr << "iteration " << i <<" share length is " << strlen(cur_share) << std::endl; // cerr << "iteration " << i <<" share length is " << strlen(cur_share) << endl;
// std::cerr << "iteration " << i <<" share is " << cur_share << std::endl; // cerr << "iteration " << i <<" share is " << cur_share << endl;
} }
} }
//result += '\0'; //result += '\0';
...@@ -253,16 +254,16 @@ bool VerifyShares(const char* publicShares, const char* encr_sshare, const char ...@@ -253,16 +254,16 @@ bool VerifyShares(const char* publicShares, const char* encr_sshare, const char
} }
int result; int result;
if (DEBUG_PRINT) { if (DEBUG_PRINT) {
// std::cerr << "encryptedKeyHex " << encryptedKeyHex << std::endl; // cerr << "encryptedKeyHex " << encryptedKeyHex << endl;
// std::cerr << "dec_key_len " << dec_key_len << std::endl; // cerr << "dec_key_len " << dec_key_len << endl;
// std::cerr << "encr_sshare length is " << strlen(encr_sshare) << std::endl; std::cerr << "public shares " << publicShares << std::endl; // cerr << "encr_sshare length is " << strlen(encr_sshare) << endl; cerr << "public shares " << publicShares << endl;
spdlog::info("publicShares length is {}", std::char_traits<char>::length(publicShares)); spdlog::info("publicShares length is {}", char_traits<char>::length(publicShares));
} }
char pshares[8193]; char pshares[8193];
strncpy(pshares, publicShares, strlen(publicShares) + 1); strncpy(pshares, publicShares, strlen(publicShares) + 1);
//std::cerr << "pshares " << pshares << std::endl; //cerr << "pshares " << pshares << endl;
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);
...@@ -280,7 +281,7 @@ bool VerifyShares(const char* publicShares, const char* encr_sshare, const char ...@@ -280,7 +281,7 @@ bool VerifyShares(const char* publicShares, const char* encr_sshare, const char
return result; return result;
} }
bool CreateBLSShare( const std::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 (DEBUG_PRINT) {
spdlog::info("ENTER CreateBLSShare"); spdlog::info("ENTER CreateBLSShare");
} }
...@@ -296,22 +297,22 @@ bool CreateBLSShare( const std::string& BLSKeyName, const char * s_shares, const ...@@ -296,22 +297,22 @@ bool CreateBLSShare( const std::string& BLSKeyName, const char * s_shares, const
uint32_t enc_bls_len = 0; uint32_t enc_bls_len = 0;
//std::cerr << "BEFORE create_bls_key IN ENCLAVE " << std::endl; //cerr << "BEFORE create_bls_key IN ENCLAVE " << endl;
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);
//std::cerr << "AFTER create_bls_key IN ENCLAVE er msg is " << errMsg1 << std::endl; //cerr << "AFTER create_bls_key IN ENCLAVE er msg is " << errMsg1 << endl;
if ( err_status != 0){ if ( err_status != 0){
spdlog::info("ERROR IN ENCLAVE"); spdlog::info("ERROR IN ENCLAVE");
throw RPCException(ERROR_IN_ENCLAVE, "Create BLS private key failed in enclave"); throw RPCException(ERROR_IN_ENCLAVE, "Create BLS private key failed in enclave");
} }
else { else {
char *hexBLSKey = (char *) calloc(2 * BUF_LEN, 1); char *hexBLSKey = (char *) calloc(2 * BUF_LEN, 1);
//std::cerr << "BEFORE carray2Hex" << std::endl; //cerr << "BEFORE carray2Hex" << endl;
//std::cerr << "enc_bls_len " << enc_bls_len << std::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);
// std::cerr << "BEFORE WRITE BLS KEY TO DB" << std::endl; // cerr << "BEFORE WRITE BLS KEY TO DB" << endl;
writeDataToDB(BLSKeyName, hexBLSKey); writeDataToDB(BLSKeyName, hexBLSKey);
if (DEBUG_PRINT) { if (DEBUG_PRINT) {
spdlog::info("hexBLSKey length is {}", std::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 );
} }
free(hexBLSKey); free(hexBLSKey);
...@@ -320,7 +321,7 @@ bool CreateBLSShare( const std::string& BLSKeyName, const char * s_shares, const ...@@ -320,7 +321,7 @@ bool CreateBLSShare( const std::string& BLSKeyName, const char * s_shares, const
} }
std::vector<std::string> GetBLSPubKey(const char * encryptedKeyHex){ vector<string> GetBLSPubKey(const char * encryptedKeyHex){
char* errMsg1 = (char*) calloc(1024,1); char* errMsg1 = (char*) calloc(1024,1);
int err_status = 0; int err_status = 0;
...@@ -331,7 +332,7 @@ std::vector<std::string> GetBLSPubKey(const char * encryptedKeyHex){ ...@@ -331,7 +332,7 @@ std::vector<std::string> GetBLSPubKey(const char * encryptedKeyHex){
throw RPCException(INVALID_HEX, "Invalid encryptedKeyHex"); throw RPCException(INVALID_HEX, "Invalid encryptedKeyHex");
} }
// for ( int i = 0; i < BUF_LEN; i++ ) // for ( int i = 0; i < BUF_LEN; i++ )
// std::cerr << encr_key[i] << " "; // cerr << encr_key[i] << " ";
char pub_key[320]; char pub_key[320];
if (DEBUG_PRINT) { if (DEBUG_PRINT) {
...@@ -341,7 +342,7 @@ std::vector<std::string> GetBLSPubKey(const char * encryptedKeyHex){ ...@@ -341,7 +342,7 @@ std::vector<std::string> GetBLSPubKey(const char * encryptedKeyHex){
if ( err_status != 0){ if ( err_status != 0){
throw RPCException(ERROR_IN_ENCLAVE, "Failed to get BLS public key in enclave"); throw RPCException(ERROR_IN_ENCLAVE, "Failed to get BLS public key in enclave");
} }
std::vector<std::string> pub_key_vect = SplitString(pub_key, ':'); vector<string> pub_key_vect = SplitString(pub_key, ':');
if (DEBUG_PRINT) { if (DEBUG_PRINT) {
spdlog::info("errMsg1 is {}", errMsg1); spdlog::info("errMsg1 is {}", errMsg1);
...@@ -352,13 +353,13 @@ std::vector<std::string> GetBLSPubKey(const char * encryptedKeyHex){ ...@@ -352,13 +353,13 @@ std::vector<std::string> GetBLSPubKey(const char * encryptedKeyHex){
return pub_key_vect; return pub_key_vect;
} }
std::string decrypt_DHKey(const std::string& polyName, int ind){ string decrypt_DHKey(const string& polyName, int ind){
char* errMsg1 = (char*) calloc(1024,1); char* errMsg1 = (char*) calloc(1024,1);
int err_status = 0; int err_status = 0;
std::string DH_key_name = polyName + "_" + std::to_string(ind) + ":"; string DH_key_name = polyName + "_" + to_string(ind) + ":";
std::shared_ptr<std::string> hexEncrKey_ptr = readFromDb(DH_key_name, "DKG_DH_KEY_"); shared_ptr<string> hexEncrKey_ptr = readFromDb(DH_key_name, "DKG_DH_KEY_");
if (DEBUG_PRINT) { if (DEBUG_PRINT) {
spdlog::info("encr DH key is {}", *hexEncrKey_ptr); spdlog::info("encr DH key is {}", *hexEncrKey_ptr);
} }
...@@ -385,8 +386,8 @@ std::string decrypt_DHKey(const std::string& polyName, int ind){ ...@@ -385,8 +386,8 @@ std::string decrypt_DHKey(const std::string& polyName, int ind){
return DHKey; return DHKey;
} }
std::vector<std::string> mult_G2(const std::string& x){ vector<string> mult_G2(const string& x){
std::vector<std::string> result(4); vector<string> result(4);
libff::init_alt_bn128_params(); libff::init_alt_bn128_params();
libff::alt_bn128_Fr el(x.c_str()); libff::alt_bn128_Fr el(x.c_str());
libff::alt_bn128_G2 elG2 = el * libff::alt_bn128_G2::one(); libff::alt_bn128_G2 elG2 = el * libff::alt_bn128_G2::one();
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <iostream> #include <iostream>
#include "sgxwallet_common.h" #include "sgxwallet_common.h"
#include "common.h"
#include "sgxwallet.h" #include "sgxwallet.h"
void generate_SEK(){ void generate_SEK(){
...@@ -40,14 +41,14 @@ void generate_SEK(){ ...@@ -40,14 +41,14 @@ void generate_SEK(){
status = generate_SEK(eid, &err_status, errMsg, encr_SEK, &enc_len); status = generate_SEK(eid, &err_status, errMsg, encr_SEK, &enc_len);
if ( err_status != 0 ){ if ( err_status != 0 ){
std::cerr << "RPCException thrown" << std::endl; cerr << "RPCException thrown" << endl;
throw RPCException(-666, errMsg) ; throw RPCException(-666, errMsg) ;
} }
char *hexEncrKey = (char *) calloc(2*enc_len + 1, 1); char *hexEncrKey = (char *) calloc(2*enc_len + 1, 1);
carray2Hex(encr_SEK, enc_len, hexEncrKey); carray2Hex(encr_SEK, enc_len, hexEncrKey);
std::cegit crr << "key is " << errMsg << std::endl; cerr << "key is " << errMsg << endl;
LevelDB::getLevelDb()->writeDataUnique("SEK", hexEncrKey); LevelDB::getLevelDb()->writeDataUnique("SEK", hexEncrKey);
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#include "LevelDB.h" #include "LevelDB.h"
#include "spdlog/spdlog.h" #include "spdlog/spdlog.h"
#include "common.h"
int DEBUG_PRINT = 0; int DEBUG_PRINT = 0;
int is_sgx_https = 1; int is_sgx_https = 1;
...@@ -64,30 +65,30 @@ SGXRegistrationServer::SGXRegistrationServer(AbstractServerConnector &connector, ...@@ -64,30 +65,30 @@ SGXRegistrationServer::SGXRegistrationServer(AbstractServerConnector &connector,
: AbstractRegServer(connector, type), is_cert_created(false), cert_auto_sign(auto_sign) {} : AbstractRegServer(connector, type), is_cert_created(false), cert_auto_sign(auto_sign) {}
Json::Value SignCertificateImpl(const std::string& csr, bool auto_sign = false){ Json::Value SignCertificateImpl(const string& csr, bool auto_sign = 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");
std::string status = "1"; string status = "1";
std::string hash = cryptlite::sha256::hash_hex(csr); string hash = cryptlite::sha256::hash_hex(csr);
if ( !auto_sign) { if ( !auto_sign) {
std::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 (auto_sign) {
std::string csr_name = "cert/" + hash + ".csr"; string csr_name = "cert/" + hash + ".csr";
std::ofstream outfile(csr_name); ofstream outfile(csr_name);
outfile << csr << std::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");
} }
std::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");
...@@ -95,8 +96,8 @@ Json::Value SignCertificateImpl(const std::string& csr, bool auto_sign = false){ ...@@ -95,8 +96,8 @@ Json::Value SignCertificateImpl(const std::string& csr, bool auto_sign = false){
} }
else{ else{
spdlog::info("CLIENT CERTIFICATE GENERATION FAILED"); spdlog::info("CLIENT CERTIFICATE GENERATION FAILED");
std::string status_db_key = "CSR:HASH:" + hash + "STATUS:"; string status_db_key = "CSR:HASH:" + hash + "STATUS:";
LevelDB::getCsrStatusDb()->writeDataUnique(status_db_key, std::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);
} }
...@@ -105,11 +106,11 @@ Json::Value SignCertificateImpl(const std::string& csr, bool auto_sign = false){ ...@@ -105,11 +106,11 @@ Json::Value SignCertificateImpl(const std::string& csr, bool auto_sign = false){
result["result"] = true; result["result"] = true;
result["hash"] = hash; result["hash"] = hash;
std::string db_key = "CSR:HASH:" + hash + "STATUS:"; string db_key = "CSR:HASH:" + hash + "STATUS:";
LevelDB::getCsrStatusDb()->writeDataUnique(db_key, status); LevelDB::getCsrStatusDb()->writeDataUnique(db_key, status);
} catch (RPCException &_e) { } catch (RPCException &_e) {
std::cerr << " err str " << _e.errString << std::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;
...@@ -118,17 +119,17 @@ Json::Value SignCertificateImpl(const std::string& csr, bool auto_sign = false){ ...@@ -118,17 +119,17 @@ Json::Value SignCertificateImpl(const std::string& csr, bool auto_sign = false){
return result; return result;
} }
Json::Value GetSertificateImpl(const std::string& hash){ Json::Value GetSertificateImpl(const string& hash){
Json::Value result; Json::Value result;
std::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 = std::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";
...@@ -137,7 +138,7 @@ Json::Value GetSertificateImpl(const std::string& hash){ ...@@ -137,7 +138,7 @@ Json::Value GetSertificateImpl(const std::string& hash){
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, std::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;
...@@ -145,9 +146,9 @@ Json::Value GetSertificateImpl(const std::string& hash){ ...@@ -145,9 +146,9 @@ Json::Value GetSertificateImpl(const std::string& hash){
cert = ss.str(); cert = ss.str();
infile.close(); infile.close();
std::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){
//std::cerr << "cert removed" << std::endl; //cerr << "cert removed" << endl;
spdlog::info(" cert removed "); spdlog::info(" cert removed ");
} }
...@@ -162,7 +163,7 @@ Json::Value GetSertificateImpl(const std::string& hash){ ...@@ -162,7 +163,7 @@ Json::Value GetSertificateImpl(const std::string& hash){
result["cert"] = cert; result["cert"] = cert;
} catch (RPCException &_e) { } catch (RPCException &_e) {
std::cerr << " err str " << _e.errString << std::endl; cerr << " err str " << _e.errString << endl;
result["status"] = _e.status; result["status"] = _e.status;
result["errorMessage"] = _e.errString; result["errorMessage"] = _e.errString;
} }
...@@ -171,13 +172,13 @@ Json::Value GetSertificateImpl(const std::string& hash){ ...@@ -171,13 +172,13 @@ Json::Value GetSertificateImpl(const std::string& hash){
} }
Json::Value SGXRegistrationServer::SignCertificate(const std::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, cert_auto_sign);
} }
Json::Value SGXRegistrationServer::GetCertificate(const std::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);
} }
...@@ -191,19 +192,19 @@ void SGXRegistrationServer::set_cert_created(bool b){ ...@@ -191,19 +192,19 @@ void SGXRegistrationServer::set_cert_created(bool b){
int init_registration_server(bool sign_automatically) { int init_registration_server(bool sign_automatically) {
// std::string certPath = "cert/SGXCACertificate.crt"; // string certPath = "cert/SGXCACertificate.crt";
// std::string keyPath = "cert/SGXCACertificate.key"; // string keyPath = "cert/SGXCACertificate.key";
// //
// if (access(certPath.c_str(), F_OK) != 0){ // if (access(certPath.c_str(), F_OK) != 0){
// std::cerr << "CERTIFICATE IS GOING TO BE CREATED" << std::endl; // cerr << "CERTIFICATE IS GOING TO BE CREATED" << endl;
// //
// std::string genCert = "cd cert && ./self-signed-tls -c=US -s=California -l=San-Francisco -o=\"Skale Labs\" -u=\"Department of Software Engineering\" -n=\"SGXCACertificate\" -e=info@skalelabs.com"; // string genCert = "cd cert && ./self-signed-tls -c=US -s=California -l=San-Francisco -o=\"Skale Labs\" -u=\"Department of Software Engineering\" -n=\"SGXCACertificate\" -e=info@skalelabs.com";
// //
// if (system(genCert.c_str()) == 0){ // if (system(genCert.c_str()) == 0){
// std::cerr << "CERTIFICATE IS SUCCESSFULLY GENERATED" << std::endl; // cerr << "CERTIFICATE IS SUCCESSFULLY GENERATED" << endl;
// } // }
// else{ // else{
// std::cerr << "CERTIFICATE GENERATION FAILED" << std::endl; // cerr << "CERTIFICATE GENERATION FAILED" << endl;
// exit(-1); // exit(-1);
// } // }
// } // }
......
...@@ -43,17 +43,13 @@ ...@@ -43,17 +43,13 @@
#include "spdlog/spdlog.h" #include "spdlog/spdlog.h"
//#if __cplusplus < 201412L #include "common.h"
//#error expecting C++17 standard
//#endif
//#include <boost/filesystem.hpp>
bool isStringDec( string & str){
bool isStringDec( std::string & str){ auto res = find_if_not(str.begin(), str.end(), [](char c)->bool{
auto res = std::find_if_not(str.begin(), str.end(), [](char c)->bool{ return isdigit(c);
return std::isdigit(c);
}); });
return !str.empty() && res == str.end(); return !str.empty() && res == str.end();
} }
...@@ -67,11 +63,11 @@ SGXWalletServer::SGXWalletServer(AbstractServerConnector &connector, ...@@ -67,11 +63,11 @@ SGXWalletServer::SGXWalletServer(AbstractServerConnector &connector,
: AbstractStubServer(connector, type) {} : AbstractStubServer(connector, type) {}
void debug_print(){ void debug_print(){
std::cout << "HERE ARE YOUR KEYS: " << std::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){
std::cout << _data << std::endl; cout << _data << endl;
} }
}; };
...@@ -82,14 +78,14 @@ void debug_print(){ ...@@ -82,14 +78,14 @@ void debug_print(){
int init_https_server(bool check_certs) { int init_https_server(bool check_certs) {
std::string rootCAPath = std::string(SGXDATA_FOLDER) + "cert_data/rootCA.pem"; string rootCAPath = string(SGXDATA_FOLDER) + "cert_data/rootCA.pem";
std::string keyCAPath = std::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");
std::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");
...@@ -100,14 +96,14 @@ int init_https_server(bool check_certs) { ...@@ -100,14 +96,14 @@ int init_https_server(bool check_certs) {
} }
} }
std::string certPath = std::string(SGXDATA_FOLDER) + "cert_data/SGXServerCert.crt"; string certPath = string(SGXDATA_FOLDER) + "cert_data/SGXServerCert.crt";
std::string keyPath = std::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");
std::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");
...@@ -146,7 +142,7 @@ int init_http_server() { //without ssl ...@@ -146,7 +142,7 @@ int init_http_server() { //without ssl
} }
Json::Value Json::Value
importBLSKeyShareImpl(const std::string &_keyShare, const std::string &_keyShareName, int t, int n, int index) { importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int t, int n, int index) {
Json::Value result; Json::Value result;
int errStatus = UNKNOWN_ERROR; int errStatus = UNKNOWN_ERROR;
...@@ -182,7 +178,7 @@ importBLSKeyShareImpl(const std::string &_keyShare, const std::string &_keyShare ...@@ -182,7 +178,7 @@ importBLSKeyShareImpl(const std::string &_keyShare, const std::string &_keyShare
return result; return result;
} }
Json::Value blsSignMessageHashImpl(const std::string &keyShareName, const std::string &messageHash,int t, int n, int signerIndex) { Json::Value blsSignMessageHashImpl(const string &keyShareName, const string &messageHash,int t, int n, int signerIndex) {
Json::Value result; Json::Value result;
result["status"] = -1; result["status"] = -1;
result["errorMessage"] = "Unknown server error"; result["errorMessage"] = "Unknown server error";
...@@ -190,13 +186,13 @@ Json::Value blsSignMessageHashImpl(const std::string &keyShareName, const std::s ...@@ -190,13 +186,13 @@ Json::Value blsSignMessageHashImpl(const std::string &keyShareName, const std::s
char *signature = (char *) calloc(BUF_LEN, 1); char *signature = (char *) calloc(BUF_LEN, 1);
shared_ptr <std::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");
} }
std::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);
} }
...@@ -214,7 +210,7 @@ Json::Value blsSignMessageHashImpl(const std::string &keyShareName, const std::s ...@@ -214,7 +210,7 @@ Json::Value blsSignMessageHashImpl(const std::string &keyShareName, const std::s
result["errorMessage"] = _e.errString; result["errorMessage"] = _e.errString;
return result; return result;
} catch (...) { } catch (...) {
std::exception_ptr p = std::current_exception(); exception_ptr p = current_exception();
printf("Exception %s \n", p.__cxa_exception_type()->name()); printf("Exception %s \n", p.__cxa_exception_type()->name());
result["status"] = -1; result["status"] = -1;
result["errorMessage"] = "Read key share has thrown exception:"; result["errorMessage"] = "Read key share has thrown exception:";
...@@ -240,7 +236,7 @@ Json::Value blsSignMessageHashImpl(const std::string &keyShareName, const std::s ...@@ -240,7 +236,7 @@ Json::Value blsSignMessageHashImpl(const std::string &keyShareName, const std::s
} }
Json::Value importECDSAKeyImpl(const std::string &key, const std::string &keyName) { Json::Value importECDSAKeyImpl(const string &key, const string &keyName) {
Json::Value result; Json::Value result;
result["status"] = 0; result["status"] = 0;
result["errorMessage"] = ""; result["errorMessage"] = "";
...@@ -258,7 +254,7 @@ Json::Value generateECDSAKeyImpl() { ...@@ -258,7 +254,7 @@ Json::Value generateECDSAKeyImpl() {
spdlog::info("Calling method generateECDSAKey"); spdlog::info("Calling method generateECDSAKey");
std::vector<std::string>keys; vector<string>keys;
try { try {
keys = gen_ecdsa_key(); keys = gen_ecdsa_key();
...@@ -267,7 +263,7 @@ Json::Value generateECDSAKeyImpl() { ...@@ -267,7 +263,7 @@ Json::Value generateECDSAKeyImpl() {
throw RPCException(UNKNOWN_ERROR, "key was not generated"); throw RPCException(UNKNOWN_ERROR, "key was not generated");
} }
std::string keyName = "NEK:" + keys.at(2); string keyName = "NEK:" + keys.at(2);
if (DEBUG_PRINT) { if (DEBUG_PRINT) {
spdlog::info("write encr key {}", keys.at(0)); spdlog::info("write encr key {}", keys.at(0));
...@@ -282,7 +278,7 @@ Json::Value generateECDSAKeyImpl() { ...@@ -282,7 +278,7 @@ Json::Value generateECDSAKeyImpl() {
result["KeyName"] = keyName; result["KeyName"] = keyName;
} catch (RPCException &_e) { } catch (RPCException &_e) {
std::cerr << " err str " << _e.errString << std::endl; cerr << " err str " << _e.errString << endl;
result["status"] = _e.status; result["status"] = _e.status;
result["errorMessage"] = _e.errString; result["errorMessage"] = _e.errString;
} }
...@@ -290,7 +286,7 @@ Json::Value generateECDSAKeyImpl() { ...@@ -290,7 +286,7 @@ Json::Value generateECDSAKeyImpl() {
return result; return result;
} }
Json::Value renameECDSAKeyImpl(const std::string& KeyName, const std::string& tempKeyName){ Json::Value renameECDSAKeyImpl(const string& KeyName, const string& tempKeyName){
Json::Value result; Json::Value result;
result["status"] = 0; result["status"] = 0;
result["errorMessage"] = ""; result["errorMessage"] = "";
...@@ -298,7 +294,7 @@ Json::Value renameECDSAKeyImpl(const std::string& KeyName, const std::string& te ...@@ -298,7 +294,7 @@ Json::Value renameECDSAKeyImpl(const std::string& KeyName, const std::string& te
try { try {
std::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");
} }
...@@ -306,18 +302,18 @@ Json::Value renameECDSAKeyImpl(const std::string& KeyName, const std::string& te ...@@ -306,18 +302,18 @@ Json::Value renameECDSAKeyImpl(const std::string& KeyName, const std::string& te
if (prefix != "NEK_NODE_ID:") { if (prefix != "NEK_NODE_ID:") {
throw RPCException(UNKNOWN_ERROR, "wrong key name"); throw RPCException(UNKNOWN_ERROR, "wrong key name");
} }
std::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");
} }
std::shared_ptr<std::string> key_ptr = readFromDb(tempKeyName); shared_ptr<string> key_ptr = readFromDb(tempKeyName);
std::cerr << "new key name is " << KeyName <<std::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) {
std::cerr << " err str " << _e.errString << std::endl; cerr << " err str " << _e.errString << endl;
result["status"] = _e.status; result["status"] = _e.status;
result["errorMessage"] = _e.errString; result["errorMessage"] = _e.errString;
} }
...@@ -326,7 +322,7 @@ Json::Value renameECDSAKeyImpl(const std::string& KeyName, const std::string& te ...@@ -326,7 +322,7 @@ Json::Value renameECDSAKeyImpl(const std::string& KeyName, const std::string& te
} }
Json::Value ecdsaSignMessageHashImpl(int base, const std::string &_keyName, const std::string &messageHash) { Json::Value ecdsaSignMessageHashImpl(int base, const string &_keyName, const string &messageHash) {
Json::Value result; Json::Value result;
result["status"] = 0; result["status"] = 0;
result["errorMessage"] = ""; result["errorMessage"] = "";
...@@ -334,7 +330,7 @@ Json::Value ecdsaSignMessageHashImpl(int base, const std::string &_keyName, cons ...@@ -334,7 +330,7 @@ Json::Value ecdsaSignMessageHashImpl(int base, const std::string &_keyName, cons
result["signature_r"] = ""; result["signature_r"] = "";
result["signature_s"] = ""; result["signature_s"] = "";
std::vector<std::string> sign_vect(3); vector<string> sign_vect(3);
if (DEBUG_PRINT) { if (DEBUG_PRINT) {
spdlog::info("entered ecdsaSignMessageHashImpl {}", messageHash, "length {}", messageHash.length()); spdlog::info("entered ecdsaSignMessageHashImpl {}", messageHash, "length {}", messageHash.length());
...@@ -342,7 +338,7 @@ Json::Value ecdsaSignMessageHashImpl(int base, const std::string &_keyName, cons ...@@ -342,7 +338,7 @@ Json::Value ecdsaSignMessageHashImpl(int base, const std::string &_keyName, cons
try { try {
std::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);
} }
...@@ -364,7 +360,7 @@ Json::Value ecdsaSignMessageHashImpl(int base, const std::string &_keyName, cons ...@@ -364,7 +360,7 @@ Json::Value ecdsaSignMessageHashImpl(int base, const std::string &_keyName, cons
throw RPCException(-22, "Invalid base"); throw RPCException(-22, "Invalid base");
} }
std::shared_ptr<std::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 ){
...@@ -380,7 +376,7 @@ Json::Value ecdsaSignMessageHashImpl(int base, const std::string &_keyName, cons ...@@ -380,7 +376,7 @@ Json::Value ecdsaSignMessageHashImpl(int base, const std::string &_keyName, cons
result["signature_s"] = sign_vect.at(2); result["signature_s"] = sign_vect.at(2);
} catch (RPCException &_e) { } catch (RPCException &_e) {
std::cerr << "err str " << _e.errString << std::endl; cerr << "err str " << _e.errString << endl;
result["status"] = _e.status; result["status"] = _e.status;
result["errorMessage"] = _e.errString; result["errorMessage"] = _e.errString;
} }
...@@ -388,7 +384,7 @@ Json::Value ecdsaSignMessageHashImpl(int base, const std::string &_keyName, cons ...@@ -388,7 +384,7 @@ Json::Value ecdsaSignMessageHashImpl(int base, const std::string &_keyName, cons
return result; return result;
} }
Json::Value getPublicECDSAKeyImpl(const std::string& keyName){ Json::Value getPublicECDSAKeyImpl(const string& keyName){
Json::Value result; Json::Value result;
result["status"] = 0; result["status"] = 0;
result["errorMessage"] = ""; result["errorMessage"] = "";
...@@ -396,13 +392,13 @@ Json::Value getPublicECDSAKeyImpl(const std::string& keyName){ ...@@ -396,13 +392,13 @@ Json::Value getPublicECDSAKeyImpl(const std::string& keyName){
spdlog::info("Calling method getPublicECDSAKey"); spdlog::info("Calling method getPublicECDSAKey");
std::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");
} }
std::shared_ptr<std::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 (DEBUG_PRINT) {
spdlog::info("PublicKey {}", Pkey); spdlog::info("PublicKey {}", Pkey);
...@@ -418,14 +414,14 @@ Json::Value getPublicECDSAKeyImpl(const std::string& keyName){ ...@@ -418,14 +414,14 @@ Json::Value getPublicECDSAKeyImpl(const std::string& keyName){
return result; return result;
} }
Json::Value generateDKGPolyImpl(const std::string& polyName, int t) { Json::Value generateDKGPolyImpl(const string& polyName, int t) {
Json::Value result; Json::Value result;
result["status"] = 0; result["status"] = 0;
result["errorMessage"] = ""; result["errorMessage"] = "";
//result["encryptedPoly"] = ""; //result["encryptedPoly"] = "";
std::string encrPolyHex; string encrPolyHex;
try { try {
if ( !checkName(polyName, "POLY")){ if ( !checkName(polyName, "POLY")){
...@@ -439,7 +435,7 @@ Json::Value generateDKGPolyImpl(const std::string& polyName, int t) { ...@@ -439,7 +435,7 @@ Json::Value generateDKGPolyImpl(const std::string& polyName, int t) {
//result["encryptedPoly"] = encrPolyHex; //result["encryptedPoly"] = encrPolyHex;
} catch (RPCException &_e) { } catch (RPCException &_e) {
std::cerr << " err str " << _e.errString << std::endl; cerr << " err str " << _e.errString << endl;
result["status"] = _e.status; result["status"] = _e.status;
result["errorMessage"] = _e.errString; result["errorMessage"] = _e.errString;
} }
...@@ -447,13 +443,13 @@ Json::Value generateDKGPolyImpl(const std::string& polyName, int t) { ...@@ -447,13 +443,13 @@ Json::Value generateDKGPolyImpl(const std::string& polyName, int t) {
return result; return result;
} }
Json::Value getVerificationVectorImpl(const std::string& polyName, int t, int n) { Json::Value getVerificationVectorImpl(const string& polyName, int t, int n) {
Json::Value result; Json::Value result;
result["status"] = 0; result["status"] = 0;
result["errorMessage"] = ""; result["errorMessage"] = "";
std::vector <std::vector<std::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");
...@@ -462,20 +458,20 @@ Json::Value getVerificationVectorImpl(const std::string& polyName, int t, int n) ...@@ -462,20 +458,20 @@ Json::Value getVerificationVectorImpl(const std::string& polyName, int t, int n)
throw RPCException(INVALID_DKG_PARAMS, "Invalid parameters: n or t "); throw RPCException(INVALID_DKG_PARAMS, "Invalid parameters: n or t ");
} }
std::shared_ptr<std::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);
//std::cerr << "verif vect size " << verifVector.size() << std::endl; //cerr << "verif vect size " << verifVector.size() << endl;
for ( int i = 0; i < t; i++){ for ( int i = 0; i < t; i++){
std::vector<std::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["Verification Vector"][i][j] = cur_coef.at(j); result["Verification Vector"][i][j] = cur_coef.at(j);
} }
} }
} catch (RPCException &_e) { } catch (RPCException &_e) {
std::cerr << " err str " << _e.errString << std::endl; cerr << " err str " << _e.errString << endl;
result["status"] = _e.status; result["status"] = _e.status;
result["errorMessage"] = _e.errString; result["errorMessage"] = _e.errString;
result["Verification Vector"] = ""; result["Verification Vector"] = "";
...@@ -484,7 +480,7 @@ Json::Value getVerificationVectorImpl(const std::string& polyName, int t, int n) ...@@ -484,7 +480,7 @@ Json::Value getVerificationVectorImpl(const std::string& polyName, int t, int n)
return result; return result;
} }
Json::Value getSecretShareImpl(const std::string& polyName, const Json::Value& publicKeys, int t, int n){ Json::Value 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;
...@@ -501,9 +497,9 @@ Json::Value getSecretShareImpl(const std::string& polyName, const Json::Value& p ...@@ -501,9 +497,9 @@ Json::Value getSecretShareImpl(const std::string& polyName, const Json::Value& p
throw RPCException(INVALID_DKG_PARAMS, "Invalid DKG parameters: n or t "); throw RPCException(INVALID_DKG_PARAMS, "Invalid DKG parameters: n or t ");
} }
std::shared_ptr<std::string> encr_poly_ptr = readFromDb(polyName); shared_ptr<string> encr_poly_ptr = readFromDb(polyName);
std::vector<std::string> pubKeys_vect; vector<string> pubKeys_vect;
for ( int i = 0; i < n ; i++) { for ( int i = 0; i < n ; i++) {
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");
...@@ -511,12 +507,12 @@ Json::Value getSecretShareImpl(const std::string& polyName, const Json::Value& p ...@@ -511,12 +507,12 @@ Json::Value getSecretShareImpl(const std::string& polyName, const Json::Value& p
pubKeys_vect.push_back(publicKeys[i].asString()); pubKeys_vect.push_back(publicKeys[i].asString());
} }
std::string s = get_secret_shares(polyName, encr_poly_ptr->c_str(), pubKeys_vect, t, n); string s = get_secret_shares(polyName, encr_poly_ptr->c_str(), pubKeys_vect, t, n);
//std::cerr << "result is " << s << std::endl; //cerr << "result is " << s << endl;
result["SecretShare"] = s; result["SecretShare"] = s;
} catch (RPCException &_e) { } catch (RPCException &_e) {
//std::cerr << " err str " << _e.errString << std::endl; //cerr << " err str " << _e.errString << endl;
result["status"] = _e.status; result["status"] = _e.status;
result["errorMessage"] = _e.errString; result["errorMessage"] = _e.errString;
result["SecretShare"] = ""; result["SecretShare"] = "";
...@@ -525,8 +521,8 @@ Json::Value getSecretShareImpl(const std::string& polyName, const Json::Value& p ...@@ -525,8 +521,8 @@ Json::Value getSecretShareImpl(const std::string& polyName, const Json::Value& p
return result; return result;
} }
Json::Value DKGVerificationImpl(const std::string& publicShares, const std::string& EthKeyName, Json::Value DKGVerificationImpl(const string& publicShares, const string& EthKeyName,
const std::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");
...@@ -550,14 +546,14 @@ Json::Value DKGVerificationImpl(const std::string& publicShares, const std::stri ...@@ -550,14 +546,14 @@ Json::Value DKGVerificationImpl(const std::string& publicShares, const std::stri
throw RPCException(INVALID_DKG_PARAMS, "Invalid length of public shares"); throw RPCException(INVALID_DKG_PARAMS, "Invalid length of public shares");
} }
std::shared_ptr<std::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) {
//std::cerr << " err str " << _e.errString << std::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;
...@@ -566,7 +562,7 @@ Json::Value DKGVerificationImpl(const std::string& publicShares, const std::stri ...@@ -566,7 +562,7 @@ Json::Value DKGVerificationImpl(const std::string& publicShares, const std::stri
return result; return result;
} }
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 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");
...@@ -593,12 +589,12 @@ Json::Value CreateBLSPrivateKeyImpl(const std::string & BLSKeyName, const std::s ...@@ -593,12 +589,12 @@ Json::Value CreateBLSPrivateKeyImpl(const std::string & BLSKeyName, const std::s
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 ");
} }
std::vector<std::string> sshares_vect; vector<string> sshares_vect;
if (DEBUG_PRINT) { if (DEBUG_PRINT) {
spdlog::info("secret shares from json are - {}", SecretShare); spdlog::info("secret shares from json are - {}", SecretShare);
} }
std::shared_ptr<std::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){
...@@ -609,14 +605,14 @@ Json::Value CreateBLSPrivateKeyImpl(const std::string & BLSKeyName, const std::s ...@@ -609,14 +605,14 @@ Json::Value CreateBLSPrivateKeyImpl(const std::string & BLSKeyName, const std::s
} }
for ( int i = 0; i < n; i++){ for ( int i = 0; i < n; i++){
std::string name = polyName + "_" + std::to_string(i) + ":"; string name = polyName + "_" + to_string(i) + ":";
LevelDB::getLevelDb() -> deleteDHDKGKey(name); LevelDB::getLevelDb() -> deleteDHDKGKey(name);
std::string shareG2_name = "shareG2_" + polyName + "_" + std::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) {
//std::cerr << " err str " << _e.errString << std::endl; //cerr << " err str " << _e.errString << endl;
result["status"] = _e.status; result["status"] = _e.status;
result["errorMessage"] = _e.errString; result["errorMessage"] = _e.errString;
...@@ -625,7 +621,7 @@ Json::Value CreateBLSPrivateKeyImpl(const std::string & BLSKeyName, const std::s ...@@ -625,7 +621,7 @@ Json::Value CreateBLSPrivateKeyImpl(const std::string & BLSKeyName, const std::s
return result; return result;
} }
Json::Value GetBLSPublicKeyShareImpl(const std::string & BLSKeyName){ Json::Value GetBLSPublicKeyShareImpl(const string & BLSKeyName){
Json::Value result; Json::Value result;
result["status"] = 0; result["status"] = 0;
...@@ -635,20 +631,20 @@ Json::Value GetBLSPublicKeyShareImpl(const std::string & BLSKeyName){ ...@@ -635,20 +631,20 @@ Json::Value GetBLSPublicKeyShareImpl(const std::string & BLSKeyName){
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");
} }
std::shared_ptr<std::string> encryptedKeyHex_ptr = readFromDb(BLSKeyName); shared_ptr<string> encryptedKeyHex_ptr = readFromDb(BLSKeyName);
if (DEBUG_PRINT) { if (DEBUG_PRINT) {
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());
//std::cerr << "encr_bls_key_share is " << *encryptedKeyHex_ptr << std::endl; //cerr << "encr_bls_key_share is " << *encryptedKeyHex_ptr << endl;
// std::cerr << "length is " << encryptedKeyHex_ptr->length() << std::endl; // cerr << "length is " << encryptedKeyHex_ptr->length() << endl;
} }
std::vector<std::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) {
std::cerr << " err str " << _e.errString << std::endl; cerr << " err str " << _e.errString << endl;
result["status"] = _e.status; result["status"] = _e.status;
result["errorMessage"] = _e.errString; result["errorMessage"] = _e.errString;
} }
...@@ -658,7 +654,7 @@ Json::Value GetBLSPublicKeyShareImpl(const std::string & BLSKeyName){ ...@@ -658,7 +654,7 @@ Json::Value GetBLSPublicKeyShareImpl(const std::string & BLSKeyName){
return result; return result;
} }
Json::Value ComplaintResponseImpl(const std::string& polyName, int ind){ Json::Value ComplaintResponseImpl(const string& polyName, int ind){
Json::Value result; Json::Value result;
result["status"] = 0; result["status"] = 0;
result["errorMessage"] = ""; result["errorMessage"] = "";
...@@ -666,16 +662,16 @@ Json::Value ComplaintResponseImpl(const std::string& polyName, int ind){ ...@@ -666,16 +662,16 @@ Json::Value ComplaintResponseImpl(const std::string& polyName, int ind){
if ( !checkName(polyName, "POLY")){ if ( !checkName(polyName, "POLY")){
throw RPCException(INVALID_POLY_NAME, "Invalid polynomial name"); throw RPCException(INVALID_POLY_NAME, "Invalid polynomial name");
} }
std::string shareG2_name = "shareG2_" + polyName + "_" + std::to_string(ind) + ":"; string shareG2_name = "shareG2_" + polyName + "_" + to_string(ind) + ":";
std::shared_ptr<std::string> shareG2_ptr = readFromDb(shareG2_name); shared_ptr<string> shareG2_ptr = readFromDb(shareG2_name);
std::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) {
std::cerr << " err str " << _e.errString << std::endl; cerr << " err str " << _e.errString << endl;
result["status"] = _e.status; result["status"] = _e.status;
result["errorMessage"] = _e.errString; result["errorMessage"] = _e.errString;
} }
...@@ -684,19 +680,19 @@ Json::Value ComplaintResponseImpl(const std::string& polyName, int ind){ ...@@ -684,19 +680,19 @@ Json::Value ComplaintResponseImpl(const std::string& polyName, int ind){
} }
Json::Value MultG2Impl(const std::string& x){ Json::Value 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 ");
std::vector<std::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);
} }
} catch (RPCException &_e) { } catch (RPCException &_e) {
std::cerr << " err str " << _e.errString << std::endl; cerr << " err str " << _e.errString << endl;
result["status"] = _e.status; result["status"] = _e.status;
result["errorMessage"] = _e.errString; result["errorMessage"] = _e.errString;
} }
...@@ -704,10 +700,10 @@ Json::Value MultG2Impl(const std::string& x){ ...@@ -704,10 +700,10 @@ Json::Value MultG2Impl(const std::string& x){
return result; return result;
} }
Json::Value IsPolyExistsImpl(const std::string& polyName){ Json::Value IsPolyExistsImpl(const string& polyName){
Json::Value result; Json::Value result;
std::shared_ptr<std::string> poly_str_ptr = LevelDB::getLevelDb()->readString(polyName); shared_ptr<string> poly_str_ptr = LevelDB::getLevelDb()->readString(polyName);
result["IsExist"] = true; result["IsExist"] = true;
if (poly_str_ptr == nullptr){ if (poly_str_ptr == nullptr){
result["IsExist"] = false; result["IsExist"] = false;
...@@ -726,33 +722,33 @@ Json::Value getServerStatusImpl() { ...@@ -726,33 +722,33 @@ Json::Value getServerStatusImpl() {
} }
Json::Value SGXWalletServer::generateDKGPoly(const std::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 std::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 std::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 std::string& publicShares, const std::string& EthKeyName, const std::string& SecretShare, int t, int n, int index){ Json::Value SGXWalletServer::DKGVerification( const string& publicShares, const string& EthKeyName, const string& SecretShare, int t, int n, int index){
lock_guard<recursive_mutex> lock(m); lock_guard<recursive_mutex> lock(m);
return DKGVerificationImpl(publicShares, EthKeyName, SecretShare, t, n, index); return DKGVerificationImpl(publicShares, EthKeyName, SecretShare, t, n, index);
} }
Json::Value SGXWalletServer::CreateBLSPrivateKey(const std::string & BLSKeyName, const std::string& EthKeyName, const std::string& polyName, const std::string& SecretShare, int t, int n){ Json::Value SGXWalletServer::CreateBLSPrivateKey(const string & BLSKeyName, const string& EthKeyName, const string& polyName, const string& SecretShare, int t, int n){
lock_guard<recursive_mutex> lock(m); lock_guard<recursive_mutex> lock(m);
return CreateBLSPrivateKeyImpl(BLSKeyName, EthKeyName, polyName, SecretShare, t, n); return CreateBLSPrivateKeyImpl(BLSKeyName, EthKeyName, polyName, SecretShare, t, n);
} }
Json::Value SGXWalletServer::GetBLSPublicKeyShare(const std::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);
} }
...@@ -764,18 +760,18 @@ Json::Value SGXWalletServer::generateECDSAKey() { ...@@ -764,18 +760,18 @@ Json::Value SGXWalletServer::generateECDSAKey() {
return generateECDSAKeyImpl(); return generateECDSAKeyImpl();
} }
Json::Value SGXWalletServer::renameECDSAKey(const std::string& KeyName, const std::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 std::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 std::string &_keyName, const std::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 (DEBUG_PRINT) {
...@@ -786,34 +782,34 @@ Json::Value SGXWalletServer::ecdsaSignMessageHash(int base, const std::string &_ ...@@ -786,34 +782,34 @@ Json::Value SGXWalletServer::ecdsaSignMessageHash(int base, const std::string &_
Json::Value Json::Value
SGXWalletServer::importBLSKeyShare(const std::string &_keyShare, const std::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 std::string &keyShareName, const std::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 std::string &key, const std::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 std::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 std::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 std::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);
} }
...@@ -856,7 +852,7 @@ void writeKeyShare(const string &_keyShareName, const string &value, int index, ...@@ -856,7 +852,7 @@ void writeKeyShare(const string &_keyShareName, const string &value, int index,
val["index"] = index; val["index"] = index;
val["n'"] = n; val["n'"] = n;
std::string json = writer.write(val); string json = writer.write(val);
auto key = "BLSKEYSHARE:" + _keyShareName; auto key = "BLSKEYSHARE:" + _keyShareName;
...@@ -872,7 +868,7 @@ void writeDataToDB(const string & Name, const string &value) { ...@@ -872,7 +868,7 @@ void writeDataToDB(const string & Name, const string &value) {
Json::FastWriter writer; Json::FastWriter writer;
val["value"] = value; val["value"] = value;
std::string json = writer.write(val); string json = writer.write(val);
auto key = Name; auto key = Name;
......
...@@ -28,14 +28,15 @@ ...@@ -28,14 +28,15 @@
#include <iostream> #include <iostream>
#include "spdlog/spdlog.h" #include "spdlog/spdlog.h"
#include "common.h"
std::vector<std::string> SplitString(const std::string& str, const std::string& delim = ":"){ vector<string> SplitString(const string& str, const string& delim = ":"){
std::vector<std::string> tokens; vector<string> tokens;
size_t prev = 0, pos = 0; size_t prev = 0, pos = 0;
do { do {
pos = str.find(delim, prev); pos = str.find(delim, prev);
if (pos == std::string::npos) pos = str.length(); if (pos == string::npos) pos = str.length();
std::string token = str.substr(prev, pos-prev); string token = str.substr(prev, pos-prev);
if (!token.empty()) tokens.push_back(token); if (!token.empty()) tokens.push_back(token);
prev = pos + delim.length(); prev = pos + delim.length();
} while (pos < str.length() && prev < str.length()); } while (pos < str.length() && prev < str.length());
...@@ -43,8 +44,8 @@ std::vector<std::string> SplitString(const std::string& str, const std::string& ...@@ -43,8 +44,8 @@ std::vector<std::string> SplitString(const std::string& str, const std::string&
return tokens; return tokens;
} }
bool checkECDSAKeyName(const std::string& keyName) { bool checkECDSAKeyName(const string& keyName) {
std::vector<std::string> parts = SplitString(keyName); vector<string> parts = SplitString(keyName);
if (parts.size() != 2) { if (parts.size() != 2) {
spdlog::info("ECDSAKeyName num parts != 2"); spdlog::info("ECDSAKeyName num parts != 2");
return false; return false;
...@@ -69,7 +70,7 @@ bool checkECDSAKeyName(const std::string& keyName) { ...@@ -69,7 +70,7 @@ bool checkECDSAKeyName(const std::string& keyName) {
return true; return true;
} }
bool checkHex(const std::string& hex, const uint32_t sizeInBytes){ bool checkHex(const string& hex, const uint32_t sizeInBytes){
if ( hex.length() > sizeInBytes * 2 || hex.length() == 0){ if ( hex.length() > sizeInBytes * 2 || hex.length() == 0){
return false; return false;
} }
...@@ -86,8 +87,8 @@ bool checkHex(const std::string& hex, const uint32_t sizeInBytes){ ...@@ -86,8 +87,8 @@ bool checkHex(const std::string& hex, const uint32_t sizeInBytes){
return true; return true;
} }
bool checkName (const std::string& Name, const std::string& prefix){ bool checkName (const string& Name, const string& prefix){
std::vector<std::string> parts = SplitString(Name); vector<string> parts = SplitString(Name);
if ( parts.size() != 7) { if ( parts.size() != 7) {
spdlog::info("parts.size() != 7"); spdlog::info("parts.size() != 7");
return false; return false;
......
/usr/share/automake-1.16/compile
\ No newline at end of file
/usr/share/automake-1.16/depcomp
\ No newline at end of file
/usr/share/automake-1.16/install-sh
\ No newline at end of file
/usr/share/automake-1.16/missing
\ No newline at end of file
...@@ -79,10 +79,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ...@@ -79,10 +79,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "BLSPublicKey.h" #include "BLSPublicKey.h"
#include <thread> #include <thread>
#include "common.h"
std::string stringFromFr(libff::alt_bn128_Fr& el) { string stringFromFr(libff::alt_bn128_Fr& el) {
mpz_t t; mpz_t t;
mpz_init(t); mpz_init(t);
...@@ -94,7 +95,7 @@ std::string stringFromFr(libff::alt_bn128_Fr& el) { ...@@ -94,7 +95,7 @@ std::string stringFromFr(libff::alt_bn128_Fr& el) {
char *tmp = mpz_get_str(arr, 10, t); char *tmp = mpz_get_str(arr, 10, t);
mpz_clear(t); mpz_clear(t);
return std::string(tmp); return string(tmp);
} }
...@@ -313,17 +314,17 @@ TEST_CASE( "DKG gen test", "[dkg-gen]" ) { ...@@ -313,17 +314,17 @@ TEST_CASE( "DKG gen test", "[dkg-gen]" ) {
sgx_destroy_enclave(eid); sgx_destroy_enclave(eid);
} }
std::vector<libff::alt_bn128_Fr> SplitStringToFr(const char* koefs, const char symbol){ vector<libff::alt_bn128_Fr> SplitStringToFr(const char* koefs, const char symbol){
std::string str(koefs); string str(koefs);
std::string delim; string delim;
delim.push_back(symbol); delim.push_back(symbol);
std::vector<libff::alt_bn128_Fr> tokens; vector<libff::alt_bn128_Fr> tokens;
size_t prev = 0, pos = 0; size_t prev = 0, pos = 0;
do do
{ {
pos = str.find(delim, prev); pos = str.find(delim, prev);
if (pos == std::string::npos) pos = str.length(); if (pos == string::npos) pos = str.length();
std::string token = str.substr(prev, pos-prev); string token = str.substr(prev, pos-prev);
if (!token.empty()) { if (!token.empty()) {
libff::alt_bn128_Fr koef(token.c_str()); libff::alt_bn128_Fr koef(token.c_str());
tokens.push_back(koef); tokens.push_back(koef);
...@@ -335,20 +336,20 @@ std::vector<libff::alt_bn128_Fr> SplitStringToFr(const char* koefs, const char s ...@@ -335,20 +336,20 @@ std::vector<libff::alt_bn128_Fr> SplitStringToFr(const char* koefs, const char s
return tokens; return tokens;
} }
std::vector<std::string> SplitStringTest(const char* koefs, const char symbol){ vector<string> SplitStringTest(const char* koefs, const char symbol){
libff::init_alt_bn128_params(); libff::init_alt_bn128_params();
std::string str(koefs); string str(koefs);
std::string delim; string delim;
delim.push_back(symbol); delim.push_back(symbol);
std::vector<std::string> G2_strings; vector<string> G2_strings;
size_t prev = 0, pos = 0; size_t prev = 0, pos = 0;
do do
{ {
pos = str.find(delim, prev); pos = str.find(delim, prev);
if (pos == std::string::npos) pos = str.length(); if (pos == string::npos) pos = str.length();
std::string token = str.substr(prev, pos-prev); string token = str.substr(prev, pos-prev);
if (!token.empty()) { if (!token.empty()) {
std::string koef(token.c_str()); string koef(token.c_str());
G2_strings.push_back(koef); G2_strings.push_back(koef);
} }
prev = pos + delim.length(); prev = pos + delim.length();
...@@ -358,7 +359,7 @@ std::vector<std::string> SplitStringTest(const char* koefs, const char symbol){ ...@@ -358,7 +359,7 @@ std::vector<std::string> SplitStringTest(const char* koefs, const char symbol){
return G2_strings; return G2_strings;
} }
libff::alt_bn128_G2 VectStringToG2(const std::vector<std::string>& G2_str_vect){ libff::alt_bn128_G2 VectStringToG2(const vector<string>& G2_str_vect){
libff::init_alt_bn128_params(); libff::init_alt_bn128_params();
libff::alt_bn128_G2 koef = libff::alt_bn128_G2::zero(); libff::alt_bn128_G2 koef = libff::alt_bn128_G2::zero();
koef.X.c0 = libff::alt_bn128_Fq(G2_str_vect.at(0).c_str()); koef.X.c0 = libff::alt_bn128_Fq(G2_str_vect.at(0).c_str());
...@@ -406,7 +407,7 @@ libff::alt_bn128_G2 VectStringToG2(const std::vector<std::string>& G2_str_vect){ ...@@ -406,7 +407,7 @@ libff::alt_bn128_G2 VectStringToG2(const std::vector<std::string>& G2_str_vect){
printf("\nget_secret_shares status: %d %s \n", err_status, errMsg1); printf("\nget_secret_shares status: %d %s \n", err_status, errMsg1);
printf("secret shares %s \n\n", secret_shares); printf("secret shares %s \n\n", secret_shares);
std::vector <libff::alt_bn128_Fr> s_shares = SplitStringToFr( secret_shares, colon); vector <libff::alt_bn128_Fr> s_shares = SplitStringToFr( secret_shares, colon);
char* secret = (char*)calloc(DKG_BUFER_LENGTH, sizeof(char)); char* secret = (char*)calloc(DKG_BUFER_LENGTH, sizeof(char));
status = decrypt_dkg_secret(eid, &err_status, errMsg1, encrypted_dkg_secret, (uint8_t*)secret, &dec_len); status = decrypt_dkg_secret(eid, &err_status, errMsg1, encrypted_dkg_secret, (uint8_t*)secret, &dec_len);
...@@ -415,8 +416,8 @@ libff::alt_bn128_G2 VectStringToG2(const std::vector<std::string>& G2_str_vect){ ...@@ -415,8 +416,8 @@ libff::alt_bn128_G2 VectStringToG2(const std::vector<std::string>& G2_str_vect){
signatures::Dkg dkg_obj(t,n); signatures::Dkg dkg_obj(t,n);
std::vector < libff::alt_bn128_Fr> poly = SplitStringToFr((char*)secret, colon); vector < libff::alt_bn128_Fr> poly = SplitStringToFr((char*)secret, colon);
std::vector < libff::alt_bn128_Fr> s_shares_dkg = dkg_obj.SecretKeyContribution(SplitStringToFr((char*)secret, colon)); vector < libff::alt_bn128_Fr> s_shares_dkg = dkg_obj.SecretKeyContribution(SplitStringToFr((char*)secret, colon));
printf("calculated secret length %d : \n", s_shares_dkg.size()); printf("calculated secret length %d : \n", s_shares_dkg.size());
for ( int i = 0; i < s_shares_dkg.size(); i++){ for ( int i = 0; i < s_shares_dkg.size(); i++){
libff::alt_bn128_Fr cur_share = s_shares_dkg.at(i); libff::alt_bn128_Fr cur_share = s_shares_dkg.at(i);
...@@ -467,12 +468,12 @@ TEST_CASE( "DKG public shares test", "[dkg-pub_shares]" ) { ...@@ -467,12 +468,12 @@ TEST_CASE( "DKG public shares test", "[dkg-pub_shares]" ) {
printf(" LEN: %d \n", strlen(public_shares)); printf(" LEN: %d \n", strlen(public_shares));
printf(" result: %s \n", public_shares); printf(" result: %s \n", public_shares);
std::vector <std::string> G2_strings = SplitString( public_shares, ','); vector <string> G2_strings = SplitString( public_shares, ',');
std::vector <libff::alt_bn128_G2> pub_shares_G2; vector <libff::alt_bn128_G2> pub_shares_G2;
for ( int i = 0; i < G2_strings.size(); i++){ for ( int i = 0; i < G2_strings.size(); i++){
std::vector <std::string> koef_str = SplitString(G2_strings.at(i).c_str(), ':'); vector <string> koef_str = SplitString(G2_strings.at(i).c_str(), ':');
libff::alt_bn128_G2 el = VectStringToG2(koef_str); libff::alt_bn128_G2 el = VectStringToG2(koef_str);
//std::cerr << "pub_share G2 " << i+1 << " : " << std::endl; //cerr << "pub_share G2 " << i+1 << " : " << endl;
//el.print_coordinates(); //el.print_coordinates();
pub_shares_G2.push_back(VectStringToG2(koef_str)); pub_shares_G2.push_back(VectStringToG2(koef_str));
} }
...@@ -484,8 +485,8 @@ TEST_CASE( "DKG public shares test", "[dkg-pub_shares]" ) { ...@@ -484,8 +485,8 @@ TEST_CASE( "DKG public shares test", "[dkg-pub_shares]" ) {
signatures::Dkg dkg_obj(t,n); signatures::Dkg dkg_obj(t,n);
std::vector < libff::alt_bn128_Fr> poly = SplitStringToFr((char*)secret, colon); vector < libff::alt_bn128_Fr> poly = SplitStringToFr((char*)secret, colon);
std::vector < libff::alt_bn128_G2> pub_shares_dkg = dkg_obj.VerificationVector(poly); vector < libff::alt_bn128_G2> pub_shares_dkg = dkg_obj.VerificationVector(poly);
printf("calculated public shares (X.c0): \n"); printf("calculated public shares (X.c0): \n");
for ( int i = 0; i < pub_shares_dkg.size(); i++){ for ( int i = 0; i < pub_shares_dkg.size(); i++){
libff::alt_bn128_G2 el = pub_shares_dkg.at(i); libff::alt_bn128_G2 el = pub_shares_dkg.at(i);
...@@ -529,11 +530,11 @@ TEST_CASE( "DKG encrypted secret shares test", "[dkg-encr_sshares]" ) { ...@@ -529,11 +530,11 @@ TEST_CASE( "DKG encrypted secret shares test", "[dkg-encr_sshares]" ) {
status = gen_dkg_secret (eid, &err_status, errMsg, encrypted_dkg_secret, &enc_len, 2); status = gen_dkg_secret (eid, &err_status, errMsg, encrypted_dkg_secret, &enc_len, 2);
REQUIRE(status == SGX_SUCCESS); REQUIRE(status == SGX_SUCCESS);
std::cerr << " poly generated" << std::endl; cerr << " poly generated" << endl;
status = set_encrypted_dkg_poly(eid, &err_status, errMsg, encrypted_dkg_secret); status = set_encrypted_dkg_poly(eid, &err_status, errMsg, encrypted_dkg_secret);
REQUIRE(status == SGX_SUCCESS); REQUIRE(status == SGX_SUCCESS);
std::cerr << " poly set" << std::endl; cerr << " poly set" << endl;
uint8_t *encr_pr_DHkey = (uint8_t *)calloc(1024, 1); uint8_t *encr_pr_DHkey = (uint8_t *)calloc(1024, 1);
char *pub_key_x = (char *)calloc(1024, 1); char *pub_key_x = (char *)calloc(1024, 1);
...@@ -546,7 +547,7 @@ TEST_CASE( "DKG encrypted secret shares test", "[dkg-encr_sshares]" ) { ...@@ -546,7 +547,7 @@ TEST_CASE( "DKG encrypted secret shares test", "[dkg-encr_sshares]" ) {
REQUIRE(status == SGX_SUCCESS); REQUIRE(status == SGX_SUCCESS);
printf(" get_encr_sshare completed with status: %d %s \n", err_status, errMsg); printf(" get_encr_sshare completed with status: %d %s \n", err_status, errMsg);
std::cerr << "secret share is " << result << std::endl; cerr << "secret share is " << result << endl;
} }
TEST_CASE( "DKG verification test", "[dkg-verify]" ) { TEST_CASE( "DKG verification test", "[dkg-verify]" ) {
...@@ -567,11 +568,11 @@ TEST_CASE( "DKG verification test", "[dkg-verify]" ) { ...@@ -567,11 +568,11 @@ TEST_CASE( "DKG verification test", "[dkg-verify]" ) {
status = gen_dkg_secret (eid, &err_status, errMsg, encrypted_dkg_secret, &enc_len, 2); status = gen_dkg_secret (eid, &err_status, errMsg, encrypted_dkg_secret, &enc_len, 2);
REQUIRE(status == SGX_SUCCESS); REQUIRE(status == SGX_SUCCESS);
std::cerr << " poly generated" << std::endl; cerr << " poly generated" << endl;
status = set_encrypted_dkg_poly(eid, &err_status, errMsg, encrypted_dkg_secret); status = set_encrypted_dkg_poly(eid, &err_status, errMsg, encrypted_dkg_secret);
REQUIRE(status == SGX_SUCCESS); REQUIRE(status == SGX_SUCCESS);
std::cerr << " poly set" << std::endl; cerr << " poly set" << endl;
uint8_t *encr_pr_DHkey = (uint8_t *)calloc(1024, 1); uint8_t *encr_pr_DHkey = (uint8_t *)calloc(1024, 1);
char *pub_key_x = (char *)calloc(1024, 1); char *pub_key_x = (char *)calloc(1024, 1);
...@@ -585,7 +586,7 @@ TEST_CASE( "DKG verification test", "[dkg-verify]" ) { ...@@ -585,7 +586,7 @@ TEST_CASE( "DKG verification test", "[dkg-verify]" ) {
REQUIRE(status == SGX_SUCCESS); REQUIRE(status == SGX_SUCCESS);
printf(" get_encr_sshare completed with status: %d %s \n", err_status, errMsg); printf(" get_encr_sshare completed with status: %d %s \n", err_status, errMsg);
std::cerr << "secret share is " << result << std::endl; cerr << "secret share is " << result << endl;
} }
...@@ -723,8 +724,8 @@ TEST_CASE( "pub_bls_key", "[pub_bls]" ) { ...@@ -723,8 +724,8 @@ TEST_CASE( "pub_bls_key", "[pub_bls]" ) {
char *encryptedKeyHex = char *encryptedKeyHex =
"04000200000000000406ffffff02000000000000000000000b000000000000ff0000000000000000813f8390f6228a568e181a4dadb6508e3e66f5247175d65dbd0d8c7fbfa4df45000000f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000008000000000000000000000000000000000dc044ae0cd79faaf41e8a7abb412790476738a98b5b6ce95fa1a32db5551b0a0d867305f4de558c64fee730a1f62394633c7d4ca65e3a40b7883e89c2801c61918b01c5de8624a52963df6f4de8581bcbdd2f9b69720d4cc764e03a04c7a99314bfdb5d2d55deda2ca40cd691f093fb2ecbae24cdacdd4d5de93189c6dfd6792d7b95bd5e330aec3538e7a85d15793"; // encryptTestKey(); "04000200000000000406ffffff02000000000000000000000b000000000000ff0000000000000000813f8390f6228a568e181a4dadb6508e3e66f5247175d65dbd0d8c7fbfa4df45000000f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000008000000000000000000000000000000000dc044ae0cd79faaf41e8a7abb412790476738a98b5b6ce95fa1a32db5551b0a0d867305f4de558c64fee730a1f62394633c7d4ca65e3a40b7883e89c2801c61918b01c5de8624a52963df6f4de8581bcbdd2f9b69720d4cc764e03a04c7a99314bfdb5d2d55deda2ca40cd691f093fb2ecbae24cdacdd4d5de93189c6dfd6792d7b95bd5e330aec3538e7a85d15793"; // encryptTestKey();
//writeDataToDB("test_bls_key0", encryptedKeyHex); //writeDataToDB("test_bls_key0", encryptedKeyHex);
std::vector<std::string> result = GetBLSPubKey(encryptedKeyHex); vector<string> result = GetBLSPubKey(encryptedKeyHex);
//std::cerr << "pub key " << result << std::endl; //cerr << "pub key " << result << endl;
sgx_destroy_enclave(eid); sgx_destroy_enclave(eid);
} }
...@@ -734,7 +735,7 @@ TEST_CASE( "pub_bls_key", "[pub_bls]" ) { ...@@ -734,7 +735,7 @@ TEST_CASE( "pub_bls_key", "[pub_bls]" ) {
using namespace jsonrpc; using namespace jsonrpc;
using namespace std; using namespace std;
std::string ConvertDecToHex(std::string dec, int numBytes = 32){ string ConvertDecToHex(string dec, int numBytes = 32){
mpz_t num; mpz_t num;
mpz_init(num); mpz_init(num);
mpz_set_str(num, dec.c_str(), 10); mpz_set_str(num, dec.c_str(), 10);
...@@ -742,7 +743,7 @@ std::string ConvertDecToHex(std::string dec, int numBytes = 32){ ...@@ -742,7 +743,7 @@ std::string ConvertDecToHex(std::string dec, int numBytes = 32){
char tmp[mpz_sizeinbase (num, 16) + 2]; char tmp[mpz_sizeinbase (num, 16) + 2];
char * hex = mpz_get_str(tmp, 16, num); char * hex = mpz_get_str(tmp, 16, num);
std::string result = hex; string result = hex;
int n_zeroes = numBytes * 2 - result.length(); int n_zeroes = numBytes * 2 - result.length();
result.insert(0, n_zeroes, '0'); result.insert(0, n_zeroes, '0');
...@@ -753,7 +754,7 @@ std::string ConvertDecToHex(std::string dec, int numBytes = 32){ ...@@ -753,7 +754,7 @@ std::string ConvertDecToHex(std::string dec, int numBytes = 32){
TEST_CASE("BLS_DKG test", "[bls_dkg]") { TEST_CASE("BLS_DKG test", "[bls_dkg]") {
is_sgx_https = 0; is_sgx_https = 0;
DEBUG_PRINT = 1; DEBUG_PRINT = 1;
std::cerr<< "test started" << std::endl; cerr<< "test started" << endl;
init_all(false, false); init_all(false, false);
cerr << "Server inited" << endl; cerr << "Server inited" << endl;
HttpClient client("http://localhost:1029"); HttpClient client("http://localhost:1029");
...@@ -770,16 +771,16 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") { ...@@ -770,16 +771,16 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
Json::Value secretShares[n]; Json::Value secretShares[n];
Json::Value pubBLSKeys[n]; Json::Value pubBLSKeys[n];
Json::Value BLSSigShares[n]; Json::Value BLSSigShares[n];
std::vector<std::string> pubShares(n); vector<string> pubShares(n);
std::vector<std::string> poly_names(n); vector<string> poly_names(n);
for ( uint8_t i = 0; i < n; i++){ for ( uint8_t i = 0; i < n; i++){
EthKeys[i] = c.generateECDSAKey(); EthKeys[i] = c.generateECDSAKey();
std::string polyName = "POLY:SCHAIN_ID:1:NODE_ID:" + std::to_string(i) + ":DKG_ID:0"; string polyName = "POLY:SCHAIN_ID:1:NODE_ID:" + to_string(i) + ":DKG_ID:0";
c.generateDKGPoly(polyName, t); c.generateDKGPoly(polyName, t);
poly_names[i] = polyName; poly_names[i] = polyName;
VerifVects[i] = c.getVerificationVector(polyName, t, n); VerifVects[i] = c.getVerificationVector(polyName, t, n);
cout << "VV " << i << " " << VerifVects[i] << std::endl; cout << "VV " << i << " " << VerifVects[i] << endl;
pubEthKeys.append(EthKeys[i]["PublicKey"]); pubEthKeys.append(EthKeys[i]["PublicKey"]);
} }
...@@ -788,88 +789,88 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") { ...@@ -788,88 +789,88 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
secretShares[i] = c.getSecretShare(poly_names[i], pubEthKeys, t, n); secretShares[i] = c.getSecretShare(poly_names[i], pubEthKeys, t, n);
for ( uint8_t k = 0; k < t; k++ ) { for ( uint8_t k = 0; k < t; k++ ) {
for (uint8_t j = 0; j < 4; j++) { for (uint8_t j = 0; j < 4; j++) {
std::string pubShare = VerifVects[i]["Verification Vector"][k][j].asString(); string pubShare = VerifVects[i]["Verification Vector"][k][j].asString();
pubShares[i] += ConvertDecToHex(pubShare); pubShares[i] += ConvertDecToHex(pubShare);
} }
} }
// std::cerr << "i is " << i << " pubShares[i] = " << pubShares[i] << std::endl; // cerr << "i is " << i << " pubShares[i] = " << pubShares[i] << endl;
// std::cerr << "length is" << pubShares[i].length() << std::endl; // cerr << "length is" << pubShares[i].length() << endl;
} }
Json::Value ComplaintResponse = c.ComplaintResponse(poly_names[1], 0); Json::Value ComplaintResponse = c.ComplaintResponse(poly_names[1], 0);
std::cerr << "share * G2 is " << ComplaintResponse["share*G2"].asString(); cerr << "share * G2 is " << ComplaintResponse["share*G2"].asString();
std::cerr << "DHKey is " << ComplaintResponse["DHKey"].asString(); cerr << "DHKey is " << ComplaintResponse["DHKey"].asString();
int k = 0; int k = 0;
std::vector < std::string> secShares_vect(n); vector < string> secShares_vect(n);
std::vector <std::string> pSharesBad(pubShares); vector <string> pSharesBad(pubShares);
for ( int i = 0; i < n; i++) for ( int i = 0; i < n; i++)
for ( int j = 0; j < n; j++){ for ( int j = 0; j < n; j++){
// if ( i != j ){ // if ( i != j ){
std::cerr << "SecretShare length is " << secretShares[i]["SecretShare"].asString().length() << std::endl; cerr << "SecretShare length is " << secretShares[i]["SecretShare"].asString().length() << endl;
std::string secretShare = secretShares[i]["SecretShare"].asString().substr(192*j, 192); string secretShare = secretShares[i]["SecretShare"].asString().substr(192*j, 192);
secShares_vect[i] += secretShares[j]["SecretShare"].asString().substr(192*i, 192); secShares_vect[i] += secretShares[j]["SecretShare"].asString().substr(192*i, 192);
bool res = c.DKGVerification(pubShares[i], EthKeys[j]["KeyName"].asString(), secretShare, t, n, j)["result"].asBool(); bool res = c.DKGVerification(pubShares[i], EthKeys[j]["KeyName"].asString(), secretShare, t, n, j)["result"].asBool();
k++; k++;
std::cerr << "NOW K IS " << k << " i is " << i << " j is " << j << std::endl; cerr << "NOW K IS " << k << " i is " << i << " j is " << j << endl;
REQUIRE(res); REQUIRE(res);
pSharesBad[i][0] = 'q'; pSharesBad[i][0] = 'q';
Json::Value wrongVerif = c.DKGVerification(pSharesBad[i], EthKeys[j]["KeyName"].asString(), secretShare, t, n, j); Json::Value wrongVerif = c.DKGVerification(pSharesBad[i], EthKeys[j]["KeyName"].asString(), secretShare, t, n, j);
res = wrongVerif["result"].asBool(); res = wrongVerif["result"].asBool();
REQUIRE(!res); REQUIRE(!res);
std::cerr << "wrong verification " << wrongVerif << std::endl; cerr << "wrong verification " << wrongVerif << endl;
// } // }
} }
BLSSigShareSet sigShareSet(t, n); BLSSigShareSet sigShareSet(t, n);
std::string hash = "09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"; string hash = "09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db";
auto hash_arr = std::make_shared<std::array<uint8_t, 32>>(); auto hash_arr = make_shared<array<uint8_t, 32>>();
uint64_t binLen; uint64_t binLen;
if (!hex2carray(hash.c_str(), &binLen, hash_arr->data())){ if (!hex2carray(hash.c_str(), &binLen, hash_arr->data())){
throw RPCException(INVALID_HEX, "Invalid hash"); throw RPCException(INVALID_HEX, "Invalid hash");
} }
std::map<size_t, std::shared_ptr<BLSPublicKeyShare>> koefs_pkeys_map; map<size_t, shared_ptr<BLSPublicKeyShare>> koefs_pkeys_map;
for ( int i = 0; i < t; i++){ for ( int i = 0; i < t; i++){
std::string endName = poly_names[i].substr(4); string endName = poly_names[i].substr(4);
std::string blsName = "BLS_KEY" + poly_names[i].substr(4); string blsName = "BLS_KEY" + poly_names[i].substr(4);
std::string secretShare = secretShares[i]["SecretShare"].asString(); string secretShare = secretShares[i]["SecretShare"].asString();
//cout << c.CreateBLSPrivateKey(blsName, EthKeys[i]["KeyName"].asString(), poly_names[i], secretShare, t, n); //cout << c.CreateBLSPrivateKey(blsName, EthKeys[i]["KeyName"].asString(), poly_names[i], secretShare, t, n);
cout << c.CreateBLSPrivateKey(blsName, EthKeys[i]["KeyName"].asString(), poly_names[i], secShares_vect[i], t, n); cout << c.CreateBLSPrivateKey(blsName, EthKeys[i]["KeyName"].asString(), poly_names[i], secShares_vect[i], t, n);
pubBLSKeys[i] = c.GetBLSPublicKeyShare(blsName); pubBLSKeys[i] = c.GetBLSPublicKeyShare(blsName);
std::cerr << "BLS KEY SHARE NAME IS " << blsName << std::endl; cerr << "BLS KEY SHARE NAME IS " << blsName << endl;
//std::string hash = "09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"; //string hash = "09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db";
BLSSigShares[i] = c.blsSignMessageHash(blsName, hash, t, n, i + 1); BLSSigShares[i] = c.blsSignMessageHash(blsName, hash, t, n, i + 1);
std::cerr << i << " sig share is created " << std::endl; cerr << i << " sig share is created " << endl;
std::shared_ptr<std::string> sig_share_ptr = std::make_shared<std::string>(BLSSigShares[i]["signatureShare"].asString()); shared_ptr<string> sig_share_ptr = make_shared<string>(BLSSigShares[i]["signatureShare"].asString());
BLSSigShare sig(sig_share_ptr, i + 1, t, n); BLSSigShare sig(sig_share_ptr, i + 1, t, n);
sigShareSet.addSigShare(std::make_shared<BLSSigShare>(sig)); sigShareSet.addSigShare(make_shared<BLSSigShare>(sig));
std::vector<std::string> pubKey_vect; vector<string> pubKey_vect;
for ( uint8_t j = 0; j < 4; j++){ for ( uint8_t j = 0; j < 4; j++){
pubKey_vect.push_back(pubBLSKeys[i]["BLSPublicKeyShare"][j].asString()); pubKey_vect.push_back(pubBLSKeys[i]["BLSPublicKeyShare"][j].asString());
} }
BLSPublicKeyShare pubKey(std::make_shared<std::vector<std::string>>(pubKey_vect), t, n); BLSPublicKeyShare pubKey(make_shared<vector<string>>(pubKey_vect), t, n);
REQUIRE( pubKey.VerifySigWithHelper(hash_arr, std::make_shared<BLSSigShare>(sig) , t, n)); REQUIRE( pubKey.VerifySigWithHelper(hash_arr, make_shared<BLSSigShare>(sig) , t, n));
koefs_pkeys_map[i+1] = std::make_shared<BLSPublicKeyShare>(pubKey); koefs_pkeys_map[i+1] = make_shared<BLSPublicKeyShare>(pubKey);
} }
std::shared_ptr<BLSSignature> commonSig = sigShareSet.merge(); shared_ptr<BLSSignature> commonSig = sigShareSet.merge();
BLSPublicKey common_public(std::make_shared<std::map<size_t, std::shared_ptr<BLSPublicKeyShare>>>(koefs_pkeys_map), t, n); BLSPublicKey common_public(make_shared<map<size_t, shared_ptr<BLSPublicKeyShare>>>(koefs_pkeys_map), t, n);
REQUIRE( common_public.VerifySigWithHelper(hash_arr, commonSig, t, n) ); REQUIRE( common_public.VerifySigWithHelper(hash_arr, commonSig, t, n) );
std::cout << "try to get bls public key" << std::endl; cout << "try to get bls public key" << endl;
std::cout << c.GetBLSPublicKeyShare("BLS_KEY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:0"); cout << c.GetBLSPublicKeyShare("BLS_KEY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:0");
} }
...@@ -877,7 +878,7 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") { ...@@ -877,7 +878,7 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
TEST_CASE("API test", "[api_test]") { TEST_CASE("API test", "[api_test]") {
//DEBUG_PRINT = 1; //DEBUG_PRINT = 1;
is_sgx_https = 0; is_sgx_https = 0;
//std::cerr << __GNUC__ << std::endl; //cerr << __GNUC__ << endl;
cerr << "API test started" << endl; cerr << "API test started" << endl;
init_all(false, false); init_all(false, false);
//HttpServer httpserver(1025); //HttpServer httpserver(1025);
...@@ -892,11 +893,11 @@ TEST_CASE("API test", "[api_test]") { ...@@ -892,11 +893,11 @@ TEST_CASE("API test", "[api_test]") {
try { try {
// for ( uint8_t i = 0; i < 2; i++) { // for ( uint8_t i = 0; i < 2; i++) {
// levelDb->deleteKey("POLY:SCHAIN_ID:1:NODE_ID:" + std::to_string(i) + // levelDb->deleteKey("POLY:SCHAIN_ID:1:NODE_ID:" + to_string(i) +
// ":DKG_ID:0"); // ":DKG_ID:0");
// //
// levelDb->deleteKey(" DKG_DH_KEY_POLY:SCHAIN_ID:0:NODE_ID:" + std::to_string(i)+ ":DKG_ID:0_0"); // levelDb->deleteKey(" DKG_DH_KEY_POLY:SCHAIN_ID:0:NODE_ID:" + to_string(i)+ ":DKG_ID:0_0");
// levelDb->deleteKey(" DKG_DH_KEY_POLY:SCHAIN_ID:0:NODE_ID:" + std::to_string(i)+ ":DKG_ID:0_1"); // levelDb->deleteKey(" DKG_DH_KEY_POLY:SCHAIN_ID:0:NODE_ID:" + to_string(i)+ ":DKG_ID:0_1");
// } // }
//cout << c.importBLSKeyShare("4160780231445160889237664391382223604184857153814275770598791864649971919844","BLS_KEY:SCHAIN_ID:2660016693368503500803087136248943520694587309641817:NODE_ID:33909:DKG_ID:3522960548719023733985054069487289468077787284706573", 4, 3,1); //cout << c.importBLSKeyShare("4160780231445160889237664391382223604184857153814275770598791864649971919844","BLS_KEY:SCHAIN_ID:2660016693368503500803087136248943520694587309641817:NODE_ID:33909:DKG_ID:3522960548719023733985054069487289468077787284706573", 4, 3,1);
...@@ -905,7 +906,7 @@ TEST_CASE("API test", "[api_test]") { ...@@ -905,7 +906,7 @@ TEST_CASE("API test", "[api_test]") {
cout << genKey << endl; cout << genKey << endl;
cout << c.ecdsaSignMessageHash(16, genKey["KeyName"].asString(),"0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db" ); cout << c.ecdsaSignMessageHash(16, genKey["KeyName"].asString(),"0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db" );
Json::Value getPubKey = c.getPublicECDSAKey(genKey["KeyName"].asString()); Json::Value getPubKey = c.getPublicECDSAKey(genKey["KeyName"].asString());
cout << getPubKey << std::endl; cout << getPubKey << endl;
// cout << c.renameESDSAKey("NODE_1CHAIN_1","tmp_NEK:bcacde0d26c0ea2c7e649992e7f791e1fba2492f5b7ae63dadb799075167c7fc"); // cout << c.renameESDSAKey("NODE_1CHAIN_1","tmp_NEK:bcacde0d26c0ea2c7e649992e7f791e1fba2492f5b7ae63dadb799075167c7fc");
// cout<<c.getPublicECDSAKey("NEK:7ca98cf32fd1edba26ea685820719fd2201b068a10c1264d382abbde13802a0e"); // cout<<c.getPublicECDSAKey("NEK:7ca98cf32fd1edba26ea685820719fd2201b068a10c1264d382abbde13802a0e");
//cout << c.ecdsaSignMessageHash(16, "NEK:697fadfc597bdbfae9ffb7412b80939e848c9c2fec2657bb2122b6d0d4a0dca8","0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db" ); //cout << c.ecdsaSignMessageHash(16, "NEK:697fadfc597bdbfae9ffb7412b80939e848c9c2fec2657bb2122b6d0d4a0dca8","0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db" );
...@@ -937,11 +938,11 @@ TEST_CASE("API test", "[api_test]") { ...@@ -937,11 +938,11 @@ TEST_CASE("API test", "[api_test]") {
std::string share_big0 = "501e364a6ea516f4812b013bcc150cbb435a2c465c9fd525951264969d8441a986798fd3317c1c3e60f868bb26c4cff837d9185f4be6015d8326437cb5b69480495859cd5a385430ece51252acdc234d8dbde75708b600ac50b2974e813ee26bd87140d88647fcc44df7262bbba24328e8ce622cd627a15b508ffa0db9ae81e0e110fab42cfe40da66b524218ca3c8e5aa3363fbcadef748dc3523a7ffb95b8f5d8141a5163db9f69d1ab223494ed71487c9bb032a74c08a222d897a5e49a617"; string share_big0 = "501e364a6ea516f4812b013bcc150cbb435a2c465c9fd525951264969d8441a986798fd3317c1c3e60f868bb26c4cff837d9185f4be6015d8326437cb5b69480495859cd5a385430ece51252acdc234d8dbde75708b600ac50b2974e813ee26bd87140d88647fcc44df7262bbba24328e8ce622cd627a15b508ffa0db9ae81e0e110fab42cfe40da66b524218ca3c8e5aa3363fbcadef748dc3523a7ffb95b8f5d8141a5163db9f69d1ab223494ed71487c9bb032a74c08a222d897a5e49a617";
std::string share_big = "03f749e2fcc28021895d757ec16d1636784446f5effcd3096b045136d8ab02657b32adc577f421330b81f5b7063df3b08a0621a897df2584b9046ca416e50ecc27e8c3277e981f7e650f8640289be128eecf0105f89a20e5ffb164744c45cf191d627ce9ab6c44e2ef96f230f2a4de742ea43b6f74b56849138026610b2d965605ececba527048a0f29f46334b1cec1d23df036248b24eccca99057d24764acee66c1a3f2f44771d0d237bf9d18c4177277e3ce3dc4e83686a2647fce1565ee0"; string share_big = "03f749e2fcc28021895d757ec16d1636784446f5effcd3096b045136d8ab02657b32adc577f421330b81f5b7063df3b08a0621a897df2584b9046ca416e50ecc27e8c3277e981f7e650f8640289be128eecf0105f89a20e5ffb164744c45cf191d627ce9ab6c44e2ef96f230f2a4de742ea43b6f74b56849138026610b2d965605ececba527048a0f29f46334b1cec1d23df036248b24eccca99057d24764acee66c1a3f2f44771d0d237bf9d18c4177277e3ce3dc4e83686a2647fce1565ee0";
std::string share = share_big.substr(0, 192); string share = share_big.substr(0, 192);
std::string publicShares = "1fc8154abcbf0c2ebf559571d7b57a8995c0e293a73d4676a8f76051a0d0ace30e00a87c9f087254c9c860c3215c4f11e8f85a3e8fae19358f06a0cbddf3df1924b1347b9b58f5bcb20958a19bdbdd832181cfa9f9e9fd698f6a485051cb47b829d10f75b6e227a7d7366dd02825b5718072cd42c39f0352071808622b7db6421b1069f519527e49052a8da6e3720cbda9212fc656eef945f5e56a4159c3b9622d883400460a9eff07fe1873f9b1ec50f6cf70098b9da0b90625b176f12329fa2ecc65082c626dc702d9cfb23a06770d4a2c7867e269efe84e3709b11001fb380a32d609855d1d46bc60f21140c636618b8ff55ed06d7788b6f81b498f96d3f9"; string publicShares = "1fc8154abcbf0c2ebf559571d7b57a8995c0e293a73d4676a8f76051a0d0ace30e00a87c9f087254c9c860c3215c4f11e8f85a3e8fae19358f06a0cbddf3df1924b1347b9b58f5bcb20958a19bdbdd832181cfa9f9e9fd698f6a485051cb47b829d10f75b6e227a7d7366dd02825b5718072cd42c39f0352071808622b7db6421b1069f519527e49052a8da6e3720cbda9212fc656eef945f5e56a4159c3b9622d883400460a9eff07fe1873f9b1ec50f6cf70098b9da0b90625b176f12329fa2ecc65082c626dc702d9cfb23a06770d4a2c7867e269efe84e3709b11001fb380a32d609855d1d46bc60f21140c636618b8ff55ed06d7788b6f81b498f96d3f9";
// cout << c.DKGVerification(publicShares, "test_key1", "37092c06c423b627c38ff86d1e66608bdc1496ef855b86e9f773441ac0b285d92aa466376a6008de4aab9858aa34848775282c4c3b56370bf25827321619c6e47701c8a32e3f4bb28f5a3b12a09800f318c550cedff6150e9a673ea56ece8b76", 2, 2, 0); // cout << c.DKGVerification(publicShares, "test_key1", "37092c06c423b627c38ff86d1e66608bdc1496ef855b86e9f773441ac0b285d92aa466376a6008de4aab9858aa34848775282c4c3b56370bf25827321619c6e47701c8a32e3f4bb28f5a3b12a09800f318c550cedff6150e9a673ea56ece8b76", 2, 2, 0);
// cout << c.DKGVerification("oleh1", "key0", "37092c06c423b627c38ff86d1e66608bdc1496ef855b86e9f773441ac0b285d92aa466376a6008de4aab9858aa34848775282c4c3b56370bf25827321619c6e47701c8a32e3f4bb28f5a3b12a09800f318c550cedff6150e9a673ea56ece8b76", 2, 2, 0); // cout << c.DKGVerification("oleh1", "key0", "37092c06c423b627c38ff86d1e66608bdc1496ef855b86e9f773441ac0b285d92aa466376a6008de4aab9858aa34848775282c4c3b56370bf25827321619c6e47701c8a32e3f4bb28f5a3b12a09800f318c550cedff6150e9a673ea56ece8b76", 2, 2, 0);
...@@ -952,14 +953,14 @@ TEST_CASE("API test", "[api_test]") { ...@@ -952,14 +953,14 @@ TEST_CASE("API test", "[api_test]") {
//cout << c.CreateBLSPrivateKey( "test_bls_key1","test_key1", "p2", share_big0, 2, 2 ); //cout << c.CreateBLSPrivateKey( "test_bls_key1","test_key1", "p2", share_big0, 2, 2 );
// std::string shares = "252122c309ed1f32faa897ede140c5b9c1bc07d5d9c94b7a22d4eeb13da7b7142aa466376a6008de4aab9858aa34848775282c4c3b56370bf25827321619c6e47701c8a32e3f4bb28f5a3b12a09800f318c550cedff6150e9a673ea56ece8b76df831dbef474cfc38be1c980130a8d273ff410fbf87deece9d7756a1b08ba9e954c1676cc7f2cac16e16cff0c877d8cf967381321fb4cc78e3638245a1dc85419766d281aff4935cc6eac25c9842032c8f7fae567c57622969599a72c42d2e1e"; // string shares = "252122c309ed1f32faa897ede140c5b9c1bc07d5d9c94b7a22d4eeb13da7b7142aa466376a6008de4aab9858aa34848775282c4c3b56370bf25827321619c6e47701c8a32e3f4bb28f5a3b12a09800f318c550cedff6150e9a673ea56ece8b76df831dbef474cfc38be1c980130a8d273ff410fbf87deece9d7756a1b08ba9e954c1676cc7f2cac16e16cff0c877d8cf967381321fb4cc78e3638245a1dc85419766d281aff4935cc6eac25c9842032c8f7fae567c57622969599a72c42d2e1e";
std::string shares = "252122c309ed1f32faa897ede140c5b9c1bc07d5d9c94b7a22d4eeb13da7b7142aa466376a6008de4aab9858aa34848775282c4c3b56370bf25827321619c6e47701c8a32e3f4bb28f5a3b12a09800f318c550cedff6150e9a673ea56ece8b7637092c06c423b627c38ff86d1e66608bdc1496ef855b86e9f773441ac0b285d92aa466376a6008de4aab9858aa34848775282c4c3b56370bf25827321619c6e47701c8a32e3f4bb28f5a3b12a09800f318c550cedff6150e9a673ea56ece8b76"; string shares = "252122c309ed1f32faa897ede140c5b9c1bc07d5d9c94b7a22d4eeb13da7b7142aa466376a6008de4aab9858aa34848775282c4c3b56370bf25827321619c6e47701c8a32e3f4bb28f5a3b12a09800f318c550cedff6150e9a673ea56ece8b7637092c06c423b627c38ff86d1e66608bdc1496ef855b86e9f773441ac0b285d92aa466376a6008de4aab9858aa34848775282c4c3b56370bf25827321619c6e47701c8a32e3f4bb28f5a3b12a09800f318c550cedff6150e9a673ea56ece8b76";
//cout << c.CreateBLSPrivateKey( "test_bls1","key0", "oleh1", shares, 2, 2 ); //cout << c.CreateBLSPrivateKey( "test_bls1","key0", "oleh1", shares, 2, 2 );
//cout << c.GetBLSPublicKeyShare("test_bls_key0"); //cout << c.GetBLSPublicKeyShare("test_bls_key0");
std::string s_share = "13b871ad5025fed10a41388265b19886e78f449f758fe8642ade51440fcf850bb2083f87227d8fb53fdfb2854e2d0abec4f47e2197b821b564413af96124cd84a8700f8eb9ed03161888c9ef58d6e5896403de3608e634e23e92fba041aa283484427d0e6de20922216c65865cfe26edd2cf9cbfc3116d007710e8d82feafd9135c497bef0c800ca310ba6044763572681510dad5e043ebd87ffaa1a4cd45a899222207f3d05dec8110d132ad34c62d6a3b40bf8e9f40f875125c3035062d2ca"; string s_share = "13b871ad5025fed10a41388265b19886e78f449f758fe8642ade51440fcf850bb2083f87227d8fb53fdfb2854e2d0abec4f47e2197b821b564413af96124cd84a8700f8eb9ed03161888c9ef58d6e5896403de3608e634e23e92fba041aa283484427d0e6de20922216c65865cfe26edd2cf9cbfc3116d007710e8d82feafd9135c497bef0c800ca310ba6044763572681510dad5e043ebd87ffaa1a4cd45a899222207f3d05dec8110d132ad34c62d6a3b40bf8e9f40f875125c3035062d2ca";
std::string EthKeyName = "tmp_NEK:8abc8e8280fb060988b65da4b8cb00779a1e816ec42f8a40ae2daa520e484a01"; string EthKeyName = "tmp_NEK:8abc8e8280fb060988b65da4b8cb00779a1e816ec42f8a40ae2daa520e484a01";
//cout << c.CreateBLSPrivateKey( "test_blskey", EthKeyName, "JCGMt", s_share, 2, 2 ); //cout << c.CreateBLSPrivateKey( "test_blskey", EthKeyName, "JCGMt", s_share, 2, 2 );
//cout << c.GetBLSPublicKeyShare("test_blskey"); //cout << c.GetBLSPublicKeyShare("test_blskey");
...@@ -986,10 +987,10 @@ TEST_CASE("getServerStatus test", "[getServerStatus_test]") { ...@@ -986,10 +987,10 @@ TEST_CASE("getServerStatus test", "[getServerStatus_test]") {
sgx_destroy_enclave(eid); sgx_destroy_enclave(eid);
} }
std::default_random_engine rand_gen((unsigned int) time(0)); default_random_engine rand_gen((unsigned int) time(0));
void SendRPCRequest(){ void SendRPCRequest(){
std::cout << "Hello from thread " << std::this_thread::get_id() << std::endl; cout << "Hello from thread " << this_thread::get_id() << endl;
HttpClient client("http://localhost:1029"); HttpClient client("http://localhost:1029");
StubClient c(client, JSONRPC_CLIENT_V2); StubClient c(client, JSONRPC_CLIENT_V2);
reset_db(); reset_db();
...@@ -1002,18 +1003,18 @@ void SendRPCRequest(){ ...@@ -1002,18 +1003,18 @@ void SendRPCRequest(){
Json::Value secretShares[n]; Json::Value secretShares[n];
Json::Value pubBLSKeys[n]; Json::Value pubBLSKeys[n];
Json::Value BLSSigShares[n]; Json::Value BLSSigShares[n];
std::vector<std::string> pubShares(n); vector<string> pubShares(n);
std::vector<std::string> poly_names(n); vector<string> poly_names(n);
int schain_id = rand_gen(); int schain_id = rand_gen();
int dkg_id = rand_gen(); int dkg_id = rand_gen();
for ( uint8_t i = 0; i < n; i++){ for ( uint8_t i = 0; i < n; i++){
EthKeys[i] = c.generateECDSAKey(); EthKeys[i] = c.generateECDSAKey();
std::string polyName = "POLY:SCHAIN_ID:" + std::to_string(schain_id) + ":NODE_ID:" + std::to_string(i) + ":DKG_ID:" + std::to_string(dkg_id); string polyName = "POLY:SCHAIN_ID:" + to_string(schain_id) + ":NODE_ID:" + to_string(i) + ":DKG_ID:" + to_string(dkg_id);
c.generateDKGPoly(polyName, t); c.generateDKGPoly(polyName, t);
poly_names[i] = polyName; poly_names[i] = polyName;
VerifVects[i] = c.getVerificationVector(polyName, t, n); VerifVects[i] = c.getVerificationVector(polyName, t, n);
cout << "VV " << i << " " << VerifVects[i] << std::endl; cout << "VV " << i << " " << VerifVects[i] << endl;
pubEthKeys.append(EthKeys[i]["PublicKey"]); pubEthKeys.append(EthKeys[i]["PublicKey"]);
} }
...@@ -1021,31 +1022,31 @@ void SendRPCRequest(){ ...@@ -1021,31 +1022,31 @@ void SendRPCRequest(){
secretShares[i] = c.getSecretShare(poly_names[i], pubEthKeys, t, n); secretShares[i] = c.getSecretShare(poly_names[i], pubEthKeys, t, n);
for ( uint8_t k = 0; k < t; k++ ) { for ( uint8_t k = 0; k < t; k++ ) {
for (uint8_t j = 0; j < 4; j++) { for (uint8_t j = 0; j < 4; j++) {
std::string pubShare = VerifVects[i]["Verification Vector"][k][j].asString(); string pubShare = VerifVects[i]["Verification Vector"][k][j].asString();
pubShares[i] += ConvertDecToHex(pubShare); pubShares[i] += ConvertDecToHex(pubShare);
} }
} }
// std::cerr << "i is " << i << " pubShares[i] = " << pubShares[i] << std::endl; // cerr << "i is " << i << " pubShares[i] = " << pubShares[i] << endl;
// std::cerr << "length is" << pubShares[i].length() << std::endl; // cerr << "length is" << pubShares[i].length() << endl;
} }
// Json::Value ComplaintResponse = c.ComplaintResponse(poly_names[1], 0); // Json::Value ComplaintResponse = c.ComplaintResponse(poly_names[1], 0);
// std::cerr << "share * G2 is " << ComplaintResponse["share*G2"].asString(); // cerr << "share * G2 is " << ComplaintResponse["share*G2"].asString();
// std::cerr << "DHKey is " << ComplaintResponse["DHKey"].asString(); // cerr << "DHKey is " << ComplaintResponse["DHKey"].asString();
int k = 0; int k = 0;
std::vector <std::string> secShares_vect(n); vector <string> secShares_vect(n);
for ( int i = 0; i < n; i++) for ( int i = 0; i < n; i++)
for ( int j = 0; j < n; j++){ for ( int j = 0; j < n; j++){
if ( i != j ){ if ( i != j ){
std::cerr << "SecretShare length is " << secretShares[i]["SecretShare"].asString().length() << std::endl; cerr << "SecretShare length is " << secretShares[i]["SecretShare"].asString().length() << endl;
std::string secretShare = secretShares[i]["SecretShare"].asString().substr(192*j, 192 ); string secretShare = secretShares[i]["SecretShare"].asString().substr(192*j, 192 );
secShares_vect[i] += secretShares[j]["SecretShare"].asString().substr(192*i, 192 ); secShares_vect[i] += secretShares[j]["SecretShare"].asString().substr(192*i, 192 );
bool res = c.DKGVerification(pubShares[i], EthKeys[j]["KeyName"].asString(), secretShare, t, n, j)["result"].asBool(); bool res = c.DKGVerification(pubShares[i], EthKeys[j]["KeyName"].asString(), secretShare, t, n, j)["result"].asBool();
k++; k++;
std::cerr << "NOW K IS " << k << " i is " << i << " j is " << j << std::endl; cerr << "NOW K IS " << k << " i is " << i << " j is " << j << endl;
REQUIRE( res ); REQUIRE( res );
} }
} }
...@@ -1055,10 +1056,10 @@ TEST_CASE("ManySimultaneousThreads", "[many_threads_test]") { ...@@ -1055,10 +1056,10 @@ TEST_CASE("ManySimultaneousThreads", "[many_threads_test]") {
is_sgx_https = 0; is_sgx_https = 0;
init_all( false, false ); init_all( false, false );
std::vector<std::thread> threads; vector<thread> threads;
int num_threads = 16; int num_threads = 16;
for (int i = 0; i < num_threads; i++){ for (int i = 0; i < num_threads; i++){
threads.push_back(std::thread(SendRPCRequest)); threads.push_back(thread(SendRPCRequest));
} }
for(auto& thread : threads){ for(auto& thread : threads){
...@@ -1087,32 +1088,32 @@ TEST_CASE("ecdsa API test", "[ecdsa_api_test]") { ...@@ -1087,32 +1088,32 @@ TEST_CASE("ecdsa API test", "[ecdsa_api_test]") {
REQUIRE(genKey["status"].asInt() == 0); REQUIRE(genKey["status"].asInt() == 0);
Json::Value getPubKey = c.getPublicECDSAKey(genKey["KeyName"].asString()); Json::Value getPubKey = c.getPublicECDSAKey(genKey["KeyName"].asString());
cout << getPubKey << std::endl; cout << getPubKey << endl;
REQUIRE(getPubKey["status"].asInt() == 0); REQUIRE(getPubKey["status"].asInt() == 0);
REQUIRE(getPubKey["PublicKey"].asString() == genKey["PublicKey"].asString()); REQUIRE(getPubKey["PublicKey"].asString() == genKey["PublicKey"].asString());
Json::Value ecdsaSign = c.ecdsaSignMessageHash(16, genKey["KeyName"].asString(), "0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"); Json::Value ecdsaSign = c.ecdsaSignMessageHash(16, genKey["KeyName"].asString(), "0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db");
cout << ecdsaSign << std::endl; cout << ecdsaSign << endl;
REQUIRE(ecdsaSign["status"].asInt() == 0); REQUIRE(ecdsaSign["status"].asInt() == 0);
// //wrong base // //wrong base
// Json::Value ecdsaSignWrongBase = c.ecdsaSignMessageHash(0, genKey["KeyName"].asString(), "0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"); // Json::Value ecdsaSignWrongBase = c.ecdsaSignMessageHash(0, genKey["KeyName"].asString(), "0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db");
// cout << ecdsaSignWrongBase << std::endl; // cout << ecdsaSignWrongBase << endl;
// REQUIRE(ecdsaSignWrongBase["status"].asInt() != 0); // REQUIRE(ecdsaSignWrongBase["status"].asInt() != 0);
// //
// //wrong keyName // //wrong keyName
// Json::Value ecdsaSignWrongKeyName = c.ecdsaSignMessageHash(0, "", "0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"); // Json::Value ecdsaSignWrongKeyName = c.ecdsaSignMessageHash(0, "", "0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db");
// cout << ecdsaSignWrongKeyName << std::endl; // cout << ecdsaSignWrongKeyName << endl;
// REQUIRE(ecdsaSignWrongKeyName["status"].asInt() != 0); // REQUIRE(ecdsaSignWrongKeyName["status"].asInt() != 0);
// Json::Value getPubKeyWrongKeyName = c.getPublicECDSAKey("keyName"); // Json::Value getPubKeyWrongKeyName = c.getPublicECDSAKey("keyName");
// REQUIRE(getPubKeyWrongKeyName["status"].asInt() != 0); // REQUIRE(getPubKeyWrongKeyName["status"].asInt() != 0);
// cout << getPubKeyWrongKeyName << std::endl; // cout << getPubKeyWrongKeyName << endl;
// //
// //wrong hash // //wrong hash
// Json::Value ecdsaSignWrongHash = c.ecdsaSignMessageHash(16, genKey["KeyName"].asString(), ""); // Json::Value ecdsaSignWrongHash = c.ecdsaSignMessageHash(16, genKey["KeyName"].asString(), "");
// cout << ecdsaSignWrongHash << std::endl; // cout << ecdsaSignWrongHash << endl;
// REQUIRE(ecdsaSignWrongHash["status"].asInt() != 0); // REQUIRE(ecdsaSignWrongHash["status"].asInt() != 0);
sgx_destroy_enclave(eid); sgx_destroy_enclave(eid);
...@@ -1133,7 +1134,7 @@ TEST_CASE("dkg API test", "[dkg_api_test]") { ...@@ -1133,7 +1134,7 @@ TEST_CASE("dkg API test", "[dkg_api_test]") {
reset_db(); reset_db();
std::string polyName = "POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1"; string polyName = "POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1";
Json::Value genPoly = c.generateDKGPoly(polyName, 2); Json::Value genPoly = c.generateDKGPoly(polyName, 2);
Json::Value publicKeys; Json::Value publicKeys;
...@@ -1207,15 +1208,15 @@ TEST_CASE("IsPolyExists test", "[is_poly_test]") { ...@@ -1207,15 +1208,15 @@ TEST_CASE("IsPolyExists test", "[is_poly_test]") {
reset_db(); reset_db();
std::string polyName = "POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1"; string polyName = "POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1";
Json::Value genPoly = c.generateDKGPoly(polyName, 2); Json::Value genPoly = c.generateDKGPoly(polyName, 2);
cout << genPoly << std::endl; cout << genPoly << endl;
Json::Value polyExists = c.IsPolyExists(polyName); Json::Value polyExists = c.IsPolyExists(polyName);
cout << polyExists << std::endl; cout << polyExists << endl;
REQUIRE(polyExists["IsExist"].asBool()); REQUIRE(polyExists["IsExist"].asBool());
Json::Value polyDoesNotExist = c.IsPolyExists("Vasya"); Json::Value polyDoesNotExist = c.IsPolyExists("Vasya");
cout << polyDoesNotExist << std::endl; cout << polyDoesNotExist << endl;
REQUIRE(!polyDoesNotExist["IsExist"].asBool()); REQUIRE(!polyDoesNotExist["IsExist"].asBool());
......
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