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
93b8db50
Unverified
Commit
93b8db50
authored
Nov 13, 2019
by
svetaro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-1779 Add key name correctness check
parent
d3d3523c
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
41 additions
and
18 deletions
+41
-18
ECDSACrypto.cpp
ECDSACrypto.cpp
+3
-1
SGXWalletServer.cpp
SGXWalletServer.cpp
+27
-8
SGXWalletServer.hpp
SGXWalletServer.hpp
+2
-2
abstractstubserver.h
abstractstubserver.h
+4
-4
spec.json
spec.json
+1
-1
stubclient.h
stubclient.h
+2
-2
testw.cpp
testw.cpp
+2
-0
No files found.
ECDSACrypto.cpp
View file @
93b8db50
...
...
@@ -10,6 +10,8 @@
#include <gmp.h>
#include <random>
static
std
::
default_random_engine
rand_gen
((
unsigned
int
)
time
(
0
));
std
::
vector
<
std
::
string
>
gen_ecdsa_key
(){
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
int
err_status
=
0
;
...
...
@@ -28,7 +30,7 @@ std::vector<std::string> gen_ecdsa_key(){
//std::cerr << "in ECDSACrypto encr key x " << keys.at(0) << std::endl;
//std::cerr << "in ECDSACrypto encr_len %d " << enc_len << std::endl;
std
::
default_random_engine
rand_gen
((
unsigned
int
)
time
(
0
));
unsigned
long
seed
=
rand_gen
();
std
::
cerr
<<
"seed is "
<<
seed
<<
std
::
endl
;
gmp_randstate_t
state
;
...
...
SGXWalletServer.cpp
View file @
93b8db50
...
...
@@ -29,6 +29,19 @@
#include "SGXWalletServer.h"
#include "SGXWalletServer.hpp"
#include <algorithm>
bool
isStringDec
(
std
::
string
&
str
){
auto
res
=
std
::
find_if_not
(
str
.
begin
(),
str
.
end
(),
[](
char
c
)
->
bool
{
return
std
::
isdigit
(
c
);
});
return
!
str
.
empty
()
&&
res
==
str
.
end
();
// bool res =tr
// for (int i = 0; i < str.length; i++){
// }
}
SGXWalletServer
::
SGXWalletServer
(
AbstractServerConnector
&
connector
,
serverVersion_t
type
)
:
AbstractStubServer
(
connector
,
type
)
{}
...
...
@@ -179,7 +192,7 @@ Json::Value generateECDSAKeyImpl() {
return
result
;
}
Json
::
Value
renameE
S
DSAKeyImpl
(
const
std
::
string
&
KeyName
,
const
std
::
string
&
tempKeyName
){
Json
::
Value
renameE
C
DSAKeyImpl
(
const
std
::
string
&
KeyName
,
const
std
::
string
&
tempKeyName
){
Json
::
Value
result
;
result
[
"status"
]
=
0
;
result
[
"errorMessage"
]
=
""
;
...
...
@@ -189,14 +202,19 @@ Json::Value renameESDSAKeyImpl(const std::string& KeyName, const std::string& te
std
::
string
prefix
=
tempKeyName
.
substr
(
0
,
8
);
if
(
prefix
!=
"tmp_NEK:"
)
{
throw
RPCException
(
UNKNOWN_ERROR
,
""
);
throw
RPCException
(
UNKNOWN_ERROR
,
"
wrong temp key name
"
);
}
prefix
=
KeyName
.
substr
(
0
,
5
);
prefix
=
KeyName
.
substr
(
0
,
12
);
if
(
prefix
!=
"NEK_NODE_ID:"
)
{
throw
RPCException
(
UNKNOWN_ERROR
,
""
);
throw
RPCException
(
UNKNOWN_ERROR
,
"wrong key name"
);
}
std
::
string
postfix
=
KeyName
.
substr
(
12
,
KeyName
.
length
());
if
(
!
isStringDec
(
postfix
)){
throw
RPCException
(
UNKNOWN_ERROR
,
"wrong key name"
);
}
std
::
shared_ptr
<
std
::
string
>
key_ptr
=
readFromDb
(
tempKeyName
);
std
::
cerr
<<
"new key name is "
<<
KeyName
<<
std
::
endl
;
writeDataToDB
(
KeyName
,
*
key_ptr
);
levelDb
->
deleteTempNEK
(
tempKeyName
);
...
...
@@ -417,7 +435,7 @@ Json::Value CreateBLSPrivateKeyImpl(const std::string & BLSKeyName, const std::s
//std::cerr << sshares << std::endl;
//std::cerr << "length is " << strlen(sshares);
std
::
shared_ptr
<
std
::
string
>
encryptedKeyHex_ptr
=
readFromDb
(
EthKeyName
);
//readECDSAKey(EthKeyName);
std
::
shared_ptr
<
std
::
string
>
encryptedKeyHex_ptr
=
readFromDb
(
EthKeyName
);
bool
res
=
CreateBLSShare
(
BLSKeyName
,
sshares
,
encryptedKeyHex_ptr
->
c_str
());
if
(
res
){
...
...
@@ -523,9 +541,9 @@ Json::Value SGXWalletServer::generateECDSAKey() {
return
generateECDSAKeyImpl
();
}
Json
::
Value
SGXWalletServer
::
renameE
S
DSAKey
(
const
std
::
string
&
KeyName
,
const
std
::
string
&
tempKeyName
){
Json
::
Value
SGXWalletServer
::
renameE
C
DSAKey
(
const
std
::
string
&
KeyName
,
const
std
::
string
&
tempKeyName
){
lock_guard
<
recursive_mutex
>
lock
(
m
);
return
renameE
S
DSAKeyImpl
(
KeyName
,
tempKeyName
);
return
renameE
C
DSAKeyImpl
(
KeyName
,
tempKeyName
);
}
Json
::
Value
SGXWalletServer
::
getPublicECDSAKey
(
const
std
::
string
&
_keyName
)
{
...
...
@@ -668,3 +686,4 @@ void writeDataToDB(const string & Name, const string &value) {
levelDb
->
writeString
(
key
,
value
);
}
SGXWalletServer.hpp
View file @
93b8db50
...
...
@@ -25,7 +25,7 @@ public:
virtual
Json
::
Value
importECDSAKey
(
const
std
::
string
&
key
,
const
std
::
string
&
keyName
);
virtual
Json
::
Value
generateECDSAKey
();
virtual
Json
::
Value
renameE
S
DSAKey
(
const
std
::
string
&
KeyName
,
const
std
::
string
&
tempKeyName
);
virtual
Json
::
Value
renameE
C
DSAKey
(
const
std
::
string
&
KeyName
,
const
std
::
string
&
tempKeyName
);
virtual
Json
::
Value
ecdsaSignMessageHash
(
int
base
,
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
);
virtual
Json
::
Value
getPublicECDSAKey
(
const
std
::
string
&
keyName
);
...
...
@@ -56,7 +56,7 @@ Json::Value blsSignMessageHashImpl(const std::string& keyShareName, const std::s
Json
::
Value
importECDSAKeyImpl
(
const
std
::
string
&
key
,
const
std
::
string
&
keyName
);
Json
::
Value
generateECDSAKeyImpl
();
Json
::
Value
renameE
S
DSAKeyImpl
(
const
std
::
string
&
KeyName
,
const
std
::
string
&
tempKeyName
);
Json
::
Value
renameE
C
DSAKeyImpl
(
const
std
::
string
&
KeyName
,
const
std
::
string
&
tempKeyName
);
Json
::
Value
ecdsaSignMessageHashImpl
(
int
base
,
const
std
::
string
&
keyName
,
const
std
::
string
&
messageHash
);
Json
::
Value
getPublicECDSAKeyImpl
(
const
std
::
string
&
keyName
);
...
...
abstractstubserver.h
View file @
93b8db50
...
...
@@ -17,7 +17,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"importECDSAKey"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"key"
,
jsonrpc
::
JSON_STRING
,
"keyName"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
importECDSAKeyI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"generateECDSAKey"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
NULL
),
&
AbstractStubServer
::
generateECDSAKeyI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"renameE
SDSAKey"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"KeyName"
,
jsonrpc
::
JSON_STRING
,
"tempKeyName"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
renameES
DSAKeyI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"renameE
CDSAKey"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"KeyName"
,
jsonrpc
::
JSON_STRING
,
"tempKeyName"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
renameEC
DSAKeyI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"getPublicECDSAKey"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"keyName"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
getPublicECDSAKeyI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"ecdsaSignMessageHash"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"base"
,
jsonrpc
::
JSON_INTEGER
,
"keyName"
,
jsonrpc
::
JSON_STRING
,
"messageHash"
,
jsonrpc
::
JSON_STRING
,
NULL
),
&
AbstractStubServer
::
ecdsaSignMessageHashI
);
...
...
@@ -47,9 +47,9 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
(
void
)
request
;
response
=
this
->
generateECDSAKey
();
}
inline
virtual
void
renameE
S
DSAKeyI
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
inline
virtual
void
renameE
C
DSAKeyI
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
{
response
=
this
->
renameE
S
DSAKey
(
request
[
"KeyName"
].
asString
(),
request
[
"tempKeyName"
].
asString
());
response
=
this
->
renameE
C
DSAKey
(
request
[
"KeyName"
].
asString
(),
request
[
"tempKeyName"
].
asString
());
}
inline
virtual
void
getPublicECDSAKeyI
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
{
...
...
@@ -88,7 +88,7 @@ class AbstractStubServer : public jsonrpc::AbstractServer<AbstractStubServer>
virtual
Json
::
Value
blsSignMessageHash
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
,
int
n
,
int
signerIndex
,
int
t
)
=
0
;
virtual
Json
::
Value
importECDSAKey
(
const
std
::
string
&
key
,
const
std
::
string
&
keyName
)
=
0
;
virtual
Json
::
Value
generateECDSAKey
()
=
0
;
virtual
Json
::
Value
renameE
S
DSAKey
(
const
std
::
string
&
KeyName
,
const
std
::
string
&
tempKeyName
)
=
0
;
virtual
Json
::
Value
renameE
C
DSAKey
(
const
std
::
string
&
KeyName
,
const
std
::
string
&
tempKeyName
)
=
0
;
virtual
Json
::
Value
getPublicECDSAKey
(
const
std
::
string
&
keyName
)
=
0
;
virtual
Json
::
Value
ecdsaSignMessageHash
(
int
base
,
const
std
::
string
&
keyName
,
const
std
::
string
&
messageHash
)
=
0
;
...
...
spec.json
View file @
93b8db50
...
...
@@ -56,7 +56,7 @@
},
{
"name"
:
"renameE
S
DSAKey"
,
"name"
:
"renameE
C
DSAKey"
,
"params"
:
{
"tempKeyName"
:
"key1"
,
"KeyName"
:
"key2"
...
...
stubclient.h
View file @
93b8db50
...
...
@@ -61,12 +61,12 @@ class StubClient : public jsonrpc::Client
else
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
}
Json
::
Value
renameE
S
DSAKey
(
const
std
::
string
&
KeyName
,
const
std
::
string
&
tempKeyName
)
throw
(
jsonrpc
::
JsonRpcException
)
Json
::
Value
renameE
C
DSAKey
(
const
std
::
string
&
KeyName
,
const
std
::
string
&
tempKeyName
)
throw
(
jsonrpc
::
JsonRpcException
)
{
Json
::
Value
p
;
p
[
"KeyName"
]
=
KeyName
;
p
[
"tempKeyName"
]
=
tempKeyName
;
Json
::
Value
result
=
this
->
CallMethod
(
"renameE
S
DSAKey"
,
p
);
Json
::
Value
result
=
this
->
CallMethod
(
"renameE
C
DSAKey"
,
p
);
if
(
result
.
isObject
())
return
result
;
else
...
...
testw.cpp
View file @
93b8db50
...
...
@@ -722,6 +722,8 @@ TEST_CASE("API test", "[api_test]") {
try
{
//levelDb->deleteOlegKey("0");
//levelDb->deleteOlegKey("1");
levelDb
->
deleteDHDKGKey
(
"p2_0:"
);
levelDb
->
deleteDHDKGKey
(
"p2_1:"
);
//cout << c.generateECDSAKey() << endl;
...
...
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