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
cb024a2c
Unverified
Commit
cb024a2c
authored
Jun 09, 2020
by
Oleh Nikolaiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-2002 fix bls key length
parent
a1dfeb15
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
60 additions
and
254 deletions
+60
-254
BLSPrivateKeyShareSGX.cpp
BLSPrivateKeyShareSGX.cpp
+2
-128
CSRManagerServer.cpp
CSRManagerServer.cpp
+1
-2
CSRManagerServer.h
CSRManagerServer.h
+0
-4
ECDSACrypto.cpp
ECDSACrypto.cpp
+0
-6
Exception.cpp
Exception.cpp
+1
-2
LevelDB.cpp
LevelDB.cpp
+7
-45
Log.cpp
Log.cpp
+0
-1
SEKManager.cpp
SEKManager.cpp
+35
-45
SGXRegistrationServer.cpp
SGXRegistrationServer.cpp
+0
-10
SGXWalletServer.cpp
SGXWalletServer.cpp
+0
-7
ServerDataChecker.cpp
ServerDataChecker.cpp
+1
-2
EnclaveConstants.h
secure_enclave/EnclaveConstants.h
+2
-0
secure_enclave.c
secure_enclave/secure_enclave.c
+11
-2
No files found.
BLSPrivateKeyShareSGX.cpp
View file @
cb024a2c
...
...
@@ -39,7 +39,6 @@
std
::
string
*
stringFromFq
(
libff
::
alt_bn128_Fq
*
_fq
)
{
mpz_t
t
;
mpz_init
(
t
);
...
...
@@ -54,13 +53,10 @@ std::string *stringFromFq(libff::alt_bn128_Fq*_fq) {
}
std
::
string
*
stringFromG1
(
libff
::
alt_bn128_G1
*
_g1
)
{
auto
sX
=
stringFromFq
(
&
_g1
->
X
);
auto
sY
=
stringFromFq
(
&
_g1
->
Y
);
auto
sZ
=
stringFromFq
(
&
_g1
->
Z
);
auto
sG1
=
new
std
::
string
(
*
sX
+
":"
+
*
sY
+
":"
+
*
sZ
);
delete
(
sX
);
...
...
@@ -68,7 +64,6 @@ std::string *stringFromG1(libff::alt_bn128_G1 *_g1) {
delete
(
sZ
);
return
sG1
;
}
...
...
@@ -105,9 +100,6 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr(
size_t
_signerIndex
)
{
shared_ptr
<
signatures
::
Bls
>
obj
;
// if (_signerIndex == 0) {
// BOOST_THROW_EXCEPTION(runtime_error("Zero signer index"));
// }
if
(
hash_byte_arr
==
nullptr
)
{
std
::
cerr
<<
"Hash is null"
<<
std
::
endl
;
BOOST_THROW_EXCEPTION
(
runtime_error
(
"Hash is null"
));
...
...
@@ -121,7 +113,6 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr(
int
errStatus
=
0
;
string
*
xStr
=
stringFromFq
(
&
(
hash_with_hint
.
first
.
X
));
if
(
xStr
==
nullptr
)
{
...
...
@@ -136,7 +127,6 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr(
BOOST_THROW_EXCEPTION
(
runtime_error
(
"Null yStr"
));
}
char
errMsg
[
BUF_LEN
];
memset
(
errMsg
,
0
,
BUF_LEN
);
...
...
@@ -152,7 +142,6 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr(
size_t
sz
=
0
;
uint8_t
encryptedKey
[
BUF_LEN
];
bool
result
=
hex2carray
(
encryptedKeyHex
->
c_str
(),
&
sz
,
encryptedKey
);
...
...
@@ -168,17 +157,13 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr(
trustedBlsSignMessage
(
eid
,
&
errStatus
,
errMsg
,
encryptedKey
,
encryptedKeyHex
->
size
()
/
2
,
xStrArg
,
yStrArg
,
signature
);
// strncpy(signature, "8175162913343900215959836578795929492705714455632345516427532159927644835012:15265825550804683171644566522808807137117748565649051208189914766494241035855", 1024);
printf
(
"sig is: %s
\n
"
,
signature
);
if
(
status
!=
SGX_SUCCESS
)
{
gmp_printf
(
"SGX enclave call
to trustedBlsSignMessage failed: 0x%04x
\n
"
,
status
);
gmp_printf
(
"SGX enclave call to trustedBlsSignMessage failed: 0x%04x
\n
"
,
status
);
BOOST_THROW_EXCEPTION
(
runtime_error
(
"SGX enclave call to trustedBlsSignMessage failed"
));
}
if
(
errStatus
!=
0
)
{
BOOST_THROW_EXCEPTION
(
runtime_error
(
"Enclave trustedBlsSignMessage failed:"
+
to_string
(
errStatus
)
+
":"
+
errMsg
));
return
nullptr
;
...
...
@@ -190,137 +175,26 @@ std::string BLSPrivateKeyShareSGX::signWithHelperSGXstr(
BOOST_THROW_EXCEPTION
(
runtime_error
(
"Signature is too short:"
+
to_string
(
sigLen
)));
}
std
::
string
hint
=
BLSutils
::
ConvertToString
(
hash_with_hint
.
first
.
Y
)
+
":"
+
hash_with_hint
.
second
;
std
::
string
sig
=
signature
;
sig
.
append
(
":"
);
sig
.
append
(
hint
);
return
sig
;
}
std
::
shared_ptr
<
BLSSigShare
>
BLSPrivateKeyShareSGX
::
signWithHelperSGX
(
std
::
shared_ptr
<
std
::
array
<
uint8_t
,
32
>>
hash_byte_arr
,
size_t
_signerIndex
)
{
/* shared_ptr<signatures::Bls> obj;
if (_signerIndex == 0) {
BOOST_THROW_EXCEPTION(runtime_error("Zero signer index"));
}
if (hash_byte_arr == nullptr) {
BOOST_THROW_EXCEPTION(runtime_error("Hash is null"));
}
obj = make_shared<signatures::Bls>(
signatures::Bls(requiredSigners, totalSigners));
std::pair<libff::alt_bn128_G1, std::string> hash_with_hint =
obj->HashtoG1withHint(hash_byte_arr);
int errStatus = 0;
string* xStr = stringFromFq(&(hash_with_hint.first.X));
if (xStr == nullptr) {
BOOST_THROW_EXCEPTION(runtime_error("Null xStr"));
}
string* yStr = stringFromFq(&(hash_with_hint.first.Y));
if (xStr == nullptr) {
BOOST_THROW_EXCEPTION(runtime_error("Null yStr"));
}
char errMsg[BUF_LEN];
memset(errMsg, 0, BUF_LEN);
char xStrArg[BUF_LEN];
char yStrArg[BUF_LEN];
char signature [BUF_LEN];
memset(xStrArg, 0, BUF_LEN);
memset(yStrArg, 0, BUF_LEN);
strncpy(xStrArg, xStr->c_str(), BUF_LEN);
strncpy(yStrArg, yStr->c_str(), BUF_LEN);
size_t sz = 0;
uint8_t encryptedKey[BUF_LEN];
bool result = hex2carray(encryptedKeyHex->c_str(), &sz, encryptedKey);
if (!result) {
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid hex encrypted key"));
}
cerr << "Key is " + *encryptedKeyHex << endl;
// sgx_status_t status =
// trustedBlsSignMessage(eid, &errStatus, errMsg, encryptedKey,
// encryptedKeyHex->size() / 2, xStrArg, yStrArg, signature);
strncpy(signature, "8175162913343900215959836578795929492705714455632345516427532159927644835012:15265825550804683171644566522808807137117748565649051208189914766494241035855", 1024);
printf("---: %s\n", signature);
// if (status != SGX_SUCCESS) {
// gmp_printf("SGX enclave call to trustedBlsSignMessage failed: 0x%04x\n", status);
// BOOST_THROW_EXCEPTION(runtime_error("SGX enclave call to trustedBlsSignMessage failed"));
// }
// if (errStatus != 0) {
// BOOST_THROW_EXCEPTION(runtime_error("Enclave trustedBlsSignMessage failed:" + to_string(errStatus) + ":" + errMsg ));
// return nullptr;
// }
int sigLen;
if ((sigLen = strnlen(signature, 10)) < 10) {
BOOST_THROW_EXCEPTION(runtime_error("Signature too short:" + to_string(sigLen)));
}
std::string hint = BLSutils::ConvertToString(hash_with_hint.first.Y) + ":" +
hash_with_hint.second;
auto sig = make_shared<string>(signature);
sig->append(":");
sig->append(hint);*/
std
::
string
signature
=
signWithHelperSGXstr
(
hash_byte_arr
,
_signerIndex
);
auto
sig
=
make_shared
<
string
>
(
signature
);
//BLSSigShare* sig_test = new BLSSigShare(sig, _signerIndex, requiredSigners, totalSigners);
//std::string hello = "hello";
//std::cout << "HINT " << *((void**)&(sig_test->hint)) << std::endl;
//std::shared_ptr<BLSSigShare> s; s.reset( sig_test );//(sig, _signerIndex, requiredSigners,
//totalSigners);
std
::
shared_ptr
<
BLSSigShare
>
s
=
std
::
make_shared
<
BLSSigShare
>
(
sig
,
_signerIndex
,
requiredSigners
,
totalSigners
);
return
s
;
}
\ No newline at end of file
}
CSRManagerServer.cpp
View file @
cb024a2c
...
...
@@ -47,7 +47,6 @@ shared_ptr<jsonrpc::HttpServer> CSRManagerServer::hs3 = nullptr;
CSRManagerServer
::
CSRManagerServer
(
AbstractServerConnector
&
connector
,
serverVersion_t
type
)
:
abstractCSRManagerServer
(
connector
,
type
)
{}
Json
::
Value
getUnsignedCSRsImpl
()
{
spdlog
::
info
(
__FUNCTION__
);
INIT_RESULT
(
result
)
...
...
@@ -137,4 +136,4 @@ int CSRManagerServer::initCSRManagerServer() {
spdlog
::
info
(
"CSR manager server started on port {}"
,
BASE_PORT
+
2
);
}
return
0
;
};
\ No newline at end of file
};
CSRManagerServer.h
View file @
cb024a2c
...
...
@@ -32,14 +32,10 @@
#include "abstractCSRManagerServer.h"
#include "LevelDB.h"
using
namespace
jsonrpc
;
using
namespace
std
;
class
CSRManagerServer
:
public
abstractCSRManagerServer
{
recursive_mutex
m
;
static
shared_ptr
<
HttpServer
>
hs3
;
...
...
ECDSACrypto.cpp
View file @
cb024a2c
...
...
@@ -50,7 +50,6 @@ string concatPubKeyWith0x(char *pub_key_x, char *pub_key_y) {
return
result
;
}
void
fillRandomBuffer
(
vector
<
unsigned
char
>
&
_buffer
)
{
ifstream
devRandom
(
"/dev/urandom"
,
ios
::
in
|
ios
::
binary
);
devRandom
.
exceptions
(
ifstream
::
failbit
|
ifstream
::
badbit
);
...
...
@@ -97,7 +96,6 @@ vector <string> genECDSAKey() {
}
string
getECDSAPubKey
(
const
char
*
_encryptedKeyHex
)
{
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);
vector
<
char
>
pubKeyX
(
BUF_LEN
,
0
);
vector
<
char
>
pubKeyY
(
BUF_LEN
,
0
);
...
...
@@ -139,7 +137,6 @@ bool verifyECDSASig(string& pubKeyStr, const char *hashHex, const char *signatur
domain_parameters_load_curve
(
curve
,
secp256k1
);
point
publicKey
=
point_init
();
mpz_t
msgMpz
;
mpz_init
(
msgMpz
);
if
(
mpz_set_str
(
msgMpz
,
hashHex
,
16
)
==
-
1
)
{
...
...
@@ -165,7 +162,6 @@ bool verifyECDSASig(string& pubKeyStr, const char *hashHex, const char *signatur
signature_free
(
sig
);
return
result
;
}
vector
<
string
>
ecdsaSignHash
(
const
char
*
encryptedKeyHex
,
const
char
*
hashHex
,
int
base
)
{
...
...
@@ -200,7 +196,6 @@ vector <string> ecdsaSignHash(const char *encryptedKeyHex, const char *hashHex,
goto
clean
;
}
if
(
status
!=
SGX_SUCCESS
)
{
spdlog
::
error
(
"failed to sign {}"
,
status
);
exception
=
make_shared
<
SGXException
>
(
666
,
"failed to sign"
);
...
...
@@ -222,7 +217,6 @@ vector <string> ecdsaSignHash(const char *encryptedKeyHex, const char *hashHex,
goto
clean
;
}
clean
:
if
(
exception
)
...
...
Exception.cpp
View file @
cb024a2c
...
...
@@ -29,7 +29,6 @@ void Exception::logNested(const std::exception &e, int level)
{
string
prefix
;
if
(
level
==
0
)
{
prefix
=
"!Exception:"
;
}
else
{
...
...
@@ -46,4 +45,4 @@ void Exception::logNested(const std::exception &e, int level)
}
catch
(
const
std
::
exception
&
e
)
{
logNested
(
e
,
level
+
1
);
}
catch
(...)
{}
};
\ No newline at end of file
};
LevelDB.cpp
View file @
cb024a2c
...
...
@@ -39,19 +39,12 @@
#include "spdlog/spdlog.h"
#include "common.h"
using
namespace
leveldb
;
static
WriteOptions
writeOptions
;
static
ReadOptions
readOptions
;
std
::
shared_ptr
<
string
>
LevelDB
::
readString
(
const
string
&
_key
)
{
std
::
lock_guard
<
std
::
recursive_mutex
>
lock
(
mutex
);
auto
result
=
std
::
make_shared
<
string
>
();
...
...
@@ -62,10 +55,7 @@ std::shared_ptr<string> LevelDB::readString(const string &_key) {
auto
status
=
db
->
Get
(
readOptions
,
_key
,
&*
result
);
spdlog
::
debug
(
"key to read from db: {}"
,
_key
);
//std::cerr << "key to read from db: " << _key << std::endl;
spdlog
::
debug
(
"key to read from db: {}"
,
_key
);
throwExceptionOnError
(
status
);
...
...
@@ -76,22 +66,17 @@ std::shared_ptr<string> LevelDB::readString(const string &_key) {
}
void
LevelDB
::
writeString
(
const
string
&
_key
,
const
string
&
_value
)
{
std
::
lock_guard
<
std
::
recursive_mutex
>
lock
(
mutex
);
auto
status
=
db
->
Put
(
writeOptions
,
Slice
(
_key
),
Slice
(
_value
));
throwExceptionOnError
(
status
);
spdlog
::
debug
(
"written key: {}"
,
_key
);
// std::cerr << "written key " << _key << std::endl;
spdlog
::
debug
(
"written key: {}"
,
_key
);
}
void
LevelDB
::
deleteDHDKGKey
(
const
string
&
_key
)
{
std
::
lock_guard
<
std
::
recursive_mutex
>
lock
(
mutex
);
string
full_key
=
"DKG_DH_KEY_"
+
_key
;
...
...
@@ -100,13 +85,10 @@ void LevelDB::deleteDHDKGKey (const string &_key) {
throwExceptionOnError
(
status
);
spdlog
::
debug
(
"key deleted: {}"
,
full_key
);
//std::cerr << "key deleted " << full_key << std::endl;
spdlog
::
debug
(
"key deleted: {}"
,
full_key
);
}
void
LevelDB
::
deleteTempNEK
(
const
string
&
_key
){
void
LevelDB
::
deleteTempNEK
(
const
string
&
_key
)
{
std
::
lock_guard
<
std
::
recursive_mutex
>
lock
(
mutex
);
string
prefix
=
_key
.
substr
(
0
,
8
);
...
...
@@ -121,24 +103,20 @@ void LevelDB::deleteTempNEK(const string &_key){
std
::
cerr
<<
"key deleted "
<<
_key
<<
std
::
endl
;
}
void
LevelDB
::
deleteKey
(
const
string
&
_key
){
void
LevelDB
::
deleteKey
(
const
string
&
_key
)
{
std
::
lock_guard
<
std
::
recursive_mutex
>
lock
(
mutex
);
auto
status
=
db
->
Delete
(
writeOptions
,
Slice
(
_key
));
throwExceptionOnError
(
status
);
spdlog
::
debug
(
"key deleted: {}"
,
_key
);
// std::cerr << "key deleted " << _key << std::endl;
spdlog
::
debug
(
"key deleted: {}"
,
_key
);
}
void
LevelDB
::
writeByteArray
(
const
char
*
_key
,
size_t
_keyLen
,
const
char
*
value
,
size_t
_valueLen
)
{
std
::
lock_guard
<
std
::
recursive_mutex
>
lock
(
mutex
);
auto
status
=
db
->
Put
(
writeOptions
,
Slice
(
_key
,
_keyLen
),
Slice
(
value
,
_valueLen
));
...
...
@@ -149,7 +127,6 @@ void LevelDB::writeByteArray(const char *_key, size_t _keyLen, const char *value
void
LevelDB
::
writeByteArray
(
string
&
_key
,
const
char
*
value
,
size_t
_valueLen
)
{
std
::
lock_guard
<
std
::
recursive_mutex
>
lock
(
mutex
);
auto
status
=
db
->
Put
(
writeOptions
,
Slice
(
_key
),
Slice
(
value
,
_valueLen
));
...
...
@@ -158,18 +135,15 @@ void LevelDB::writeByteArray(string &_key, const char *value,
}
void
LevelDB
::
throwExceptionOnError
(
Status
_status
)
{
if
(
_status
.
IsNotFound
())
return
;
if
(
!
_status
.
ok
())
{
throw
SGXException
(
COULD_NOT_ACCESS_DATABASE
,
(
"Could not access database database:"
+
_status
.
ToString
()).
c_str
());
}
}
uint64_t
LevelDB
::
visitKeys
(
LevelDB
::
KeyVisitor
*
_visitor
,
uint64_t
_maxKeysToVisit
)
{
uint64_t
readCounter
=
0
;
leveldb
::
Iterator
*
it
=
db
->
NewIterator
(
readOptions
);
...
...
@@ -194,7 +168,6 @@ std::vector<string> LevelDB::writeKeysToVector1(uint64_t _maxKeysToVisit){
for
(
it
->
SeekToFirst
();
it
->
Valid
();
it
->
Next
())
{
string
cur_key
(
it
->
key
().
data
(),
it
->
key
().
size
());
keys
.
push_back
(
cur_key
);
// keys.push_back(it->key().data());
readCounter
++
;
if
(
readCounter
>=
_maxKeysToVisit
)
{
break
;
...
...
@@ -207,25 +180,20 @@ std::vector<string> LevelDB::writeKeysToVector1(uint64_t _maxKeysToVisit){
}
void
LevelDB
::
writeDataUnique
(
const
string
&
Name
,
const
string
&
value
)
{
auto
key
=
Name
;
if
(
readString
(
Name
)
!=
nullptr
)
{
spdlog
::
debug
(
"name {}"
,
Name
,
" already exists"
);
// std::cerr << "name " << Name << " already exists" << std::endl;
throw
SGXException
(
KEY_SHARE_ALREADY_EXISTS
,
"Data with this name already exists"
);
}
writeString
(
key
,
value
);
spdlog
::
debug
(
"{}"
,
Name
,
" is written to db"
);
spdlog
::
debug
(
"{}"
,
Name
,
" is written to db"
);
}
LevelDB
::
LevelDB
(
string
&
filename
)
{
leveldb
::
Options
options
;
options
.
create_if_missing
=
true
;
...
...
@@ -236,7 +204,6 @@ LevelDB::LevelDB(string &filename) {
if
(
db
==
nullptr
)
{
throw
std
::
runtime_error
(
"Null levelDB object"
);
}
}
LevelDB
::~
LevelDB
()
{
...
...
@@ -269,16 +236,13 @@ string LevelDB::sgx_data_folder;
bool
LevelDB
::
isInited
=
false
;
void
LevelDB
::
initDataFolderAndDBs
()
{
CHECK_STATE
(
!
isInited
)
isInited
=
true
;
spdlog
::
info
(
"Initing wallet database ... "
);
char
cwd
[
PATH_MAX
];
if
(
getcwd
(
cwd
,
sizeof
(
cwd
))
==
NULL
)
{
spdlog
::
error
(
"could not get current workin directory"
);
exit
(
-
1
);
...
...
@@ -299,7 +263,6 @@ void LevelDB::initDataFolderAndDBs() {
}
}
spdlog
::
info
(
"Opening wallet databases"
);
auto
dbName
=
sgx_data_folder
+
WALLETDB_NAME
;
...
...
@@ -312,7 +275,6 @@ void LevelDB::initDataFolderAndDBs() {
csrStatusDb
=
make_shared
<
LevelDB
>
(
csr_status_dbname
);
spdlog
::
info
(
"Successfully opened databases"
);
}
const
string
&
LevelDB
::
getSgxDataFolder
()
{
...
...
Log.cpp
View file @
cb024a2c
...
...
@@ -34,7 +34,6 @@ void Log::setGlobalLogLevel(string &_s) {
}
level_enum
Log
::
logLevelFromString
(
string
&
_s
)
{
level_enum
result
=
trace
;
if
(
_s
==
"trace"
)
...
...
SEKManager.cpp
View file @
cb024a2c
...
...
@@ -59,8 +59,6 @@ void create_test_key(){
throw
SGXException
(
status
,
errMsg
.
data
())
;
}
//std::cerr << "enc len is " << enc_len << std::endl;
vector
<
char
>
hexEncrKey
(
2
*
enc_len
+
1
,
0
);
carray2Hex
(
encrypted_key
,
enc_len
,
hexEncrKey
.
data
());
...
...
@@ -77,49 +75,41 @@ void create_test_key(){
bool
check_SEK
(
std
::
string
SEK
){
std
::
shared_ptr
<
std
::
string
>
test_key_ptr
=
LevelDB
::
getLevelDb
()
->
readString
(
"TEST_KEY"
);
// if (test_key_ptr == nullptr){
// spdlog::error("empty db" );
// exit(-1);
// }
// else{
vector
<
uint8_t
>
encr_test_key
(
BUF_LEN
,
0
);
uint64_t
len
;
if
(
!
hex2carray
(
test_key_ptr
->
c_str
(),
&
len
,
encr_test_key
.
data
())){
spdlog
::
error
(
"wrong test key"
);
exit
(
-
1
);
}
vector
<
char
>
decr_key
(
1024
,
0
);
vector
<
char
>
errMsg
(
1024
,
0
);
int
err_status
=
0
;
vector
<
uint8_t
>
encr_SEK
(
1024
,
0
);
uint32_t
l
=
len
;
std
::
cerr
<<
" l is "
<<
l
<<
std
::
endl
;
status
=
trustedSetSEK_backup
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_SEK
.
data
(),
&
l
,
SEK
.
c_str
()
);
if
(
status
!=
SGX_SUCCESS
){
cerr
<<
"RPCException thrown with status "
<<
status
<<
endl
;
throw
SGXException
(
status
,
errMsg
.
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"
);
spdlog
::
error
(
errMsg
.
data
());
exit
(
-
1
);
}
std
::
string
test_key
=
TEST_VALUE
;
if
(
test_key
.
compare
(
decr_key
.
data
())
!=
0
){
std
::
cerr
<<
"decrypted key is "
<<
decr_key
.
data
()
<<
std
::
endl
;
spdlog
::
error
(
"Invalid SEK"
);
return
false
;
}
return
true
;
// }
vector
<
uint8_t
>
encr_test_key
(
BUF_LEN
,
0
);
uint64_t
len
;
if
(
!
hex2carray
(
test_key_ptr
->
c_str
(),
&
len
,
encr_test_key
.
data
())){
spdlog
::
error
(
"wrong test key"
);
exit
(
-
1
);
}
vector
<
char
>
decr_key
(
1024
,
0
);
vector
<
char
>
errMsg
(
1024
,
0
);
int
err_status
=
0
;
vector
<
uint8_t
>
encr_SEK
(
1024
,
0
);
uint32_t
l
=
len
;
status
=
trustedSetSEK_backup
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_SEK
.
data
(),
&
l
,
SEK
.
c_str
()
);
if
(
status
!=
SGX_SUCCESS
){
cerr
<<
"RPCException thrown with status "
<<
status
<<
endl
;
throw
SGXException
(
status
,
errMsg
.
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"
);
spdlog
::
error
(
errMsg
.
data
());
exit
(
-
1
);
}
std
::
string
test_key
=
TEST_VALUE
;
if
(
test_key
.
compare
(
decr_key
.
data
())
!=
0
){
std
::
cerr
<<
"decrypted key is "
<<
decr_key
.
data
()
<<
std
::
endl
;
spdlog
::
error
(
"Invalid SEK"
);
return
false
;
}
return
true
;
}
void
gen_SEK
(){
...
...
SGXRegistrationServer.cpp
View file @
cb024a2c
...
...
@@ -66,7 +66,6 @@ Json::Value signCertificateImpl(const string &_csr, bool _autoSign = false) {
result
[
"result"
]
=
false
;
try
{
string
hash
=
cryptlite
::
sha256
::
hash_hex
(
_csr
);
if
(
system
(
"ls "
CERT_DIR
"/"
CERT_CREATE_COMMAND
)
!=
0
)
{
...
...
@@ -74,7 +73,6 @@ Json::Value signCertificateImpl(const string &_csr, bool _autoSign = false) {
throw
SGXException
(
FAIL_TO_CREATE_CERTIFICATE
,
"CLIENT CERTIFICATE GENERATION FAILED"
);
}
string
csr_name
=
string
(
CERT_DIR
)
+
"/"
+
hash
+
".csr"
;
ofstream
outfile
(
csr_name
);
outfile
.
exceptions
(
std
::
ifstream
::
failbit
|
std
::
ifstream
::
badbit
);
...
...
@@ -91,21 +89,16 @@ Json::Value signCertificateImpl(const string &_csr, bool _autoSign = false) {
throw
SGXException
(
FAIL_TO_CREATE_CERTIFICATE
,
"Incorrect CSR format "
);
}
if
(
_autoSign
)
{
string
genCert
=
string
(
"cd "
)
+
CERT_DIR
+
"&& ./"
+
CERT_CREATE_COMMAND
+
" "
+
hash
;
if
(
system
(
genCert
.
c_str
())
==
0
)
{
spdlog
::
info
(
"Client cert "
+
hash
+
" generated"
);
string
db_key
=
"CSR:HASH:"
+
hash
+
"STATUS:"
;
string
status
=
"0"
;
LevelDB
::
getCsrStatusDb
()
->
writeDataUnique
(
db_key
,
status
);
}
else
{
spdlog
::
error
(
"Client cert generation failed: {} "
,
genCert
);
throw
SGXException
(
FAIL_TO_CREATE_CERTIFICATE
,
"CLIENT CERTIFICATE GENERATION FAILED"
);
}
...
...
@@ -172,7 +165,6 @@ Json::Value SGXRegistrationServer::GetCertificate(const string &hash) {
int
SGXRegistrationServer
::
initRegistrationServer
(
bool
_autoSign
)
{
httpServer
=
make_shared
<
HttpServer
>
(
BASE_PORT
+
1
);
server
=
make_shared
<
SGXRegistrationServer
>
(
*
httpServer
,
JSONRPC_SERVER_V2
,
...
...
@@ -185,7 +177,6 @@ int SGXRegistrationServer::initRegistrationServer(bool _autoSign) {
spdlog
::
info
(
"Registration server started on port {}"
,
BASE_PORT
+
1
);
}
return
0
;
}
...
...
@@ -194,4 +185,3 @@ shared_ptr<SGXRegistrationServer> SGXRegistrationServer::getServer() {
CHECK_STATE
(
server
);
return
server
;
}
SGXWalletServer.cpp
View file @
cb024a2c
...
...
@@ -170,7 +170,6 @@ SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_k
char
*
encryptedKeyShareHex
=
nullptr
;
try
{
encryptedKeyShareHex
=
encryptBLSKeyShare2Hex
(
&
errStatus
,
errMsg
,
_keyShare
.
c_str
());
if
(
encryptedKeyShareHex
==
nullptr
)
{
...
...
@@ -184,7 +183,6 @@ SGXWalletServer::importBLSKeyShareImpl(const string &_keyShare, const string &_k
result
[
"encryptedKeyShare"
]
=
string
(
encryptedKeyShareHex
);
writeKeyShare
(
_keyShareName
,
encryptedKeyShareHex
,
_index
,
n
,
t
);
}
catch
(
SGXException
&
_e
)
{
result
[
"status"
]
=
_e
.
status
;
result
[
"errorMessage"
]
=
_e
.
errString
;
...
...
@@ -304,7 +302,6 @@ Json::Value SGXWalletServer::renameECDSAKeyImpl(const string &_keyName, const st
result
[
"encryptedKey"
]
=
""
;
try
{
string
prefix
=
_tempKeyName
.
substr
(
0
,
8
);
if
(
prefix
!=
"tmp_NEK:"
)
{
throw
SGXException
(
UNKNOWN_ERROR
,
"invalid temp key name"
);
...
...
@@ -446,7 +443,6 @@ Json::Value SGXWalletServer::getVerificationVectorImpl(const string &_polyName,
result
[
"verificationVector"
][
i
][
j
]
=
currentCoef
.
at
(
j
);
}
}
}
catch
(
SGXException
&
_e
)
{
cerr
<<
" err str "
<<
_e
.
errString
<<
endl
;
result
[
"status"
]
=
_e
.
status
;
...
...
@@ -485,7 +481,6 @@ Json::Value SGXWalletServer::getSecretShareImpl(const string &_polyName, const J
string
s
=
trustedGetSecretShares
(
_polyName
,
encrPoly
->
c_str
(),
pubKeysStrs
,
_t
,
_n
);
result
[
"secretShare"
]
=
s
;
}
catch
(
SGXException
&
_e
)
{
result
[
"status"
]
=
_e
.
status
;
result
[
"errorMessage"
]
=
_e
.
errString
;
...
...
@@ -522,7 +517,6 @@ Json::Value SGXWalletServer::dkgVerificationImpl(const string &_publicShares, co
if
(
!
verifyShares
(
_publicShares
.
c_str
(),
_secretShare
.
c_str
(),
encryptedKeyHex_ptr
->
c_str
(),
_t
,
_n
,
_index
))
{
result
[
"result"
]
=
false
;
}
}
catch
(
SGXException
&
_e
)
{
result
[
"status"
]
=
_e
.
status
;
result
[
"errorMessage"
]
=
_e
.
errString
;
...
...
@@ -787,7 +781,6 @@ shared_ptr <string> SGXWalletServer::readKeyShare(const string &_keyShareName) {
}
return
keyShareStr
;
}
void
SGXWalletServer
::
writeKeyShare
(
const
string
&
_keyShareName
,
const
string
&
_value
,
int
_index
,
int
_n
,
int
_t
)
{
...
...
ServerDataChecker.cpp
View file @
cb024a2c
...
...
@@ -73,7 +73,6 @@ bool checkECDSAKeyName(const string& keyName) {
bool
checkHex
(
const
string
&
hex
,
const
uint32_t
sizeInBytes
){
if
(
hex
.
length
()
>
sizeInBytes
*
2
||
hex
.
length
()
==
0
){
spdlog
::
error
(
"key is too long or zero - "
,
hex
.
length
());
std
::
cerr
<<
"key length is "
<<
hex
.
length
()
<<
std
::
endl
;
return
false
;
}
...
...
@@ -173,4 +172,4 @@ bool check_n_t ( const int t, const int n){
}
return
true
;
}
\ No newline at end of file
}
secure_enclave/EnclaveConstants.h
View file @
cb024a2c
...
...
@@ -41,6 +41,8 @@
#define SECRET_SHARE_NUM_BYTES 96
#define BLS_KEY_LENGTH 65
#define ECDSA_SKEY_LEN 65
#define ECDSA_SKEY_BASE 16
#define ECDSA_ENCR_LEN 93
...
...
secure_enclave/secure_enclave.c
View file @
cb024a2c
...
...
@@ -1576,8 +1576,17 @@ void trustedCreateBlsKeyAES(int *errStatus, char *errString, const char *s_share
mpz_mod
(
bls_key
,
sum
,
q
);
char
key_share
[
mpz_sizeinbase
(
bls_key
,
16
)
+
2
];
mpz_get_str
(
key_share
,
16
,
bls_key
);
// char key_share[mpz_sizeinbase(bls_key, 16) + 2];
// mpz_get_str(key_share, 16, bls_key);
char
key_share
[
BLS_KEY_LENGTH
];
char
arr_skey_str
[
mpz_sizeinbase
(
bls_key
,
16
)
+
2
];
mpz_get_str
(
arr_skey_str
,
16
,
bls_key
);
int
n_zeroes
=
64
-
strlen
(
arr_skey_str
);
for
(
int
i
=
0
;
i
<
n_zeroes
;
i
++
)
{
key_share
[
i
]
=
'0'
;
}
strncpy
(
key_share
+
n_zeroes
,
arr_skey_str
,
65
-
n_zeroes
);
key_share
[
BLS_KEY_LENGTH
-
1
]
=
0
;
snprintf
(
errString
,
BUF_LEN
,
" bls private key is %s"
,
key_share
);
status
=
AES_encrypt
(
key_share
,
encr_bls_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