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
83d6a406
Unverified
Commit
83d6a406
authored
Dec 03, 2020
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-3636-sgx-server-anti-dos-protections
parent
dcbec9b5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
8 deletions
+61
-8
Log.h
Log.h
+10
-0
SGXWalletServer.cpp
SGXWalletServer.cpp
+39
-8
SGXWalletServer.hpp
SGXWalletServer.hpp
+11
-0
common.h
common.h
+1
-0
No files found.
Log.h
View file @
83d6a406
...
...
@@ -74,6 +74,16 @@ public:
static
void
handleSGXException
(
Json
::
Value
&
_result
,
SGXException
&
_e
);
};
#define COUNT_STATISTICS \
static uint64_t __COUNT__ = 0; \
__COUNT__++; \
if (__COUNT__ % 1000 == 0) { \
spdlog::info(string(__FUNCTION__) + " processed " + to_string(__COUNT__) + " requests"); \
}
#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"] = \
"Server error. Please see server log.";
...
...
SGXWalletServer.cpp
View file @
83d6a406
...
...
@@ -227,9 +227,32 @@ SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_k
RETURN_SUCCESS
(
result
);
}
map
<
string
,
string
>
SGXWalletServer
::
blsRequests
;
recursive_mutex
SGXWalletServer
::
blsRequestsLock
;
map
<
string
,
string
>
SGXWalletServer
::
ecdsaRequests
;
recursive_mutex
SGXWalletServer
::
ecdsaRequestsLock
;
void
SGXWalletServer
::
checkForDuplicate
(
map
<
string
,
string
>
&
_map
,
recursive_mutex
&
_m
,
const
string
&
_key
,
const
string
&
_value
)
{
LOCK
(
_m
);
if
(
_map
.
count
(
_key
)
&&
_map
.
at
(
_key
)
==
_value
)
{
sleep
(
100
);
spdlog
::
warn
(
string
(
"Received an identical request from the client:"
)
+
__FUNCTION__
);
}
_map
[
_key
]
=
_value
;
}
Json
::
Value
SGXWalletServer
::
blsSignMessageHashImpl
(
const
string
&
_keyShareName
,
const
string
&
_messageHash
,
int
t
,
int
n
)
{
spdlog
::
trace
(
"Entering {}"
,
__FUNCTION__
);
COUNT_STATISTICS
INIT_RESULT
(
result
)
result
[
"status"
]
=
-
1
;
...
...
@@ -240,6 +263,10 @@ SGXWalletServer::blsSignMessageHashImpl(const string &_keyShareName, const strin
shared_ptr
<
string
>
value
=
nullptr
;
checkForDuplicate
(
blsRequests
,
blsRequestsLock
,
_keyShareName
,
_messageHash
);
try
{
if
(
!
checkName
(
_keyShareName
,
"BLS_KEY"
))
{
throw
SGXException
(
INVALID_POLY_NAME
,
"Invalid BLSKey name"
);
...
...
@@ -343,6 +370,9 @@ Json::Value SGXWalletServer::ecdsaSignMessageHashImpl(int _base, const string &_
vector
<
string
>
signatureVector
(
3
);
checkForDuplicate
(
ecdsaRequests
,
ecdsaRequestsLock
,
_keyName
,
_messageHash
);
try
{
string
hashTmp
=
_messageHash
;
if
(
hashTmp
[
0
]
==
'0'
&&
(
hashTmp
[
1
]
==
'x'
||
hashTmp
[
1
]
==
'X'
))
{
...
...
@@ -666,10 +696,10 @@ Json::Value SGXWalletServer::complaintResponseImpl(const string &_polyName, int
}
for
(
int
i
=
0
;
i
<
_n
;
i
++
)
{
string
name
=
_polyName
+
"_"
+
to_string
(
i
)
+
":"
;
LevelDB
::
getLevelDb
()
->
deleteDHDKGKey
(
name
);
string
shareG2_name
=
"shareG2_"
+
_polyName
+
"_"
+
to_string
(
i
)
+
":"
;
LevelDB
::
getLevelDb
()
->
deleteKey
(
shareG2_name
);
string
name
=
_polyName
+
"_"
+
to_string
(
i
)
+
":"
;
LevelDB
::
getLevelDb
()
->
deleteDHDKGKey
(
name
);
string
shareG2_name
=
"shareG2_"
+
_polyName
+
"_"
+
to_string
(
i
)
+
":"
;
LevelDB
::
getLevelDb
()
->
deleteKey
(
shareG2_name
);
}
LevelDB
::
getLevelDb
()
->
deleteKey
(
_polyName
);
...
...
@@ -744,7 +774,8 @@ Json::Value SGXWalletServer::deleteBlsKeyImpl(const string &name) {
RETURN_SUCCESS
(
result
)
}
Json
::
Value
SGXWalletServer
::
getSecretShareV2Impl
(
const
string
&
_polyName
,
const
Json
::
Value
&
_pubKeys
,
int
_t
,
int
_n
)
{
Json
::
Value
SGXWalletServer
::
getSecretShareV2Impl
(
const
string
&
_polyName
,
const
Json
::
Value
&
_pubKeys
,
int
_t
,
int
_n
)
{
spdlog
::
info
(
"Entering {}"
,
__FUNCTION__
);
INIT_RESULT
(
result
);
result
[
"secretShare"
]
=
""
;
...
...
@@ -785,7 +816,7 @@ Json::Value SGXWalletServer::getSecretShareV2Impl(const string &_polyName, const
}
Json
::
Value
SGXWalletServer
::
dkgVerificationV2Impl
(
const
string
&
_publicShares
,
const
string
&
_ethKeyName
,
const
string
&
_secretShare
,
int
_t
,
int
_n
,
int
_index
)
{
const
string
&
_secretShare
,
int
_t
,
int
_n
,
int
_index
)
{
spdlog
::
info
(
"Entering {}"
,
__FUNCTION__
);
INIT_RESULT
(
result
)
result
[
"result"
]
=
false
;
...
...
@@ -903,8 +934,8 @@ Json::Value SGXWalletServer::getSecretShareV2(const string &_polyName, const Jso
Json
::
Value
SGXWalletServer
::
dkgVerificationV2
(
const
string
&
_publicShares
,
const
string
&
ethKeyName
,
const
string
&
SecretShare
,
int
t
,
int
n
,
int
index
)
{
int
t
,
int
n
,
int
index
)
{
return
dkgVerificationV2Impl
(
_publicShares
,
ethKeyName
,
SecretShare
,
t
,
n
,
index
);
}
...
...
SGXWalletServer.hpp
View file @
83d6a406
...
...
@@ -38,6 +38,17 @@ using namespace std;
class
SGXWalletServer
:
public
AbstractStubServer
{
static
shared_ptr
<
SGXWalletServer
>
server
;
static
shared_ptr
<
HttpServer
>
httpServer
;
static
map
<
string
,
string
>
blsRequests
;
static
recursive_mutex
blsRequestsLock
;
static
map
<
string
,
string
>
ecdsaRequests
;
static
recursive_mutex
ecdsaRequestsLock
;
static
void
checkForDuplicate
(
map
<
string
,
string
>
&
_map
,
recursive_mutex
&
_m
,
const
string
&
_key
,
const
string
&
_value
);
public
:
static
const
char
*
getVersion
()
{
return
TOSTRING
(
SGXWALLET_VERSION
);
...
...
common.h
View file @
83d6a406
...
...
@@ -107,6 +107,7 @@ extern uint64_t initTime;
#define ENCLAVE_RESTART_PERIOD_S 60 * 10
#endif
#define LOCK(__X__) std::lock_guard<std::recursive_mutex> __LOCK__(__X__);
#define READ_LOCK(__X__) std::shared_lock<std::shared_timed_mutex> __LOCK__(__X__);
#define WRITE_LOCK(__X__) std::unique_lock<std::shared_timed_mutex> __LOCK__(__X__);
...
...
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