diff --git a/interfaces/inner_kits/native_cpp/include/dm_device_info.h b/interfaces/inner_kits/native_cpp/include/dm_device_info.h index 67c3a32aec0a6114bef43e50c0ce4ad577cbf7eb..b7704d94df412168e0e12abc80305242450246e6 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -439,7 +439,8 @@ enum class DMLocalServiceInfoAuthType : int32_t { enum class DMLocalServiceInfoPinExchangeType : int32_t { PINBOX = 1, ULTRASOUND = 2, - FROMDP = 3 + FROMDP = 3, + IMPORT_AUTH_CODE = 5 }; enum class DMLocalServiceInfoAuthBoxType : int32_t { diff --git a/services/implementation/include/authentication_v2/dm_freeze_process.h b/services/implementation/include/authentication_v2/dm_freeze_process.h index 796f36196a339668330bff2661646c56da61a58b..7c297457021a6c4646402b8a491e84130c1bd222 100644 --- a/services/implementation/include/authentication_v2/dm_freeze_process.h +++ b/services/implementation/include/authentication_v2/dm_freeze_process.h @@ -18,8 +18,10 @@ #include #include -#include "kv_adapter_manager.h" +#include "deviceprofile_connector.h" +#include "dm_auth_context.h" #include "dm_single_instance.h" +#include "kv_adapter_manager.h" namespace OHOS { namespace DistributedHardware { @@ -59,6 +61,7 @@ public: bool IsFrozen(int64_t &remainingFrozenTime); int32_t DeleteFreezeRecord(); int32_t UpdateFreezeRecord(); + bool IsNeedFreeze(std::shared_ptr context); private: FreezeProcess() = default; ~FreezeProcess() = default; diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 88f61775ecbce6cdf55418b3356ed986f9056d46..42dc1d7df36dcc9d5c30b79baaf8441510ce1766 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -1608,7 +1608,8 @@ bool DmAuthManager::IsServiceInfoPinExchangeTypeValid(int32_t pinExchangeType) { if (pinExchangeType != (int32_t)DMLocalServiceInfoPinExchangeType::PINBOX && pinExchangeType != (int32_t)DMLocalServiceInfoPinExchangeType::FROMDP && - pinExchangeType != (int32_t)DMLocalServiceInfoPinExchangeType::ULTRASOUND) { + pinExchangeType != (int32_t)DMLocalServiceInfoPinExchangeType::ULTRASOUND && + pinExchangeType != (int32_t)DMLocalServiceInfoPinExchangeType::IMPORT_AUTH_CODE) { return false; } return true; diff --git a/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp b/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp index a4581ac99f1ae17287c1e36491d5a78670303721..fa0d1e9d9163202014c6934c7ed7cb830883ca85 100644 --- a/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp +++ b/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp @@ -21,6 +21,7 @@ #include "dm_auth_attest_common.h" #include "dm_auth_cert.h" #include "dm_auth_context.h" +#include "dm_auth_manager_base.h" #include "dm_auth_state.h" #include "dm_auth_state_machine.h" #include "dm_constants.h" @@ -211,7 +212,10 @@ int32_t AuthSinkFinishState::Action(std::shared_ptr context) ret = FreezeProcess::GetInstance().DeleteFreezeRecord(); LOGI("DeleteFreezeRecord ret: %{public}d", ret); } - if (context->reason == ERR_DM_BIND_PIN_CODE_ERROR) { + bool isNeedFreeze = FreezeProcess::GetInstance().IsNeedFreeze(context); + bool isInWhiteList = AuthManagerBase::CheckProcessNameInWhiteList(context->accessee.bundleName); + LOGI("isInWhiteList: %{public}d.", isInWhiteList); + if (context->reason == ERR_DM_BIND_PIN_CODE_ERROR && (isNeedFreeze || !isInWhiteList)) { ret = FreezeProcess::GetInstance().UpdateFreezeRecord(); LOGI("UpdateFreezeData ret: %{public}d", ret); } diff --git a/services/implementation/src/authentication_v2/dm_freeze_process.cpp b/services/implementation/src/authentication_v2/dm_freeze_process.cpp index 9e7d4a1e3bb90ed0fffebe5a7364418026474a8a..7c34cb41fce5dad2f001fa239a458ff606a42dbb 100644 --- a/services/implementation/src/authentication_v2/dm_freeze_process.cpp +++ b/services/implementation/src/authentication_v2/dm_freeze_process.cpp @@ -30,6 +30,9 @@ constexpr const char* START_FREEZE_TIME_KEY = "startFreezeTimeStamp"; constexpr const char* STOP_FREEZE_TIME_KEY = "stopFreezeTimeStamp"; constexpr const char* FAILED_TIMES_STAMPS_KEY = "failedTimeStamps"; constexpr const char* FREEZE_TIMES_STAMPS_KEY = "freezeTimeStamps"; +constexpr const char* IS_NEED_FREEZE = "IsNeedFreeze"; +constexpr const char* NEED_FREEZE = "0"; +constexpr const char* NO_NEED_FREEZE = "1"; constexpr int32_t MAX_CONTINUOUS_BIND_FAILED_NUM = 2; constexpr int64_t CONTINUEOUS_FAILED_INTERVAL = 6 * 60; constexpr int64_t DATA_REFRESH_INTERVAL = 20 * 60; @@ -331,5 +334,43 @@ void FreezeProcess::CalculateNextFreezeTime(int64_t nowFreezeTime, int64_t &next break; } } + +bool FreezeProcess::IsNeedFreeze(std::shared_ptr context) +{ + LOGI("called"); + bool isNeedFreeze = true; + if (context == nullptr) { + LOGE("context is null"); + return isNeedFreeze; + } + OHOS::DistributedDeviceProfile::LocalServiceInfo srvInfo; + auto ret = DeviceProfileConnector::GetInstance().GetLocalServiceInfoByBundleNameAndPinExchangeType( + context->accessee.pkgName, context->authType, srvInfo); + if (ret != DM_OK) { + LOGE("ServiceInfo not found"); + return isNeedFreeze; + } + std::string extraInfo = srvInfo.GetExtraInfo(); + if (extraInfo.empty()) { + LOGE("no extraInfo"); + return isNeedFreeze; + } + JsonObject jsonObj; + jsonObj.Parse(extraInfo); + if (jsonObj.IsDiscarded()) { + LOGE("extraInfo invalid"); + return isNeedFreeze; + } + std::string isNeedFreezeStr; + if (IsString(jsonObj, IS_NEED_FREEZE)) { + isNeedFreezeStr = jsonObj[IS_NEED_FREEZE].Get(); + LOGI("isNeedFreezeStr: %{public}s.", isNeedFreezeStr.c_str()); + } + if (isNeedFreezeStr == NEED_FREEZE || isNeedFreezeStr == NO_NEED_FREEZE) { + isNeedFreeze = std::atoi(isNeedFreezeStr.c_str()); + } + LOGI("isNeedFreeze: %{public}d.", isNeedFreeze); + return isNeedFreeze; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index a12e0cfdcfd3921e08b544f8a0a9b4fe33e5d4a0..5342cfb74d7af959f1b5f3c89f0ef41d9064d567 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -2466,6 +2466,7 @@ ohos_unittest("UTTest_freeze_process") { "device_auth:deviceauth_sdk", "device_info_manager:distributed_device_profile_common", "device_info_manager:distributed_device_profile_sdk", + "dsoftbus:softbus_client", "ffrt:libffrt", "googletest:gmock", "hilog:libhilog",