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
908d0711
Unverified
Commit
908d0711
authored
Jan 25, 2020
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-2077 cleaned up LevelDB init
parent
b099b4fb
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
157 additions
and
84 deletions
+157
-84
CSRManagerServer.cpp
CSRManagerServer.cpp
+24
-24
LevelDB.cpp
LevelDB.cpp
+56
-19
LevelDB.h
LevelDB.h
+24
-6
SEKManager.cpp
SEKManager.cpp
+2
-2
SGXRegistrationServer.cpp
SGXRegistrationServer.cpp
+10
-10
SGXWalletServer.cpp
SGXWalletServer.cpp
+11
-11
ServerInit.cpp
ServerInit.cpp
+4
-11
ServerInit.h
ServerInit.h
+0
-1
common.h
common.h
+26
-0
No files found.
CSRManagerServer.cpp
View file @
908d0711
...
...
@@ -12,6 +12,7 @@
#include <jsonrpccpp/server/connectors/httpserver.h>
#include "spdlog/spdlog.h"
#include "common.h"
CSRManagerServer
*
cs
=
nullptr
;
...
...
@@ -27,15 +28,14 @@ Json::Value GetUnsignedCSRsImpl(){
Json
::
Value
result
;
result
[
"status"
]
=
0
;
result
[
"errorMessage"
]
=
""
;
//result["hashes"] =;
try
{
std
::
vector
<
std
::
string
>
hashes_vect
=
csrDb
->
writeKeysToVector1
(
MAX_CSR_NUM
);
for
(
int
i
=
0
;
i
<
hashes_vect
.
size
();
i
++
){
vector
<
string
>
hashes_vect
=
LevelDB
::
getCsrDb
()
->
writeKeysToVector1
(
MAX_CSR_NUM
);
for
(
int
i
=
0
;
i
<
(
int
)
hashes_vect
.
size
();
i
++
){
result
[
"hashes"
][
i
]
=
hashes_vect
.
at
(
i
);
}
}
catch
(
RPCException
&
_e
)
{
std
::
cerr
<<
" err str "
<<
_e
.
errString
<<
std
::
endl
;
cerr
<<
" err str "
<<
_e
.
errString
<<
endl
;
result
[
"status"
]
=
_e
.
status
;
result
[
"errorMessage"
]
=
_e
.
errString
;
...
...
@@ -44,7 +44,7 @@ Json::Value GetUnsignedCSRsImpl(){
return
result
;
}
Json
::
Value
SignByHashImpl
(
const
st
d
::
st
ring
&
hash
,
int
status
){
Json
::
Value
SignByHashImpl
(
const
string
&
hash
,
int
status
){
Json
::
Value
result
;
result
[
"errorMessage"
]
=
""
;
...
...
@@ -53,46 +53,46 @@ Json::Value SignByHashImpl(const std::string& hash, int status){
throw
RPCException
(
-
111
,
"Invalid csr status"
);
}
st
d
::
st
ring
csr_db_key
=
"CSR:HASH:"
+
hash
;
s
td
::
shared_ptr
<
std
::
string
>
csr_ptr
=
csrDb
->
readString
(
csr_db_key
);
string
csr_db_key
=
"CSR:HASH:"
+
hash
;
s
hared_ptr
<
string
>
csr_ptr
=
LevelDB
::
getCsrDb
()
->
readString
(
csr_db_key
);
if
(
csr_ptr
==
nullptr
){
throw
RPCException
(
KEY_SHARE_DOES_NOT_EXIST
,
"HASH DOES NOT EXIST IN DB"
);
}
if
(
status
==
0
)
{
st
d
::
st
ring
csr_name
=
"sgx_data/cert/"
+
hash
+
".csr"
;
std
::
ofstream
outfile
(
csr_name
);
outfile
<<
*
csr_ptr
<<
std
::
endl
;
string
csr_name
=
"sgx_data/cert/"
+
hash
+
".csr"
;
ofstream
outfile
(
csr_name
);
outfile
<<
*
csr_ptr
<<
endl
;
outfile
.
close
();
if
(
access
(
csr_name
.
c_str
(),
F_OK
)
!=
0
)
{
csrDb
->
deleteKey
(
csr_db_key
);
LevelDB
::
getCsrDb
()
->
deleteKey
(
csr_db_key
);
throw
RPCException
(
FILE_NOT_FOUND
,
"Csr does not exist"
);
}
st
d
::
st
ring
signClientCert
=
"cd sgx_data/cert && ./create_client_cert "
+
hash
;
string
signClientCert
=
"cd sgx_data/cert && ./create_client_cert "
+
hash
;
if
(
system
(
signClientCert
.
c_str
())
==
0
)
{
spdlog
::
info
(
"CLIENT CERTIFICATE IS SUCCESSFULLY GENERATED"
);
}
else
{
spdlog
::
info
(
"CLIENT CERTIFICATE GENERATION FAILED"
);
csrDb
->
deleteKey
(
csr_db_key
);
st
d
::
st
ring
status_db_key
=
"CSR:HASH:"
+
hash
+
"STATUS:"
;
csrStatusDb
->
deleteKey
(
status_db_key
);
csrStatusDb
->
writeDataUnique
(
status_db_key
,
"-1"
);
LevelDB
::
getCsrDb
()
->
deleteKey
(
csr_db_key
);
string
status_db_key
=
"CSR:HASH:"
+
hash
+
"STATUS:"
;
LevelDB
::
getCsrStatusDb
()
->
deleteKey
(
status_db_key
);
LevelDB
::
getCsrStatusDb
()
->
writeDataUnique
(
status_db_key
,
"-1"
);
throw
RPCException
(
FAIL_TO_CREATE_CERTIFICATE
,
"CLIENT CERTIFICATE GENERATION FAILED"
);
//exit(-1);
}
}
csrDb
->
deleteKey
(
csr_db_key
);
st
d
::
st
ring
status_db_key
=
"CSR:HASH:"
+
hash
+
"STATUS:"
;
csrStatusDb
->
deleteKey
(
status_db_key
);
csrStatusDb
->
writeDataUnique
(
status_db_key
,
std
::
to_string
(
status
));
LevelDB
::
getCsrDb
()
->
deleteKey
(
csr_db_key
);
string
status_db_key
=
"CSR:HASH:"
+
hash
+
"STATUS:"
;
LevelDB
::
getCsrStatusDb
()
->
deleteKey
(
status_db_key
);
LevelDB
::
getCsrStatusDb
()
->
writeDataUnique
(
status_db_key
,
to_string
(
status
));
result
[
"status"
]
=
status
;
}
catch
(
RPCException
&
_e
)
{
std
::
cerr
<<
" err str "
<<
_e
.
errString
<<
std
::
endl
;
cerr
<<
" err str "
<<
_e
.
errString
<<
endl
;
result
[
"status"
]
=
_e
.
status
;
result
[
"errorMessage"
]
=
_e
.
errString
;
}
...
...
@@ -102,12 +102,12 @@ Json::Value SignByHashImpl(const std::string& hash, int status){
Json
::
Value
CSRManagerServer
::
GetUnsignedCSRs
(){
std
::
lock_guard
<
std
::
recursive_mutex
>
lock
(
m
);
lock_guard
<
recursive_mutex
>
lock
(
m
);
return
GetUnsignedCSRsImpl
();
}
Json
::
Value
CSRManagerServer
::
SignByHash
(
const
st
d
::
st
ring
&
hash
,
int
status
){
std
::
lock_guard
<
std
::
recursive_mutex
>
lock
(
m
);
Json
::
Value
CSRManagerServer
::
SignByHash
(
const
string
&
hash
,
int
status
){
lock_guard
<
recursive_mutex
>
lock
(
m
);
return
SignByHashImpl
(
hash
,
status
);
}
...
...
LevelDB.cpp
View file @
908d0711
...
...
@@ -37,24 +37,24 @@
#include "ServerInit.h"
#include "spdlog/spdlog.h"
#include "common.h"
using
namespace
leveldb
;
static
WriteOptions
writeOptions
;
static
ReadOptions
readOptions
;
LevelDB
*
levelDb
=
nullptr
;
LevelDB
*
csrDb
=
nullptr
;
LevelDB
*
csrStatusDb
=
nullptr
;
std
::
shared_ptr
<
st
d
::
string
>
LevelDB
::
readString
(
const
std
::
string
&
_key
)
{
std
::
shared_ptr
<
st
ring
>
LevelDB
::
readString
(
const
string
&
_key
)
{
std
::
lock_guard
<
std
::
recursive_mutex
>
lock
(
mutex
);
auto
result
=
std
::
make_shared
<
st
d
::
st
ring
>
();
auto
result
=
std
::
make_shared
<
string
>
();
if
(
db
==
nullptr
)
{
throw
RPCException
(
NULL_DATABASE
,
"Null db"
);
...
...
@@ -75,7 +75,7 @@ std::shared_ptr<std::string> LevelDB::readString(const std::string &_key) {
return
result
;
}
void
LevelDB
::
writeString
(
const
st
d
::
string
&
_key
,
const
std
::
string
&
_value
)
{
void
LevelDB
::
writeString
(
const
st
ring
&
_key
,
const
string
&
_value
)
{
std
::
lock_guard
<
std
::
recursive_mutex
>
lock
(
mutex
);
...
...
@@ -90,11 +90,11 @@ void LevelDB::writeString(const std::string &_key, const std::string &_value) {
}
void
LevelDB
::
deleteDHDKGKey
(
const
st
d
::
st
ring
&
_key
)
{
void
LevelDB
::
deleteDHDKGKey
(
const
string
&
_key
)
{
std
::
lock_guard
<
std
::
recursive_mutex
>
lock
(
mutex
);
st
d
::
st
ring
full_key
=
"DKG_DH_KEY_"
+
_key
;
string
full_key
=
"DKG_DH_KEY_"
+
_key
;
auto
status
=
db
->
Delete
(
writeOptions
,
Slice
(
_key
));
...
...
@@ -106,11 +106,11 @@ void LevelDB::deleteDHDKGKey (const std::string &_key) {
}
}
void
LevelDB
::
deleteTempNEK
(
const
st
d
::
st
ring
&
_key
){
void
LevelDB
::
deleteTempNEK
(
const
string
&
_key
){
std
::
lock_guard
<
std
::
recursive_mutex
>
lock
(
mutex
);
st
d
::
st
ring
prefix
=
_key
.
substr
(
0
,
8
);
string
prefix
=
_key
.
substr
(
0
,
8
);
if
(
prefix
!=
"tmp_NEK:"
)
{
return
;
}
...
...
@@ -122,7 +122,7 @@ void LevelDB::deleteTempNEK(const std::string &_key){
std
::
cerr
<<
"key deleted "
<<
_key
<<
std
::
endl
;
}
void
LevelDB
::
deleteKey
(
const
st
d
::
st
ring
&
_key
){
void
LevelDB
::
deleteKey
(
const
string
&
_key
){
std
::
lock_guard
<
std
::
recursive_mutex
>
lock
(
mutex
);
...
...
@@ -149,7 +149,7 @@ void LevelDB::writeByteArray(const char *_key, size_t _keyLen, const char *value
}
void
LevelDB
::
writeByteArray
(
st
d
::
st
ring
&
_key
,
const
char
*
value
,
void
LevelDB
::
writeByteArray
(
string
&
_key
,
const
char
*
value
,
size_t
_valueLen
)
{
std
::
lock_guard
<
std
::
recursive_mutex
>
lock
(
mutex
);
...
...
@@ -188,13 +188,13 @@ uint64_t LevelDB::visitKeys(LevelDB::KeyVisitor *_visitor, uint64_t _maxKeysToVi
return
readCounter
;
}
std
::
vector
<
st
d
::
st
ring
>
LevelDB
::
writeKeysToVector1
(
uint64_t
_maxKeysToVisit
){
std
::
vector
<
string
>
LevelDB
::
writeKeysToVector1
(
uint64_t
_maxKeysToVisit
){
uint64_t
readCounter
=
0
;
std
::
vector
<
st
d
::
st
ring
>
keys
;
std
::
vector
<
string
>
keys
;
leveldb
::
Iterator
*
it
=
db
->
NewIterator
(
readOptions
);
for
(
it
->
SeekToFirst
();
it
->
Valid
();
it
->
Next
())
{
st
d
::
st
ring
cur_key
(
it
->
key
().
data
(),
it
->
key
().
size
());
string
cur_key
(
it
->
key
().
data
(),
it
->
key
().
size
());
keys
.
push_back
(
cur_key
);
// keys.push_back(it->key().data());
readCounter
++
;
...
...
@@ -208,7 +208,7 @@ std::vector<std::string> LevelDB::writeKeysToVector1(uint64_t _maxKeysToVisit){
return
keys
;
}
void
LevelDB
::
writeDataUnique
(
const
st
d
::
string
&
Name
,
const
std
::
string
&
value
)
{
void
LevelDB
::
writeDataUnique
(
const
st
ring
&
Name
,
const
string
&
value
)
{
auto
key
=
Name
;
...
...
@@ -226,7 +226,7 @@ void LevelDB::writeDataUnique(const std::string & Name, const std::string &value
}
LevelDB
::
LevelDB
(
st
d
::
st
ring
&
filename
)
{
LevelDB
::
LevelDB
(
string
&
filename
)
{
leveldb
::
Options
options
;
...
...
@@ -243,9 +243,46 @@ LevelDB::LevelDB(std::string &filename) {
}
LevelDB
::~
LevelDB
()
{
if
(
db
!=
nullptr
)
delete
db
;
}
const
std
::
shared_ptr
<
LevelDB
>
&
LevelDB
::
getLevelDb
()
{
CHECK_STATE
(
levelDb
)
return
levelDb
;
}
const
std
::
shared_ptr
<
LevelDB
>
&
LevelDB
::
getCsrDb
()
{
CHECK_STATE
(
csrDb
)
return
csrDb
;
}
const
std
::
shared_ptr
<
LevelDB
>
&
LevelDB
::
getCsrStatusDb
()
{
CHECK_STATE
(
csrStatusDb
)
return
csrStatusDb
;
}
std
::
shared_ptr
<
LevelDB
>
LevelDB
::
levelDb
=
nullptr
;
std
::
shared_ptr
<
LevelDB
>
LevelDB
::
csrDb
=
nullptr
;
std
::
shared_ptr
<
LevelDB
>
LevelDB
::
csrStatusDb
=
nullptr
;
std
::
shared_ptr
<
string
>
LevelDB
::
sgx_data_folder
=
nullptr
;
bool
LevelDB
::
isInited
=
false
;
void
LevelDB
::
initDBs
(
string
&
_sgx_data_folder
)
{
if
(
isInited
)
return
;
auto
dbName
=
_sgx_data_folder
+
WALLETDB_NAME
;
levelDb
=
make_shared
<
LevelDB
>
(
dbName
);
auto
csr_dbname
=
_sgx_data_folder
+
"CSR_DB"
;
csrDb
=
make_shared
<
LevelDB
>
(
csr_dbname
);
auto
csr_status_dbname
=
_sgx_data_folder
+
"CSR_STATUS_DB"
;
csrStatusDb
=
make_shared
<
LevelDB
>
(
csr_status_dbname
);
}
LevelDB.h
View file @
908d0711
...
...
@@ -29,7 +29,7 @@
#include <string>
#include <mutex>
#include <vector>
#include "common.h"
namespace
leveldb
{
class
DB
;
class
Status
;
...
...
@@ -40,7 +40,29 @@ class LevelDB {
std
::
recursive_mutex
mutex
;
leveldb
::
DB
*
db
;
std
::
shared_ptr
<
leveldb
::
DB
>
db
;
static
bool
isInited
;
static
std
::
shared_ptr
<
LevelDB
>
levelDb
;
static
std
::
shared_ptr
<
LevelDB
>
csrDb
;
static
std
::
shared_ptr
<
LevelDB
>
csrStatusDb
;
static
std
::
shared_ptr
<
std
::
string
>
sgx_data_folder
;
public
:
static
void
initDBs
(
std
::
string
&
_sgx_data_folder
);
static
const
std
::
shared_ptr
<
LevelDB
>
&
getLevelDb
();
static
const
std
::
shared_ptr
<
LevelDB
>
&
getCsrDb
();
static
const
std
::
shared_ptr
<
LevelDB
>
&
getCsrStatusDb
();
public
:
...
...
@@ -92,10 +114,6 @@ public:
};
extern
LevelDB
*
levelDb
;
extern
LevelDB
*
csrDb
;
extern
LevelDB
*
csrStatusDb
;
#endif
\ No newline at end of file
SEKManager.cpp
View file @
908d0711
...
...
@@ -47,9 +47,9 @@ void generate_SEK(){
char
*
hexEncrKey
=
(
char
*
)
calloc
(
2
*
enc_len
+
1
,
1
);
carray2Hex
(
encr_SEK
,
enc_len
,
hexEncrKey
);
std
::
cerr
<<
"key is "
<<
errMsg
<<
std
::
endl
;
std
::
ce
git
c
rr
<<
"key is "
<<
errMsg
<<
std
::
endl
;
levelDb
->
writeDataUnique
(
"SEK"
,
hexEncrKey
);
LevelDB
::
getLevelDb
()
->
writeDataUnique
(
"SEK"
,
hexEncrKey
);
free
(
errMsg
);
free
(
encr_SEK
);
...
...
SGXRegistrationServer.cpp
View file @
908d0711
...
...
@@ -75,7 +75,7 @@ Json::Value SignCertificateImpl(const std::string& csr, bool auto_sign = false){
std
::
string
hash
=
cryptlite
::
sha256
::
hash_hex
(
csr
);
if
(
!
auto_sign
)
{
std
::
string
db_key
=
"CSR:HASH:"
+
hash
;
csrDb
->
writeDataUnique
(
db_key
,
csr
);
LevelDB
::
getCsrStatusDb
()
->
writeDataUnique
(
db_key
,
csr
);
}
if
(
auto_sign
)
{
...
...
@@ -96,7 +96,7 @@ Json::Value SignCertificateImpl(const std::string& csr, bool auto_sign = false){
else
{
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
));
LevelDB
::
getCsrStatusDb
()
->
writeDataUnique
(
status_db_key
,
std
::
to_string
(
FAIL_TO_CREATE_CERTIFICATE
));
throw
RPCException
(
FAIL_TO_CREATE_CERTIFICATE
,
"CLIENT CERTIFICATE GENERATION FAILED"
);
//exit(-1);
}
...
...
@@ -106,7 +106,7 @@ Json::Value SignCertificateImpl(const std::string& csr, bool auto_sign = false){
result
[
"hash"
]
=
hash
;
std
::
string
db_key
=
"CSR:HASH:"
+
hash
+
"STATUS:"
;
csrStatusDb
->
writeDataUnique
(
db_key
,
status
);
LevelDB
::
getCsrStatusDb
()
->
writeDataUnique
(
db_key
,
status
);
}
catch
(
RPCException
&
_e
)
{
std
::
cerr
<<
" err str "
<<
_e
.
errString
<<
std
::
endl
;
...
...
@@ -123,21 +123,21 @@ Json::Value GetSertificateImpl(const std::string& hash){
std
::
string
cert
;
try
{
st
d
::
st
ring
db_key
=
"CSR:HASH:"
+
hash
+
"STATUS:"
;
s
td
::
shared_ptr
<
string
>
status_str_ptr
=
csrStatusDb
->
readString
(
db_key
);
string
db_key
=
"CSR:HASH:"
+
hash
+
"STATUS:"
;
s
hared_ptr
<
string
>
status_str_ptr
=
LevelDB
::
getCsrStatusDb
()
->
readString
(
db_key
);
if
(
status_str_ptr
==
nullptr
){
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
());
if
(
status
==
0
){
st
d
::
st
ring
crt_name
=
"cert/"
+
hash
+
".crt"
;
string
crt_name
=
"cert/"
+
hash
+
".crt"
;
//if (access(crt_name.c_str(), F_OK) == 0){
std
::
ifstream
infile
(
crt_name
);
ifstream
infile
(
crt_name
);
if
(
!
infile
.
is_open
())
{
st
d
::
st
ring
status_db_key
=
"CSR:HASH:"
+
hash
+
"STATUS:"
;
csrStatusDb
->
deleteKey
(
status_db_key
);
csrStatusDb
->
writeDataUnique
(
status_db_key
,
std
::
to_string
(
FILE_NOT_FOUND
));
string
status_db_key
=
"CSR:HASH:"
+
hash
+
"STATUS:"
;
LevelDB
::
getCsrStatusDb
()
->
deleteKey
(
status_db_key
);
LevelDB
::
getCsrStatusDb
()
->
writeDataUnique
(
status_db_key
,
std
::
to_string
(
FILE_NOT_FOUND
));
throw
RPCException
(
FILE_NOT_FOUND
,
"Certificate does not exist"
);
}
else
{
ostringstream
ss
;
...
...
SGXWalletServer.cpp
View file @
908d0711
...
...
@@ -77,7 +77,7 @@ void debug_print(){
MyVisitor
v
;
levelDb
->
visitKeys
(
&
v
,
100000000
);
LevelDB
::
getLevelDb
()
->
visitKeys
(
&
v
,
100000000
);
}
int
init_https_server
(
bool
check_certs
)
{
...
...
@@ -314,7 +314,7 @@ Json::Value renameECDSAKeyImpl(const std::string& KeyName, const std::string& te
std
::
shared_ptr
<
std
::
string
>
key_ptr
=
readFromDb
(
tempKeyName
);
std
::
cerr
<<
"new key name is "
<<
KeyName
<<
std
::
endl
;
writeDataToDB
(
KeyName
,
*
key_ptr
);
levelDb
->
deleteTempNEK
(
tempKeyName
);
LevelDB
::
getLevelDb
()
->
deleteTempNEK
(
tempKeyName
);
}
catch
(
RPCException
&
_e
)
{
std
::
cerr
<<
" err str "
<<
_e
.
errString
<<
std
::
endl
;
...
...
@@ -610,9 +610,9 @@ Json::Value CreateBLSPrivateKeyImpl(const std::string & BLSKeyName, const std::s
for
(
int
i
=
0
;
i
<
n
;
i
++
){
std
::
string
name
=
polyName
+
"_"
+
std
::
to_string
(
i
)
+
":"
;
levelDb
->
deleteDHDKGKey
(
name
);
LevelDB
::
getLevelDb
()
->
deleteDHDKGKey
(
name
);
std
::
string
shareG2_name
=
"shareG2_"
+
polyName
+
"_"
+
std
::
to_string
(
i
)
+
":"
;
levelDb
->
deleteKey
(
shareG2_name
);
LevelDB
::
getLevelDb
()
->
deleteKey
(
shareG2_name
);
}
}
catch
(
RPCException
&
_e
)
{
...
...
@@ -707,7 +707,7 @@ Json::Value MultG2Impl(const std::string& x){
Json
::
Value
IsPolyExistsImpl
(
const
std
::
string
&
polyName
){
Json
::
Value
result
;
std
::
shared_ptr
<
std
::
string
>
poly_str_ptr
=
levelDb
->
readString
(
polyName
);
std
::
shared_ptr
<
std
::
string
>
poly_str_ptr
=
LevelDB
::
getLevelDb
()
->
readString
(
polyName
);
result
[
"IsExist"
]
=
true
;
if
(
poly_str_ptr
==
nullptr
){
result
[
"IsExist"
]
=
false
;
...
...
@@ -825,7 +825,7 @@ Json::Value SGXWalletServer::getServerStatus() {
shared_ptr
<
string
>
readFromDb
(
const
string
&
name
,
const
string
&
prefix
)
{
auto
dataStr
=
levelDb
->
readString
(
prefix
+
name
);
auto
dataStr
=
LevelDB
::
getLevelDb
()
->
readString
(
prefix
+
name
);
if
(
dataStr
==
nullptr
)
{
throw
RPCException
(
KEY_SHARE_DOES_NOT_EXIST
,
"Data with this name does not exist"
);
...
...
@@ -836,7 +836,7 @@ shared_ptr<string> readFromDb(const string & name, const string & prefix) {
shared_ptr
<
string
>
readKeyShare
(
const
string
&
_keyShareName
)
{
auto
keyShareStr
=
levelDb
->
readString
(
"BLSKEYSHARE:"
+
_keyShareName
);
auto
keyShareStr
=
LevelDB
::
getLevelDb
()
->
readString
(
"BLSKEYSHARE:"
+
_keyShareName
);
if
(
keyShareStr
==
nullptr
)
{
throw
RPCException
(
KEY_SHARE_DOES_NOT_EXIST
,
"Key share with this name does not exist"
);
...
...
@@ -860,11 +860,11 @@ void writeKeyShare(const string &_keyShareName, const string &value, int index,
auto
key
=
"BLSKEYSHARE:"
+
_keyShareName
;
if
(
levelDb
->
readString
(
_keyShareName
)
!=
nullptr
)
{
if
(
LevelDB
::
getLevelDb
()
->
readString
(
_keyShareName
)
!=
nullptr
)
{
throw
RPCException
(
KEY_SHARE_ALREADY_EXISTS
,
"Key share with this name already exists"
);
}
levelDb
->
writeString
(
key
,
value
);
LevelDB
::
getLevelDb
()
->
writeString
(
key
,
value
);
}
void
writeDataToDB
(
const
string
&
Name
,
const
string
&
value
)
{
...
...
@@ -876,12 +876,12 @@ void writeDataToDB(const string & Name, const string &value) {
auto
key
=
Name
;
if
(
levelDb
->
readString
(
Name
)
!=
nullptr
)
{
if
(
LevelDB
::
getLevelDb
()
->
readString
(
Name
)
!=
nullptr
)
{
spdlog
::
info
(
"name {}"
,
Name
,
" already exists"
);
throw
RPCException
(
KEY_SHARE_ALREADY_EXISTS
,
"Data with this name already exists"
);
}
levelDb
->
writeString
(
key
,
value
);
LevelDB
::
getLevelDb
()
->
writeString
(
key
,
value
);
if
(
DEBUG_PRINT
)
{
spdlog
::
info
(
"{} "
,
Name
,
" is written to db "
);
}
...
...
ServerInit.cpp
View file @
908d0711
...
...
@@ -93,16 +93,10 @@ void init_daemon() {
}
}
static
std
::
string
dbName
=
sgx_data_folder
+
WALLETDB_NAME
;
levelDb
=
new
LevelDB
(
dbName
);
LevelDB
::
initDBs
(
sgx_data_folder
);
static
std
::
string
csr_dbname
=
sgx_data_folder
+
"CSR_DB"
;
csrDb
=
new
LevelDB
(
csr_dbname
);
static
std
::
string
csr_status_dbname
=
sgx_data_folder
+
"CSR_STATUS_DB"
;
csrStatusDb
=
new
LevelDB
(
csr_status_dbname
);
std
::
shared_ptr
<
std
::
string
>
encr_SEK_ptr
=
levelDb
->
readString
(
"SEK"
);
std
::
shared_ptr
<
std
::
string
>
encr_SEK_ptr
=
LevelDB
::
getLevelDb
()
->
readString
(
"SEK"
);
if
(
encr_SEK_ptr
==
nullptr
){
spdlog
::
info
(
"SEK was not created yet"
);
generate_SEK
();
...
...
@@ -116,9 +110,10 @@ void init_enclave() {
eid
=
0
;
updated
=
0
;
unsigned
long
support
;
#ifndef SGX_HW_SIM
unsigned
long
support
;
support
=
get_sgx_support
();
if
(
!
SGX_OK
(
support
))
{
sgx_support_perror
(
support
);
...
...
@@ -170,8 +165,6 @@ void init_all(bool check_cert, bool sign_automatically) {
sgxServerInited
=
1
;
init_daemon
();
if
(
is_sgx_https
)
{
init_https_server
(
check_cert
);
init_registration_server
(
sign_automatically
);
...
...
ServerInit.h
View file @
908d0711
...
...
@@ -31,7 +31,6 @@
#endif
EXTERNC
void
init_all
(
bool
check_cert
,
bool
sign_automatically
);
EXTERNC
void
init_daemon
();
...
...
common.h
0 → 100644
View file @
908d0711
//
// Created by kladko on 25.01.20.
//
#ifndef SGXWALLET_COMMON_H
#define SGXWALLET_COMMON_H
using
namespace
std
;
#include <stdlib.h>
#include <iostream>
#include <map>
#include <memory>
#define CHECK_ARGUMENT(_EXPRESSION_) \
if (!(_EXPRESSION_)) { \
auto __msg__ = string("Argument Check failed:") + #_EXPRESSION_ + "\n" + __CLASS_NAME__ + ":" + __FUNCTION__ + \
+ " " + string(__FILE__) + ":" + to_string(__LINE__); \
throw runtime_error(__msg__);}
#define CHECK_STATE(_EXPRESSION_) \
if (!(_EXPRESSION_)) { \
auto __msg__ = string("State check failed::") + #_EXPRESSION_ + " " + string(__FILE__) + ":" + to_string(__LINE__); \
throw runtime_error(__msg__);}
#endif //SGXWALLET_COMMON_H
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