From d602937f6a2f4adbbe6436c8d479201649201692 Mon Sep 17 00:00:00 2001 From: wangxu43 Date: Fri, 21 Jan 2022 17:00:45 +0800 Subject: [PATCH] Pin auth bug fix Signed-off-by: wangxu43 --- hdi/database/src/pin_db.c | 30 ++++++++++++++++------------- hdi/main/src/pin_func.c | 11 +++++------ services/src/pinauth_controller.cpp | 2 +- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/hdi/database/src/pin_db.c b/hdi/database/src/pin_db.c index a0b5d1c..6fa23f9 100644 --- a/hdi/database/src/pin_db.c +++ b/hdi/database/src/pin_db.c @@ -854,12 +854,12 @@ static ResultCode UpdateAntiBruteFile(uint64_t templateId, int32_t authResultSuc return RESULT_BAD_PARAM; } - if (!authResultSucc) { + if (authResultSucc == RESULT_SUCCESS) { ResultCode ret = ClearAntiBruteParamsById(templateId); if (ret != RESULT_SUCCESS) { LOG_ERROR("ClearAntiBruteParamsById fail."); - return ret; } + return ret; } uint64_t nowTime = GetRtcTime() * MS_OF_S; @@ -875,21 +875,22 @@ static ResultCode UpdateAntiBruteFile(uint64_t templateId, int32_t authResultSuc ret = SetAntiBruteInfoById(templateId, errorCount, nowTime); if (ret != RESULT_SUCCESS) { LOG_ERROR("SetAntiBruteInfoById fail."); - return ret; } - return ret; } static int32_t CompareData(uint8_t *inputData, uint32_t inputDataLen, uint8_t *storeData, uint32_t storeDataLen) { if (inputDataLen != storeDataLen) { - return RESULT_PIN_FAIL; + LOG_ERROR("get false len."); + return RESULT_BAD_MATCH; } if (memcmp(inputData, storeData, inputDataLen) == 0) { + LOG_INFO("auth pin success."); return RESULT_SUCCESS; } - return RESULT_PIN_FAIL; + LOG_ERROR("auth pin fail."); + return RESULT_BAD_MATCH; } ResultCode AuthPinById(uint8_t *inputData, uint32_t inputDataLen, uint64_t templateId) @@ -912,25 +913,28 @@ ResultCode AuthPinById(uint8_t *inputData, uint32_t inputDataLen, uint64_t templ return RESULT_GENERAL_ERROR; } + ResultCode compareRet = RESULT_BAD_MATCH; ResultCode ret = ReadPinFile(storeData, storeDataLen, templateId, CRYPTO_SUFFIX); if (ret != RESULT_SUCCESS) { LOG_ERROR("Read pin store File fail."); goto EXIT; } - - ret = CompareData(inputData, inputDataLen, storeData, storeDataLen); + compareRet = CompareData(inputData, inputDataLen, storeData, storeDataLen); + if (compareRet != RESULT_SUCCESS) { + LOG_ERROR("CompareData fail."); + } /* * If the authentication succeeds, set authErrorConut to 0 and set startFreezeTime to the default value. * If the authentication fails, the value of authErrorConut is incremented by 1 and the * current time(startFreezeTime) is recorded. */ - - ret = UpdateAntiBruteFile(templateId, ret); + ret = UpdateAntiBruteFile(templateId, compareRet); if (ret != RESULT_SUCCESS) { - LOG_ERROR("AuthPinBuffer fail."); + LOG_ERROR("UpdateAntiBruteFile fail."); goto EXIT; } - LOG_INFO("AuthPinById succ."); + ret = compareRet; + LOG_INFO("AuthPinById end."); EXIT: Free(storeData); @@ -967,4 +971,4 @@ ResultCode VerifyTemplateDataPin(uint64_t *templateIdList, uint32_t templateIdLi } LOG_INFO("VerifyTemplateDataPin succ."); return RESULT_SUCCESS; -} \ No newline at end of file +} diff --git a/hdi/main/src/pin_func.c b/hdi/main/src/pin_func.c index a850566..ffa204f 100644 --- a/hdi/main/src/pin_func.c +++ b/hdi/main/src/pin_func.c @@ -83,16 +83,16 @@ ResultCode DoAuthPin(PinAuthParam *pinAuthParam, Buffer *retTlv) ret = AuthPinById(&(pinAuthParam->pinData[0]), CONST_PIN_DATA_LEN, pinAuthParam->templateId); if (ret != RESULT_SUCCESS) { LOG_ERROR("AuthPinById fail."); - return ret; } } else { + LOG_ERROR("Pin is freezing."); ret = RESULT_PIN_FREEZE; } - ret = GenerateRetTlv(RESULT_SUCCESS, pinAuthParam->scheduleId, subType, pinAuthParam->templateId, retTlv); - if (ret != RESULT_SUCCESS) { + ResultCode tlvRet = GenerateRetTlv(ret, pinAuthParam->scheduleId, subType, pinAuthParam->templateId, retTlv); + if (tlvRet != RESULT_SUCCESS) { LOG_ERROR("GenerateRetTlv DoAuthPin fail."); - return ret; + return tlvRet; } return ret; } @@ -110,7 +110,6 @@ ResultCode DoQueryPinInfo(uint64_t templateId, PinCredentialInfos *pinCredential LOG_ERROR("GetSubTypeAndFreezeTime fail."); return ret; } - if (pinCredentialInfo->freezeTime > 0) { pinCredentialInfo->remainTimes = 0; } else { @@ -259,4 +258,4 @@ ResultCode DoVerifyTemplateData(uint64_t *templateIdList, uint32_t templateIdLis return ret; } return RESULT_SUCCESS; -} \ No newline at end of file +} diff --git a/services/src/pinauth_controller.cpp b/services/src/pinauth_controller.cpp index 18e06b0..dd0a0b4 100644 --- a/services/src/pinauth_controller.cpp +++ b/services/src/pinauth_controller.cpp @@ -92,7 +92,7 @@ void PinAuthController::OnSetData(int32_t authSubType, std::vector data } else if (command_ == COMMAND_AUTH_PIN) { PINAUTH_HILOGE(MODULE_SERVICE, "PinAuthController::onSetData command == COMMAND_AUTH_PIN"); ret = pin_->AuthPin(scheduleId_, templateId_, data, result); - PINAUTH_HILOGI(MODULE_COMMON, "----------AuthPin finish-----------"); + PINAUTH_HILOGI(MODULE_COMMON, "----------AuthPin finish %{public}d-----------", ret); } } -- Gitee