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
551b80ab
Unverified
Commit
551b80ab
authored
Dec 09, 2020
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-3654-better-errors
parent
0b6294b6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
128 additions
and
68 deletions
+128
-68
DKGCrypto.cpp
DKGCrypto.cpp
+4
-6
Log.h
Log.h
+16
-9
SGXWalletServer.cpp
SGXWalletServer.cpp
+48
-48
sgxwallet_common.h
sgxwallet_common.h
+60
-5
No files found.
DKGCrypto.cpp
View file @
551b80ab
...
@@ -92,7 +92,7 @@ string convertHexToDec(const string &hex_str) {
...
@@ -92,7 +92,7 @@ string convertHexToDec(const string &hex_str) {
throw
SGXException
(
INCORRECT_STRING_CONVERSION
,
e
.
what
());
throw
SGXException
(
INCORRECT_STRING_CONVERSION
,
e
.
what
());
}
catch
(...)
{
}
catch
(...)
{
mpz_clear
(
dec
);
mpz_clear
(
dec
);
throw
SGXException
(
UNKNOWN_ERROR
,
"
"
);
throw
SGXException
(
EXCEPTION_IN_CONVERT_HEX_TO_DEC
,
"Exception in convert hex to dec
"
);
}
}
clean
:
clean
:
...
@@ -117,10 +117,10 @@ string convertG2ToString(const libff::alt_bn128_G2 &elem, int base, const string
...
@@ -117,10 +117,10 @@ string convertG2ToString(const libff::alt_bn128_G2 &elem, int base, const string
return
result
;
return
result
;
}
catch
(
exception
&
e
)
{
}
catch
(
exception
&
e
)
{
throw
SGXException
(
INCORRECT_STRING_CONVERSION
,
e
.
what
());
throw
SGXException
(
CONVERT_G2_
INCORRECT_STRING_CONVERSION
,
e
.
what
());
return
result
;
return
result
;
}
catch
(...)
{
}
catch
(...)
{
throw
SGXException
(
UNKNOWN_ERROR
,
"
"
);
throw
SGXException
(
EXCEPTION_IN_CONVERT_G2_STRING
,
"Exception in convert G2 to string
"
);
return
result
;
return
result
;
}
}
...
@@ -236,7 +236,6 @@ getSecretShares(const string &_polyName, const char *_encryptedPolyHex, const ve
...
@@ -236,7 +236,6 @@ getSecretShares(const string &_polyName, const char *_encryptedPolyHex, const ve
throw
SGXException
(
INVALID_HEX
,
"Invalid encryptedPolyHex"
);
throw
SGXException
(
INVALID_HEX
,
"Invalid encryptedPolyHex"
);
}
}
sgx_status_t
status
=
SGX_SUCCESS
;
READ_LOCK
(
sgxInitMutex
);
READ_LOCK
(
sgxInitMutex
);
...
@@ -295,10 +294,9 @@ string getSecretSharesV2(const string& _polyName, const char* _encryptedPolyHex,
...
@@ -295,10 +294,9 @@ string getSecretSharesV2(const string& _polyName, const char* _encryptedPolyHex,
if
(
!
hex2carray
(
_encryptedPolyHex
,
&
encLen
,
encrDKGPoly
.
data
(),
BUF_LEN
))
{
if
(
!
hex2carray
(
_encryptedPolyHex
,
&
encLen
,
encrDKGPoly
.
data
(),
BUF_LEN
))
{
throw
SGXException
(
INVALID_HEX
,
"Invalid encryptedPoly
Hex"
);
throw
SGXException
(
GET_SS_V2_INVALID_HEX
,
"Invalid encrypted poly
Hex"
);
}
}
sgx_status_t
status
=
SGX_SUCCESS
;
READ_LOCK
(
sgxInitMutex
);
READ_LOCK
(
sgxInitMutex
);
...
...
Log.h
View file @
551b80ab
/*
/*
*
Copyright (C) 2019-Present SKALE Labs
Copyright (C) 2019-Present SKALE Labs
This file is part of sgxwallet.
This file is part of sgxwallet.
...
@@ -83,26 +84,32 @@ spdlog::info(string(__FUNCTION__) + " processed " + to_string(__COUNT__) + " re
...
@@ -83,26 +84,32 @@ spdlog::info(string(__FUNCTION__) + " processed " + to_string(__COUNT__) + " re
}
}
// if uknown error, the error is 10000 + line number
#define INIT_RESULT(__RESULT__) Json::Value __RESULT__; \
#define INIT_RESULT(__RESULT__) Json::Value __RESULT__; \
int errStatus = UNKNOWN_ERROR; boost::ignore_unused(errStatus); string errMsg(BUF_LEN, '\0');__RESULT__["status"] = UNKNOWN_ERROR; __RESULT__["errorMessage"] = \
int errStatus = -1 * (10000 + __LINE__); boost::ignore_unused(errStatus); string errMsg(BUF_LEN, '\0');__RESULT__["status"] = -1 * (10000 + __LINE__); __RESULT__["errorMessage"] = \
"Server error. Please see server log.";
string(__FUNCTION__); \
string(__FUNCTION__) + ": server error. Please see server log.";
#define HANDLE_SGX_EXCEPTION(__RESULT__) \
#define HANDLE_SGX_EXCEPTION(__RESULT__) \
catch (SGXException& _e) { \
catch (const SGXException& _e) { \
if (_e.status != 0) {__RESULT__["status"] = _e.status;} else { __RESULT__["status"] = UNKNOWN_ERROR;}; \
if (_e.status != 0) {__RESULT__["status"] = _e.status;} else { __RESULT__["status"] = -1 * (10000 + __LINE__);}; \
__RESULT__["errorMessage"] = _e.errString; \
__RESULT__["errorMessage"] = _e.errString; \
if (_e.errString.size() == 0) {__RESULT__["errorMessage"] = string(__FUNCTION__);}; \
spdlog::error("JSON call failed {}", __FUNCTION__); \
spdlog::error("JSON call failed {}", __FUNCTION__); \
return __RESULT__; \
return __RESULT__; \
} catch (exception& _e) { \
} catch (const exception& _e) { \
__RESULT__["errorMessage"] = _e.what(); \
__RESULT__["status"] = -1 * (10000 + __LINE__); \
exception_ptr p = current_exception(); \
__RESULT__["errorMessage"] = string(p.__cxa_exception_type()->name()) + ":" + _e.what(); \
spdlog::error("JSON call failed {}", __FUNCTION__); \
spdlog::error("JSON call failed {}", __FUNCTION__); \
return __RESULT__; \
return __RESULT__; \
}\
}\
catch (...) { \
catch (...) { \
exception_ptr p = current_exception(); \
exception_ptr p = current_exception(); \
printf("Exception %s \n",
p.__cxa_exception_type()->name()); \
spdlog::error(string("Exception:") +
p.__cxa_exception_type()->name()); \
__RESULT__["errorMessage"] =
"Unknown exception";
\
__RESULT__["errorMessage"] =
string(p.__cxa_exception_type()->name());
\
spdlog::error("JSON call failed {}", __FUNCTION__); \
spdlog::error("JSON call failed {}", __FUNCTION__); \
return __RESULT__; \
return __RESULT__; \
}
}
...
...
SGXWalletServer.cpp
View file @
551b80ab
...
@@ -217,7 +217,7 @@ SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_k
...
@@ -217,7 +217,7 @@ SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_k
}
}
if
(
!
checkHex
(
hashTmp
))
{
if
(
!
checkHex
(
hashTmp
))
{
throw
SGXException
(
INVALID_
HEX
,
"Invalid BLS key share, please use hex"
);
throw
SGXException
(
INVALID_
BLS_KEY_SHARE
,
"Invalid BLS key share, please use hex"
);
}
}
encryptedKeyShareHex
=
encryptBLSKeyShare2Hex
(
&
errStatus
,
(
char
*
)
errMsg
.
data
(),
hashTmp
.
c_str
());
encryptedKeyShareHex
=
encryptBLSKeyShare2Hex
(
&
errStatus
,
(
char
*
)
errMsg
.
data
(),
hashTmp
.
c_str
());
...
@@ -227,7 +227,7 @@ SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_k
...
@@ -227,7 +227,7 @@ SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_k
}
}
if
(
encryptedKeyShareHex
.
empty
())
{
if
(
encryptedKeyShareHex
.
empty
())
{
throw
SGXException
(
UNKNOWN_ERROR
,
""
);
throw
SGXException
(
EMPTY_ENCRYPTED_KEY_SHARE
,
""
);
}
}
result
[
"encryptedKeyShare"
]
=
encryptedKeyShareHex
;
result
[
"encryptedKeyShare"
]
=
encryptedKeyShareHex
;
...
@@ -296,14 +296,14 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin
...
@@ -296,14 +296,14 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin
}
}
if
(
!
checkHex
(
hashTmp
))
{
if
(
!
checkHex
(
hashTmp
))
{
throw
SGXException
(
INVALID_
HEX
,
"Invalid hash
"
);
throw
SGXException
(
INVALID_
BLS_HEX
,
"Invalid bls hex
"
);
}
}
value
=
readFromDb
(
_keyShareName
);
value
=
readFromDb
(
_keyShareName
);
if
(
!
bls_sign
(
value
->
c_str
(),
_messageHash
.
c_str
(),
t
,
n
,
signature
.
data
()))
{
if
(
!
bls_sign
(
value
->
c_str
(),
_messageHash
.
c_str
(),
t
,
n
,
signature
.
data
()))
{
throw
SGXException
(
-
1
,
"Could not
sign data "
);
throw
SGXException
(
COULD_NOT_BLS_SIGN
,
"Could not bls
sign data "
);
}
}
}
HANDLE_SGX_EXCEPTION
(
result
)
}
HANDLE_SGX_EXCEPTION
(
result
)
...
@@ -324,7 +324,7 @@ Json::Value SGXWalletServer::importECDSAKeyImpl(const string &_keyShare,
...
@@ -324,7 +324,7 @@ Json::Value SGXWalletServer::importECDSAKeyImpl(const string &_keyShare,
try
{
try
{
if
(
!
checkECDSAKeyName
(
_keyShareName
))
{
if
(
!
checkECDSAKeyName
(
_keyShareName
))
{
throw
SGXException
(
INVALID_ECDSA_
KEY_NAME
,
"Invalid ECDSA
key name"
);
throw
SGXException
(
INVALID_ECDSA_
IMPORT_KEY_NAME
,
"Invalid ECDSA import
key name"
);
}
}
string
hashTmp
=
_keyShare
;
string
hashTmp
=
_keyShare
;
...
@@ -333,7 +333,7 @@ Json::Value SGXWalletServer::importECDSAKeyImpl(const string &_keyShare,
...
@@ -333,7 +333,7 @@ Json::Value SGXWalletServer::importECDSAKeyImpl(const string &_keyShare,
}
}
if
(
!
checkHex
(
hashTmp
))
{
if
(
!
checkHex
(
hashTmp
))
{
throw
SGXException
(
INVALID_HEX
,
"Invalid ECDSA key share, please use hex"
);
throw
SGXException
(
INVALID_
ECDSA_IMPORT_
HEX
,
"Invalid ECDSA key share, please use hex"
);
}
}
string
encryptedKey
=
encryptECDSAKey
(
hashTmp
);
string
encryptedKey
=
encryptECDSAKey
(
hashTmp
);
...
@@ -359,7 +359,7 @@ Json::Value SGXWalletServer::generateECDSAKeyImpl() {
...
@@ -359,7 +359,7 @@ Json::Value SGXWalletServer::generateECDSAKeyImpl() {
keys
=
genECDSAKey
();
keys
=
genECDSAKey
();
if
(
keys
.
size
()
==
0
)
{
if
(
keys
.
size
()
==
0
)
{
throw
SGXException
(
UNKNOWN_ERROR
,
"key was not generated"
);
throw
SGXException
(
ECDSA_GEN_EMPTY_KEY
,
"key was not generated"
);
}
}
string
keyName
=
"NEK:"
+
keys
.
at
(
2
);
string
keyName
=
"NEK:"
+
keys
.
at
(
2
);
...
@@ -388,7 +388,6 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_
...
@@ -388,7 +388,6 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_
checkForDuplicate
(
ecdsaRequests
,
ecdsaRequestsLock
,
_keyName
,
_messageHash
);
checkForDuplicate
(
ecdsaRequests
,
ecdsaRequestsLock
,
_keyName
,
_messageHash
);
try
{
try
{
string
hashTmp
=
_messageHash
;
string
hashTmp
=
_messageHash
;
if
(
hashTmp
[
0
]
==
'0'
&&
(
hashTmp
[
1
]
==
'x'
||
hashTmp
[
1
]
==
'X'
))
{
if
(
hashTmp
[
0
]
==
'0'
&&
(
hashTmp
[
1
]
==
'x'
||
hashTmp
[
1
]
==
'X'
))
{
...
@@ -399,20 +398,20 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_
...
@@ -399,20 +398,20 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_
}
}
if
(
!
checkECDSAKeyName
(
_keyName
))
{
if
(
!
checkECDSAKeyName
(
_keyName
))
{
throw
SGXException
(
INVALID_ECDSA_
KEY_NAME
,
"Invalid ECDSA
key name"
);
throw
SGXException
(
INVALID_ECDSA_
SIGN_KEY_NAME
,
"Invalid ECDSA sign
key name"
);
}
}
if
(
!
checkHex
(
hashTmp
))
{
if
(
!
checkHex
(
hashTmp
))
{
throw
SGXException
(
INVALID_
HEX
,
"Invalid
hash"
);
throw
SGXException
(
INVALID_
ECDSA_SIGN_HASH
,
"Invalid ECDSA sign
hash"
);
}
}
if
(
_base
<=
0
||
_base
>
32
)
{
if
(
_base
<=
0
||
_base
>
32
)
{
throw
SGXException
(
-
22
,
"Invalid
base"
);
throw
SGXException
(
INVALID_ECDSA_SIGN_BASE
,
"Invalid ECDSA sign
base"
);
}
}
shared_ptr
<
string
>
encryptedKey
=
readFromDb
(
_keyName
,
""
);
shared_ptr
<
string
>
encryptedKey
=
readFromDb
(
_keyName
,
""
);
signatureVector
=
ecdsaSignHash
(
encryptedKey
->
c_str
(),
hashTmp
.
c_str
(),
_base
);
signatureVector
=
ecdsaSignHash
(
encryptedKey
->
c_str
(),
hashTmp
.
c_str
(),
_base
);
if
(
signatureVector
.
size
()
!=
3
)
{
if
(
signatureVector
.
size
()
!=
3
)
{
throw
SGXException
(
INVALID_ECSDA_SIGNATURE
,
"Invalid ecdsa signature"
);
throw
SGXException
(
INVALID_ECSDA_SIGN
_SIGN
ATURE
,
"Invalid ecdsa signature"
);
}
}
result
[
"signature_v"
]
=
signatureVector
.
at
(
0
);
result
[
"signature_v"
]
=
signatureVector
.
at
(
0
);
...
@@ -435,7 +434,7 @@ Json::Value SGXWalletServer::getPublicECDSAKeyImpl(const string &_keyName) {
...
@@ -435,7 +434,7 @@ Json::Value SGXWalletServer::getPublicECDSAKeyImpl(const string &_keyName) {
try
{
try
{
if
(
!
checkECDSAKeyName
(
_keyName
))
{
if
(
!
checkECDSAKeyName
(
_keyName
))
{
throw
SGXException
(
INVALID_ECDSA_
KEY_NAME
,
"Invalid ECDSA
key name"
);
throw
SGXException
(
INVALID_ECDSA_
GETPKEY_KEY_NAME
,
"Invalid ECDSA import
key name"
);
}
}
shared_ptr
<
string
>
keyStr
=
readFromDb
(
_keyName
);
shared_ptr
<
string
>
keyStr
=
readFromDb
(
_keyName
);
publicKey
=
getECDSAPubKey
(
keyStr
->
c_str
());
publicKey
=
getECDSAPubKey
(
keyStr
->
c_str
());
...
@@ -455,11 +454,11 @@ Json::Value SGXWalletServer::generateDKGPolyImpl(const string &_polyName, int _t
...
@@ -455,11 +454,11 @@ Json::Value SGXWalletServer::generateDKGPolyImpl(const string &_polyName, int _t
try
{
try
{
if
(
!
checkName
(
_polyName
,
"POLY"
))
{
if
(
!
checkName
(
_polyName
,
"POLY"
))
{
throw
SGXException
(
INVALID_POLY_NAME
,
throw
SGXException
(
INVALID_
GEN_DKG_
POLY_NAME
,
"Invalid
polynomial name, it should be like POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1
"
);
"Invalid
gen DKG polynomial name.
"
);
}
}
if
(
_t
<=
0
||
_t
>
32
)
{
if
(
_t
<=
0
||
_t
>
32
)
{
throw
SGXException
(
INVALID_DKG_PARAMS
,
"Invalid
parameter
t "
);
throw
SGXException
(
INVALID_DKG_PARAMS
,
"Invalid
gen dkg param
t "
);
}
}
encrPolyHex
=
gen_dkg_poly
(
_t
);
encrPolyHex
=
gen_dkg_poly
(
_t
);
writeDataToDB
(
_polyName
,
encrPolyHex
);
writeDataToDB
(
_polyName
,
encrPolyHex
);
...
@@ -476,10 +475,10 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName,
...
@@ -476,10 +475,10 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName,
vector
<
vector
<
string
>>
verifVector
;
vector
<
vector
<
string
>>
verifVector
;
try
{
try
{
if
(
!
checkName
(
_polyName
,
"POLY"
))
{
if
(
!
checkName
(
_polyName
,
"POLY"
))
{
throw
SGXException
(
INVALID_POLY_NAME
,
"Invalid polynomial name"
);
throw
SGXException
(
INVALID_
DKG_GETVV_
POLY_NAME
,
"Invalid polynomial name"
);
}
}
if
(
!
check_n_t
(
_t
,
_n
))
{
if
(
!
check_n_t
(
_t
,
_n
))
{
throw
SGXException
(
INVALID_DKG_
PARAMS
,
"Invalid parameters:
n or t "
);
throw
SGXException
(
INVALID_DKG_
GETVV_PARAMS
,
"Invalid parameters
n or t "
);
}
}
shared_ptr
<
string
>
encrPoly
=
readFromDb
(
_polyName
);
shared_ptr
<
string
>
encrPoly
=
readFromDb
(
_polyName
);
...
@@ -506,13 +505,13 @@ Json::Value SGXWalletServer::getSecretShareImpl(const string &_polyName, const J
...
@@ -506,13 +505,13 @@ Json::Value SGXWalletServer::getSecretShareImpl(const string &_polyName, const J
try
{
try
{
if
(
_pubKeys
.
size
()
!=
(
uint64_t
)
_n
)
{
if
(
_pubKeys
.
size
()
!=
(
uint64_t
)
_n
)
{
throw
SGXException
(
INVALID_DKG_
PARAMS
,
"invalid number of public keys
"
);
throw
SGXException
(
INVALID_DKG_
GETSS_PUB_KEY_COUNT
,
"invalid pubkey count
"
);
}
}
if
(
!
checkName
(
_polyName
,
"POLY"
))
{
if
(
!
checkName
(
_polyName
,
"POLY"
))
{
throw
SGXException
(
INVALID_POLY_NAME
,
"Invalid polynomial name"
);
throw
SGXException
(
INVALID_
DKG_GETSS_
POLY_NAME
,
"Invalid polynomial name"
);
}
}
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_
GETSS_POLY_NAME
,
"Invalid DKG parameters: n or t "
);
}
}
shared_ptr
<
string
>
encrPoly
=
readFromDb
(
_polyName
);
shared_ptr
<
string
>
encrPoly
=
readFromDb
(
_polyName
);
...
@@ -520,7 +519,7 @@ Json::Value SGXWalletServer::getSecretShareImpl(const string &_polyName, const J
...
@@ -520,7 +519,7 @@ Json::Value SGXWalletServer::getSecretShareImpl(const string &_polyName, const J
vector
<
string
>
pubKeysStrs
;
vector
<
string
>
pubKeysStrs
;
for
(
int
i
=
0
;
i
<
_n
;
i
++
)
{
for
(
int
i
=
0
;
i
<
_n
;
i
++
)
{
if
(
!
checkHex
(
_pubKeys
[
i
].
asString
(),
64
))
{
if
(
!
checkHex
(
_pubKeys
[
i
].
asString
(),
64
))
{
throw
SGXException
(
INVALID_HEX
,
"Invalid public key"
);
throw
SGXException
(
INVALID_
DKG_GETSS_KEY_
HEX
,
"Invalid public key"
);
}
}
pubKeysStrs
.
push_back
(
_pubKeys
[
i
].
asString
());
pubKeysStrs
.
push_back
(
_pubKeys
[
i
].
asString
());
}
}
...
@@ -548,16 +547,16 @@ Json::Value SGXWalletServer::dkgVerificationImpl(const string &_publicShares, co
...
@@ -548,16 +547,16 @@ Json::Value SGXWalletServer::dkgVerificationImpl(const string &_publicShares, co
try
{
try
{
if
(
!
checkECDSAKeyName
(
_ethKeyName
))
{
if
(
!
checkECDSAKeyName
(
_ethKeyName
))
{
throw
SGXException
(
INVALID_ECDSA_KEY_NAME
,
"Invalid ECDSA key name"
);
throw
SGXException
(
INVALID_
DKG_VERIFY_
ECDSA_KEY_NAME
,
"Invalid ECDSA key name"
);
}
}
if
(
!
check_n_t
(
_t
,
_n
)
||
_index
>=
_n
||
_index
<
0
)
{
if
(
!
check_n_t
(
_t
,
_n
)
||
_index
>=
_n
||
_index
<
0
)
{
throw
SGXException
(
INVALID_DKG_PARAMS
,
"Invalid DKG parameters: n or t "
);
throw
SGXException
(
INVALID_DKG_
VERIFY_
PARAMS
,
"Invalid DKG parameters: n or t "
);
}
}
if
(
!
checkHex
(
_secretShare
,
SECRET_SHARE_NUM_BYTES
))
{
if
(
!
checkHex
(
_secretShare
,
SECRET_SHARE_NUM_BYTES
))
{
throw
SGXException
(
INVALID_HEX
,
"Invalid Secret share"
);
throw
SGXException
(
INVALID_
DKG_VERIFY_SS_
HEX
,
"Invalid Secret share"
);
}
}
if
(
_publicShares
.
length
()
!=
(
uint64_t
)
256
*
_t
)
{
if
(
_publicShares
.
length
()
!=
(
uint64_t
)
256
*
_t
)
{
throw
SGXException
(
INVALID_DKG_
PARAMS
,
"Invalid length of public shares"
);
throw
SGXException
(
INVALID_DKG_
VERIFY_PUBSHARES_LENGTH
,
"Invalid length of public shares"
);
}
}
shared_ptr
<
string
>
encryptedKeyHex_ptr
=
readFromDb
(
_ethKeyName
);
shared_ptr
<
string
>
encryptedKeyHex_ptr
=
readFromDb
(
_ethKeyName
);
...
@@ -579,19 +578,19 @@ SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string
...
@@ -579,19 +578,19 @@ SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string
try
{
try
{
if
(
_secretShare
.
length
()
!=
(
uint64_t
)
_n
*
192
)
{
if
(
_secretShare
.
length
()
!=
(
uint64_t
)
_n
*
192
)
{
throw
SGXException
(
INVALID_SECRET_SHARES_LENGTH
,
"Invalid secret share length"
);
throw
SGXException
(
INVALID_
CREATE_BLS_KEY_
SECRET_SHARES_LENGTH
,
"Invalid secret share length"
);
}
}
if
(
!
checkECDSAKeyName
(
_ethKeyName
))
{
if
(
!
checkECDSAKeyName
(
_ethKeyName
))
{
throw
SGXException
(
INVALID_ECDSA_KEY_NAME
,
"Invalid ECDSA key name"
);
throw
SGXException
(
INVALID_
CREATE_BLS_
ECDSA_KEY_NAME
,
"Invalid ECDSA key name"
);
}
}
if
(
!
checkName
(
_polyName
,
"POLY"
))
{
if
(
!
checkName
(
_polyName
,
"POLY"
))
{
throw
SGXException
(
INVALID_POLY_NAME
,
"Invalid polynomial name"
);
throw
SGXException
(
INVALID_
CREATE_BLS_
POLY_NAME
,
"Invalid polynomial name"
);
}
}
if
(
!
checkName
(
_blsKeyName
,
"BLS_KEY"
))
{
if
(
!
checkName
(
_blsKeyName
,
"BLS_KEY"
))
{
throw
SGXException
(
INVALID_
BLS
_NAME
,
"Invalid BLS key name"
);
throw
SGXException
(
INVALID_
CREATE_BLS_KEY
_NAME
,
"Invalid BLS key name"
);
}
}
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_
CREATE_BLS_
DKG_PARAMS
,
"Invalid DKG parameters: n or t "
);
}
}
vector
<
string
>
sshares_vect
;
vector
<
string
>
sshares_vect
;
...
@@ -603,7 +602,7 @@ SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string
...
@@ -603,7 +602,7 @@ SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string
if
(
res
)
{
if
(
res
)
{
spdlog
::
info
(
"BLS KEY SHARE CREATED "
);
spdlog
::
info
(
"BLS KEY SHARE CREATED "
);
}
else
{
}
else
{
throw
SGXException
(
-
122
,
"Error while creating BLS key share"
);
throw
SGXException
(
INVALID_CREATE_BLS_SHARE
,
"Error while creating BLS key share"
);
}
}
...
@@ -631,7 +630,7 @@ Json::Value SGXWalletServer::getBLSPublicKeyShareImpl(const string &_blsKeyName)
...
@@ -631,7 +630,7 @@ Json::Value SGXWalletServer::getBLSPublicKeyShareImpl(const string &_blsKeyName)
try
{
try
{
if
(
!
checkName
(
_blsKeyName
,
"BLS_KEY"
))
{
if
(
!
checkName
(
_blsKeyName
,
"BLS_KEY"
))
{
throw
SGXException
(
INVALID_
BLS
_NAME
,
"Invalid BLSKey name"
);
throw
SGXException
(
INVALID_
GET_BLS_PUBKEY
_NAME
,
"Invalid BLSKey name"
);
}
}
shared_ptr
<
string
>
encryptedKeyHex_ptr
=
readFromDb
(
_blsKeyName
);
shared_ptr
<
string
>
encryptedKeyHex_ptr
=
readFromDb
(
_blsKeyName
);
...
@@ -651,24 +650,24 @@ Json::Value SGXWalletServer::calculateAllBLSPublicKeysImpl(const Json::Value &pu
...
@@ -651,24 +650,24 @@ Json::Value SGXWalletServer::calculateAllBLSPublicKeysImpl(const Json::Value &pu
try
{
try
{
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_
CALCULATE_ALL_
PARAMS
,
"Invalid DKG parameters: n or t "
);
}
}
if
(
!
publicShares
.
isArray
())
{
if
(
!
publicShares
.
isArray
())
{
throw
SGXException
(
INVALID_DKG_
PARAM
S
,
"Invalid public shares format"
);
throw
SGXException
(
INVALID_DKG_
CALCULATE_ALL_PUBSHARE
S
,
"Invalid public shares format"
);
}
}
if
(
publicShares
.
size
()
!=
(
uint64_t
)
n
)
{
if
(
publicShares
.
size
()
!=
(
uint64_t
)
n
)
{
throw
SGXException
(
INVALID_DKG_
PARAMS
,
"Invalid length of public shares"
);
throw
SGXException
(
INVALID_DKG_
CALCULATE_ALL_PUBSHARES_SIZE
,
"Invalid length of public shares"
);
}
}
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
if
(
!
publicShares
[
i
].
isString
())
{
if
(
!
publicShares
[
i
].
isString
())
{
throw
SGXException
(
INVALID_DKG_
PARAMS
,
"Invalid public shares parts format
"
);
throw
SGXException
(
INVALID_DKG_
CALCULATE_ALL_PUBSHARES_STRING
,
"Invalid public shares string
"
);
}
}
if
(
publicShares
[
i
].
asString
().
length
()
!=
(
uint64_t
)
256
*
t
)
{
if
(
publicShares
[
i
].
asString
().
length
()
!=
(
uint64_t
)
256
*
t
)
{
throw
SGXException
(
INVALID_DKG_
PARAMS
,
"Invalid length of public shares parts"
);
throw
SGXException
(
INVALID_DKG_
CALCULATE_ALL_STRING_PUBSHARES_SLENGTH
,
"Invalid length of public shares parts"
);
}
}
}
}
...
@@ -680,7 +679,8 @@ Json::Value SGXWalletServer::calculateAllBLSPublicKeysImpl(const Json::Value &pu
...
@@ -680,7 +679,8 @@ Json::Value SGXWalletServer::calculateAllBLSPublicKeysImpl(const Json::Value &pu
vector
<
string
>
public_keys
=
calculateAllBlsPublicKeys
(
public_shares
);
vector
<
string
>
public_keys
=
calculateAllBlsPublicKeys
(
public_shares
);
if
(
public_keys
.
size
()
!=
(
uint64_t
)
n
)
{
if
(
public_keys
.
size
()
!=
(
uint64_t
)
n
)
{
throw
SGXException
(
UNKNOWN_ERROR
,
""
);
throw
SGXException
(
INVALID_DKG_CALCULATE_ALL_STRING_PUBKEYS_SIZE
,
"Invalid pubkeys array size"
);
}
}
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
...
@@ -698,7 +698,7 @@ Json::Value SGXWalletServer::complaintResponseImpl(const string &_polyName, int
...
@@ -698,7 +698,7 @@ Json::Value SGXWalletServer::complaintResponseImpl(const string &_polyName, int
try
{
try
{
if
(
!
checkName
(
_polyName
,
"POLY"
))
{
if
(
!
checkName
(
_polyName
,
"POLY"
))
{
throw
SGXException
(
INVALID_POLY_NAME
,
"Invalid polynomial name"
);
throw
SGXException
(
INVALID_
COMPLAINT_RESPONSE_
POLY_NAME
,
"Invalid polynomial name"
);
}
}
string
shareG2_name
=
"shareG2_"
+
_polyName
+
"_"
+
to_string
(
_ind
)
+
":"
;
string
shareG2_name
=
"shareG2_"
+
_polyName
+
"_"
+
to_string
(
_ind
)
+
":"
;
...
@@ -813,13 +813,13 @@ SGXWalletServer::getSecretShareV2Impl(const string &_polyName, const Json::Value
...
@@ -813,13 +813,13 @@ SGXWalletServer::getSecretShareV2Impl(const string &_polyName, const Json::Value
try
{
try
{
if
(
_pubKeys
.
size
()
!=
(
uint64_t
)
_n
)
{
if
(
_pubKeys
.
size
()
!=
(
uint64_t
)
_n
)
{
throw
SGXException
(
INVALID_DKG_
PARAMS
,
"invalid number of public keys"
);
throw
SGXException
(
INVALID_DKG_
GETSS_V2_PUBKEY_COUNT
,
"invalid number of public keys"
);
}
}
if
(
!
checkName
(
_polyName
,
"POLY"
))
{
if
(
!
checkName
(
_polyName
,
"POLY"
))
{
throw
SGXException
(
INVALID_POLY_NAME
,
"Invalid polynomial name"
);
throw
SGXException
(
INVALID_
DKG_GETSS_V2_
POLY_NAME
,
"Invalid polynomial name"
);
}
}
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_
GETSS_V2_PUBKEY_COUNT
,
"Invalid DKG parameters: n or t "
);
}
}
shared_ptr
<
string
>
encrPoly
=
readFromDb
(
_polyName
);
shared_ptr
<
string
>
encrPoly
=
readFromDb
(
_polyName
);
...
@@ -827,7 +827,7 @@ SGXWalletServer::getSecretShareV2Impl(const string &_polyName, const Json::Value
...
@@ -827,7 +827,7 @@ SGXWalletServer::getSecretShareV2Impl(const string &_polyName, const Json::Value
vector
<
string
>
pubKeysStrs
;
vector
<
string
>
pubKeysStrs
;
for
(
int
i
=
0
;
i
<
_n
;
i
++
)
{
for
(
int
i
=
0
;
i
<
_n
;
i
++
)
{
if
(
!
checkHex
(
_pubKeys
[
i
].
asString
(),
64
))
{
if
(
!
checkHex
(
_pubKeys
[
i
].
asString
(),
64
))
{
throw
SGXException
(
INVALID_HEX
,
"Invalid public key"
);
throw
SGXException
(
INVALID_
DKG_GETSS_V2_PUBKEY_
HEX
,
"Invalid public key"
);
}
}
pubKeysStrs
.
push_back
(
_pubKeys
[
i
].
asString
());
pubKeysStrs
.
push_back
(
_pubKeys
[
i
].
asString
());
}
}
...
@@ -855,16 +855,16 @@ Json::Value SGXWalletServer::dkgVerificationV2Impl(const string &_publicShares,
...
@@ -855,16 +855,16 @@ Json::Value SGXWalletServer::dkgVerificationV2Impl(const string &_publicShares,
try
{
try
{
if
(
!
checkECDSAKeyName
(
_ethKeyName
))
{
if
(
!
checkECDSAKeyName
(
_ethKeyName
))
{
throw
SGXException
(
INVALID_ECDSA_KEY_NAME
,
"Invalid ECDSA key name"
);
throw
SGXException
(
INVALID_
DKG_VV_V2_
ECDSA_KEY_NAME
,
"Invalid ECDSA key name"
);
}
}
if
(
!
check_n_t
(
_t
,
_n
)
||
_index
>=
_n
||
_index
<
0
)
{
if
(
!
check_n_t
(
_t
,
_n
)
||
_index
>=
_n
||
_index
<
0
)
{
throw
SGXException
(
INVALID_DKG_PARAMS
,
"Invalid DKG parameters: n or t "
);
throw
SGXException
(
INVALID_DKG_
VV_V2_
PARAMS
,
"Invalid DKG parameters: n or t "
);
}
}
if
(
!
checkHex
(
_secretShare
,
SECRET_SHARE_NUM_BYTES
))
{
if
(
!
checkHex
(
_secretShare
,
SECRET_SHARE_NUM_BYTES
))
{
throw
SGXException
(
INVALID_HEX
,
"Invalid Secret share"
);
throw
SGXException
(
INVALID_
DKG_VV_V2_SS_
HEX
,
"Invalid Secret share"
);
}
}
if
(
_publicShares
.
length
()
!=
(
uint64_t
)
256
*
_t
)
{
if
(
_publicShares
.
length
()
!=
(
uint64_t
)
256
*
_t
)
{
throw
SGXException
(
INVALID_DKG_
PARAMS
,
"Invalid length
of public shares"
);
throw
SGXException
(
INVALID_DKG_
VV_V2_SS_COUNT
,
"Invalid count
of public shares"
);
}
}
shared_ptr
<
string
>
encryptedKeyHex_ptr
=
readFromDb
(
_ethKeyName
);
shared_ptr
<
string
>
encryptedKeyHex_ptr
=
readFromDb
(
_ethKeyName
);
...
...
sgxwallet_common.h
View file @
551b80ab
...
@@ -67,7 +67,7 @@ extern bool autoconfirm;
...
@@ -67,7 +67,7 @@ extern bool autoconfirm;
#define ECDSA_ENCR_LEN 93
#define ECDSA_ENCR_LEN 93
#define ECDSA_BIN_LEN 33
#define ECDSA_BIN_LEN 33
#define UNKNOWN_ERROR -1
#define PLAINTEXT_KEY_TOO_LONG -2
#define PLAINTEXT_KEY_TOO_LONG -2
#define UNPADDED_KEY -3
#define UNPADDED_KEY -3
#define NULL_KEY -4
#define NULL_KEY -4
...
@@ -88,14 +88,69 @@ extern bool autoconfirm;
...
@@ -88,14 +88,69 @@ extern bool 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 KEY_NAME_ALREADY_EXISTS -23 \
#define INVALID_ECSDA_SIGNATURE -22
#define KEY_NAME_ALREADY_EXISTS -23
#define EMPTY_ENCRYPTED_KEY_SHARE -24
#define INVALID_BLS_KEY_SHARE -25
#define INVALID_BLS_HEX -26
#define INVALID_ECDSA_HEX -27
#define COULD_NOT_BLS_SIGN -28
#define INVALID_ECDSA_IMPORT_KEY_NAME -29
#define INVALID_ECDSA_IMPORT_HEX -30
#define ECDSA_GEN_EMPTY_KEY -31
#define INVALID_ECDSA_SIGN_KEY_NAME -32
#define ERROR_IN_ENCLAVE -33
#define ERROR_IN_ENCLAVE -33
#define INVALID_ECDSA_SIGN_HASH -34
#define INVALID_ECDSA_SIGN_BASE -35
#define INVALID_ECSDA_SIGN_SIGNATURE -36
#define INVALID_ECDSA_GETPKEY_KEY_NAME -37
#define INVALID_GEN_DKG_POLY_NAME -38
#define INVALID_GEN_DKG_PARAM_T -39
#define INVALID_VERIFY_DKG_PARAM_T -40
#define INVALID_DKG_GETVV_POLY_NAME -41
#define INVALID_DKG_GETVV_PARAMS -42
#define INVALID_DKG_GETSS_POLY_NAME -43
#define FILE_NOT_FOUND -44
#define FILE_NOT_FOUND -44
#define INVALID_DKG_GETSS_PARAMS -45
#define INVALID_DKG_GETSS_PUB_KEY_COUNT -46
#define INVALID_DKG_GETSS_KEY_HEX -47
#define INVALID_DKG_VERIFY_ECDSA_KEY_NAME -48
#define INVALID_DKG_VERIFY_PARAMS -49
#define INVALID_DKG_VERIFY_SS_HEX -50
#define INVALID_DKG_VERIFY_PUBSHARES_LENGTH -51
#define INVALID_CREATE_BLS_KEY_SECRET_SHARES_LENGTH -52
#define INVALID_CREATE_BLS_ECDSA_KEY_NAME -53
#define INVALID_CREATE_BLS_POLY_NAME -54
#define FAIL_TO_CREATE_CERTIFICATE -55
#define FAIL_TO_CREATE_CERTIFICATE -55
#define INVALID_CREATE_BLS_KEY_NAME -56
#define INVALID_CREATE_BLS_DKG_PARAMS -57
#define INVALID_CREATE_BLS_SHARE -58
#define INVALID_GET_BLS_PUBKEY_NAME -59
#define INVALID_DKG_CALCULATE_ALL_PARAMS -60
#define INVALID_DKG_CALCULATE_ALL_PUBSHARES -61
#define INVALID_DKG_CALCULATE_ALL_PUBSHARES_SIZE -62
#define INVALID_DKG_CALCULATE_ALL_PUBSHARES_STRING -63
#define INVALID_DKG_CALCULATE_ALL_STRING_PUBSHARES_SLENGTH -64
#define INVALID_DKG_CALCULATE_ALL_STRING_PUBKEYS_SIZE -65
#define INVALID_COMPLAINT_RESPONSE_POLY_NAME -66
#define INVALID_DKG_GETSS_V2_PARAMS -63
#define INVALID_DKG_GETSS_V2_POLY_NAME -64
#define INVALID_DKG_GETSS_V2_PUBKEY_COUNT -65
#define INVALID_DKG_GETSS_V2_PUBKEY_HEX -66
#define INVALID_DKG_VV_V2_ECDSA_KEY_NAME -67
#define INVALID_DKG_VV_V2_PARAMS -68
#define INVALID_DKG_VV_V2_SS_HEX -69
#define INVALID_DKG_VV_V2_SS_COUNT -70
#define EXCEPTION_IN_CONVERT_HEX_TO_DEC -71
#define GET_SS_V2_INVALID_HEX -72
#define EXCEPTION_IN_CONVERT_G2_STRING -73
#define CONVERT_G2_INCORRECT_STRING_CONVERSION -74
#define SGX_ENCLAVE_ERROR -666
#define SGX_ENCLAVE_ERROR -666
...
...
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