Unverified Commit 8a524e3a authored by kladko's avatar kladko

SKALE-3228

parent 0ee1256d
...@@ -71,28 +71,34 @@ void create_test_key() { ...@@ -71,28 +71,34 @@ void create_test_key() {
shared_ptr <vector<uint8_t>> check_and_set_SEK(const string &SEK) { shared_ptr <vector<uint8_t>> check_and_set_SEK(const string &SEK) {
shared_ptr <string> test_key_ptr = LevelDB::getLevelDb()->readString("TEST_KEY");
vector <uint8_t> encr_test_key(BUF_LEN, 0);
uint64_t len;
if (!hex2carray(test_key_ptr->c_str(), &len, encr_test_key.data(), vector<char> decr_key(BUF_LEN, 0);
BUF_LEN)) { vector<char> errMsg(BUF_LEN, 0);
spdlog::error("Corrupt test key is LevelDB");
exit(-1);
}
vector<char> decr_key(1024, 0);
vector<char> errMsg(1024, 0);
int err_status = 0; int err_status = 0;
auto encrypted_SEK = make_shared < vector < uint8_t >> (1024, 0); auto encrypted_SEK = make_shared < vector < uint8_t >> (BUF_LEN, 0);
uint32_t l = len; uint32_t l = 0;
sgx_status_t status = trustedSetSEK_backup(eid, &err_status, errMsg.data(), encrypted_SEK->data(), &l, SEK.c_str()); sgx_status_t status = trustedSetSEK_backup(eid, &err_status, errMsg.data(), encrypted_SEK->data(), &l, SEK.c_str());
encrypted_SEK->resize(l);
HANDLE_TRUSTED_FUNCTION_ERROR(status, err_status, errMsg.data()); HANDLE_TRUSTED_FUNCTION_ERROR(status, err_status, errMsg.data());
shared_ptr <string> test_key_ptr = LevelDB::getLevelDb()->readString("TEST_KEY");
vector <uint8_t> encr_test_key(BUF_LEN, 0);
uint64_t len = 0;
if (!hex2carray(test_key_ptr->c_str(), &len, encr_test_key.data(),
BUF_LEN)) {
spdlog::error("Corrupt test key is LevelDB");
exit(-1);
}
status = trustedDecryptKeyAES(eid, &err_status, errMsg.data(), encr_test_key.data(), len, decr_key.data()); status = trustedDecryptKeyAES(eid, &err_status, errMsg.data(), encr_test_key.data(), len, decr_key.data());
HANDLE_TRUSTED_FUNCTION_ERROR(status, err_status, errMsg.data()); HANDLE_TRUSTED_FUNCTION_ERROR(status, err_status, errMsg.data());
...@@ -106,8 +112,6 @@ shared_ptr <vector<uint8_t>> check_and_set_SEK(const string &SEK) { ...@@ -106,8 +112,6 @@ shared_ptr <vector<uint8_t>> check_and_set_SEK(const string &SEK) {
exit(-1); exit(-1);
} }
encrypted_SEK->resize(l);
return encrypted_SEK; return encrypted_SEK;
} }
...@@ -181,6 +185,7 @@ void setSEK(shared_ptr <string> hex_encrypted_SEK) { ...@@ -181,6 +185,7 @@ void setSEK(shared_ptr <string> hex_encrypted_SEK) {
HANDLE_TRUSTED_FUNCTION_ERROR(status, err_status, errMsg.data()); HANDLE_TRUSTED_FUNCTION_ERROR(status, err_status, errMsg.data());
} }
#include "experimental/filesystem" #include "experimental/filesystem"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment