Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sgxwallet
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
董子豪
sgxwallet
Commits
d73d650c
Unverified
Commit
d73d650c
authored
Jan 20, 2020
by
svetaro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-1990-Add-timestams-to-logs
parent
ba1019c1
Changes
13
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
169 additions
and
122 deletions
+169
-122
BLSCrypto.cpp
BLSCrypto.cpp
+4
-2
CSRManagerServer.cpp
CSRManagerServer.cpp
+7
-6
DKGCrypto.cpp
DKGCrypto.cpp
+33
-28
ECDSACrypto.cpp
ECDSACrypto.cpp
+12
-10
LevelDB.cpp
LevelDB.cpp
+22
-7
SGXRegistrationServer.cpp
SGXRegistrationServer.cpp
+12
-8
SGXWalletServer.cpp
SGXWalletServer.cpp
+41
-38
ServerDataChecker.cpp
ServerDataChecker.cpp
+16
-14
ServerInit.cpp
ServerInit.cpp
+13
-5
ServerInit.h
ServerInit.h
+2
-0
sgxwallet.c
sgxwallet.c
+2
-2
sgxwallet_common.h
sgxwallet_common.h
+2
-0
testw.cpp
testw.cpp
+3
-2
No files found.
BLSCrypto.cpp
View file @
d73d650c
...
@@ -50,7 +50,7 @@
...
@@ -50,7 +50,7 @@
#include "RPCException.h"
#include "RPCException.h"
#include "spdlog/spdlog.h"
int
char2int
(
char
_input
)
{
int
char2int
(
char
_input
)
{
if
(
_input
>=
'0'
&&
_input
<=
'9'
)
if
(
_input
>=
'0'
&&
_input
<=
'9'
)
...
@@ -187,7 +187,9 @@ char *encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key)
...
@@ -187,7 +187,9 @@ char *encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key)
status
=
encrypt_key
(
eid
,
errStatus
,
errMsg
,
keyArray
,
encryptedKey
,
&
encryptedLen
);
status
=
encrypt_key
(
eid
,
errStatus
,
errMsg
,
keyArray
,
encryptedKey
,
&
encryptedLen
);
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
)
{
if
(
status
!=
SGX_SUCCESS
)
{
...
...
CSRManagerServer.cpp
View file @
d73d650c
...
@@ -11,6 +11,8 @@
...
@@ -11,6 +11,8 @@
#include <jsonrpccpp/server/connectors/httpserver.h>
#include <jsonrpccpp/server/connectors/httpserver.h>
#include "spdlog/spdlog.h"
CSRManagerServer
*
cs
=
nullptr
;
CSRManagerServer
*
cs
=
nullptr
;
jsonrpc
::
HttpServer
*
hs3
=
nullptr
;
jsonrpc
::
HttpServer
*
hs3
=
nullptr
;
...
@@ -21,7 +23,7 @@ CSRManagerServer::CSRManagerServer(AbstractServerConnector &connector,
...
@@ -21,7 +23,7 @@ CSRManagerServer::CSRManagerServer(AbstractServerConnector &connector,
Json
::
Value
GetUnsignedCSRsImpl
(){
Json
::
Value
GetUnsignedCSRsImpl
(){
s
td
::
cerr
<<
"Enter GetUnsignedCSRsImpl"
<<
std
::
endl
;
s
pdlog
::
info
(
"Enter GetUnsignedCSRsImpl"
)
;
Json
::
Value
result
;
Json
::
Value
result
;
result
[
"status"
]
=
0
;
result
[
"status"
]
=
0
;
result
[
"errorMessage"
]
=
""
;
result
[
"errorMessage"
]
=
""
;
...
@@ -70,9 +72,9 @@ Json::Value SignByHashImpl(const std::string& hash, int status){
...
@@ -70,9 +72,9 @@ Json::Value SignByHashImpl(const std::string& hash, int status){
std
::
string
signClientCert
=
"cd cert && ./create_client_cert "
+
hash
;
std
::
string
signClientCert
=
"cd cert && ./create_client_cert "
+
hash
;
if
(
system
(
signClientCert
.
c_str
())
==
0
)
{
if
(
system
(
signClientCert
.
c_str
())
==
0
)
{
s
td
::
cerr
<<
"CLIENT CERTIFICATE IS SUCCESSFULLY GENERATED"
<<
std
::
endl
;
s
pdlog
::
info
(
"CLIENT CERTIFICATE IS SUCCESSFULLY GENERATED"
)
;
}
else
{
}
else
{
s
td
::
cerr
<<
"CLIENT CERTIFICATE GENERATION FAILED"
<<
std
::
endl
;
s
pdlog
::
info
(
"CLIENT CERTIFICATE GENERATION FAILED"
)
;
csrDb
->
deleteKey
(
csr_db_key
);
csrDb
->
deleteKey
(
csr_db_key
);
std
::
string
status_db_key
=
"CSR:HASH:"
+
hash
+
"STATUS:"
;
std
::
string
status_db_key
=
"CSR:HASH:"
+
hash
+
"STATUS:"
;
csrStatusDb
->
deleteKey
(
status_db_key
);
csrStatusDb
->
deleteKey
(
status_db_key
);
...
@@ -115,12 +117,11 @@ int init_csrmanager_server(){
...
@@ -115,12 +117,11 @@ int init_csrmanager_server(){
cs
=
new
CSRManagerServer
(
*
hs3
,
JSONRPC_SERVER_V2
);
// server (json-rpc 2.0)
cs
=
new
CSRManagerServer
(
*
hs3
,
JSONRPC_SERVER_V2
);
// server (json-rpc 2.0)
if
(
!
cs
->
StartListening
())
{
if
(
!
cs
->
StartListening
())
{
s
td
::
cerr
<<
"CSR manager server could not start listening"
<<
std
::
endl
;
s
pdlog
::
info
(
"CSR manager server could not start listening"
)
;
exit
(
-
1
);
exit
(
-
1
);
}
}
else
{
else
{
s
td
::
cerr
<<
"CSR manager server started on port "
<<
BASE_PORT
+
2
<<
std
::
endl
;
s
pdlog
::
info
(
"CSR manager server started on port {}"
,
BASE_PORT
+
2
)
;
}
}
std
::
cerr
<<
"CSR manager inited"
<<
std
::
endl
;
return
0
;
return
0
;
};
};
\ No newline at end of file
DKGCrypto.cpp
View file @
d73d650c
...
@@ -34,6 +34,8 @@
...
@@ -34,6 +34,8 @@
//#include <libBLS/libff/libff/algebra/curves/alt_bn128/alt_bn128_pp.hpp>
//#include <libBLS/libff/libff/algebra/curves/alt_bn128/alt_bn128_pp.hpp>
#include <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
::
vector
<
std
::
string
>
SplitString
(
const
char
*
koefs
,
const
char
symbol
){
std
::
string
str
(
koefs
);
std
::
string
str
(
koefs
);
std
::
string
delim
;
std
::
string
delim
;
...
@@ -86,13 +88,13 @@ std::string gen_dkg_poly( int _t){
...
@@ -86,13 +88,13 @@ std::string gen_dkg_poly( int _t){
}
}
if
(
DEBUG_PRINT
)
{
if
(
DEBUG_PRINT
)
{
s
td
::
cerr
<<
"gen_dkg_secret, status "
<<
err_status
<<
" err msg "
<<
errMsg
<<
std
::
endl
;
s
pdlog
::
info
(
"gen_dkg_secret, status {}"
,
err_status
,
" err msg "
,
errMsg
)
;
/* std::cerr << "encr raw poly: " << std::endl;
/* std::cerr << "encr raw poly: " << std::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] );*/
s
td
::
cerr
<<
"in DKGCrypto encr len is "
<<
enc_len
<<
std
::
endl
;
s
pdlog
::
info
(
"in DKGCrypto encr len is {}"
,
enc_len
)
;
}
}
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);
...
@@ -116,7 +118,7 @@ std::vector <std::vector<std::string>> get_verif_vect(const char* encryptedPolyH
...
@@ -116,7 +118,7 @@ std::vector <std::vector<std::string>> get_verif_vect(const char* encryptedPolyH
if
(
DEBUG_PRINT
)
{
if
(
DEBUG_PRINT
)
{
// std::cerr << "got encr poly " << encryptedPolyHex << std::endl;
// std::cerr << "got encr poly " << encryptedPolyHex << std::endl;
s
td
::
cerr
<<
"got encr poly size "
<<
strlen
(
encryptedPolyHex
)
<<
std
::
endl
;
s
pdlog
::
info
(
"got encr poly size {}"
,
strlen
(
encryptedPolyHex
))
;
}
}
char
*
public_shares
=
(
char
*
)
calloc
(
10000
,
1
);
char
*
public_shares
=
(
char
*
)
calloc
(
10000
,
1
);
...
@@ -129,7 +131,7 @@ std::vector <std::vector<std::string>> get_verif_vect(const char* encryptedPolyH
...
@@ -129,7 +131,7 @@ std::vector <std::vector<std::string>> get_verif_vect(const char* encryptedPolyH
}
}
if
(
DEBUG_PRINT
)
{
if
(
DEBUG_PRINT
)
{
s
td
::
cerr
<<
"enc len "
<<
enc_len
<<
std
::
endl
;
s
pdlog
::
info
(
"enc len {}"
,
enc_len
)
;
/*std::cerr << "encr raw poly: " << std::endl;
/*std::cerr << "encr raw poly: " << std::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] );*/
...
@@ -142,12 +144,14 @@ std::vector <std::vector<std::string>> get_verif_vect(const char* encryptedPolyH
...
@@ -142,12 +144,14 @@ std::vector <std::vector<std::string>> get_verif_vect(const char* encryptedPolyH
}
}
if
(
DEBUG_PRINT
)
{
if
(
DEBUG_PRINT
)
{
std
::
cerr
<<
"err msg "
<<
errMsg1
<<
std
::
endl
;
spdlog
::
info
(
"err msg is {}"
,
errMsg1
);
std
::
cerr
<<
"public_shares:"
<<
std
::
endl
;
std
::
cerr
<<
public_shares
<<
std
::
endl
;
printf
(
"
\n
get_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
,
','
);
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
...
@@ -191,7 +195,7 @@ std::string get_secret_shares(const std::string& polyName, const char* encrypted
char
s_shareG2
[
320
];
char
s_shareG2
[
320
];
std
::
string
pub_keyB
=
publicKeys
.
at
(
i
);
//publicKeys.substr(128*i, 128*i + 128);
std
::
string
pub_keyB
=
publicKeys
.
at
(
i
);
//publicKeys.substr(128*i, 128*i + 128);
if
(
DEBUG_PRINT
)
{
if
(
DEBUG_PRINT
)
{
s
td
::
cerr
<<
"pub_keyB is "
<<
pub_keyB
<<
std
::
endl
;
s
pdlog
::
info
(
"pub_keyB is {}"
,
pub_keyB
)
;
}
}
char
pubKeyB
[
129
];
char
pubKeyB
[
129
];
strncpy
(
pubKeyB
,
pub_keyB
.
c_str
(),
128
);
strncpy
(
pubKeyB
,
pub_keyB
.
c_str
(),
128
);
...
@@ -206,24 +210,25 @@ std::string get_secret_shares(const std::string& polyName, const char* encrypted
...
@@ -206,24 +210,25 @@ std::string get_secret_shares(const std::string& polyName, const char* encrypted
//uint32_t enc_len = BUF_LEN;
//uint32_t enc_len = BUF_LEN;
if
(
DEBUG_PRINT
)
{
if
(
DEBUG_PRINT
)
{
s
td
::
cerr
<<
"dec len is "
<<
dec_len
<<
std
::
endl
;
s
pdlog
::
info
(
"dec len is {}"
,
dec_len
)
;
}
}
carray2Hex
(
encrypted_skey
,
dec_len
,
hexEncrKey
);
carray2Hex
(
encrypted_skey
,
dec_len
,
hexEncrKey
);
std
::
string
DHKey_name
=
"DKG_DH_KEY_"
+
polyName
+
"_"
+
std
::
to_string
(
i
)
+
":"
;
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;
// std::cerr << "hexEncrKey: " << hexEncrKey << std::endl;
writeDataToDB
(
DHKey_name
,
hexEncrKey
);
writeDataToDB
(
DHKey_name
,
hexEncrKey
);
std
::
string
shareG2_name
=
"shareG2_"
+
polyName
+
"_"
+
std
::
to_string
(
i
)
+
":"
;
std
::
string
shareG2_name
=
"shareG2_"
+
polyName
+
"_"
+
std
::
to_string
(
i
)
+
":"
;
if
(
DEBUG_PRINT
)
{
if
(
DEBUG_PRINT
)
{
std
::
cerr
<<
"name to write to db is "
<<
shareG2_name
<<
std
::
endl
;
spdlog
::
info
(
"name to write to db is {}"
,
DHKey_name
);
std
::
cerr
<<
"s_shareG2: "
<<
s_shareG2
<<
std
::
endl
;
spdlog
::
info
(
"name to write to db is {}"
,
shareG2_name
);
spdlog
::
info
(
"s_shareG2: {}"
,
s_shareG2
);
}
}
writeDataToDB
(
shareG2_name
,
s_shareG2
);
writeDataToDB
(
shareG2_name
,
s_shareG2
);
if
(
DEBUG_PRINT
)
{
if
(
DEBUG_PRINT
)
{
s
td
::
cerr
<<
errMsg1
<<
std
::
endl
<<
std
::
endl
;
s
pdlog
::
info
(
"errMsg: {}"
,
errMsg1
)
;
// std::cerr << "iteration " << i <<" result length is " << result.length() << std::endl ;
// 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 length is " << strlen(cur_share) << std::endl;
// std::cerr << "iteration " << i <<" share is " << 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
...
@@ -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 << "encr_sshare length is " << strlen(encr_sshare) << std::endl; std::cerr << "public shares " << publicShares << std::endl;
s
td
::
cerr
<<
"publicShares length is "
<<
std
::
char_traits
<
char
>::
length
(
publicShares
)
<<
std
::
endl
;
//strlen(publicShares)<< std::endl
;
s
pdlog
::
info
(
"publicShares length is {}"
,
std
::
char_traits
<
char
>::
length
(
publicShares
))
;
}
}
char
pshares
[
8193
];
char
pshares
[
8193
];
strncpy
(
pshares
,
publicShares
,
strlen
(
publicShares
)
+
1
);
strncpy
(
pshares
,
publicShares
,
strlen
(
publicShares
)
+
1
);
...
@@ -267,8 +272,8 @@ bool VerifyShares(const char* publicShares, const char* encr_sshare, const char
...
@@ -267,8 +272,8 @@ bool VerifyShares(const char* publicShares, const char* encr_sshare, const char
}
}
if
(
DEBUG_PRINT
)
{
if
(
DEBUG_PRINT
)
{
s
td
::
cerr
<<
"errMsg1: "
<<
errMsg1
<<
std
::
endl
;
s
pdlog
::
info
(
"errMsg1: {}"
,
errMsg1
)
;
s
td
::
cerr
<<
"result is "
<<
result
<<
std
::
endl
;
s
pdlog
::
info
(
"result is: {}"
,
result
)
;
}
}
free
(
errMsg1
);
free
(
errMsg1
);
...
@@ -278,7 +283,7 @@ bool VerifyShares(const char* publicShares, const char* encr_sshare, const char
...
@@ -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
){
bool
CreateBLSShare
(
const
std
::
string
&
BLSKeyName
,
const
char
*
s_shares
,
const
char
*
encryptedKeyHex
){
if
(
DEBUG_PRINT
)
{
if
(
DEBUG_PRINT
)
{
s
td
::
cerr
<<
"ENTER CreateBLSShare"
<<
std
::
endl
;
s
pdlog
::
info
(
"ENTER CreateBLSShare"
)
;
}
}
char
*
errMsg1
=
(
char
*
)
calloc
(
1024
,
1
);
char
*
errMsg1
=
(
char
*
)
calloc
(
1024
,
1
);
int
err_status
=
0
;
int
err_status
=
0
;
...
@@ -296,7 +301,7 @@ bool CreateBLSShare( const std::string& BLSKeyName, const char * s_shares, const
...
@@ -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
);
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;
//std::cerr << "AFTER create_bls_key IN ENCLAVE er msg is " << errMsg1 << std::endl;
if
(
err_status
!=
0
){
if
(
err_status
!=
0
){
s
td
::
cerr
<<
"ERROR IN ENCLAVE"
<<
std
::
endl
;
s
pdlog
::
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
{
...
@@ -307,8 +312,8 @@ bool CreateBLSShare( const std::string& BLSKeyName, const char * s_shares, const
...
@@ -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;
// std::cerr << "BEFORE WRITE BLS KEY TO DB" << std::endl;
writeDataToDB
(
BLSKeyName
,
hexBLSKey
);
writeDataToDB
(
BLSKeyName
,
hexBLSKey
);
if
(
DEBUG_PRINT
)
{
if
(
DEBUG_PRINT
)
{
s
td
::
cerr
<<
"hexBLSKey length is "
<<
strlen
(
hexBLSKey
)
<<
std
::
endl
;
s
pdlog
::
info
(
"hexBLSKey length is {}"
,
strlen
(
hexBLSKey
))
;
s
td
::
cerr
<<
"bls key "
<<
BLSKeyName
<<
" is "
<<
hexBLSKey
<<
std
::
endl
;
s
pdlog
::
info
(
"bls key {}"
,
BLSKeyName
,
" is "
,
hexBLSKey
)
;
}
}
free
(
hexBLSKey
);
free
(
hexBLSKey
);
return
true
;
return
true
;
...
@@ -331,7 +336,7 @@ std::vector<std::string> GetBLSPubKey(const char * encryptedKeyHex){
...
@@ -331,7 +336,7 @@ std::vector<std::string> GetBLSPubKey(const char * encryptedKeyHex){
char
pub_key
[
320
];
char
pub_key
[
320
];
if
(
DEBUG_PRINT
)
{
if
(
DEBUG_PRINT
)
{
s
td
::
cerr
<<
"dec_key_len is "
<<
dec_key_len
<<
std
::
endl
;
s
pdlog
::
info
(
"dec_key_len is {}"
,
dec_key_len
)
;
}
}
get_bls_pub_key
(
eid
,
&
err_status
,
errMsg1
,
encr_key
,
dec_key_len
,
pub_key
);
get_bls_pub_key
(
eid
,
&
err_status
,
errMsg1
,
encr_key
,
dec_key_len
,
pub_key
);
if
(
err_status
!=
0
){
if
(
err_status
!=
0
){
...
@@ -340,10 +345,10 @@ std::vector<std::string> GetBLSPubKey(const char * encryptedKeyHex){
...
@@ -340,10 +345,10 @@ std::vector<std::string> GetBLSPubKey(const char * encryptedKeyHex){
std
::
vector
<
std
::
string
>
pub_key_vect
=
SplitString
(
pub_key
,
':'
);
std
::
vector
<
std
::
string
>
pub_key_vect
=
SplitString
(
pub_key
,
':'
);
if
(
DEBUG_PRINT
)
{
if
(
DEBUG_PRINT
)
{
s
td
::
cerr
<<
"errMsg1 is "
<<
errMsg1
<<
std
::
endl
;
s
pdlog
::
info
(
"errMsg1 is {}"
,
errMsg1
)
;
s
td
::
cerr
<<
"pub key is"
<<
std
::
endl
;
s
pdlog
::
info
(
"pub key is "
)
;
for
(
int
i
=
0
;
i
<
4
;
i
++
)
for
(
int
i
=
0
;
i
<
4
;
i
++
)
s
td
::
cerr
<<
pub_key_vect
.
at
(
i
)
<<
std
::
endl
;
s
pdlog
::
info
(
"{}"
,
pub_key_vect
.
at
(
i
))
;
}
}
return
pub_key_vect
;
return
pub_key_vect
;
}
}
...
@@ -356,7 +361,7 @@ std::string decrypt_DHKey(const std::string& polyName, int ind){
...
@@ -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
::
string
DH_key_name
=
polyName
+
"_"
+
std
::
to_string
(
ind
)
+
":"
;
std
::
shared_ptr
<
std
::
string
>
hexEncrKey_ptr
=
readFromDb
(
DH_key_name
,
"DKG_DH_KEY_"
);
std
::
shared_ptr
<
std
::
string
>
hexEncrKey_ptr
=
readFromDb
(
DH_key_name
,
"DKG_DH_KEY_"
);
if
(
DEBUG_PRINT
)
{
if
(
DEBUG_PRINT
)
{
s
td
::
cerr
<<
"encr DH key is "
<<
hexEncrKey_ptr
<<
std
::
endl
;
s
pdlog
::
info
(
"encr DH key is {}"
,
*
hexEncrKey_ptr
)
;
}
}
char
*
hexEncrKey
=
(
char
*
)
calloc
(
2
*
BUF_LEN
,
1
);
char
*
hexEncrKey
=
(
char
*
)
calloc
(
2
*
BUF_LEN
,
1
);
...
...
ECDSACrypto.cpp
View file @
d73d650c
...
@@ -31,6 +31,8 @@
...
@@ -31,6 +31,8 @@
#include <gmp.h>
#include <gmp.h>
#include <random>
#include <random>
#include "spdlog/spdlog.h"
static
std
::
default_random_engine
rand_gen
((
unsigned
int
)
time
(
0
));
static
std
::
default_random_engine
rand_gen
((
unsigned
int
)
time
(
0
));
...
@@ -66,7 +68,7 @@ std::vector<std::string> gen_ecdsa_key(){
...
@@ -66,7 +68,7 @@ std::vector<std::string> gen_ecdsa_key(){
unsigned
long
seed
=
rand_gen
();
unsigned
long
seed
=
rand_gen
();
if
(
DEBUG_PRINT
)
{
if
(
DEBUG_PRINT
)
{
s
td
::
cerr
<<
"seed is "
<<
seed
<<
std
::
endl
;
s
pdlog
::
info
(
"seed is {}"
,
seed
)
;
}
}
gmp_randstate_t
state
;
gmp_randstate_t
state
;
gmp_randinit_default
(
state
);
gmp_randinit_default
(
state
);
...
@@ -115,9 +117,9 @@ std::string get_ecdsa_pubkey(const char* encryptedKeyHex){
...
@@ -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);//
std
::
string
pubKey
=
std
::
string
(
pub_key_x
)
+
std
::
string
(
pub_key_y
);
//concatPubKeyWith0x(pub_key_x, pub_key_y);//
if
(
DEBUG_PRINT
)
{
if
(
DEBUG_PRINT
)
{
s
td
::
cerr
<<
"pubkey is "
<<
pubKey
<<
std
::
endl
;
s
pdlog
::
info
(
"pubkey is {}"
,
pubKey
)
;
s
td
::
cerr
<<
"pubkey length is "
<<
pubKey
.
length
()
<<
std
::
endl
;
s
pdlog
::
info
(
"pubkey length is {}"
,
pubKey
.
length
())
;
s
td
::
cerr
<<
"err str "
<<
errMsg
<<
std
::
endl
;
s
pdlog
::
info
(
"err str is {}"
,
errMsg
)
;
}
}
free
(
errMsg
);
free
(
errMsg
);
...
@@ -143,9 +145,9 @@ std::vector<std::string> ecdsa_sign_hash(const char* encryptedKeyHex, const char
...
@@ -143,9 +145,9 @@ std::vector<std::string> ecdsa_sign_hash(const char* encryptedKeyHex, const char
}
}
if
(
DEBUG_PRINT
)
{
if
(
DEBUG_PRINT
)
{
s
td
::
cerr
<<
"encryptedKeyHex: "
<<
encryptedKeyHex
<<
std
::
endl
;
s
pdlog
::
info
(
"encryptedKeyHex: {}"
,
encryptedKeyHex
)
;
s
td
::
cerr
<<
"HASH: "
<<
hashHex
<<
std
::
endl
;
s
pdlog
::
info
(
"HASH: {}"
,
hashHex
)
;
s
td
::
cerr
<<
"encrypted len"
<<
dec_len
<<
std
::
endl
;
s
pdlog
::
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
);
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
...
@@ -154,12 +156,12 @@ std::vector<std::string> ecdsa_sign_hash(const char* encryptedKeyHex, const char
}
}
if
(
DEBUG_PRINT
)
{
if
(
DEBUG_PRINT
)
{
s
td
::
cerr
<<
"signature r in ecdsa_sign_hash "
<<
signature_r
<<
std
::
endl
;
s
pdlog
::
info
(
"signature r in ecdsa_sign_hash: {}"
,
signature_r
)
;
s
td
::
cerr
<<
"signature s in ecdsa_sign_hash "
<<
signature_s
<<
std
::
endl
;
s
pdlog
::
info
(
"signature s in ecdsa_sign_hash: {}"
,
signature_s
)
;
}
}
if
(
status
!=
SGX_SUCCESS
){
if
(
status
!=
SGX_SUCCESS
){
s
td
::
cerr
<<
"failed to sign "
<<
std
::
endl
;
s
pdlog
::
info
(
" failed to sign "
)
;
}
}
signature_vect
.
at
(
0
)
=
std
::
to_string
(
signature_v
);
signature_vect
.
at
(
0
)
=
std
::
to_string
(
signature_v
);
if
(
base
==
16
)
{
if
(
base
==
16
)
{
...
...
LevelDB.cpp
View file @
d73d650c
...
@@ -36,6 +36,8 @@
...
@@ -36,6 +36,8 @@
#include "ServerInit.h"
#include "ServerInit.h"
#include "spdlog/spdlog.h"
using
namespace
leveldb
;
using
namespace
leveldb
;
...
@@ -64,7 +66,8 @@ std::shared_ptr<std::string> LevelDB::readString(const std::string &_key) {
...
@@ -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");
// throw RPCException(KEY_SHARE_DOES_NOT_EXIST, "Data with this name does not exist");
// }
// }
if
(
DEBUG_PRINT
)
{
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
);
throwExceptionOnError
(
status
);
...
@@ -84,7 +87,8 @@ void LevelDB::writeString(const std::string &_key, const std::string &_value) {
...
@@ -84,7 +87,8 @@ void LevelDB::writeString(const std::string &_key, const std::string &_value) {
throwExceptionOnError
(
status
);
throwExceptionOnError
(
status
);
if
(
DEBUG_PRINT
)
{
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) {
...
@@ -99,7 +103,11 @@ void LevelDB::deleteDHDKGKey (const std::string &_key) {
throwExceptionOnError
(
status
);
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
)
{
void
LevelDB
::
deleteOlegKey
(
const
std
::
string
&
_key
)
{
...
@@ -112,7 +120,9 @@ void LevelDB::deleteOlegKey (const std::string &_key) {
...
@@ -112,7 +120,9 @@ void LevelDB::deleteOlegKey (const std::string &_key) {
throwExceptionOnError
(
status
);
throwExceptionOnError
(
status
);
if
(
DEBUG_PRINT
)
{
std
::
cerr
<<
"key deleted "
<<
full_key
<<
std
::
endl
;
std
::
cerr
<<
"key deleted "
<<
full_key
<<
std
::
endl
;
}
}
}
void
LevelDB
::
deleteTempNEK
(
const
std
::
string
&
_key
){
void
LevelDB
::
deleteTempNEK
(
const
std
::
string
&
_key
){
...
@@ -140,7 +150,8 @@ void LevelDB::deleteKey(const std::string &_key){
...
@@ -140,7 +150,8 @@ void LevelDB::deleteKey(const std::string &_key){
throwExceptionOnError
(
status
);
throwExceptionOnError
(
status
);
if
(
DEBUG_PRINT
)
{
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
...
@@ -221,12 +232,16 @@ void LevelDB::writeDataUnique(const std::string & Name, const std::string &value
auto
key
=
Name
;
auto
key
=
Name
;
if
(
readString
(
Name
)
!=
nullptr
)
{
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"
);
throw
RPCException
(
KEY_SHARE_ALREADY_EXISTS
,
"Data with this name already exists"
);
}
}
writeString
(
key
,
value
);
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;
}
}
}
...
...
SGXRegistrationServer.cpp
View file @
d73d650c
...
@@ -43,6 +43,8 @@
...
@@ -43,6 +43,8 @@
#include "SGXRegistrationServer.h"
#include "SGXRegistrationServer.h"
#include "LevelDB.h"
#include "LevelDB.h"
#include "spdlog/spdlog.h"
int
DEBUG_PRINT
=
0
;
int
DEBUG_PRINT
=
0
;
int
is_sgx_https
=
1
;
int
is_sgx_https
=
1
;
...
@@ -66,7 +68,7 @@ Json::Value SignCertificateImpl(const std::string& csr, bool auto_sign = false){
...
@@ -66,7 +68,7 @@ Json::Value SignCertificateImpl(const std::string& csr, bool auto_sign = false){
result
[
"status"
]
=
0
;
result
[
"status"
]
=
0
;
result
[
"errorMessage"
]
=
""
;
result
[
"errorMessage"
]
=
""
;
try
{
try
{
s
td
::
cerr
<<
" enter SignCertificateImpl "
<<
std
::
endl
;
s
pdlog
::
info
(
"enter SignCertificateImpl"
)
;
std
::
string
status
=
"1"
;
std
::
string
status
=
"1"
;
std
::
string
hash
=
cryptlite
::
sha256
::
hash_hex
(
csr
);
std
::
string
hash
=
cryptlite
::
sha256
::
hash_hex
(
csr
);
...
@@ -87,11 +89,11 @@ Json::Value SignCertificateImpl(const std::string& csr, bool auto_sign = false){
...
@@ -87,11 +89,11 @@ Json::Value SignCertificateImpl(const std::string& csr, bool auto_sign = false){
std
::
string
genCert
=
"cd cert && ./create_client_cert "
+
hash
;
std
::
string
genCert
=
"cd cert && ./create_client_cert "
+
hash
;
if
(
system
(
genCert
.
c_str
())
==
0
){
if
(
system
(
genCert
.
c_str
())
==
0
){
s
td
::
cerr
<<
"CLIENT CERTIFICATE IS SUCCESSFULLY GENERATED"
<<
std
::
endl
;
s
pdlog
::
info
(
"CLIENT CERTIFICATE IS SUCCESSFULLY GENERATED"
)
;
status
=
"0"
;
status
=
"0"
;
}
}
else
{
else
{
s
td
::
cerr
<<
"CLIENT CERTIFICATE GENERATION FAILED"
<<
std
::
endl
;
s
pdlog
::
info
(
"CLIENT CERTIFICATE GENERATION FAILED"
)
;
std
::
string
status_db_key
=
"CSR:HASH:"
+
hash
+
"STATUS:"
;
std
::
string
status_db_key
=
"CSR:HASH:"
+
hash
+
"STATUS:"
;
csrStatusDb
->
writeDataUnique
(
status_db_key
,
std
::
to_string
(
FAIL_TO_CREATE_CERTIFICATE
));
csrStatusDb
->
writeDataUnique
(
status_db_key
,
std
::
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"
);
...
@@ -144,10 +146,12 @@ Json::Value GetSertificateImpl(const std::string& hash){
...
@@ -144,10 +146,12 @@ Json::Value GetSertificateImpl(const std::string& hash){
infile
.
close
();
infile
.
close
();
std
::
string
remove_crt
=
"cd cert && rm -rf "
+
hash
+
".crt && rm -rf "
+
hash
+
".csr"
;
std
::
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
;
//std::cerr << "cert removed" << std::endl;
spdlog
::
info
(
" cert removed "
);
}
}
else
{
else
{
s
td
::
cerr
<<
"cert was not removed"
<<
std
::
endl
;
s
pdlog
::
info
(
" cert was not removed "
)
;
}
}
}
}
...
@@ -167,7 +171,7 @@ Json::Value GetSertificateImpl(const std::string& hash){
...
@@ -167,7 +171,7 @@ Json::Value GetSertificateImpl(const std::string& hash){
Json
::
Value
SGXRegistrationServer
::
SignCertificate
(
const
std
::
string
&
csr
){
Json
::
Value
SGXRegistrationServer
::
SignCertificate
(
const
std
::
string
&
csr
){
s
td
::
cerr
<<
"Enter SignCertificate "
<<
std
::
endl
;
s
pdlog
::
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
);
}
}
...
@@ -208,11 +212,11 @@ int init_registration_server(bool sign_automatically) {
...
@@ -208,11 +212,11 @@ int init_registration_server(bool sign_automatically) {
JSONRPC_SERVER_V2
,
sign_automatically
);
// hybrid server (json-rpc 1.0 & 2.0)
JSONRPC_SERVER_V2
,
sign_automatically
);
// hybrid server (json-rpc 1.0 & 2.0)
if
(
!
regs
->
StartListening
())
{
if
(
!
regs
->
StartListening
())
{
cerr
<<
"Registration server could not start listening"
<<
endl
;
spdlog
::
info
(
"Registration server could not start listening"
)
;
exit
(
-
1
);
exit
(
-
1
);
}
}
else
{
else
{
cerr
<<
"Registration Server started on port "
<<
BASE_PORT
+
1
<<
endl
;
spdlog
::
info
(
"Registration server started on port {}"
,
BASE_PORT
+
1
)
;
}
}
...
...
SGXWalletServer.cpp
View file @
d73d650c
This diff is collapsed.
Click to expand it.
ServerDataChecker.cpp
View file @
d73d650c
...
@@ -27,6 +27,8 @@
...
@@ -27,6 +27,8 @@
#include <iostream>
#include <iostream>
#include "spdlog/spdlog.h"
std
::
vector
<
std
::
string
>
SplitString
(
const
std
::
string
&
str
,
const
std
::
string
&
delim
=
":"
){
std
::
vector
<
std
::
string
>
SplitString
(
const
std
::
string
&
str
,
const
std
::
string
&
delim
=
":"
){
std
::
vector
<
std
::
string
>
tokens
;
std
::
vector
<
std
::
string
>
tokens
;
size_t
prev
=
0
,
pos
=
0
;
size_t
prev
=
0
,
pos
=
0
;
...
@@ -44,15 +46,15 @@ std::vector<std::string> SplitString(const std::string& str, const std::string&
...
@@ -44,15 +46,15 @@ std::vector<std::string> SplitString(const std::string& str, const std::string&
bool
checkECDSAKeyName
(
const
std
::
string
&
keyName
)
{
bool
checkECDSAKeyName
(
const
std
::
string
&
keyName
)
{
std
::
vector
<
std
::
string
>
parts
=
SplitString
(
keyName
);
std
::
vector
<
std
::
string
>
parts
=
SplitString
(
keyName
);
if
(
parts
.
size
()
!=
2
)
{
if
(
parts
.
size
()
!=
2
)
{
s
td
::
cerr
<<
"num parts != 2"
<<
std
::
endl
;
s
pdlog
::
info
(
"ECDSAKeyName num parts != 2"
)
;
return
false
;
return
false
;
}
}
if
(
parts
.
at
(
0
)
!=
"NEK"
)
{
if
(
parts
.
at
(
0
)
!=
"NEK"
)
{
s
td
::
cerr
<<
"key doesn't start from NEK"
<<
std
::
endl
;
s
pdlog
::
info
(
"key doesn't start from NEK"
)
;
return
false
;
return
false
;
}
}
if
(
parts
.
at
(
1
).
length
()
>
64
||
parts
.
at
(
1
).
length
()
<
1
){
if
(
parts
.
at
(
1
).
length
()
>
64
||
parts
.
at
(
1
).
length
()
<
1
){
s
td
::
cerr
<<
"wrong key length"
<<
std
::
endl
;
s
pdlog
::
info
(
"wrong key length"
)
;
return
false
;
return
false
;
}
}
...
@@ -87,36 +89,36 @@ bool checkHex(const std::string& hex, const uint32_t sizeInBytes){
...
@@ -87,36 +89,36 @@ bool checkHex(const std::string& hex, const uint32_t sizeInBytes){
bool
checkName
(
const
std
::
string
&
Name
,
const
std
::
string
&
prefix
){
bool
checkName
(
const
std
::
string
&
Name
,
const
std
::
string
&
prefix
){
std
::
vector
<
std
::
string
>
parts
=
SplitString
(
Name
);
std
::
vector
<
std
::
string
>
parts
=
SplitString
(
Name
);
if
(
parts
.
size
()
!=
7
)
{
if
(
parts
.
size
()
!=
7
)
{
s
td
::
cerr
<<
"parts.size() != 7"
<<
std
::
endl
;
s
pdlog
::
info
(
"parts.size() != 7"
)
;
return
false
;
return
false
;
}
}
if
(
parts
.
at
(
0
)
!=
prefix
)
{
if
(
parts
.
at
(
0
)
!=
prefix
)
{
s
td
::
cerr
<<
"parts.at(0) != prefix"
<<
std
::
endl
;
s
pdlog
::
info
(
"parts.at(0) != prefix"
)
;
return
false
;
return
false
;
}
}
if
(
parts
.
at
(
1
)
!=
"SCHAIN_ID"
){
if
(
parts
.
at
(
1
)
!=
"SCHAIN_ID"
){
s
td
::
cerr
<<
"parts.at(1) != SCHAIN_ID"
<<
std
::
endl
;
s
pdlog
::
info
(
"parts.at(1) != SCHAIN_ID"
)
;
return
false
;
return
false
;
}
}
if
(
parts
.
at
(
3
)
!=
"NODE_ID"
){
if
(
parts
.
at
(
3
)
!=
"NODE_ID"
){
s
td
::
cerr
<<
"parts.at(3) != Node_ID"
<<
std
::
endl
;
s
pdlog
::
info
(
"parts.at(3) != Node_ID"
)
;
return
false
;
return
false
;
}
}
if
(
parts
.
at
(
5
)
!=
"DKG_ID"
){
if
(
parts
.
at
(
5
)
!=
"DKG_ID"
){
s
td
::
cerr
<<
"parts.at(1) != DKG_ID"
<<
std
::
endl
;
s
pdlog
::
info
(
"parts.at(1) != DKG_ID"
)
;
return
false
;
return
false
;
}
}
if
(
parts
.
at
(
2
).
length
()
>
78
||
parts
.
at
(
2
).
length
()
<
1
){
if
(
parts
.
at
(
2
).
length
()
>
78
||
parts
.
at
(
2
).
length
()
<
1
){
s
td
::
cerr
<<
"parts.at(2).length() > 78"
<<
std
::
endl
;
s
pdlog
::
info
(
"parts.at(2).length() > 78"
)
;
return
false
;
return
false
;
}
}
if
(
parts
.
at
(
4
).
length
()
>
5
||
parts
.
at
(
4
).
length
()
<
1
){
if
(
parts
.
at
(
4
).
length
()
>
5
||
parts
.
at
(
4
).
length
()
<
1
){
s
td
::
cerr
<<
"parts.at(4).length() > 5"
<<
std
::
endl
;
s
pdlog
::
info
(
"parts.at(4).length() > 5"
)
;
return
false
;
return
false
;
}
}
if
(
parts
.
at
(
6
).
length
()
>
78
||
parts
.
at
(
6
).
length
()
<
1
){
if
(
parts
.
at
(
6
).
length
()
>
78
||
parts
.
at
(
6
).
length
()
<
1
){
s
td
::
cerr
<<
"parts.at(6).length() > 78"
<<
std
::
endl
;
s
pdlog
::
info
(
"parts.at(6).length() > 78"
)
;
return
false
;
return
false
;
}
}
...
@@ -125,7 +127,7 @@ bool checkName (const std::string& Name, const std::string& prefix){
...
@@ -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
){
if
(
mpz_set_str
(
num
,
parts
.
at
(
2
).
c_str
(),
10
)
==
-
1
){
mpz_clear
(
num
);
mpz_clear
(
num
);
s
td
::
cerr
<<
"parts.at(2) not num"
<<
std
::
endl
;
s
pdlog
::
info
(
"parts.at(2) not num"
)
;
return
false
;
return
false
;
}
}
mpz_clear
(
num
);
mpz_clear
(
num
);
...
@@ -133,7 +135,7 @@ bool checkName (const std::string& Name, const std::string& prefix){
...
@@ -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
){
if
(
mpz_set_str
(
num
,
parts
.
at
(
4
).
c_str
(),
10
)
==
-
1
){
mpz_clear
(
num
);
mpz_clear
(
num
);
s
td
::
cerr
<<
"parts.at(4) not num"
<<
std
::
endl
;
s
pdlog
::
info
(
"parts.at(4) not num"
)
;
return
false
;
return
false
;
}
}
mpz_clear
(
num
);
mpz_clear
(
num
);
...
@@ -141,7 +143,7 @@ bool checkName (const std::string& Name, const std::string& prefix){
...
@@ -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
){
if
(
mpz_set_str
(
num
,
parts
.
at
(
6
).
c_str
(),
10
)
==
-
1
){
mpz_clear
(
num
);
mpz_clear
(
num
);
s
td
::
cerr
<<
"parts.at(6) not num"
<<
std
::
endl
;
s
pdlog
::
info
(
"parts.at(6) not num"
)
;
return
false
;
return
false
;
}
}
mpz_clear
(
num
);
mpz_clear
(
num
);
...
...
ServerInit.cpp
View file @
d73d650c
...
@@ -54,6 +54,7 @@
...
@@ -54,6 +54,7 @@
#include <iostream>
#include <iostream>
#include "spdlog/spdlog.h"
void
init_daemon
()
{
void
init_daemon
()
{
...
@@ -87,7 +88,10 @@ void init_enclave() {
...
@@ -87,7 +88,10 @@ void init_enclave() {
}
}
#endif
#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
,
status
=
sgx_create_enclave_search
(
ENCLAVE_NAME
,
SGX_DEBUG_FLAG
,
&
token
,
&
updated
,
&
eid
,
0
);
&
updated
,
&
eid
,
0
);
...
@@ -102,7 +106,8 @@ void init_enclave() {
...
@@ -102,7 +106,8 @@ void init_enclave() {
exit
(
1
);
exit
(
1
);
}
}
fprintf
(
stderr
,
"Enclave launched
\n
"
);
//fprintf(stderr, "Enclave launched\n");
spdlog
::
info
(
"Enclave launched"
);
status
=
tgmp_init
(
eid
);
status
=
tgmp_init
(
eid
);
if
(
status
!=
SGX_SUCCESS
)
{
if
(
status
!=
SGX_SUCCESS
)
{
...
@@ -110,14 +115,17 @@ void init_enclave() {
...
@@ -110,14 +115,17 @@ void init_enclave() {
exit
(
1
);
exit
(
1
);
}
}
fprintf
(
stderr
,
"libtgmp initialized
\n
"
);
if
(
DEBUG_PRINT
)
{
spdlog
::
info
(
"libtgmp initialized"
);
//fprintf(stderr, "libtgmp initialized\n");
}
}
}
int
sgxServerInited
=
0
;
int
sgxServerInited
=
0
;
void
init_all
(
bool
check_cert
,
bool
sign_automatically
)
{
void
init_all
(
bool
check_cert
,
bool
sign_automatically
)
{
//spdlog::set_pattern("%c");
if
(
sgxServerInited
==
1
)
if
(
sgxServerInited
==
1
)
return
;
return
;
...
@@ -132,6 +140,6 @@ void init_all(bool check_cert, bool sign_automatically) {
...
@@ -132,6 +140,6 @@ void init_all(bool check_cert, bool sign_automatically) {
init_http_server
();
init_http_server
();
}
}
init_enclave
();
init_enclave
();
std
::
cerr
<<
"enclave inited"
<<
std
::
endl
;
//
std::cerr << "enclave inited" << std::endl;
init_daemon
();
init_daemon
();
}
}
ServerInit.h
View file @
d73d650c
...
@@ -30,6 +30,8 @@
...
@@ -30,6 +30,8 @@
#define EXTERNC
#define EXTERNC
#endif
#endif
EXTERNC
void
init_all
(
bool
check_cert
,
bool
sign_automatically
);
EXTERNC
void
init_all
(
bool
check_cert
,
bool
sign_automatically
);
EXTERNC
void
init_daemon
();
EXTERNC
void
init_daemon
();
...
...
sgxwallet.c
View file @
d73d650c
...
@@ -68,8 +68,8 @@ int main(int argc, char *argv[]) {
...
@@ -68,8 +68,8 @@ int main(int argc, char *argv[]) {
if
(
strlen
(
argv
[
1
])
==
2
)
{
if
(
strlen
(
argv
[
1
])
==
2
)
{
fprintf
(
stderr
,
"-c client certificate will not be checked
\n
"
);
fprintf
(
stderr
,
"-c client certificate will not be checked
\n
"
);
fprintf
(
stderr
,
"-s client certificate will be signed automatically
\n
"
);
fprintf
(
stderr
,
"-s client certificate will be signed automatically
\n
"
);
printf
(
stderr
,
"-d turn on debug output
\n
"
);
f
printf
(
stderr
,
"-d turn on debug output
\n
"
);
printf
(
stderr
,
"-0 SGXWalletServer will be launched on http (not https)
\n
"
);
f
printf
(
stderr
,
"-0 SGXWalletServer will be launched on http (not https)
\n
"
);
exit
(
0
);
exit
(
0
);
}
else
{
}
else
{
fprintf
(
stderr
,
"unknown flag %s
\n
"
,
argv
[
1
]);
fprintf
(
stderr
,
"unknown flag %s
\n
"
,
argv
[
1
]);
...
...
sgxwallet_common.h
View file @
d73d650c
...
@@ -33,6 +33,8 @@
...
@@ -33,6 +33,8 @@
#include <stdbool.h>
#include <stdbool.h>
extern
int
DEBUG_PRINT
;
extern
int
DEBUG_PRINT
;
extern
int
is_sgx_https
;
extern
int
is_sgx_https
;
...
...
testw.cpp
View file @
d73d650c
...
@@ -746,6 +746,7 @@ std::string ConvertDecToHex(std::string dec, int numBytes = 32){
...
@@ -746,6 +746,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
;
std
::
cerr
<<
"test started"
<<
std
::
endl
;
std
::
cerr
<<
"test started"
<<
std
::
endl
;
init_all
(
false
,
false
);
init_all
(
false
,
false
);
cerr
<<
"Server inited"
<<
endl
;
cerr
<<
"Server inited"
<<
endl
;
...
@@ -1066,7 +1067,7 @@ TEST_CASE("ManySimultaneousThreads", "[many_threads_test]") {
...
@@ -1066,7 +1067,7 @@ TEST_CASE("ManySimultaneousThreads", "[many_threads_test]") {
}
}
TEST_CASE
(
"ecdsa API test"
,
"[ecdsa_api_test]"
)
{
TEST_CASE
(
"ecdsa API test"
,
"[ecdsa_api_test]"
)
{
//
DEBUG_PRINT = 1;
DEBUG_PRINT
=
1
;
is_sgx_https
=
0
;
is_sgx_https
=
0
;
cerr
<<
"ecdsa_api_test started"
<<
endl
;
cerr
<<
"ecdsa_api_test started"
<<
endl
;
...
@@ -1110,7 +1111,7 @@ TEST_CASE("ecdsa API test", "[ecdsa_api_test]") {
...
@@ -1110,7 +1111,7 @@ TEST_CASE("ecdsa API test", "[ecdsa_api_test]") {
}
}
TEST_CASE
(
"dkg API test"
,
"[dkg_api_test]"
)
{
TEST_CASE
(
"dkg API test"
,
"[dkg_api_test]"
)
{
//
DEBUG_PRINT = 1;
DEBUG_PRINT
=
1
;
is_sgx_https
=
0
;
is_sgx_https
=
0
;
cerr
<<
"dkg_api_test started"
<<
endl
;
cerr
<<
"dkg_api_test started"
<<
endl
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment