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
20362fb3
Unverified
Commit
20362fb3
authored
Aug 12, 2020
by
Oleh Nikolaiev
Committed by
GitHub
Aug 12, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #137 from skalenetwork/bug/SKALE-2977-sgx-crash
Bug/skale 2977 sgx crash
parents
4fcda5df
1df51891
Changes
21
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
77 additions
and
123 deletions
+77
-123
BLSCrypto.cpp
BLSCrypto.cpp
+4
-3
BLSPrivateKeyShareSGX.cpp
BLSPrivateKeyShareSGX.cpp
+4
-4
ECDSACrypto.cpp
ECDSACrypto.cpp
+26
-22
ECDSACrypto.h
ECDSACrypto.h
+2
-2
ECDSAImpl.c
ECDSAImpl.c
+1
-1
LevelDB.cpp
LevelDB.cpp
+5
-7
Makefile.am
Makefile.am
+3
-4
RPCException.cpp
RPCException.cpp
+0
-24
SGXException.h
SGXException.h
+0
-2
SGXWalletServer.cpp
SGXWalletServer.cpp
+16
-24
ServerDataChecker.cpp
ServerDataChecker.cpp
+5
-5
VERSION
VERSION
+1
-1
common.h
common.h
+1
-5
libBLS
libBLS
+1
-1
linux-sgx-driver
linux-sgx-driver
+1
-1
EnclaveCommon.cpp
secure_enclave/EnclaveCommon.cpp
+1
-1
EnclaveCommon.h
secure_enclave/EnclaveCommon.h
+0
-2
secure_enclave.c
secure_enclave/secure_enclave.c
+2
-7
secure_enclave.edl
secure_enclave/secure_enclave.edl
+1
-1
testw.cpp
testw.cpp
+3
-3
testw.h
testw.h
+0
-3
No files found.
BLSCrypto.cpp
View file @
20362fb3
...
...
@@ -181,6 +181,7 @@ bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz
if
(
yStr
==
nullptr
)
{
std
::
cerr
<<
"Null yStr"
<<
std
::
endl
;
delete
xStr
;
BOOST_THROW_EXCEPTION
(
runtime_error
(
"Null yStr"
));
}
...
...
@@ -197,6 +198,9 @@ bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz
strncpy
(
xStrArg
,
xStr
->
c_str
(),
BUF_LEN
);
strncpy
(
yStrArg
,
yStr
->
c_str
(),
BUF_LEN
);
delete
xStr
;
delete
yStr
;
size_t
sz
=
0
;
uint8_t
encryptedKey
[
BUF_LEN
];
...
...
@@ -233,9 +237,6 @@ bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz
strncpy
(
_sig
,
sig
.
c_str
(),
BUF_LEN
);
delete
xStr
;
delete
yStr
;
return
true
;
}
...
...
BLSPrivateKeyShareSGX.cpp
View file @
20362fb3
...
...
@@ -117,6 +117,7 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr(
if
(
yStr
==
nullptr
)
{
std
::
cerr
<<
"Null yStr"
<<
std
::
endl
;
delete
xStr
;
BOOST_THROW_EXCEPTION
(
runtime_error
(
"Null yStr"
));
}
...
...
@@ -133,6 +134,9 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr(
strncpy
(
xStrArg
,
xStr
->
c_str
(),
BUF_LEN
);
strncpy
(
yStrArg
,
yStr
->
c_str
(),
BUF_LEN
);
delete
xStr
;
delete
yStr
;
size_t
sz
=
0
;
uint8_t
encryptedKey
[
BUF_LEN
];
...
...
@@ -159,7 +163,6 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr(
if
(
errStatus
!=
0
)
{
BOOST_THROW_EXCEPTION
(
runtime_error
(
"Enclave trustedBlsSignMessage failed:"
+
to_string
(
errStatus
)
+
":"
+
errMsg
));
return
nullptr
;
}
int
sigLen
;
...
...
@@ -176,9 +179,6 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr(
sig
.
append
(
":"
);
sig
.
append
(
hint
);
delete
xStr
;
delete
yStr
;
return
sig
;
}
...
...
ECDSACrypto.cpp
View file @
20362fb3
...
...
@@ -85,7 +85,7 @@ vector <string> genECDSAKey() {
return
keys
;
}
string
getECDSAPubKey
(
const
char
*
_encryptedKeyHex
)
{
string
getECDSAPubKey
(
const
std
::
string
&
_encryptedKeyHex
)
{
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);
vector
<
char
>
pubKeyX
(
BUF_LEN
,
0
);
vector
<
char
>
pubKeyY
(
BUF_LEN
,
0
);
...
...
@@ -94,7 +94,7 @@ string getECDSAPubKey(const char *_encryptedKeyHex) {
int
errStatus
=
0
;
uint64_t
enc_len
=
0
;
if
(
!
hex2carray
(
_encryptedKeyHex
,
&
enc_len
,
encrPrKey
.
data
()))
{
if
(
!
hex2carray
(
_encryptedKeyHex
.
c_str
()
,
&
enc_len
,
encrPrKey
.
data
()))
{
throw
SGXException
(
INVALID_HEX
,
"Invalid encryptedKeyHex"
);
}
...
...
@@ -122,47 +122,49 @@ string getECDSAPubKey(const char *_encryptedKeyHex) {
bool
verifyECDSASig
(
string
&
pubKeyStr
,
const
char
*
hashHex
,
const
char
*
signatureR
,
const
char
*
signatureS
,
int
base
)
{
bool
result
=
false
;
signature
sig
=
signature_init
();
auto
x
=
pubKeyStr
.
substr
(
0
,
64
);
auto
y
=
pubKeyStr
.
substr
(
64
,
128
);
domain_parameters
curve
=
domain_parameters_init
();
domain_parameters_load_curve
(
curve
,
secp256k1
);
point
publicKey
=
point_init
();
mpz_t
msgMpz
;
mpz_init
(
msgMpz
);
if
(
mpz_set_str
(
msgMpz
,
hashHex
,
16
)
==
-
1
)
{
spdlog
::
error
(
"invalid message hash {}"
,
hashHex
);
goto
clean
;
mpz_clear
(
msgMpz
);
return
false
;
}
signature
sig
=
signature_init
();
if
(
signature_set_str
(
sig
,
signatureR
,
signatureS
,
base
)
!=
0
)
{
spdlog
::
error
(
"Failed to set str signature"
);
goto
clean
;
mpz_clear
(
msgMpz
);
signature_free
(
sig
);
return
false
;
}
domain_parameters
curve
=
domain_parameters_init
();
domain_parameters_load_curve
(
curve
,
secp256k1
);
point
publicKey
=
point_init
();
point_set_hex
(
publicKey
,
x
.
c_str
(),
y
.
c_str
());
if
(
!
signature_verify
(
msgMpz
,
sig
,
publicKey
,
curve
))
{
spdlog
::
error
(
"ECDSA sig not verified"
);
goto
clean
;
mpz_clear
(
msgMpz
);
signature_free
(
sig
);
domain_parameters_clear
(
curve
);
point_clear
(
publicKey
);
return
false
;
}
result
=
true
;
clean
:
mpz_clear
(
msgMpz
);
signature_free
(
sig
);
domain_parameters_clear
(
curve
);
point_clear
(
publicKey
);
signature_free
(
sig
);
return
result
;
return
true
;
}
vector
<
string
>
ecdsaSignHash
(
const
char
*
encryptedKeyHex
,
const
char
*
hashHex
,
int
base
)
{
vector
<
string
>
ecdsaSignHash
(
const
std
::
string
&
encryptedKeyHex
,
const
char
*
hashHex
,
int
base
)
{
vector
<
string
>
signatureVector
(
3
);
vector
<
char
>
errMsg
(
1024
,
0
);
...
...
@@ -175,21 +177,22 @@ vector <string> ecdsaSignHash(const char *encryptedKeyHex, const char *hashHex,
string
pubKeyStr
=
""
;
if
(
!
hex2carray
(
encryptedKeyHex
,
&
decLen
,
encryptedKey
.
data
()))
{
if
(
!
hex2carray
(
encryptedKeyHex
.
c_str
()
,
&
decLen
,
encryptedKey
.
data
()))
{
throw
SGXException
(
INVALID_HEX
,
"Invalid encryptedKeyHex"
);
}
status
=
trustedEcdsaSignAES
(
eid
,
&
errStatus
,
errMsg
.
data
(),
encryptedKey
.
data
(),
decLen
,
(
unsigned
char
*
)
hashHex
,
errMsg
.
data
(),
encryptedKey
.
data
(),
decLen
,
hashHex
,
signatureR
.
data
(),
signatureS
.
data
(),
&
signatureV
,
base
);
if
(
errStatus
!=
0
)
{
spdlog
::
error
(
"failed to sign {}"
,
errStatus
);
throw
SGXException
(
666
,
errMsg
.
data
());
}
if
(
status
!=
SGX_SUCCESS
)
{
spdlog
::
error
(
"failed to sign {}"
,
status
);
spdlog
::
error
(
"failed to sign
in enclave
{}"
,
status
);
throw
SGXException
(
666
,
"failed to sign"
);
}
...
...
@@ -213,6 +216,7 @@ vector <string> ecdsaSignHash(const char *encryptedKeyHex, const char *hashHex,
if
(
i
%
1000
==
0
)
{
if
(
!
verifyECDSASig
(
pubKeyStr
,
hashHex
,
signatureR
.
data
(),
signatureS
.
data
(),
base
))
{
spdlog
::
error
(
"failed to verify ecdsa signature"
);
throw
SGXException
(
667
,
"ECDSA did not verify"
);
}
}
...
...
ECDSACrypto.h
View file @
20362fb3
...
...
@@ -31,9 +31,9 @@ using namespace std;
vector
<
string
>
genECDSAKey
();
string
getECDSAPubKey
(
const
char
*
_encryptedKeyHex
);
string
getECDSAPubKey
(
const
std
::
string
&
_encryptedKeyHex
);
vector
<
string
>
ecdsaSignHash
(
const
char
*
encryptedKeyHex
,
const
char
*
hashHex
,
int
base
);
vector
<
string
>
ecdsaSignHash
(
const
std
::
string
&
encryptedKeyHex
,
const
char
*
hashHex
,
int
base
);
#endif //SGXD_ECDSACRYPTO_H
ECDSAImpl.c
View file @
20362fb3
...
...
@@ -2,4 +2,4 @@
#include "secure_enclave/DomainParameters.c"
#include "secure_enclave/NumberTheory.c"
#include "secure_enclave/Signature.c"
#include "secure_enclave/Curves.c"
\ No newline at end of file
#include "secure_enclave/Curves.c"
LevelDB.cpp
View file @
20362fb3
...
...
@@ -21,13 +21,11 @@
@date 2019
*/
#include <stdexcept>
#include <memory>
#include <string>
#include <iostream>
#include "leveldb/db.h"
#include "sgxwallet_common.h"
...
...
@@ -53,9 +51,9 @@ std::shared_ptr<string> LevelDB::readString(const string &_key) {
throw
SGXException
(
NULL_DATABASE
,
"Null db"
);
}
spdlog
::
debug
(
"key to read from db: {}"
,
_key
);
spdlog
::
debug
(
"key to read from db: {}"
,
_key
);
auto
status
=
db
->
Get
(
readOptions
,
_key
,
&*
result
);
auto
status
=
db
->
Get
(
readOptions
,
_key
,
result
.
get
()
);
throwExceptionOnError
(
status
);
...
...
@@ -73,7 +71,7 @@ void LevelDB::writeString(const string &_key, const string &_value) {
throwExceptionOnError
(
status
);
spdlog
::
debug
(
"written key: {}"
,
_key
);
spdlog
::
debug
(
"written key: {}"
,
_key
);
}
...
...
@@ -101,7 +99,7 @@ void LevelDB::deleteTempNEK(const string &_key) {
throwExceptionOnError
(
status
);
s
td
::
cerr
<<
"key deleted "
<<
_key
<<
std
::
endl
;
s
pdlog
::
debug
(
"key deleted: {}"
,
_key
)
;
}
void
LevelDB
::
deleteKey
(
const
string
&
_key
)
{
...
...
@@ -111,7 +109,7 @@ void LevelDB::deleteKey(const string &_key) {
throwExceptionOnError
(
status
);
spdlog
::
debug
(
"key deleted: {}"
,
_key
);
spdlog
::
debug
(
"key deleted: {}"
,
_key
);
}
...
...
Makefile.am
View file @
20362fb3
...
...
@@ -54,8 +54,7 @@ AM_CPPFLAGS += -DSGXWALLET_VERSION="$(WALLET_VERSION)" -Wall -DSKALE_SGX=1 -DBIN
## Additional targets to remove with 'make clean'. You must list
## any edger8r generated files here.
CLEANFILES
=
$(COMMON_ENCLAVE_SRC)
secure_enclave.edl
\
secure_enclave.signed.so
CLEANFILES
=
$(COMMON_ENCLAVE_SRC)
secure_enclave.edl secure_enclave.signed.so
## The build target
...
...
@@ -67,7 +66,7 @@ bin_PROGRAMS = sgxwallet testw cert_util
## have to be explicitly listed.
COMMON_SRC
=
InvalidStateException.cpp Exception.cpp InvalidArgumentException.cpp Log.cpp
\
SGXWalletServer.cpp SGXRegistrationServer.cpp CSRManagerServer.cpp
RPCException.cpp
BLSCrypto.cpp
\
SGXWalletServer.cpp SGXRegistrationServer.cpp CSRManagerServer.cpp BLSCrypto.cpp
\
ECDSACrypto.cpp
\
DKGCrypto.cpp ServerInit.cpp BLSPrivateKeyShareSGX.cpp LevelDB.cpp ServerDataChecker.cpp SEKManager.cpp
\
third_party/intel/sgx_stub.c third_party/intel/sgx_detect_linux.c third_party/intel/create_enclave.c third_party/intel/oc_alloc.c
\
...
...
@@ -113,7 +112,7 @@ nodist_testw_SOURCES=${nodist_sgxwallet_SOURCES}
EXTRA_testw_DEPENDENCIES
=
${
EXTRA_sgxwallet_DEPENDENCIES
}
testw_LDADD
=
${
sgxwallet_LDADD
}
cert_util_SOURCES
=
InvalidStateException.cpp Exception.cpp InvalidArgumentException.cpp Log.cpp cert_util.cpp stubclient.cpp
RPCException.cpp
LevelDB.cpp SGXRegistrationServer.cpp CSRManagerServer.cpp
cert_util_SOURCES
=
InvalidStateException.cpp Exception.cpp InvalidArgumentException.cpp Log.cpp cert_util.cpp stubclient.cpp LevelDB.cpp SGXRegistrationServer.cpp CSRManagerServer.cpp
cert_util_LDADD
=
-LlibBLS
/deps/deps_inst/x86_or_x64/lib
-Lleveldb
/build
-LlibBLS
/build
\
-LlibBLS
/build/libff/libff
\
-l
:libbls.a
-l
:libleveldb.a
\
...
...
RPCException.cpp
deleted
100644 → 0
View file @
4fcda5df
/*
Copyright (C) 2019-Present SKALE Labs
This file is part of sgxwallet.
sgxwallet is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
sgxwallet is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with sgxwallet. If not, see <https://www.gnu.org/licenses/>.
@file RPCException.cpp
@author Stan Kladko
@date 2019
*/
#include "SGXException.h"
SGXException.h
View file @
20362fb3
...
...
@@ -24,7 +24,6 @@
#ifndef SGXD_RPCEXCEPTION_H
#define SGXD_RPCEXCEPTION_H
#include <string>
#include <exception>
...
...
@@ -39,5 +38,4 @@ public:
};
#endif //SGXD_RPCEXCEPTION_H
SGXWalletServer.cpp
View file @
20362fb3
...
...
@@ -236,7 +236,7 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin
exception_ptr
p
=
current_exception
();
printf
(
"Exception %s
\n
"
,
p
.
__cxa_exception_type
()
->
name
());
result
[
"status"
]
=
-
1
;
result
[
"errorMessage"
]
=
"Read key share has thrown exception
:
"
;
result
[
"errorMessage"
]
=
"Read key share has thrown exception"
;
return
result
;
}
...
...
@@ -252,10 +252,10 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin
return
result
;
}
auto
it
=
s
td
::
find
(
signature
.
begin
(),
signature
.
end
(),
'\0'
);
auto
it
=
s
ignature
.
find
(
'\0'
);
result
[
"status"
]
=
0
;
result
[
"errorMessage"
]
=
""
;
result
[
"signatureShare"
]
=
std
::
string
(
signature
.
begin
(),
it
);
result
[
"signatureShare"
]
=
std
::
string
(
signature
.
begin
(),
signature
.
begin
()
+
it
);
return
result
;
}
...
...
@@ -332,16 +332,16 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_
result
[
"signature_r"
]
=
""
;
result
[
"signature_s"
]
=
""
;
vector
<
string
>
signatureVector
(
3
);
vector
<
string
>
signatureVector
(
3
);
try
{
string
hashTmp
=
_messageHash
;
if
(
hashTmp
[
0
]
==
'0'
&&
(
hashTmp
[
1
]
==
'x'
||
hashTmp
[
1
]
==
'X'
))
{
hashTmp
.
erase
(
hashTmp
.
begin
(),
hashTmp
.
begin
()
+
2
);
}
while
(
hashTmp
[
0
]
==
'0'
)
{
hashTmp
.
erase
(
hashTmp
.
begin
(),
hashTmp
.
begin
()
+
1
);
}
//
while (hashTmp[0] == '0') {
//
hashTmp.erase(hashTmp.begin(), hashTmp.begin() + 1);
//
}
if
(
!
checkECDSAKeyName
(
_keyName
))
{
throw
SGXException
(
INVALID_ECDSA_KEY_NAME
,
"Invalid ECDSA key name"
);
...
...
@@ -353,9 +353,9 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_
throw
SGXException
(
-
22
,
"Invalid 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
,
hashTmp
.
c_str
(),
_base
);
if
(
signatureVector
.
size
()
!=
3
)
{
throw
SGXException
(
INVALID_ECSDA_SIGNATURE
,
"Invalid ecdsa signature"
);
}
...
...
@@ -546,11 +546,11 @@ SGXWalletServer::createBLSPrivateKeyImpl(const string &_blsKeyName, const string
if
(
!
check_n_t
(
_t
,
_n
))
{
throw
SGXException
(
INVALID_DKG_PARAMS
,
"Invalid DKG parameters: n or t "
);
}
vector
<
string
>
sshares_vect
;
vector
<
string
>
sshares_vect
;
spdlog
::
debug
(
"secret shares from json are - {}"
,
_secretShare
);
shared_ptr
<
string
>
encryptedKeyHex_ptr
=
readFromDb
(
_ethKeyName
);
shared_ptr
<
string
>
encryptedKeyHex_ptr
=
readFromDb
(
_ethKeyName
);
bool
res
=
CreateBLSShare
(
_blsKeyName
,
_secretShare
.
c_str
(),
encryptedKeyHex_ptr
->
c_str
());
if
(
res
)
{
...
...
@@ -579,11 +579,11 @@ Json::Value SGXWalletServer::getBLSPublicKeyShareImpl(const string &_blsKeyName)
if
(
!
checkName
(
_blsKeyName
,
"BLS_KEY"
))
{
throw
SGXException
(
INVALID_BLS_NAME
,
"Invalid BLSKey name"
);
}
shared_ptr
<
string
>
encryptedKeyHex_ptr
=
readFromDb
(
_blsKeyName
);
shared_ptr
<
string
>
encryptedKeyHex_ptr
=
readFromDb
(
_blsKeyName
);
spdlog
::
debug
(
"encr_bls_key_share is {}"
,
*
encryptedKeyHex_ptr
);
spdlog
::
debug
(
"length is {}"
,
encryptedKeyHex_ptr
->
length
());
vector
<
string
>
public_key_vect
=
GetBLSPubKey
(
encryptedKeyHex_ptr
->
c_str
());
vector
<
string
>
public_key_vect
=
GetBLSPubKey
(
encryptedKeyHex_ptr
->
c_str
());
for
(
uint8_t
i
=
0
;
i
<
4
;
i
++
)
{
result
[
"blsPublicKeyShare"
][
i
]
=
public_key_vect
.
at
(
i
);
}
...
...
@@ -776,17 +776,9 @@ void SGXWalletServer::writeKeyShare(const string &_keyShareName, const string &_
LevelDB
::
getLevelDb
()
->
writeString
(
_keyShareName
,
_value
);
}
void
SGXWalletServer
::
writeDataToDB
(
const
string
&
Name
,
const
string
&
value
)
{
Json
::
Value
val
;
Json
::
FastWriter
writer
;
val
[
"value"
]
=
value
;
writer
.
write
(
val
);
auto
key
=
Name
;
if
(
LevelDB
::
getLevelDb
()
->
readString
(
Name
)
!=
nullptr
)
{
spdlog
::
info
(
"name {}"
,
Name
,
" already exists"
);
void
SGXWalletServer
::
writeDataToDB
(
const
string
&
key
,
const
string
&
value
)
{
if
(
LevelDB
::
getLevelDb
()
->
readString
(
key
)
!=
nullptr
)
{
spdlog
::
info
(
"name {}"
,
key
,
" already exists"
);
throw
SGXException
(
KEY_SHARE_ALREADY_EXISTS
,
"Key share already exists"
);
}
...
...
ServerDataChecker.cpp
View file @
20362fb3
...
...
@@ -79,7 +79,7 @@ bool checkHex(const string& hex, const uint32_t sizeInBytes){
mpz_t
num
;
mpz_init
(
num
);
if
(
mpz_set_str
(
num
,
hex
.
c_str
(),
16
)
==
-
1
)
{
if
(
mpz_set_str
(
num
,
hex
.
c_str
(),
16
)
==
-
1
)
{
spdlog
::
error
(
"key is not hex {}"
,
hex
);
mpz_clear
(
num
);
return
false
;
...
...
@@ -128,9 +128,9 @@ bool checkName (const string& Name, const string& prefix){
mpz_t
num
;
mpz_init
(
num
);
if
(
mpz_set_str
(
num
,
parts
.
at
(
2
).
c_str
(),
10
)
==
-
1
){
if
(
mpz_set_str
(
num
,
parts
.
at
(
2
).
c_str
(),
10
)
==
-
1
)
{
mpz_clear
(
num
);
spdlog
::
info
(
"parts.at(2)
not num
"
);
spdlog
::
info
(
"parts.at(2)
is not decimal number
"
);
return
false
;
}
mpz_clear
(
num
);
...
...
@@ -138,7 +138,7 @@ bool checkName (const string& Name, const string& prefix){
if
(
mpz_set_str
(
num
,
parts
.
at
(
4
).
c_str
(),
10
)
==
-
1
){
mpz_clear
(
num
);
spdlog
::
info
(
"parts.at(4)
not num
"
);
spdlog
::
info
(
"parts.at(4)
is not decimal number
"
);
return
false
;
}
mpz_clear
(
num
);
...
...
@@ -146,7 +146,7 @@ bool checkName (const string& Name, const string& prefix){
if
(
mpz_set_str
(
num
,
parts
.
at
(
6
).
c_str
(),
10
)
==
-
1
){
mpz_clear
(
num
);
spdlog
::
info
(
"parts.at(6)
not num
"
);
spdlog
::
info
(
"parts.at(6)
is not decimal number
"
);
return
false
;
}
mpz_clear
(
num
);
...
...
VERSION
View file @
20362fb3
1.56.0
1.56.0
\ No newline at end of file
common.h
View file @
20362fb3
...
...
@@ -32,13 +32,10 @@ using namespace std;
#include <map>
#include <memory>
#include <gmp.h>
#include "secure_enclave/Verify.h"
#include "InvalidStateException.h"
#define SAFE_FREE(__POINTER__) {if (__POINTER__) {free(__POINTER__); __POINTER__ = NULL;}}
inline
std
::
string
className
(
const
std
::
string
&
prettyFunction
)
{
...
...
@@ -51,12 +48,11 @@ inline std::string className(const std::string &prettyFunction) {
return
prettyFunction
.
substr
(
begin
,
end
);
}
#define __CLASS_NAME__ className( __PRETTY_FUNCTION__ )
#define CHECK_STATE(_EXPRESSION_) \
if (!(_EXPRESSION_)) { \
auto __msg__ = st
ring("State check failed::") + #_EXPRESSION_ + " " + string(__FILE__) + ":" +
to_string(__LINE__); \
auto __msg__ = st
d::string("State check failed::") + #_EXPRESSION_ + " " + std::string(__FILE__) + ":" + std::
to_string(__LINE__); \
throw InvalidStateException(__msg__, __CLASS_NAME__);}
...
...
libBLS
@
6c863ecc
Subproject commit
78ea56c3b5251e9d840ef65705bb2c5f8f193662
Subproject commit
6c863ecc15eb5580e469f6b7f59817fdd08da1d1
linux-sgx-driver
@
b0a445ba
Subproject commit
95eaa6f6693cd86c35e10a22b4f8e483373c987c
Subproject commit
b0a445ba09e96e1d0507487e5c496485a9cf3742
secure_enclave/EnclaveCommon.cpp
View file @
20362fb3
...
...
@@ -188,7 +188,7 @@ bool enclave_sign(const char *_keyString, const char *_hashXString, const char *
}
void
carray2Hex
(
const
unsigned
char
*
d
,
int
_len
,
char
*
_hexArray
)
{
void
carray2Hex
(
const
unsigned
char
*
d
,
int
_len
,
char
*
_hexArray
)
{
char
hexval
[
16
]
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
};
...
...
secure_enclave/EnclaveCommon.h
View file @
20362fb3
...
...
@@ -48,8 +48,6 @@ EXTERNC bool hex2carray2(const char * _hex, uint64_t *_bin_len,
uint8_t
*
_bin
,
const
int
_max_length
);
EXTERNC
void
enclave_init
();
void
get_global_random
(
unsigned
char
*
_randBuff
,
uint64_t
size
);
EXTERNC
uint8_t
*
getThreadLocalDecryptedDkgPoly
();
...
...
secure_enclave/secure_enclave.c
View file @
20362fb3
...
...
@@ -459,7 +459,7 @@ void trustedEncryptKey(int *errStatus, char *errString, const char *key,
uint64_t
decryptedKeyLen
=
strnlen
(
decryptedKey
,
MAX_KEY_LENGTH
);
if
(
decryptedKeyLen
==
MAX_KEY_LENGTH
)
{
if
(
decryptedKeyLen
==
MAX_KEY_LENGTH
)
{
snprintf
(
errString
,
BUF_LEN
,
"Decrypted key is not null terminated"
);
LOG_ERROR
(
errString
);
goto
clean
;
...
...
@@ -1116,15 +1116,11 @@ void trustedSetSEK_backup(int *errStatus, char *errString,
snprintf
(
errString
,
BUF_LEN
,
"seal SEK failed with status %d"
,
status
);
*
errStatus
=
status
;
LOG_ERROR
(
errString
);
goto
clean
;
}
*
enc_len
=
sealedLen
;
*
errStatus
=
0
;
clean:
;
}
void
trustedGenerateEcdsaKeyAES
(
int
*
errStatus
,
char
*
errString
,
...
...
@@ -1291,9 +1287,8 @@ void trustedGetPublicEcdsaKeyAES(int *errStatus, char *errString,
static
uint64_t
sigCounter
=
0
;
void
trustedEcdsaSignAES
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encryptedPrivateKey
,
uint32_t
enc_len
,
unsigned
char
*
hash
,
char
*
sigR
,
char
*
sigS
,
uint8_t
*
sig_v
,
int
base
)
{
const
char
*
hash
,
char
*
sigR
,
char
*
sigS
,
uint8_t
*
sig_v
,
int
base
)
{
LOG_DEBUG
(
__FUNCTION__
);
*
errString
=
0
;
...
...
secure_enclave/secure_enclave.edl
View file @
20362fb3
...
...
@@ -187,7 +187,7 @@ enclave {
[out, count = SMALL_BUF_SIZE] char* err_string,
[in, count = SMALL_BUF_SIZE] uint8_t* encrypted_key,
uint32_t enc_len,
[in, string]
unsigned
char* hash,
[in, string]
const
char* hash,
[out, count = SMALL_BUF_SIZE] char* sig_r,
[out, count = SMALL_BUF_SIZE] char* sig_s,
[out] uint8_t* sig_v,
...
...
testw.cpp
View file @
20362fb3
...
...
@@ -84,7 +84,7 @@ public:
TestFixtureHTTPS
()
{
TestUtils
::
resetDB
();
setOptions
(
L_INFO
,
true
,
true
);
initAll
(
0
,
false
,
true
);
initAll
(
L_INFO
,
false
,
true
);
}
~
TestFixtureHTTPS
()
{
...
...
@@ -146,7 +146,7 @@ TEST_CASE_METHOD(TestFixture, "ECDSA AES keygen and signature test", "[ecdsa-aes
for
(
int
i
=
0
;
i
<
50
;
i
++
)
{
status
=
trustedEcdsaSignAES
(
eid
,
&
errStatus
,
errMsg
.
data
(),
encrPrivKey
.
data
(),
encLen
,
(
unsigned
char
*
)
hex
.
data
(),
hex
.
data
(),
signatureR
.
data
(),
signatureS
.
data
(),
&
signatureV
,
16
);
}
...
...
@@ -889,7 +889,7 @@ TEST_CASE_METHOD(TestFixture, "AES == NOT AES", "[aes-not-aes]") {
uint8_t
signatureVAES
=
0
;
status
=
trustedEcdsaSignAES
(
eid
,
&
errStatusAES
,
errMsgAES
.
data
(),
encrPrivKeyAES
.
data
(),
enc_lenAES
,
(
unsigned
char
*
)
hex
.
data
(),
hex
.
data
(),
signatureRAES
.
data
(),
signatureSAES
.
data
(),
&
signatureVAES
,
16
);
REQUIRE
(
status
==
SGX_SUCCESS
);
...
...
testw.h
View file @
20362fb3
...
...
@@ -35,15 +35,12 @@
#define RPC_ENDPOINT "http://localhost:1029"
#define SAMPLE_PUBLIC_KEY_B "c0152c48bf640449236036075d65898fded1e242c00acb45519ad5f788ea7cbf9a5df1559e7fc87932eee5478b1b9023de19df654395574a690843988c3ff475"
#define SAMPLE_DKG_PUB_KEY_1 "505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e2"
#define SAMPLE_DKG_PUB_KEY_2 "378b3e6fdfe2633256ae1662fcd23466d02ead907b5d4366136341cea5e46f5a7bb67d897d6e35f619810238aa143c416f61c640ed214eb9c67a34c4a31b7d25"
//openssl req -new -newkey rsa:2048 -nodes -keyout yourdomain.key -out yourdomain.csr^
#define SAMPLE_CSR_FILE_NAME "samples/yourdomain.csr"
#define ECDSA_KEY_NAME_SIZE 68
#endif //SGXWALLET_TESTW_H
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