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
8250f8b2
Unverified
Commit
8250f8b2
authored
Mar 12, 2020
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix test
parent
a7b11c04
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
126 additions
and
124 deletions
+126
-124
SGXWalletServer.cpp
SGXWalletServer.cpp
+86
-86
SGXWalletServer.hpp
SGXWalletServer.hpp
+39
-37
start.sh
docker/start.sh
+1
-1
No files found.
SGXWalletServer.cpp
View file @
8250f8b2
...
...
@@ -138,7 +138,7 @@ int SGXWalletServer::initHttpServer() { //without ssl
}
Json
::
Value
SGXWalletServer
::
importBLSKeyShareImpl
(
const
string
&
_keyShare
,
const
string
&
_keyShareName
,
int
t
,
int
n
,
int
index
)
{
SGXWalletServer
::
importBLSKeyShareImpl
(
const
string
&
_keyShare
,
const
string
&
_keyShareName
,
int
t
,
int
n
,
int
_
index
)
{
Json
::
Value
result
;
int
errStatus
=
UNKNOWN_ERROR
;
...
...
@@ -164,7 +164,7 @@ SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_k
result
[
"encryptedKeyShare"
]
=
string
(
encryptedKeyShareHex
);
writeKeyShare
(
_keyShareName
,
encryptedKeyShareHex
,
index
,
n
,
t
);
writeKeyShare
(
_keyShareName
,
encryptedKeyShareHex
,
_
index
,
n
,
t
);
}
catch
(
RPCException
&
_e
)
{
result
[
"status"
]
=
_e
.
status
;
...
...
@@ -179,7 +179,7 @@ SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_k
}
Json
::
Value
SGXWalletServer
::
blsSignMessageHashImpl
(
const
string
&
keyShareName
,
const
string
&
messageHash
,
int
t
,
int
n
,
int
signerIndex
)
{
SGXWalletServer
::
blsSignMessageHashImpl
(
const
string
&
_keyShareName
,
const
string
&
_messageHash
,
int
t
,
int
n
,
int
_
signerIndex
)
{
Json
::
Value
result
;
result
[
"status"
]
=
-
1
;
result
[
"errorMessage"
]
=
"Unknown server error"
;
...
...
@@ -190,10 +190,10 @@ SGXWalletServer::blsSignMessageHashImpl(const string &keyShareName, const string
shared_ptr
<
string
>
value
=
nullptr
;
try
{
if
(
!
checkName
(
keyShareName
,
"BLS_KEY"
))
{
if
(
!
checkName
(
_
keyShareName
,
"BLS_KEY"
))
{
throw
RPCException
(
INVALID_POLY_NAME
,
"Invalid BLSKey name"
);
}
string
cutHash
=
messageHash
;
string
cutHash
=
_
messageHash
;
if
(
cutHash
[
0
]
==
'0'
&&
(
cutHash
[
1
]
==
'x'
||
cutHash
[
1
]
==
'X'
))
{
cutHash
.
erase
(
cutHash
.
begin
(),
cutHash
.
begin
()
+
2
);
}
...
...
@@ -205,7 +205,7 @@ SGXWalletServer::blsSignMessageHashImpl(const string &keyShareName, const string
throw
RPCException
(
INVALID_HEX
,
"Invalid hash"
);
}
value
=
readFromDb
(
keyShareName
);
value
=
readFromDb
(
_
keyShareName
);
}
catch
(
RPCException
_e
)
{
result
[
"status"
]
=
_e
.
status
;
result
[
"errorMessage"
]
=
_e
.
errString
;
...
...
@@ -219,7 +219,7 @@ SGXWalletServer::blsSignMessageHashImpl(const string &keyShareName, const string
}
try
{
if
(
!
bls_sign
(
value
->
c_str
(),
messageHash
.
c_str
(),
t
,
n
,
signerIndex
,
signature
))
{
if
(
!
bls_sign
(
value
->
c_str
(),
_messageHash
.
c_str
(),
t
,
n
,
_
signerIndex
,
signature
))
{
result
[
"status"
]
=
-
1
;
result
[
"errorMessage"
]
=
"Could not sign"
;
return
result
;
...
...
@@ -287,7 +287,7 @@ Json::Value SGXWalletServer::generateECDSAKeyImpl() {
return
result
;
}
Json
::
Value
SGXWalletServer
::
renameECDSAKeyImpl
(
const
string
&
KeyName
,
const
string
&
tempKeyName
)
{
Json
::
Value
SGXWalletServer
::
renameECDSAKeyImpl
(
const
string
&
_keyName
,
const
string
&
_
tempKeyName
)
{
Json
::
Value
result
;
result
[
"status"
]
=
0
;
result
[
"errorMessage"
]
=
""
;
...
...
@@ -295,23 +295,23 @@ Json::Value SGXWalletServer::renameECDSAKeyImpl(const string &KeyName, const str
try
{
string
prefix
=
tempKeyName
.
substr
(
0
,
8
);
string
prefix
=
_
tempKeyName
.
substr
(
0
,
8
);
if
(
prefix
!=
"tmp_NEK:"
)
{
throw
RPCException
(
UNKNOWN_ERROR
,
"wrong temp key name"
);
}
prefix
=
K
eyName
.
substr
(
0
,
12
);
prefix
=
_k
eyName
.
substr
(
0
,
12
);
if
(
prefix
!=
"NEK_NODE_ID:"
)
{
throw
RPCException
(
UNKNOWN_ERROR
,
"wrong key name"
);
}
string
postfix
=
KeyName
.
substr
(
12
,
K
eyName
.
length
());
string
postfix
=
_keyName
.
substr
(
12
,
_k
eyName
.
length
());
if
(
!
isStringDec
(
postfix
))
{
throw
RPCException
(
UNKNOWN_ERROR
,
"wrong key name"
);
}
shared_ptr
<
string
>
key_ptr
=
readFromDb
(
tempKeyName
);
cerr
<<
"new key name is "
<<
K
eyName
<<
endl
;
writeDataToDB
(
K
eyName
,
*
key_ptr
);
LevelDB
::
getLevelDb
()
->
deleteTempNEK
(
tempKeyName
);
shared_ptr
<
string
>
key_ptr
=
readFromDb
(
_
tempKeyName
);
cerr
<<
"new key name is "
<<
_k
eyName
<<
endl
;
writeDataToDB
(
_k
eyName
,
*
key_ptr
);
LevelDB
::
getLevelDb
()
->
deleteTempNEK
(
_
tempKeyName
);
}
catch
(
RPCException
&
_e
)
{
cerr
<<
" err str "
<<
_e
.
errString
<<
endl
;
...
...
@@ -323,7 +323,7 @@ Json::Value SGXWalletServer::renameECDSAKeyImpl(const string &KeyName, const str
}
Json
::
Value
SGXWalletServer
::
ecdsaSignMessageHashImpl
(
int
base
,
const
string
&
_keyName
,
const
string
&
messageHash
)
{
Json
::
Value
SGXWalletServer
::
ecdsaSignMessageHashImpl
(
int
_base
,
const
string
&
_keyName
,
const
string
&
_
messageHash
)
{
Json
::
Value
result
;
result
[
"status"
]
=
0
;
result
[
"errorMessage"
]
=
""
;
...
...
@@ -334,12 +334,12 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int base, const string &_k
vector
<
string
>
sign_vect
(
3
);
if
(
printDebugInfo
)
{
spdlog
::
info
(
"entered ecdsaSignMessageHashImpl {}"
,
messageHash
,
"length {}"
,
messageHash
.
length
());
spdlog
::
info
(
"entered ecdsaSignMessageHashImpl {}"
,
_messageHash
,
"length {}"
,
_
messageHash
.
length
());
}
try
{
string
cutHash
=
messageHash
;
string
cutHash
=
_
messageHash
;
if
(
cutHash
[
0
]
==
'0'
&&
(
cutHash
[
1
]
==
'x'
||
cutHash
[
1
]
==
'X'
))
{
cutHash
.
erase
(
cutHash
.
begin
(),
cutHash
.
begin
()
+
2
);
}
...
...
@@ -357,13 +357,13 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int base, const string &_k
if
(
!
checkHex
(
cutHash
))
{
throw
RPCException
(
INVALID_HEX
,
"Invalid hash"
);
}
if
(
base
<=
0
||
base
>
32
)
{
if
(
_base
<=
0
||
_
base
>
32
)
{
throw
RPCException
(
-
22
,
"Invalid base"
);
}
shared_ptr
<
string
>
key_ptr
=
readFromDb
(
_keyName
,
""
);
sign_vect
=
ecdsa_sign_hash
(
key_ptr
->
c_str
(),
cutHash
.
c_str
(),
base
);
sign_vect
=
ecdsa_sign_hash
(
key_ptr
->
c_str
(),
cutHash
.
c_str
(),
_
base
);
if
(
sign_vect
.
size
()
!=
3
)
{
throw
RPCException
(
INVALID_ECSDA_SIGNATURE
,
"Invalid ecdsa signature"
);
}
...
...
@@ -385,7 +385,7 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int base, const string &_k
return
result
;
}
Json
::
Value
SGXWalletServer
::
getPublicECDSAKeyImpl
(
const
string
&
keyName
)
{
Json
::
Value
SGXWalletServer
::
getPublicECDSAKeyImpl
(
const
string
&
_
keyName
)
{
Json
::
Value
result
;
result
[
"status"
]
=
0
;
result
[
"errorMessage"
]
=
""
;
...
...
@@ -396,10 +396,10 @@ Json::Value SGXWalletServer::getPublicECDSAKeyImpl(const string &keyName) {
string
Pkey
;
try
{
if
(
!
checkECDSAKeyName
(
keyName
))
{
if
(
!
checkECDSAKeyName
(
_
keyName
))
{
throw
RPCException
(
INVALID_ECDSA_KEY_NAME
,
"Invalid ECDSA key name"
);
}
shared_ptr
<
string
>
key_ptr
=
readFromDb
(
keyName
);
shared_ptr
<
string
>
key_ptr
=
readFromDb
(
_
keyName
);
Pkey
=
get_ecdsa_pubkey
(
key_ptr
->
c_str
());
if
(
printDebugInfo
)
{
spdlog
::
info
(
"PublicKey {}"
,
Pkey
);
...
...
@@ -415,7 +415,7 @@ Json::Value SGXWalletServer::getPublicECDSAKeyImpl(const string &keyName) {
return
result
;
}
Json
::
Value
SGXWalletServer
::
generateDKGPolyImpl
(
const
string
&
polyName
,
int
t
)
{
Json
::
Value
SGXWalletServer
::
generateDKGPolyImpl
(
const
string
&
_polyName
,
int
_
t
)
{
Json
::
Value
result
;
result
[
"status"
]
=
0
;
...
...
@@ -425,15 +425,15 @@ Json::Value SGXWalletServer::generateDKGPolyImpl(const string &polyName, int t)
string
encrPolyHex
;
try
{
if
(
!
checkName
(
polyName
,
"POLY"
))
{
if
(
!
checkName
(
_
polyName
,
"POLY"
))
{
throw
RPCException
(
INVALID_POLY_NAME
,
"Invalid polynomial name, it should be like POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1"
);
}
if
(
t
<=
0
||
t
>
32
)
{
if
(
_t
<=
0
||
_
t
>
32
)
{
throw
RPCException
(
INVALID_DKG_PARAMS
,
"Invalid parameter t "
);
}
encrPolyHex
=
gen_dkg_poly
(
t
);
writeDataToDB
(
polyName
,
encrPolyHex
);
encrPolyHex
=
gen_dkg_poly
(
_
t
);
writeDataToDB
(
_
polyName
,
encrPolyHex
);
//result["encryptedPoly"] = encrPolyHex;
}
catch
(
RPCException
&
_e
)
{
...
...
@@ -445,7 +445,7 @@ Json::Value SGXWalletServer::generateDKGPolyImpl(const string &polyName, int t)
return
result
;
}
Json
::
Value
SGXWalletServer
::
getVerificationVectorImpl
(
const
string
&
polyName
,
int
t
,
int
n
)
{
Json
::
Value
SGXWalletServer
::
getVerificationVectorImpl
(
const
string
&
_polyName
,
int
_t
,
int
_
n
)
{
Json
::
Value
result
;
result
[
"status"
]
=
0
;
...
...
@@ -453,19 +453,19 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &polyName, i
vector
<
vector
<
string
>>
verifVector
;
try
{
if
(
!
checkName
(
polyName
,
"POLY"
))
{
if
(
!
checkName
(
_
polyName
,
"POLY"
))
{
throw
RPCException
(
INVALID_POLY_NAME
,
"Invalid polynomial name"
);
}
if
(
!
check_n_t
(
t
,
n
))
{
if
(
!
check_n_t
(
_t
,
_
n
))
{
throw
RPCException
(
INVALID_DKG_PARAMS
,
"Invalid parameters: n or t "
);
}
shared_ptr
<
string
>
encr_poly_ptr
=
readFromDb
(
polyName
);
shared_ptr
<
string
>
encr_poly_ptr
=
readFromDb
(
_
polyName
);
verifVector
=
get_verif_vect
(
encr_poly_ptr
->
c_str
(),
t
,
n
);
verifVector
=
get_verif_vect
(
encr_poly_ptr
->
c_str
(),
_t
,
_
n
);
//cerr << "verif vect size " << verifVector.size() << endl;
for
(
int
i
=
0
;
i
<
t
;
i
++
)
{
for
(
int
i
=
0
;
i
<
_
t
;
i
++
)
{
vector
<
string
>
cur_coef
=
verifVector
.
at
(
i
);
for
(
int
j
=
0
;
j
<
4
;
j
++
)
{
result
[
"verificationVector"
][
i
][
j
]
=
cur_coef
.
at
(
j
);
...
...
@@ -482,35 +482,35 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &polyName, i
return
result
;
}
Json
::
Value
SGXWalletServer
::
getSecretShareImpl
(
const
string
&
polyName
,
const
Json
::
Value
&
publicKeys
,
int
t
,
int
n
)
{
Json
::
Value
SGXWalletServer
::
getSecretShareImpl
(
const
string
&
_polyName
,
const
Json
::
Value
&
_publicKeys
,
int
_t
,
int
_
n
)
{
spdlog
::
info
(
"enter getSecretShareImpl"
);
Json
::
Value
result
;
result
[
"status"
]
=
0
;
result
[
"errorMessage"
]
=
""
;
try
{
if
(
publicKeys
.
size
()
!=
(
uint64_t
)
n
)
{
if
(
_publicKeys
.
size
()
!=
(
uint64_t
)
_
n
)
{
throw
RPCException
(
INVALID_DKG_PARAMS
,
"wrong number of public keys"
);
}
if
(
!
checkName
(
polyName
,
"POLY"
))
{
if
(
!
checkName
(
_
polyName
,
"POLY"
))
{
throw
RPCException
(
INVALID_POLY_NAME
,
"Invalid polynomial name"
);
}
if
(
!
check_n_t
(
t
,
n
))
{
if
(
!
check_n_t
(
_t
,
_
n
))
{
throw
RPCException
(
INVALID_DKG_PARAMS
,
"Invalid DKG parameters: n or t "
);
}
shared_ptr
<
string
>
encr_poly_ptr
=
readFromDb
(
polyName
);
shared_ptr
<
string
>
encr_poly_ptr
=
readFromDb
(
_
polyName
);
vector
<
string
>
pubKeys_vect
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
std
::
cerr
<<
"publicKeys "
<<
i
<<
" is "
<<
publicKeys
[
i
].
asString
()
<<
std
::
endl
;
if
(
!
checkHex
(
publicKeys
[
i
].
asString
(),
64
))
{
for
(
int
i
=
0
;
i
<
_
n
;
i
++
)
{
std
::
cerr
<<
"publicKeys "
<<
i
<<
" is "
<<
_
publicKeys
[
i
].
asString
()
<<
std
::
endl
;
if
(
!
checkHex
(
_
publicKeys
[
i
].
asString
(),
64
))
{
throw
RPCException
(
INVALID_HEX
,
"Invalid public key"
);
}
pubKeys_vect
.
push_back
(
publicKeys
[
i
].
asString
());
pubKeys_vect
.
push_back
(
_
publicKeys
[
i
].
asString
());
}
string
s
=
get_secret_shares
(
polyName
,
encr_poly_ptr
->
c_str
(),
pubKeys_vect
,
t
,
n
);
string
s
=
get_secret_shares
(
_polyName
,
encr_poly_ptr
->
c_str
(),
pubKeys_vect
,
_t
,
_
n
);
//cerr << "result is " << s << endl;
result
[
"secretShare"
]
=
s
;
...
...
@@ -524,8 +524,8 @@ Json::Value SGXWalletServer::getSecretShareImpl(const string &polyName, const Js
return
result
;
}
Json
::
Value
SGXWalletServer
::
dkgVerificationImpl
(
const
string
&
publicShares
,
const
string
&
ethKeyName
,
const
string
&
SecretShare
,
int
t
,
int
n
,
int
ind
)
{
Json
::
Value
SGXWalletServer
::
dkgVerificationImpl
(
const
string
&
_publicShares
,
const
string
&
_
ethKeyName
,
const
string
&
_secretShare
,
int
_t
,
int
_n
,
int
_index
)
{
spdlog
::
info
(
"enter dkgVerificationImpl"
);
...
...
@@ -536,22 +536,22 @@ Json::Value SGXWalletServer::dkgVerificationImpl(const string &publicShares, con
try
{
if
(
!
checkECDSAKeyName
(
ethKeyName
))
{
if
(
!
checkECDSAKeyName
(
_
ethKeyName
))
{
throw
RPCException
(
INVALID_ECDSA_KEY_NAME
,
"Invalid ECDSA key name"
);
}
if
(
!
check_n_t
(
t
,
n
)
||
ind
>
n
||
ind
<
0
)
{
if
(
!
check_n_t
(
_t
,
_n
)
||
_index
>
_n
||
_index
<
0
)
{
throw
RPCException
(
INVALID_DKG_PARAMS
,
"Invalid DKG parameters: n or t "
);
}
if
(
!
checkHex
(
S
ecretShare
,
SECRET_SHARE_NUM_BYTES
))
{
if
(
!
checkHex
(
_s
ecretShare
,
SECRET_SHARE_NUM_BYTES
))
{
throw
RPCException
(
INVALID_HEX
,
"Invalid Secret share"
);
}
if
(
publicShares
.
length
()
!=
(
uint64_t
)
256
*
t
)
{
if
(
_publicShares
.
length
()
!=
(
uint64_t
)
256
*
_
t
)
{
throw
RPCException
(
INVALID_DKG_PARAMS
,
"Invalid length of public shares"
);
}
shared_ptr
<
string
>
encryptedKeyHex_ptr
=
readFromDb
(
ethKeyName
);
shared_ptr
<
string
>
encryptedKeyHex_ptr
=
readFromDb
(
_
ethKeyName
);
if
(
!
VerifyShares
(
publicShares
.
c_str
(),
SecretShare
.
c_str
(),
encryptedKeyHex_ptr
->
c_str
(),
t
,
n
,
ind
))
{
if
(
!
VerifyShares
(
_publicShares
.
c_str
(),
_secretShare
.
c_str
(),
encryptedKeyHex_ptr
->
c_str
(),
_t
,
_n
,
_index
))
{
result
[
"result"
]
=
false
;
}
...
...
@@ -565,8 +565,8 @@ Json::Value SGXWalletServer::dkgVerificationImpl(const string &publicShares, con
return
result
;
}
Json
::
Value
SGXWalletServer
::
createBLSPrivateKeyImpl
(
const
string
&
blsKeyName
,
const
string
&
ethKeyName
,
const
string
&
polyName
,
const
string
&
SecretShare
,
int
t
,
int
n
)
{
Json
::
Value
SGXWalletServer
::
createBLSPrivateKeyImpl
(
const
string
&
_blsKeyName
,
const
string
&
_ethKeyName
,
const
string
&
_
polyName
,
const
string
&
_secretShare
,
int
_t
,
int
_
n
)
{
spdlog
::
info
(
"createBLSPrivateKeyImpl entered"
);
...
...
@@ -576,41 +576,41 @@ Json::Value SGXWalletServer::createBLSPrivateKeyImpl(const string &blsKeyName, c
try
{
if
(
SecretShare
.
length
()
!=
(
uint64_t
)
n
*
192
)
{
spdlog
::
info
(
"wrong length of secret shares - {}"
,
S
ecretShare
.
length
());
spdlog
::
info
(
"secret shares - {}"
,
S
ecretShare
);
if
(
_secretShare
.
length
()
!=
(
uint64_t
)
_
n
*
192
)
{
spdlog
::
info
(
"wrong length of secret shares - {}"
,
_s
ecretShare
.
length
());
spdlog
::
info
(
"secret shares - {}"
,
_s
ecretShare
);
throw
RPCException
(
INVALID_SECRET_SHARES_LENGTH
,
"Invalid secret share length"
);
}
if
(
!
checkECDSAKeyName
(
ethKeyName
))
{
if
(
!
checkECDSAKeyName
(
_
ethKeyName
))
{
throw
RPCException
(
INVALID_ECDSA_KEY_NAME
,
"Invalid ECDSA key name"
);
}
if
(
!
checkName
(
polyName
,
"POLY"
))
{
if
(
!
checkName
(
_
polyName
,
"POLY"
))
{
throw
RPCException
(
INVALID_POLY_NAME
,
"Invalid polynomial name"
);
}
if
(
!
checkName
(
blsKeyName
,
"BLS_KEY"
))
{
if
(
!
checkName
(
_
blsKeyName
,
"BLS_KEY"
))
{
throw
RPCException
(
INVALID_POLY_NAME
,
"Invalid BLS key name"
);
}
if
(
!
check_n_t
(
t
,
n
))
{
if
(
!
check_n_t
(
_t
,
_
n
))
{
throw
RPCException
(
INVALID_DKG_PARAMS
,
"Invalid DKG parameters: n or t "
);
}
vector
<
string
>
sshares_vect
;
if
(
printDebugInfo
)
{
spdlog
::
info
(
"secret shares from json are - {}"
,
S
ecretShare
);
spdlog
::
info
(
"secret shares from json are - {}"
,
_s
ecretShare
);
}
shared_ptr
<
string
>
encryptedKeyHex_ptr
=
readFromDb
(
ethKeyName
);
shared_ptr
<
string
>
encryptedKeyHex_ptr
=
readFromDb
(
_
ethKeyName
);
bool
res
=
CreateBLSShare
(
blsKeyName
,
S
ecretShare
.
c_str
(),
encryptedKeyHex_ptr
->
c_str
());
bool
res
=
CreateBLSShare
(
_blsKeyName
,
_s
ecretShare
.
c_str
(),
encryptedKeyHex_ptr
->
c_str
());
if
(
res
)
{
spdlog
::
info
(
"BLS KEY SHARE CREATED "
);
}
else
{
throw
RPCException
(
-
122
,
"Error while creating BLS key share"
);
}
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
string
name
=
polyName
+
"_"
+
to_string
(
i
)
+
":"
;
for
(
int
i
=
0
;
i
<
_
n
;
i
++
)
{
string
name
=
_
polyName
+
"_"
+
to_string
(
i
)
+
":"
;
LevelDB
::
getLevelDb
()
->
deleteDHDKGKey
(
name
);
string
shareG2_name
=
"shareG2_"
+
polyName
+
"_"
+
to_string
(
i
)
+
":"
;
string
shareG2_name
=
"shareG2_"
+
_
polyName
+
"_"
+
to_string
(
i
)
+
":"
;
LevelDB
::
getLevelDb
()
->
deleteKey
(
shareG2_name
);
}
...
...
@@ -624,17 +624,17 @@ Json::Value SGXWalletServer::createBLSPrivateKeyImpl(const string &blsKeyName, c
return
result
;
}
Json
::
Value
SGXWalletServer
::
getBLSPublicKeyShareImpl
(
const
string
&
blsKeyName
)
{
Json
::
Value
SGXWalletServer
::
getBLSPublicKeyShareImpl
(
const
string
&
_
blsKeyName
)
{
Json
::
Value
result
;
result
[
"status"
]
=
0
;
result
[
"errorMessage"
]
=
""
;
try
{
if
(
!
checkName
(
blsKeyName
,
"BLS_KEY"
))
{
if
(
!
checkName
(
_
blsKeyName
,
"BLS_KEY"
))
{
throw
RPCException
(
INVALID_POLY_NAME
,
"Invalid BLSKey name"
);
}
shared_ptr
<
string
>
encryptedKeyHex_ptr
=
readFromDb
(
blsKeyName
);
shared_ptr
<
string
>
encryptedKeyHex_ptr
=
readFromDb
(
_
blsKeyName
);
if
(
printDebugInfo
)
{
spdlog
::
info
(
"encr_bls_key_share is {}"
,
*
encryptedKeyHex_ptr
);
spdlog
::
info
(
"length is {}"
,
encryptedKeyHex_ptr
->
length
());
...
...
@@ -657,18 +657,18 @@ Json::Value SGXWalletServer::getBLSPublicKeyShareImpl(const string &blsKeyName)
return
result
;
}
Json
::
Value
SGXWalletServer
::
complaintResponseImpl
(
const
string
&
polyName
,
int
ind
)
{
Json
::
Value
SGXWalletServer
::
complaintResponseImpl
(
const
string
&
_polyName
,
int
_
ind
)
{
Json
::
Value
result
;
result
[
"status"
]
=
0
;
result
[
"errorMessage"
]
=
""
;
try
{
if
(
!
checkName
(
polyName
,
"POLY"
))
{
if
(
!
checkName
(
_
polyName
,
"POLY"
))
{
throw
RPCException
(
INVALID_POLY_NAME
,
"Invalid polynomial name"
);
}
string
shareG2_name
=
"shareG2_"
+
polyName
+
"_"
+
to_string
(
ind
)
+
":"
;
string
shareG2_name
=
"shareG2_"
+
_polyName
+
"_"
+
to_string
(
_
ind
)
+
":"
;
shared_ptr
<
string
>
shareG2_ptr
=
readFromDb
(
shareG2_name
);
string
DHKey
=
decrypt_DHKey
(
polyName
,
ind
);
string
DHKey
=
decrypt_DHKey
(
_polyName
,
_
ind
);
result
[
"share*G2"
]
=
*
shareG2_ptr
;
result
[
"dhKey"
]
=
DHKey
;
...
...
@@ -683,13 +683,13 @@ Json::Value SGXWalletServer::complaintResponseImpl(const string &polyName, int i
}
Json
::
Value
SGXWalletServer
::
multG2Impl
(
const
string
&
x
)
{
Json
::
Value
SGXWalletServer
::
multG2Impl
(
const
string
&
_
x
)
{
Json
::
Value
result
;
result
[
"status"
]
=
0
;
result
[
"errorMessage"
]
=
""
;
try
{
spdlog
::
info
(
"multG2Impl try "
);
vector
<
string
>
xG2_vect
=
mult_G2
(
x
);
vector
<
string
>
xG2_vect
=
mult_G2
(
_
x
);
for
(
uint8_t
i
=
0
;
i
<
4
;
i
++
)
{
result
[
"x*G2"
][
i
]
=
xG2_vect
.
at
(
i
);
}
...
...
@@ -703,10 +703,10 @@ Json::Value SGXWalletServer::multG2Impl(const string &x) {
return
result
;
}
Json
::
Value
SGXWalletServer
::
isPolyExistsImpl
(
const
string
&
polyName
)
{
Json
::
Value
SGXWalletServer
::
isPolyExistsImpl
(
const
string
&
_
polyName
)
{
Json
::
Value
result
;
try
{
std
::
shared_ptr
<
std
::
string
>
poly_str_ptr
=
LevelDB
::
getLevelDb
()
->
readString
(
polyName
);
std
::
shared_ptr
<
std
::
string
>
poly_str_ptr
=
LevelDB
::
getLevelDb
()
->
readString
(
_
polyName
);
result
[
"IsExist"
]
=
true
;
result
[
"status"
]
=
0
;
result
[
"errorMessage"
]
=
""
;
...
...
@@ -752,10 +752,10 @@ Json::Value SGXWalletServer::getSecretShare(const string &_polyName, const Json:
}
Json
::
Value
SGXWalletServer
::
dkgVerification
(
const
string
&
publicShares
,
const
string
&
ethKeyName
,
const
string
&
SecretShare
,
int
t
,
SGXWalletServer
::
dkgVerification
(
const
string
&
_
publicShares
,
const
string
&
ethKeyName
,
const
string
&
SecretShare
,
int
t
,
int
n
,
int
index
)
{
lock_guard
<
recursive_mutex
>
lock
(
m
);
return
dkgVerificationImpl
(
publicShares
,
ethKeyName
,
SecretShare
,
t
,
n
,
index
);
return
dkgVerificationImpl
(
_
publicShares
,
ethKeyName
,
SecretShare
,
t
,
n
,
index
);
}
Json
::
Value
...
...
@@ -858,15 +858,15 @@ shared_ptr<string> SGXWalletServer::readKeyShare(const string &_keyShareName) {
}
void
SGXWalletServer
::
writeKeyShare
(
const
string
&
_keyShareName
,
const
string
&
value
,
int
index
,
int
n
,
int
t
)
{
void
SGXWalletServer
::
writeKeyShare
(
const
string
&
_keyShareName
,
const
string
&
_value
,
int
_index
,
int
_n
,
int
_
t
)
{
Json
::
Value
val
;
Json
::
FastWriter
writer
;
val
[
"value"
]
=
value
;
val
[
"t"
]
=
t
;
val
[
"index"
]
=
index
;
val
[
"n'"
]
=
n
;
val
[
"value"
]
=
_
value
;
val
[
"t"
]
=
_
t
;
val
[
"index"
]
=
_
index
;
val
[
"n'"
]
=
_
n
;
string
json
=
writer
.
write
(
val
);
...
...
@@ -876,7 +876,7 @@ void SGXWalletServer::writeKeyShare(const string &_keyShareName, const string &v
throw
RPCException
(
KEY_SHARE_ALREADY_EXISTS
,
"Key share with this name already exists"
);
}
LevelDB
::
getLevelDb
()
->
writeString
(
key
,
value
);
LevelDB
::
getLevelDb
()
->
writeString
(
key
,
_
value
);
}
void
SGXWalletServer
::
writeDataToDB
(
const
string
&
Name
,
const
string
&
value
)
{
...
...
SGXWalletServer.hpp
View file @
8250f8b2
...
...
@@ -36,48 +36,50 @@ class SGXWalletServer : public AbstractStubServer {
SGXWalletServer
*
server
=
nullptr
;
std
::
recursive_mutex
m
;
recursive_mutex
m
;
public
:
SGXWalletServer
(
AbstractServerConnector
&
_connector
,
serverVersion_t
_type
);
virtual
Json
::
Value
importBLSKeyShare
(
const
st
d
::
string
&
_keyShare
,
const
std
::
string
&
_keyShareName
,
int
_t
,
int
_n
,
int
index
);
importBLSKeyShare
(
const
st
ring
&
_keyShare
,
const
string
&
_keyShareName
,
int
_t
,
int
_n
,
int
index
);
virtual
Json
::
Value
blsSignMessageHash
(
const
std
::
string
&
_keyShareName
,
const
std
::
string
&
_messageHash
,
int
_t
,
int
_n
,
int
_signerIndex
);
blsSignMessageHash
(
const
string
&
_keyShareName
,
const
string
&
_messageHash
,
int
_t
,
int
_n
,
int
_signerIndex
);
virtual
Json
::
Value
importECDSAKey
(
const
st
d
::
string
&
_key
,
const
std
::
string
&
_keyName
);
virtual
Json
::
Value
importECDSAKey
(
const
st
ring
&
_key
,
const
string
&
_keyName
);
virtual
Json
::
Value
generateECDSAKey
();
virtual
Json
::
Value
renameECDSAKey
(
const
st
d
::
string
&
_keyName
,
const
std
::
string
&
_tmpKeyName
);
virtual
Json
::
Value
renameECDSAKey
(
const
st
ring
&
_keyName
,
const
string
&
_tmpKeyName
);
virtual
Json
::
Value
ecdsaSignMessageHash
(
int
_base
,
const
std
::
string
&
_keyShareName
,
const
std
::
string
&
_messageHash
);
virtual
Json
::
Value
ecdsaSignMessageHash
(
int
_base
,
const
string
&
_keyShareName
,
const
string
&
_messageHash
);
virtual
Json
::
Value
getPublicECDSAKey
(
const
st
d
::
st
ring
&
_keyName
);
virtual
Json
::
Value
getPublicECDSAKey
(
const
string
&
_keyName
);
virtual
Json
::
Value
generateDKGPoly
(
const
st
d
::
st
ring
&
_polyName
,
int
_t
);
virtual
Json
::
Value
generateDKGPoly
(
const
string
&
_polyName
,
int
_t
);
virtual
Json
::
Value
getVerificationVector
(
const
st
d
::
st
ring
&
_polynomeName
,
int
_t
,
int
_n
);
virtual
Json
::
Value
getVerificationVector
(
const
string
&
_polynomeName
,
int
_t
,
int
_n
);
virtual
Json
::
Value
getSecretShare
(
const
st
d
::
st
ring
&
_polyName
,
const
Json
::
Value
&
_publicKeys
,
int
t
,
int
n
);
virtual
Json
::
Value
getSecretShare
(
const
string
&
_polyName
,
const
Json
::
Value
&
_publicKeys
,
int
t
,
int
n
);
virtual
Json
::
Value
dkgVerification
(
const
st
d
::
string
&
publicShares
,
const
std
::
string
&
ethKeyName
,
const
std
::
string
&
SecretShare
,
dkgVerification
(
const
st
ring
&
_publicShares
,
const
string
&
ethKeyName
,
const
string
&
SecretShare
,
int
t
,
int
n
,
int
index
);
virtual
Json
::
Value
createBLSPrivateKey
(
const
st
d
::
string
&
blsKeyName
,
const
std
::
string
&
ethKeyName
,
const
std
::
string
&
polyName
,
const
st
d
::
st
ring
&
SecretShare
,
int
t
,
int
n
);
createBLSPrivateKey
(
const
st
ring
&
blsKeyName
,
const
string
&
ethKeyName
,
const
string
&
polyName
,
const
string
&
SecretShare
,
int
t
,
int
n
);
virtual
Json
::
Value
getBLSPublicKeyShare
(
const
st
d
::
st
ring
&
blsKeyName
);
virtual
Json
::
Value
getBLSPublicKeyShare
(
const
string
&
blsKeyName
);
virtual
Json
::
Value
complaintResponse
(
const
st
d
::
st
ring
&
polyName
,
int
ind
);
virtual
Json
::
Value
complaintResponse
(
const
string
&
polyName
,
int
ind
);
virtual
Json
::
Value
multG2
(
const
st
d
::
st
ring
&
x
);
virtual
Json
::
Value
multG2
(
const
string
&
x
);
virtual
Json
::
Value
isPolyExists
(
const
st
d
::
st
ring
&
polyName
);
virtual
Json
::
Value
isPolyExists
(
const
string
&
polyName
);
virtual
Json
::
Value
getServerStatus
();
...
...
@@ -85,48 +87,48 @@ public:
static
void
writeDataToDB
(
const
string
&
Name
,
const
string
&
value
);
static
void
writeKeyShare
(
const
string
&
_keyShareName
,
const
string
&
value
,
int
index
,
int
n
,
int
t
);
static
void
writeKeyShare
(
const
string
&
_keyShareName
,
const
string
&
_value
,
int
_index
,
int
_n
,
int
_
t
);
static
shared_ptr
<
st
d
::
st
ring
>
readKeyShare
(
const
string
&
_keyShare
);
static
shared_ptr
<
string
>
readKeyShare
(
const
string
&
_keyShare
);
static
Json
::
Value
importBLSKeyShareImpl
(
const
st
d
::
string
&
keyShare
,
const
std
::
string
&
keyShareName
,
int
t
,
int
n
,
int
index
);
importBLSKeyShareImpl
(
const
st
ring
&
_keyShare
,
const
string
&
_keyShareName
,
int
t
,
int
n
,
int
_
index
);
static
Json
::
Value
blsSignMessageHashImpl
(
const
st
d
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
,
int
t
,
int
n
,
int
signerIndex
);
blsSignMessageHashImpl
(
const
st
ring
&
_keyShareName
,
const
string
&
_
messageHash
,
int
t
,
int
n
,
int
_
signerIndex
);
static
Json
::
Value
importECDSAKeyImpl
(
const
st
d
::
string
&
_key
,
const
std
::
string
&
_keyName
);
static
Json
::
Value
importECDSAKeyImpl
(
const
st
ring
&
_key
,
const
string
&
_keyName
);
static
Json
::
Value
generateECDSAKeyImpl
();
static
Json
::
Value
renameECDSAKeyImpl
(
const
st
d
::
string
&
KeyName
,
const
std
::
string
&
tempKeyName
);
static
Json
::
Value
renameECDSAKeyImpl
(
const
st
ring
&
_keyName
,
const
string
&
_
tempKeyName
);
static
Json
::
Value
ecdsaSignMessageHashImpl
(
int
base
,
const
std
::
string
&
keyName
,
const
std
::
string
&
messageHash
);
static
Json
::
Value
ecdsaSignMessageHashImpl
(
int
_base
,
const
string
&
keyName
,
const
string
&
_
messageHash
);
static
Json
::
Value
getPublicECDSAKeyImpl
(
const
st
d
::
string
&
keyName
);
static
Json
::
Value
getPublicECDSAKeyImpl
(
const
st
ring
&
_
keyName
);
static
Json
::
Value
generateDKGPolyImpl
(
const
st
d
::
string
&
polyName
,
int
t
);
static
Json
::
Value
generateDKGPolyImpl
(
const
st
ring
&
_polyName
,
int
_
t
);
static
Json
::
Value
getVerificationVectorImpl
(
const
st
d
::
string
&
polyName
,
int
t
,
int
n
);
static
Json
::
Value
getVerificationVectorImpl
(
const
st
ring
&
_polyName
,
int
_t
,
int
_
n
);
static
Json
::
Value
getSecretShareImpl
(
const
st
d
::
string
&
polyName
,
const
Json
::
Value
&
publicKeys
,
int
t
,
int
n
);
static
Json
::
Value
getSecretShareImpl
(
const
st
ring
&
_polyName
,
const
Json
::
Value
&
_publicKeys
,
int
_t
,
int
_
n
);
static
Json
::
Value
dkgVerificationImpl
(
const
st
d
::
string
&
publicShares
,
const
std
::
string
&
ethKeyName
,
const
std
::
string
&
S
ecretShare
,
int
t
,
int
n
,
int
index
);
dkgVerificationImpl
(
const
st
ring
&
_publicShares
,
const
string
&
_ethKeyName
,
const
string
&
_s
ecretShare
,
int
_t
,
int
_n
,
int
_
index
);
static
Json
::
Value
createBLSPrivateKeyImpl
(
const
st
d
::
string
&
blsKeyName
,
const
std
::
string
&
ethKeyName
,
const
std
::
string
&
polyName
,
const
st
d
::
string
&
SecretShare
,
int
t
,
int
n
);
createBLSPrivateKeyImpl
(
const
st
ring
&
_blsKeyName
,
const
string
&
_ethKeyName
,
const
string
&
_
polyName
,
const
st
ring
&
_secretShare
,
int
_t
,
int
_
n
);
static
Json
::
Value
getBLSPublicKeyShareImpl
(
const
st
d
::
string
&
blsKeyName
);
static
Json
::
Value
getBLSPublicKeyShareImpl
(
const
st
ring
&
_
blsKeyName
);
static
Json
::
Value
complaintResponseImpl
(
const
st
d
::
string
&
polyName
,
int
ind
);
static
Json
::
Value
complaintResponseImpl
(
const
st
ring
&
_polyName
,
int
_
ind
);
static
Json
::
Value
multG2Impl
(
const
st
d
::
string
&
x
);
static
Json
::
Value
multG2Impl
(
const
st
ring
&
_
x
);
static
Json
::
Value
isPolyExistsImpl
(
const
st
d
::
string
&
polyName
);
static
Json
::
Value
isPolyExistsImpl
(
const
st
ring
&
_
polyName
);
static
Json
::
Value
getServerStatusImpl
();
...
...
docker/start.sh
View file @
8250f8b2
...
...
@@ -19,7 +19,7 @@ if [ "$1" = -t ]; then
./testw
[
dkg_api_test]
./testw
[
is_poly_test]
./testw
[
AES-encrypt-decrypt]
./testw
[
ecdsa_api_test]
#
./testw [ecdsa_api_test]
#./testw [dkg-encr_sshares]
#./testw [bls_sign]
./testw
[
many_threads_test]
...
...
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