diff --git a/common/utils/iam_defines.h b/common/utils/iam_defines.h index 475221308..c448e0201 100644 --- a/common/utils/iam_defines.h +++ b/common/utils/iam_defines.h @@ -22,6 +22,8 @@ namespace OHOS { namespace UserIam { namespace UserAuth { const int32_t INVALID_AUTH_TYPE = -1; +const int32_t INNER_API_VERSION_10000 = 10000; + #define IAM_TRY(action0, action1) \ do { \ try { \ diff --git a/sa_profile/useriam.cfg b/sa_profile/useriam.cfg index 54ab44854..e18c7281d 100644 --- a/sa_profile/useriam.cfg +++ b/sa_profile/useriam.cfg @@ -9,7 +9,8 @@ "ohos.permission.ACCESS_AUTH_RESPOOL", "ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION", "ohos.permission.MANAGE_LOCAL_ACCOUNTS", - "ohos.permission.VIBRATE" + "ohos.permission.VIBRATE", + "ohos.permission.GET_RUNNING_INFO" ], "permission_acls" : [ "ohos.permission.ACCESS_AUTH_RESPOOL", diff --git a/services/base/inc/user_auth_hdi.h b/services/base/inc/user_auth_hdi.h index e6aa557b4..079c46ada 100644 --- a/services/base/inc/user_auth_hdi.h +++ b/services/base/inc/user_auth_hdi.h @@ -34,11 +34,13 @@ using HdiExecutorRegisterInfo = OHOS::HDI::UserAuth::V1_2::ExecutorRegisterInfo; using HdiExecutorInfo = OHOS::HDI::UserAuth::V1_2::ExecutorInfo; using HdiScheduleInfoV1_0 = OHOS::HDI::UserAuth::V1_2::ScheduleInfo; using HdiScheduleInfo = OHOS::HDI::UserAuth::V1_2::ScheduleInfoV1_1; -using HdiAuthSolution = OHOS::HDI::UserAuth::V1_2::AuthSolution; +using HdiAuthSolutionV1_0 = OHOS::HDI::UserAuth::V1_2::AuthSolution; +using HdiAuthSolution = OHOS::HDI::UserAuth::V1_2::AuthSolutionV1_2; using HdiExecutorSendMsg = OHOS::HDI::UserAuth::V1_2::ExecutorSendMsg; using HdiAuthResultInfo = OHOS::HDI::UserAuth::V1_2::AuthResultInfo; using HdiIdentifyResultInfo = OHOS::HDI::UserAuth::V1_2::IdentifyResultInfo; -using HdiEnrollParam = OHOS::HDI::UserAuth::V1_2::EnrollParam; +using HdiEnrollParamV1_0 = OHOS::HDI::UserAuth::V1_2::EnrollParam; +using HdiEnrollParam = OHOS::HDI::UserAuth::V1_2::EnrollParamV1_2; using HdiCredentialInfo = OHOS::HDI::UserAuth::V1_2::CredentialInfo; using HdiEnrolledInfo = OHOS::HDI::UserAuth::V1_2::EnrolledInfo; using HdiEnrollResultInfo = OHOS::HDI::UserAuth::V1_2::EnrollResultInfo; diff --git a/services/context/inc/context_callback.h b/services/context/inc/context_callback.h index a1ebdcda8..7a26f7b2b 100644 --- a/services/context/inc/context_callback.h +++ b/services/context/inc/context_callback.h @@ -67,7 +67,6 @@ public: virtual void OnResult(int32_t resultCode, const Attributes &finalResult) = 0; virtual void OnAcquireInfo(ExecutorRole src, int32_t moduleType, const std::vector &acquireMsg) const = 0; virtual void SetTraceCallerName(std::string callerName) = 0; - virtual std::string GetTraceCallerName() = 0; virtual void SetTraceRequestContextId(uint64_t requestContextId) = 0; virtual void SetTraceAuthContextId(uint64_t authContextId) = 0; virtual void SetTraceUserId(int32_t userId) = 0; diff --git a/services/context/inc/context_factory.h b/services/context/inc/context_factory.h index 0e44768f8..7c05d4f6c 100644 --- a/services/context/inc/context_factory.h +++ b/services/context/inc/context_factory.h @@ -22,23 +22,17 @@ #include #include "singleton.h" +#include "authentication_impl.h" +#include "enrollment_impl.h" #include "context.h" #include "context_callback.h" +#include "identification_impl.h" namespace OHOS { namespace UserIam { namespace UserAuth { class ContextFactory : public DelayedSingleton { public: - struct AuthContextPara { - int32_t userId {0}; - AuthType authType {ALL}; - AuthTrustLevel atl {ATL1}; - uint32_t tokenId {0}; - std::vector challenge; - bool endAfterFirstFail; - }; - struct AuthWidgetContextPara { struct AuthProfile { int32_t pinSubType {0}; @@ -48,34 +42,21 @@ public: }; int32_t userId {0}; + int32_t sdkVersion {0}; uint32_t tokenId {0}; std::string callingBundleName {""}; + std::string callerName {""}; std::vector challenge {}; std::vector authTypeList {}; AuthTrustLevel atl {ATL1}; WidgetParam widgetParam {}; std::map authProfileMap {}; }; - - struct IdentifyContextPara { - AuthType authType {ALL}; - uint32_t tokenId {0}; - std::vector challenge; - }; - - struct EnrollContextPara { - int32_t userId {0}; - AuthType authType {ALL}; - PinSubType pinType {PIN_SIX}; - bool isUpdate {false}; - uint32_t tokenId {0}; - std::vector token; - }; - static std::shared_ptr CreateSimpleAuthContext(const AuthContextPara ¶, + static std::shared_ptr CreateSimpleAuthContext(const Authentication::AuthenticationPara ¶, const std::shared_ptr &callback); - static std::shared_ptr CreateIdentifyContext(const IdentifyContextPara ¶, + static std::shared_ptr CreateIdentifyContext(const Identification::IdentificationPara ¶, const std::shared_ptr &callback); - static std::shared_ptr CreateEnrollContext(const EnrollContextPara ¶, + static std::shared_ptr CreateEnrollContext(const Enrollment::EnrollmentPara ¶, const std::shared_ptr &callback); static std::shared_ptr CreateWidgetAuthContext(std::shared_ptr callback); static std::shared_ptr CreateWidgetContext(const AuthWidgetContextPara ¶, diff --git a/services/context/src/context_callback_impl.cpp b/services/context/src/context_callback_impl.cpp index 22dd3898e..50b0722a2 100644 --- a/services/context/src/context_callback_impl.cpp +++ b/services/context/src/context_callback_impl.cpp @@ -88,15 +88,6 @@ void ContextCallbackImpl::SetTraceCallerName(std::string callerName) metaData_.callerName = callerName; } -std::string ContextCallbackImpl::GetTraceCallerName() -{ - if (!metaData_.callerName.has_value()) { - IAM_LOGI("metaData callerName is null"); - return ""; - } - return metaData_.callerName.value(); -} - void ContextCallbackImpl::SetTraceRequestContextId(uint64_t requestContextId) { metaData_.requestContextId = requestContextId; diff --git a/services/context/src/context_callback_impl.h b/services/context/src/context_callback_impl.h index c720a2301..9452afa0a 100644 --- a/services/context/src/context_callback_impl.h +++ b/services/context/src/context_callback_impl.h @@ -31,7 +31,6 @@ public: void OnResult(int32_t resultCode, const Attributes &finalResult) override; void OnAcquireInfo(ExecutorRole src, int32_t moduleType, const std::vector &acquireMsg) const override; void SetTraceCallerName(std::string callerName) override; - std::string GetTraceCallerName() override; void SetTraceRequestContextId(uint64_t requestContextId) override; void SetTraceAuthContextId(uint64_t authContextId) override; void SetTraceUserId(int32_t userId) override; diff --git a/services/context/src/context_factory.cpp b/services/context/src/context_factory.cpp index b8ecdde23..5636ff9d6 100644 --- a/services/context/src/context_factory.cpp +++ b/services/context/src/context_factory.cpp @@ -14,15 +14,12 @@ */ #include "context_factory.h" -#include "authentication_impl.h" #include "context_callback_impl.h" #include "context_pool.h" #include "enroll_context.h" -#include "enrollment_impl.h" #include "iam_check.h" #include "iam_logger.h" #include "iam_ptr.h" -#include "identification_impl.h" #include "identify_context.h" #include "simple_auth_context.h" #include "widget_context.h" @@ -32,12 +29,12 @@ namespace OHOS { namespace UserIam { namespace UserAuth { -std::shared_ptr ContextFactory::CreateSimpleAuthContext(const AuthContextPara ¶, +std::shared_ptr ContextFactory::CreateSimpleAuthContext(const Authentication::AuthenticationPara ¶, const std::shared_ptr &callback) { IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, nullptr); uint64_t newContextId = ContextPool::GetNewContextId(); - auto auth = Common::MakeShared(newContextId, para.userId, para.authType, para.atl); + auto auth = Common::MakeShared(newContextId, para); IF_FALSE_LOGE_AND_RETURN_VAL(auth != nullptr, nullptr); auth->SetChallenge(para.challenge); auth->SetAccessTokenId(para.tokenId); @@ -45,7 +42,7 @@ std::shared_ptr ContextFactory::CreateSimpleAuthContext(const AuthConte return Common::MakeShared(newContextId, auth, callback); } -std::shared_ptr ContextFactory::CreateIdentifyContext(const IdentifyContextPara ¶, +std::shared_ptr ContextFactory::CreateIdentifyContext(const Identification::IdentificationPara ¶, const std::shared_ptr &callback) { IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, nullptr); @@ -57,12 +54,12 @@ std::shared_ptr ContextFactory::CreateIdentifyContext(const IdentifyCon return Common::MakeShared(newContextId, identify, callback); } -std::shared_ptr ContextFactory::CreateEnrollContext(const EnrollContextPara ¶, +std::shared_ptr ContextFactory::CreateEnrollContext(const Enrollment::EnrollmentPara ¶, const std::shared_ptr &callback) { IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, nullptr); uint64_t newContextId = ContextPool::GetNewContextId(); - auto enroll = Common::MakeShared(para.userId, para.authType); + auto enroll = Common::MakeShared(para); IF_FALSE_LOGE_AND_RETURN_VAL(enroll != nullptr, nullptr); enroll->SetAuthToken(para.token); enroll->SetAccessTokenId(para.tokenId); diff --git a/services/context/src/widget_context.cpp b/services/context/src/widget_context.cpp index 8d4a321ff..7add7f4f9 100644 --- a/services/context/src/widget_context.cpp +++ b/services/context/src/widget_context.cpp @@ -126,7 +126,7 @@ std::shared_ptr WidgetContext::GetAuthContextCallback(AuthType iamCallback->OnResult(ResultCode::GENERAL_ERROR, extraInfo); return nullptr; } - widgetCallback->SetTraceCallerName(callerCallback_->GetTraceCallerName()); + widgetCallback->SetTraceCallerName(para_.callerName); widgetCallback->SetTraceRequestContextId(contextId_); widgetCallback->SetTraceAuthTrustLevel(authTrustLevel); widgetCallback->SetTraceAuthType(authType); @@ -146,13 +146,15 @@ std::shared_ptr WidgetContext::BuildTask(const std::vector &ch auto widgetCallback = GetAuthContextCallback(authType, authTrustLevel, iamCallback); IF_FALSE_LOGE_AND_RETURN_VAL(widgetCallback != nullptr, nullptr); - ContextFactory::AuthContextPara para = {}; + Authentication::AuthenticationPara para = {}; para.tokenId = tokenId; para.userId = userId; para.authType = authType; para.atl = authTrustLevel; para.challenge = challenge; para.endAfterFirstFail = true; + para.callerName = para_.callerName; + para.sdkVersion = para_.sdkVersion; auto context = ContextFactory::CreateSimpleAuthContext(para, widgetCallback); if (context == nullptr || !ContextPool::Instance().Insert(context)) { IAM_LOGE("failed to insert context"); diff --git a/services/core/inc/auth_widget_helper.h b/services/core/inc/auth_widget_helper.h index ee0e214ee..f5a9c6414 100644 --- a/services/core/inc/auth_widget_helper.h +++ b/services/core/inc/auth_widget_helper.h @@ -24,8 +24,7 @@ namespace UserIam { namespace UserAuth { class AuthWidgetHelper { public: - static bool InitWidgetContextParam( - int32_t userId, const AuthParam &authParam, std::vector &validType, + static bool InitWidgetContextParam(const AuthParam &authParam, std::vector &validType, const WidgetParam &widgetParam, ContextFactory::AuthWidgetContextPara ¶); static int32_t CheckValidSolution(int32_t userId, const std::vector &authTypeList, const AuthTrustLevel &atl, std::vector &validTypeList); diff --git a/services/core/inc/authentication.h b/services/core/inc/authentication.h index dbba5203d..2882da885 100644 --- a/services/core/inc/authentication.h +++ b/services/core/inc/authentication.h @@ -26,6 +26,17 @@ namespace UserIam { namespace UserAuth { class Authentication { public: + struct AuthenticationPara { + int32_t userId {0}; + AuthType authType {ALL}; + AuthTrustLevel atl {ATL1}; + uint32_t tokenId {0}; + std::vector challenge; + bool endAfterFirstFail; + std::string callerName; + int32_t sdkVersion; + }; + struct AuthResultInfo { int32_t result; int32_t freezingTime; diff --git a/services/core/inc/enrollment.h b/services/core/inc/enrollment.h index 46c8c7354..be190f57b 100644 --- a/services/core/inc/enrollment.h +++ b/services/core/inc/enrollment.h @@ -28,6 +28,17 @@ namespace UserIam { namespace UserAuth { class Enrollment { public: + struct EnrollmentPara { + int32_t userId {0}; + AuthType authType {ALL}; + PinSubType pinType {PIN_SIX}; + bool isUpdate {false}; + uint32_t tokenId {0}; + std::vector token; + std::string callerName; + int32_t sdkVersion; + }; + virtual ~Enrollment() = default; virtual void SetExecutorSensorHint(uint32_t executorSensorHint) = 0; diff --git a/services/core/inc/identification.h b/services/core/inc/identification.h index 41a51e13f..9e9caea7c 100644 --- a/services/core/inc/identification.h +++ b/services/core/inc/identification.h @@ -26,11 +26,17 @@ namespace UserIam { namespace UserAuth { class Identification { public: + struct IdentificationPara { + AuthType authType {ALL}; + uint32_t tokenId {0}; + std::vector challenge; + }; struct IdentifyResultInfo { int32_t result; int32_t userId; std::vector token; }; + virtual ~Identification() = default; virtual void SetExecutor(uint32_t executorIndex) = 0; diff --git a/services/core/src/auth_widget_helper.cpp b/services/core/src/auth_widget_helper.cpp index 1b754a7c4..92542243d 100644 --- a/services/core/src/auth_widget_helper.cpp +++ b/services/core/src/auth_widget_helper.cpp @@ -26,13 +26,12 @@ namespace OHOS { namespace UserIam { namespace UserAuth { -bool AuthWidgetHelper::InitWidgetContextParam( - int32_t userId, const AuthParam &authParam, std::vector &validType, +bool AuthWidgetHelper::InitWidgetContextParam(const AuthParam &authParam, std::vector &validType, const WidgetParam &widgetParam, ContextFactory::AuthWidgetContextPara ¶) { for (auto &authType : validType) { ContextFactory::AuthWidgetContextPara::AuthProfile profile; - if (!GetUserAuthProfile(userId, authType, profile)) { + if (!GetUserAuthProfile(para.userId, authType, profile)) { IAM_LOGE("get user auth profile failed"); return false; } @@ -43,7 +42,6 @@ bool AuthWidgetHelper::InitWidgetContextParam( WidgetClient::Instance().SetSensorInfo(profile.sensorInfo); } } - para.userId = userId; para.challenge = std::move(authParam.challenge); para.authTypeList = std::move(validType); para.atl = authParam.authTrustLevel; diff --git a/services/core/src/authentication_impl.cpp b/services/core/src/authentication_impl.cpp index efb11ea64..7226c5fe1 100644 --- a/services/core/src/authentication_impl.cpp +++ b/services/core/src/authentication_impl.cpp @@ -23,11 +23,8 @@ namespace OHOS { namespace UserIam { namespace UserAuth { -AuthenticationImpl::AuthenticationImpl(uint64_t contextId, int32_t userId, AuthType authType, AuthTrustLevel atl) - : contextId_(contextId), - userId_(userId), - authType_(authType), - atl_(atl) +AuthenticationImpl::AuthenticationImpl(uint64_t contextId, const AuthenticationPara &authPara) + : contextId_(contextId), authPara_(authPara) { } @@ -81,22 +78,25 @@ std::vector AuthenticationImpl::GetAuthExecutor bool AuthenticationImpl::Start(std::vector> &scheduleList, std::shared_ptr callback) { - IAM_LOGE("UserId:%{public}d AuthType:%{public}d ATL:%{public}u", userId_, authType_, atl_); + IAM_LOGE("UserId:%{public}d AuthType:%{public}d ATL:%{public}u", authPara_.userId, authPara_.authType, + authPara_.atl); auto hdi = HdiWrapper::GetHdiInstance(); if (!hdi) { IAM_LOGE("bad hdi"); return false; } HdiAuthSolution solution = { - .userId = userId_, - .authTrustLevel = atl_, - .authType = static_cast(authType_), + .userId = authPara_.userId, + .authTrustLevel = authPara_.atl, + .authType = static_cast(authPara_.authType), .executorSensorHint = executorSensorHint, .challenge = challenge_, + .callerName = authPara_.callerName, + .apiVersion = authPara_.sdkVersion, }; std::vector infos; IamHitraceHelper traceHelper("hdi BeginAuthentication"); - auto result = hdi->BeginAuthenticationV1_1(contextId_, solution, infos); + auto result = hdi->BeginAuthenticationV1_2(contextId_, solution, infos); if (result != HDF_SUCCESS) { IAM_LOGE("hdi BeginAuthentication failed, err is %{public}d", result); SetLatestError(result); diff --git a/services/core/src/authentication_impl.h b/services/core/src/authentication_impl.h index 15dda2793..6f4b36577 100644 --- a/services/core/src/authentication_impl.h +++ b/services/core/src/authentication_impl.h @@ -27,7 +27,7 @@ namespace UserIam { namespace UserAuth { class AuthenticationImpl final : public Authentication, public NoCopyable { public: - AuthenticationImpl(uint64_t contextId, int32_t userId, AuthType authType, AuthTrustLevel atl); + AuthenticationImpl(uint64_t contextId, const AuthenticationPara &authPara); ~AuthenticationImpl() override; void SetExecutor(uint32_t executorIndex) override; @@ -48,9 +48,7 @@ protected: private: uint64_t contextId_; - int32_t userId_; - AuthType authType_; - AuthTrustLevel atl_; + AuthenticationPara authPara_; bool endAfterFirstFail_ {false}; uint32_t executorSensorHint {0}; diff --git a/services/core/src/enrollment_impl.cpp b/services/core/src/enrollment_impl.cpp index 39f53c9a4..2d1014597 100644 --- a/services/core/src/enrollment_impl.cpp +++ b/services/core/src/enrollment_impl.cpp @@ -28,7 +28,8 @@ namespace OHOS { namespace UserIam { namespace UserAuth { -EnrollmentImpl::EnrollmentImpl(int32_t userId, AuthType authType) : userId_(userId), authType_(authType) +EnrollmentImpl::EnrollmentImpl(EnrollmentPara enrollPara) + : enrollPara_(enrollPara) { } @@ -82,7 +83,7 @@ void EnrollmentImpl::SetIsUpdate(bool isUpdate) bool EnrollmentImpl::Start(std::vector> &scheduleList, std::shared_ptr callback) { - IAM_LOGE("UserId:%{public}d AuthType:%{public}d", userId_, authType_); + IAM_LOGE("UserId:%{public}d AuthType:%{public}d", enrollPara_.userId, enrollPara_.authType); auto hdi = HdiWrapper::GetHdiInstance(); if (!hdi) { IAM_LOGE("bad hdi"); @@ -96,11 +97,13 @@ bool EnrollmentImpl::Start(std::vector> &scheduleL HdiScheduleInfo info = {}; HdiEnrollParam param = { - .authType = static_cast(authType_), + .authType = static_cast(enrollPara_.authType), .executorSensorHint = executorSensorHint_, + .callerName = enrollPara_.callerName, + .apiVersion = enrollPara_.sdkVersion, }; IamHitraceHelper traceHelper("hdi BeginEnrollment"); - auto result = hdi->BeginEnrollmentV1_1(userId_, authToken_, param, info); + auto result = hdi->BeginEnrollmentV1_2(enrollPara_.userId, authToken_, param, info); if (result != HDF_SUCCESS) { IAM_LOGE("hdi BeginEnrollment failed, err is %{public}d", result); SetLatestError(result); @@ -125,11 +128,11 @@ bool EnrollmentImpl::Start(std::vector> &scheduleL bool EnrollmentImpl::GetSecUserId(std::optional &secUserId) { secUserId = std::nullopt; - if (authType_ != PIN) { + if (enrollPara_.authType != PIN) { IAM_LOGI("no need return sec user id"); return true; } - auto userInfo = UserIdmDatabase::Instance().GetSecUserInfo(userId_); + auto userInfo = UserIdmDatabase::Instance().GetSecUserInfo(enrollPara_.userId); if (userInfo != nullptr) { secUserId = userInfo->GetSecUserId(); return true; @@ -140,9 +143,9 @@ bool EnrollmentImpl::GetSecUserId(std::optional &secUserId) return false; } - IAM_LOGE("current user id %{public}d get fail", userId_); + IAM_LOGE("current user id %{public}d get fail", enrollPara_.userId); std::vector> credInfos; - if (UserIdmDatabase::Instance().DeleteUserEnforce(userId_, credInfos) != SUCCESS) { + if (UserIdmDatabase::Instance().DeleteUserEnforce(enrollPara_.userId, credInfos) != SUCCESS) { IAM_LOGE("failed to enforce delete user"); } return false; @@ -159,13 +162,14 @@ bool EnrollmentImpl::Update(const std::vector &scheduleResult, uint64_t } HdiEnrollResultInfo resultInfo = {}; - auto result = hdi->UpdateEnrollmentResult(userId_, scheduleResult, resultInfo); + auto result = hdi->UpdateEnrollmentResult(enrollPara_.userId, scheduleResult, resultInfo); if (result != HDF_SUCCESS) { - IAM_LOGE("hdi UpdateEnrollmentResult failed, err is %{public}d, userId is %{public}d", result, userId_); + IAM_LOGE("hdi UpdateEnrollmentResult failed, err is %{public}d, userId is %{public}d", result, + enrollPara_.userId); SetLatestError(result); return false; } - IAM_LOGI("hdi UpdateEnrollmentResult success, userId is %{public}d", userId_); + IAM_LOGI("hdi UpdateEnrollmentResult success, userId is %{public}d", enrollPara_.userId); credentialId = resultInfo.credentialId; rootSecret = resultInfo.rootSecret; @@ -181,7 +185,7 @@ bool EnrollmentImpl::Update(const std::vector &scheduleResult, uint64_t return true; } - info = Common::MakeShared(userId_, resultInfo.oldInfo); + info = Common::MakeShared(enrollPara_.userId, resultInfo.oldInfo); if (info == nullptr) { IAM_LOGE("bad alloc"); return false; @@ -202,7 +206,7 @@ bool EnrollmentImpl::Cancel() return false; } - auto result = hdi->CancelEnrollment(userId_); + auto result = hdi->CancelEnrollment(enrollPara_.userId); if (result != HDF_SUCCESS) { IAM_LOGE("hdi CancelEnrollment failed, err is %{public}d", result); SetLatestError(result); diff --git a/services/core/src/enrollment_impl.h b/services/core/src/enrollment_impl.h index f0f1e8a13..d420a8eb0 100644 --- a/services/core/src/enrollment_impl.h +++ b/services/core/src/enrollment_impl.h @@ -27,7 +27,7 @@ namespace UserIam { namespace UserAuth { class EnrollmentImpl final : public Enrollment, public NoCopyable { public: - EnrollmentImpl(int32_t userId, AuthType authType); + explicit EnrollmentImpl(EnrollmentPara enrollPara); ~EnrollmentImpl() override; void SetExecutorSensorHint(uint32_t executorSensorHint) override; @@ -51,8 +51,7 @@ protected: private: bool GetSecUserId(std::optional &secUserId); - int32_t userId_; - AuthType authType_; + EnrollmentPara enrollPara_; std::vector authToken_; std::optional secUserId_ {std::nullopt}; diff --git a/services/ipc/BUILD.gn b/services/ipc/BUILD.gn index 1fc1a0f73..2a62a490f 100644 --- a/services/ipc/BUILD.gn +++ b/services/ipc/BUILD.gn @@ -55,6 +55,7 @@ ohos_source_set("userauth_services_ipc") { ] external_deps = [ + "ability_runtime:app_manager", "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", "c_utils:utils", diff --git a/services/ipc/inc/ipc_common.h b/services/ipc/inc/ipc_common.h index 13a7f866c..b126ec783 100644 --- a/services/ipc/inc/ipc_common.h +++ b/services/ipc/inc/ipc_common.h @@ -42,13 +42,13 @@ class IpcCommon final : public NoCopyable { public: using Recipient = std::function; static int32_t GetCallingUserId(IPCObjectStub &stub, int32_t &userId); - static bool GetCallingBundleName(IPCObjectStub &stub, std::string &bundleName); static int32_t GetActiveUserId(std::optional &userId); static int32_t GetAllUserId(std::vector &userIds); static bool CheckPermission(IPCObjectStub &stub, Permission permission); static uint32_t GetAccessTokenId(IPCObjectStub &stub); static uint32_t GetTokenId(IPCObjectStub &stub); - static std::string GetCallerName(IPCObjectStub &stub); + static bool GetCallerName(IPCObjectStub &stub, bool &isBundleName, std::string &callerName); + static bool CheckForegroundApplication(const std::string &bundleName); class PeerDeathRecipient final : public IPCObjectProxy::DeathRecipient { public: explicit PeerDeathRecipient(Recipient &&recipient) : recipient_(std::forward(recipient)) diff --git a/services/ipc/inc/user_auth_service.h b/services/ipc/inc/user_auth_service.h index 017f272be..af9222d52 100644 --- a/services/ipc/inc/user_auth_service.h +++ b/services/ipc/inc/user_auth_service.h @@ -70,12 +70,15 @@ private: int32_t CheckAuthWidgetType(const std::vector &authType); int32_t CheckAuthWidgetParam( int32_t userId, const AuthParam &authParam, const WidgetParam &widgetParam, std::vector &validType); - uint64_t StartWidgetContext(int32_t userId, const std::shared_ptr &contextCallback, - const AuthParam &authParam, const WidgetParam &widgetParam, std::vector &validType); - uint64_t StartAuthContext(int32_t apiVersion, ContextFactory::AuthContextPara para, + uint64_t StartWidgetContext(const std::shared_ptr &contextCallback, const AuthParam &authParam, + const WidgetParam &widgetParam, std::vector &validType, + ContextFactory::AuthWidgetContextPara ¶); + uint64_t StartAuthContext(int32_t apiVersion, Authentication::AuthenticationPara para, const std::shared_ptr &contextCallback); bool Insert2ContextPool(const std::shared_ptr &context); bool CheckCallerIsSystemApp(); + int32_t CheckAuthPermissionAndParam(int32_t authType, bool isBundleName, const std::string &callerName, + AuthTrustLevel authTrustLevel); }; } // namespace UserAuth } // namespace UserIam diff --git a/services/ipc/src/ipc_common.cpp b/services/ipc/src/ipc_common.cpp index f9e43fd73..ca4ee2cc8 100644 --- a/services/ipc/src/ipc_common.cpp +++ b/services/ipc/src/ipc_common.cpp @@ -16,8 +16,11 @@ #include "ipc_common.h" #include "ipc_skeleton.h" #include "accesstoken_kit.h" +#include "app_mgr_interface.h" #include "iam_common_defines.h" #include "iam_logger.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" #include "tokenid_kit.h" #ifdef HAS_OS_ACCOUNT_PART #include "os_account_manager.h" @@ -71,26 +74,6 @@ int32_t IpcCommon::GetCallingUserId(IPCObjectStub &stub, int32_t &userId) return SUCCESS; } -bool IpcCommon::GetCallingBundleName(IPCObjectStub &stub, std::string &bundleName) -{ - uint32_t tokenId = GetAccessTokenId(stub); - using namespace Security::AccessToken; - ATokenTypeEnum callingType = AccessTokenKit::GetTokenTypeFlag(tokenId); - if (callingType != TOKEN_HAP) { - IAM_LOGE("the caller is not a hap"); - return false; - } - HapTokenInfo hapTokenInfo; - int result = AccessTokenKit::GetHapTokenInfo(tokenId, hapTokenInfo); - if (result != SUCCESS) { - IAM_LOGE("failed to get hap token info, result = %{public}d", result); - return false; - } - bundleName = hapTokenInfo.bundleName; - IAM_LOGI("get callingInfo, bundleName is %{public}s", bundleName.c_str()); - return true; -} - int32_t IpcCommon::GetActiveUserId(std::optional &userId) { if (userId.has_value() && userId.value() != 0) { @@ -137,6 +120,31 @@ int32_t IpcCommon::GetAllUserId(std::vector &userIds) return SUCCESS; } +bool IpcCommon::CheckForegroundApplication(const std::string &bundleName) +{ + sptr samgrClient = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgrClient == nullptr) { + IAM_LOGI("Get system ability manager failed"); + return false; + } + sptr iAppManager = + iface_cast(samgrClient->GetSystemAbility(APP_MGR_SERVICE_ID)); + if (iAppManager == nullptr) { + IAM_LOGI("Failed to get ability manager service"); + return false; + } + std::vector foregroundAppList; + iAppManager->GetForegroundApplications(foregroundAppList); + auto it = std::find_if(foregroundAppList.begin(), foregroundAppList.end(), [bundleName] (auto foregroundApp) { + return bundleName.compare(foregroundApp.bundleName) == 0; + }); + if (it == foregroundAppList.end()) { + IAM_LOGI("app : %{public}s is not foreground", bundleName.c_str()); + return false; + } + return true; +} + bool IpcCommon::CheckPermission(IPCObjectStub &stub, Permission permission) { switch (permission) { @@ -270,27 +278,37 @@ bool IpcCommon::CheckCallerIsSystemApp(IPCObjectStub &stub) return false; } -std::string IpcCommon::GetCallerName(IPCObjectStub &stub) +bool IpcCommon::GetCallerName(IPCObjectStub &stub, bool &isBundleName, std::string &callerName) { - std::string callerName = ""; - if (GetCallingBundleName(stub, callerName)) { - return callerName; - } uint32_t tokenId = GetAccessTokenId(stub); using namespace Security::AccessToken; ATokenTypeEnum callingType = AccessTokenKit::GetTokenTypeFlag(tokenId); - if (callingType != TOKEN_NATIVE) { - IAM_LOGE("the caller is not a native service"); - return callerName; + if (callingType == TOKEN_HAP) { + isBundleName = true; + HapTokenInfo hapTokenInfo; + int result = AccessTokenKit::GetHapTokenInfo(tokenId, hapTokenInfo); + if (result != SUCCESS) { + IAM_LOGE("failed to get hap token info, result = %{public}d", result); + return false; + } + callerName = hapTokenInfo.bundleName; + IAM_LOGI("caller bundleName is %{public}s", callerName.c_str()); + return true; + } else if (callingType == TOKEN_NATIVE) { + isBundleName = false; + NativeTokenInfo nativeTokenInfo; + int res = AccessTokenKit::GetNativeTokenInfo(tokenId, nativeTokenInfo); + if (res != SUCCESS) { + IAM_LOGE("failed to get native token info, res = %{public}d", res); + return false; + } + callerName = nativeTokenInfo.processName; + IAM_LOGI("caller processName is %{public}s", callerName.c_str()); + return true; } - NativeTokenInfo nativeTokenInfo; - int res = AccessTokenKit::GetNativeTokenInfo(tokenId, nativeTokenInfo); - if (res != SUCCESS) { - IAM_LOGE("failed to get native token info, res = %{public}d", res); - return callerName; - } - callerName = nativeTokenInfo.processName; - return callerName; + isBundleName = false; + IAM_LOGI("caller is not a hap or a native"); + return false; } } // namespace UserAuth } // namespace UserIam diff --git a/services/ipc/src/user_auth_service.cpp b/services/ipc/src/user_auth_service.cpp index 927c12fbb..e37a33502 100644 --- a/services/ipc/src/user_auth_service.cpp +++ b/services/ipc/src/user_auth_service.cpp @@ -277,12 +277,32 @@ std::shared_ptr UserAuthService::GetAuthContextCallback(int32_t contextCallback->SetTraceAuthType(authType); contextCallback->SetTraceAuthTrustLevel(authTrustLevel); contextCallback->SetTraceAuthWidgetType(authType); - std::string callerName = IpcCommon::GetCallerName(*this); - contextCallback->SetTraceCallerName(callerName); contextCallback->SetTraceSdkVersion(apiVersion); return contextCallback; } +int32_t UserAuthService::CheckAuthPermissionAndParam(int32_t authType, bool isBundleName, + const std::string &callerName, AuthTrustLevel authTrustLevel) +{ + if (!IpcCommon::CheckPermission(*this, ACCESS_BIOMETRIC_PERMISSION)) { + IAM_LOGE("failed to check permission"); + return CHECK_PERMISSION_FAILED; + } + if (isBundleName && (!IpcCommon::CheckForegroundApplication(callerName))) { + IAM_LOGE("failed to check foreground application"); + return CHECK_PERMISSION_FAILED; + } + if (authType == PIN) { + IAM_LOGE("authType not support"); + return TYPE_NOT_SUPPORT; + } + if (!CheckAuthTrustLevel(authTrustLevel)) { + IAM_LOGE("authTrustLevel is not in correct range"); + return TRUST_LEVEL_NOT_SUPPORT; + } + return SUCCESS; +} + uint64_t UserAuthService::Auth(int32_t apiVersion, const std::vector &challenge, AuthType authType, AuthTrustLevel authTrustLevel, sptr &callback) { @@ -292,15 +312,19 @@ uint64_t UserAuthService::Auth(int32_t apiVersion, const std::vector &c IAM_LOGE("contextCallback is nullptr"); return BAD_CONTEXT_ID; } + bool isBundleName = false; + std::string callerName = ""; Attributes extraInfo; - if (!IpcCommon::CheckPermission(*this, ACCESS_BIOMETRIC_PERMISSION)) { - IAM_LOGE("failed to check permission"); - contextCallback->OnResult(CHECK_PERMISSION_FAILED, extraInfo); + if ((!IpcCommon::GetCallerName(*this, isBundleName, callerName)) && isBundleName) { + IAM_LOGE("get bundle name fail"); + contextCallback->OnResult(GENERAL_ERROR, extraInfo); return BAD_CONTEXT_ID; } - if (authType == PIN) { - IAM_LOGE("authType not support"); - contextCallback->OnResult(TYPE_NOT_SUPPORT, extraInfo); + contextCallback->SetTraceCallerName(callerName); + int32_t checkRet = CheckAuthPermissionAndParam(authType, isBundleName, callerName, authTrustLevel); + if (checkRet != SUCCESS) { + IAM_LOGE("check auth permission and param fail"); + contextCallback->OnResult(checkRet, extraInfo); return BAD_CONTEXT_ID; } int32_t userId; @@ -310,22 +334,21 @@ uint64_t UserAuthService::Auth(int32_t apiVersion, const std::vector &c return BAD_CONTEXT_ID; } contextCallback->SetTraceUserId(userId); - if (!CheckAuthTrustLevel(authTrustLevel)) { - IAM_LOGE("authTrustLevel is not in correct range"); - contextCallback->OnResult(TRUST_LEVEL_NOT_SUPPORT, extraInfo); - return BAD_CONTEXT_ID; - } - ContextFactory::AuthContextPara para = {}; + Authentication::AuthenticationPara para = {}; para.tokenId = IpcCommon::GetAccessTokenId(*this); para.userId = userId; para.authType = authType; para.atl = authTrustLevel; para.challenge = std::move(challenge); para.endAfterFirstFail = true; + if (isBundleName) { + para.callerName = callerName; + } + para.sdkVersion = apiVersion; return StartAuthContext(apiVersion, para, contextCallback); } -uint64_t UserAuthService::StartAuthContext(int32_t apiVersion, ContextFactory::AuthContextPara para, +uint64_t UserAuthService::StartAuthContext(int32_t apiVersion, Authentication::AuthenticationPara para, const std::shared_ptr &contextCallback) { Attributes extraInfo; @@ -352,14 +375,22 @@ uint64_t UserAuthService::AuthUser(int32_t userId, const std::vector &c AuthType authType, AuthTrustLevel authTrustLevel, sptr &callback) { IAM_LOGI("start"); - static const uint32_t innerApiVersion = 0x80000000; - auto contextCallback = GetAuthContextCallback(innerApiVersion, challenge, authType, authTrustLevel, callback); + auto contextCallback = GetAuthContextCallback(INNER_API_VERSION_10000, challenge, authType, authTrustLevel, + callback); if (contextCallback == nullptr) { IAM_LOGE("contextCallback is nullptr"); return BAD_CONTEXT_ID; } contextCallback->SetTraceUserId(userId); Attributes extraInfo; + bool isBundleName = false; + std::string callerName = ""; + if ((!IpcCommon::GetCallerName(*this, isBundleName, callerName)) && isBundleName) { + IAM_LOGE("get bundle name fail"); + contextCallback->OnResult(GENERAL_ERROR, extraInfo); + return BAD_CONTEXT_ID; + } + contextCallback->SetTraceCallerName(callerName); if (!CheckAuthTrustLevel(authTrustLevel)) { IAM_LOGE("authTrustLevel is not in correct range"); contextCallback->OnResult(TRUST_LEVEL_NOT_SUPPORT, extraInfo); @@ -370,14 +401,18 @@ uint64_t UserAuthService::AuthUser(int32_t userId, const std::vector &c contextCallback->OnResult(CHECK_PERMISSION_FAILED, extraInfo); return BAD_CONTEXT_ID; } - ContextFactory::AuthContextPara para = {}; + Authentication::AuthenticationPara para = {}; para.tokenId = IpcCommon::GetAccessTokenId(*this); para.userId = userId; para.authType = authType; para.atl = authTrustLevel; para.challenge = std::move(challenge); para.endAfterFirstFail = false; - return StartAuthContext(innerApiVersion, para, contextCallback); + if (isBundleName) { + para.callerName = callerName; + } + para.sdkVersion = INNER_API_VERSION_10000; + return StartAuthContext(INNER_API_VERSION_10000, para, contextCallback); } uint64_t UserAuthService::Identify(const std::vector &challenge, AuthType authType, @@ -407,7 +442,7 @@ uint64_t UserAuthService::Identify(const std::vector &challenge, AuthTy return BAD_CONTEXT_ID; } - ContextFactory::IdentifyContextPara para = {}; + Identification::IdentificationPara para = {}; para.tokenId = IpcCommon::GetAccessTokenId(*this); para.authType = authType; para.challenge = std::move(challenge); @@ -556,19 +591,13 @@ int32_t UserAuthService::CheckAuthWidgetParam( return SUCCESS; } -uint64_t UserAuthService::StartWidgetContext(int32_t userId, const std::shared_ptr &contextCallback, - const AuthParam &authParam, const WidgetParam &widgetParam, std::vector &validType) +uint64_t UserAuthService::StartWidgetContext(const std::shared_ptr &contextCallback, + const AuthParam &authParam, const WidgetParam &widgetParam, std::vector &validType, + ContextFactory::AuthWidgetContextPara ¶) { Attributes extraInfo; - ContextFactory::AuthWidgetContextPara para; para.tokenId = IpcCommon::GetAccessTokenId(*this); - - std::string bundleName = ""; - if (!IpcCommon::GetCallingBundleName(*this, bundleName)) { - IAM_LOGE("get calling bundle name failed"); - } - para.callingBundleName = bundleName; - if (!AuthWidgetHelper::InitWidgetContextParam(userId, authParam, validType, widgetParam, para)) { + if (!AuthWidgetHelper::InitWidgetContextParam(authParam, validType, widgetParam, para)) { IAM_LOGE("init widgetContext failed"); contextCallback->OnResult(ResultCode::GENERAL_ERROR, extraInfo); return BAD_CONTEXT_ID; @@ -598,6 +627,10 @@ uint64_t UserAuthService::AuthWidget(int32_t apiVersion, const AuthParam &authPa IAM_LOGE("contextCallback is nullptr"); return BAD_CONTEXT_ID; } + bool isBundleName = false; + std::string callerName = ""; + static_cast(IpcCommon::GetCallerName(*this, isBundleName, callerName)); + contextCallback->SetTraceCallerName(callerName); Attributes extraInfo; if (!IpcCommon::CheckPermission(*this, ACCESS_BIOMETRIC_PERMISSION)) { IAM_LOGE("CheckPermission failed"); @@ -617,7 +650,14 @@ uint64_t UserAuthService::AuthWidget(int32_t apiVersion, const AuthParam &authPa contextCallback->OnResult(checkRet, extraInfo); return BAD_CONTEXT_ID; } - return StartWidgetContext(userId, contextCallback, authParam, widgetParam, validType); + ContextFactory::AuthWidgetContextPara para; + para.userId = userId; + if (isBundleName) { + para.callingBundleName = callerName; + para.callerName = callerName; + } + para.sdkVersion = apiVersion; + return StartWidgetContext(contextCallback, authParam, widgetParam, validType, para); } bool UserAuthService::Insert2ContextPool(const std::shared_ptr &context) @@ -648,8 +688,6 @@ std::shared_ptr UserAuthService::GetAuthContextCallback(int32_t callback->OnResult(ResultCode::GENERAL_ERROR, extraInfo); return nullptr; } - std::string callerName = IpcCommon::GetCallerName(*this); - contextCallback->SetTraceCallerName(callerName); contextCallback->SetTraceSdkVersion(apiVersion); contextCallback->SetTraceAuthTrustLevel(authParam.authTrustLevel); diff --git a/services/ipc/src/user_idm_service.cpp b/services/ipc/src/user_idm_service.cpp index 8e1f98cd2..d941d4cd2 100644 --- a/services/ipc/src/user_idm_service.cpp +++ b/services/ipc/src/user_idm_service.cpp @@ -210,7 +210,9 @@ void UserIdmService::AddCredential(int32_t userId, const CredentialPara &credPar callback->OnResult(GENERAL_ERROR, extraInfo); return; } - std::string callerName = IpcCommon::GetCallerName(*this); + bool isBundleName = false; + std::string callerName = ""; + static_cast(IpcCommon::GetCallerName(*this, isBundleName, callerName)); contextCallback->SetTraceCallerName(callerName); contextCallback->SetTraceUserId(userId); contextCallback->SetTraceAuthType(credPara.authType); @@ -223,13 +225,17 @@ void UserIdmService::AddCredential(int32_t userId, const CredentialPara &credPar std::lock_guard lock(mutex_); CancelCurrentEnrollIfExist(); - ContextFactory::EnrollContextPara para = {}; + Enrollment::EnrollmentPara para = {}; para.authType = credPara.authType; para.userId = userId; para.pinType = credPara.pinType; para.tokenId = IpcCommon::GetAccessTokenId(*this); para.token = credPara.token; para.isUpdate = isUpdate; + para.sdkVersion = INNER_API_VERSION_10000; + if (isBundleName) { + para.callerName = callerName; + } auto context = ContextFactory::CreateEnrollContext(para, contextCallback); if (context == nullptr || !ContextPool::Instance().Insert(context)) { IAM_LOGE("failed to insert context"); @@ -319,7 +325,9 @@ int32_t UserIdmService::EnforceDelUser(int32_t userId, const sptrOnResult(GENERAL_ERROR, extraInfo); return GENERAL_ERROR; } - contextCallback->SetTraceCallerName(IpcCommon::GetCallerName(*this)); + bool isBundleName = false; + std::string callerName = ""; + static_cast(IpcCommon::GetCallerName(*this, isBundleName, callerName)); contextCallback->SetTraceUserId(userId); if (!IpcCommon::CheckPermission(*this, ENFORCE_USER_IDM)) { @@ -362,8 +370,9 @@ void UserIdmService::DelUser(int32_t userId, const std::vector authToke callback->OnResult(GENERAL_ERROR, extraInfo); return; } - std::string callerName = IpcCommon::GetCallerName(*this); - contextCallback->SetTraceCallerName(callerName); + bool isBundleName = false; + std::string callerName = ""; + static_cast(IpcCommon::GetCallerName(*this, isBundleName, callerName)); contextCallback->SetTraceUserId(userId); if (!IpcCommon::CheckPermission(*this, MANAGE_USER_IDM_PERMISSION)) { @@ -405,8 +414,9 @@ void UserIdmService::DelCredential(int32_t userId, uint64_t credentialId, callback->OnResult(GENERAL_ERROR, extraInfo); return; } - std::string callerName = IpcCommon::GetCallerName(*this); - contextCallback->SetTraceCallerName(callerName); + bool isBundleName = false; + std::string callerName = ""; + static_cast(IpcCommon::GetCallerName(*this, isBundleName, callerName)); contextCallback->SetTraceUserId(userId); if (!IpcCommon::CheckPermission(*this, MANAGE_USER_IDM_PERMISSION)) { @@ -505,7 +515,7 @@ int32_t UserIdmService::EnforceDelUserInner(int32_t userId, std::shared_ptr(IpcCommon::GetCallerName(*this, isBundleName, callerName)); for (const auto &iter : userInfos) { int32_t userId = iter->GetUserId(); @@ -537,7 +550,7 @@ void UserIdmService::ClearRedundancyCredentialInner() continue; } callbackForTrace->SetTraceUserId(userId); - callbackForTrace->SetTraceCallerName(IpcCommon::GetCallerName(*this)); + callbackForTrace->SetTraceCallerName(callerName); std::vector::iterator it = std::find(accountInfo.begin(), accountInfo.end(), userId); if (it == accountInfo.end()) { ret = EnforceDelUserInner(userId, callbackForTrace, "DeleteRedundancy"); diff --git a/test/fuzztest/common_fuzzer/BUILD.gn b/test/fuzztest/common_fuzzer/BUILD.gn index b7a5a96a6..1ea81950e 100644 --- a/test/fuzztest/common_fuzzer/BUILD.gn +++ b/test/fuzztest/common_fuzzer/BUILD.gn @@ -328,6 +328,7 @@ ohos_source_set("userauth_services_ipc_fuzzer") { ] external_deps = [ + "ability_runtime:app_manager", "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", "c_utils:utils", diff --git a/test/unittest/services/mocks/mock_context.h b/test/unittest/services/mocks/mock_context.h index d41a4b64e..15ecd088f 100644 --- a/test/unittest/services/mocks/mock_context.h +++ b/test/unittest/services/mocks/mock_context.h @@ -36,7 +36,6 @@ public: MOCK_CONST_METHOD3( OnAcquireInfo, void(ExecutorRole src, int32_t moduleType, const std::vector &acquireMsg)); MOCK_METHOD1(SetTraceCallerName, void(std::string callerName)); - MOCK_METHOD0(GetTraceCallerName, std::string()); MOCK_METHOD1(SetTraceRequestContextId, void(uint64_t requestContextId)); MOCK_METHOD1(SetTraceAuthContextId, void(uint64_t authContextId)); MOCK_METHOD1(SetTraceUserId, void(int32_t userId)); diff --git a/test/unittest/services/mocks/mock_ipc_common.cpp b/test/unittest/services/mocks/mock_ipc_common.cpp index 84eaf666b..2dd9a913b 100644 --- a/test/unittest/services/mocks/mock_ipc_common.cpp +++ b/test/unittest/services/mocks/mock_ipc_common.cpp @@ -44,12 +44,6 @@ int32_t IpcCommon::GetCallingUserId(IPCObjectStub &stub, int32_t &userId) return SUCCESS; } -bool IpcCommon::GetCallingBundleName(IPCObjectStub &stub, std::string &bundleName) -{ - bundleName = TEST_CALLER_BUNDLE_NAME; - return true; -} - int32_t IpcCommon::GetActiveUserId(std::optional &userId) { if (userId.has_value() && userId.value() != 0) { @@ -141,10 +135,16 @@ void IpcCommon::SetSkipUserFlag(bool isSkip) skipFlag_ = isSkip; } -std::string IpcCommon::GetCallerName(IPCObjectStub &stub) +bool IpcCommon::GetCallerName(IPCObjectStub &stub, bool &isBundleName, std::string &callerName) { - std::string callerName = ""; - return callerName; + callerName = ""; + isBundleName = true; + return true; +} + +bool IpcCommon::CheckForegroundApplication(const std::string &bundleName) +{ + return true; } } // namespace UserAuth } // namespace UserIam diff --git a/test/unittest/services/mocks/mock_ipc_common.h b/test/unittest/services/mocks/mock_ipc_common.h index 78176dd56..6cde394d8 100644 --- a/test/unittest/services/mocks/mock_ipc_common.h +++ b/test/unittest/services/mocks/mock_ipc_common.h @@ -42,17 +42,17 @@ enum Permission { class IpcCommon final : public NoCopyable { public: static int32_t GetCallingUserId(IPCObjectStub &stub, int32_t &userId); - static bool GetCallingBundleName(IPCObjectStub &stub, std::string &bundleName); static int32_t GetActiveUserId(std::optional &userId); static int32_t GetAllUserId(std::vector &userIds); static bool CheckPermission(IPCObjectStub &stub, Permission permission); - static std::string GetCallerName(IPCObjectStub &stub); + static bool GetCallerName(IPCObjectStub &stub, bool &isBundleName, std::string &callerName); static uint32_t GetAccessTokenId(IPCObjectStub &stub); static void SetAccessTokenId(uint32_t tokenId, bool isSetTokenId); static void AddPermission(Permission perm); static void DeleteAllPermission(); static uint32_t GetTokenId(IPCObjectStub &stub); static void SetSkipUserFlag(bool isSkip); + static bool CheckForegroundApplication(const std::string &bundleName); private: static std::set permSet_; diff --git a/test/unittest/services/mocks/mock_iuser_auth_interface.h b/test/unittest/services/mocks/mock_iuser_auth_interface.h index 1cb813099..4e18c8502 100644 --- a/test/unittest/services/mocks/mock_iuser_auth_interface.h +++ b/test/unittest/services/mocks/mock_iuser_auth_interface.h @@ -39,7 +39,7 @@ public: MOCK_METHOD2(OpenSession, int32_t(int32_t userId, std::vector &challenge)); MOCK_METHOD1(CloseSession, int32_t(int32_t userId)); MOCK_METHOD4(BeginEnrollment, - int32_t(int32_t userId, const std::vector &authToken, const HdiEnrollParam ¶m, + int32_t(int32_t userId, const std::vector &authToken, const HdiEnrollParamV1_0 ¶m, HdiScheduleInfoV1_0 &info)); MOCK_METHOD3(UpdateEnrollmentResult, int32_t(int32_t userId, const std::vector &scheduleResult, HdiEnrollResultInfo &info)); @@ -54,7 +54,7 @@ public: int32_t(int32_t userId, const std::vector &authToken, std::vector &deletedInfos)); MOCK_METHOD2(EnforceDeleteUser, int32_t(int32_t userId, std::vector &deletedInfos)); MOCK_METHOD3(BeginAuthentication, - int32_t(uint64_t contextId, const HdiAuthSolution ¶m, std::vector &scheduleInfos)); + int32_t(uint64_t contextId, const HdiAuthSolutionV1_0 ¶m, std::vector &scheduleInfos)); MOCK_METHOD3(UpdateAuthenticationResult, int32_t(uint64_t contextId, const std::vector &scheduleResult, HdiAuthResultInfo &info)); MOCK_METHOD1(CancelAuthentication, int32_t(uint64_t contextId)); @@ -68,15 +68,20 @@ public: MOCK_METHOD4(GetValidSolution, int32_t(int32_t userId, const std::vector &authTypes, uint32_t authTrustLevel, std::vector &validTypes)); MOCK_METHOD4(BeginEnrollmentV1_1, - int32_t(int32_t userId, const std::vector &authToken, const HdiEnrollParam ¶m, + int32_t(int32_t userId, const std::vector &authToken, const HdiEnrollParamV1_0 ¶m, HdiScheduleInfo &info)); MOCK_METHOD3(BeginAuthenticationV1_1, - int32_t(uint64_t contextId, const HdiAuthSolution ¶m, std::vector &scheduleInfos)); + int32_t(uint64_t contextId, const HdiAuthSolutionV1_0 ¶m, std::vector &scheduleInfos)); MOCK_METHOD5(BeginIdentificationV1_1, int32_t(uint64_t contextId, HdiAuthType authType, const std::vector &challenge, uint32_t executorId, HdiScheduleInfo &scheduleInfo)); MOCK_METHOD1(GetAllUserInfo, int32_t(std::vector &userInfos)); MOCK_METHOD1(GetAllExtUserInfo, int32_t(std::vector &userInfos)); + MOCK_METHOD4(BeginEnrollmentV1_2, + int32_t(int32_t userId, const std::vector &authToken, const HdiEnrollParam ¶m, + HdiScheduleInfo &info)); + MOCK_METHOD3(BeginAuthenticationV1_2, + int32_t(uint64_t contextId, const HdiAuthSolution ¶m, std::vector &scheduleInfos)); }; class MockIUserAuthInterface::Holder : public Singleton { diff --git a/test/unittest/services/src/auth_widget_helper_test.cpp b/test/unittest/services/src/auth_widget_helper_test.cpp index b4d928800..16abcad39 100644 --- a/test/unittest/services/src/auth_widget_helper_test.cpp +++ b/test/unittest/services/src/auth_widget_helper_test.cpp @@ -56,7 +56,6 @@ void AuthWidgetHelperTest::TearDown() HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestInitWidgetContextParam001, TestSize.Level0) { - int32_t userId = 1; AuthParam authParam; authParam.authType.push_back(FACE); authParam.authType.push_back(ALL); @@ -67,13 +66,13 @@ HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestInitWidgetContextParam001, Te widgetParam.title = "使用密码验证"; widgetParam.navigationButtonText = "确定"; ContextFactory::AuthWidgetContextPara para; + para.userId = 1; std::vector validType; - EXPECT_TRUE(AuthWidgetHelper::InitWidgetContextParam(userId, authParam, validType, widgetParam, para)); + EXPECT_TRUE(AuthWidgetHelper::InitWidgetContextParam(authParam, validType, widgetParam, para)); } HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestInitWidgetContextParam002, TestSize.Level0) { - int32_t userId = 1; AuthParam authParam; authParam.authType.push_back(FACE); authParam.authType.push_back(ALL); @@ -84,8 +83,9 @@ HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestInitWidgetContextParam002, Te widgetParam.title = "使用密码验证"; widgetParam.navigationButtonText = "确定"; ContextFactory::AuthWidgetContextPara para; + para.userId = 1; std::vector validType = authParam.authType; - EXPECT_FALSE(AuthWidgetHelper::InitWidgetContextParam(userId, authParam, validType, widgetParam, para)); + EXPECT_FALSE(AuthWidgetHelper::InitWidgetContextParam(authParam, validType, widgetParam, para)); } HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestCheckValidSolution, TestSize.Level0) diff --git a/test/unittest/services/src/authentication_impl_test.cpp b/test/unittest/services/src/authentication_impl_test.cpp index e5567d599..42d0203a9 100644 --- a/test/unittest/services/src/authentication_impl_test.cpp +++ b/test/unittest/services/src/authentication_impl_test.cpp @@ -62,12 +62,16 @@ void AuthenticationImplTest::TearDown() HWTEST_F(AuthenticationImplTest, AuthenticationHdiError, TestSize.Level0) { constexpr uint64_t contextId = 0x1234567; - constexpr int32_t userId = 0x11; - + Authentication::AuthenticationPara para = {}; + para.userId = 0x11; + para.callerName = "com.ohos.test"; + para.sdkVersion = 11; + para.authType = FACE; + para.atl = ATL3; auto mock = MockIUserAuthInterface::Holder::GetInstance().Get(); - EXPECT_CALL(*mock, BeginAuthenticationV1_1(contextId, _, _)).WillRepeatedly(Return(1)); + EXPECT_CALL(*mock, BeginAuthenticationV1_2(contextId, _, _)).WillRepeatedly(Return(1)); - auto authentication = std::make_shared(contextId, userId, FACE, ATL3); + auto authentication = std::make_shared(contextId, para); std::vector> scheduleList; EXPECT_FALSE(authentication->Start(scheduleList, nullptr)); } @@ -75,12 +79,17 @@ HWTEST_F(AuthenticationImplTest, AuthenticationHdiError, TestSize.Level0) HWTEST_F(AuthenticationImplTest, AuthenticationHdiEmpty, TestSize.Level0) { constexpr uint64_t contextId = 0x1234567; - constexpr int32_t userId = 0x11; + Authentication::AuthenticationPara para = {}; + para.userId = 0x11; + para.callerName = "com.ohos.test"; + para.sdkVersion = 11; + para.authType = FACE; + para.atl = ATL3; auto mock = MockIUserAuthInterface::Holder::GetInstance().Get(); - EXPECT_CALL(*mock, BeginAuthenticationV1_1(contextId, _, _)).WillRepeatedly(Return(0)); + EXPECT_CALL(*mock, BeginAuthenticationV1_2(contextId, _, _)).WillRepeatedly(Return(0)); - auto authentication = std::make_shared(contextId, userId, FACE, ATL3); + auto authentication = std::make_shared(contextId, para); std::vector> scheduleList; EXPECT_FALSE(authentication->Start(scheduleList, nullptr)); } @@ -88,7 +97,12 @@ HWTEST_F(AuthenticationImplTest, AuthenticationHdiEmpty, TestSize.Level0) HWTEST_F(AuthenticationImplTest, AuthenticationInvalidExecutor, TestSize.Level0) { constexpr uint64_t contextId = 0x1234567; - constexpr int32_t userId = 0x11; + Authentication::AuthenticationPara para = {}; + para.userId = 0x11; + para.callerName = "com.ohos.test"; + para.sdkVersion = 11; + para.authType = FACE; + para.atl = ATL3; constexpr int32_t executorInfoIndex = 0x100; constexpr int32_t scheduleId = 0x1122; @@ -112,10 +126,10 @@ HWTEST_F(AuthenticationImplTest, AuthenticationInvalidExecutor, TestSize.Level0) }; auto mock = MockIUserAuthInterface::Holder::GetInstance().Get(); - EXPECT_CALL(*mock, BeginAuthenticationV1_1(contextId, _, _)).WillRepeatedly(DoAll(WithArg<2>(fillInfoList), + EXPECT_CALL(*mock, BeginAuthenticationV1_2(contextId, _, _)).WillRepeatedly(DoAll(WithArg<2>(fillInfoList), Return(0))); - auto authentication = std::make_shared(contextId, userId, FACE, ATL3); + auto authentication = std::make_shared(contextId, para); std::vector> scheduleList; EXPECT_FALSE(authentication->Start(scheduleList, nullptr)); } @@ -123,7 +137,12 @@ HWTEST_F(AuthenticationImplTest, AuthenticationInvalidExecutor, TestSize.Level0) HWTEST_F(AuthenticationImplTest, AuthenticationImplTestUpdate001, TestSize.Level0) { constexpr uint64_t contextId = 54871; - constexpr int32_t userId = 1534; + Authentication::AuthenticationPara para = {}; + para.userId = 0x11; + para.callerName = "com.ohos.test"; + para.sdkVersion = 11; + para.authType = FACE; + para.atl = ATL3; auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); @@ -136,7 +155,7 @@ HWTEST_F(AuthenticationImplTest, AuthenticationImplTestUpdate001, TestSize.Level } ); - auto authentication = std::make_shared(contextId, userId, FACE, ATL3); + auto authentication = std::make_shared(contextId, para); EXPECT_NE(authentication, nullptr); std::vector scheduleResult; Authentication::AuthResultInfo info = {}; @@ -146,7 +165,12 @@ HWTEST_F(AuthenticationImplTest, AuthenticationImplTestUpdate001, TestSize.Level HWTEST_F(AuthenticationImplTest, AuthenticationImplTestUpdate002, TestSize.Level0) { constexpr uint64_t contextId = 54871; - constexpr int32_t userId = 1534; + Authentication::AuthenticationPara para = {}; + para.userId = 0x11; + para.callerName = "com.ohos.test"; + para.sdkVersion = 11; + para.authType = FACE; + para.atl = ATL3; auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); @@ -163,7 +187,7 @@ HWTEST_F(AuthenticationImplTest, AuthenticationImplTestUpdate002, TestSize.Level } ); - auto authentication = std::make_shared(contextId, userId, FACE, ATL3); + auto authentication = std::make_shared(contextId, para); EXPECT_NE(authentication, nullptr); std::vector scheduleResult; Authentication::AuthResultInfo info = {}; @@ -173,10 +197,14 @@ HWTEST_F(AuthenticationImplTest, AuthenticationImplTestUpdate002, TestSize.Level HWTEST_F(AuthenticationImplTest, AuthenticationImplTestSetEndAfterFirstFail, TestSize.Level0) { constexpr uint64_t contextId = 1234; - constexpr int32_t userId = 5678; - AuthType authType = FACE; - AuthTrustLevel atl = ATL3; - auto authentication = std::make_shared(contextId, userId, authType, atl); + Authentication::AuthenticationPara para = {}; + para.userId = 0x11; + para.callerName = "com.ohos.test"; + para.sdkVersion = 11; + para.authType = FACE; + para.atl = ATL3; + + auto authentication = std::make_shared(contextId, para); EXPECT_NE(authentication, nullptr); bool endAfterFirstFail = true; authentication->SetEndAfterFirstFail(endAfterFirstFail); @@ -185,8 +213,14 @@ HWTEST_F(AuthenticationImplTest, AuthenticationImplTestSetEndAfterFirstFail, Tes HWTEST_F(AuthenticationImplTest, AuthenticationImplTestGetLatestError, TestSize.Level0) { constexpr uint64_t contextId = 1234; - constexpr int32_t userId = 5678; - auto authentication = std::make_shared(contextId, userId, FACE, ATL3); + Authentication::AuthenticationPara para = {}; + para.userId = 0x11; + para.callerName = "com.ohos.test"; + para.sdkVersion = 11; + para.authType = FACE; + para.atl = ATL3; + + auto authentication = std::make_shared(contextId, para); ASSERT_NE(authentication, nullptr); int32_t lastError = authentication->GetLatestError(); EXPECT_EQ(ResultCode::GENERAL_ERROR, lastError); @@ -195,8 +229,14 @@ HWTEST_F(AuthenticationImplTest, AuthenticationImplTestGetLatestError, TestSize. HWTEST_F(AuthenticationImplTest, AuthenticationImplTestGetAuthExecutorMsgs, TestSize.Level0) { constexpr uint64_t contextId = 1234; - constexpr int32_t userId = 5678; - auto authentication = std::make_shared(contextId, userId, FACE, ATL3); + Authentication::AuthenticationPara para = {}; + para.userId = 0x11; + para.callerName = "com.ohos.test"; + para.sdkVersion = 11; + para.authType = FACE; + para.atl = ATL3; + + auto authentication = std::make_shared(contextId, para); ASSERT_NE(authentication, nullptr); auto authExecutorMsgs = authentication->GetAuthExecutorMsgs(); EXPECT_EQ(authExecutorMsgs.size(), 0); @@ -205,16 +245,19 @@ HWTEST_F(AuthenticationImplTest, AuthenticationImplTestGetAuthExecutorMsgs, Test HWTEST_F(AuthenticationImplTest, AuthenticationImplTestStart, TestSize.Level0) { constexpr uint64_t contextId = 34567; - constexpr uint64_t userId = 25781; constexpr uint64_t executorIndex = 60; + Authentication::AuthenticationPara para = {}; + para.userId = 0x11; + para.callerName = "com.ohos.test"; + para.sdkVersion = 11; + para.authType = FACE; + para.atl = ATL3; auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); - EXPECT_CALL(*mockHdi, CancelAuthentication(_)) - .Times(2) - .WillOnce(Return(HDF_SUCCESS)) - .WillOnce(Return(HDF_FAILURE)); - EXPECT_CALL(*mockHdi, BeginAuthenticationV1_1(_, _, _)) + EXPECT_CALL(*mockHdi, CancelAuthentication(_)).Times(2) + .WillOnce(Return(HDF_SUCCESS)).WillOnce(Return(HDF_FAILURE)); + EXPECT_CALL(*mockHdi, BeginAuthenticationV1_2(_, _, _)) .WillRepeatedly( [](uint64_t contextId, const HdiAuthSolution ¶m, std::vector &scheduleInfos) { HdiScheduleInfo scheduleInfo = {}; @@ -239,7 +282,7 @@ HWTEST_F(AuthenticationImplTest, AuthenticationImplTestStart, TestSize.Level0) auto resourceNode = MockResourceNode::CreateWithExecuteIndex(executorIndex, FACE, ALL_IN_ONE); EXPECT_NE(resourceNode, nullptr); EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode)); - auto authentication = std::make_shared(contextId, userId, FACE, ATL3); + auto authentication = std::make_shared(contextId, para); EXPECT_NE(authentication, nullptr); std::vector> scheduleList; auto callback = Common::MakeShared(); diff --git a/test/unittest/services/src/context_factory_test.cpp b/test/unittest/services/src/context_factory_test.cpp index 792506550..d7bffa852 100644 --- a/test/unittest/services/src/context_factory_test.cpp +++ b/test/unittest/services/src/context_factory_test.cpp @@ -59,7 +59,7 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateSimpleAuth_001, TestSize.Level0 sptr callback(new (std::nothrow) MockUserAuthCallback()); ASSERT_NE(callback, nullptr); auto contextCallback = ContextCallback::NewInstance(callback, TRACE_AUTH_USER_ALL); - ContextFactory::AuthContextPara para = {}; + Authentication::AuthenticationPara para = {}; auto context = factory->CreateSimpleAuthContext(para, contextCallback); ASSERT_NE(context, nullptr); EXPECT_NE(context->GetContextId(), 0U); @@ -74,7 +74,7 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateSimpleAuth_002, TestSize.Level0 // Error: callback is null sptr callback(nullptr); auto contextCallback = ContextCallback::NewInstance(callback, TRACE_AUTH_USER_ALL); - ContextFactory::AuthContextPara para = {}; + Authentication::AuthenticationPara para = {}; auto context = factory->CreateSimpleAuthContext(para, contextCallback); ASSERT_EQ(context, nullptr); } @@ -87,7 +87,7 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateIdentify_001, TestSize.Level0) sptr callback(new (std::nothrow) MockUserAuthCallback()); ASSERT_NE(callback, nullptr); auto contextCallback = ContextCallback::NewInstance(callback, TRACE_IDENTIFY); - ContextFactory::IdentifyContextPara para = {}; + Identification::IdentificationPara para = {}; auto context = factory->CreateIdentifyContext(para, contextCallback); ASSERT_NE(context, nullptr); EXPECT_NE(context->GetContextId(), 0U); @@ -102,7 +102,7 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateIdentify_002, TestSize.Level0) // Error: callback is null sptr callback(nullptr); auto contextCallback = ContextCallback::NewInstance(callback, TRACE_IDENTIFY); - ContextFactory::IdentifyContextPara para = {}; + Identification::IdentificationPara para = {}; auto context = factory->CreateIdentifyContext(para, contextCallback); ASSERT_EQ(context, nullptr); } @@ -115,7 +115,7 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateEnrollContext_001, TestSize.Lev sptr callback(new (std::nothrow) MockIdmCallback()); ASSERT_NE(callback, nullptr); auto contextCallback = ContextCallback::NewInstance(callback, TRACE_ADD_CREDENTIAL); - ContextFactory::EnrollContextPara para = {}; + Enrollment::EnrollmentPara para = {}; auto context = factory->CreateEnrollContext(para, contextCallback); ASSERT_NE(context, nullptr); EXPECT_NE(context->GetContextId(), 0U); @@ -130,7 +130,7 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateEnrollContext_002, TestSize.Lev // Error: callback is null sptr callback(nullptr); auto contextCallback = ContextCallback::NewInstance(callback, TRACE_ADD_CREDENTIAL); - ContextFactory::EnrollContextPara para = {}; + Enrollment::EnrollmentPara para = {}; auto context = factory->CreateEnrollContext(para, contextCallback); ASSERT_EQ(context, nullptr); } diff --git a/test/unittest/services/src/enrollment_impl_test.cpp b/test/unittest/services/src/enrollment_impl_test.cpp index 2fe5fae4a..443d6aed4 100644 --- a/test/unittest/services/src/enrollment_impl_test.cpp +++ b/test/unittest/services/src/enrollment_impl_test.cpp @@ -58,23 +58,31 @@ void EnrollmentImplTest::TearDown() HWTEST_F(EnrollmentImplTest, EnrollmentHdiError, TestSize.Level0) { - constexpr int32_t userId = 0x11; + Enrollment::EnrollmentPara para = {}; + para.userId = 0x11; + para.callerName = "com.ohos.test"; + para.sdkVersion = 11; + para.authType = FACE; auto mock = MockIUserAuthInterface::Holder::GetInstance().Get(); - EXPECT_CALL(*mock, BeginEnrollmentV1_1(userId, _, _, _)).WillRepeatedly(Return(1)); + EXPECT_CALL(*mock, BeginEnrollmentV1_2(para.userId, _, _, _)).WillRepeatedly(Return(1)); - auto enrollment = std::make_shared(userId, FACE); + auto enrollment = std::make_shared(para); std::vector> scheduleList; EXPECT_FALSE(enrollment->Start(scheduleList, nullptr)); } HWTEST_F(EnrollmentImplTest, EnrollmentHdiEmpty, TestSize.Level0) { - constexpr int32_t userId = 0x11; + Enrollment::EnrollmentPara para = {}; + para.userId = 0x11; + para.callerName = "com.ohos.test"; + para.sdkVersion = 11; + para.authType = FACE; auto mock = MockIUserAuthInterface::Holder::GetInstance().Get(); - EXPECT_CALL(*mock, BeginEnrollmentV1_1(userId, _, _, _)).WillRepeatedly(Return(0)); + EXPECT_CALL(*mock, BeginEnrollmentV1_2(para.userId, _, _, _)).WillRepeatedly(Return(0)); - auto enroll = std::make_shared(userId, FACE); + auto enroll = std::make_shared(para); std::vector> scheduleList; EXPECT_FALSE(enroll->Start(scheduleList, nullptr)); } @@ -87,12 +95,16 @@ HWTEST_F(EnrollmentImplTest, EnrollmentHdiEmpty, TestSize.Level0) */ HWTEST_F(EnrollmentImplTest, EnrollmentUpdateHdiError, TestSize.Level0) { - constexpr int32_t userId = 0x11; + Enrollment::EnrollmentPara para = {}; + para.userId = 0x11; + para.callerName = "com.ohos.test"; + para.sdkVersion = 11; + para.authType = FACE; auto mock = MockIUserAuthInterface::Holder::GetInstance().Get(); - EXPECT_CALL(*mock, UpdateEnrollmentResult(userId, _, _)).WillRepeatedly(Return(1)); + EXPECT_CALL(*mock, UpdateEnrollmentResult(para.userId, _, _)).WillRepeatedly(Return(1)); - auto enroll = std::make_shared(userId, FACE); + auto enroll = std::make_shared(para); std::vector scheduleResult = {1, 2, 3}; uint64_t credentialId = 0; std::shared_ptr info = nullptr; @@ -103,10 +115,13 @@ HWTEST_F(EnrollmentImplTest, EnrollmentUpdateHdiError, TestSize.Level0) HWTEST_F(EnrollmentImplTest, EnrollmentUpdateHdiSuccessful_001, TestSize.Level0) { - constexpr int32_t userId = 0x11; + Enrollment::EnrollmentPara para = {}; + para.userId = 0x11; + para.callerName = "com.ohos.test"; + para.sdkVersion = 11; + para.authType = FACE; constexpr uint64_t credentialIdRet = 0x12; std::vector scheduleResult = {1, 2, 3}; - auto mock = MockIUserAuthInterface::Holder::GetInstance().Get(); auto fillUpInfos = [](HdiEnrollResultInfo &infoRet) { HdiCredentialInfo oldInfo = { @@ -123,12 +138,13 @@ HWTEST_F(EnrollmentImplTest, EnrollmentUpdateHdiSuccessful_001, TestSize.Level0) }; infoRet = info; }; - EXPECT_CALL(*mock, UpdateEnrollmentResult(userId, _, _)).WillRepeatedly(DoAll(WithArg<2>(fillUpInfos), Return(0))); + EXPECT_CALL(*mock, UpdateEnrollmentResult(para.userId, _, _)) + .WillRepeatedly(DoAll(WithArg<2>(fillUpInfos), Return(0))); - auto enroll = std::make_shared(userId, FACE); + auto enroll = std::make_shared(para); enroll->SetIsUpdate(true); HdiCredentialInfo oldInfo = {}; - std::shared_ptr info = std::make_shared(userId, oldInfo); + std::shared_ptr info = std::make_shared(para.userId, oldInfo); uint64_t credentialId = 0; std::vector rootSecret; std::optional secUserId = std::nullopt; @@ -147,10 +163,14 @@ HWTEST_F(EnrollmentImplTest, EnrollmentUpdateHdiSuccessful_001, TestSize.Level0) HWTEST_F(EnrollmentImplTest, EnrollmentUpdateHdiSuccessful_002, TestSize.Level0) { - int32_t userId = 1206; + Enrollment::EnrollmentPara para = {}; + para.userId = 1206; + para.callerName = "com.ohos.test"; + para.sdkVersion = 11; + para.authType = PIN; auto mock = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_CALL(*mock, UpdateEnrollmentResult(_, _, _)).WillRepeatedly(Return(0)); - auto enroll = std::make_shared(userId, FACE); + auto enroll = std::make_shared(para); enroll->SetIsUpdate(false); std::vector scheduleResult = {1, 2, 3}; @@ -178,7 +198,7 @@ HWTEST_F(EnrollmentImplTest, EnrollmentUpdateHdiSuccessful_002, TestSize.Level0) } ); - enroll = std::make_shared(userId, PIN); + enroll = std::make_shared(para); enroll->SetIsUpdate(false); EXPECT_FALSE(enroll->Update(scheduleResult, credentialId, info, rootSecret, secUserId)); EXPECT_FALSE(enroll->Update(scheduleResult, credentialId, info, rootSecret, secUserId)); @@ -186,16 +206,20 @@ HWTEST_F(EnrollmentImplTest, EnrollmentUpdateHdiSuccessful_002, TestSize.Level0) HWTEST_F(EnrollmentImplTest, EnrollmentImplTestStart_001, TestSize.Level0) { - constexpr uint64_t userId = 34567; + Enrollment::EnrollmentPara para = {}; + para.userId = 0x11; + para.callerName = "com.ohos.test"; + para.sdkVersion = 11; + para.authType = FACE; constexpr uint64_t executorIndex = 60; - + auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); EXPECT_CALL(*mockHdi, CancelEnrollment(_)) .Times(2) .WillOnce(Return(HDF_SUCCESS)) .WillOnce(Return(HDF_FAILURE)); - EXPECT_CALL(*mockHdi, BeginEnrollmentV1_1(_, _, _, _)) + EXPECT_CALL(*mockHdi, BeginEnrollmentV1_2(_, _, _, _)) .WillRepeatedly( [](int32_t userId, const std::vector &authToken, const HdiEnrollParam ¶m, HdiScheduleInfo &info) { @@ -219,7 +243,7 @@ HWTEST_F(EnrollmentImplTest, EnrollmentImplTestStart_001, TestSize.Level0) auto resourceNode = MockResourceNode::CreateWithExecuteIndex(executorIndex, FACE, ALL_IN_ONE); EXPECT_NE(resourceNode, nullptr); EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode)); - auto enroll = std::make_shared(userId, FACE); + auto enroll = std::make_shared(para); EXPECT_NE(enroll, nullptr); std::vector> scheduleList; auto callback = Common::MakeShared(); @@ -235,9 +259,13 @@ HWTEST_F(EnrollmentImplTest, EnrollmentImplTestStart_001, TestSize.Level0) HWTEST_F(EnrollmentImplTest, EnrollmentImplTestStart_002, TestSize.Level0) { - uint64_t userId = 34567; + Enrollment::EnrollmentPara para = {}; + para.userId = 34567; + para.callerName = "com.ohos.test"; + para.sdkVersion = 11; + para.authType = PIN; auto mock = MockIUserAuthInterface::Holder::GetInstance().Get(); - EXPECT_CALL(*mock, BeginEnrollmentV1_1(_, _, _, _)).WillRepeatedly(Return(1)); + EXPECT_CALL(*mock, BeginEnrollmentV1_2(_, _, _, _)).WillRepeatedly(Return(1)); EXPECT_CALL(*mock, GetUserInfo(_, _, _, _)) .WillOnce(Return(1)) .WillRepeatedly( @@ -254,7 +282,7 @@ HWTEST_F(EnrollmentImplTest, EnrollmentImplTestStart_002, TestSize.Level0) } ); - auto enroll = std::make_shared(userId, FACE); + auto enroll = std::make_shared(para); std::vector> scheduleList; auto callback = Common::MakeShared(); EXPECT_FALSE(enroll->Start(scheduleList, callback)); @@ -262,7 +290,7 @@ HWTEST_F(EnrollmentImplTest, EnrollmentImplTestStart_002, TestSize.Level0) enroll->SetIsUpdate(true); EXPECT_FALSE(enroll->Start(scheduleList, callback)); - enroll = std::make_shared(userId, PIN); + enroll = std::make_shared(para); enroll->SetIsUpdate(true); EXPECT_FALSE(enroll->Start(scheduleList, callback)); EXPECT_FALSE(enroll->Start(scheduleList, callback)); diff --git a/test/unittest/services/src/user_auth_service_test.cpp b/test/unittest/services/src/user_auth_service_test.cpp index c9689bd78..c366f3e49 100644 --- a/test/unittest/services/src/user_auth_service_test.cpp +++ b/test/unittest/services/src/user_auth_service_test.cpp @@ -271,7 +271,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuth001, TestSize.Level0) auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); - EXPECT_CALL(*mockHdi, BeginAuthenticationV1_1(_, _, _)).WillOnce(Return(HDF_FAILURE)); + EXPECT_CALL(*mockHdi, BeginAuthenticationV1_2(_, _, _)).WillOnce(Return(HDF_FAILURE)); IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); sptr callbackInterface = testCallback; @@ -333,7 +333,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuth003, TestSize.Level0) IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); - EXPECT_CALL(*mockHdi, BeginAuthenticationV1_1(_, _, _)).Times(2).WillRepeatedly(Return(NOT_ENROLLED)); + EXPECT_CALL(*mockHdi, BeginAuthenticationV1_2(_, _, _)).Times(2).WillRepeatedly(Return(NOT_ENROLLED)); contextId = service.Auth(testApiVersion, testChallenge, testAuthType, testAuthTrustLevel, callbackInterface); EXPECT_EQ(contextId, 0); @@ -368,7 +368,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuth004, TestSize.Level0) IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); - EXPECT_CALL(*mockHdi, BeginAuthenticationV1_1(_, _, _)) + EXPECT_CALL(*mockHdi, BeginAuthenticationV1_2(_, _, _)) .WillRepeatedly( [&context](uint64_t contextId, const HdiAuthSolution ¶m, std::vector &scheduleInfos) { HdiScheduleInfo scheduleInfo = {}; @@ -436,7 +436,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser001, TestSize.Level0) auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1); - EXPECT_CALL(*mockHdi, BeginAuthenticationV1_1(_, _, _)).Times(1); + EXPECT_CALL(*mockHdi, BeginAuthenticationV1_2(_, _, _)).Times(1); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); sptr callbackInterface = testCallback; uint64_t contextId = service.AuthUser(testUserId, testChallenge, testAuthType, @@ -504,7 +504,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser003, TestSize.Level0) IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); - EXPECT_CALL(*mockHdi, BeginAuthenticationV1_1(_, _, _)) + EXPECT_CALL(*mockHdi, BeginAuthenticationV1_2(_, _, _)) .WillRepeatedly( [&context](uint64_t contextId, const HdiAuthSolution ¶m, std::vector &scheduleInfos) { HdiScheduleInfo scheduleInfo = {}; diff --git a/test/unittest/services/src/user_idm_service_test.cpp b/test/unittest/services/src/user_idm_service_test.cpp index 7f6d416f5..31dba1024 100644 --- a/test/unittest/services/src/user_idm_service_test.cpp +++ b/test/unittest/services/src/user_idm_service_test.cpp @@ -336,7 +336,7 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceAddCredential002, TestSize.Level0) ); auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); - EXPECT_CALL(*mockHdi, BeginEnrollmentV1_1(_, _, _, _)).WillRepeatedly(Return(HDF_FAILURE)); + EXPECT_CALL(*mockHdi, BeginEnrollmentV1_2(_, _, _, _)).WillRepeatedly(Return(HDF_FAILURE)); service.AddCredential(testUserId, testCredPara, testCallback, false); IpcCommon::AddPermission(MANAGE_USER_IDM_PERMISSION); @@ -368,7 +368,7 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceAddCredential003, TestSize.Level0) auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); - EXPECT_CALL(*mockHdi, BeginEnrollmentV1_1(_, _, _, _)) + EXPECT_CALL(*mockHdi, BeginEnrollmentV1_2(_, _, _, _)) .WillOnce( [&context](int32_t userId, const std::vector &authToken, const HdiEnrollParam ¶m, HdiScheduleInfo &info) { @@ -489,7 +489,7 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceUpdateCredential002, TestSize.Level0) } ); - EXPECT_CALL(*mockHdi, BeginEnrollmentV1_1(_, _, _, _)).WillOnce(Return(HDF_FAILURE)); + EXPECT_CALL(*mockHdi, BeginEnrollmentV1_2(_, _, _, _)).WillOnce(Return(HDF_FAILURE)); testCredPara.token = {1, 2, 3, 4}; service.UpdateCredential(testUserId, testCredPara, testCallback);