Unverified Commit d73d650c authored by svetaro's avatar svetaro

SKALE-1990-Add-timestams-to-logs

parent ba1019c1
......@@ -50,7 +50,7 @@
#include "RPCException.h"
#include "spdlog/spdlog.h"
int char2int(char _input) {
if (_input >= '0' && _input <= '9')
......@@ -187,7 +187,9 @@ char *encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key)
status = encrypt_key(eid, errStatus, errMsg, keyArray, encryptedKey, &encryptedLen);
std::cerr << "errStatus is " << *errStatus << " errMsg is " << errMsg << std::endl;
if (DEBUG_PRINT) {
spdlog::info("errStatus is {}",*errStatus, " errMsg is ", errMsg );
}
if (status != SGX_SUCCESS) {
......
......@@ -11,6 +11,8 @@
#include <jsonrpccpp/server/connectors/httpserver.h>
#include "spdlog/spdlog.h"
CSRManagerServer *cs = nullptr;
jsonrpc::HttpServer *hs3 = nullptr;
......@@ -21,7 +23,7 @@ CSRManagerServer::CSRManagerServer(AbstractServerConnector &connector,
Json::Value GetUnsignedCSRsImpl(){
std::cerr << "Enter GetUnsignedCSRsImpl" << std::endl;
spdlog::info("Enter GetUnsignedCSRsImpl");
Json::Value result;
result["status"] = 0;
result["errorMessage"] = "";
......@@ -70,9 +72,9 @@ Json::Value SignByHashImpl(const std::string& hash, int status){
std::string signClientCert = "cd cert && ./create_client_cert " + hash;
if (system(signClientCert.c_str()) == 0) {
std::cerr << "CLIENT CERTIFICATE IS SUCCESSFULLY GENERATED" << std::endl;
spdlog::info("CLIENT CERTIFICATE IS SUCCESSFULLY GENERATED");
} else {
std::cerr << "CLIENT CERTIFICATE GENERATION FAILED" << std::endl;
spdlog::info("CLIENT CERTIFICATE GENERATION FAILED");
csrDb->deleteKey(csr_db_key);
std::string status_db_key = "CSR:HASH:" + hash + "STATUS:";
csrStatusDb->deleteKey(status_db_key);
......@@ -115,12 +117,11 @@ int init_csrmanager_server(){
cs = new CSRManagerServer(*hs3, JSONRPC_SERVER_V2); // server (json-rpc 2.0)
if (!cs->StartListening()) {
std::cerr << "CSR manager server could not start listening" << std::endl;
spdlog::info("CSR manager server could not start listening");
exit(-1);
}
else {
std::cerr << "CSR manager server started on port " << BASE_PORT + 2 << std::endl;
spdlog::info("CSR manager server started on port {}", BASE_PORT + 2);
}
std::cerr << "CSR manager inited" << std::endl;
return 0;
};
\ No newline at end of file
......@@ -34,6 +34,8 @@
//#include <libBLS/libff/libff/algebra/curves/alt_bn128/alt_bn128_pp.hpp>
#include <libff/algebra/curves/alt_bn128/alt_bn128_pp.hpp>
#include "spdlog/spdlog.h"
std::vector<std::string> SplitString(const char* koefs, const char symbol){
std::string str(koefs);
std::string delim;
......@@ -86,13 +88,13 @@ std::string gen_dkg_poly( int _t){
}
if (DEBUG_PRINT) {
std::cerr << "gen_dkg_secret, status " << err_status << " err msg " << errMsg << std::endl;
spdlog::info("gen_dkg_secret, status {}", err_status, " err msg ", errMsg);
/* std::cerr << "encr raw poly: " << std::endl;
for ( int i = 0 ; i < 3050; i++)
printf(" %d ", encrypted_dkg_secret[i] );*/
std::cerr << "in DKGCrypto encr len is " << enc_len << std::endl;
spdlog::info("in DKGCrypto encr len is {}", enc_len);
}
char *hexEncrPoly = (char *) calloc(DKG_MAX_SEALED_LEN * 2 + 1, 1);//(4*BUF_LEN, 1);
......@@ -116,7 +118,7 @@ std::vector <std::vector<std::string>> get_verif_vect(const char* encryptedPolyH
if (DEBUG_PRINT) {
// std::cerr << "got encr poly " << encryptedPolyHex << std::endl;
std::cerr << "got encr poly size " << strlen(encryptedPolyHex) << std::endl;
spdlog::info("got encr poly size {}", strlen(encryptedPolyHex));
}
char* public_shares = (char*)calloc(10000, 1);
......@@ -129,7 +131,7 @@ std::vector <std::vector<std::string>> get_verif_vect(const char* encryptedPolyH
}
if (DEBUG_PRINT) {
std::cerr << "enc len " << enc_len << std::endl;
spdlog::info("enc len {}", enc_len);
/*std::cerr << "encr raw poly: " << std::endl;
for ( int i = 0 ; i < 3050; i++)
printf(" %d ", encr_dkg_poly[i] );*/
......@@ -142,12 +144,14 @@ std::vector <std::vector<std::string>> get_verif_vect(const char* encryptedPolyH
}
if (DEBUG_PRINT) {
std::cerr << "err msg " << errMsg1 << std::endl;
std::cerr << "public_shares:" << std::endl;
std::cerr << public_shares << std::endl;
spdlog::info("err msg is {}", errMsg1);
printf("\nget_public_shares status: %d error %s \n\n", err_status, errMsg1);
spdlog::info("public_shares:");
spdlog::info("{}", public_shares);
// std::cerr << "public_shares:" << std::endl;
// std::cerr << public_shares << std::endl;
spdlog::info("get_public_shares status: {}", err_status);
//printf("\nget_public_shares status: %d error %s \n\n", err_status, errMsg1);
}
std::vector <std::string> G2_strings = SplitString( public_shares, ',');
......@@ -191,7 +195,7 @@ std::string get_secret_shares(const std::string& polyName, const char* encrypted
char s_shareG2[320];
std::string pub_keyB = publicKeys.at(i);//publicKeys.substr(128*i, 128*i + 128);
if (DEBUG_PRINT) {
std::cerr << "pub_keyB is " << pub_keyB << std::endl;
spdlog::info("pub_keyB is {}", pub_keyB);
}
char pubKeyB[129];
strncpy(pubKeyB, pub_keyB.c_str(), 128);
......@@ -206,24 +210,25 @@ std::string get_secret_shares(const std::string& polyName, const char* encrypted
//uint32_t enc_len = BUF_LEN;
if (DEBUG_PRINT) {
std::cerr << "dec len is " << dec_len << std::endl;
spdlog::info("dec len is {}", dec_len);
}
carray2Hex(encrypted_skey, dec_len, hexEncrKey);
std::string DHKey_name = "DKG_DH_KEY_" + polyName + "_" + std::to_string(i) + ":";
std::cerr << "name to write to db is " << DHKey_name << std::endl;
// std::cerr << "hexEncrKey: " << hexEncrKey << std::endl;
writeDataToDB(DHKey_name, hexEncrKey);
std::string shareG2_name = "shareG2_" + polyName + "_" + std::to_string(i) + ":";
if (DEBUG_PRINT) {
std::cerr << "name to write to db is " << shareG2_name << std::endl;
std::cerr << "s_shareG2: " << s_shareG2 << std::endl;
spdlog::info("name to write to db is {}", DHKey_name);
spdlog::info("name to write to db is {}", shareG2_name);
spdlog::info("s_shareG2: {}", s_shareG2);
}
writeDataToDB(shareG2_name, s_shareG2);
if (DEBUG_PRINT) {
std::cerr << errMsg1 << std::endl << std::endl;
spdlog::info("errMsg: {}", errMsg1);
// std::cerr << "iteration " << i <<" result length is " << result.length() << std::endl ;
// std::cerr << "iteration " << i <<" share length is " << strlen(cur_share) << std::endl;
// std::cerr << "iteration " << i <<" share is " << cur_share << std::endl;
......@@ -254,7 +259,7 @@ bool VerifyShares(const char* publicShares, const char* encr_sshare, const char
// std::cerr << "encr_sshare length is " << strlen(encr_sshare) << std::endl; std::cerr << "public shares " << publicShares << std::endl;
std::cerr << "publicShares length is " << std::char_traits<char>::length(publicShares)<<std::endl; //strlen(publicShares)<< std::endl;
spdlog::info("publicShares length is {}", std::char_traits<char>::length(publicShares));
}
char pshares[8193];
strncpy(pshares, publicShares, strlen(publicShares) + 1);
......@@ -267,8 +272,8 @@ bool VerifyShares(const char* publicShares, const char* encr_sshare, const char
}
if (DEBUG_PRINT) {
std::cerr << "errMsg1: " << errMsg1 << std::endl;
std::cerr << "result is " << result << std::endl;
spdlog::info("errMsg1: {}", errMsg1);
spdlog::info("result is: {}", result);
}
free(errMsg1);
......@@ -278,7 +283,7 @@ bool VerifyShares(const char* publicShares, const char* encr_sshare, const char
bool CreateBLSShare( const std::string& BLSKeyName, const char * s_shares, const char * encryptedKeyHex){
if (DEBUG_PRINT) {
std::cerr << "ENTER CreateBLSShare" << std::endl;
spdlog::info("ENTER CreateBLSShare");
}
char* errMsg1 = (char*) calloc(1024,1);
int err_status = 0;
......@@ -296,7 +301,7 @@ bool CreateBLSShare( const std::string& BLSKeyName, const char * s_shares, const
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;
if ( err_status != 0){
std::cerr << "ERROR IN ENCLAVE" << std::endl;
spdlog::info("ERROR IN ENCLAVE");
throw RPCException(ERROR_IN_ENCLAVE, "Create BLS private key failed in enclave");
}
else {
......@@ -307,8 +312,8 @@ bool CreateBLSShare( const std::string& BLSKeyName, const char * s_shares, const
// std::cerr << "BEFORE WRITE BLS KEY TO DB" << std::endl;
writeDataToDB(BLSKeyName, hexBLSKey);
if (DEBUG_PRINT) {
std::cerr << "hexBLSKey length is " << strlen(hexBLSKey) << std::endl;
std::cerr << "bls key " << BLSKeyName << " is " << hexBLSKey << std::endl;
spdlog::info("hexBLSKey length is {}", strlen(hexBLSKey));
spdlog::info("bls key {}", BLSKeyName, " is ", hexBLSKey );
}
free(hexBLSKey);
return true;
......@@ -331,7 +336,7 @@ std::vector<std::string> GetBLSPubKey(const char * encryptedKeyHex){
char pub_key[320];
if (DEBUG_PRINT) {
std::cerr << "dec_key_len is " << dec_key_len << std::endl;
spdlog::info("dec_key_len is {}", dec_key_len);
}
get_bls_pub_key(eid, &err_status, errMsg1, encr_key, dec_key_len, pub_key);
if ( err_status != 0){
......@@ -340,10 +345,10 @@ std::vector<std::string> GetBLSPubKey(const char * encryptedKeyHex){
std::vector<std::string> pub_key_vect = SplitString(pub_key, ':');
if (DEBUG_PRINT) {
std::cerr << "errMsg1 is " << errMsg1 << std::endl;
std::cerr << "pub key is" << std::endl;
spdlog::info("errMsg1 is {}", errMsg1);
spdlog::info("pub key is ");
for (int i = 0; i < 4; i++)
std::cerr << pub_key_vect.at(i) << std::endl;
spdlog::info("{}", pub_key_vect.at(i));
}
return pub_key_vect;
}
......@@ -356,7 +361,7 @@ std::string decrypt_DHKey(const std::string& polyName, int ind){
std::string DH_key_name = polyName + "_" + std::to_string(ind) + ":";
std::shared_ptr<std::string> hexEncrKey_ptr = readFromDb(DH_key_name, "DKG_DH_KEY_");
if (DEBUG_PRINT) {
std::cerr << "encr DH key is " << hexEncrKey_ptr << std::endl;
spdlog::info("encr DH key is {}", *hexEncrKey_ptr);
}
char *hexEncrKey = (char *) calloc(2 * BUF_LEN, 1);
......
......@@ -31,6 +31,8 @@
#include <gmp.h>
#include <random>
#include "spdlog/spdlog.h"
static std::default_random_engine rand_gen((unsigned int) time(0));
......@@ -66,7 +68,7 @@ std::vector<std::string> gen_ecdsa_key(){
unsigned long seed = rand_gen();
if (DEBUG_PRINT) {
std::cerr << "seed is " << seed << std::endl;
spdlog::info("seed is {}", seed);
}
gmp_randstate_t state;
gmp_randinit_default(state);
......@@ -115,9 +117,9 @@ std::string get_ecdsa_pubkey(const char* encryptedKeyHex){
std::string pubKey = std::string(pub_key_x) + std::string(pub_key_y);//concatPubKeyWith0x(pub_key_x, pub_key_y);//
if (DEBUG_PRINT) {
std::cerr << "pubkey is " << pubKey << std::endl;
std::cerr << "pubkey length is " << pubKey.length() << std::endl;
std::cerr << "err str " << errMsg << std::endl;
spdlog::info("pubkey is {}", pubKey);
spdlog::info("pubkey length is {}", pubKey.length());
spdlog::info("err str is {}", errMsg);
}
free(errMsg);
......@@ -143,9 +145,9 @@ std::vector<std::string> ecdsa_sign_hash(const char* encryptedKeyHex, const char
}
if (DEBUG_PRINT) {
std::cerr << "encryptedKeyHex: " << encryptedKeyHex << std::endl;
std::cerr << "HASH: " << hashHex << std::endl;
std::cerr << "encrypted len" << dec_len << std::endl;
spdlog::info("encryptedKeyHex: {}", encryptedKeyHex);
spdlog::info("HASH: {}", hashHex);
spdlog::info("encrypted len: {}", dec_len);
}
status = ecdsa_sign1(eid, &err_status, errMsg, encr_key, ECDSA_ENCR_LEN, (unsigned char*)hashHex, signature_r, signature_s, &signature_v, base );
......@@ -154,12 +156,12 @@ std::vector<std::string> ecdsa_sign_hash(const char* encryptedKeyHex, const char
}
if (DEBUG_PRINT) {
std::cerr << "signature r in ecdsa_sign_hash " << signature_r << std::endl;
std::cerr << "signature s in ecdsa_sign_hash " << signature_s << std::endl;
spdlog::info("signature r in ecdsa_sign_hash: {}", signature_r);
spdlog::info("signature s in ecdsa_sign_hash: {}", signature_s);
}
if ( status != SGX_SUCCESS){
std::cerr << "failed to sign " << std::endl;
spdlog::info(" failed to sign ");
}
signature_vect.at(0) = std::to_string(signature_v);
if ( base == 16) {
......
......@@ -36,6 +36,8 @@
#include "ServerInit.h"
#include "spdlog/spdlog.h"
using namespace leveldb;
......@@ -64,7 +66,8 @@ std::shared_ptr<std::string> LevelDB::readString(const std::string &_key) {
// throw RPCException(KEY_SHARE_DOES_NOT_EXIST, "Data with this name does not exist");
// }
if (DEBUG_PRINT) {
std::cerr << "key to read from db: " << _key << std::endl;
spdlog::info("key to read from db: {}",_key );
//std::cerr << "key to read from db: " << _key << std::endl;
}
throwExceptionOnError(status);
......@@ -84,7 +87,8 @@ void LevelDB::writeString(const std::string &_key, const std::string &_value) {
throwExceptionOnError(status);
if (DEBUG_PRINT) {
std::cerr << "written key " << _key << std::endl;
spdlog::info("written key: {}",_key );
// std::cerr << "written key " << _key << std::endl;
}
}
......@@ -99,7 +103,11 @@ void LevelDB::deleteDHDKGKey (const std::string &_key) {
throwExceptionOnError(status);
std::cerr << "key deleted " << full_key << std::endl;
if (DEBUG_PRINT) {
spdlog::info("key deleted: {}",full_key );
//std::cerr << "key deleted " << full_key << std::endl;
}
}
void LevelDB::deleteOlegKey (const std::string &_key) {
......@@ -112,7 +120,9 @@ void LevelDB::deleteOlegKey (const std::string &_key) {
throwExceptionOnError(status);
if (DEBUG_PRINT) {
std::cerr << "key deleted " << full_key << std::endl;
}
}
void LevelDB::deleteTempNEK(const std::string &_key){
......@@ -140,7 +150,8 @@ void LevelDB::deleteKey(const std::string &_key){
throwExceptionOnError(status);
if (DEBUG_PRINT) {
std::cerr << "key deleted " << _key << std::endl;
spdlog::info("key deleted: {}",_key );
// std::cerr << "key deleted " << _key << std::endl;
}
}
......@@ -221,12 +232,16 @@ void LevelDB::writeDataUnique(const std::string & Name, const std::string &value
auto key = Name;
if (readString(Name) != nullptr) {
std::cerr << "name " << Name << " already exists" << std::endl;
spdlog::info("name {}",Name, " already exists");
// std::cerr << "name " << Name << " already exists" << std::endl;
throw RPCException(KEY_SHARE_ALREADY_EXISTS, "Data with this name already exists");
}
writeString(key, value);
std::cerr << Name << " is written to db " << std::endl;
if (DEBUG_PRINT) {
spdlog::info("{}",Name, " is written to db");
//std::cerr << Name << " is written to db " << std::endl;
}
}
......
......@@ -43,6 +43,8 @@
#include "SGXRegistrationServer.h"
#include "LevelDB.h"
#include "spdlog/spdlog.h"
int DEBUG_PRINT = 0;
int is_sgx_https = 1;
......@@ -66,7 +68,7 @@ Json::Value SignCertificateImpl(const std::string& csr, bool auto_sign = false){
result["status"] = 0;
result["errorMessage"] = "";
try{
std::cerr << " enter SignCertificateImpl " << std::endl;
spdlog::info("enter SignCertificateImpl");
std::string status = "1";
std::string hash = cryptlite::sha256::hash_hex(csr);
......@@ -87,11 +89,11 @@ Json::Value SignCertificateImpl(const std::string& csr, bool auto_sign = false){
std::string genCert = "cd cert && ./create_client_cert " + hash;
if (system(genCert.c_str()) == 0){
std::cerr << "CLIENT CERTIFICATE IS SUCCESSFULLY GENERATED" << std::endl;
spdlog::info("CLIENT CERTIFICATE IS SUCCESSFULLY GENERATED");
status = "0";
}
else{
std::cerr << "CLIENT CERTIFICATE GENERATION FAILED" << std::endl;
spdlog::info("CLIENT CERTIFICATE GENERATION FAILED");
std::string status_db_key = "CSR:HASH:" + hash + "STATUS:";
csrStatusDb->writeDataUnique(status_db_key, std::to_string(FAIL_TO_CREATE_CERTIFICATE));
throw RPCException(FAIL_TO_CREATE_CERTIFICATE, "CLIENT CERTIFICATE GENERATION FAILED");
......@@ -144,10 +146,12 @@ Json::Value GetSertificateImpl(const std::string& hash){
infile.close();
std::string remove_crt = "cd cert && rm -rf " + hash + ".crt && rm -rf " + hash + ".csr";
if(system(remove_crt.c_str()) == 0){
std::cerr << "cert removed" << std::endl;
//std::cerr << "cert removed" << std::endl;
spdlog::info(" cert removed ");
}
else{
std::cerr << "cert was not removed" << std::endl;
spdlog::info(" cert was not removed ");
}
}
......@@ -167,7 +171,7 @@ Json::Value GetSertificateImpl(const std::string& hash){
Json::Value SGXRegistrationServer::SignCertificate(const std::string& csr){
std::cerr << "Enter SignCertificate " << std::endl;
spdlog::info("Enter SignCertificate ");
lock_guard<recursive_mutex> lock(m);
return SignCertificateImpl(csr, cert_auto_sign);
}
......@@ -208,11 +212,11 @@ int init_registration_server(bool sign_automatically) {
JSONRPC_SERVER_V2, sign_automatically); // hybrid server (json-rpc 1.0 & 2.0)
if (!regs->StartListening()) {
cerr << "Registration server could not start listening" << endl;
spdlog::info("Registration server could not start listening");
exit(-1);
}
else {
cerr << "Registration Server started on port " << BASE_PORT + 1 << endl;
spdlog::info("Registration server started on port {}", BASE_PORT + 1);
}
......
......@@ -41,6 +41,8 @@
#include "ServerInit.h"
#include "spdlog/spdlog.h"
//#if __cplusplus < 201412L
//#error expecting C++17 standard
//#endif
......@@ -79,20 +81,21 @@ void debug_print(){
}
int init_https_server(bool check_certs) {
std::string rootCAPath = "cert/rootCA.pem";
std::string keyCAPath = "cert/rootCA.key";
if (access(rootCAPath.c_str(), F_OK) != 0 || access(keyCAPath.c_str(), F_OK) != 0){
std::cerr << "YOU DO NOT HAVE ROOT CA CERTIFICATE" << std::endl;
std::cerr << "ROOT CA CERTIFICATE IS GOING TO BE CREATED" << std::endl;
spdlog::info("YOU DO NOT HAVE ROOT CA CERTIFICATE");
spdlog::info("ROOT CA CERTIFICATE IS GOING TO BE CREATED");
std::string genRootCACert = "cd cert && ./create_CA";
if (system(genRootCACert.c_str()) == 0){
std::cerr << "ROOT CA CERTIFICATE IS SUCCESSFULLY GENERATED" << std::endl;
spdlog::info("ROOT CA CERTIFICATE IS SUCCESSFULLY GENERATED");
}
else{
std::cerr << "ROOT CA CERTIFICATE GENERATION FAILED" << std::endl;
spdlog::info("ROOT CA CERTIFICATE GENERATION FAILED");
exit(-1);
}
}
......@@ -101,16 +104,16 @@ int init_https_server(bool check_certs) {
std::string keyPath = "cert/SGXServerCert.key";
if (access(certPath.c_str(), F_OK) != 0 || access(certPath.c_str(), F_OK) != 0){
std::cerr << "YOU DO NOT HAVE SERVER CERTIFICATE " << std::endl;
std::cerr << "SERVER CERTIFICATE IS GOING TO BE CREATED" << std::endl;
spdlog::info("YOU DO NOT HAVE SERVER CERTIFICATE");
spdlog::info("SERVER CERTIFICATE IS GOING TO BE CREATED");
std::string genCert = "cd cert && ./create_server_cert";
if (system(genCert.c_str()) == 0){
std::cerr << "SERVER CERTIFICATE IS SUCCESSFULLY GENERATED" << std::endl;
spdlog::info("SERVER CERTIFICATE IS SUCCESSFULLY GENERATED");
}
else{
std::cerr << "SERVER CERTIFICATE GENERATION FAILED" << std::endl;
spdlog::info("SERVER CERTIFICATE GENERATION FAILED");
exit(-1);
}
}
......@@ -120,11 +123,11 @@ int init_https_server(bool check_certs) {
JSONRPC_SERVER_V2); // hybrid server (json-rpc 1.0 & 2.0)
if (!s->StartListening()) {
cerr << "SGX Server could not start listening" << endl;
spdlog::info("SGX Server could not start listening");
exit(-1);
}
else{
cerr << "SGX Server started on port " << BASE_PORT << endl;
spdlog::info("SGX Server started on port {}", BASE_PORT);
}
return 0;
}
......@@ -136,7 +139,7 @@ int init_http_server() { //without ssl
s = new SGXWalletServer(*hs,
JSONRPC_SERVER_V2); // hybrid server (json-rpc 1.0 & 2.0)
if (!s->StartListening()) {
cerr << "Server could not start listening" << endl;
spdlog::info("Server could not start listening");
exit(-1);
}
return 0;
......@@ -253,7 +256,7 @@ Json::Value generateECDSAKeyImpl() {
result["errorMessage"] = "";
result["encryptedKey"] = "";
cerr << "Calling method generateECDSAKey" << endl;
spdlog::info("Calling method generateECDSAKey");
std::vector<std::string>keys;
......@@ -267,9 +270,9 @@ Json::Value generateECDSAKeyImpl() {
std::string keyName = "NEK:" + keys.at(2);
if (DEBUG_PRINT) {
std::cerr << "write encr key" << keys.at(0) << std::endl;
std::cerr << "keyname length is " << keyName.length() << std::endl;
std::cerr << "key name generated: " << keyName << std::endl;
spdlog::info("write encr key {}", keys.at(0));
spdlog::info("keyname length is {}", keyName.length());
spdlog::info("key name generated: {}", keyName);
}
//writeECDSAKey(keyName, keys.at(0));
......@@ -335,8 +338,7 @@ Json::Value ecdsaSignMessageHashImpl(int base, const std::string &_keyName, cons
std::vector<std::string> sign_vect(3);
if (DEBUG_PRINT) {
std::cerr << "entered ecdsaSignMessageHashImpl" << messageHash
<< "length " << messageHash.length() << std::endl;
spdlog::info("entered ecdsaSignMessageHashImpl {}", messageHash, "length {}", messageHash.length());
}
try {
......@@ -350,7 +352,7 @@ Json::Value ecdsaSignMessageHashImpl(int base, const std::string &_keyName, cons
}
if (DEBUG_PRINT) {
std::cerr << "Hash handled " << cutHash << std::endl;
spdlog::info("Hash handled {}", cutHash);
}
if ( !checkECDSAKeyName(_keyName)){
......@@ -371,7 +373,7 @@ Json::Value ecdsaSignMessageHashImpl(int base, const std::string &_keyName, cons
}
if (DEBUG_PRINT) {
std::cerr << "got signature_s " << sign_vect.at(2) << std::endl;
spdlog::info("got signature_s {}", sign_vect.at(2));
}
result["signature_v"] = sign_vect.at(0);
......@@ -393,7 +395,7 @@ Json::Value getPublicECDSAKeyImpl(const std::string& keyName){
result["errorMessage"] = "";
result["PublicKey"] = "";
cerr << "Calling method getPublicECDSAKey" << endl;
spdlog::info("Calling method getPublicECDSAKey");
std::string Pkey;
......@@ -404,8 +406,8 @@ Json::Value getPublicECDSAKeyImpl(const std::string& keyName){
std::shared_ptr<std::string> key_ptr = readFromDb(keyName);
Pkey = get_ecdsa_pubkey( key_ptr->c_str());
if (DEBUG_PRINT) {
std::cerr << "PublicKey " << Pkey << std::endl;
std::cerr << "PublicKey length" << Pkey.length() << std::endl;
spdlog::info("PublicKey {}", Pkey);
spdlog::info("PublicKey length {}", Pkey.length());
}
result["PublicKey"] = Pkey;
......@@ -484,7 +486,7 @@ Json::Value getVerificationVectorImpl(const std::string& polyName, int t, int n)
}
Json::Value getSecretShareImpl(const std::string& polyName, const Json::Value& publicKeys, int t, int n){
std::cerr << " enter getSecretShareImpl" << std::endl;
spdlog::info("enter getSecretShareImpl");
Json::Value result;
result["status"] = 0;
result["errorMessage"] = "";
......@@ -527,7 +529,7 @@ Json::Value getSecretShareImpl(const std::string& polyName, const Json::Value& p
Json::Value DKGVerificationImpl(const std::string& publicShares, const std::string& EthKeyName,
const std::string& SecretShare, int t, int n, int ind){
std::cerr << " enter DKGVerificationImpl" << std::endl;
spdlog::info("enter DKGVerificationImpl");
Json::Value result;
result["status"] = 0;
......@@ -567,7 +569,7 @@ Json::Value DKGVerificationImpl(const std::string& publicShares, const std::stri
Json::Value CreateBLSPrivateKeyImpl(const std::string & BLSKeyName, const std::string& EthKeyName, const std::string& polyName, const std::string & SecretShare, int t, int n){
std::cerr << "CreateBLSPrivateKeyImpl entered" << std::endl;
spdlog::info("CreateBLSPrivateKeyImpl entered");
Json::Value result;
result["status"] = 0;
......@@ -576,8 +578,8 @@ Json::Value CreateBLSPrivateKeyImpl(const std::string & BLSKeyName, const std::s
try {
if (SecretShare.length() != n * 192){
std::cerr << "wrong length of secret shares - " << SecretShare.length() << std::endl;
std::cerr << "secret shares - " << SecretShare << std::endl;
spdlog::info("wrong length of secret shares - {}", SecretShare.length());
spdlog::info("secret shares - {}", SecretShare);
throw RPCException(INVALID_SECRET_SHARES_LENGTH, "Invalid secret share length");
}
if ( !checkECDSAKeyName(EthKeyName)){
......@@ -594,15 +596,14 @@ Json::Value CreateBLSPrivateKeyImpl(const std::string & BLSKeyName, const std::s
}
std::vector<std::string> sshares_vect;
if (DEBUG_PRINT) {
std::cerr << "sshares from json are " << SecretShare << std::endl;
spdlog::info("secret shares from json are - {}", SecretShare);
}
std::shared_ptr<std::string> encryptedKeyHex_ptr = readFromDb(EthKeyName);
bool res = CreateBLSShare(BLSKeyName, SecretShare.c_str(), encryptedKeyHex_ptr->c_str());
if ( res){
std::cerr << "BLS KEY SHARE CREATED " << std::endl;
spdlog::info("BLS KEY SHARE CREATED ");
}
else {
throw RPCException(-122, "Error while creating BLS key share");
......@@ -635,8 +636,10 @@ Json::Value GetBLSPublicKeyShareImpl(const std::string & BLSKeyName){
}
std::shared_ptr<std::string> encryptedKeyHex_ptr = readFromDb(BLSKeyName);
if (DEBUG_PRINT) {
std::cerr << "encr_bls_key_share is " << *encryptedKeyHex_ptr << std::endl;
std::cerr << "length is " << encryptedKeyHex_ptr->length() << std::endl;
spdlog::info("encr_bls_key_share is {}", *encryptedKeyHex_ptr);
spdlog::info("length is {}", encryptedKeyHex_ptr->length());
//std::cerr << "encr_bls_key_share is " << *encryptedKeyHex_ptr << std::endl;
// std::cerr << "length is " << encryptedKeyHex_ptr->length() << std::endl;
}
std::vector<std::string> public_key_vect = GetBLSPubKey(encryptedKeyHex_ptr->c_str());
for ( uint8_t i = 0; i < 4; i++) {
......@@ -685,7 +688,7 @@ Json::Value MultG2Impl(const std::string& x){
result["status"] = 0;
result["errorMessage"] = "";
try {
std::cerr << "MultG2Impl try " << std::endl;
spdlog::info("MultG2Impl try ");
std::vector<std::string> xG2_vect = mult_G2(x);
for ( uint8_t i = 0; i < 4; i++) {
result["x*G2"][i] = xG2_vect.at(i);
......@@ -711,7 +714,7 @@ Json::Value getServerStatusImpl() {
Json::Value SGXWalletServer::generateDKGPoly(const std::string& polyName, int t){
std::cerr << "entered generateDKGPoly" << std::endl;
spdlog::info("entered generateDKGPoly");
lock_guard<recursive_mutex> lock(m);
return generateDKGPolyImpl(polyName, t);
}
......@@ -761,9 +764,9 @@ Json::Value SGXWalletServer::getPublicECDSAKey(const std::string &_keyName) {
Json::Value SGXWalletServer::ecdsaSignMessageHash(int base, const std::string &_keyName, const std::string &messageHash ) {
lock_guard<recursive_mutex> lock(m);
std::cerr << "entered ecdsaSignMessageHash" << std::endl;
spdlog::info("entered ecdsaSignMessageHash");
if (DEBUG_PRINT) {
std::cerr << "MessageHash first " << messageHash << std::endl;
spdlog::info("MessageHash first {}", messageHash);
}
return ecdsaSignMessageHashImpl(base,_keyName, messageHash);
}
......@@ -856,13 +859,13 @@ void writeDataToDB(const string & Name, const string &value) {
auto key = Name;
if (levelDb->readString(Name) != nullptr) {
std::cerr << "name " << Name << " already exists" << std::endl;
spdlog::info("name {}", Name, " already exists");
throw RPCException(KEY_SHARE_ALREADY_EXISTS, "Data with this name already exists");
}
levelDb->writeString(key, value);
if (DEBUG_PRINT) {
std::cerr << Name << " is written to db " << std::endl;
spdlog::info("{} ", Name, " is written to db ");
}
}
......@@ -27,6 +27,8 @@
#include <iostream>
#include "spdlog/spdlog.h"
std::vector<std::string> SplitString(const std::string& str, const std::string& delim = ":"){
std::vector<std::string> tokens;
size_t prev = 0, pos = 0;
......@@ -44,15 +46,15 @@ std::vector<std::string> SplitString(const std::string& str, const std::string&
bool checkECDSAKeyName(const std::string& keyName) {
std::vector<std::string> parts = SplitString(keyName);
if (parts.size() != 2) {
std::cerr << "num parts != 2" << std::endl;
spdlog::info("ECDSAKeyName num parts != 2");
return false;
}
if (parts.at(0) != "NEK") {
std::cerr << "key doesn't start from NEK" << std::endl;
spdlog::info("key doesn't start from NEK");
return false;
}
if ( parts.at(1).length() > 64 || parts.at(1).length() < 1){
std::cerr << "wrong key length" << std::endl;
spdlog::info("wrong key length");
return false;
}
......@@ -87,36 +89,36 @@ bool checkHex(const std::string& hex, const uint32_t sizeInBytes){
bool checkName (const std::string& Name, const std::string& prefix){
std::vector<std::string> parts = SplitString(Name);
if ( parts.size() != 7) {
std::cerr << "parts.size() != 7" << std::endl;
spdlog::info("parts.size() != 7");
return false;
}
if ( parts.at(0) != prefix ) {
std::cerr << "parts.at(0) != prefix" << std::endl;
spdlog::info("parts.at(0) != prefix");
return false;
}
if ( parts.at(1) != "SCHAIN_ID"){
std::cerr << "parts.at(1) != SCHAIN_ID" << std::endl;
spdlog::info("parts.at(1) != SCHAIN_ID");
return false;
}
if ( parts.at(3) != "NODE_ID"){
std::cerr << "parts.at(3) != Node_ID" << std::endl;
spdlog::info("parts.at(3) != Node_ID");
return false;
}
if ( parts.at(5) != "DKG_ID"){
std::cerr << "parts.at(1) != DKG_ID" << std::endl;
spdlog::info("parts.at(1) != DKG_ID");
return false;
}
if ( parts.at(2).length() > 78 || parts.at(2).length() < 1){
std::cerr << "parts.at(2).length() > 78" << std::endl;
spdlog::info("parts.at(2).length() > 78");
return false;
}
if (parts.at(4).length() > 5 || parts.at(4).length() < 1){
std::cerr << "parts.at(4).length() > 5" << std::endl;
spdlog::info("parts.at(4).length() > 5");
return false;
}
if ( parts.at(6).length() > 78 || parts.at(6).length() < 1){
std::cerr << "parts.at(6).length() > 78" << std::endl;
spdlog::info("parts.at(6).length() > 78");
return false;
}
......@@ -125,7 +127,7 @@ bool checkName (const std::string& Name, const std::string& prefix){
if ( mpz_set_str(num, parts.at(2).c_str(), 10) == -1){
mpz_clear(num);
std::cerr << "parts.at(2) not num" << std::endl;
spdlog::info("parts.at(2) not num");
return false;
}
mpz_clear(num);
......@@ -133,7 +135,7 @@ bool checkName (const std::string& Name, const std::string& prefix){
if ( mpz_set_str(num, parts.at(4).c_str(), 10) == -1){
mpz_clear(num);
std::cerr << "parts.at(4) not num" << std::endl;
spdlog::info("parts.at(4) not num");
return false;
}
mpz_clear(num);
......@@ -141,7 +143,7 @@ bool checkName (const std::string& Name, const std::string& prefix){
if ( mpz_set_str(num, parts.at(6).c_str(),10) == -1){
mpz_clear(num);
std::cerr << "parts.at(6) not num" << std::endl;
spdlog::info("parts.at(6) not num");
return false;
}
mpz_clear(num);
......
......@@ -54,6 +54,7 @@
#include <iostream>
#include "spdlog/spdlog.h"
void init_daemon() {
......@@ -87,7 +88,10 @@ void init_enclave() {
}
#endif
std::cerr << "SGX_DEBUG_FLAG = " << SGX_DEBUG_FLAG << std::endl;
if ( DEBUG_PRINT) {
spdlog::info("SGX_DEBUG_FLAG = {}", SGX_DEBUG_FLAG);
//std::cerr << "SGX_DEBUG_FLAG = " << SGX_DEBUG_FLAG << std::endl;
}
status = sgx_create_enclave_search(ENCLAVE_NAME, SGX_DEBUG_FLAG, &token,
&updated, &eid, 0);
......@@ -102,7 +106,8 @@ void init_enclave() {
exit(1);
}
fprintf(stderr, "Enclave launched\n");
//fprintf(stderr, "Enclave launched\n");
spdlog::info( "Enclave launched");
status = tgmp_init(eid);
if (status != SGX_SUCCESS) {
......@@ -110,14 +115,17 @@ void init_enclave() {
exit(1);
}
fprintf(stderr, "libtgmp initialized\n");
if (DEBUG_PRINT) {
spdlog::info("libtgmp initialized");
//fprintf(stderr, "libtgmp initialized\n");
}
}
int sgxServerInited = 0;
void init_all(bool check_cert, bool sign_automatically) {
//spdlog::set_pattern("%c");
if (sgxServerInited == 1)
return;
......@@ -132,6 +140,6 @@ void init_all(bool check_cert, bool sign_automatically) {
init_http_server();
}
init_enclave();
std::cerr << "enclave inited" << std::endl;
//std::cerr << "enclave inited" << std::endl;
init_daemon();
}
......@@ -30,6 +30,8 @@
#define EXTERNC
#endif
EXTERNC void init_all(bool check_cert, bool sign_automatically);
EXTERNC void init_daemon();
......
......@@ -68,8 +68,8 @@ int main(int argc, char *argv[]) {
if (strlen(argv[1]) == 2 ) {
fprintf(stderr, "-c client certificate will not be checked\n");
fprintf(stderr, "-s client certificate will be signed automatically\n");
printf(stderr, "-d turn on debug output\n");
printf(stderr, "-0 SGXWalletServer will be launched on http (not https)\n");
fprintf(stderr, "-d turn on debug output\n");
fprintf(stderr, "-0 SGXWalletServer will be launched on http (not https)\n");
exit(0);
} else {
fprintf(stderr, "unknown flag %s\n", argv[1]);
......
......@@ -33,6 +33,8 @@
#include <stdbool.h>
extern int DEBUG_PRINT;
extern int is_sgx_https;
......
......@@ -746,6 +746,7 @@ std::string ConvertDecToHex(std::string dec, int numBytes = 32){
TEST_CASE("BLS_DKG test", "[bls_dkg]") {
is_sgx_https = 0;
DEBUG_PRINT = 1;
std::cerr<< "test started" << std::endl;
init_all(false, false);
cerr << "Server inited" << endl;
......@@ -1066,7 +1067,7 @@ TEST_CASE("ManySimultaneousThreads", "[many_threads_test]") {
}
TEST_CASE("ecdsa API test", "[ecdsa_api_test]") {
//DEBUG_PRINT = 1;
DEBUG_PRINT = 1;
is_sgx_https = 0;
cerr << "ecdsa_api_test started" << endl;
......@@ -1110,7 +1111,7 @@ TEST_CASE("ecdsa API test", "[ecdsa_api_test]") {
}
TEST_CASE("dkg API test", "[dkg_api_test]") {
// DEBUG_PRINT = 1;
DEBUG_PRINT = 1;
is_sgx_https = 0;
cerr << "dkg_api_test started" << endl;
......
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