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
8aabe34e
Unverified
Commit
8aabe34e
authored
Dec 06, 2019
by
svetaro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-1775 Boost is removed from dependencies
parent
19bd17a3
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
250 additions
and
74 deletions
+250
-74
DKGCrypto.cpp
DKGCrypto.cpp
+61
-7
DKGCrypto.h
DKGCrypto.h
+6
-0
Makefile.am
Makefile.am
+10
-1
SGXWalletServer.cpp
SGXWalletServer.cpp
+74
-30
SGXWalletServer.hpp
SGXWalletServer.hpp
+2
-0
abstractstubserver.h
abstractstubserver.h
+6
-0
DH_dkg.c
secure_enclave/DH_dkg.c
+4
-1
DKGUtils.cpp
secure_enclave/DKGUtils.cpp
+2
-0
secure_enclave.c
secure_enclave/secure_enclave.c
+28
-28
sgxwallet_common.h
sgxwallet_common.h
+1
-1
spec.json
spec.json
+3
-1
stubclient.h
stubclient.h
+12
-0
testw.cpp
testw.cpp
+41
-5
No files found.
DKGCrypto.cpp
View file @
8aabe34e
...
...
@@ -39,6 +39,23 @@ std::vector<std::string> SplitString(const char* koefs, const char symbol){
return
G2_strings
;
}
template
<
class
T
>
std
::
string
ConvertToString
(
T
field_elem
,
int
base
=
10
)
{
mpz_t
t
;
mpz_init
(
t
);
field_elem
.
as_bigint
().
to_mpz
(
t
);
char
arr
[
mpz_sizeinbase
(
t
,
base
)
+
2
];
char
*
tmp
=
mpz_get_str
(
arr
,
base
,
t
);
mpz_clear
(
t
);
std
::
string
output
=
tmp
;
return
output
;
}
std
::
string
gen_dkg_poly
(
int
_t
){
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
int
err_status
=
0
;
...
...
@@ -207,7 +224,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
){
std
::
cerr
<<
"ENTER CreateBLSShare"
<<
std
::
endl
;
char
*
errMsg1
=
(
char
*
)
calloc
(
1024
,
1
);
int
err_status
=
0
;
...
...
@@ -215,23 +232,25 @@ bool CreateBLSShare( const std::string& BLSKeyName, const char * s_shares, const
uint8_t
encr_bls_key
[
BUF_LEN
];
uint8_t
encr_key
[
BUF_LEN
];
if
(
!
hex2carray
(
encryptedKeyHex
,
&
dec_key_len
,
encr_key
)){
throw
RPCException
(
INVALID_HEX
,
"Invalid encrypted
Pol
yHex"
);
throw
RPCException
(
INVALID_HEX
,
"Invalid encrypted
Ke
yHex"
);
}
uint32_t
enc_bls_len
=
0
;
create_bls_key
(
eid
,
&
err_status
,
errMsg1
,
s_shares
,
encr_key
,
dec_key_len
,
encr_bls_key
,
&
enc_bls_len
);
std
::
cerr
<<
"
er msg is
"
<<
errMsg1
<<
std
::
endl
;
std
::
cerr
<<
"
AFTER create_bls_key IN ENCLAVE er msg is
"
<<
errMsg1
<<
std
::
endl
;
if
(
err_status
!=
0
){
std
::
cerr
<<
"ERROR IN ENCLAVE"
<<
std
::
endl
;
return
false
;
}
else
{
char
*
hexBLSKey
=
(
char
*
)
calloc
(
2
*
BUF_LEN
,
1
);
std
::
cerr
<<
"enc_bls_len "
<<
enc_bls_len
<<
std
::
endl
;
carray2Hex
(
encr_bls_key
,
enc_bls_len
,
hexBLSKey
);
writeDataToDB
(
BLSKeyName
,
hexBLSKey
);
std
::
cerr
<<
"BEFORE carray2Hex"
<<
std
::
endl
;
//std::cerr << "enc_bls_len " << enc_bls_len << std::endl;
carray2Hex
(
encr_bls_key
,
enc_bls_len
,
hexBLSKey
);
std
::
cerr
<<
"BEFORE WRITE BLS KEY TO DB"
<<
std
::
endl
;
writeDataToDB
(
BLSKeyName
,
hexBLSKey
);
std
::
cerr
<<
"hexBLSKey length is "
<<
strlen
(
hexBLSKey
)
<<
std
::
endl
;
std
::
cerr
<<
"bls key "
<<
BLSKeyName
<<
" is "
<<
hexBLSKey
<<
std
::
endl
;
free
(
hexBLSKey
);
...
...
@@ -292,3 +311,38 @@ std::string decrypt_DHKey(const std::string& polyName, int ind){
return
DHKey
;
}
std
::
vector
<
std
::
string
>
mult_G2
(
const
std
::
string
&
x
){
std
::
vector
<
std
::
string
>
result
(
4
);
libff
::
init_alt_bn128_params
();
libff
::
alt_bn128_Fr
el
(
x
.
c_str
());
libff
::
alt_bn128_G2
elG2
=
el
*
libff
::
alt_bn128_G2
::
one
();
elG2
.
to_affine_coordinates
();
result
[
0
]
=
ConvertToString
(
elG2
.
X
.
c0
);
result
[
1
]
=
ConvertToString
(
elG2
.
X
.
c1
);
result
[
2
]
=
ConvertToString
(
elG2
.
Y
.
c0
);
result
[
3
]
=
ConvertToString
(
elG2
.
Y
.
c1
);
return
result
;
}
bool
TestCreateBLSShare
(
const
char
*
s_shares
)
{
char
*
errMsg1
=
(
char
*
)
calloc
(
1024
,
1
);
int
err_status
=
0
;
uint32_t
enc_bls_len
=
0
;
uint8_t
encr_key
[
BUF_LEN
];
memset
(
encr_key
,
1
,
BUF_LEN
);
uint64_t
dec_key_len
;
uint8_t
encr_bls_key
[
BUF_LEN
];
std
::
cerr
<<
"Enter TestCreateBLSShare"
<<
std
::
endl
;
create_bls_key
(
eid
,
&
err_status
,
errMsg1
,
s_shares
,
encr_key
,
dec_key_len
,
encr_bls_key
,
&
enc_bls_len
);
if
(
err_status
!=
0
){
std
::
cerr
<<
"something went wrong in enclave"
<<
std
::
endl
;
}
}
DKGCrypto.h
View file @
8aabe34e
...
...
@@ -24,5 +24,11 @@ bool CreateBLSShare( const std::string& BLSKeyName, const char * s_shares, const
std
::
vector
<
std
::
string
>
GetBLSPubKey
(
const
char
*
encryptedKeyHex
);
std
::
vector
<
std
::
string
>
mult_G2
(
const
std
::
string
&
x
);
bool
TestCreateBLSShare
(
const
char
*
s_shares
);
#endif //SGXD_DKGCRYPTO_H
Makefile.am
View file @
8aabe34e
...
...
@@ -94,7 +94,16 @@ secure_enclave.signed.so: secure_enclave/secure_enclave.signed.so
sgxwallet_LDADD
=
-l
$(SGX_URTS_LIB)
-Lleveldb
/build
-LlibBLS
/build
-LlibBLS
/build/libff/libff
-l
:libbls.a
-l
:libleveldb.a
\
-l
:libff.a
-lgmp
-ldl
-l
:libsgx_capable.a
-l
:libsgx_tprotected_fs.a
-ljsonrpccpp-stub
-lpthread
-ljsonrpccpp-common
\
-ljsonrpccpp-server
-ljsonrpccpp-client
-ljsoncpp
-lcurl
-lprocps
intel-sgx-ssl/Linux/package/lib64/libsgx_usgxssl.a
\
intel-sgx-ssl/Linux/package/lib64/libsgx_tsgxssl_crypto.a
-lboost_system
-lboost_filesystem
intel-sgx-ssl/Linux/package/lib64/libsgx_tsgxssl_crypto.a
#-lboost_system -lboost_filesystem
# -lboost_filesystem
# -llibboost_filesystem.a
# find /usr -name *libboost_filesystem*so*
# -llibboost_filesystem.so
### libboost_filesystem.so.67.1
...
...
SGXWalletServer.cpp
View file @
8aabe34e
...
...
@@ -34,12 +34,14 @@
#include <algorithm>
#include <stdlib.h>
#include <unistd.h>
//#if __cplusplus < 201412L
//#error expecting C++17 standard
//#endif
#include <boost/filesystem.hpp>
//
#include <boost/filesystem.hpp>
bool
isStringDec
(
std
::
string
&
str
){
...
...
@@ -49,18 +51,33 @@ bool isStringDec( std::string & str){
return
!
str
.
empty
()
&&
res
==
str
.
end
();
}
SGXWalletServer
*
s
=
nullptr
;
HttpServer
*
hs
=
nullptr
;
SGXWalletServer
::
SGXWalletServer
(
AbstractServerConnector
&
connector
,
serverVersion_t
type
)
:
AbstractStubServer
(
connector
,
type
)
{}
SGXWalletServer
*
s
=
nullptr
;
HttpServer
*
hs
=
nullptr
;
void
debug_print
(){
std
::
cout
<<
"HERE ARE YOUR KEYS: "
<<
std
::
endl
;
class
MyVisitor
:
public
LevelDB
::
KeyVisitor
{
public
:
virtual
void
visitDBKey
(
const
char
*
_data
){
std
::
cout
<<
_data
<<
std
::
endl
;
}
};
int
init_server
()
{
std
::
string
certPath
=
""
;
//"cert/SGXServerCertificate.crt";
std
::
string
keyPath
=
""
;
//"cert/SGXServerCertificate.key";
MyVisitor
v
;
// if (!boost::filesystem::exists(certPath) ){
levelDb
->
visitKeys
(
&
v
,
100000000
);
}
//int init_server() {
// std::string certPath = "cert/SGXServerCertificate.crt";
// std::string keyPath = "cert/SGXServerCertificate.key";
//
// if (access(certPath.c_str(), F_OK) != 0){ //(!boost::filesystem::exists(certPath) ){
// std::cerr << "NO!!! " << std::endl;
// std::cerr << "CERTIFICATE IS GOING TO BE CREATED" << std::endl;
//
...
...
@@ -74,11 +91,23 @@ int init_server() {
// exit(-1);
// }
// }
//
// hs = new HttpServer(1026, certPath, keyPath, 1);
// s = new SGXWalletServer(*hs,
// JSONRPC_SERVER_V2); // hybrid server (json-rpc 1.0 & 2.0)
//
// if (!s->StartListening()) {
// cerr << "Server could not start listening" << endl;
// exit(-1);
// }
// return 0;
//}
hs
=
new
HttpServer
(
1027
,
certPath
,
keyPath
);
s
=
new
SGXWalletServer
(
*
hs
,
JSONRPC_SERVER_V2
);
// hybrid server (json-rpc 1.0 & 2.0)
int
init_server
()
{
//without ssl
hs
=
new
HttpServer
(
1027
,
""
,
""
,
1
);
s
=
new
SGXWalletServer
(
*
hs
,
JSONRPC_SERVER_V2
);
// hybrid server (json-rpc 1.0 & 2.0)
if
(
!
s
->
StartListening
())
{
cerr
<<
"Server could not start listening"
<<
endl
;
exit
(
-
1
);
...
...
@@ -93,7 +122,6 @@ importBLSKeyShareImpl(const std::string &_keyShare, const std::string &_keyShare
int
errStatus
=
UNKNOWN_ERROR
;
char
*
errMsg
=
(
char
*
)
calloc
(
BUF_LEN
,
1
);
result
[
"status"
]
=
0
;
result
[
"errorMessage"
]
=
""
;
result
[
"encryptedKeyShare"
]
=
""
;
...
...
@@ -492,6 +520,7 @@ Json::Value DKGVerificationImpl(const std::string& publicShares, const std::stri
}
Json
::
Value
CreateBLSPrivateKeyImpl
(
const
std
::
string
&
BLSKeyName
,
const
std
::
string
&
EthKeyName
,
const
std
::
string
&
polyName
,
const
std
::
string
&
SecretShare
,
int
t
,
int
n
){
std
::
cerr
<<
"CreateBLSPrivateKeyImpl entered"
<<
std
::
endl
;
...
...
@@ -516,27 +545,14 @@ Json::Value CreateBLSPrivateKeyImpl(const std::string & BLSKeyName, const std::s
throw
RPCException
(
INVALID_POLY_NAME
,
"Invalid BLS key name"
);
}
std
::
vector
<
std
::
string
>
sshares_vect
;
std
::
cerr
<<
"sshares are "
<<
SecretShare
<<
std
::
endl
;
char
sshares
[
192
*
n
+
1
];
for
(
int
i
=
0
;
i
<
n
;
i
++
){
std
::
string
cur_share
=
SecretShare
.
substr
(
192
*
i
,
192
*
i
+
192
);
// if ( !checkHex(SecretShare, SECRET_SHARE_NUM_BYTES)){
// throw RPCException(INVALID_HEX, "Invalid Secret share");
// }
// std::cerr << " share " << i << " is " << cur_share << std::endl;
sshares_vect
.
push_back
(
cur_share
);
// std::cerr << sshares_vect[i] << " ";
strncpy
(
sshares
+
i
*
192
,
cur_share
.
c_str
(),
192
);
}
sshares
[
192
*
n
]
=
0
;
//std::cerr << sshares << std::endl;
//std::cerr << "length is " << strlen(sshares);
std
::
cerr
<<
"sshares from json are "
<<
SecretShare
<<
std
::
endl
;
std
::
shared_ptr
<
std
::
string
>
encryptedKeyHex_ptr
=
readFromDb
(
EthKeyName
);
bool
res
=
CreateBLSShare
(
BLSKeyName
,
sshares
,
encryptedKeyHex_ptr
->
c_str
());
bool
res
=
CreateBLSShare
(
BLSKeyName
,
SecretShare
.
c_str
()
,
encryptedKeyHex_ptr
->
c_str
());
if
(
res
){
std
::
cerr
<<
"
key created
"
<<
std
::
endl
;
std
::
cerr
<<
"
BLS KEY SHARE CREATED
"
<<
std
::
endl
;
}
else
{
...
...
@@ -582,6 +598,8 @@ Json::Value GetBLSPublicKeyShareImpl(const std::string & BLSKeyName){
result
[
"errorMessage"
]
=
_e
.
errString
;
}
//debug_print();
return
result
;
}
...
...
@@ -611,6 +629,26 @@ Json::Value ComplaintResponseImpl(const std::string& polyName, int ind){
}
Json
::
Value
MultG2Impl
(
const
std
::
string
&
x
){
Json
::
Value
result
;
result
[
"status"
]
=
0
;
result
[
"errorMessage"
]
=
""
;
try
{
std
::
cerr
<<
"MultG2Impl try "
<<
std
::
endl
;
std
::
vector
<
std
::
string
>
xG2_vect
=
mult_G2
(
x
);
for
(
uint8_t
i
=
0
;
i
<
4
;
i
++
)
{
result
[
"x*G2"
][
i
]
=
xG2_vect
.
at
(
i
);
}
}
catch
(
RPCException
&
_e
)
{
std
::
cerr
<<
" err str "
<<
_e
.
errString
<<
std
::
endl
;
result
[
"status"
]
=
_e
.
status
;
result
[
"errorMessage"
]
=
_e
.
errString
;
}
return
result
;
}
Json
::
Value
SGXWalletServer
::
generateDKGPoly
(
const
std
::
string
&
polyName
,
int
t
){
std
::
cerr
<<
"entered generateDKGPoly"
<<
std
::
endl
;
...
...
@@ -692,13 +730,18 @@ Json::Value SGXWalletServer::ComplaintResponse(const std::string& polyName, int
return
ComplaintResponseImpl
(
polyName
,
ind
);
}
Json
::
Value
SGXWalletServer
::
MultG2
(
const
std
::
string
&
x
){
lock_guard
<
recursive_mutex
>
lock
(
m
);
return
MultG2Impl
(
x
);
}
shared_ptr
<
string
>
readFromDb
(
const
string
&
name
,
const
string
&
prefix
)
{
auto
dataStr
=
levelDb
->
readString
(
prefix
+
name
);
if
(
dataStr
==
nullptr
)
{
throw
RPCException
(
KEY_SHARE_DOES_NOT_EXIST
,
"Data with this name does not exist
s
"
);
throw
RPCException
(
KEY_SHARE_DOES_NOT_EXIST
,
"Data with this name does not exist"
);
}
return
dataStr
;
...
...
@@ -709,7 +752,7 @@ shared_ptr<string> readKeyShare(const string &_keyShareName) {
auto
keyShareStr
=
levelDb
->
readString
(
"BLSKEYSHARE:"
+
_keyShareName
);
if
(
keyShareStr
==
nullptr
)
{
throw
RPCException
(
KEY_SHARE_DOES_NOT_EXIST
,
"Key share with this name does not exist
s
"
);
throw
RPCException
(
KEY_SHARE_DOES_NOT_EXIST
,
"Key share with this name does not exist"
);
}
return
keyShareStr
;
...
...
@@ -752,5 +795,6 @@ void writeDataToDB(const string & Name, const string &value) {
}
levelDb
->
writeString
(
key
,
value
);
std
::
cerr
<<
Name
<<
" is written to db "
<<
std
::
endl
;
}
SGXWalletServer.hpp
View file @
8aabe34e
...
...
@@ -36,6 +36,7 @@ public:
virtual
Json
::
Value
CreateBLSPrivateKey
(
const
std
::
string
&
BLSKeyName
,
const
std
::
string
&
EthKeyName
,
const
std
::
string
&
polyName
,
const
std
::
string
&
SecretShare
,
int
t
,
int
n
);
virtual
Json
::
Value
GetBLSPublicKeyShare
(
const
std
::
string
&
BLSKeyName
);
virtual
Json
::
Value
ComplaintResponse
(
const
std
::
string
&
polyName
,
int
ind
);
virtual
Json
::
Value
MultG2
(
const
std
::
string
&
x
);
};
...
...
@@ -61,5 +62,6 @@ Json::Value DKGVerificationImpl(const std::string& publicShares, const std::stri
Json
::
Value
CreateBLSPrivateKeyImpl
(
const
std
::
string
&
BLSKeyName
,
const
std
::
string
&
EthKeyName
,
const
std
::
string
&
polyName
,
const
std
::
string
&
SecretShare
,
int
t
,
int
n
);
Json
::
Value
GetBLSPublicKeyShareImpl
(
const
std
::
string
&
BLSKeyName
);
Json
::
Value
ComplaintResponseImpl
(
const
std
::
string
&
polyName
,
int
ind
);
Json
::
Value
MultG2Impl
(
const
std
::
string
&
x
);
#endif //SGXWALLET_SGXWALLETSERVER_HPP
\ No newline at end of file
abstractstubserver.h
View file @
8aabe34e
...
...
@@ -28,6 +28,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"CreateBLSPrivateKey"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"BLSKeyName"
,
jsonrpc
::
JSON_STRING
,
"EthKeyName"
,
jsonrpc
::
JSON_STRING
,
"polyName"
,
jsonrpc
::
JSON_STRING
,
"SecretShare"
,
jsonrpc
::
JSON_STRING
,
"t"
,
jsonrpc
::
JSON_INTEGER
,
"n"
,
jsonrpc
::
JSON_INTEGER
,
NULL
),
&
AbstractStubServer
::
CreateBLSPrivateKeyI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"GetBLSPublicKeyShare"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"BLSKeyName"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
GetBLSPublicKeyShareI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"ComplaintResponse"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"polyName"
,
jsonrpc
::
JSON_STRING
,
"ind"
,
jsonrpc
::
JSON_INTEGER
,
NULL
),
&
AbstractStubServer
::
ComplaintResponseI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"MultG2"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"x"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
MultG2I
);
}
...
...
@@ -88,6 +89,10 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
{
response
=
this
->
ComplaintResponse
(
request
[
"polyName"
].
asString
(),
request
[
"ind"
].
asInt
());
}
inline
virtual
void
MultG2I
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
{
response
=
this
->
MultG2
(
request
[
"x"
].
asString
());
}
virtual
Json
::
Value
importBLSKeyShare
(
const
std
::
string
&
keyShare
,
const
std
::
string
&
keyShareName
,
int
t
,
int
n
,
int
index
)
=
0
;
virtual
Json
::
Value
blsSignMessageHash
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
,
int
t
,
int
n
,
int
signerIndex
)
=
0
;
...
...
@@ -104,6 +109,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
virtual
Json
::
Value
CreateBLSPrivateKey
(
const
std
::
string
&
BLSKeyName
,
const
std
::
string
&
EthKeyName
,
const
std
::
string
&
polyName
,
const
std
::
string
&
SecretShare
,
int
t
,
int
n
)
=
0
;
virtual
Json
::
Value
GetBLSPublicKeyShare
(
const
std
::
string
&
BLSKeyName
)
=
0
;
virtual
Json
::
Value
ComplaintResponse
(
const
std
::
string
&
polyName
,
int
ind
)
=
0
;
virtual
Json
::
Value
MultG2
(
const
std
::
string
&
x
)
=
0
;
};
#endif //JSONRPC_CPP_STUB_ABSTRACTSTUBSERVER_H_
secure_enclave/DH_dkg.c
View file @
8aabe34e
...
...
@@ -69,7 +69,10 @@ void session_key_recover(const char *skey_str, const char* sshare, char* common_
mpz_t
skey
;
mpz_init
(
skey
);
mpz_set_str
(
skey
,
skey_str
,
16
);
if
(
mpz_set_str
(
skey
,
skey_str
,
16
)
==
-
1
){
common_key
=
NULL
;
return
;
}
point
pub_keyB
=
point_init
();
point_set_hex
(
pub_keyB
,
pb_keyB_x
,
pb_keyB_y
);
...
...
secure_enclave/DKGUtils.cpp
View file @
8aabe34e
...
...
@@ -189,6 +189,8 @@ void calc_secret_shareG2(const char* s_share, char * s_shareG2){
libff
::
alt_bn128_G2
secret_shareG2
=
secret_share
*
libff
::
alt_bn128_G2
::
one
();
secret_shareG2
.
to_affine_coordinates
();
std
::
string
secret_shareG2_str
=
ConvertG2ToString
(
secret_shareG2
);
strncpy
(
s_shareG2
,
secret_shareG2_str
.
c_str
(),
secret_shareG2_str
.
length
()
+
1
);
...
...
secure_enclave/secure_enclave.c
View file @
8aabe34e
...
...
@@ -694,15 +694,19 @@ void dkg_verification(int *err_status, char* err_string, const char * public_sha
char
common_key
[
65
];
char
decr_sshare
[
65
];
session_key_recover
(
skey
,
s_share
,
common_key
);
common_key
[
64
]
=
0
;
if
(
common_key
==
NULL
){
*
err_status
=
1
;
snprintf
(
err_string
,
BUF_LEN
,
"invalid common_key"
);
return
;
}
xor_decrypt
(
common_key
,
encr_sshare
,
decr_sshare
);
if
(
decr_sshare
==
NULL
){
*
err_status
=
1
;
snprintf
(
err_string
,
BUF_LEN
,
"invalid common_key"
);
return
;
}
if
(
decr_sshare
==
NULL
){
*
err_status
=
1
;
snprintf
(
err_string
,
BUF_LEN
,
"invalid common_key"
);
return
;
}
//snprintf(err_string, BUF_LEN,"encr_share is %s length is %d", encr_sshare, strlen(encr_sshare));
...
...
@@ -724,14 +728,13 @@ void dkg_verification(int *err_status, char* err_string, const char * public_sha
*
result
=
Verification
(
public_shares
,
s
,
_t
,
_ind
);
snprintf
(
err_string
,
BUF_LEN
,
"
data is %s"
,
public_shares
);
snprintf
(
err_string
,
BUF_LEN
,
"
common_key in verification is %s"
,
common_key
);
}
void
create_bls_key
(
int
*
err_status
,
char
*
err_string
,
const
char
*
s_shares
,
uint8_t
*
encrypted_key
,
uint64_t
key_len
,
uint8_t
*
encr_bls_key
,
uint32_t
*
enc_bls_key_len
){
//uint32_t dec_len = 625;
char
skey
[
ECDSA_SKEY_LEN
];
sgx_status_t
status
=
sgx_unseal_data
(
(
const
sgx_sealed_data_t
*
)
encrypted_key
,
NULL
,
0
,
(
uint8_t
*
)
skey
,
&
key_len
);
...
...
@@ -740,6 +743,8 @@ void create_bls_key(int *err_status, char* err_string, const char* s_shares,
return
;
}
//char * skey = "a15c19da241e5b1db20d8dd8ca4b5eeaee01c709b49ec57aa78c2133d3c1b3c9";
int
num_shares
=
strlen
(
s_shares
)
/
192
;
mpz_t
sum
;
...
...
@@ -747,18 +752,6 @@ void create_bls_key(int *err_status, char* err_string, const char* s_shares,
mpz_set_ui
(
sum
,
0
);
char
encr_sshare
[
65
];
strncpy
(
encr_sshare
,
s_shares
,
64
);
encr_sshare
[
64
]
=
0
;
char
s_share
[
193
];
strncpy
(
s_share
,
s_shares
,
192
);
s_share
[
192
]
=
0
;
char
common_key
[
65
];
session_key_recover
(
skey
,
s_share
,
common_key
);
common_key
[
64
]
=
0
;
//snprintf(err_string, BUF_LEN,"comon0 is %s len is %d\n", common_key, strlen(common_key));
...
...
@@ -775,6 +768,11 @@ void create_bls_key(int *err_status, char* err_string, const char* s_shares,
session_key_recover
(
skey
,
s_share
,
common_key
);
common_key
[
64
]
=
0
;
if
(
common_key
==
NULL
){
*
err_status
=
1
;
snprintf
(
err_string
,
BUF_LEN
,
"invalid common_key"
);
return
;
}
//snprintf(err_string + 85*(i+1) , BUF_LEN,"common is %s len is %d\n", common_key, strlen(common_key));
...
...
@@ -782,12 +780,14 @@ void create_bls_key(int *err_status, char* err_string, const char* s_shares,
char
decr_sshare
[
65
];
xor_decrypt
(
common_key
,
encr_sshare
,
decr_sshare
);
if
(
decr_sshare
==
NULL
){
*
err_status
=
1
;
snprintf
(
err_string
,
BUF_LEN
,
"invalid common_key"
);
return
;
}
if
(
decr_sshare
==
NULL
){
*
err_status
=
1
;
snprintf
(
err_string
,
BUF_LEN
,
"invalid common_key"
);
return
;
}
//decr_sshare[64] = 0;
snprintf
(
err_string
+
158
*
i
,
BUF_LEN
,
"decr sshare is %s"
,
decr_sshare
);
snprintf
(
err_string
+
158
*
i
+
79
,
BUF_LEN
,
" common_key is %s"
,
common_key
);
//snprintf(err_string + 89*i, BUF_LEN,"share is %s length is %d ", decr_sshare, strlen(decr_sshare));
//snprintf(err_string + 65*i, BUF_LEN,"%s ", decr_sshare);
...
...
@@ -816,18 +816,18 @@ void create_bls_key(int *err_status, char* err_string, const char* s_shares,
char
key_share
[
mpz_sizeinbase
(
bls_key
,
16
)
+
2
];
char
*
key
=
mpz_get_str
(
key_share
,
16
,
bls_key
);
snprintf
(
err_string
,
BUF_LEN
,
"
bls private key is %s"
,
key_share
);
snprintf
(
err_string
+
158
*
num_shares
,
BUF_LEN
,
"
bls private key is %s"
,
key_share
);
uint32_t
sealedLen
=
sgx_calc_sealed_data_size
(
0
,
ECDSA_SKEY_LEN
);
status
=
sgx_seal_data
(
0
,
NULL
,
ECDSA_SKEY_LEN
,
(
uint8_t
*
)
key_share
,
sealedLen
,(
sgx_sealed_data_t
*
)
encr_bls_key
);
if
(
status
!=
SGX_SUCCESS
)
{
*
err_status
=
-
1
;
snprintf
(
err_string
,
BUF_LEN
,
"seal bls private key failed with status %d "
,
status
);
return
;
}
*
enc_bls_key_len
=
sealedLen
;
//snprintf(err_string, BUF_LEN,"sshare is %s", decr_sshare);
//snprintf(err_string, BUF_LEN,"encr_share is %s", encr_sshare);
//snprintf(err_string, BUF_LEN,"common_key is %s", common_key);
...
...
sgxwallet_common.h
View file @
8aabe34e
...
...
@@ -56,7 +56,7 @@
#define SGX_ENCLAVE_ERROR -666;
#define WALLETDB_NAME
"test_sgxwallet1.db"//"sgxwallet.db"
#define WALLETDB_NAME
"test_sgxwallet1.db"//"sgxwallet.db"//////////
#define ENCLAVE_NAME "secure_enclave.signed.so"
...
...
spec.json
View file @
8aabe34e
...
...
@@ -194,7 +194,9 @@
"share*G2"
:
"123"
,
"DHKey"
:
"123"
}
}
},
]
\ No newline at end of file
stubclient.h
View file @
8aabe34e
...
...
@@ -185,6 +185,18 @@ class StubClient : public jsonrpc::Client
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
}
Json
::
Value
MultG2
(
const
std
::
string
&
x
)
throw
(
jsonrpc
::
JsonRpcException
)
{
Json
::
Value
p
;
p
[
"x"
]
=
x
;
Json
::
Value
result
=
this
->
CallMethod
(
"MultG2"
,
p
);
if
(
result
.
isObject
())
return
result
;
else
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
}
};
#endif //JSONRPC_CPP_STUB_STUBCLIENT_H_
testw.cpp
View file @
8aabe34e
...
...
@@ -736,6 +736,7 @@ std::string ConvertDecToHex(std::string dec, int numBytes = 32){
return
result
;
}
TEST_CASE
(
"BLS_DKG test"
,
"[bls_dkg]"
)
{
std
::
cerr
<<
"test started"
<<
std
::
endl
;
init_all
();
...
...
@@ -746,7 +747,11 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
reset_db
();
int
n
=
4
,
t
=
2
;
int
n
=
2
,
t
=
2
;
Json
::
Value
EthKeys
[
n
];
Json
::
Value
VerifVects
[
n
];
Json
::
Value
pubEthKeys
;
...
...
@@ -785,11 +790,14 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
int
k
=
0
;
std
::
vector
<
std
::
string
>
secShares_vect
(
n
);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
j
=
0
;
j
<
n
;
j
++
){
// if ( i != j ){
std
::
cerr
<<
"SecretShare length is "
<<
secretShares
[
i
][
"SecretShare"
].
asString
().
length
()
<<
std
::
endl
;
std
::
string
secretShare
=
secretShares
[
i
][
"SecretShare"
].
asString
().
substr
(
192
*
j
,
192
*
(
j
+
1
));
secShares_vect
[
i
]
+=
secretShares
[
j
][
"SecretShare"
].
asString
().
substr
(
192
*
i
,
192
*
(
i
+
1
));
bool
res
=
c
.
DKGVerification
(
pubShares
[
i
],
EthKeys
[
j
][
"KeyName"
].
asString
(),
secretShare
,
t
,
n
,
j
)[
"result"
].
asBool
();
k
++
;
std
::
cerr
<<
"NOW K IS "
<<
k
<<
" i is "
<<
i
<<
" j is "
<<
j
<<
std
::
endl
;
...
...
@@ -807,14 +815,17 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
throw
RPCException
(
INVALID_HEX
,
"Invalid hash"
);
}
std
::
map
<
size_t
,
std
::
shared_ptr
<
BLSPublicKeyShare
>>
koefs_pkeys_map
;
for
(
int
i
=
0
;
i
<
t
;
i
++
){
std
::
string
endName
=
poly_names
[
i
].
substr
(
4
);
std
::
string
blsName
=
"BLS_KEY"
+
poly_names
[
i
].
substr
(
4
);
std
::
string
secretShare
=
secretShares
[
i
][
"SecretShare"
].
asString
();
cout
<<
c
.
CreateBLSPrivateKey
(
blsName
,
EthKeys
[
i
][
"KeyName"
].
asString
(),
poly_names
[
i
],
secretShare
,
t
,
n
);
//cout << c.CreateBLSPrivateKey(blsName, EthKeys[i]["KeyName"].asString(), poly_names[i], secretShare, t, n);
cout
<<
c
.
CreateBLSPrivateKey
(
blsName
,
EthKeys
[
i
][
"KeyName"
].
asString
(),
poly_names
[
i
],
secShares_vect
[
i
],
t
,
n
);
pubBLSKeys
[
i
]
=
c
.
GetBLSPublicKeyShare
(
blsName
);
std
::
cerr
<<
"BLS KEY SHARE NAME IS "
<<
blsName
<<
std
::
endl
;
//std::string hash = "09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db";
BLSSigShares
[
i
]
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
,
i
+
1
);
std
::
cerr
<<
i
<<
" sig share is created "
<<
std
::
endl
;
...
...
@@ -837,17 +848,27 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
BLSPublicKey
common_public
(
std
::
make_shared
<
std
::
map
<
size_t
,
std
::
shared_ptr
<
BLSPublicKeyShare
>>>
(
koefs_pkeys_map
),
t
,
n
);
REQUIRE
(
common_public
.
VerifySigWithHelper
(
hash_arr
,
commonSig
,
t
,
n
)
);
std
::
cout
<<
"try to get bls public key"
<<
std
::
endl
;
std
::
cout
<<
c
.
GetBLSPublicKeyShare
(
"BLS_KEY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:0"
);
exit
(
0
);
}
TEST_CASE
(
"create_bls_key_share"
,
"[create_bls_key]"
)
{
init_enclave
();
std
::
string
SecrShare
=
"937c9c846a6fa7fd1984fe82e739ae37fcaa555c1dc0e8597c9f81b6a12f232ffdf8101e91bd658fa1cea6fdd75adb8542951ce3d251cdaa78f43493dad730b59d32d2e872b36aa70cdce544b550ebe96994de860b6f6ebb7d0b4d4e6724b4bf7232f27fdfe521f3c7997dbb1c15452b7f196bd119d915ce76af3d1a008e1810086ff076abe442563ae9b8938d483ae581f4de2ee54298b3078289bbd85250c8df956450d32f671e4a8ec1e584119753ff171e80a61465246bfd291e8dac3d"
;
bool
res
=
TestCreateBLSShare
(
SecrShare
.
c_str
());
REQUIRE
(
res
);
sgx_destroy_enclave
(
eid
);
}
TEST_CASE
(
"API test"
,
"[api_test]"
)
{
std
::
cerr
<<
__GNUC__
<<
std
::
endl
;
//
std::cerr << __GNUC__ << std::endl;
cerr
<<
"API test started"
<<
endl
;
init_all
();
//HttpServer httpserver(1025);
...
...
@@ -883,7 +904,7 @@ TEST_CASE("API test", "[api_test]") {
// cout << c.blsSignMessageHash(TEST_BLS_KEY_NAME, "0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db", 2,2,1 );
// cout << c.generateDKGPoly("pp2", 2);
// cout << c.generateDKGPoly("POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1", 2);
cout
<<
c
.
generateDKGPoly
(
"POLY:SCHAIN_ID:14225439306783892379384764908040542049263455631509697460847850632966314337557:NODE_ID:1:DKG_ID:71951190446274221430521459675625214118086594348715"
,
1
);
//
cout << c.generateDKGPoly("POLY:SCHAIN_ID:14225439306783892379384764908040542049263455631509697460847850632966314337557:NODE_ID:1:DKG_ID:71951190446274221430521459675625214118086594348715", 1);
//cout << c.getVerificationVector("POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:2", 2, 2);
// cout << c.getVerificationVector("polyy", 5, 5);
...
...
@@ -936,9 +957,24 @@ TEST_CASE("API test", "[api_test]") {
// cout << c.blsSignMessageHash("dOsRY","38433e5ce087dcc1be82fcc834eae83c256b3db87d34f84440d0b708daa0c6f7", 2, 2, 1);
// cout << c.ComplaintResponse("POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1", 0);
// cout << c.GetBLSPublicKeyShare("BLS_KEY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:0");
// cout << c.getPublicECDSAKey("NEK:91573248d6b0ebd5b1bd313ab35163361b423c0f9f01bad085d166650b8b2c1f");
cout
<<
c
.
MultG2
(
"4160780231445160889237664391382223604184857153814275770598791864649971919844"
);
}
catch
(
JsonRpcException
&
e
)
{
cerr
<<
e
.
what
()
<<
endl
;
}
sgx_destroy_enclave
(
eid
);
}
//decr sshare is 0570d18552dc248c5f806cbfeb96cdc40234d51233b3ba80a9c7b790ae4eed13
//common_key is e6d91ec58664d25dd80071520793ab307bf408158543a9710445bd663041a760decr
//sshare is d56909d4b29a0f1d306be98c019bed02e9c6b9b56bfe9e933314815983401b40
//common_key is 0e4506de4faa7a241fccbcc9339cce03737415ba38349ccfa7aec916d37cee07
//
//
//decr sshare is 1f63caaf684e632338cd7c17569fb65d820004266acd36f0b6d2cbd05648b071
//common_key is e969840c044a3e7252e4677225f2513722d545ff1612f35d0cd66cda65185356decr
//sshare is 20d254d489bb31fc5b470c641ba280ea35e7da3a86c11ccdb74d3f9898daaa93
//common_key is 18dffe11f73f6d53e8f53ce1fe0ab8192f7a9180d50fb7e34a01776652e73471
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