diff --git a/bundle.json b/bundle.json index 47d5acde74cd3b3c48252f1a5faf8c8b34421135..7a954b8eb8e983ac0ba326fc926855eed04a26dc 100644 --- a/bundle.json +++ b/bundle.json @@ -32,7 +32,8 @@ "drivers_interface_pin_auth", "c_utils", "enterprise_device_management", - "openssl" + "openssl", + "data_share" ] }, "build": { diff --git a/frameworks/BUILD.gn b/frameworks/BUILD.gn index b5e4f293c5bb6a67428fcf672c7c958b1ded1a6f..19b9f4954d8e0f4e1c1c4df62f25638ecbb7b776 100644 --- a/frameworks/BUILD.gn +++ b/frameworks/BUILD.gn @@ -44,6 +44,7 @@ ohos_source_set("pinauth_framework_source_set") { "client/src/inputer_data_impl.cpp", "client/src/inputer_get_data_service.cpp", "client/src/pinauth_register_impl.cpp", + "client/src/settings_data_manager.cpp", "scrypt/src/scrypt.cpp", ] @@ -51,6 +52,7 @@ ohos_source_set("pinauth_framework_source_set") { external_deps = [ "c_utils:utils", + "data_share:datashare_consumer", "hilog:libhilog", "ipc:ipc_single", "openssl:libcrypto_shared", diff --git a/frameworks/client/inc/inputer_data_impl.h b/frameworks/client/inc/inputer_data_impl.h index c52b19886f4b6e44bc96d11c10e4dc8c2670ccaf..1124e9872a5aedc69b8a6c24fafc7a4166d7d18e 100644 --- a/frameworks/client/inc/inputer_data_impl.h +++ b/frameworks/client/inc/inputer_data_impl.h @@ -33,8 +33,7 @@ namespace UserIam { namespace PinAuth { class InputerDataImpl : public IInputerData { public: - InputerDataImpl(GetDataMode mode, uint32_t algoVersion, const std::vector &algoParameter, - const sptr &inputerSetData); + InputerDataImpl(const InputerGetDataParam ¶m); ~InputerDataImpl() override = default; void OnSetData(int32_t authSubType, std::vector data) override; @@ -44,11 +43,18 @@ private: int32_t authSubType, const std::vector &dataIn, std::vector &dataOut, int32_t &errorCode); void OnSetDataInner(int32_t authSubType, std::vector &setData, int32_t errorCode); int32_t CheckPinComplexity(int32_t authSubType, const std::vector &data); + bool CheckEdmPinComplexity(int32_t authSubType, std::vector &input); + bool CheckSpecialPinComplexity(std::vector &input, int32_t authSubType); + bool CheckPinSizeBySubType(int32_t authSubType, size_t size); + bool CheckPinComplexityByReg(std::vector &input, const std::string &complexityReg); GetDataMode mode_ = GET_DATA_MODE_NONE; uint32_t algoVersion_ = 0; std::vector algoParameter_; sptr inputerSetData_; + std::string complexityReg_; + int32_t userId_; + int32_t authIntent_; }; } // namespace PinAuth } // namespace UserIam diff --git a/frameworks/client/inc/settings_data_manager.h b/frameworks/client/inc/settings_data_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..f9ddbf16a7994d6687a8f34d06e8e0db41b45671 --- /dev/null +++ b/frameworks/client/inc/settings_data_manager.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SETTINGS_DATA_MANAGER_H +#define SETTINGS_DATA_MANAGER_H + +#include "datashare_helper.h" + +namespace OHOS { +namespace UserIam { +namespace PinAuth { +class SettingsDataManager : public NoCopyable { +public: + SettingsDataManager() = default; + ~SettingsDataManager() override = default; + static bool GetIntValue(int32_t userId, const std::string &key, int32_t &value); + +private: + std::shared_ptr CreateDataShareHelper(int32_t userId); + void ReleaseDataShareHelper(std::shared_ptr &helper); + Uri AssembleUri(int32_t userId, const std::string &key); + bool GetStringValue(int32_t userId, const std::string &key, std::string &value); +}; +} // namespace PinAuth +} // namespace UserIam +} // namespace OHOS +#endif // SETTINGS_DATA_MANAGER_H diff --git a/frameworks/client/src/inputer_data_impl.cpp b/frameworks/client/src/inputer_data_impl.cpp index 77b06cc9bca78c3eb0c60e8efb494642dbabc4fc..c58938a48c31ef417e8114a2adccf253db35f6ff 100644 --- a/frameworks/client/src/inputer_data_impl.cpp +++ b/frameworks/client/src/inputer_data_impl.cpp @@ -26,6 +26,7 @@ #include "iam_logger.h" #include "iam_ptr.h" #include "scrypt.h" +#include "settings_data_manager.h" #ifdef CUSTOMIZATION_ENTERPRISE_DEVICE_MANAGEMENT_ENABLE #include "security_manager_proxy.h" #endif @@ -36,21 +37,27 @@ namespace OHOS { namespace UserIam { namespace PinAuth { namespace { -constexpr uint32_t MIN_PIN_LENGTH = 4; +constexpr uint32_t PIN_LEN_FOUR = 4; +constexpr uint32_t PIN_LEN_SIX = 6; +constexpr uint32_t PIN_LEN_SEVEN = 7; +constexpr uint32_t PIN_LEN_NINE = 9; +constexpr uint32_t SPECIFY_PIN_COMPLEXITY = 10002; } -InputerDataImpl::InputerDataImpl(GetDataMode mode, uint32_t algoVersion, const std::vector &algoParameter, - const sptr &inputerSetData) - : mode_(mode), algoVersion_(algoVersion), algoParameter_(algoParameter), inputerSetData_(inputerSetData) +InputerDataImpl::InputerDataImpl(const InputerGetDataParam ¶m) + : mode_(param.mode), algoVersion_(param.algoVersion), algoParameter_(param.algoParameter), + inputerSetData_(param.inputerSetData), complexityReg_(param.complexityReg), userId_(param.userId), + authIntent_(param.authIntent) { } void InputerDataImpl::GetPinData( int32_t authSubType, const std::vector &dataIn, std::vector &dataOut, int32_t &errorCode) { + IAM_LOGI("start authSubType: %{public}d", authSubType); errorCode = CheckPinComplexity(authSubType, dataIn); - if (errorCode != UserAuth::SUCCESS) { - IAM_LOGE("CheckPinComplexity failed"); + if (errorCode != UserAuth::SUCCESS && mode_ == GET_DATA_MODE_ALL_IN_ONE_ENROLL) { + IAM_LOGE("CheckPinComplexity enroll failed"); return; } @@ -93,7 +100,8 @@ void InputerDataImpl::GetPinData( void InputerDataImpl::OnSetData(int32_t authSubType, std::vector data) { - IAM_LOGI("start and data size:%{public}zu algo version:%{public}u", data.size(), algoVersion_); + IAM_LOGI("start userId:%{public}d, data size:%{public}zu, algo version:%{public}u, complexityReg size:%{public}zu", + userId_, data.size(), algoVersion_, complexityReg_.size()); std::vector setData; int32_t errorCode = UserAuth::GENERAL_ERROR; GetPinData(authSubType, data, setData, errorCode); @@ -128,6 +136,23 @@ void InputerDataImpl::OnSetDataInner(int32_t authSubType, std::vector & inputerSetData_->OnSetData(authSubType, setData, errorCode); } +bool InputerDataImpl::CheckPinSizeBySubType(int32_t authSubType, size_t size) +{ + if (mode_ != GET_DATA_MODE_ALL_IN_ONE_ENROLL) { + return true; + } + if (size < PIN_LEN_FOUR) { + return false; + } + switch (authSubType) { + case UserAuth::PIN_FOUR: + return (size == PIN_LEN_FOUR); + case UserAuth::PIN_PATTERN: + return (size >= PIN_LEN_FOUR && size <= PIN_LEN_NINE); + default: + return (size >= PIN_LEN_SIX); + } +} int32_t InputerDataImpl::CheckPinComplexity(int32_t authSubType, const std::vector &data) { @@ -135,41 +160,96 @@ int32_t InputerDataImpl::CheckPinComplexity(int32_t authSubType, const std::vect IAM_LOGE("get empty data"); return UserAuth::COMPLEXITY_CHECK_FAILED; } + if (!CheckPinSizeBySubType(authSubType, data.size())) { + IAM_LOGE("check data size failed"); + return UserAuth::COMPLEXITY_CHECK_FAILED; + } + std::vector input = data; + input.emplace_back('\0'); + if (!CheckEdmPinComplexity(authSubType, input)) { + IAM_LOGE("CheckEdmPinComplexity failed"); + (void)memset_s(input.data(), input.size(), 0, input.size()); + return UserAuth::COMPLEXITY_CHECK_FAILED; + } + if (!CheckSpecialPinComplexity(input, authSubType)) { + IAM_LOGE("CheckSpecialPinComplexity failed"); + (void)memset_s(input.data(), input.size(), 0, input.size()); + return UserAuth::COMPLEXITY_CHECK_FAILED; + } + (void)memset_s(input.data(), input.size(), 0, input.size()); + return UserAuth::SUCCESS; +} + +bool InputerDataImpl::CheckSpecialPinComplexity(std::vector &input, int32_t authSubType) +{ + IAM_LOGI("start"); + if (mode_ != GET_DATA_MODE_ALL_IN_ONE_ENROLL && + !(mode_ == GET_DATA_MODE_ALL_IN_ONE_AUTH && authIntent_ == SPECIFY_PIN_COMPLEXITY)) { + return true; + } + if (complexityReg_.empty()) { + IAM_LOGI("complexityReg is empty"); + return true; + } + const std::string key = "payment_security_level"; + int32_t isCheckPinComplexity = 0; + if (!SettingsDataManager::GetIntValue(userId_, key, isCheckPinComplexity)) { + IAM_LOGI("no exist isCheckPinComplexity"); + return true; + } + if (isCheckPinComplexity == 0) { + IAM_LOGI("no need check special pin complexity"); + return true; + } + if (authSubType == UserAuth::PIN_FOUR || authSubType == UserAuth::PIN_PATTERN) { + IAM_LOGE("authSubType is PIN_FOUR or PIN_PATTERN"); + return false; + } + if (input.size() < PIN_LEN_SEVEN) { + IAM_LOGE("check data size failed"); + return false; + } + return CheckPinComplexityByReg(input, complexityReg_); +} + +bool InputerDataImpl::CheckEdmPinComplexity(int32_t authSubType, std::vector &input) +{ + IAM_LOGI("start"); if (mode_ != GET_DATA_MODE_ALL_IN_ONE_ENROLL) { - return UserAuth::SUCCESS; + return true; } #ifdef CUSTOMIZATION_ENTERPRISE_DEVICE_MANAGEMENT_ENABLE EDM::PasswordPolicy policy; int32_t ret = EDM::SecurityManagerProxy::GetSecurityManagerProxy()->GetPasswordPolicy(policy); if (ret != ERR_OK || policy.complexityReg.empty()) { - IAM_LOGE("GetPasswordPolicy failed, use default policy"); - return (data.size() >= MIN_PIN_LENGTH ? UserAuth::SUCCESS : UserAuth::COMPLEXITY_CHECK_FAILED); + IAM_LOGE("GetPasswordPolicy failed, check other policy"); + return true; } if (authSubType != UserAuth::PIN_MIXED) { IAM_LOGE("GetPasswordPolicy success, authSubType can only be PIN_MIXED"); - return UserAuth::COMPLEXITY_CHECK_FAILED; + return false; } - std::vector input = data; - input.emplace_back('\0'); + return CheckPinComplexityByReg(input, policy.complexityReg); +#else + IAM_LOGI("This device not support edm"); +#endif + return true; +} + +bool InputerDataImpl::CheckPinComplexityByReg(std::vector &input, const std::string &complexityReg) +{ try { - std::regex regex(policy.complexityReg); + std::regex regex(complexityReg); bool checkRet = std::regex_match(reinterpret_cast(input.data()), regex); if (!checkRet) { IAM_LOGE("PIN_MIXED does not pass complexity check"); - (void)memset_s(input.data(), input.size(), 0, input.size()); - return UserAuth::COMPLEXITY_CHECK_FAILED; + return false; } } catch (const std::regex_error &e) { IAM_LOGE("create regex failed"); - (void)memset_s(input.data(), input.size(), 0, input.size()); - return UserAuth::COMPLEXITY_CHECK_FAILED; + return false; } - (void)memset_s(input.data(), input.size(), 0, input.size()); - return UserAuth::SUCCESS; -#else - IAM_LOGI("This device not support edm, subType:%{public}d", authSubType); - return (data.size() >= MIN_PIN_LENGTH ? UserAuth::SUCCESS : UserAuth::COMPLEXITY_CHECK_FAILED); -#endif + return true; } } // namespace PinAuth } // namespace UserIam diff --git a/frameworks/client/src/inputer_get_data_service.cpp b/frameworks/client/src/inputer_get_data_service.cpp index 847c65f69c299a91f78f50d0d05da50bba265788..8d558c4eef8c2af13dc1c39983f0aa877f1217f7 100644 --- a/frameworks/client/src/inputer_get_data_service.cpp +++ b/frameworks/client/src/inputer_get_data_service.cpp @@ -36,8 +36,7 @@ void InputerGetDataService::OnGetData(const InputerGetDataParam &getDataParam) return; } - std::shared_ptr sharedInputerData = Common::MakeShared( - getDataParam.mode, getDataParam.algoVersion, getDataParam.algoParameter, getDataParam.inputerSetData); + std::shared_ptr sharedInputerData = Common::MakeShared(getDataParam); if (sharedInputerData == nullptr) { IAM_LOGE("sharedInputerData is nullptr"); return; diff --git a/frameworks/client/src/settings_data_manager.cpp b/frameworks/client/src/settings_data_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..136ece9277d7081b8f08d7bbcf6b3fc469043b87 --- /dev/null +++ b/frameworks/client/src/settings_data_manager.cpp @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "settings_data_manager.h" + +#include "iam_logger.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" +#include "uri.h" + +#define LOG_TAG "PIN_AUTH_SDK" + +namespace OHOS { +namespace UserIam { +namespace PinAuth { +namespace { +const std::string SETTING_COLUMN_KEYWORD = "KEYWORD"; +const std::string SETTING_COLUMN_VALUE = "VALUE"; +const char *PIN_SETTING_URI_PROXY = "datashare:///com.ohos.settingsdata/entry/settingsdata/USER_SETTINGSDATA_SECURE_"; +const char *SETTINGS_DATA_EXT_URI = "datashare:///com.ohos.settingsdata.DataAbility"; +} // namespace + +bool SettingsDataManager::GetIntValue(int32_t userId, const std::string &key, int32_t &value) +{ + std::string valueStr = ""; + SettingsDataManager settingsDataManager; + if (!settingsDataManager.GetStringValue(userId, key, valueStr)) { + IAM_LOGE("GetStringValue failed"); + return false; + } + const int32_t DECIMAL = 10; + value = static_cast(strtoll(valueStr.c_str(), nullptr, DECIMAL)); + return true; +} + +bool SettingsDataManager::GetStringValue(int32_t userId, const std::string &key, std::string &value) +{ + auto helper = CreateDataShareHelper(userId); + if (helper == nullptr) { + return false; + } + std::vector columns = {SETTING_COLUMN_VALUE}; + DataShare::DataSharePredicates predicates; + predicates.EqualTo(SETTING_COLUMN_KEYWORD, key); + Uri uri(AssembleUri(userId, key)); + auto resultSet = helper->Query(uri, predicates, columns); + ReleaseDataShareHelper(helper); + if (resultSet == nullptr) { + IAM_LOGE("helper->Query return nullptr"); + return false; + } + int32_t count; + resultSet->GetRowCount(count); + if (count == 0) { + IAM_LOGE("not found value, key=%{public}s, count=%{public}d", key.c_str(), count); + resultSet->Close(); + return false; + } + const int32_t index = 0; + resultSet->GoToRow(index); + int32_t ret = resultSet->GetString(index, value); + resultSet->Close(); + if (ret != DataShare::E_OK) { + IAM_LOGE("resultSet->GetString return not ok, ret=%{public}d", ret); + return false; + } + return true; +} + +std::shared_ptr SettingsDataManager::CreateDataShareHelper(int32_t userId) +{ + sptr sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (sam == nullptr) { + IAM_LOGE("GetSystemAbilityManager return nullptr"); + return nullptr; + } + auto remoteObj = sam->GetSystemAbility(SUBSYS_USERIAM_SYS_ABILITY_PINAUTH); + if (remoteObj == nullptr) { + IAM_LOGE("GetSystemAbility return nullptr"); + return nullptr; + } + + std::string uriStr = std::string(PIN_SETTING_URI_PROXY) + std::to_string(userId) + "?Proxy=true"; + std::string extUriStr(SETTINGS_DATA_EXT_URI); + auto helper = DataShare::DataShareHelper::Creator(remoteObj, uriStr, extUriStr); + if (helper == nullptr) { + IAM_LOGE("helper is nullptr, uri=%{public}s", uriStr.c_str()); + return nullptr; + } + return helper; +} + +void SettingsDataManager::ReleaseDataShareHelper(std::shared_ptr &helper) +{ + if (!helper->Release()) { + IAM_LOGE("release helper fail"); + } +} + +Uri SettingsDataManager::AssembleUri(int32_t userId, const std::string &key) +{ + std::string uriStr = std::string(PIN_SETTING_URI_PROXY) + std::to_string(userId) + "?Proxy=true"; + Uri uri(uriStr + "&key=" + key); + return uri; +} +} // namespace PinAuth +} // namespace UserIam +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ipc/common_defines/inputer_get_data.h b/frameworks/ipc/common_defines/inputer_get_data.h index daadba4c0947fe072a508f0a058d048a174c9255..461b0f1aeadef24f7b347303a3002b0b6648ab33 100644 --- a/frameworks/ipc/common_defines/inputer_get_data.h +++ b/frameworks/ipc/common_defines/inputer_get_data.h @@ -39,6 +39,9 @@ struct InputerGetDataParam { std::vector algoParameter; std::vector challenge; sptr inputerSetData; + int32_t userId; + std::string complexityReg; + int32_t authIntent; }; class InputerGetData : public IRemoteBroker { diff --git a/frameworks/ipc/inc/inputer_get_data_proxy.h b/frameworks/ipc/inc/inputer_get_data_proxy.h index 266b34446092514e55d3703e19403b04b3a4fe07..f78e9cc9c1db030aefe2308bd4f6c2421f5c95b9 100644 --- a/frameworks/ipc/inc/inputer_get_data_proxy.h +++ b/frameworks/ipc/inc/inputer_get_data_proxy.h @@ -36,6 +36,7 @@ public: private: static inline BrokerDelegator delegator_; bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); + bool WriteInputerGetDataParam(MessageParcel &data, const InputerGetDataParam &getDataParam); }; } // namespace PinAuth } // namespace UserIam diff --git a/frameworks/ipc/inc/inputer_get_data_stub.h b/frameworks/ipc/inc/inputer_get_data_stub.h index f3037d32f6725a3c767e82b8777927965a924481..fc775de00441adcf1f3d3b19802e090c3164661d 100644 --- a/frameworks/ipc/inc/inputer_get_data_stub.h +++ b/frameworks/ipc/inc/inputer_get_data_stub.h @@ -33,6 +33,7 @@ public: private: void OnGetDataStub(MessageParcel &data, MessageParcel &reply); + bool ReadInputerGetDataParam(MessageParcel &data, InputerGetDataParam &getDataParam); }; } // namespace PinAuth } // namespace UserIam diff --git a/frameworks/ipc/src/inputer_get_data_proxy.cpp b/frameworks/ipc/src/inputer_get_data_proxy.cpp index 3626e69c40ce7658c76e7ceb2a10cfe78b9c4a4f..3d433652ebb42ccb5b97107cdc4b3abf4e45a14a 100644 --- a/frameworks/ipc/src/inputer_get_data_proxy.cpp +++ b/frameworks/ipc/src/inputer_get_data_proxy.cpp @@ -22,47 +22,65 @@ namespace OHOS { namespace UserIam { namespace PinAuth { -void InputerGetDataProxy::OnGetData(const InputerGetDataParam &getDataParam) +bool InputerGetDataProxy::WriteInputerGetDataParam(MessageParcel &data, const InputerGetDataParam &getDataParam) { - IAM_LOGI("start"); - if (getDataParam.inputerSetData == nullptr) { - IAM_LOGE("inputerSetData is nullptr"); - return; - } - - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(InputerGetDataProxy::GetDescriptor())) { - IAM_LOGE("write descriptor fail"); - return; - } if (!data.WriteInt32(getDataParam.mode)) { IAM_LOGE("write mode fail"); - return; + return false; } if (!data.WriteInt32(getDataParam.authSubType)) { IAM_LOGE("write authSubType fail"); - return; + return false; } if (!data.WriteUint32(getDataParam.algoVersion)) { IAM_LOGE("write algoVersion fail"); - return; + return false; } if (!data.WriteUInt8Vector(getDataParam.algoParameter)) { IAM_LOGE("write algoParameter fail"); - return; + return false; } if (!data.WriteUInt8Vector(getDataParam.challenge)) { IAM_LOGE("write challenge fail"); - return; + return false; + } + if (!data.WriteInt32(getDataParam.userId)) { + IAM_LOGE("write userId fail"); + return false; + } + if (!data.WriteString(getDataParam.complexityReg)) { + IAM_LOGE("write complexityReg fail"); + return false; + } + if (!data.WriteInt32(getDataParam.authIntent)) { + IAM_LOGE("write authIntent fail"); + return false; } if (!data.WriteRemoteObject(getDataParam.inputerSetData->AsObject())) { IAM_LOGE("write inputerData fail"); + return false; + } + return true; +} + +void InputerGetDataProxy::OnGetData(const InputerGetDataParam &getDataParam) +{ + IAM_LOGI("start"); + if (getDataParam.inputerSetData == nullptr) { + IAM_LOGE("inputerSetData is nullptr"); + return; + } + MessageParcel data; + MessageParcel reply; + if (!data.WriteInterfaceToken(InputerGetDataProxy::GetDescriptor())) { + IAM_LOGE("write descriptor fail"); + return; + } + if (!WriteInputerGetDataParam(data, getDataParam)) { + IAM_LOGE("WriteInputerGetDataParam fail"); return; } - bool ret = SendRequest(InputerGetDataInterfaceCode::ON_GET_DATA, data, reply); - if (ret) { + if (SendRequest(InputerGetDataInterfaceCode::ON_GET_DATA, data, reply)) { int32_t result = reply.ReadInt32(); IAM_LOGI("result = %{public}d", result); } diff --git a/frameworks/ipc/src/inputer_get_data_stub.cpp b/frameworks/ipc/src/inputer_get_data_stub.cpp index 033601819f9adb5c6096bb77f658f8e235507a43..fa1bbebc5db4a962fa4c0135ea80e829f10a830e 100644 --- a/frameworks/ipc/src/inputer_get_data_stub.cpp +++ b/frameworks/ipc/src/inputer_get_data_stub.cpp @@ -40,43 +40,62 @@ int32_t InputerGetDataStub::OnRemoteRequest(uint32_t code, MessageParcel &data, } } -void InputerGetDataStub::OnGetDataStub(MessageParcel &data, MessageParcel &reply) +bool InputerGetDataStub::ReadInputerGetDataParam(MessageParcel &data, InputerGetDataParam &getDataParam) { - InputerGetDataParam getDataParam; - int32_t mode; if (!data.ReadInt32(mode)) { IAM_LOGE("failed to read mode"); - return; + return false; } getDataParam.mode = static_cast(mode); if (!data.ReadInt32(getDataParam.authSubType)) { IAM_LOGE("failed to read authSubType"); - return; + return false; } if (!data.ReadUint32(getDataParam.algoVersion)) { IAM_LOGE("failed to read algoVersion"); - return; + return false; } if (!data.ReadUInt8Vector(&(getDataParam.algoParameter))) { IAM_LOGE("failed to read algoParameter"); - return; + return false; } if (!data.ReadUInt8Vector(&(getDataParam.challenge))) { IAM_LOGE("failed to read challenge"); - return; + return false; + } + if (!data.ReadInt32(getDataParam.userId)) { + IAM_LOGE("failed to read userId"); + return false; + } + if (!data.ReadString(getDataParam.complexityReg)) { + IAM_LOGE("failed to read complexityReg"); + return false; + } + if (!data.ReadInt32(getDataParam.authIntent)) { + IAM_LOGE("failed to read authIntent"); + return false; } sptr obj = data.ReadRemoteObject(); if (obj == nullptr) { IAM_LOGE("failed to read remote object"); - return; + return false; } getDataParam.inputerSetData = iface_cast(obj); if (getDataParam.inputerSetData == nullptr) { IAM_LOGE("inputerSetData is nullptr"); - return; + return false; } + return true; +} +void InputerGetDataStub::OnGetDataStub(MessageParcel &data, MessageParcel &reply) +{ + InputerGetDataParam getDataParam; + if (!ReadInputerGetDataParam(data, getDataParam)) { + IAM_LOGE("ReadInputerGetDataParam failed"); + return; + } OnGetData(getDataParam); } } // namespace PinAuth diff --git a/services/modules/executors/inc/pin_auth_executor_callback_hdi.h b/services/modules/executors/inc/pin_auth_executor_callback_hdi.h index 3723623807896df3e3bf6f5fe9b982c51b2d45d2..6e6cbcfbc6cce16c933297953c9eb4faf45d28ca 100644 --- a/services/modules/executors/inc/pin_auth_executor_callback_hdi.h +++ b/services/modules/executors/inc/pin_auth_executor_callback_hdi.h @@ -43,9 +43,9 @@ public: ~PinAuthExecutorCallbackHdi() override = default; int32_t OnResult(int32_t code, const std::vector &extraInfo) override; int32_t OnGetData(const std::vector& algoParameter, uint64_t authSubType, uint32_t algoVersion, - const std::vector& challenge) override; - int32_t OnTip(int32_t tip, const std::vector& extraInfo) override; - int32_t OnMessage(int32_t destRole, const std::vector& msg) override; + const std::vector &challenge, const std::string &complexityReg) override; + int32_t OnTip(int32_t tip, const std::vector &extraInfo) override; + int32_t OnMessage(int32_t destRole, const std::vector &msg) override; private: void DoVibrator(); @@ -57,6 +57,7 @@ private: GetDataMode mode_; uint64_t scheduleId_; int32_t authIntent_; + int32_t userId_; }; } // PinAuth } // UserIam diff --git a/services/modules/executors/src/pin_auth_all_in_one_hdi.cpp b/services/modules/executors/src/pin_auth_all_in_one_hdi.cpp index 7638996d09c23cc37f77fdb31ddd1f54d11780d6..4f241a3570be4cdd12f634ed67b14967265d1cc0 100644 --- a/services/modules/executors/src/pin_auth_all_in_one_hdi.cpp +++ b/services/modules/executors/src/pin_auth_all_in_one_hdi.cpp @@ -120,6 +120,7 @@ UserAuth::ResultCode PinAuthAllInOneHdi::Enroll(uint64_t scheduleId, const UserA UserAuth::ExecutorParam executorParam = { .tokenId = param.tokenId, .scheduleId = scheduleId, + .userId = param.userId, }; auto callback = sptr(new (std::nothrow) PinAuthExecutorCallbackHdi(callbackObj, shared_from_this(), executorParam, GET_DATA_MODE_ALL_IN_ONE_ENROLL)); @@ -152,6 +153,7 @@ UserAuth::ResultCode PinAuthAllInOneHdi::Authenticate( .tokenId = param.tokenId, .authIntent = param.authIntent, .scheduleId = scheduleId, + .userId = param.userId, }; auto callback = sptr(new (std::nothrow) PinAuthExecutorCallbackHdi(callbackObj, shared_from_this(), executorParam, GET_DATA_MODE_ALL_IN_ONE_AUTH)); diff --git a/services/modules/executors/src/pin_auth_executor_callback_hdi.cpp b/services/modules/executors/src/pin_auth_executor_callback_hdi.cpp index e52e10b83964705eadf9fdbf5a8bca27d3cfc9e0..ef29ddde2f439f2fce111a6672beb33056328148 100644 --- a/services/modules/executors/src/pin_auth_executor_callback_hdi.cpp +++ b/services/modules/executors/src/pin_auth_executor_callback_hdi.cpp @@ -35,25 +35,29 @@ namespace OHOS { namespace UserIam { namespace PinAuth { +static const uint32_t SPECIFY_PIN_COMPLEXITY = 10002; PinAuthExecutorCallbackHdi::PinAuthExecutorCallbackHdi( std::shared_ptr frameworkCallback, std::shared_ptr pinAuthAllInOneHdi, const UserAuth::ExecutorParam ¶m, GetDataMode mode) : frameworkCallback_(frameworkCallback), pinAuthAllInOneHdi_(pinAuthAllInOneHdi), pinAuthCollectorHdi_(nullptr), - tokenId_(param.tokenId), mode_(mode), scheduleId_(param.scheduleId), authIntent_(param.authIntent) {} + tokenId_(param.tokenId), mode_(mode), scheduleId_(param.scheduleId), authIntent_(param.authIntent), + userId_(param.userId) {} PinAuthExecutorCallbackHdi::PinAuthExecutorCallbackHdi( std::shared_ptr frameworkCallback, std::shared_ptr pinAuthCollectorHdi, const UserAuth::ExecutorParam ¶m, GetDataMode mode) : frameworkCallback_(frameworkCallback), pinAuthAllInOneHdi_(nullptr), pinAuthCollectorHdi_(pinAuthCollectorHdi), - tokenId_(param.tokenId), mode_(mode), scheduleId_(param.scheduleId), authIntent_(param.authIntent) {} + tokenId_(param.tokenId), mode_(mode), scheduleId_(param.scheduleId), authIntent_(param.authIntent), + userId_(param.userId) {} PinAuthExecutorCallbackHdi::PinAuthExecutorCallbackHdi(std::shared_ptr frameworkCallback, const UserAuth::ExecutorParam ¶m, GetDataMode mode) : frameworkCallback_(frameworkCallback), pinAuthAllInOneHdi_(nullptr), pinAuthCollectorHdi_(nullptr), - tokenId_(param.tokenId), mode_(mode), scheduleId_(param.scheduleId), authIntent_(param.authIntent) {} + tokenId_(param.tokenId), mode_(mode), scheduleId_(param.scheduleId), authIntent_(param.authIntent), + userId_(param.userId) {} void PinAuthExecutorCallbackHdi::DoVibrator() { @@ -101,50 +105,36 @@ int32_t PinAuthExecutorCallbackHdi::OnResult(int32_t code, const std::vector& algoParameter, uint64_t authSubType, - uint32_t algoVersion, const std::vector& challenge) +int32_t PinAuthExecutorCallbackHdi::OnGetData(const std::vector &algoParameter, uint64_t authSubType, + uint32_t algoVersion, const std::vector &challenge, const std::string &complexityReg) { - static_cast(challenge); - - IAM_LOGI("Start tokenId_ is %{public}s", GET_MASKED_STRING(tokenId_).c_str()); + IAM_LOGI("Start, userId:%{public}d, tokenId_:%{public}s, authIntent:%{public}d, complexityReg size %{public}zu", + userId_, GET_MASKED_STRING(tokenId_).c_str(), authIntent_, complexityReg.size()); sptr inputer = PinAuthManager::GetInstance().GetInputerLock(tokenId_); - if (inputer == nullptr) { - IAM_LOGE("inputer is nullptr"); - return HDF_FAILURE; + IF_FALSE_LOGE_AND_RETURN_VAL(inputer != nullptr, HDF_FAILURE); + InputerGetDataParam param = { + .mode = mode_, + .authSubType = authSubType, + .algoVersion = algoVersion, + .algoParameter = algoParameter, + .challenge = challenge, + .userId = userId_, + .authIntent = authIntent_, + }; + if (mode_ == GET_DATA_MODE_ALL_IN_ONE_ENROLL || + (authIntent_ == SPECIFY_PIN_COMPLEXITY && mode_ == GET_DATA_MODE_ALL_IN_ONE_AUTH)) { + param.complexityReg = complexityReg; } - if (pinAuthAllInOneHdi_ != nullptr) { sptr iInputerDataImpl(new (std::nothrow) IInputerDataImpl(scheduleId_, pinAuthAllInOneHdi_)); - if (iInputerDataImpl == nullptr) { - IAM_LOGE("iInputerDataImpl is nullptr"); - return HDF_FAILURE; - } - - InputerGetDataParam param = { - .mode = mode_, - .authSubType = authSubType, - .algoVersion = algoVersion, - .algoParameter = algoParameter, - .challenge = challenge, - .inputerSetData = iInputerDataImpl, - }; + IF_FALSE_LOGE_AND_RETURN_VAL(iInputerDataImpl != nullptr, HDF_FAILURE); + param.inputerSetData = iInputerDataImpl; inputer->OnGetData(param); return HDF_SUCCESS; } else if (pinAuthCollectorHdi_ != nullptr) { sptr iInputerDataImpl(new (std::nothrow) IInputerDataImpl(scheduleId_, pinAuthCollectorHdi_)); - if (iInputerDataImpl == nullptr) { - IAM_LOGE("iInputerDataImpl is nullptr"); - return HDF_FAILURE; - } - - InputerGetDataParam param = { - .mode = mode_, - .authSubType = authSubType, - .algoVersion = algoVersion, - .algoParameter = algoParameter, - .challenge = challenge, - .inputerSetData = iInputerDataImpl, - }; + IF_FALSE_LOGE_AND_RETURN_VAL(iInputerDataImpl != nullptr, HDF_FAILURE); + param.inputerSetData = iInputerDataImpl; inputer->OnGetData(param); return HDF_SUCCESS; } diff --git a/services/modules/executors/src/pin_auth_verifier_hdi.cpp b/services/modules/executors/src/pin_auth_verifier_hdi.cpp index 53a03b0a27266c0080005f1277a74bc172c6c949..4d1a537ea00195c6c834cadaf3c585743bb32a05 100644 --- a/services/modules/executors/src/pin_auth_verifier_hdi.cpp +++ b/services/modules/executors/src/pin_auth_verifier_hdi.cpp @@ -116,6 +116,7 @@ UserAuth::ResultCode PinAuthVerifierHdi::Authenticate(uint64_t scheduleId, const .tokenId = param.tokenId, .authIntent = param.authIntent, .scheduleId = scheduleId, + .userId = param.userId, }; auto callback = sptr( new (std::nothrow) PinAuthExecutorCallbackHdi(callbackObj, executorParam, GET_DATA_MODE_NONE)); diff --git a/test/fuzztest/services/modules/executors/pinauthexecutorcallbackhdi_fuzzer/pin_auth_executor_callback_hdi_fuzzer.cpp b/test/fuzztest/services/modules/executors/pinauthexecutorcallbackhdi_fuzzer/pin_auth_executor_callback_hdi_fuzzer.cpp index 0700be3711b0d2fa9ed0f1f72e075a794a6d056d..0f67483ef56c7a4c3fe2f8b4e17a96dbe9dc6ace 100644 --- a/test/fuzztest/services/modules/executors/pinauthexecutorcallbackhdi_fuzzer/pin_auth_executor_callback_hdi_fuzzer.cpp +++ b/test/fuzztest/services/modules/executors/pinauthexecutorcallbackhdi_fuzzer/pin_auth_executor_callback_hdi_fuzzer.cpp @@ -110,10 +110,12 @@ void FuzzOnGetData(Parcel &parcel) uint64_t authSubType = static_cast(parcel.ReadUint32()); uint32_t algoVersion = parcel.ReadUint32(); std::vector challenge; + std::string pinComplexityReg; FillFuzzUint8Vector(parcel, algoParameter); FillFuzzUint8Vector(parcel, challenge); if (pinAuthExecutorCallbackHdi_ != nullptr) { - pinAuthExecutorCallbackHdi_->OnGetData(algoParameter, authSubType, algoVersion, challenge); + pinAuthExecutorCallbackHdi_->OnGetData(algoParameter, authSubType, algoVersion, challenge, + pinComplexityReg); } IAM_LOGI("end"); } diff --git a/test/unittest/src/inputer_data_impl_test.cpp b/test/unittest/src/inputer_data_impl_test.cpp index f339edcd64a6376126f39b9af9c56763db503607..58ac0c0de883968dcb7d94be7fdcd32c0190342d 100644 --- a/test/unittest/src/inputer_data_impl_test.cpp +++ b/test/unittest/src/inputer_data_impl_test.cpp @@ -58,12 +58,14 @@ sptr GetMockInputerSetData(int32_t testAuthSubType, HWTEST_F(InputerDataImplTest, CheckPinComplexity001, TestSize.Level0) { + InputerGetDataParam param = {}; + param.algoVersion = ALGO_VERSION_V2; + param.algoParameter = {1, 2, 3, 4, 5}; + param.mode = GET_DATA_MODE_NONE; constexpr int32_t testAuthSubType = 10000; - constexpr uint32_t testAlgoVersion = ALGO_VERSION_V2; - std::vector testSalt = {1, 2, 3, 4, 5}; - constexpr GetDataMode testMode = GET_DATA_MODE_NONE; #define CUSTOMIZATION_ENTERPRISE_DEVICE_MANAGEMENT_ENABLE - InputerDataImpl inputerDataImpl(testMode, testAlgoVersion, testSalt, nullptr); + InputerDataImpl inputerDataImpl(param); + std::vector testSalt = {1, 2, 3, 4, 5, 6}; int32_t result = inputerDataImpl.CheckPinComplexity(testAuthSubType, testSalt); EXPECT_EQ(result, 0); } @@ -71,11 +73,13 @@ HWTEST_F(InputerDataImplTest, CheckPinComplexity001, TestSize.Level0) HWTEST_F(InputerDataImplTest, CheckPinComplexity002, TestSize.Level0) { constexpr int32_t testAuthSubType = 10000; - constexpr uint32_t testAlgoVersion = ALGO_VERSION_V2; - std::vector testSalt = {1, 2, 3, 4, 5}; - constexpr GetDataMode testMode = GET_DATA_MODE_NONE; + InputerGetDataParam param = {}; + param.algoVersion = ALGO_VERSION_V2; + param.algoParameter = {1, 2, 3, 4, 5}; + param.mode = GET_DATA_MODE_NONE; #define CUSTOMIZATION_ENTERPRISE_DEVICE_MANAGEMENT_ENABLE - InputerDataImpl inputerDataImpl(testMode, testAlgoVersion, testSalt, nullptr); + InputerDataImpl inputerDataImpl(param); + std::vector testSalt = {1, 2, 3, 4, 5, 6}; int32_t result = inputerDataImpl.CheckPinComplexity(testAuthSubType, testSalt); EXPECT_EQ(result, 0); } @@ -83,38 +87,42 @@ HWTEST_F(InputerDataImplTest, CheckPinComplexity002, TestSize.Level0) HWTEST_F(InputerDataImplTest, OnSetDataInner001, TestSize.Level0) { constexpr int32_t testAuthSubType = 10000; - constexpr uint32_t testAlgoVersion = ALGO_VERSION_V2; - constexpr GetDataMode testMode = GET_DATA_MODE_NONE; - std::vector testSalt = {1, 2, 3, 4, 5}; + InputerGetDataParam param = {}; + param.algoVersion = ALGO_VERSION_V2; + param.algoParameter = {1, 2, 3, 4, 5}; + param.mode = GET_DATA_MODE_NONE; std::vector testSetData; constexpr int32_t testErrorCode = 14; - InputerDataImpl inputerDataImpl(testMode, testAlgoVersion, testSalt, nullptr); + InputerDataImpl inputerDataImpl(param); EXPECT_NO_THROW(inputerDataImpl.OnSetDataInner(testAuthSubType, testSetData, testErrorCode)); } HWTEST_F(InputerDataImplTest, GetPinDataTest001, TestSize.Level0) { - constexpr int32_t testAuthSubType = 10000; - constexpr uint32_t testAlgoVersion = ALGO_VERSION_V2; - constexpr GetDataMode testMode = GET_DATA_MODE_NONE; - std::vector testSalt = {1, 2, 3, 4, 5}; + InputerGetDataParam param = {}; + param.mode = GET_DATA_MODE_NONE; + param.algoVersion = ALGO_VERSION_V2; + param.authSubType = 10000; + param.algoParameter = {1, 2, 3, 4, 5}; + std::vector testData = {6, 7}; std::vector testSetData; int32_t testErrorCode = 14; - auto mockInputerSetData = GetMockInputerSetData(testAuthSubType, testSetData, testErrorCode); + auto mockInputerSetData = GetMockInputerSetData(param.authSubType, testSetData, testErrorCode); ASSERT_NE(mockInputerSetData, nullptr); - InputerDataImpl inputerDataImpl(testMode, testAlgoVersion, testSalt, mockInputerSetData); - EXPECT_NO_THROW(inputerDataImpl.GetPinData(testAuthSubType, testData, testSetData, testErrorCode)); + InputerDataImpl inputerDataImpl(param); + EXPECT_NO_THROW(inputerDataImpl.GetPinData(param.authSubType, testData, testSetData, testErrorCode)); } HWTEST_F(InputerDataImplTest, GetPinDataTest002, TestSize.Level0) { constexpr int32_t testAuthSubType = 10000; - constexpr uint32_t testAlgoVersion = ALGO_VERSION_V2; - constexpr GetDataMode testMode = GET_DATA_MODE_ALL_IN_ONE_ENROLL; - std::vector testSalt = {1, 2, 3, 4, 5}; + InputerGetDataParam param = {}; + param.algoVersion = ALGO_VERSION_V2; + param.algoParameter = {1, 2, 3, 4, 5}; + param.mode = GET_DATA_MODE_ALL_IN_ONE_ENROLL; std::vector testData = {1, 2, 3, 4, 6}; std::vector testSetData; int32_t testErrorCode = 14; @@ -122,16 +130,17 @@ HWTEST_F(InputerDataImplTest, GetPinDataTest002, TestSize.Level0) auto mockInputerSetData = GetMockInputerSetData(testAuthSubType, testSetData, testErrorCode); ASSERT_NE(mockInputerSetData, nullptr); - InputerDataImpl inputerDataImpl(testMode, testAlgoVersion, testSalt, mockInputerSetData); + InputerDataImpl inputerDataImpl(param); EXPECT_NO_THROW(inputerDataImpl.GetPinData(testAuthSubType, testData, testSetData, testErrorCode)); } HWTEST_F(InputerDataImplTest, InputerDataImplEnrollTest001, TestSize.Level0) { constexpr int32_t testAuthSubType = 10000; - constexpr uint32_t testAlgoVersion = ALGO_VERSION_V0; - constexpr GetDataMode testMode = GET_DATA_MODE_ALL_IN_ONE_ENROLL; - std::vector testSalt = {1, 2, 3, 4, 5}; + InputerGetDataParam param = {}; + param.algoVersion = ALGO_VERSION_V0; + param.algoParameter = {1, 2, 3, 4, 5}; + param.mode = GET_DATA_MODE_ALL_IN_ONE_ENROLL; std::vector testData; std::vector testSetData; int32_t testErrorCode = 14; @@ -139,59 +148,65 @@ HWTEST_F(InputerDataImplTest, InputerDataImplEnrollTest001, TestSize.Level0) auto mockInputerSetData = GetMockInputerSetData(testAuthSubType, testSetData, testErrorCode); ASSERT_NE(mockInputerSetData, nullptr); - InputerDataImpl inputerDataImpl(testMode, testAlgoVersion, testSalt, mockInputerSetData); + InputerDataImpl inputerDataImpl(param); inputerDataImpl.OnSetData(testAuthSubType, testData); } HWTEST_F(InputerDataImplTest, InputerDataImplEnrollTest002, TestSize.Level0) { constexpr int32_t testAuthSubType = 10000; - constexpr uint32_t testAlgoVersion = ALGO_VERSION_V0; - constexpr GetDataMode testMode = GET_DATA_MODE_ALL_IN_ONE_ENROLL; - std::vector testSalt = {2, 3, 4, 5, 6, 7}; + InputerGetDataParam param = {}; + param.algoVersion = ALGO_VERSION_V0; + param.algoParameter = {2, 3, 4, 5, 6, 7}; + param.mode = GET_DATA_MODE_ALL_IN_ONE_ENROLL; std::vector testData = {1, 2, 3, 4, 5, 6}; constexpr int32_t testErrorCode = 0; + std::vector testSalt = {2, 3, 4, 5, 6, 7}; Scrypt scrypt(testSalt); - std::vector testSetData = scrypt.GetScrypt(testData, testAlgoVersion); + std::vector testSetData = scrypt.GetScrypt(testData, param.algoVersion); auto mockInputerSetData = GetMockInputerSetData(testAuthSubType, testSetData, testErrorCode); ASSERT_NE(mockInputerSetData, nullptr); - InputerDataImpl inputerDataImpl(testMode, testAlgoVersion, testSalt, mockInputerSetData); + InputerDataImpl inputerDataImpl(param); inputerDataImpl.OnSetData(testAuthSubType, testData); } HWTEST_F(InputerDataImplTest, InputerDataImplEnrollTest003, TestSize.Level0) { constexpr int32_t testAuthSubType = 10000; - constexpr uint32_t testAlgoVersion = ALGO_VERSION_V1; - constexpr GetDataMode testMode = GET_DATA_MODE_ALL_IN_ONE_ENROLL; - std::vector testSalt = {3, 4, 5, 6, 7, 8}; + InputerGetDataParam param = {}; + param.algoVersion = ALGO_VERSION_V1; + param.algoParameter = {3, 4, 5, 6, 7, 8}; + param.mode = GET_DATA_MODE_ALL_IN_ONE_ENROLL; std::vector testData = {2, 3, 4, 5, 6, 7}; constexpr int32_t testErrorCode = 0; + std::vector testSalt = {2, 3, 4, 5, 6, 7}; Scrypt scrypt(testSalt); - std::vector testSetData = scrypt.GetScrypt(testData, testAlgoVersion); + std::vector testSetData = scrypt.GetScrypt(testData, param.algoVersion); auto mockInputerSetData = GetMockInputerSetData(testAuthSubType, testSetData, testErrorCode); ASSERT_NE(mockInputerSetData, nullptr); - InputerDataImpl inputerDataImpl(testMode, testAlgoVersion, testSalt, mockInputerSetData); + InputerDataImpl inputerDataImpl(param); inputerDataImpl.OnSetData(testAuthSubType, testData); } HWTEST_F(InputerDataImplTest, InputerDataImplEnrollTest004, TestSize.Level0) { constexpr int32_t testAuthSubType = 10000; - constexpr uint32_t testAlgoVersion = ALGO_VERSION_V2; - constexpr GetDataMode testMode = GET_DATA_MODE_ALL_IN_ONE_ENROLL; - std::vector testSalt = {4, 5, 6, 7, 8, 9}; + InputerGetDataParam param = {}; + param.algoVersion = ALGO_VERSION_V2; + param.algoParameter = {4, 5, 6, 7, 8, 9}; + param.mode = GET_DATA_MODE_ALL_IN_ONE_ENROLL; std::vector testData = {3, 4, 5, 6, 7, 8}; constexpr int32_t testErrorCode = 0; + std::vector testSalt = {3, 4, 5, 6, 7, 8}; Scrypt scrypt(testSalt); - std::vector testSetData = scrypt.GetScrypt(testData, testAlgoVersion); + std::vector testSetData = scrypt.GetScrypt(testData, param.algoVersion); uint8_t sha256Result[SHA256_DIGEST_LENGTH] = {}; EXPECT_EQ(SHA256(testData.data(), testData.size(), sha256Result), sha256Result); @@ -200,16 +215,16 @@ HWTEST_F(InputerDataImplTest, InputerDataImplEnrollTest004, TestSize.Level0) auto mockInputerSetData = GetMockInputerSetData(testAuthSubType, testSetData, testErrorCode); ASSERT_NE(mockInputerSetData, nullptr); - InputerDataImpl inputerDataImpl(testMode, testAlgoVersion, testSalt, mockInputerSetData); + InputerDataImpl inputerDataImpl(param); inputerDataImpl.OnSetData(testAuthSubType, testData); } HWTEST_F(InputerDataImplTest, InputerDataImplAuthTest001, TestSize.Level0) { constexpr int32_t testAuthSubType = 10000; - constexpr uint32_t testAlgoVersion = ALGO_VERSION_V0; - constexpr GetDataMode testMode = GET_DATA_MODE_ALL_IN_ONE_AUTH; - std::vector testSalt; + InputerGetDataParam param = {}; + param.algoVersion = ALGO_VERSION_V0; + param.mode = GET_DATA_MODE_ALL_IN_ONE_AUTH; std::vector testData; std::vector testSetData; constexpr int32_t testErrorCode = 14; @@ -217,44 +232,48 @@ HWTEST_F(InputerDataImplTest, InputerDataImplAuthTest001, TestSize.Level0) auto mockInputerSetData = GetMockInputerSetData(testAuthSubType, testSetData, testErrorCode); ASSERT_NE(mockInputerSetData, nullptr); - InputerDataImpl inputerDataImpl(testMode, testAlgoVersion, testSalt, mockInputerSetData); + InputerDataImpl inputerDataImpl(param); inputerDataImpl.OnSetData(testAuthSubType, testData); } HWTEST_F(InputerDataImplTest, InputerDataImplAuthTest002, TestSize.Level0) { constexpr int32_t testAuthSubType = 10000; - constexpr uint32_t testAlgoVersion = ALGO_VERSION_V0; - constexpr GetDataMode testMode = GET_DATA_MODE_ALL_IN_ONE_AUTH; - std::vector testSalt = {5, 6, 7, 8, 9, 10}; + InputerGetDataParam param = {}; + param.algoVersion = ALGO_VERSION_V0; + param.algoParameter = {5, 6, 7, 8, 9, 10}; + param.mode = GET_DATA_MODE_ALL_IN_ONE_AUTH; std::vector testData = {5, 6, 7, 8, 9, 10}; constexpr int32_t testErrorCode = 0; + std::vector testSalt = {5, 6, 7, 8, 9, 10}; Scrypt scrypt(testSalt); - std::vector testSetData = scrypt.GetScrypt(testData, testAlgoVersion); + std::vector testSetData = scrypt.GetScrypt(testData, param.algoVersion); auto mockInputerSetData = GetMockInputerSetData(testAuthSubType, testSetData, testErrorCode); ASSERT_NE(mockInputerSetData, nullptr); - InputerDataImpl inputerDataImpl(testMode, testAlgoVersion, testSalt, mockInputerSetData); + InputerDataImpl inputerDataImpl(param); inputerDataImpl.OnSetData(testAuthSubType, testData); } HWTEST_F(InputerDataImplTest, InputerDataImplAuthTest003, TestSize.Level0) { constexpr int32_t testAuthSubType = 10000; - constexpr uint32_t testAlgoVersion = ALGO_VERSION_V1; - constexpr GetDataMode testMode = GET_DATA_MODE_ALL_IN_ONE_AUTH; - std::vector testSalt = {6, 7, 8, 9, 10, 11}; + InputerGetDataParam param = {}; + param.algoVersion = ALGO_VERSION_V1; + param.algoParameter = {6, 7, 8, 9, 10, 11}; + param.mode = GET_DATA_MODE_ALL_IN_ONE_AUTH; std::vector testData = {6, 7, 8, 9, 10, 11}; constexpr int32_t testErrorCode = 0; + std::vector testSalt = {6, 7, 8, 9, 10, 11}; Scrypt scrypt(testSalt); - std::vector testSetData = scrypt.GetScrypt(testData, testAlgoVersion); + std::vector testSetData = scrypt.GetScrypt(testData, param.algoVersion); auto mockInputerSetData = GetMockInputerSetData(testAuthSubType, testSetData, testErrorCode); ASSERT_NE(mockInputerSetData, nullptr); - InputerDataImpl inputerDataImpl(testMode, testAlgoVersion, testSalt, mockInputerSetData); + InputerDataImpl inputerDataImpl(param); inputerDataImpl.OnSetData(testAuthSubType, testData); } } // namespace PinAuth diff --git a/test/unittest/src/inputer_get_data_stub_test.cpp b/test/unittest/src/inputer_get_data_stub_test.cpp index 1cf19e33b642629bb34305784dc8405dfe398095..95504760e4bfd76fd8c5f49ed86ecb70f32785ec 100644 --- a/test/unittest/src/inputer_get_data_stub_test.cpp +++ b/test/unittest/src/inputer_get_data_stub_test.cpp @@ -117,6 +117,9 @@ HWTEST_F(InputerGetDataStubTest, InputerGetDataStubTestOnGetData002, TestSize.Le HWTEST_F(InputerGetDataStubTest, OnRemoteRequestTest001, TestSize.Level0) { + int32_t userId = 1; + int32_t authIntent = 1; + std::string complexityReg = ""; int32_t testAuthSubType = 10000; std::vector testSalt = {1, 2, 3, 4, 5}; std::vector testChallenge = {2, 3, 4, 5, 6}; @@ -155,6 +158,9 @@ HWTEST_F(InputerGetDataStubTest, OnRemoteRequestTest001, TestSize.Level0) EXPECT_TRUE(data.WriteUint32(testAlgoVersion)); EXPECT_TRUE(data.WriteUInt8Vector(testSalt)); EXPECT_TRUE(data.WriteUInt8Vector(testChallenge)); + EXPECT_TRUE(data.WriteInt32(userId)); + EXPECT_TRUE(data.WriteString(complexityReg)); + EXPECT_TRUE(data.WriteInt32(authIntent)); ASSERT_NE(tempInputerSetData->AsObject(), nullptr); EXPECT_TRUE(data.WriteRemoteObject(tempInputerSetData->AsObject())); diff --git a/test/unittest/src/pin_auth_executor_callback_hdi_unit_test.cpp b/test/unittest/src/pin_auth_executor_callback_hdi_unit_test.cpp index 1fca4c73ce2f530784e25f3d2189a15e0811663b..9396fdc748b4ba0e40c02297afc0359fcd13fb26 100644 --- a/test/unittest/src/pin_auth_executor_callback_hdi_unit_test.cpp +++ b/test/unittest/src/pin_auth_executor_callback_hdi_unit_test.cpp @@ -76,7 +76,8 @@ HWTEST_F(PinAuthExecutorCallbackHdiUnitTest, PinAuthExecutorCallback_OnGetData_0 uint64_t authSubType = 0; uint32_t algoVersion = 0; std::vector challenge = {1, 2, 3, 4, 5}; - + std::string pinComplexityReg = {}; + PinAuthExecutorCallbackHdi callbackHdi( executeCallback, pinAuthCollectorHdi, executorParam, GET_DATA_MODE_COLLECTOR); sptr inputer(new (std::nothrow) MockInputerGetData()); @@ -84,7 +85,7 @@ HWTEST_F(PinAuthExecutorCallbackHdiUnitTest, PinAuthExecutorCallback_OnGetData_0 PinAuthManager::GetInstance().pinAuthInputerMap_.emplace(tempTokenId, inputer); callbackHdi.pinAuthAllInOneHdi_ = nullptr; callbackHdi.pinAuthCollectorHdi_ = nullptr; - EXPECT_EQ(callbackHdi.OnGetData(algoParameter, authSubType, algoVersion, challenge), HDF_FAILURE); + EXPECT_EQ(callbackHdi.OnGetData(algoParameter, authSubType, algoVersion, challenge, pinComplexityReg), HDF_FAILURE); } HWTEST_F(PinAuthExecutorCallbackHdiUnitTest, PinAuthExecutorCallback_OnGetData_004, TestSize.Level0) @@ -102,13 +103,14 @@ HWTEST_F(PinAuthExecutorCallbackHdiUnitTest, PinAuthExecutorCallback_OnGetData_0 uint64_t authSubType = 0; uint32_t algoVersion = 0; std::vector challenge = {1, 2, 3, 4, 5}; + std::string pinComplexityReg = {}; PinAuthExecutorCallbackHdi callbackHdi( executeCallback, pinAuthCollectorHdi, executorParam, GET_DATA_MODE_COLLECTOR); sptr inputer(new (std::nothrow) MockInputerGetData()); callbackHdi.tokenId_ = tempTokenId; PinAuthManager::GetInstance().pinAuthInputerMap_.emplace(tempTokenId, inputer); - EXPECT_EQ(callbackHdi.OnGetData(algoParameter, authSubType, algoVersion, challenge), HDF_SUCCESS); + EXPECT_EQ(callbackHdi.OnGetData(algoParameter, authSubType, algoVersion, challenge, pinComplexityReg), HDF_SUCCESS); } HWTEST_F(PinAuthExecutorCallbackHdiUnitTest, PinAuthExecutorCallback_OnGetData_003, TestSize.Level0) @@ -129,12 +131,13 @@ HWTEST_F(PinAuthExecutorCallbackHdiUnitTest, PinAuthExecutorCallback_OnGetData_0 uint64_t authSubType = 0; uint32_t algoVersion = 0; std::vector challenge = {1, 2, 3, 4, 5}; + std::string pinComplexityReg = {}; sptr inputer(new (std::nothrow) MockInputerGetData()); callbackHdi.tokenId_ = tempTokenId; PinAuthManager::GetInstance().pinAuthInputerMap_.emplace(tempTokenId, inputer); - EXPECT_EQ(callbackHdi.OnGetData(algoParameter, authSubType, algoVersion, challenge), HDF_SUCCESS); + EXPECT_EQ(callbackHdi.OnGetData(algoParameter, authSubType, algoVersion, challenge, pinComplexityReg), HDF_SUCCESS); } @@ -236,7 +239,9 @@ HWTEST_F(PinAuthExecutorCallbackHdiUnitTest, PinAuthExecutorCallback_OnGetData_0 uint64_t authSubType = 0; uint32_t algoVersion = 0; std::vector challenge = {1, 2, 3, 4, 5}; - EXPECT_EQ(callbackHdi.OnGetData(algoParameter, authSubType, algoVersion, challenge), HDF_SUCCESS); + std::string pinComplexityReg = {}; + EXPECT_EQ(callbackHdi.OnGetData(algoParameter, authSubType, algoVersion, challenge, pinComplexityReg), + HDF_SUCCESS); } HWTEST_F(PinAuthExecutorCallbackHdiUnitTest, PinAuthExecutorCallback_OnResult_001, TestSize.Level0)