!293 PIN离线防暴力破解相关接口上库

Merge pull request !293 from 韩震/master
This commit is contained in:
openharmony_ci 2022-06-30 09:54:09 +00:00 committed by Gitee
commit f25bbad701
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 20 additions and 11 deletions

View File

@ -78,6 +78,7 @@ struct SetPropertyRequest {
struct AuthResult {
std::vector<uint8_t> token {};
std::vector<uint8_t> rootSecret {};
uint32_t remainTimes {0};
uint32_t freezingTime {0};
};

View File

@ -49,6 +49,7 @@ struct AddCredInfo {
struct RequestResult {
uint64_t credentialId;
std::vector<uint8_t> rootSecret;
};
} // namespace UserAuth
} // namespace UserIAM

View File

@ -114,6 +114,7 @@ struct AddCredInfo {
struct RequestResult {
uint64_t credentialId {0};
std::vector<uint8_t> rootSecret;
};
} // namespace UserIDM
} // namespace UserIAM

View File

@ -97,7 +97,7 @@ bool EnrollmentImpl::Start(std::vector<std::shared_ptr<ScheduleNode>> &scheduleL
bool EnrollmentImpl::Update(const std::vector<uint8_t> &scheduleResult, uint64_t &credentialId,
std::shared_ptr<CredentialInfo> &info)
{
using HdiCredentialInfo = OHOS::HDI::UserAuth::V1_0::CredentialInfo;
using HdiEnrollResultInfo = OHOS::HDI::UserAuth::V1_0::EnrollResultInfo;
auto hdi = HdiWrapper::GetHdiInstance();
if (!hdi) {
@ -105,18 +105,19 @@ bool EnrollmentImpl::Update(const std::vector<uint8_t> &scheduleResult, uint64_t
return false;
}
HdiCredentialInfo oldInfo = {};
auto result = hdi->UpdateEnrollmentResult(userId_, scheduleResult, credentialId, oldInfo);
HdiEnrollResultInfo resultInfo = {};
auto result = hdi->UpdateEnrollmentResult(userId_, scheduleResult, resultInfo);
if (result != HDF_SUCCESS) {
IAM_LOGE("hdi UpdateEnrollmentResult failed, err is %{public}d, userId is %{public}d", result, userId_);
return false;
}
IAM_LOGI("hdi UpdateEnrollmentResult success, userId is %{public}d", userId_);
auto infoRet = MakeShared<CredentialInfoImpl>(userId_, oldInfo);
auto infoRet = MakeShared<CredentialInfoImpl>(userId_, resultInfo.oldInfo);
if (infoRet == nullptr) {
IAM_LOGE("bad alloc");
return false;
}
credentialId = resultInfo.credentialId;
info = infoRet;
return true;

View File

@ -40,6 +40,7 @@ public:
using AuthSolution = OHOS::HDI::UserAuth::V1_0::AuthSolution;
using AuthResultInfo = OHOS::HDI::UserAuth::V1_0::AuthResultInfo;
using IdentifyResultInfo = OHOS::HDI::UserAuth::V1_0::IdentifyResultInfo;
using EnrollResultInfo = OHOS::HDI::UserAuth::V1_0::EnrollResultInfo;
class Holder;
MOCK_METHOD0(Init, int32_t());
@ -51,8 +52,8 @@ public:
MOCK_METHOD1(CloseSession, int32_t(int32_t userId));
MOCK_METHOD4(BeginEnrollment,
int32_t(int32_t userId, const std::vector<uint8_t> &authToken, const EnrollParam &param, ScheduleInfo &info));
MOCK_METHOD4(UpdateEnrollmentResult, int32_t(int32_t userId, const std::vector<uint8_t> &scheduleResult,
uint64_t &credentialId, CredentialInfo &oldInfo));
MOCK_METHOD3(UpdateEnrollmentResult, int32_t(int32_t userId, const std::vector<uint8_t> &scheduleResult,
EnrollResultInfo &info));
MOCK_METHOD1(CancelEnrollment, int32_t(int32_t userId));
MOCK_METHOD4(DeleteCredential,
int32_t(int32_t userId, uint64_t credentialId, const std::vector<uint8_t> &authToken, CredentialInfo &info));

View File

@ -80,7 +80,7 @@ HWTEST_F(EnrollmentImplTest, EnrollmentUpdateHdiError, TestSize.Level1)
constexpr int32_t userId = 0x11;
auto mock = MockIUserAuthInterface::Holder::GetInstance().Get();
EXPECT_CALL(*mock, UpdateEnrollmentResult(userId, _, _, _)).WillRepeatedly(Return(1));
EXPECT_CALL(*mock, UpdateEnrollmentResult(userId, _, _)).WillRepeatedly(Return(1));
auto authentication = std::make_shared<EnrollmentImpl>(userId, FACE);
std::vector<uint8_t> scheduleResult = {1, 2, 3};
@ -92,13 +92,14 @@ HWTEST_F(EnrollmentImplTest, EnrollmentUpdateHdiError, TestSize.Level1)
HWTEST_F(EnrollmentImplTest, EnrollmentUpdateHdiSuccessful, TestSize.Level1)
{
using HdiCredentialInfo = OHOS::HDI::UserAuth::V1_0::CredentialInfo;
using HdiEnrollResultInfo = OHOS::HDI::UserAuth::V1_0::EnrollResultInfo;
constexpr int32_t userId = 0x11;
constexpr uint64_t credentialIdRet = 0x12;
std::vector<uint8_t> scheduleResult = {1, 2, 3};
auto mock = MockIUserAuthInterface::Holder::GetInstance().Get();
auto fillUpInfos = [](HdiCredentialInfo &infoRet) {
HdiCredentialInfo info = {
auto fillUpInfos = [](HdiEnrollResultInfo &infoRet) {
HdiCredentialInfo oldInfo = {
.credentialId = 1,
.executorIndex = 2,
.templateId = 3,
@ -106,10 +107,13 @@ HWTEST_F(EnrollmentImplTest, EnrollmentUpdateHdiSuccessful, TestSize.Level1)
.executorMatcher = 5,
.executorSensorHint = 6,
};
HdiEnrollResultInfo info = {
.oldInfo = oldInfo,
.credentialId = credentialIdRet,
};
infoRet = info;
};
EXPECT_CALL(*mock, UpdateEnrollmentResult(userId, _, _, _))
.WillRepeatedly(DoAll(SetArgReferee<2>(credentialIdRet), WithArg<3>(fillUpInfos), Return(0)));
EXPECT_CALL(*mock, UpdateEnrollmentResult(userId, _, _)).WillRepeatedly(DoAll(WithArg<2>(fillUpInfos), Return(0)));
auto authentication = std::make_shared<EnrollmentImpl>(userId, FACE);
HdiCredentialInfo oldInfo = {};