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
5969ed05
Unverified
Commit
5969ed05
authored
Feb 11, 2020
by
svetaro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-2003 Add test key
parent
7da4edf6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
36 deletions
+15
-36
SEKManager.cpp
SEKManager.cpp
+13
-35
secure_enclave.c
secure_enclave/secure_enclave.c
+2
-1
No files found.
SEKManager.cpp
View file @
5969ed05
...
@@ -53,7 +53,7 @@ void create_test_key(){
...
@@ -53,7 +53,7 @@ void create_test_key(){
std
::
string
key
=
TEST_VALUE
;
std
::
string
key
=
TEST_VALUE
;
status
=
encrypt_key_aes
(
eid
,
&
errStatus
,
errMsg
.
data
(),
key
.
c_str
(),
encrypted_key
,
&
enc_len
);
status
=
encrypt_key_aes
(
eid
,
&
errStatus
,
errMsg
.
data
(),
key
.
c_str
(),
encrypted_key
,
&
enc_len
);
if
(
status
!=
0
){
if
(
status
!=
0
){
std
::
cerr
<<
"encrypt test key failed with status "
<<
status
<<
std
::
endl
;
std
::
cerr
<<
"encrypt test key failed with status "
<<
status
<<
std
::
endl
;
throw
RPCException
(
status
,
errMsg
.
data
())
;
throw
RPCException
(
status
,
errMsg
.
data
())
;
...
@@ -65,10 +65,11 @@ void create_test_key(){
...
@@ -65,10 +65,11 @@ void create_test_key(){
carray2Hex
(
encrypted_key
,
enc_len
,
hexEncrKey
.
data
());
carray2Hex
(
encrypted_key
,
enc_len
,
hexEncrKey
.
data
());
// std::cerr << "encr test key is " << std::endl;
uint64_t
test_len
;
// for (int i = 0; i < 2 * enc_len + 1; i++)
vector
<
uint8_t
>
test_encr_key
(
1024
,
0
);
// std::cerr << (int)hexEncrKey[i] << " ";
if
(
!
hex2carray
(
hexEncrKey
.
data
(),
&
test_len
,
test_encr_key
.
data
())){
std
::
cerr
<<
"wrong encrypted test key"
<<
std
::
endl
;
}
LevelDB
::
getLevelDb
()
->
writeDataUnique
(
"TEST_KEY"
,
hexEncrKey
.
data
());
LevelDB
::
getLevelDb
()
->
writeDataUnique
(
"TEST_KEY"
,
hexEncrKey
.
data
());
...
@@ -87,10 +88,6 @@ bool check_SEK(std::string SEK){
...
@@ -87,10 +88,6 @@ bool check_SEK(std::string SEK){
spdlog
::
error
(
"wrong test key"
);
spdlog
::
error
(
"wrong test key"
);
exit
(
-
1
);
exit
(
-
1
);
}
}
// std::cerr << "encr test key is " << std::endl;
// for ( int i = 0; i < BUF_LEN; i++ ){
// std::cerr << (int)encr_test_key[i] << " ";
// }
vector
<
char
>
decr_key
(
1024
,
0
);
vector
<
char
>
decr_key
(
1024
,
0
);
vector
<
char
>
errMsg
(
1024
,
0
);
vector
<
char
>
errMsg
(
1024
,
0
);
...
@@ -101,31 +98,21 @@ bool check_SEK(std::string SEK){
...
@@ -101,31 +98,21 @@ bool check_SEK(std::string SEK){
uint32_t
l
=
len
;
uint32_t
l
=
len
;
std
::
cerr
<<
" l is "
<<
l
<<
std
::
endl
;
std
::
cerr
<<
" l is "
<<
l
<<
std
::
endl
;
status
=
set_SEK_backup
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_SEK
.
data
(),
(
uint32_t
*
)
&
len
,
SEK
.
c_str
()
);
status
=
set_SEK_backup
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_SEK
.
data
(),
&
l
,
SEK
.
c_str
()
);
if
(
status
!=
SGX_SUCCESS
){
if
(
status
!=
SGX_SUCCESS
){
cerr
<<
"RPCException thrown with status "
<<
status
<<
endl
;
cerr
<<
"RPCException thrown with status "
<<
status
<<
endl
;
throw
RPCException
(
status
,
errMsg
.
data
());
throw
RPCException
(
status
,
errMsg
.
data
());
}
}
// std::cerr << "encr SEK is " << std::endl;
// for ( int i = 0; i < BUF_LEN; i++ ){
// std::cerr << (int)encr_SEK[i] << " ";
// }
status
=
decrypt_key_aes
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_test_key
.
data
(),
len
,
decr_key
.
data
());
status
=
decrypt_key_aes
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_test_key
.
data
(),
len
,
decr_key
.
data
());
if
(
status
!=
0
){
if
(
status
!=
SGX_SUCCESS
||
err_status
!=
0
){
spdlog
::
error
(
"failed to decrypt test key"
);
spdlog
::
error
(
"failed to decrypt test key"
);
spdlog
::
error
(
errMsg
.
data
());
exit
(
-
1
);
exit
(
-
1
);
}
}
// std::cerr << "decr test key is " << std::endl;
// for ( int i = 0; i < BUF_LEN; i++ ){
// std::cerr << (int)decr_key[i] << " ";
// }
std
::
string
test_key
=
TEST_VALUE
;
std
::
string
test_key
=
TEST_VALUE
;
std
::
cerr
<<
"test key is "
<<
test_key
<<
std
::
endl
;
if
(
test_key
.
compare
(
decr_key
.
data
())
!=
0
){
if
(
test_key
.
compare
(
decr_key
.
data
())
!=
0
){
std
::
cerr
<<
"decrypted key is "
<<
decr_key
.
data
()
<<
std
::
endl
;
std
::
cerr
<<
"decrypted key is "
<<
decr_key
.
data
()
<<
std
::
endl
;
spdlog
::
error
(
"Invalid SEK"
);
spdlog
::
error
(
"Invalid SEK"
);
...
@@ -187,19 +174,12 @@ void set_SEK(std::shared_ptr<std::string> hex_encr_SEK){
...
@@ -187,19 +174,12 @@ void set_SEK(std::shared_ptr<std::string> hex_encr_SEK){
throw
RPCException
(
INVALID_HEX
,
"Invalid encrypted SEK Hex"
);
throw
RPCException
(
INVALID_HEX
,
"Invalid encrypted SEK Hex"
);
}
}
// std::cerr << "encr hex key is " << *hex_encr_SEK << std::endl;
std
::
cerr
<<
"len is "
<<
len
<<
std
::
endl
;
status
=
set_SEK
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_SEK
,
len
);
status
=
set_SEK
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_SEK
,
len
);
if
(
status
!=
SGX_SUCCESS
||
err_status
!=
0
){
if
(
status
!=
SGX_SUCCESS
||
err_status
!=
0
){
cerr
<<
"RPCException thrown"
<<
endl
;
cerr
<<
"RPCException thrown"
<<
endl
;
throw
RPCException
(
status
,
errMsg
.
data
())
;
throw
RPCException
(
status
,
errMsg
.
data
())
;
}
}
std
::
cerr
<<
"status is "
<<
status
<<
std
::
endl
;
// std::cerr << " aes key is " << errMsg.data() << std::endl;
// for ( uint32_t i = 0; i < 1024; i++)
// printf("%d ", errMsg[i]);
}
}
void
enter_SEK
(){
void
enter_SEK
(){
...
@@ -217,13 +197,13 @@ void enter_SEK(){
...
@@ -217,13 +197,13 @@ void enter_SEK(){
std
::
string
SEK
;
std
::
string
SEK
;
std
::
cout
<<
"ENTER BACKUP KEY"
<<
std
::
endl
;
std
::
cout
<<
"ENTER BACKUP KEY"
<<
std
::
endl
;
std
::
cin
>>
SEK
;
std
::
cin
>>
SEK
;
while
(
!
checkHex
(
SEK
,
16
)
/*|| !check_SEK(SEK)*/
){
while
(
!
checkHex
(
SEK
,
16
)
||
!
check_SEK
(
SEK
)
){
std
::
cout
<<
"KEY IS INVALID.TRY ONCE MORE"
<<
std
::
endl
;
std
::
cout
<<
"KEY IS INVALID.TRY ONCE MORE"
<<
std
::
endl
;
SEK
=
""
;
SEK
=
""
;
std
::
cin
>>
SEK
;
std
::
cin
>>
SEK
;
}
}
if
(
DEBUG_PRINT
)
//
if (DEBUG_PRINT)
std
::
cerr
<<
"your key is "
<<
SEK
<<
std
::
endl
;
//
std::cerr << "your key is " << SEK << std::endl;
status
=
set_SEK_backup
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_SEK
.
data
(),
&
enc_len
,
SEK
.
c_str
()
);
status
=
set_SEK_backup
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_SEK
.
data
(),
&
enc_len
,
SEK
.
c_str
()
);
...
@@ -253,6 +233,4 @@ void init_SEK(){
...
@@ -253,6 +233,4 @@ void init_SEK(){
}
}
}
}
//a002e7ca685d46a32771d16fe2518e58
\ No newline at end of file
//1e6a4c0bcc1ddad3508b7182a0d893d5
secure_enclave/secure_enclave.c
View file @
5969ed05
...
@@ -1272,6 +1272,7 @@ void decrypt_key_aes(int *err_status, char *err_string, uint8_t *encrypted_key,
...
@@ -1272,6 +1272,7 @@ void decrypt_key_aes(int *err_status, char *err_string, uint8_t *encrypted_key,
//snprintf(err_string, BUF_LEN, "decr key is %s", key);
//snprintf(err_string, BUF_LEN, "decr key is %s", key);
if
(
decLen
>
MAX_KEY_LENGTH
)
{
if
(
decLen
>
MAX_KEY_LENGTH
)
{
*
err_status
=
1
;
snprintf
(
err_string
,
BUF_LEN
,
"wrong decLen"
);
//"decLen != MAX_KEY_LENGTH");
snprintf
(
err_string
,
BUF_LEN
,
"wrong decLen"
);
//"decLen != MAX_KEY_LENGTH");
return
;
return
;
}
}
...
@@ -1288,7 +1289,7 @@ void decrypt_key_aes(int *err_status, char *err_string, uint8_t *encrypted_key,
...
@@ -1288,7 +1289,7 @@ void decrypt_key_aes(int *err_status, char *err_string, uint8_t *encrypted_key,
}
}
*
err_status
=
0
;
*
err_status
=
0
;
return
;
memcpy
(
err_string
,
AES_key
,
1024
)
;
}
}
...
...
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