mirror of
https://gitee.com/openharmony/distributeddatamgr_relational_store
synced 2024-11-23 07:00:41 +00:00
!1687 LoadSecretKeyFromDisk函数 bug 修复
Merge pull request !1687 from zhaojinghui/changjiaxing
This commit is contained in:
commit
f41f60126b
@ -481,11 +481,21 @@ bool RdbSecurityManager::LoadSecretKeyFromDisk(const std::string &keyPath, RdbSe
|
||||
}
|
||||
}
|
||||
|
||||
auto size = content.size();
|
||||
auto offset = 0;
|
||||
auto iter = content.begin();
|
||||
if (offset + 1 >= size) {
|
||||
return false;
|
||||
}
|
||||
keyData.distributed = *iter;
|
||||
iter++;
|
||||
offset++;
|
||||
|
||||
std::vector<uint8_t> createTime;
|
||||
if (offset + sizeof(time_t) / sizeof(uint8_t) >= size) {
|
||||
return false;
|
||||
}
|
||||
offset += sizeof(time_t) / sizeof(uint8_t);
|
||||
for (int i = 0; i < static_cast<int>(sizeof(time_t) / sizeof(uint8_t)); i++) {
|
||||
createTime.push_back(*iter);
|
||||
iter++;
|
||||
@ -495,6 +505,10 @@ bool RdbSecurityManager::LoadSecretKeyFromDisk(const std::string &keyPath, RdbSe
|
||||
keyData.timeValue = *reinterpret_cast<time_t *>(&createTime[0]);
|
||||
}
|
||||
|
||||
if (offset + AEAD_LEN >= size) {
|
||||
return false;
|
||||
}
|
||||
offset = size;
|
||||
keyData.secretKey.insert(keyData.secretKey.end(), iter, content.end());
|
||||
|
||||
return true;
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include "common.h"
|
||||
#include "rdb_errno.h"
|
||||
#include "file_ex.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::NativeRdb;
|
||||
@ -99,4 +100,24 @@ HWTEST_F(RdbSecurityManagerTest, LockUnlock, TestSize.Level1)
|
||||
ASSERT_TRUE(afterUnlock);
|
||||
thread.join();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: LoadSecretKeyFromDiskTest
|
||||
* @tc.desc: test load secret key from disk test
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RdbSecurityManagerTest, LoadSecretKeyFromDiskTest, TestSize.Level1)
|
||||
{
|
||||
std::string name = "secret_key_load_test";
|
||||
auto keyPath = RDB_TEST_PATH + "key/" + name + ".pub_key";
|
||||
RdbSecurityManager::KeyFiles keyFile(keyPath);
|
||||
|
||||
const std::string file = keyFile.GetKeyFile(RdbSecurityManager::KeyFileType::PUB_KEY_FILE);
|
||||
std::vector<char> content = { 'a' };
|
||||
bool ret = OHOS::SaveBufferToFile(file, content);
|
||||
ASSERT_TRUE(ret);
|
||||
RdbPassword pwd =
|
||||
RdbSecurityManager::GetInstance().GetRdbPassword(keyPath, RdbSecurityManager::KeyFileType::PUB_KEY_FILE);
|
||||
ASSERT_EQ(pwd.GetSize(), 0);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user