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
0684b96a
Unverified
Commit
0684b96a
authored
Sep 03, 2020
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-3213-improve-error-handling
parent
ecdc091e
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
62 additions
and
141 deletions
+62
-141
BLSCrypto.cpp
BLSCrypto.cpp
+5
-4
BLSPrivateKeyShareSGX.cpp
BLSPrivateKeyShareSGX.cpp
+4
-4
DKGCrypto.cpp
DKGCrypto.cpp
+22
-59
DKGCrypto.h
DKGCrypto.h
+1
-1
ECDSACrypto.cpp
ECDSACrypto.cpp
+8
-23
SEKManager.cpp
SEKManager.cpp
+13
-41
SEKManager.h
SEKManager.h
+1
-1
SGXWalletServer.cpp
SGXWalletServer.cpp
+1
-1
ServerInit.cpp
ServerInit.cpp
+2
-1
VERSION
VERSION
+1
-1
sgxwallet.c
sgxwallet.c
+0
-1
sgxwallet.h
sgxwallet.h
+0
-1
testw.cpp
testw.cpp
+4
-3
No files found.
BLSCrypto.cpp
View file @
0684b96a
...
@@ -233,15 +233,16 @@ bool bls_sign(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz
...
@@ -233,15 +233,16 @@ bool bls_sign(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz
string
encryptBLSKeyShare2Hex
(
int
*
errStatus
,
char
*
err_string
,
const
char
*
_key
)
{
string
encryptBLSKeyShare2Hex
(
int
*
errStatus
,
char
*
err_string
,
const
char
*
_key
)
{
auto
keyArray
=
make_shared
<
vector
<
char
>>
(
BUF_LEN
,
0
);
auto
keyArray
=
make_shared
<
vector
<
char
>>
(
BUF_LEN
,
0
);
auto
encryptedKey
=
make_shared
<
vector
<
uint8_t
>>
(
BUF_LEN
,
0
);
auto
encryptedKey
=
make_shared
<
vector
<
uint8_t
>>
(
BUF_LEN
,
0
);
auto
errMsg
=
make_shared
<
vector
<
char
>>
(
BUF_LEN
,
0
);
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);
strncpy
(
keyArray
->
data
(),
_key
,
BUF_LEN
);
strncpy
(
keyArray
->
data
(),
_key
,
BUF_LEN
);
*
errStatus
=
-
1
;
*
errStatus
=
0
;
unsigned
int
encryptedLen
=
0
;
unsigned
int
encryptedLen
=
0
;
s
tatus
=
trustedEncryptKeyAES
(
eid
,
errStatus
,
errMsg
->
data
(),
keyArray
->
data
(),
encryptedKey
->
data
(),
&
encryptedLen
);
s
gx_status_t
status
=
trustedEncryptKeyAES
(
eid
,
errStatus
,
errMsg
.
data
(),
keyArray
->
data
(),
encryptedKey
->
data
(),
&
encryptedLen
);
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
*
errStatus
,
errMsg
->
data
());
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
*
errStatus
,
errMsg
.
data
());
string
result
(
2
*
BUF_LEN
,
'\0'
);
string
result
(
2
*
BUF_LEN
,
'\0'
);
...
...
BLSPrivateKeyShareSGX.cpp
View file @
0684b96a
...
@@ -124,8 +124,8 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr(
...
@@ -124,8 +124,8 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr(
}
}
char
errMsg
[
BUF_LEN
]
;
vector
<
char
>
errMsg
(
BUF_LEN
,
0
)
;
memset
(
errMsg
,
0
,
BUF_LEN
);
char
xStrArg
[
BUF_LEN
];
char
xStrArg
[
BUF_LEN
];
char
yStrArg
[
BUF_LEN
];
char
yStrArg
[
BUF_LEN
];
...
@@ -152,10 +152,10 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr(
...
@@ -152,10 +152,10 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr(
}
}
sgx_status_t
status
=
sgx_status_t
status
=
trustedBlsSignMessageAES
(
eid
,
&
errStatus
,
errMsg
,
encryptedKey
,
trustedBlsSignMessageAES
(
eid
,
&
errStatus
,
errMsg
.
data
()
,
encryptedKey
,
encryptedKeyHex
->
size
()
/
2
,
xStrArg
,
yStrArg
,
signature
);
encryptedKeyHex
->
size
()
/
2
,
xStrArg
,
yStrArg
,
signature
);
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
errStatus
,
errMsg
);
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
errStatus
,
errMsg
.
data
()
);
int
sigLen
;
int
sigLen
;
...
...
DKGCrypto.cpp
View file @
0684b96a
...
@@ -139,19 +139,8 @@ string gen_dkg_poly(int _t) {
...
@@ -139,19 +139,8 @@ string gen_dkg_poly(int _t) {
uint32_t
enc_len
=
0
;
uint32_t
enc_len
=
0
;
status
=
trustedGenDkgSecretAES
(
eid
,
&
errStatus
,
errMsg
.
data
(),
encrypted_dkg_secret
.
data
(),
&
enc_len
,
_t
);
sgx_status_t
status
=
trustedGenDkgSecretAES
(
eid
,
&
errStatus
,
errMsg
.
data
(),
encrypted_dkg_secret
.
data
(),
&
enc_len
,
_t
);
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
errStatus
,
errMsg
.
data
());
if
(
errStatus
!=
0
)
{
spdlog
::
debug
(
"trustedGenDkgSecret, status {}"
,
errStatus
,
" err msg "
,
errMsg
.
data
());
spdlog
::
debug
(
"in DKGCrypto encr len is {}"
,
enc_len
);
throw
SGXException
(
-
666
,
errMsg
.
data
());
}
if
(
status
!=
0
)
{
spdlog
::
debug
(
"trustedGenDkgSecret, status {}"
,
status
,
" err msg "
,
errMsg
.
data
());
spdlog
::
debug
(
"in DKGCrypto encr len is {}"
,
enc_len
);
throw
SGXException
(
-
666
,
errMsg
.
data
());
}
uint64_t
length
=
enc_len
;;
uint64_t
length
=
enc_len
;;
...
@@ -180,25 +169,11 @@ vector <vector<string>> get_verif_vect(const char *encryptedPolyHex, int t, int
...
@@ -180,25 +169,11 @@ vector <vector<string>> get_verif_vect(const char *encryptedPolyHex, int t, int
throw
SGXException
(
INVALID_HEX
,
"Invalid encryptedPolyHex"
);
throw
SGXException
(
INVALID_HEX
,
"Invalid encryptedPolyHex"
);
}
}
spdlog
::
debug
(
"hex_encr_poly length is {}"
,
strlen
(
encryptedPolyHex
));
spdlog
::
debug
(
"enc len {}"
,
encLen
);
status
=
trustedGetPublicSharesAES
(
eid
,
&
errStatus
,
errMsg
.
data
(),
encrDKGPoly
.
data
(),
encLen
,
pubShares
.
data
(),
t
,
n
);
if
(
errStatus
!=
0
)
{
sgx_status_t
status
=
trustedGetPublicSharesAES
(
eid
,
&
errStatus
,
errMsg
.
data
(),
encrDKGPoly
.
data
(),
encLen
,
throw
SGXException
(
-
666
,
errMsg
.
data
());
pubShares
.
data
(),
t
,
n
);
}
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
errStatus
,
errMsg
.
data
());
if
(
status
!=
0
)
{
throw
SGXException
(
-
666
,
errMsg
.
data
());
}
spdlog
::
debug
(
"err msg is {}"
,
errMsg
.
data
());
spdlog
::
debug
(
"public_shares:"
);
spdlog
::
debug
(
"{}"
,
pubShares
.
data
());;
spdlog
::
debug
(
"trustedGetPublicShares status: {}"
,
errStatus
);
vector
<
string
>
g2Strings
=
splitString
(
pubShares
.
data
(),
','
);
vector
<
string
>
g2Strings
=
splitString
(
pubShares
.
data
(),
','
);
vector
<
vector
<
string
>>
pubSharesVect
;
vector
<
vector
<
string
>>
pubSharesVect
;
...
@@ -211,7 +186,7 @@ vector <vector<string>> get_verif_vect(const char *encryptedPolyHex, int t, int
...
@@ -211,7 +186,7 @@ vector <vector<string>> get_verif_vect(const char *encryptedPolyHex, int t, int
}
}
string
string
trustedG
etSecretShares
(
const
string
&
_polyName
,
const
char
*
_encryptedPolyHex
,
const
vector
<
string
>
&
_publicKeys
,
g
etSecretShares
(
const
string
&
_polyName
,
const
char
*
_encryptedPolyHex
,
const
vector
<
string
>
&
_publicKeys
,
int
_t
,
int
_t
,
int
_n
)
{
int
_n
)
{
vector
<
char
>
hexEncrKey
(
BUF_LEN
,
0
);
vector
<
char
>
hexEncrKey
(
BUF_LEN
,
0
);
...
@@ -225,11 +200,8 @@ trustedGetSecretShares(const string &_polyName, const char *_encryptedPolyHex, c
...
@@ -225,11 +200,8 @@ trustedGetSecretShares(const string &_polyName, const char *_encryptedPolyHex, c
throw
SGXException
(
INVALID_HEX
,
"Invalid encryptedPolyHex"
);
throw
SGXException
(
INVALID_HEX
,
"Invalid encryptedPolyHex"
);
}
}
status
=
trustedSetEncryptedDkgPolyAES
(
eid
,
&
errStatus
,
errMsg1
.
data
(),
encrDKGPoly
.
data
(),
encLen
);
sgx_status_t
status
=
trustedSetEncryptedDkgPolyAES
(
eid
,
&
errStatus
,
errMsg1
.
data
(),
encrDKGPoly
.
data
(),
encLen
);
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
errStatus
,
errMsg1
.
data
());
if
(
status
!=
SGX_SUCCESS
||
errStatus
!=
0
)
{
throw
SGXException
(
-
666
,
errMsg1
.
data
());
}
string
result
;
string
result
;
...
@@ -247,12 +219,9 @@ trustedGetSecretShares(const string &_polyName, const char *_encryptedPolyHex, c
...
@@ -247,12 +219,9 @@ trustedGetSecretShares(const string &_polyName, const char *_encryptedPolyHex, c
spdlog
::
debug
(
"pubKeyB is {}"
,
pub_keyB
);
spdlog
::
debug
(
"pubKeyB is {}"
,
pub_keyB
);
trustedGetEncryptedSecretShareAES
(
eid
,
&
errStatus
,
errMsg1
.
data
(),
encryptedSkey
.
data
(),
&
decLen
,
sgx_status_t
status
=
trustedGetEncryptedSecretShareAES
(
eid
,
&
errStatus
,
errMsg1
.
data
(),
encryptedSkey
.
data
(),
&
decLen
,
currentShare
.
data
(),
sShareG2
.
data
(),
pubKeyB
.
data
(),
_t
,
_n
,
i
+
1
);
currentShare
.
data
(),
sShareG2
.
data
(),
pubKeyB
.
data
(),
_t
,
_n
,
i
+
1
);
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
errStatus
,
errMsg1
.
data
());
if
(
errStatus
!=
0
)
{
throw
SGXException
(
-
666
,
errMsg1
.
data
());
}
spdlog
::
debug
(
"cur_share is {}"
,
currentShare
.
data
());
spdlog
::
debug
(
"cur_share is {}"
,
currentShare
.
data
());
...
@@ -272,7 +241,7 @@ trustedGetSecretShares(const string &_polyName, const char *_encryptedPolyHex, c
...
@@ -272,7 +241,7 @@ trustedGetSecretShares(const string &_polyName, const char *_encryptedPolyHex, c
SGXWalletServer
::
writeDataToDB
(
shareG2_name
,
sShareG2
.
data
());
SGXWalletServer
::
writeDataToDB
(
shareG2_name
,
sShareG2
.
data
());
spdlog
::
debug
(
"errMsg: {}"
,
errMsg1
.
data
());
}
}
return
result
;
return
result
;
...
@@ -280,7 +249,7 @@ trustedGetSecretShares(const string &_polyName, const char *_encryptedPolyHex, c
...
@@ -280,7 +249,7 @@ trustedGetSecretShares(const string &_polyName, const char *_encryptedPolyHex, c
bool
bool
verifyShares
(
const
char
*
publicShares
,
const
char
*
encr_sshare
,
const
char
*
encryptedKeyHex
,
int
t
,
int
n
,
int
ind
)
{
verifyShares
(
const
char
*
publicShares
,
const
char
*
encr_sshare
,
const
char
*
encryptedKeyHex
,
int
t
,
int
n
,
int
ind
)
{
char
errMsg
[
BUF_LEN
]
;
vector
<
char
>
errMsg
(
BUF_LEN
,
0
)
;
int
errStatus
=
0
;
int
errStatus
=
0
;
uint64_t
decKeyLen
;
uint64_t
decKeyLen
;
...
@@ -297,10 +266,9 @@ verifyShares(const char *publicShares, const char *encr_sshare, const char *encr
...
@@ -297,10 +266,9 @@ verifyShares(const char *publicShares, const char *encr_sshare, const char *encr
memset
(
pshares
,
0
,
8193
);
memset
(
pshares
,
0
,
8193
);
strncpy
(
pshares
,
publicShares
,
strlen
(
publicShares
));
strncpy
(
pshares
,
publicShares
,
strlen
(
publicShares
));
sgx_status_t
status
=
trustedDkgVerifyAES
(
eid
,
&
errStatus
,
errMsg
,
pshares
,
encr_sshare
,
encr_key
,
decKeyLen
,
t
,
sgx_status_t
status
=
trustedDkgVerifyAES
(
eid
,
&
errStatus
,
errMsg
.
data
()
,
pshares
,
encr_sshare
,
encr_key
,
decKeyLen
,
t
,
ind
,
&
result
);
ind
,
&
result
);
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
errStatus
,
errMsg
.
data
());
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
errStatus
,
errMsg
);
if
(
result
==
2
)
{
if
(
result
==
2
)
{
throw
SGXException
(
INVALID_HEX
,
"Invalid public shares"
);
throw
SGXException
(
INVALID_HEX
,
"Invalid public shares"
);
...
@@ -310,9 +278,8 @@ verifyShares(const char *publicShares, const char *encr_sshare, const char *encr
...
@@ -310,9 +278,8 @@ verifyShares(const char *publicShares, const char *encr_sshare, const char *encr
}
}
bool
createBLSShare
(
const
string
&
blsKeyName
,
const
char
*
s_shares
,
const
char
*
encryptedKeyHex
)
{
bool
createBLSShare
(
const
string
&
blsKeyName
,
const
char
*
s_shares
,
const
char
*
encryptedKeyHex
)
{
spdlog
::
debug
(
"ENTER createBLSShare"
);
char
errMsg
[
BUF_LEN
]
;
vector
<
char
>
errMsg
(
BUF_LEN
,
0
)
;
int
errStatus
=
0
;
int
errStatus
=
0
;
uint64_t
decKeyLen
;
uint64_t
decKeyLen
;
...
@@ -326,10 +293,10 @@ bool createBLSShare(const string &blsKeyName, const char *s_shares, const char *
...
@@ -326,10 +293,10 @@ bool createBLSShare(const string &blsKeyName, const char *s_shares, const char *
uint32_t
enc_bls_len
=
0
;
uint32_t
enc_bls_len
=
0
;
sgx_status_t
status
=
trustedCreateBlsKeyAES
(
eid
,
&
errStatus
,
errMsg
,
s_shares
,
encr_key
,
decKeyLen
,
encr_bls_key
,
sgx_status_t
status
=
trustedCreateBlsKeyAES
(
eid
,
&
errStatus
,
errMsg
.
data
()
,
s_shares
,
encr_key
,
decKeyLen
,
encr_bls_key
,
&
enc_bls_len
);
&
enc_bls_len
);
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
errStatus
,
errMsg
);
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
errStatus
,
errMsg
.
data
()
);
char
hexBLSKey
[
2
*
BUF_LEN
];
char
hexBLSKey
[
2
*
BUF_LEN
];
...
@@ -342,8 +309,7 @@ bool createBLSShare(const string &blsKeyName, const char *s_shares, const char *
...
@@ -342,8 +309,7 @@ bool createBLSShare(const string &blsKeyName, const char *s_shares, const char *
}
}
vector
<
string
>
getBLSPubKey
(
const
char
*
encryptedKeyHex
)
{
vector
<
string
>
getBLSPubKey
(
const
char
*
encryptedKeyHex
)
{
char
errMsg1
[
BUF_LEN
];
vector
<
char
>
errMsg1
(
BUF_LEN
,
0
);
int
errStatus
=
0
;
int
errStatus
=
0
;
uint64_t
decKeyLen
;
uint64_t
decKeyLen
;
...
@@ -354,11 +320,11 @@ vector <string> getBLSPubKey(const char *encryptedKeyHex) {
...
@@ -354,11 +320,11 @@ vector <string> getBLSPubKey(const char *encryptedKeyHex) {
char
pubKey
[
320
];
char
pubKey
[
320
];
trustedGetBlsPubKeyAES
(
eid
,
&
errStatus
,
errMsg1
,
encrKey
,
decKeyLen
,
pubKey
);
sgx_status_t
status
=
trustedGetBlsPubKeyAES
(
eid
,
&
errStatus
,
errMsg1
.
data
(),
encrKey
,
decKeyLen
,
pubKey
);
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
errStatus
,
errMsg1
.
data
());
vector
<
string
>
pubKeyVect
=
splitString
(
pubKey
,
':'
);
vector
<
string
>
pubKeyVect
=
splitString
(
pubKey
,
':'
);
spdlog
::
debug
(
"errMsg1 is {}"
,
errMsg1
);
spdlog
::
debug
(
"pub key is "
);
spdlog
::
debug
(
"pub key is "
);
for
(
int
i
=
0
;
i
<
4
;
i
++
)
for
(
int
i
=
0
;
i
<
4
;
i
++
)
spdlog
::
debug
(
"{}"
,
pubKeyVect
.
at
(
i
));
spdlog
::
debug
(
"{}"
,
pubKeyVect
.
at
(
i
));
...
@@ -436,11 +402,8 @@ string decryptDHKey(const string &polyName, int ind) {
...
@@ -436,11 +402,8 @@ string decryptDHKey(const string &polyName, int ind) {
char
DHKey
[
ECDSA_SKEY_LEN
];
char
DHKey
[
ECDSA_SKEY_LEN
];
trustedDecryptKeyAES
(
eid
,
&
errStatus
,
errMsg1
.
data
(),
encryptedDHKey
,
dhEncLen
,
DHKey
);
sgx_status_t
status
=
trustedDecryptKeyAES
(
eid
,
&
errStatus
,
errMsg1
.
data
(),
encryptedDHKey
,
dhEncLen
,
DHKey
);
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
errStatus
,
errMsg1
.
data
());
if
(
errStatus
!=
0
)
{
throw
SGXException
(
errStatus
,
"decrypt key failed in enclave"
);
}
return
DHKey
;
return
DHKey
;
}
}
...
...
DKGCrypto.h
View file @
0684b96a
...
@@ -37,7 +37,7 @@ vector <vector<string>> get_verif_vect(const char* encryptedPolyHex, int t, int
...
@@ -37,7 +37,7 @@ vector <vector<string>> get_verif_vect(const char* encryptedPolyHex, int t, int
vector
<
string
>
splitString
(
const
char
*
coeffs
,
const
char
symbol
);
vector
<
string
>
splitString
(
const
char
*
coeffs
,
const
char
symbol
);
string
trustedG
etSecretShares
(
const
string
&
_polyName
,
const
char
*
_encryptedPolyHex
,
const
vector
<
string
>&
_publicKeys
,
int
_t
,
int
_n
);
string
g
etSecretShares
(
const
string
&
_polyName
,
const
char
*
_encryptedPolyHex
,
const
vector
<
string
>&
_publicKeys
,
int
_t
,
int
_n
);
bool
verifyShares
(
const
char
*
publicShares
,
const
char
*
encr_sshare
,
const
char
*
encryptedKeyHex
,
int
t
,
int
n
,
int
ind
);
bool
verifyShares
(
const
char
*
publicShares
,
const
char
*
encr_sshare
,
const
char
*
encryptedKeyHex
,
int
t
,
int
n
,
int
ind
);
...
...
ECDSACrypto.cpp
View file @
0684b96a
...
@@ -56,14 +56,12 @@ vector <string> genECDSAKey() {
...
@@ -56,14 +56,12 @@ vector <string> genECDSAKey() {
uint32_t
enc_len
=
0
;
uint32_t
enc_len
=
0
;
status
=
trustedGenerateEcdsaKeyAES
(
eid
,
&
errStatus
,
s
gx_status_t
s
tatus
=
trustedGenerateEcdsaKeyAES
(
eid
,
&
errStatus
,
errMsg
.
data
(),
encr_pr_key
.
data
(),
&
enc_len
,
errMsg
.
data
(),
encr_pr_key
.
data
(),
&
enc_len
,
pub_key_x
.
data
(),
pub_key_y
.
data
());
pub_key_x
.
data
(),
pub_key_y
.
data
());
if
(
status
!=
SGX_SUCCESS
||
errStatus
!=
0
)
{
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
errStatus
,
errMsg
.
data
());
spdlog
::
error
(
"RPCException thrown with status {}"
,
status
);
throw
SGXException
(
status
,
errMsg
.
data
());
}
vector
<
string
>
keys
(
3
);
vector
<
string
>
keys
(
3
);
vector
<
char
>
hexEncrKey
(
BUF_LEN
*
2
,
0
);
vector
<
char
>
hexEncrKey
(
BUF_LEN
*
2
,
0
);
...
@@ -99,18 +97,11 @@ string getECDSAPubKey(const std::string& _encryptedKeyHex) {
...
@@ -99,18 +97,11 @@ string getECDSAPubKey(const std::string& _encryptedKeyHex) {
throw
SGXException
(
INVALID_HEX
,
"Invalid encryptedKeyHex"
);
throw
SGXException
(
INVALID_HEX
,
"Invalid encryptedKeyHex"
);
}
}
status
=
trustedGetPublicEcdsaKeyAES
(
eid
,
&
errStatus
,
s
gx_status_t
s
tatus
=
trustedGetPublicEcdsaKeyAES
(
eid
,
&
errStatus
,
errMsg
.
data
(),
encrPrKey
.
data
(),
enc_len
,
pubKeyX
.
data
(),
pubKeyY
.
data
());
errMsg
.
data
(),
encrPrKey
.
data
(),
enc_len
,
pubKeyX
.
data
(),
pubKeyY
.
data
());
if
(
errStatus
!=
0
)
{
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
errStatus
,
errMsg
.
data
())
spdlog
::
error
(
"failed to get ECDSA public key {}"
,
status
);
throw
SGXException
(
-
666
,
errMsg
.
data
());
}
if
(
status
!=
SGX_SUCCESS
)
{
spdlog
::
error
(
"failed to get ECDSA public key {}"
,
status
);
throw
SGXException
(
666
,
"failed to get ECDSA public key"
);
}
string
pubKey
=
string
(
pubKeyX
.
data
())
+
string
(
pubKeyY
.
data
());
string
pubKey
=
string
(
pubKeyX
.
data
())
+
string
(
pubKeyY
.
data
());
if
(
pubKey
.
size
()
!=
128
)
{
if
(
pubKey
.
size
()
!=
128
)
{
...
@@ -182,22 +173,16 @@ vector <string> ecdsaSignHash(const std::string& encryptedKeyHex, const char *ha
...
@@ -182,22 +173,16 @@ vector <string> ecdsaSignHash(const std::string& encryptedKeyHex, const char *ha
throw
SGXException
(
INVALID_HEX
,
"Invalid encryptedKeyHex"
);
throw
SGXException
(
INVALID_HEX
,
"Invalid encryptedKeyHex"
);
}
}
status
=
trustedEcdsaSignAES
(
eid
,
&
errStatus
,
s
gx_status_t
s
tatus
=
trustedEcdsaSignAES
(
eid
,
&
errStatus
,
errMsg
.
data
(),
encryptedKey
.
data
(),
decLen
,
hashHex
,
errMsg
.
data
(),
encryptedKey
.
data
(),
decLen
,
hashHex
,
signatureR
.
data
(),
signatureR
.
data
(),
signatureS
.
data
(),
&
signatureV
,
base
);
signatureS
.
data
(),
&
signatureV
,
base
);
if
(
errStatus
!=
0
)
{
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
errStatus
,
errMsg
.
data
());
spdlog
::
error
(
"failed to sign {}"
,
errStatus
);
throw
SGXException
(
666
,
errMsg
.
data
());
}
if
(
status
!=
SGX_SUCCESS
)
{
spdlog
::
error
(
"failed to sign in enclave {}"
,
status
);
throw
SGXException
(
666
,
"failed to sign"
);
}
signatureVector
.
at
(
0
)
=
to_string
(
signatureV
);
signatureVector
.
at
(
0
)
=
to_string
(
signatureV
);
if
(
base
==
16
)
{
if
(
base
==
16
)
{
signatureVector
.
at
(
1
)
=
"0x"
+
string
(
signatureR
.
data
());
signatureVector
.
at
(
1
)
=
"0x"
+
string
(
signatureR
.
data
());
signatureVector
.
at
(
2
)
=
"0x"
+
string
(
signatureS
.
data
());
signatureVector
.
at
(
2
)
=
"0x"
+
string
(
signatureS
.
data
());
...
...
SEKManager.cpp
View file @
0684b96a
...
@@ -59,16 +59,9 @@ void create_test_key() {
...
@@ -59,16 +59,9 @@ void create_test_key() {
string
key
=
TEST_VALUE
;
string
key
=
TEST_VALUE
;
status
=
trustedEncryptKeyAES
(
eid
,
&
errStatus
,
errMsg
.
data
(),
key
.
c_str
(),
encrypted_key
,
&
enc_len
);
sgx_status_t
status
=
trustedEncryptKeyAES
(
eid
,
&
errStatus
,
errMsg
.
data
(),
key
.
c_str
(),
encrypted_key
,
&
enc_len
);
if
(
status
!=
SGX_SUCCESS
)
{
cerr
<<
"encrypt test key failed with status "
<<
status
<<
endl
;
throw
SGXException
(
status
,
errMsg
.
data
());
}
if
(
errStatus
!=
0
)
{
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
errStatus
,
errMsg
.
data
());
cerr
<<
"encrypt test key failed with status "
<<
errStatus
<<
endl
;
throw
SGXException
(
errStatus
,
errMsg
.
data
());
}
vector
<
char
>
hexEncrKey
(
2
*
enc_len
+
1
,
0
);
vector
<
char
>
hexEncrKey
(
2
*
enc_len
+
1
,
0
);
...
@@ -101,24 +94,14 @@ shared_ptr <vector<uint8_t>> check_and_set_SEK(const string &SEK) {
...
@@ -101,24 +94,14 @@ shared_ptr <vector<uint8_t>> check_and_set_SEK(const string &SEK) {
uint32_t
l
=
len
;
uint32_t
l
=
len
;
status
=
trustedSetSEK_backup
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_SEK
->
data
(),
&
l
,
SEK
.
c_str
());
s
gx_status_t
s
tatus
=
trustedSetSEK_backup
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_SEK
->
data
(),
&
l
,
SEK
.
c_str
());
if
(
status
!=
SGX_SUCCESS
)
{
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
err_status
,
errMsg
.
data
());
spdlog
::
error
(
"trustedSetSEK_backup failed with error code {}"
,
status
);
exit
(
-
1
);
}
if
(
err_status
!=
0
)
{
spdlog
::
error
(
"trustedSetSEK_backup failed with error status {}"
,
status
);
exit
(
-
1
);
}
status
=
trustedDecryptKeyAES
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_test_key
.
data
(),
len
,
decr_key
.
data
());
status
=
trustedDecryptKeyAES
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_test_key
.
data
(),
len
,
decr_key
.
data
());
if
(
status
!=
SGX_SUCCESS
||
err_status
!=
0
)
{
spdlog
::
error
(
"Failed to decrypt test key"
);
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
err_status
,
errMsg
.
data
());
spdlog
::
error
(
errMsg
.
data
());
exit
(
-
1
);
}
string
test_key
=
TEST_VALUE
;
string
test_key
=
TEST_VALUE
;
if
(
test_key
.
compare
(
decr_key
.
data
())
!=
0
)
{
if
(
test_key
.
compare
(
decr_key
.
data
())
!=
0
)
{
...
@@ -142,15 +125,10 @@ void gen_SEK() {
...
@@ -142,15 +125,10 @@ void gen_SEK() {
spdlog
::
info
(
"Generating backup key. Will be stored in backup_key.txt ... "
);
spdlog
::
info
(
"Generating backup key. Will be stored in backup_key.txt ... "
);
status
=
trustedGenerateSEK
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_SEK
.
data
(),
&
enc_len
,
SEK
);
s
gx_status_t
s
tatus
=
trustedGenerateSEK
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_SEK
.
data
(),
&
enc_len
,
SEK
);
if
(
status
!=
SGX_SUCCESS
)
{
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
err_status
,
errMsg
.
data
());
throw
SGXException
(
status
,
errMsg
.
data
());
}
if
(
err_status
!=
0
)
{
throw
SGXException
(
err_status
,
errMsg
.
data
());
}
if
(
strnlen
(
SEK
,
33
)
!=
32
)
{
if
(
strnlen
(
SEK
,
33
)
!=
32
)
{
throw
SGXException
(
-
1
,
"strnlen(SEK,33) != 32"
);
throw
SGXException
(
-
1
,
"strnlen(SEK,33) != 32"
);
...
@@ -187,7 +165,7 @@ void gen_SEK() {
...
@@ -187,7 +165,7 @@ void gen_SEK() {
create_test_key
();
create_test_key
();
}
}
void
trustedS
etSEK
(
shared_ptr
<
string
>
hex_encrypted_SEK
)
{
void
s
etSEK
(
shared_ptr
<
string
>
hex_encrypted_SEK
)
{
vector
<
char
>
errMsg
(
1024
,
0
);
vector
<
char
>
errMsg
(
1024
,
0
);
int
err_status
=
0
;
int
err_status
=
0
;
...
@@ -200,16 +178,10 @@ void trustedSetSEK(shared_ptr <string> hex_encrypted_SEK) {
...
@@ -200,16 +178,10 @@ void trustedSetSEK(shared_ptr <string> hex_encrypted_SEK) {
throw
SGXException
(
INVALID_HEX
,
"Invalid encrypted SEK Hex"
);
throw
SGXException
(
INVALID_HEX
,
"Invalid encrypted SEK Hex"
);
}
}
status
=
trustedSetSEK
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_SEK
);
sgx_status_t
status
=
trustedSetSEK
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_SEK
);
if
(
status
!=
SGX_SUCCESS
)
{
cerr
<<
"RPCException thrown"
<<
endl
;
HANDLE_TRUSTED_FUNCTION_ERROR
(
status
,
err_status
,
errMsg
.
data
());
throw
SGXException
(
status
,
errMsg
.
data
());
}
if
(
err_status
!=
0
)
{
cerr
<<
"RPCException thrown"
<<
endl
;
throw
SGXException
(
err_status
,
errMsg
.
data
());
}
}
}
#include "experimental/filesystem"
#include "experimental/filesystem"
...
@@ -274,7 +246,7 @@ void initSEK() {
...
@@ -274,7 +246,7 @@ void initSEK() {
spdlog
::
warn
(
"SEK was not created yet. Going to create SEK"
);
spdlog
::
warn
(
"SEK was not created yet. Going to create SEK"
);
gen_SEK
();
gen_SEK
();
}
else
{
}
else
{
trustedS
etSEK
(
encrypted_SEK_ptr
);
s
etSEK
(
encrypted_SEK_ptr
);
}
}
}
}
}
}
...
...
SEKManager.h
View file @
0684b96a
...
@@ -32,7 +32,7 @@
...
@@ -32,7 +32,7 @@
void
gen_SEK
();
void
gen_SEK
();
#ifdef __cplusplus
#ifdef __cplusplus
void
trustedS
etSEK
(
std
::
shared_ptr
<
std
::
string
>
hex_encr_SEK
);
void
s
etSEK
(
std
::
shared_ptr
<
std
::
string
>
hex_encr_SEK
);
#endif
#endif
#ifdef __cplusplus
#ifdef __cplusplus
...
...
SGXWalletServer.cpp
View file @
0684b96a
...
@@ -425,7 +425,7 @@ Json::Value SGXWalletServer::getSecretShareImpl(const string &_polyName, const J
...
@@ -425,7 +425,7 @@ Json::Value SGXWalletServer::getSecretShareImpl(const string &_polyName, const J
pubKeysStrs
.
push_back
(
_pubKeys
[
i
].
asString
());
pubKeysStrs
.
push_back
(
_pubKeys
[
i
].
asString
());
}
}
string
s
=
trustedG
etSecretShares
(
_polyName
,
encrPoly
->
c_str
(),
pubKeysStrs
,
_t
,
_n
);
string
s
=
g
etSecretShares
(
_polyName
,
encrPoly
->
c_str
(),
pubKeysStrs
,
_t
,
_n
);
result
[
"secretShare"
]
=
s
;
result
[
"secretShare"
]
=
s
;
result
[
"SecretShare"
]
=
s
;
result
[
"SecretShare"
]
=
s
;
}
HANDLE_SGX_EXCEPTION
(
result
)
}
HANDLE_SGX_EXCEPTION
(
result
)
...
...
ServerInit.cpp
View file @
0684b96a
...
@@ -81,7 +81,7 @@ void initEnclave(uint32_t _logLevel) {
...
@@ -81,7 +81,7 @@ void initEnclave(uint32_t _logLevel) {
spdlog
::
info
(
"SGX_DEBUG_FLAG = {}"
,
SGX_DEBUG_FLAG
);
spdlog
::
info
(
"SGX_DEBUG_FLAG = {}"
,
SGX_DEBUG_FLAG
);
status
=
sgx_create_enclave_search
(
ENCLAVE_NAME
,
SGX_DEBUG_FLAG
,
&
token
,
s
gx_status_t
s
tatus
=
sgx_create_enclave_search
(
ENCLAVE_NAME
,
SGX_DEBUG_FLAG
,
&
token
,
&
updated
,
&
eid
,
0
);
&
updated
,
&
eid
,
0
);
if
(
status
!=
SGX_SUCCESS
)
{
if
(
status
!=
SGX_SUCCESS
)
{
...
@@ -97,6 +97,7 @@ void initEnclave(uint32_t _logLevel) {
...
@@ -97,6 +97,7 @@ void initEnclave(uint32_t _logLevel) {
spdlog
::
info
(
"Enclave created and started successfully"
);
spdlog
::
info
(
"Enclave created and started successfully"
);
status
=
trustedEnclaveInit
(
eid
,
_logLevel
);
status
=
trustedEnclaveInit
(
eid
,
_logLevel
);
if
(
status
!=
SGX_SUCCESS
)
{
if
(
status
!=
SGX_SUCCESS
)
{
spdlog
::
error
(
"trustedEnclaveInit failed: {}"
,
status
);
spdlog
::
error
(
"trustedEnclaveInit failed: {}"
,
status
);
exit
(
1
);
exit
(
1
);
...
...
VERSION
View file @
0684b96a
1.58.0
1.58.1
\ No newline at end of file
\ No newline at end of file
sgxwallet.c
View file @
0684b96a
...
@@ -37,5 +37,4 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
...
@@ -37,5 +37,4 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
sgx_launch_token_t
token
=
{
0
};
sgx_launch_token_t
token
=
{
0
};
sgx_enclave_id_t
eid
;
sgx_enclave_id_t
eid
;
sgx_status_t
status
;
int
updated
;
int
updated
;
sgxwallet.h
View file @
0684b96a
...
@@ -47,7 +47,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
...
@@ -47,7 +47,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
extern
sgx_enclave_id_t
eid
;
extern
sgx_enclave_id_t
eid
;
extern
int
updated
;
extern
int
updated
;
extern
sgx_launch_token_t
token
;
extern
sgx_launch_token_t
token
;
extern
sgx_status_t
status
;
#define ENCLAVE_NAME "secure_enclave.signed.so"
#define ENCLAVE_NAME "secure_enclave.signed.so"
...
...
testw.cpp
View file @
0684b96a
...
@@ -147,9 +147,10 @@ TEST_CASE_METHOD(TestFixture, "ECDSA AES keygen and signature test", "[ecdsa-aes
...
@@ -147,9 +147,10 @@ TEST_CASE_METHOD(TestFixture, "ECDSA AES keygen and signature test", "[ecdsa-aes
hex
.
data
(),
hex
.
data
(),
signatureR
.
data
(),
signatureR
.
data
(),
signatureS
.
data
(),
&
signatureV
,
16
);
signatureS
.
data
(),
&
signatureV
,
16
);
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
errStatus
==
SGX_SUCCESS
);
}
}
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
errStatus
==
SGX_SUCCESS
);
}
}
...
@@ -691,7 +692,7 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG test", "[aes-dkg]") {
...
@@ -691,7 +692,7 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG test", "[aes-dkg]") {
}
}
TEST_CASE_METHOD
(
TestFixture
,
"AES encrypt/decrypt"
,
"[aes-encrypt-decrypt]"
)
{
TEST_CASE_METHOD
(
TestFixture
,
"AES encrypt/decrypt"
,
"[aes-encrypt-decrypt]"
)
{
int
errStatus
=
-
1
;
int
errStatus
=
0
;
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);
uint32_t
encLen
;
uint32_t
encLen
;
string
key
=
SAMPLE_AES_KEY
;
string
key
=
SAMPLE_AES_KEY
;
...
...
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