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
ebb1f0f7
Unverified
Commit
ebb1f0f7
authored
Aug 13, 2020
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-3067-cleanup-sgx
parent
0a3d24ea
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
30 deletions
+22
-30
SGXWalletServer.cpp
SGXWalletServer.cpp
+21
-30
sgxwallet_common.h
sgxwallet_common.h
+1
-0
No files found.
SGXWalletServer.cpp
View file @
ebb1f0f7
...
@@ -85,8 +85,8 @@ bool isStringDec(const string &_str) {
...
@@ -85,8 +85,8 @@ bool isStringDec(const string &_str) {
return
!
_str
.
empty
()
&&
res
==
_str
.
end
();
return
!
_str
.
empty
()
&&
res
==
_str
.
end
();
}
}
shared_ptr
<
SGXWalletServer
>
SGXWalletServer
::
server
=
nullptr
;
shared_ptr
<
SGXWalletServer
>
SGXWalletServer
::
server
=
nullptr
;
shared_ptr
<
HttpServer
>
SGXWalletServer
::
httpServer
=
nullptr
;
shared_ptr
<
HttpServer
>
SGXWalletServer
::
httpServer
=
nullptr
;
SGXWalletServer
::
SGXWalletServer
(
AbstractServerConnector
&
_connector
,
SGXWalletServer
::
SGXWalletServer
(
AbstractServerConnector
&
_connector
,
serverVersion_t
_type
)
serverVersion_t
_type
)
...
@@ -142,7 +142,7 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) {
...
@@ -142,7 +142,7 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) {
httpServer
=
make_shared
<
HttpServer
>
(
BASE_PORT
,
certPath
,
keyPath
,
rootCAPath
,
_checkCerts
,
64
);
httpServer
=
make_shared
<
HttpServer
>
(
BASE_PORT
,
certPath
,
keyPath
,
rootCAPath
,
_checkCerts
,
64
);
server
=
make_shared
<
SGXWalletServer
>
(
*
httpServer
,
server
=
make_shared
<
SGXWalletServer
>
(
*
httpServer
,
JSONRPC_SERVER_V2
);
// hybrid server (json-rpc 1.0 & 2.0)
JSONRPC_SERVER_V2
);
// hybrid server (json-rpc 1.0 & 2.0)
if
(
!
server
->
StartListening
())
{
if
(
!
server
->
StartListening
())
{
spdlog
::
error
(
"SGX Server could not start listening"
);
spdlog
::
error
(
"SGX Server could not start listening"
);
...
@@ -156,7 +156,7 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) {
...
@@ -156,7 +156,7 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) {
int
SGXWalletServer
::
initHttpServer
()
{
//without ssl
int
SGXWalletServer
::
initHttpServer
()
{
//without ssl
httpServer
=
make_shared
<
HttpServer
>
(
BASE_PORT
+
3
);
httpServer
=
make_shared
<
HttpServer
>
(
BASE_PORT
+
3
);
server
=
make_shared
<
SGXWalletServer
>
(
*
httpServer
,
server
=
make_shared
<
SGXWalletServer
>
(
*
httpServer
,
JSONRPC_SERVER_V2
);
// hybrid server (json-rpc 1.0 & 2.0)
JSONRPC_SERVER_V2
);
// hybrid server (json-rpc 1.0 & 2.0)
if
(
!
server
->
StartListening
())
{
if
(
!
server
->
StartListening
())
{
spdlog
::
error
(
"Server could not start listening"
);
spdlog
::
error
(
"Server could not start listening"
);
exit
(
-
1
);
exit
(
-
1
);
...
@@ -174,7 +174,7 @@ SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_k
...
@@ -174,7 +174,7 @@ SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_k
string
encryptedKeyShareHex
;
string
encryptedKeyShareHex
;
try
{
try
{
encryptedKeyShareHex
=
encryptBLSKeyShare2Hex
(
&
errStatus
,
(
char
*
)
errMsg
.
data
(),
_keyShare
.
c_str
());
encryptedKeyShareHex
=
encryptBLSKeyShare2Hex
(
&
errStatus
,
(
char
*
)
errMsg
.
data
(),
_keyShare
.
c_str
());
if
(
errStatus
!=
0
)
{
if
(
errStatus
!=
0
)
{
throw
SGXException
(
errStatus
,
errMsg
.
data
());
throw
SGXException
(
errStatus
,
errMsg
.
data
());
...
@@ -241,7 +241,6 @@ Json::Value SGXWalletServer::importECDSAKeyImpl(const string &_key, const string
...
@@ -241,7 +241,6 @@ Json::Value SGXWalletServer::importECDSAKeyImpl(const string &_key, const string
INIT_RESULT
(
result
)
INIT_RESULT
(
result
)
result
[
"encryptedKey"
]
=
""
;
result
[
"encryptedKey"
]
=
""
;
RETURN_SUCCESS
(
result
)
RETURN_SUCCESS
(
result
)
return
result
;
}
}
Json
::
Value
SGXWalletServer
::
generateECDSAKeyImpl
()
{
Json
::
Value
SGXWalletServer
::
generateECDSAKeyImpl
()
{
...
@@ -259,9 +258,6 @@ Json::Value SGXWalletServer::generateECDSAKeyImpl() {
...
@@ -259,9 +258,6 @@ Json::Value SGXWalletServer::generateECDSAKeyImpl() {
string
keyName
=
"NEK:"
+
keys
.
at
(
2
);
string
keyName
=
"NEK:"
+
keys
.
at
(
2
);
spdlog
::
debug
(
"key name generated: {}"
,
keyName
);
spdlog
::
debug
(
"write encr key {}"
,
keys
.
at
(
0
));
writeDataToDB
(
keyName
,
keys
.
at
(
0
));
writeDataToDB
(
keyName
,
keys
.
at
(
0
));
result
[
"encryptedKey"
]
=
keys
.
at
(
0
);
result
[
"encryptedKey"
]
=
keys
.
at
(
0
);
...
@@ -397,7 +393,7 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName,
...
@@ -397,7 +393,7 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName,
throw
SGXException
(
INVALID_DKG_PARAMS
,
"Invalid parameters: n or t "
);
throw
SGXException
(
INVALID_DKG_PARAMS
,
"Invalid parameters: n or t "
);
}
}
shared_ptr
<
string
>
encrPoly
=
readFromDb
(
_polyName
);
shared_ptr
<
string
>
encrPoly
=
readFromDb
(
_polyName
);
verifVector
=
get_verif_vect
(
encrPoly
->
c_str
(),
_t
,
_n
);
verifVector
=
get_verif_vect
(
encrPoly
->
c_str
(),
_t
,
_n
);
...
@@ -407,13 +403,10 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName,
...
@@ -407,13 +403,10 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName,
result
[
"verificationVector"
][
i
][
j
]
=
currentCoef
.
at
(
j
);
result
[
"verificationVector"
][
i
][
j
]
=
currentCoef
.
at
(
j
);
}
}
}
}
}
catch
(
SGXException
&
_e
)
{
}
HANDLE_SGX_EXCEPTION
(
result
)
result
[
"status"
]
=
_e
.
status
;
result
[
"errorMessage"
]
=
_e
.
errString
;
RETURN_SUCCESS
(
result
)
result
[
"verificationVector"
]
=
""
;
}
return
result
;
}
}
Json
::
Value
SGXWalletServer
::
getSecretShareImpl
(
const
string
&
_polyName
,
const
Json
::
Value
&
_pubKeys
,
int
_t
,
int
_n
)
{
Json
::
Value
SGXWalletServer
::
getSecretShareImpl
(
const
string
&
_polyName
,
const
Json
::
Value
&
_pubKeys
,
int
_t
,
int
_n
)
{
...
@@ -500,11 +493,11 @@ SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string
...
@@ -500,11 +493,11 @@ SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string
if
(
!
check_n_t
(
_t
,
_n
))
{
if
(
!
check_n_t
(
_t
,
_n
))
{
throw
SGXException
(
INVALID_DKG_PARAMS
,
"Invalid DKG parameters: n or t "
);
throw
SGXException
(
INVALID_DKG_PARAMS
,
"Invalid DKG parameters: n or t "
);
}
}
vector
<
string
>
sshares_vect
;
vector
<
string
>
sshares_vect
;
spdlog
::
debug
(
"secret shares from json are - {}"
,
_secretShare
);
shared_ptr
<
string
>
encryptedKeyHex_ptr
=
readFromDb
(
_ethKeyName
);
shared_ptr
<
string
>
encryptedKeyHex_ptr
=
readFromDb
(
_ethKeyName
);
bool
res
=
CreateBLSShare
(
_blsKeyName
,
_secretShare
.
c_str
(),
encryptedKeyHex_ptr
->
c_str
());
bool
res
=
CreateBLSShare
(
_blsKeyName
,
_secretShare
.
c_str
(),
encryptedKeyHex_ptr
->
c_str
());
if
(
res
)
{
if
(
res
)
{
...
@@ -582,7 +575,7 @@ Json::Value SGXWalletServer::isPolyExistsImpl(const string &_polyName) {
...
@@ -582,7 +575,7 @@ Json::Value SGXWalletServer::isPolyExistsImpl(const string &_polyName) {
result
[
"IsExist"
]
=
false
;
result
[
"IsExist"
]
=
false
;
try
{
try
{
s
td
::
shared_ptr
<
std
::
string
>
poly_str_ptr
=
LevelDB
::
getLevelDb
()
->
readString
(
_polyName
);
s
hared_ptr
<
string
>
poly_str_ptr
=
LevelDB
::
getLevelDb
()
->
readString
(
_polyName
);
if
(
poly_str_ptr
!=
nullptr
)
{
if
(
poly_str_ptr
!=
nullptr
)
{
result
[
"IsExist"
]
=
true
;
result
[
"IsExist"
]
=
true
;
...
@@ -603,7 +596,7 @@ Json::Value SGXWalletServer::getServerVersionImpl() {
...
@@ -603,7 +596,7 @@ Json::Value SGXWalletServer::getServerVersionImpl() {
RETURN_SUCCESS
(
result
)
RETURN_SUCCESS
(
result
)
}
}
Json
::
Value
SGXWalletServer
::
deleteBlsKeyImpl
(
const
st
d
::
string
&
name
)
{
Json
::
Value
SGXWalletServer
::
deleteBlsKeyImpl
(
const
st
ring
&
name
)
{
INIT_RESULT
(
result
)
INIT_RESULT
(
result
)
result
[
"deleted"
]
=
false
;
result
[
"deleted"
]
=
false
;
...
@@ -611,18 +604,18 @@ Json::Value SGXWalletServer::deleteBlsKeyImpl(const std::string& name) {
...
@@ -611,18 +604,18 @@ Json::Value SGXWalletServer::deleteBlsKeyImpl(const std::string& name) {
if
(
!
checkName
(
name
,
"BLS_KEY"
))
{
if
(
!
checkName
(
name
,
"BLS_KEY"
))
{
throw
SGXException
(
INVALID_BLS_NAME
,
"Invalid BLSKey name format"
);
throw
SGXException
(
INVALID_BLS_NAME
,
"Invalid BLSKey name format"
);
}
}
s
td
::
shared_ptr
<
std
::
string
>
bls_ptr
=
LevelDB
::
getLevelDb
()
->
readString
(
name
);
s
hared_ptr
<
string
>
bls_ptr
=
LevelDB
::
getLevelDb
()
->
readString
(
name
);
if
(
bls_ptr
!=
nullptr
)
{
if
(
bls_ptr
!=
nullptr
)
{
LevelDB
::
getLevelDb
()
->
deleteKey
(
name
);
LevelDB
::
getLevelDb
()
->
deleteKey
(
name
);
result
[
"deleted"
]
=
true
;
result
[
"deleted"
]
=
true
;
return
result
;
}
else
{
}
else
{
std
::
string
error_msg
=
"BLS key with such name
not found: "
+
name
;
auto
error_msg
=
"BLS key
not found: "
+
name
;
throw
SGXException
(
INVALID_BLS_NAME
,
error_msg
.
c_str
());
throw
SGXException
(
INVALID_BLS_NAME
,
error_msg
.
c_str
());
}
}
}
HANDLE_SGX_EXCEPTION
(
result
)
}
HANDLE_SGX_EXCEPTION
(
result
)
return
result
;
RETURN_SUCCESS
(
result
)
}
}
Json
::
Value
SGXWalletServer
::
generateDKGPoly
(
const
string
&
_polyName
,
int
_t
)
{
Json
::
Value
SGXWalletServer
::
generateDKGPoly
(
const
string
&
_polyName
,
int
_t
)
{
...
@@ -667,7 +660,6 @@ Json::Value SGXWalletServer::getPublicECDSAKey(const string &_keyName) {
...
@@ -667,7 +660,6 @@ Json::Value SGXWalletServer::getPublicECDSAKey(const string &_keyName) {
}
}
Json
::
Value
SGXWalletServer
::
ecdsaSignMessageHash
(
int
_base
,
const
string
&
_keyShareName
,
const
string
&
_messageHash
)
{
Json
::
Value
SGXWalletServer
::
ecdsaSignMessageHash
(
int
_base
,
const
string
&
_keyShareName
,
const
string
&
_messageHash
)
{
spdlog
::
debug
(
"MessageHash first {}"
,
_messageHash
);
return
ecdsaSignMessageHashImpl
(
_base
,
_keyShareName
,
_messageHash
);
return
ecdsaSignMessageHashImpl
(
_base
,
_keyShareName
,
_messageHash
);
}
}
...
@@ -706,7 +698,7 @@ Json::Value SGXWalletServer::getServerVersion() {
...
@@ -706,7 +698,7 @@ Json::Value SGXWalletServer::getServerVersion() {
return
getServerVersionImpl
();
return
getServerVersionImpl
();
}
}
Json
::
Value
SGXWalletServer
::
deleteBlsKey
(
const
st
d
::
string
&
name
)
{
Json
::
Value
SGXWalletServer
::
deleteBlsKey
(
const
st
ring
&
name
)
{
return
deleteBlsKeyImpl
(
name
);
return
deleteBlsKeyImpl
(
name
);
}
}
...
@@ -738,8 +730,7 @@ void SGXWalletServer::writeDataToDB(const string &Name, const string &value) {
...
@@ -738,8 +730,7 @@ void SGXWalletServer::writeDataToDB(const string &Name, const string &value) {
auto
key
=
Name
;
auto
key
=
Name
;
if
(
LevelDB
::
getLevelDb
()
->
readString
(
Name
)
!=
nullptr
)
{
if
(
LevelDB
::
getLevelDb
()
->
readString
(
Name
)
!=
nullptr
)
{
spdlog
::
info
(
"name {}"
,
Name
,
" already exists"
);
throw
SGXException
(
KEY_NAME_ALREADY_EXISTS
,
"Name already exists"
);
throw
SGXException
(
KEY_SHARE_ALREADY_EXISTS
,
"Key share already exists"
);
}
}
LevelDB
::
getLevelDb
()
->
writeString
(
key
,
value
);
LevelDB
::
getLevelDb
()
->
writeString
(
key
,
value
);
...
...
sgxwallet_common.h
View file @
ebb1f0f7
...
@@ -89,6 +89,7 @@ extern int autoconfirm;
...
@@ -89,6 +89,7 @@ extern int autoconfirm;
#define INVALID_ECDSA_KEY_NAME -20
#define INVALID_ECDSA_KEY_NAME -20
#define INVALID_HEX -21
#define INVALID_HEX -21
#define INVALID_ECSDA_SIGNATURE -22
#define INVALID_ECSDA_SIGNATURE -22
#define KEY_NAME_ALREADY_EXIST -23
#define ERROR_IN_ENCLAVE -33
#define ERROR_IN_ENCLAVE -33
...
...
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