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"
......
This diff is collapsed.
...@@ -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);
// } // }
// } // }
......
This diff is collapsed.
...@@ -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
This diff is collapsed.
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