diff --git a/common/utils/iam_para2str.h b/common/utils/iam_para2str.h index c1fb160aeaafb9f9e5c2a70b35fc4bf80f24c816..1a16647d748c7f5398b0f368d859c795e75ee14b 100644 --- a/common/utils/iam_para2str.h +++ b/common/utils/iam_para2str.h @@ -48,6 +48,11 @@ static inline const char *AuthTypeToStr(uint32_t authType) } return "unknown"; } + +static inline const char *GetBoolStr(bool val) +{ + return val ? "true" : "false"; +} } // namespace Common } // namespace UserIam } // namespace OHOS diff --git a/frameworks/js/napi/user_auth/inc/user_auth_instance_v10.h b/frameworks/js/napi/user_auth/inc/user_auth_instance_v10.h index c78356a3c0c02282668c38f46e6cd0a93b3620b4..eea0715cd8ababff79ec32af109ce45c57563910 100644 --- a/frameworks/js/napi/user_auth/inc/user_auth_instance_v10.h +++ b/frameworks/js/napi/user_auth/inc/user_auth_instance_v10.h @@ -49,7 +49,7 @@ private: std::shared_ptr GetCallback(napi_env env, napi_value value); static napi_value DoGetEnrolledStateResult(napi_env env, EnrolledState enrolledState); - AuthParam authParam_; + AuthParamInner authParam_; WidgetParam widgetParam_; uint64_t contextId_ = 0; diff --git a/frameworks/js/napi/user_auth/src/user_auth_instance_v10.cpp b/frameworks/js/napi/user_auth/src/user_auth_instance_v10.cpp index 613eba2e2b3f1d818caed70ae4560df40594a512..c2d9c1b897a60b259679ec111c49043c5c55bbc7 100644 --- a/frameworks/js/napi/user_auth/src/user_auth_instance_v10.cpp +++ b/frameworks/js/napi/user_auth/src/user_auth_instance_v10.cpp @@ -169,15 +169,15 @@ UserAuthResultCode UserAuthInstanceV10::InitAuthType(napi_env env, napi_value va IAM_LOGE("authType is illegal, %{public}d", value); return UserAuthResultCode::TYPE_NOT_SUPPORT; } - auto iter = std::find(authParam_.authType.begin(), authParam_.authType.end(), static_cast(value)); - if (iter != authParam_.authType.end()) { + auto iter = std::find(authParam_.authTypes.begin(), authParam_.authTypes.end(), static_cast(value)); + if (iter != authParam_.authTypes.end()) { IAM_LOGE("napi authType:%{public}d exist", value); return UserAuthResultCode::OHOS_INVALID_PARAM; } - authParam_.authType.push_back(static_cast(value)); + authParam_.authTypes.push_back(static_cast(value)); } - IAM_LOGI("authType size:%{public}zu", authParam_.authType.size()); + IAM_LOGI("authType size:%{public}zu", authParam_.authTypes.size()); return UserAuthResultCode::SUCCESS; } @@ -366,7 +366,7 @@ UserAuthResultCode UserAuthInstanceV10::Init(napi_env env, napi_callback_info in UserAuthResultCode errCode = InitAuthParam(env, argv[PARAM0]); if (errCode != UserAuthResultCode::SUCCESS) { - IAM_LOGE("AuthParam type error, errorCode: %{public}d", errCode); + IAM_LOGE("AuthParamInner type error, errorCode: %{public}d", errCode); return errCode; } diff --git a/frameworks/native/client/inc/co_auth_client_impl.h b/frameworks/native/client/inc/co_auth_client_impl.h index 30ee367277350624376cb7b7c931d33f38e1e2d2..630247448023971994dcb6863b1fc10eab04d94a 100644 --- a/frameworks/native/client/inc/co_auth_client_impl.h +++ b/frameworks/native/client/inc/co_auth_client_impl.h @@ -29,7 +29,7 @@ namespace UserAuth { class CoAuthClientImpl final : public CoAuthClient, public NoCopyable { public: void Register(const ExecutorInfo &info, const std::shared_ptr &callback) override; - void Unregister(const ExecutorInfo &info) override; + void Unregister(uint64_t executorIndex) override; private: friend class CoAuthClient; diff --git a/frameworks/native/client/inc/executor_callback_service.h b/frameworks/native/client/inc/executor_callback_service.h index ec84f9cc67652d6cbfd6bd5a454ec7e7f9f6165f..2d698fad2da39b8b046cd19b0539b81550822d73 100644 --- a/frameworks/native/client/inc/executor_callback_service.h +++ b/frameworks/native/client/inc/executor_callback_service.h @@ -27,8 +27,8 @@ class ExecutorCallbackService : public ExecutorCallbackStub { public: explicit ExecutorCallbackService(const std::shared_ptr &impl); ~ExecutorCallbackService() override = default; - void OnMessengerReady(sptr &messenger, const std::vector &publicKey, - const std::vector &templateIdList) override; + void OnMessengerReady(uint64_t executorIndex, sptr &messenger, + const std::vector &publicKey, const std::vector &templateIdList) override; int32_t OnBeginExecute(uint64_t scheduleId, const std::vector &publicKey, const Attributes &command) override; int32_t OnEndExecute(uint64_t scheduleId, const Attributes &command) override; diff --git a/frameworks/native/client/inc/user_auth_callback_service.h b/frameworks/native/client/inc/user_auth_callback_service.h index bd45a45d230d1c64bba1acfa8f7150b990937d5d..58e396c96489f771acba69be3796cb2a1fd1b891 100644 --- a/frameworks/native/client/inc/user_auth_callback_service.h +++ b/frameworks/native/client/inc/user_auth_callback_service.h @@ -28,6 +28,7 @@ class UserAuthCallbackService : public UserAuthCallbackStub { public: explicit UserAuthCallbackService(const std::shared_ptr &impl); explicit UserAuthCallbackService(const std::shared_ptr &impl); + explicit UserAuthCallbackService(const std::shared_ptr &impl); ~UserAuthCallbackService() override; void OnResult(int32_t result, const Attributes &extraInfo) override; void OnAcquireInfo(int32_t module, int32_t acquireInfo, const Attributes &extraInfo) override; @@ -35,6 +36,7 @@ public: private: std::shared_ptr authCallback_ {nullptr}; std::shared_ptr identifyCallback_ {nullptr}; + std::shared_ptr prepareRemoteAuthCallback_ {nullptr}; std::shared_ptr iamHitraceHelper_ {nullptr}; }; diff --git a/frameworks/native/client/inc/user_auth_client_impl.h b/frameworks/native/client/inc/user_auth_client_impl.h index 4d027cfd4559e08dd591602749e0c4ec50f3af22..c1054f3fd621b9ef351e44d951d357272078d663 100644 --- a/frameworks/native/client/inc/user_auth_client_impl.h +++ b/frameworks/native/client/inc/user_auth_client_impl.h @@ -17,6 +17,7 @@ #define USER_AUTH_CLIENT_IMPL_H #include +#include #include "nocopyable.h" @@ -36,8 +37,8 @@ public: const std::shared_ptr &callback) override; void SetProperty(int32_t userId, const SetPropertyRequest &request, const std::shared_ptr &callback) override; - uint64_t BeginAuthentication(int32_t userId, const std::vector &challenge, AuthType authType, - AuthTrustLevel atl, const std::shared_ptr &callback) override; + uint64_t BeginAuthentication(const AuthParam &authParam, + const std::shared_ptr &callback) override; uint64_t BeginNorthAuthentication(int32_t apiVersion, const std::vector &challenge, AuthType authType, AuthTrustLevel atl, const std::shared_ptr &callback); int32_t CancelAuthentication(uint64_t contextId) override; @@ -45,7 +46,7 @@ public: const std::shared_ptr &callback) override; int32_t CancelIdentification(uint64_t contextId) override; int32_t GetVersion(int32_t &version); - uint64_t BeginWidgetAuth(int32_t apiVersion, const AuthParam &authParam, + uint64_t BeginWidgetAuth(int32_t apiVersion, const AuthParamInner &authParam, const WidgetParam &widgetParam, const std::shared_ptr &callback); int32_t SetWidgetCallback(int32_t version, const std::shared_ptr &callback); int32_t Notice(NoticeType noticeType, const std::string &eventData); @@ -55,6 +56,8 @@ public: int32_t UnRegistUserAuthSuccessEventListener( const sptr &listener) override; int32_t SetGlobalConfigParam(const GlobalConfigParam ¶m) override; + int32_t PrepareRemoteAuth(const std::string &networkId, + const std::shared_ptr &callback) override; private: ResultCode SetPropertyInner(int32_t userId, const SetPropertyRequest &request, diff --git a/frameworks/native/client/src/co_auth_client_impl.cpp b/frameworks/native/client/src/co_auth_client_impl.cpp index 78cbac5d2209aea1275daa66444b2a4055f851ca..f7493be3bcc0354c6bad109fced9b1903d2b14d1 100644 --- a/frameworks/native/client/src/co_auth_client_impl.cpp +++ b/frameworks/native/client/src/co_auth_client_impl.cpp @@ -47,6 +47,8 @@ void CoAuthClientImpl::Register(const ExecutorInfo &info, const std::shared_ptr< regInfo.executorMatcher = info.executorMatcher; regInfo.esl = info.esl; regInfo.publicKey = info.publicKey; + regInfo.deviceUdid = info.deviceUdid; + regInfo.signedRemoteExecutorInfo = info.signedRemoteExecutorInfo; sptr wrapper(new (std::nothrow) ExecutorCallbackService(callback)); if (wrapper == nullptr) { @@ -56,9 +58,16 @@ void CoAuthClientImpl::Register(const ExecutorInfo &info, const std::shared_ptr< proxy->ExecutorRegister(regInfo, wrapper); } -void CoAuthClientImpl::Unregister(const ExecutorInfo &info) +void CoAuthClientImpl::Unregister(uint64_t executorIndex) { - IAM_LOGI("start type:%{public}d role:%{public}d", info.authType, info.executorRole); + IAM_LOGI("start"); + + auto proxy = GetProxy(); + if (!proxy) { + return; + } + + proxy->ExecutorUnregister(executorIndex); } sptr CoAuthClientImpl::GetProxy() diff --git a/frameworks/native/client/src/executor_callback_service.cpp b/frameworks/native/client/src/executor_callback_service.cpp index 0a49742d4254d9eaa007ee16f81f84e7289a8dab..a819afe5b1d8733c9bf60ab72c6099220431819c 100644 --- a/frameworks/native/client/src/executor_callback_service.cpp +++ b/frameworks/native/client/src/executor_callback_service.cpp @@ -29,7 +29,7 @@ ExecutorCallbackService::ExecutorCallbackService(const std::shared_ptr &messenger, +void ExecutorCallbackService::OnMessengerReady(uint64_t executorIndex, sptr &messenger, const std::vector &publicKey, const std::vector &templateIdList) { IAM_LOGI("start"); @@ -42,7 +42,7 @@ void ExecutorCallbackService::OnMessengerReady(sptr IAM_LOGE("failed to create wrapper"); return; } - callback_->OnMessengerReady(wrapper, publicKey, templateIdList); + callback_->OnMessengerReady(executorIndex, wrapper, publicKey, templateIdList); } int32_t ExecutorCallbackService::OnBeginExecute(uint64_t scheduleId, const std::vector &publicKey, diff --git a/frameworks/native/client/src/user_auth_callback_service.cpp b/frameworks/native/client/src/user_auth_callback_service.cpp index 192a2ece65336a01ac7bfe87792ec0717a8598e2..af009292bdcbc02e2620c8808f6afe24772db8a5 100644 --- a/frameworks/native/client/src/user_auth_callback_service.cpp +++ b/frameworks/native/client/src/user_auth_callback_service.cpp @@ -52,6 +52,19 @@ UserAuthCallbackService::UserAuthCallbackService(const std::shared_ptr(this), action); } +UserAuthCallbackService::UserAuthCallbackService(const std::shared_ptr &impl) + : prepareRemoteAuthCallback_(impl), + iamHitraceHelper_(Common::MakeShared("UserAuth InnerKit")) +{ + CallbackManager::CallbackAction action = [impl]() { + if (impl != nullptr) { + IAM_LOGI("user auth service death, prepare remote auth callback return default result to caller"); + impl->OnResult(GENERAL_ERROR); + } + }; + CallbackManager::GetInstance().AddCallback(reinterpret_cast(this), action); +} + UserAuthCallbackService::~UserAuthCallbackService() { CallbackManager::GetInstance().RemoveCallback(reinterpret_cast(this)); @@ -64,8 +77,10 @@ void UserAuthCallbackService::OnResult(int32_t result, const Attributes &extraIn authCallback_->OnResult(result, extraInfo); } else if (identifyCallback_ != nullptr) { identifyCallback_->OnResult(result, extraInfo); + } else if (prepareRemoteAuthCallback_ != nullptr) { + prepareRemoteAuthCallback_->OnResult(result); } else { - IAM_LOGE("both auth and identify callback is nullptr"); + IAM_LOGE("all callback is nullptr"); return; } iamHitraceHelper_= nullptr; @@ -78,8 +93,10 @@ void UserAuthCallbackService::OnAcquireInfo(int32_t module, int32_t acquireInfo, authCallback_->OnAcquireInfo(module, acquireInfo, extraInfo); } else if (identifyCallback_ != nullptr) { identifyCallback_->OnAcquireInfo(module, acquireInfo, extraInfo); + } else if (prepareRemoteAuthCallback_ != nullptr) { + IAM_LOGE("prepare remote auth callback not support acquire info"); } else { - IAM_LOGE("both auth and identify callback is nullptr"); + IAM_LOGE("all callback is nullptr"); return; } } diff --git a/frameworks/native/client/src/user_auth_client_impl.cpp b/frameworks/native/client/src/user_auth_client_impl.cpp index 8816d9e27579bff05ccfadbaf7e340c9733ba4ff..da282cab27f9ef5af79a388671c8dc5cf00bf2f3 100644 --- a/frameworks/native/client/src/user_auth_client_impl.cpp +++ b/frameworks/native/client/src/user_auth_client_impl.cpp @@ -21,6 +21,7 @@ #include "callback_manager.h" #include "iam_check.h" #include "iam_logger.h" +#include "iam_para2str.h" #include "iam_ptr.h" #include "ipc_client_utils.h" #include "user_auth_callback_service.h" @@ -173,10 +174,20 @@ void UserAuthClientImpl::SetProperty(int32_t userId, const SetPropertyRequest &r } } -uint64_t UserAuthClientImpl::BeginAuthentication(int32_t userId, const std::vector &challenge, - AuthType authType, AuthTrustLevel atl, const std::shared_ptr &callback) +uint64_t UserAuthClientImpl::BeginAuthentication(const AuthParam &authParam, + const std::shared_ptr &callback) { - IAM_LOGI("start, userId:%{public}d authType:%{public}d atl:%{public}u", userId, authType, atl); + IAM_LOGI("start, userId:%{public}d authType:%{public}d atl:%{public}u remoteAuthParamHasValue:%{public}s", + authParam.userId, authParam.authType, authParam.authTrustLevel, + Common::GetBoolStr(authParam.remoteAuthParam.has_value())); + if (authParam.remoteAuthParam.has_value()) { + IAM_LOGI("verifierNetworkIdHasValue:%{public}s collectorNetworkIdHasValue:%{public}s" + "collectorTokenIdHasValue:%{public}s", + Common::GetBoolStr(authParam.remoteAuthParam->verifierNetworkId.has_value()), + Common::GetBoolStr(authParam.remoteAuthParam->collectorNetworkId.has_value()), + Common::GetBoolStr(authParam.remoteAuthParam->collectorTokenId.has_value())); + } + if (!callback) { IAM_LOGE("auth callback is nullptr"); return INVALID_SESSION_ID; @@ -197,7 +208,15 @@ uint64_t UserAuthClientImpl::BeginAuthentication(int32_t userId, const std::vect callback->OnResult(GENERAL_ERROR, extraInfo); return INVALID_SESSION_ID; } - return proxy->AuthUser(userId, challenge, authType, atl, wrapper); + AuthParamInner authParamInner = { + .userId = authParam.userId, + .challenge = authParam.challenge, + .authType = authParam.authType, + .authTrustLevel = authParam.authTrustLevel, + .authIntent = authParam.authIntent + }; + std::optional remoteAuthParam = authParam.remoteAuthParam; + return proxy->AuthUser(authParamInner, remoteAuthParam, wrapper); } uint64_t UserAuthClientImpl::BeginNorthAuthentication(int32_t apiVersion, const std::vector &challenge, @@ -372,11 +391,11 @@ UserAuthClient &UserAuthClient::GetInstance() return UserAuthClientImpl::Instance(); } -uint64_t UserAuthClientImpl::BeginWidgetAuth(int32_t apiVersion, const AuthParam &authParam, +uint64_t UserAuthClientImpl::BeginWidgetAuth(int32_t apiVersion, const AuthParamInner &authParam, const WidgetParam &widgetParam, const std::shared_ptr &callback) { IAM_LOGI("start, apiVersion:%{public}d authTypeSize:%{public}zu authTrustLevel:%{public}u", - apiVersion, authParam.authType.size(), authParam.authTrustLevel); + apiVersion, authParam.authTypes.size(), authParam.authTrustLevel); // parameter verification if (!callback) { IAM_LOGE("auth callback is nullptr"); @@ -496,6 +515,32 @@ int32_t UserAuthClientImpl::UnRegistUserAuthSuccessEventListener(const sptr &callback) +{ + IAM_LOGI("start"); + if (!callback) { + IAM_LOGE("prepare remote auth callback is nullptr"); + return GENERAL_ERROR; + } + + auto proxy = GetProxy(); + if (!proxy) { + IAM_LOGE("proxy is nullptr"); + callback->OnResult(GENERAL_ERROR); + return GENERAL_ERROR; + } + + sptr wrapper(new (std::nothrow) UserAuthCallbackService(callback)); + if (wrapper == nullptr) { + IAM_LOGE("failed to create wrapper"); + callback->OnResult(GENERAL_ERROR); + return GENERAL_ERROR; + } + + return proxy->PrepareRemoteAuth(networkId, wrapper); +} } // namespace UserAuth } // namespace UserIam } // namespace OHOS diff --git a/frameworks/native/client/user_auth_client_map b/frameworks/native/client/user_auth_client_map index 2f8580322d886d38c0a2bbde8eafc5853dd55b85..bc484d08af507c51cbb94ef3853fff131935251e 100644 --- a/frameworks/native/client/user_auth_client_map +++ b/frameworks/native/client/user_auth_client_map @@ -14,7 +14,7 @@ { global: extern "C++" { - OHOS::UserIam::UserAuth::CoAuthClient::GetInstance*; + OHOS::UserIam::UserAuth::CoAuthClient::*; OHOS::UserIam::UserAuth::UserAuthClientImpl::Instance*; OHOS::UserIam::UserAuth::UserAuthClientImpl::BeginNorthAuthentication*; OHOS::UserIam::UserAuth::UserAuthClientImpl::BeginWidgetAuth*; diff --git a/frameworks/native/common/attributes/src/attributes.cpp b/frameworks/native/common/attributes/src/attributes.cpp index 9df5a55374bd824d0afcc1595e1837f918ce2e96..a4977c0f94457525ef8ca2a1519fe615c016d5d3 100644 --- a/frameworks/native/common/attributes/src/attributes.cpp +++ b/frameworks/native/common/attributes/src/attributes.cpp @@ -47,11 +47,12 @@ public: bool SetInt32Value(AttributeKey key, int32_t value); bool SetInt64Value(AttributeKey key, int64_t value); bool SetStringValue(AttributeKey key, const std::string &value); - bool SetAttributesValue(AttributeKey key, const Impl &value); + bool SetAttributesValue(AttributeKey key, const Impl &array); bool SetUint64ArrayValue(AttributeKey key, const std::vector &value); bool SetUint32ArrayValue(AttributeKey key, const std::vector &value); bool SetUint16ArrayValue(AttributeKey key, const std::vector &value); bool SetUint8ArrayValue(AttributeKey key, const std::vector &value); + bool SetInt32ArrayValue(AttributeKey key, const std::vector &value); bool GetBoolValue(AttributeKey key, bool &value) const; bool GetUint64Value(AttributeKey key, uint64_t &value) const; @@ -65,29 +66,32 @@ public: bool GetUint32ArrayValue(AttributeKey key, std::vector &value) const; bool GetUint16ArrayValue(AttributeKey key, std::vector &value) const; bool GetUint8ArrayValue(AttributeKey key, std::vector &value) const; - bool GetAttributesValue(AttributeKey key, Impl &value) const; + bool GetInt32ArrayValue(AttributeKey key, std::vector &value) const; + bool GetAttributesValue(AttributeKey key, Impl &array) const; std::vector Serialize() const; std::vector GetKeys() const; + static bool EncodeUint32Value(uint32_t src, std::vector &dst); + static bool DecodeUint32Value(const std::vector &src, uint32_t &dst); + private: static constexpr uint32_t MAX_ATTR_LENGTH = 81920; static constexpr uint32_t MAX_ATTR_COUNT = 512; static bool EncodeBoolValue(bool src, std::vector &dst); static bool EncodeUint64Value(uint64_t src, std::vector &dst); - static bool EncodeUint32Value(uint32_t src, std::vector &dst); static bool EncodeUint16Value(uint16_t src, std::vector &dst); static bool EncodeUint8Value(uint8_t src, std::vector &dst); static bool EncodeInt32Value(int32_t src, std::vector &dst); static bool EncodeInt64Value(int64_t src, std::vector &dst); static bool EncodeStringValue(const std::string &src, std::vector &dst); static bool EncodeUint64ArrayValue(const std::vector &src, std::vector &dst); + static bool EncodeInt32ArrayValue(const std::vector &src, std::vector &dst); static bool EncodeUint32ArrayValue(const std::vector &src, std::vector &dst); static bool EncodeUint16ArrayValue(const std::vector &src, std::vector &dst); static bool EncodeUint8ArrayValue(const std::vector &src, std::vector &dst); static bool DecodeBoolValue(const std::vector &src, bool &dst); static bool DecodeUint64Value(const std::vector &src, uint64_t &dst); - static bool DecodeUint32Value(const std::vector &src, uint32_t &dst); static bool DecodeUint16Value(const std::vector &src, uint16_t &dst); static bool DecodeUint8Value(const std::vector &src, uint8_t &dst); static bool DecodeInt32Value(const std::vector &src, int32_t &dst); @@ -97,13 +101,14 @@ private: static bool DecodeUint32ArrayValue(const std::vector &src, std::vector &dst); static bool DecodeUint16ArrayValue(const std::vector &src, std::vector &dst); static bool DecodeUint8ArrayValue(const std::vector &src, std::vector &dst); + static bool DecodeInt32ArrayValue(const std::vector &src, std::vector &dst); static bool CheckAttributeLength(const uint8_t *curr, const uint8_t *end, uint32_t length); - std::map> map_; + std::map> map_; }; Attributes::Impl::Impl(const std::vector &raw) { - std::map> out; + std::map> out; const uint8_t *curr = &raw.front(); const uint8_t *end = &raw.back() + sizeof(uint8_t); @@ -143,18 +148,18 @@ Attributes::Impl::Impl(const std::vector &raw) return; } - auto ret = out.try_emplace(static_cast(type), value); + auto ret = out.insert_or_assign(static_cast(type), value); if (!ret.second) { - IAM_LOGE("emplace pair error, type is %{public}u", type); + IAM_LOGE("insert_or_assign pair error, type is %{public}u", type); return; } if (out.size() > MAX_ATTR_COUNT) { - IAM_LOGE("emplace pair error, size reach max"); + IAM_LOGE("insert_or_assign pair error, size reach max"); return; } - IAM_LOGD("emplace pair success, type is %{public}u", type); + IAM_LOGD("insert_or_assign pair success, type is %{public}u", type); curr += length; } @@ -197,8 +202,8 @@ bool Attributes::Impl::SetBoolValue(AttributeKey key, bool value) return false; } - auto ret = map_.try_emplace(key, dest); - return ret.second; + map_.insert_or_assign(key, dest); + return true; } bool Attributes::Impl::SetUint64Value(AttributeKey key, uint64_t value) @@ -214,8 +219,8 @@ bool Attributes::Impl::SetUint64Value(AttributeKey key, uint64_t value) return false; } - auto ret = map_.try_emplace(key, dest); - return ret.second; + map_.insert_or_assign(key, dest); + return true; } bool Attributes::Impl::SetUint32Value(AttributeKey key, uint32_t value) @@ -231,8 +236,8 @@ bool Attributes::Impl::SetUint32Value(AttributeKey key, uint32_t value) return false; } - auto ret = map_.try_emplace(key, dest); - return ret.second; + map_.insert_or_assign(key, dest); + return true; } bool Attributes::Impl::SetUint16Value(AttributeKey key, uint16_t value) @@ -248,8 +253,8 @@ bool Attributes::Impl::SetUint16Value(AttributeKey key, uint16_t value) return false; } - auto ret = map_.try_emplace(key, dest); - return ret.second; + map_.insert_or_assign(key, dest); + return true; } bool Attributes::Impl::SetUint8Value(AttributeKey key, uint8_t value) @@ -265,8 +270,8 @@ bool Attributes::Impl::SetUint8Value(AttributeKey key, uint8_t value) return false; } - auto ret = map_.try_emplace(key, dest); - return ret.second; + map_[key] = dest; + return true; } bool Attributes::Impl::SetInt32Value(AttributeKey key, int32_t value) @@ -282,8 +287,8 @@ bool Attributes::Impl::SetInt32Value(AttributeKey key, int32_t value) return false; } - auto ret = map_.try_emplace(key, dest); - return ret.second; + map_.insert_or_assign(key, dest); + return true; } bool Attributes::Impl::SetInt64Value(AttributeKey key, int64_t value) @@ -316,8 +321,8 @@ bool Attributes::Impl::SetStringValue(AttributeKey key, const std::string &value return false; } - auto ret = map_.try_emplace(key, dest); - return ret.second; + map_.insert_or_assign(key, dest); + return true; } bool Attributes::Impl::SetUint64ArrayValue(AttributeKey key, const std::vector &value) @@ -333,8 +338,8 @@ bool Attributes::Impl::SetUint64ArrayValue(AttributeKey key, const std::vector &value) @@ -350,8 +355,25 @@ bool Attributes::Impl::SetUint32ArrayValue(AttributeKey key, const std::vector &value) +{ + std::vector dest; + if (!EncodeInt32ArrayValue(value, dest)) { + IAM_LOGE("EncodeUint32ArrayValue error"); + return false; + } + + if (map_.size() > MAX_ATTR_COUNT) { + IAM_LOGE("attrs size reach max"); + return false; + } + + map_.insert_or_assign(key, dest); + return true; } bool Attributes::Impl::SetUint16ArrayValue(AttributeKey key, const std::vector &value) @@ -367,8 +389,8 @@ bool Attributes::Impl::SetUint16ArrayValue(AttributeKey key, const std::vector &value) @@ -384,8 +406,8 @@ bool Attributes::Impl::SetUint8ArrayValue(AttributeKey key, const std::vector &value) const +{ + auto iter = map_.find(key); + if (iter == map_.end()) { + return false; + } + + if (!DecodeInt32ArrayValue(iter->second, value)) { + IAM_LOGE("DecodeUint32ArrayValue error"); + return false; + } + + return true; +} + bool Attributes::Impl::GetUint16ArrayValue(AttributeKey key, std::vector &value) const { auto iter = map_.find(key); @@ -766,6 +803,23 @@ bool Attributes::Impl::EncodeUint16ArrayValue(const std::vector &src, return true; } +bool Attributes::Impl::EncodeInt32ArrayValue(const std::vector &src, std::vector &dst) +{ + auto size = src.size() * (sizeof(int32_t) / sizeof(uint8_t)); + if (size > MAX_ATTR_LENGTH) { + return false; + } + + std::vector out(size); + + if (!src.empty() && + memcpy_s(out.data(), out.size() * sizeof(uint8_t), src.data(), src.size() * sizeof(int32_t)) != EOK) { + return false; + } + dst.swap(out); + return true; +} + bool Attributes::Impl::EncodeUint8ArrayValue(const std::vector &src, std::vector &dst) { if (src.size() > MAX_ATTR_LENGTH) { @@ -925,6 +979,23 @@ bool Attributes::Impl::DecodeUint8ArrayValue(const std::vector &src, st return true; } +bool Attributes::Impl::DecodeInt32ArrayValue(const std::vector &src, std::vector &dst) +{ + if (src.size() % (sizeof(int32_t) / sizeof(uint8_t)) != 0) { + return false; + } + + std::vector out(src.size() / (sizeof(int32_t) / sizeof(uint8_t))); + + if (!out.empty() && + memcpy_s(out.data(), out.size() * sizeof(int32_t), src.data(), src.size() * sizeof(uint8_t)) != EOK) { + return false; + } + + dst.swap(out); + return true; +} + Attributes::Attributes() : impl_(new (std::nothrow) Attributes::Impl()) { } @@ -1044,6 +1115,14 @@ bool Attributes::SetUint8ArrayValue(AttributeKey key, const std::vector return impl_->SetUint8ArrayValue(key, value); } +bool Attributes::SetInt32ArrayValue(AttributeKey key, const std::vector &value) +{ + if (!impl_) { + return false; + } + return impl_->SetInt32ArrayValue(key, value); +} + bool Attributes::SetAttributesValue(AttributeKey key, const Attributes &value) { if (!impl_) { @@ -1052,6 +1131,78 @@ bool Attributes::SetAttributesValue(AttributeKey key, const Attributes &value) return impl_->SetAttributesValue(key, *value.impl_); } +bool Attributes::SetAttributesArrayValue(AttributeKey key, const std::vector &array) +{ + if (!impl_) { + return false; + } + + std::vector> serializedArray; + for (auto &item : array) { + if (!item.impl_) { + return false; + } + serializedArray.push_back(item.Serialize()); + } + + uint32_t dataLen = 0; + for (auto &array : serializedArray) { + dataLen += (sizeof(uint32_t) + array.size()); + } + + std::vector data; + data.reserve(dataLen); + for (auto &array : serializedArray) { + std::vector arrayLen; + bool encodeRet = Attributes::Impl::EncodeUint32Value(array.size(), arrayLen); + if (!encodeRet) { + return false; + } + std::copy(arrayLen.begin(), arrayLen.end(), std::back_inserter(data)); + std::copy(array.begin(), array.end(), std::back_inserter(data)); + } + + return impl_->SetUint8ArrayValue(key, data); +} + +bool Attributes::GetAttributesArrayValue(AttributeKey key, std::vector &array) const +{ + if (!impl_) { + return false; + } + + std::vector data; + bool getDataRet = impl_->GetUint8ArrayValue(key, data); + if (!getDataRet) { + return false; + } + + array.clear(); + uint32_t i = 0; + while (i < data.size()) { + if (data.size() - i < sizeof(uint32_t)) { + return false; + } + + std::vector arrayLenData(data.begin() + i, data.begin() + i + sizeof(uint32_t)); + uint32_t arrayLen; + bool decodeRet = Attributes::Impl::DecodeUint32Value(arrayLenData, arrayLen); + if (!decodeRet) { + return false; + } + i += sizeof(uint32_t); + + if (data.size() - i < arrayLen) { + return false; + } + + array.push_back(Attributes(std::vector(data.begin() + i, data.begin() + i + arrayLen))); + i += arrayLen; + } + + return true; +} + bool Attributes::GetBoolValue(AttributeKey key, bool &value) const { if (!impl_) { @@ -1148,6 +1299,14 @@ bool Attributes::GetUint8ArrayValue(AttributeKey key, std::vector &valu return impl_->GetUint8ArrayValue(key, value); } +bool Attributes::GetInt32ArrayValue(AttributeKey key, std::vector &value) const +{ + if (!impl_) { + return false; + } + return impl_->GetInt32ArrayValue(key, value); +} + bool Attributes::GetAttributesValue(AttributeKey key, Attributes &value) const { if (!impl_) { diff --git a/frameworks/native/executors/include/framework/framework_executor_callback.h b/frameworks/native/executors/include/framework/framework_executor_callback.h index 03c050bd801844ce02b4686f38e2297f28c169e5..a5f68b5d5445a86258d022fe7284a73a08434280 100644 --- a/frameworks/native/executors/include/framework/framework_executor_callback.h +++ b/frameworks/native/executors/include/framework/framework_executor_callback.h @@ -25,6 +25,7 @@ #include "co_auth_client_callback.h" #include "executor.h" #include "iam_common_defines.h" +#include "executor_messenger_interface.h" namespace OHOS { namespace UserIam { @@ -34,8 +35,8 @@ public: explicit FrameworkExecutorCallback(std::weak_ptr executor); ~FrameworkExecutorCallback() override = default; - void OnMessengerReady(const std::shared_ptr &messenger, const std::vector &publicKey, - const std::vector &templateIds) override; + void OnMessengerReady(uint64_t executorIndex, const std::shared_ptr &messenger, + const std::vector &publicKey, const std::vector &templateIdList) override; int32_t OnBeginExecute(uint64_t scheduleId, const std::vector &publicKey, const Attributes &commandAttrs) override; diff --git a/frameworks/native/executors/src/async_command/async_command_base.cpp b/frameworks/native/executors/src/async_command/async_command_base.cpp index aac5976e9db3a1335bbe024cc0b4c88368578cce..a030d5a941733161990535f6c2941adec6605cac 100644 --- a/frameworks/native/executors/src/async_command/async_command_base.cpp +++ b/frameworks/native/executors/src/async_command/async_command_base.cpp @@ -148,7 +148,7 @@ void AsyncCommandBase::OnMessageInner(int destRole, const std::vector & IAM_LOGE("%{public}s call SendData fail", GetDescription()); return; } - IAM_LOGI("%{public}s end, msg size %{public}uz", GetDescription(), msg.size()); + IAM_LOGI("%{public}s end, msg size %{public}zu", GetDescription(), msg.size()); } int32_t AsyncCommandBase::GetAuthType() diff --git a/frameworks/native/executors/src/async_command/auth_command.cpp b/frameworks/native/executors/src/async_command/auth_command.cpp index c51ab133c82e18dc8a17293e5d4e80227f9830f6..2ad79bfcfbd204c4cde968f2bea59ce36a56cdb0 100644 --- a/frameworks/native/executors/src/async_command/auth_command.cpp +++ b/frameworks/native/executors/src/async_command/auth_command.cpp @@ -53,7 +53,7 @@ ResultCode AuthCommand::SendRequest() bool getEndAfterFirstFailRet = attributes_->GetBoolValue(Attributes::ATTR_END_AFTER_FIRST_FAIL, endAfterFirstFail); IF_FALSE_LOGE_AND_RETURN_VAL(getEndAfterFirstFailRet == true, ResultCode::GENERAL_ERROR); std::vector extraInfo; - bool getExtraInfoRet = attributes_->GetUint8ArrayValue(Attributes::ATTR_VERIFIER_MESSAGE, extraInfo); + bool getExtraInfoRet = attributes_->GetUint8ArrayValue(Attributes::ATTR_EXTRA_INFO, extraInfo); IF_FALSE_LOGE_AND_RETURN_VAL(getExtraInfoRet == true, ResultCode::GENERAL_ERROR); IAM_LOGI("%{public}s auth message len %{public}zu", GetDescription(), extraInfo.size()); diff --git a/frameworks/native/executors/src/async_command/collect_command.cpp b/frameworks/native/executors/src/async_command/collect_command.cpp index 2142801a63e2a177b78340fa932b34b899880125..4911d692794cfe1126481520a177c637e40d584d 100644 --- a/frameworks/native/executors/src/async_command/collect_command.cpp +++ b/frameworks/native/executors/src/async_command/collect_command.cpp @@ -43,16 +43,16 @@ ResultCode CollectCommand::SendRequest() auto hdi = GetExecutorHdi(); IF_FALSE_LOGE_AND_RETURN_VAL(hdi != nullptr, ResultCode::GENERAL_ERROR); - uint32_t tokenId = 0; - bool getTokenIdRet = attributes_->GetUint32Value(Attributes::ATTR_ACCESS_TOKEN_ID, tokenId); - IF_FALSE_LOGE_AND_RETURN_VAL(getTokenIdRet == true, ResultCode::GENERAL_ERROR); + uint32_t collectorTokenId = 0; + bool getCollectorTokenIdRet = attributes_->GetUint32Value(Attributes::ATTR_COLLECTOR_TOKEN_ID, collectorTokenId); + IF_FALSE_LOGE_AND_RETURN_VAL(getCollectorTokenIdRet == true, ResultCode::GENERAL_ERROR); std::vector extraInfo; - bool getExtraInfoRet = attributes_->GetUint8ArrayValue(Attributes::ATTR_COLLECTOR_MESSAGE, extraInfo); + bool getExtraInfoRet = attributes_->GetUint8ArrayValue(Attributes::ATTR_EXTRA_INFO, extraInfo); IF_FALSE_LOGE_AND_RETURN_VAL(getExtraInfoRet == true, ResultCode::GENERAL_ERROR); IAM_LOGI("%{public}s collect message len %{public}zu", GetDescription(), extraInfo.size()); IamHitraceHelper traceHelper("hdi collect"); - ResultCode ret = hdi->Collect(scheduleId_, (CollectParam) { tokenId, extraInfo }, shared_from_this()); + ResultCode ret = hdi->Collect(scheduleId_, (CollectParam) { 0, collectorTokenId, extraInfo }, shared_from_this()); IAM_LOGI("%{public}s collect result %{public}d", GetDescription(), ret); return ret; } diff --git a/frameworks/native/executors/src/async_command/enroll_command.cpp b/frameworks/native/executors/src/async_command/enroll_command.cpp index 295586cf27bfbbb9f289fd7a2537a51b76b2fc76..bda71c652c5f2e98cdedc958222f5583fdbfecdb 100644 --- a/frameworks/native/executors/src/async_command/enroll_command.cpp +++ b/frameworks/native/executors/src/async_command/enroll_command.cpp @@ -50,7 +50,7 @@ ResultCode EnrollCommand::SendRequest() IF_FALSE_LOGE_AND_RETURN_VAL(getTokenIdRet == true, ResultCode::GENERAL_ERROR); std::vector extraInfo; - bool getExtraInfoRet = attributes_->GetUint8ArrayValue(Attributes::ATTR_VERIFIER_MESSAGE, extraInfo); + bool getExtraInfoRet = attributes_->GetUint8ArrayValue(Attributes::ATTR_EXTRA_INFO, extraInfo); IF_FALSE_LOGE_AND_RETURN_VAL(getExtraInfoRet == true, ResultCode::GENERAL_ERROR); IamHitraceHelper traceHelper("hdi Enroll"); diff --git a/frameworks/native/executors/src/async_command/identify_command.cpp b/frameworks/native/executors/src/async_command/identify_command.cpp index 1d675a3bd54e6ddb8209ae55b2396c647a82bfbf..70f9796ea4dc19459e89ba656d0781481685ca6e 100644 --- a/frameworks/native/executors/src/async_command/identify_command.cpp +++ b/frameworks/native/executors/src/async_command/identify_command.cpp @@ -46,7 +46,7 @@ ResultCode IdentifyCommand::SendRequest() IF_FALSE_LOGE_AND_RETURN_VAL(getTokenIdRet == true, ResultCode::GENERAL_ERROR); std::vector extraInfo; - bool getExtraInfoRet = attributes_->GetUint8ArrayValue(Attributes::ATTR_VERIFIER_MESSAGE, extraInfo); + bool getExtraInfoRet = attributes_->GetUint8ArrayValue(Attributes::ATTR_EXTRA_INFO, extraInfo); IF_FALSE_LOGE_AND_RETURN_VAL(getExtraInfoRet == true, ResultCode::GENERAL_ERROR); IamHitraceHelper traceHelper("hdi Identify"); diff --git a/frameworks/native/executors/src/executor.cpp b/frameworks/native/executors/src/executor.cpp index 20c1a4ce02b087efc857ba5578826a3a9622c3dd..93c6f9ec118df782ac5a2f032f923023d7e8c3ea 100644 --- a/frameworks/native/executors/src/executor.cpp +++ b/frameworks/native/executors/src/executor.cpp @@ -46,7 +46,8 @@ Executor::Executor(std::shared_ptr executorMgrWrapper, uint32_t combineExecutorId = Common::CombineUint16ToUint32(hdiId_, static_cast(executorInfo.executorSensorHint)); const uint32_t uint32HexWidth = 8; - ss << "Executor(Id:0x" << std::setfill('0') << std::setw(uint32HexWidth) << std::hex << combineExecutorId << ")"; + ss << "Executor(Id:0x" << std::setfill('0') << std::setw(uint32HexWidth) << std::hex << combineExecutorId + << ", role:" << executorRole_ << ", authType:" << authType_ << ")"; description_ = ss.str(); } diff --git a/frameworks/native/executors/src/framework/framework_executor_callback.cpp b/frameworks/native/executors/src/framework/framework_executor_callback.cpp index afe31cc8cfd61a3270fe3fdbfeb68bfb6f7aee6e..a54c68d010f90e2cd7a8953d42471eb00ea032a9 100644 --- a/frameworks/native/executors/src/framework/framework_executor_callback.cpp +++ b/frameworks/native/executors/src/framework/framework_executor_callback.cpp @@ -19,6 +19,7 @@ #include #include "auth_command.h" +#include "collect_command.h" #include "custom_command.h" #include "enroll_command.h" #include "hisysevent_adapter.h" @@ -94,8 +95,9 @@ ResultCode FrameworkExecutorCallback::OnEndExecuteInner(uint64_t scheduleId, con return ret; } -void FrameworkExecutorCallback::OnMessengerReady(const std::shared_ptr &messenger, - const std::vector &publicKey, const std::vector &templateIds) +void FrameworkExecutorCallback::OnMessengerReady(uint64_t executorIndex, + const std::shared_ptr &messenger, const std::vector &publicKey, + const std::vector &templateIdList) { IAM_LOGI("%{public}s start", GetDescription()); auto executor = executor_.lock(); @@ -107,7 +109,7 @@ void FrameworkExecutorCallback::OnMessengerReady(const std::shared_ptr extraInfo; - hdi->OnRegisterFinish(templateIds, publicKey, extraInfo); + hdi->OnRegisterFinish(templateIdList, publicKey, extraInfo); } int32_t FrameworkExecutorCallback::OnSetProperty(const Attributes &properties) @@ -195,7 +197,18 @@ ResultCode FrameworkExecutorCallback::ProcessEnrollCommand(uint64_t scheduleId, ResultCode FrameworkExecutorCallback::ProcessAuthCommand(uint64_t scheduleId, const Attributes &properties) { - auto command = Common::MakeShared(executor_, scheduleId, properties, executorMessenger_); + auto executor = executor_.lock(); + if (executor == nullptr) { + IAM_LOGE("executor has been released, process failed"); + return ResultCode::GENERAL_ERROR; + } + + std::shared_ptr command = nullptr; + if (executor->GetExecutorRole() == COLLECTOR) { + command = Common::MakeShared(executor_, scheduleId, properties, executorMessenger_); + } else { + command = Common::MakeShared(executor_, scheduleId, properties, executorMessenger_); + } IF_FALSE_LOGE_AND_RETURN_VAL(command != nullptr, ResultCode::GENERAL_ERROR); return command->StartProcess(); } diff --git a/frameworks/native/ipc/common_defines/co_auth_interface.h b/frameworks/native/ipc/common_defines/co_auth_interface.h index 88161d250560c9af19afba4455c3009b4b74bc8f..05cfd869b578d8697c338dbe482cbc11f2de99d0 100644 --- a/frameworks/native/ipc/common_defines/co_auth_interface.h +++ b/frameworks/native/ipc/common_defines/co_auth_interface.h @@ -17,6 +17,7 @@ #define CO_AUTH_INTERFACE_H #include +#include #include "executor_callback_interface.h" #include "iam_common_defines.h" @@ -38,9 +39,12 @@ public: ExecutorSecureLevel esl; uint32_t maxTemplateAcl {0}; std::vector publicKey; + std::string deviceUdid; + std::vector signedRemoteExecutorInfo; }; virtual uint64_t ExecutorRegister(const ExecutorRegisterInfo &info, sptr &callback) = 0; + virtual void ExecutorUnregister(uint64_t executorIndex) = 0; DECLARE_INTERFACE_DESCRIPTOR(u"ohos.CoAuth.ICoAuth"); }; } // namespace UserAuth diff --git a/frameworks/native/ipc/common_defines/co_auth_interface_ipc_interface_code.h b/frameworks/native/ipc/common_defines/co_auth_interface_ipc_interface_code.h index 0e506577dafaa21be70412e88e504d8165fce5d1..89ad676464bba7ef5a55dd7d162bcc93c095857f 100644 --- a/frameworks/native/ipc/common_defines/co_auth_interface_ipc_interface_code.h +++ b/frameworks/native/ipc/common_defines/co_auth_interface_ipc_interface_code.h @@ -22,6 +22,7 @@ namespace UserIam { namespace UserAuth { enum CoAuthInterfaceCode : uint32_t { CO_AUTH_EXECUTOR_REGISTER = 0, + CO_AUTH_EXECUTOR_UNREGISTER = 1, }; } // namespace UserAuth } // namespace UserIam diff --git a/frameworks/native/ipc/common_defines/executor_callback_interface.h b/frameworks/native/ipc/common_defines/executor_callback_interface.h index 4f15fd863aff070a16cc06fd6643cf25aca528cc..6a60a73fdc294a580f497d23db210e58fa779008 100644 --- a/frameworks/native/ipc/common_defines/executor_callback_interface.h +++ b/frameworks/native/ipc/common_defines/executor_callback_interface.h @@ -22,13 +22,14 @@ #include "executor_messenger_interface.h" #include "executor_callback_interface_ipc_interface_code.h" + namespace OHOS { namespace UserIam { namespace UserAuth { class ExecutorCallbackInterface : public IRemoteBroker { public: - virtual void OnMessengerReady(sptr &messenger, const std::vector &publicKey, - const std::vector &templateIdList) = 0; + virtual void OnMessengerReady(uint64_t executorIndex, sptr &messenger, + const std::vector &publicKey, const std::vector &templateIdList) = 0; virtual int32_t OnBeginExecute(uint64_t scheduleId, const std::vector &publicKey, const Attributes &command) = 0; virtual int32_t OnEndExecute(uint64_t scheduleId, const Attributes &command) = 0; diff --git a/frameworks/native/ipc/common_defines/user_auth_common_defines.h b/frameworks/native/ipc/common_defines/user_auth_common_defines.h index 49a1b80fa5e784c43395d466b2d3e7413df38b81..59f0f4424aca047385a8b23f4578d7fef892fff8 100644 --- a/frameworks/native/ipc/common_defines/user_auth_common_defines.h +++ b/frameworks/native/ipc/common_defines/user_auth_common_defines.h @@ -31,6 +31,7 @@ #include #include "iam_common_defines.h" +#include "user_auth_client_defines.h" namespace OHOS { namespace UserIam { @@ -89,15 +90,21 @@ struct ReuseUnlockResult { /** * @brief Auth parameter. */ -struct AuthParam { +struct AuthParamInner { + /** user id */ + int32_t userId; /** challenge value */ std::vector challenge; /** Credential type for authentication. */ - std::vector authType; + AuthType authType; + /** Credential type for authentication. */ + std::vector authTypes; /** Trust level of authentication result. */ AuthTrustLevel authTrustLevel; /** Reuse unlock authentication result. */ ReuseUnlockResult reuseUnlockResult; + /** Auth intent. */ + AuthIntent authIntent; }; /** diff --git a/frameworks/native/ipc/common_defines/user_auth_interface.h b/frameworks/native/ipc/common_defines/user_auth_interface.h index 50e06a2f4421c40fbe67ce59cec89b45c9613338..3537a90b97549dd92e44800616ea2484a3e404e9 100644 --- a/frameworks/native/ipc/common_defines/user_auth_interface.h +++ b/frameworks/native/ipc/common_defines/user_auth_interface.h @@ -41,13 +41,13 @@ public: virtual void SetProperty(int32_t userId, AuthType authType, const Attributes &attributes, sptr &callback) = 0; - virtual uint64_t AuthUser(int32_t userId, const std::vector &challenge, AuthType authType, - AuthTrustLevel authTrustLevel, sptr &callback) = 0; + virtual uint64_t AuthUser(AuthParamInner ¶m, std::optional &remoteAuthParam, + sptr &callback) = 0; virtual uint64_t Auth(int32_t apiVersion, const std::vector &challenge, AuthType authType, AuthTrustLevel authTrustLevel, sptr &callback) = 0; - virtual uint64_t AuthWidget(int32_t apiVersion, const AuthParam &authParam, + virtual uint64_t AuthWidget(int32_t apiVersion, const AuthParamInner &authParam, const WidgetParam &widgetParam, sptr &callback) = 0; virtual uint64_t Identify(const std::vector &challenge, AuthType authType, @@ -71,6 +71,8 @@ public: virtual int32_t SetGlobalConfigParam(const GlobalConfigParam ¶m) = 0; + virtual int32_t PrepareRemoteAuth(const std::string &networkId, sptr &callback) = 0; + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.UserIam.UserAuth.IUserAuth"); }; } // namespace UserAuth diff --git a/frameworks/native/ipc/common_defines/user_auth_interface_ipc_interface_code.h b/frameworks/native/ipc/common_defines/user_auth_interface_ipc_interface_code.h index 838b2965075e7d0a5200763206e851d76149e880..89c2d57c3235744285bd920ab9d2aa9b91b3e5a8 100644 --- a/frameworks/native/ipc/common_defines/user_auth_interface_ipc_interface_code.h +++ b/frameworks/native/ipc/common_defines/user_auth_interface_ipc_interface_code.h @@ -44,6 +44,7 @@ enum UserAuthInterfaceCode : uint32_t { USER_AUTH_UNREG_EVENT_LISTENER, USER_AUTH_EVENT_LISTENER_NOTIFY, USER_AUTH_SET_CLOBAL_CONFIG_PARAM, + USER_AUTH_PREPARE_REMOTE_AUTH, }; } // namespace UserAuth } // namespace UserIam diff --git a/frameworks/native/ipc/inc/co_auth_proxy.h b/frameworks/native/ipc/inc/co_auth_proxy.h index 1b64eb4d7a74d54e6e891c49e61080ec04db1a82..256322618a88892c1a8e3906356c77bd4bcbf0b2 100644 --- a/frameworks/native/ipc/inc/co_auth_proxy.h +++ b/frameworks/native/ipc/inc/co_auth_proxy.h @@ -29,6 +29,7 @@ public: explicit CoAuthProxy(const sptr &impl); ~CoAuthProxy() override = default; uint64_t ExecutorRegister(const ExecutorRegisterInfo &info, sptr &callback) override; + void ExecutorUnregister(uint64_t executorIndex) override; private: static inline BrokerDelegator delegator_; diff --git a/frameworks/native/ipc/inc/co_auth_stub.h b/frameworks/native/ipc/inc/co_auth_stub.h index 8cf1cfa677c3bded51cffb4712a4c6802eac71e4..47ee7043997ce6e670e720b191d56ac38aeb6f20 100644 --- a/frameworks/native/ipc/inc/co_auth_stub.h +++ b/frameworks/native/ipc/inc/co_auth_stub.h @@ -33,6 +33,7 @@ public: private: int32_t ExecutorRegisterStub(MessageParcel &data, MessageParcel &reply); + int32_t ExecutorUnregisterStub(MessageParcel &data, MessageParcel &reply); int32_t ReadExecutorRegisterInfo(ExecutorRegisterInfo &executorInfo, MessageParcel &data); }; } // namespace UserAuth diff --git a/frameworks/native/ipc/inc/executor_callback_proxy.h b/frameworks/native/ipc/inc/executor_callback_proxy.h index cd18cdd316348f0c9c4f15b7b1bf7ef69c69199a..1895ea9bebc40a0ec488a8c1faf0132f6cd9c2bd 100644 --- a/frameworks/native/ipc/inc/executor_callback_proxy.h +++ b/frameworks/native/ipc/inc/executor_callback_proxy.h @@ -29,8 +29,8 @@ public: { } ~ExecutorCallbackProxy() override = default; - void OnMessengerReady(sptr &messenger, const std::vector &publicKey, - const std::vector &templateIdList) override; + void OnMessengerReady(uint64_t executorIndex, sptr &messenger, + const std::vector &publicKey, const std::vector &templateIdList) override; int32_t OnBeginExecute(uint64_t scheduleId, const std::vector &publicKey, const Attributes &command) override; int32_t OnEndExecute(uint64_t scheduleId, const Attributes &command) override; diff --git a/frameworks/native/ipc/inc/user_auth_proxy.h b/frameworks/native/ipc/inc/user_auth_proxy.h index 7ccee3fc232006ce487ea2138401eca33803500f..38e3a81158af1c7a2e62f80e8476b3da1e8d5ddf 100644 --- a/frameworks/native/ipc/inc/user_auth_proxy.h +++ b/frameworks/native/ipc/inc/user_auth_proxy.h @@ -34,11 +34,11 @@ public: sptr &callback) override; void SetProperty(int32_t userId, AuthType authType, const Attributes &attributes, sptr &callback) override; - uint64_t AuthUser(int32_t userId, const std::vector &challenge, AuthType authType, - AuthTrustLevel authTrustLevel, sptr &callback) override; + uint64_t AuthUser(AuthParamInner ¶m, std::optional &remoteAuthParam, + sptr &callback) override; uint64_t Auth(int32_t apiVersion, const std::vector &challenge, AuthType authType, AuthTrustLevel authTrustLevel, sptr &callback) override; - uint64_t AuthWidget(int32_t apiVersion, const AuthParam &authParam, + uint64_t AuthWidget(int32_t apiVersion, const AuthParamInner &authParam, const WidgetParam &widgetParam, sptr &callback) override; uint64_t Identify(const std::vector &challenge, AuthType authType, sptr &callback) override; @@ -52,13 +52,16 @@ public: int32_t UnRegistUserAuthSuccessEventListener( const sptr &listener) override; int32_t SetGlobalConfigParam(const GlobalConfigParam ¶m) override; + int32_t PrepareRemoteAuth(const std::string &networkId, sptr &callback) override; private: static inline BrokerDelegator delegator_; - bool WriteAuthParam(MessageParcel &data, const std::vector &challenge, - AuthType authType, AuthTrustLevel authTrustLevel, sptr &callback); + bool WriteAuthParam(MessageParcel &data, const AuthParamInner &authParam); + bool WriteRemoteAuthParam(MessageParcel &data, const std::optional &remoteAuthParam); + bool WriteOptionalString(MessageParcel &data, const std::optional &str); + bool WriteOptionalUint32(MessageParcel &data, const std::optional &val); bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); - bool WriteWidgetParam(MessageParcel &data, const AuthParam &authParam, const WidgetParam &widgetParam); + bool WriteWidgetParam(MessageParcel &data, const AuthParamInner &authParam, const WidgetParam &widgetParam); }; } // namespace UserAuth } // namespace UserIam diff --git a/frameworks/native/ipc/inc/user_auth_stub.h b/frameworks/native/ipc/inc/user_auth_stub.h index fe0ab2104aa2adb0841e874a3c0fe88a1d647ae1..1078edf1ff26bbb73126affa9efa7f4cf33c0cb4 100644 --- a/frameworks/native/ipc/inc/user_auth_stub.h +++ b/frameworks/native/ipc/inc/user_auth_stub.h @@ -41,12 +41,17 @@ private: int32_t CancelAuthOrIdentifyStub(MessageParcel &data, MessageParcel &reply); int32_t GetVersionStub(MessageParcel &data, MessageParcel &reply); int32_t NoticeStub(MessageParcel &data, MessageParcel &reply); - bool ReadWidgetParam(MessageParcel &data, AuthParam &authParam, WidgetParam &widgetParam); + bool ReadWidgetParam(MessageParcel &data, AuthParamInner &authParam, WidgetParam &widgetParam); int32_t RegisterWidgetCallbackStub(MessageParcel &data, MessageParcel &reply); int32_t GetEnrolledStateStub(MessageParcel &data, MessageParcel &reply); int32_t RegistUserAuthSuccessEventListenerStub(MessageParcel &data, MessageParcel &reply); int32_t UnRegistUserAuthSuccessEventListenerStub(MessageParcel &data, MessageParcel &reply); int32_t SetGlobalConfigParamStub(MessageParcel &data, MessageParcel &reply); + int32_t PrepareRemoteAuthStub(MessageParcel &data, MessageParcel &reply); + bool ReadAuthParam(MessageParcel &data, AuthParamInner &authParam); + bool ReadRemoteAuthParam(MessageParcel &data, std::optional &remoteAuthParam); + bool ReadOptionalString(MessageParcel &data, std::optional &str); + bool ReadOptionalUint32(MessageParcel &data, std::optional &val); }; } // namespace UserAuth } // namespace UserIam diff --git a/frameworks/native/ipc/src/co_auth_proxy.cpp b/frameworks/native/ipc/src/co_auth_proxy.cpp index 3c73ac1537c67920a62bc9fdec6b68797156c10c..f7b27078efc3e77c7b6494751c475abdb62cd541 100644 --- a/frameworks/native/ipc/src/co_auth_proxy.cpp +++ b/frameworks/native/ipc/src/co_auth_proxy.cpp @@ -59,6 +59,14 @@ int32_t CoAuthProxy::WriteExecutorInfo(const ExecutorRegisterInfo &info, Message IAM_LOGE("failed to write publicKey"); return WRITE_PARCEL_ERROR; } + if (!data.WriteString(info.deviceUdid)) { + IAM_LOGE("failed to write publicKey"); + return WRITE_PARCEL_ERROR; + } + if (!data.WriteUInt8Vector(info.signedRemoteExecutorInfo)) { + IAM_LOGE("failed to write publicKey"); + return WRITE_PARCEL_ERROR; + } return SUCCESS; } @@ -99,6 +107,29 @@ uint64_t CoAuthProxy::ExecutorRegister(const ExecutorRegisterInfo &info, sptr(authType); executorInfo.executorRole = static_cast(executorRole); - executorInfo.executorSensorHint = executorSensorHint; - executorInfo.executorMatcher = executorMatcher; - executorInfo.maxTemplateAcl = maxTemplateAcl; executorInfo.esl = static_cast(esl); return SUCCESS; } diff --git a/frameworks/native/ipc/src/executor_callback_proxy.cpp b/frameworks/native/ipc/src/executor_callback_proxy.cpp index 971e1a7207a4770d963e5f0ce611ceae9c9e7181..4432b998e83aec40da9a4852fd453eb174a094d4 100644 --- a/frameworks/native/ipc/src/executor_callback_proxy.cpp +++ b/frameworks/native/ipc/src/executor_callback_proxy.cpp @@ -24,7 +24,7 @@ namespace OHOS { namespace UserIam { namespace UserAuth { -void ExecutorCallbackProxy::OnMessengerReady(sptr &messenger, +void ExecutorCallbackProxy::OnMessengerReady(uint64_t executorIndex, sptr &messenger, const std::vector &publicKey, const std::vector &templateIdList) { if (messenger == nullptr) { @@ -38,6 +38,12 @@ void ExecutorCallbackProxy::OnMessengerReady(sptr &m IAM_LOGE("failed to write descriptor"); return; } + + if (!data.WriteUint64(executorIndex)) { + IAM_LOGE("failed to write executorIndex"); + return; + } + if (!data.WriteRemoteObject(messenger->AsObject())) { IAM_LOGE("failed to write messenger failed"); return; diff --git a/frameworks/native/ipc/src/executor_callback_stub.cpp b/frameworks/native/ipc/src/executor_callback_stub.cpp index 77573404f84968460110d6ef70d8f73a65ea1640..84625e9db0e990995bb8cdac2b6cd2483353bfb0 100644 --- a/frameworks/native/ipc/src/executor_callback_stub.cpp +++ b/frameworks/native/ipc/src/executor_callback_stub.cpp @@ -52,11 +52,18 @@ int32_t ExecutorCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data int32_t ExecutorCallbackStub::OnMessengerReadyStub(MessageParcel &data, MessageParcel &reply) { + uint64_t executorIndex; + if (!data.ReadUint64(executorIndex)) { + IAM_LOGE("failed to read publicKey"); + return READ_PARCEL_ERROR; + } + sptr obj = data.ReadRemoteObject(); if (obj == nullptr) { IAM_LOGE("failed to read remote object"); return READ_PARCEL_ERROR; } + sptr messenger = iface_cast(obj); if (messenger == nullptr) { IAM_LOGE("executor messenger is nullptr"); @@ -75,7 +82,7 @@ int32_t ExecutorCallbackStub::OnMessengerReadyStub(MessageParcel &data, MessageP return READ_PARCEL_ERROR; } - OnMessengerReady(messenger, publicKey, templateIds); + OnMessengerReady(executorIndex, messenger, publicKey, templateIds); return SUCCESS; } diff --git a/frameworks/native/ipc/src/user_auth_proxy.cpp b/frameworks/native/ipc/src/user_auth_proxy.cpp index b6c71767cad6bf89f23823563f6c86d1f6df94a6..588c70ff159b685034dbf234a4513bc776778878 100644 --- a/frameworks/native/ipc/src/user_auth_proxy.cpp +++ b/frameworks/native/ipc/src/user_auth_proxy.cpp @@ -161,25 +161,99 @@ void UserAuthProxy::SetProperty(int32_t userId, AuthType authType, const Attribu } } -bool UserAuthProxy::WriteAuthParam(MessageParcel &data, const std::vector &challenge, - AuthType authType, AuthTrustLevel authTrustLevel, sptr &callback) +bool UserAuthProxy::WriteAuthParam(MessageParcel &data, const AuthParamInner &authParam) { - if (!data.WriteUInt8Vector(challenge)) { + if (!data.WriteInt32(authParam.userId)) { + IAM_LOGE("failed to write authType"); + return false; + } + if (!data.WriteUInt8Vector(authParam.challenge)) { IAM_LOGE("failed to write challenge"); return false; } - if (!data.WriteInt32(authType)) { + if (!data.WriteInt32(authParam.authType)) { IAM_LOGE("failed to write authType"); return false; } - if (!data.WriteUint32(authTrustLevel)) { + std::vector atList; + for (auto at : authParam.authTypes) { + atList.push_back(static_cast(at)); + } + if (!data.WriteInt32Vector(atList)) { + IAM_LOGE("failed to write authTypeList"); + return false; + } + if (!data.WriteUint32(authParam.authTrustLevel)) { IAM_LOGE("failed to write authTrustLevel"); return false; } - if (!data.WriteRemoteObject(callback->AsObject())) { - IAM_LOGE("failed to write callback"); + if (!data.WriteUint32(authParam.authIntent)) { + IAM_LOGE("failed to write authIntent"); + return false; + } + + return true; +} + +bool UserAuthProxy::WriteRemoteAuthParam(MessageParcel &data, const std::optional &remoteAuthParam) +{ + if (!data.WriteBool(remoteAuthParam.has_value())) { + IAM_LOGE("failed to write remoteAuthParam has value"); + return false; + } + + if (!remoteAuthParam.has_value()) { + return true; + } + + if (!WriteOptionalString(data, remoteAuthParam.value().verifierNetworkId)) { + IAM_LOGE("failed to write verifierNetworkId"); + return false; + } + + if (!WriteOptionalString(data, remoteAuthParam.value().collectorNetworkId)) { + IAM_LOGE("failed to write collectorNetworkId"); + return false; + } + + if (!WriteOptionalUint32(data, remoteAuthParam.value().collectorTokenId)) { + IAM_LOGE("failed to write collectorTokenId"); + return false; + } + + return true; +} + +bool UserAuthProxy::WriteOptionalString(MessageParcel &data, const std::optional &str) +{ + if (!data.WriteBool(str.has_value())) { + IAM_LOGE("failed to write str has value"); return false; } + + if (str.has_value()) { + if (!data.WriteString(str.value())) { + IAM_LOGE("failed to write str"); + return false; + } + } + return true; +} + +bool UserAuthProxy::WriteOptionalUint32(MessageParcel &data, const std::optional &val) +{ + if (!data.WriteBool(val.has_value())) { + IAM_LOGE("failed to write val has value"); + return false; + } + + if (val.has_value()) { + if (!data.WriteUint32(val.value())) { + IAM_LOGE("failed to write val"); + return false; + } + } + return true; } @@ -197,14 +271,26 @@ uint64_t UserAuthProxy::Auth(int32_t apiVersion, const std::vector &cha IAM_LOGE("failed to write descriptor"); return BAD_CONTEXT_ID; } - if (!WriteAuthParam(data, challenge, authType, authTrustLevel, callback)) { + if (!data.WriteInt32(apiVersion)) { + IAM_LOGE("failed to write apiVersion"); + return BAD_CONTEXT_ID; + } + AuthParamInner authParam = { + .userId = 0, + .challenge = challenge, + .authType = authType, + .authTrustLevel = authTrustLevel, + }; + if (!WriteAuthParam(data, authParam)) { IAM_LOGE("failed to write auth param"); return BAD_CONTEXT_ID; } - if (!data.WriteInt32(apiVersion)) { - IAM_LOGE("failed to write apiVersion"); + + if (!data.WriteRemoteObject(callback->AsObject())) { + IAM_LOGE("failed to write callback"); return BAD_CONTEXT_ID; } + bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_AUTH, data, reply); if (!ret) { IAM_LOGE("failed to send user auth IPC request"); @@ -217,7 +303,7 @@ uint64_t UserAuthProxy::Auth(int32_t apiVersion, const std::vector &cha return result; } -uint64_t UserAuthProxy::AuthWidget(int32_t apiVersion, const AuthParam &authParam, +uint64_t UserAuthProxy::AuthWidget(int32_t apiVersion, const AuthParamInner &authParam, const WidgetParam &widgetParam, sptr &callback) { if (callback == nullptr) { @@ -259,14 +345,15 @@ uint64_t UserAuthProxy::AuthWidget(int32_t apiVersion, const AuthParam &authPara return result; } -bool UserAuthProxy::WriteWidgetParam(MessageParcel &data, const AuthParam &authParam, const WidgetParam &widgetParam) +bool UserAuthProxy::WriteWidgetParam(MessageParcel &data, const AuthParamInner &authParam, + const WidgetParam &widgetParam) { if (!data.WriteUInt8Vector(authParam.challenge)) { IAM_LOGE("failed to write challenge"); return false; } std::vector atList; - for (auto at : authParam.authType) { + for (auto at : authParam.authTypes) { atList.push_back(static_cast(at)); } if (!data.WriteInt32Vector(atList)) { @@ -307,8 +394,8 @@ bool UserAuthProxy::WriteWidgetParam(MessageParcel &data, const AuthParam &authP return true; } -uint64_t UserAuthProxy::AuthUser(int32_t userId, const std::vector &challenge, - AuthType authType, AuthTrustLevel authTrustLevel, sptr &callback) +uint64_t UserAuthProxy::AuthUser(AuthParamInner ¶m, std::optional &remoteAuthParam, + sptr &callback) { if (callback == nullptr) { IAM_LOGE("callback is nullptr"); @@ -321,12 +408,19 @@ uint64_t UserAuthProxy::AuthUser(int32_t userId, const std::vector &cha IAM_LOGE("failed to write descriptor"); return BAD_CONTEXT_ID; } - if (!data.WriteInt32(userId)) { - IAM_LOGE("failed to write userId"); + + if (!WriteAuthParam(data, param)) { + IAM_LOGE("failed to write auth param"); return BAD_CONTEXT_ID; } - if (!WriteAuthParam(data, challenge, authType, authTrustLevel, callback)) { - IAM_LOGE("failed to write auth param"); + + if (!WriteRemoteAuthParam(data, remoteAuthParam)) { + IAM_LOGE("failed to write remote auth param"); + return BAD_CONTEXT_ID; + } + + if (!data.WriteRemoteObject(callback->AsObject())) { + IAM_LOGE("failed to write callback"); return BAD_CONTEXT_ID; } @@ -549,7 +643,7 @@ int32_t UserAuthProxy::GetEnrolledState(int32_t apiVersion, AuthType authType, E int32_t result = GENERAL_ERROR; if (!reply.ReadInt32(result)) { IAM_LOGE("failed to read result"); - return GENERAL_ERROR; + return READ_PARCEL_ERROR; } if (result != SUCCESS) { IAM_LOGE("failed to get enrolled state"); @@ -679,6 +773,41 @@ int32_t UserAuthProxy::SetGlobalConfigParam(const GlobalConfigParam ¶m) } return result; } + +int32_t UserAuthProxy::PrepareRemoteAuth(const std::string &networkId, sptr &callback) +{ + if (callback == nullptr) { + IAM_LOGE("callback is nullptr"); + return GENERAL_ERROR; + } + MessageParcel data; + MessageParcel reply; + + if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) { + IAM_LOGE("failed to write descriptor"); + return GENERAL_ERROR; + } + if (!data.WriteString(networkId)) { + IAM_LOGE("failed to write networkId"); + return GENERAL_ERROR; + } + if (!data.WriteRemoteObject(callback->AsObject())) { + IAM_LOGE("failed to write callback"); + return GENERAL_ERROR; + } + + bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_PREPARE_REMOTE_AUTH, data, reply); + if (!ret) { + IAM_LOGE("failed to send prepare remote auth IPC request"); + return GENERAL_ERROR; + } + int32_t result = GENERAL_ERROR; + if (!reply.ReadInt32(result)) { + IAM_LOGE("failed to read result"); + return READ_PARCEL_ERROR; + } + return result; +} } // namespace UserAuth } // namespace UserIam } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ipc/src/user_auth_stub.cpp b/frameworks/native/ipc/src/user_auth_stub.cpp index ce45003c78c45e7d9d8fecf20dab1d9bc01bb856..f26d71d5c56af23d1835e01ebf8e401526e13936 100644 --- a/frameworks/native/ipc/src/user_auth_stub.cpp +++ b/frameworks/native/ipc/src/user_auth_stub.cpp @@ -78,6 +78,8 @@ int32_t UserAuthStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Messag return UnRegistUserAuthSuccessEventListenerStub(data, reply); case UserAuthInterfaceCode::USER_AUTH_SET_CLOBAL_CONFIG_PARAM: return SetGlobalConfigParamStub(data, reply); + case UserAuthInterfaceCode::USER_AUTH_PREPARE_REMOTE_AUTH: + return PrepareRemoteAuthStub(data, reply); default: return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } @@ -207,21 +209,15 @@ int32_t UserAuthStub::AuthStub(MessageParcel &data, MessageParcel &reply) IAM_LOGI("enter"); ON_SCOPE_EXIT(IAM_LOGI("leave")); - std::vector challenge; - int32_t authType; - uint32_t authTrustLevel; int32_t apiVersion; - - if (!data.ReadUInt8Vector(&challenge)) { - IAM_LOGE("failed to read challenge"); - return READ_PARCEL_ERROR; - } - if (!data.ReadInt32(authType)) { - IAM_LOGE("failed to read authType"); + if (!data.ReadInt32(apiVersion)) { + IAM_LOGE("failed to read apiVersion"); return READ_PARCEL_ERROR; } - if (!data.ReadUint32(authTrustLevel)) { - IAM_LOGE("failed to read authTrustLevel"); + + AuthParamInner authParam; + if (!ReadAuthParam(data, authParam)) { + IAM_LOGE("failed to read auth param"); return READ_PARCEL_ERROR; } @@ -235,13 +231,9 @@ int32_t UserAuthStub::AuthStub(MessageParcel &data, MessageParcel &reply) IAM_LOGE("UserAuthCallbackInterface is nullptr"); return GENERAL_ERROR; } - if (!data.ReadInt32(apiVersion)) { - IAM_LOGE("failed to read apiVersion"); - return READ_PARCEL_ERROR; - } - uint64_t contextId = Auth(apiVersion, challenge, static_cast(authType), - static_cast(authTrustLevel), callback); + uint64_t contextId = Auth(apiVersion, authParam.challenge, authParam.authType, authParam.authTrustLevel, + callback); if (!reply.WriteUint64(contextId)) { IAM_LOGE("failed to write AuthUser result"); return WRITE_PARCEL_ERROR; @@ -254,7 +246,7 @@ int32_t UserAuthStub::AuthWidgetStub(MessageParcel &data, MessageParcel &reply) IAM_LOGI("enter"); ON_SCOPE_EXIT(IAM_LOGI("leave")); - AuthParam authParam; + AuthParamInner authParam; WidgetParam widgetParam; if (!ReadWidgetParam(data, authParam, widgetParam)) { IAM_LOGE("failed to read widget param"); @@ -286,7 +278,7 @@ int32_t UserAuthStub::AuthWidgetStub(MessageParcel &data, MessageParcel &reply) return ResultCode::SUCCESS; } -bool UserAuthStub::ReadWidgetParam(MessageParcel &data, AuthParam &authParam, WidgetParam &widgetParam) +bool UserAuthStub::ReadWidgetParam(MessageParcel &data, AuthParamInner &authParam, WidgetParam &widgetParam) { if (!data.ReadUInt8Vector(&authParam.challenge)) { IAM_LOGE("failed to read challenge"); @@ -298,7 +290,7 @@ bool UserAuthStub::ReadWidgetParam(MessageParcel &data, AuthParam &authParam, Wi return false; } for (auto at : atList) { - authParam.authType.push_back(static_cast(at)); + authParam.authTypes.push_back(static_cast(at)); } uint32_t authTrustLevel; @@ -342,25 +334,15 @@ int32_t UserAuthStub::AuthUserStub(MessageParcel &data, MessageParcel &reply) IAM_LOGI("enter"); ON_SCOPE_EXIT(IAM_LOGI("leave")); - int32_t userId; - std::vector challenge; - int32_t authType; - uint32_t authTrustLevel; - - if (!data.ReadInt32(userId)) { - IAM_LOGE("failed to read userId"); - return READ_PARCEL_ERROR; - } - if (!data.ReadUInt8Vector(&challenge)) { - IAM_LOGE("failed to read challenge"); - return READ_PARCEL_ERROR; - } - if (!data.ReadInt32(authType)) { - IAM_LOGE("failed to read authType"); + AuthParamInner authParam; + if (!ReadAuthParam(data, authParam)) { + IAM_LOGE("failed to read auth param"); return READ_PARCEL_ERROR; } - if (!data.ReadUint32(authTrustLevel)) { - IAM_LOGE("failed to read authTrustLevel"); + + std::optional remoteAuthParam; + if (!ReadRemoteAuthParam(data, remoteAuthParam)) { + IAM_LOGE("failed to read auth param"); return READ_PARCEL_ERROR; } @@ -375,8 +357,7 @@ int32_t UserAuthStub::AuthUserStub(MessageParcel &data, MessageParcel &reply) return GENERAL_ERROR; } - uint64_t contextId = AuthUser(userId, challenge, static_cast(authType), - static_cast(authTrustLevel), callback); + uint64_t contextId = AuthUser(authParam, remoteAuthParam, callback); if (!reply.WriteUint64(contextId)) { IAM_LOGE("failed to write AuthUser result"); return WRITE_PARCEL_ERROR; @@ -631,6 +612,149 @@ int32_t UserAuthStub::SetGlobalConfigParamStub(MessageParcel &data, MessageParce } return SUCCESS; } + +int32_t UserAuthStub::PrepareRemoteAuthStub(MessageParcel &data, MessageParcel &reply) +{ + IAM_LOGI("enter"); + ON_SCOPE_EXIT(IAM_LOGI("leave")); + + std::string networkId = data.ReadString(); + sptr obj = data.ReadRemoteObject(); + if (obj == nullptr) { + IAM_LOGE("failed to read remote object"); + return READ_PARCEL_ERROR; + } + sptr callback = iface_cast(obj); + if (callback == nullptr) { + IAM_LOGE("UserAuthCallbackInterface is nullptr"); + return GENERAL_ERROR; + } + + int32_t result = PrepareRemoteAuth(networkId, callback); + if (!reply.WriteInt32(result)) { + IAM_LOGE("failed to write PrepareRemoteAuth result"); + return WRITE_PARCEL_ERROR; + } + + return SUCCESS; +} + +bool UserAuthStub::ReadAuthParam(MessageParcel &data, AuthParamInner &authParam) +{ + if (!data.ReadInt32(authParam.userId)) { + IAM_LOGE("failed to read userId"); + return false; + } + if (!data.ReadUInt8Vector(&authParam.challenge)) { + IAM_LOGE("failed to read challenge"); + return false; + } + int32_t authTypeInt; + if (!data.ReadInt32(authTypeInt)) { + IAM_LOGE("failed to read authType"); + return false; + } + authParam.authType = static_cast(authTypeInt); + + std::vector authTypeInts; + if (!data.ReadInt32Vector(&authTypeInts)) { + IAM_LOGE("failed to read authTypeInts"); + return false; + } + + for (auto val : authTypeInts) { + authParam.authTypes.push_back(static_cast(val)); + } + + uint32_t authTrustLevelUint; + if (!data.ReadUint32(authTrustLevelUint)) { + IAM_LOGE("failed to read authTrustLevel"); + return false; + } + authParam.authTrustLevel = static_cast(authTrustLevelUint); + + uint32_t authIntent; + if (!data.ReadUint32(authIntent)) { + IAM_LOGE("failed to write authIntent"); + return false; + } + authParam.authIntent = static_cast(authIntent); + + return true; +} + +bool UserAuthStub::ReadRemoteAuthParam(MessageParcel &data, std::optional &remoteAuthParam) +{ + bool hasRemoteAuthParam; + if (!data.ReadBool(hasRemoteAuthParam)) { + IAM_LOGE("failed to read hasRemoteAuthParam"); + return false; + } + + if (!hasRemoteAuthParam) { + remoteAuthParam = std::nullopt; + return true; + } + remoteAuthParam = RemoteAuthParam{}; + + if (!ReadOptionalString(data, remoteAuthParam->verifierNetworkId)) { + IAM_LOGE("failed to read verifierNetworkId"); + return false; + } + + if (!ReadOptionalString(data, remoteAuthParam->collectorNetworkId)) { + IAM_LOGE("failed to read collectorNetworkId"); + return false; + } + + if (!ReadOptionalUint32(data, remoteAuthParam->collectorTokenId)) { + IAM_LOGE("failed to read collectorTokenId"); + return false; + } + + return true; +} + +bool UserAuthStub::ReadOptionalString(MessageParcel &data, std::optional &str) +{ + bool hasStr; + if (!data.ReadBool(hasStr)) { + IAM_LOGE("failed to read hasStr"); + return false; + } + + if (hasStr) { + std::string readStr; + if (!data.ReadString(readStr)) { + IAM_LOGE("failed to read value"); + return false; + } + str = readStr; + } else { + str = std::nullopt; + } + return true; +} +bool UserAuthStub::ReadOptionalUint32(MessageParcel &data, std::optional &val) +{ + bool hasVal; + if (!data.ReadBool(hasVal)) { + IAM_LOGE("failed to read hasVal"); + return false; + } + + if (hasVal) { + uint32_t readValue; + if (!data.ReadUint32(readValue)) { + IAM_LOGE("failed to read data"); + return false; + } + val = readValue; + } else { + val = std::nullopt; + } + return true; +} } // namespace UserAuth } // namespace UserIam } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ipc/src/user_idm_callback_stub.cpp b/frameworks/native/ipc/src/user_idm_callback_stub.cpp index cc596a2e7c9e50ab7155326f719996fbe64ec232..1356c227b5f8dc96f381c021cbececd05e5ddf9c 100644 --- a/frameworks/native/ipc/src/user_idm_callback_stub.cpp +++ b/frameworks/native/ipc/src/user_idm_callback_stub.cpp @@ -16,7 +16,6 @@ #include "user_idm_callback_stub.h" #include "iam_logger.h" -#include "iam_ptr.h" #include "user_idm_client_defines.h" #define LOG_TAG "USER_IDM_SDK" diff --git a/interfaces/inner_api/attributes.h b/interfaces/inner_api/attributes.h index de701ccef26c7adab0331f7f94d95f803091cf45..b9d31a912c906822b1ef6de1b85e7e8119e1206e 100644 --- a/interfaces/inner_api/attributes.h +++ b/interfaces/inner_api/attributes.h @@ -37,7 +37,7 @@ public: * @brief The key to set attribute. */ enum AttributeKey : uint32_t { - /** Root tag. */ + /** Root tag, the value type is std::vector. */ ATTR_ROOT = 100000, /** Result code, the value type is int32_t. */ ATTR_RESULT_CODE = 100001, @@ -59,10 +59,18 @@ public: ATTR_LOCKOUT_DURATION = ATTR_FREEZING_TIME, /** Session ID, the value type is uint64_t. */ ATTR_SESSION_ID = 100014, + /** Caller package name, the value type is string. */ + ATTR_CALLER_NAME = 100015, /** Schedule version, the value type is uint32_t. */ ATTR_SCHEDULE_VERSION = 100016, /** Schedule ID, the value type is uint64_t. */ - ATTR_SCHEDULE_ID = 100020, + ATTR_SCHEDULE_ID = 100017, + /** Locked templates, the value type is std::vector. */ + ATTR_LOCKED_TEMPLATES = 100018, + /** Unlocked templates, the value type is std::vector. */ + ATTR_UNLOCKED_TEMPLATES = 100019, + /** Data, the value type is std::vector. */ + ATTR_DATA = 100020, /** Pin subtype, the value type is int32_t. */ ATTR_PIN_SUB_TYPE = 100021, /** Schedule mode, the value type is int32_t. */ @@ -79,7 +87,7 @@ public: ATTR_RESULT = 100028, /** Capability level, the value type is uint64_t. */ ATTR_CAPABILITY_LEVEL = 100029, - /** Algorithm infomation, the value type is uint64_t. */ + /** Algorithm information, the value type is uint64_t. */ ATTR_ALGORITHM_INFO = 100030, /** Timer stamp, the value type is uint64_t. */ ATTR_TIME_STAMP = 100031, @@ -87,7 +95,7 @@ public: ATTR_ROOT_SECRET = 100032, /** Auth token, the value type is std::vector. */ ATTR_AUTH_TOKEN = 100033, - /** Security user id return when add pin credential, the value type is uint64_t. */ + /** Security user ID return when add pin credential, the value type is uint64_t. */ ATTR_SEC_USER_ID = 100034, /** Enroll progress, the value type is string. */ ATTR_ENROLL_PROGRESS = 100035, @@ -97,7 +105,7 @@ public: ATTR_KEY_LIST = 100037, /** End after first fail, the value type is boolean. */ ATTR_END_AFTER_FIRST_FAIL = 100038, - /** tip info, the value type is int32_t. */ + /** Tip info, the value type is int32_t. */ ATTR_TIP_INFO = 100039, /** Old root secret, the value type is std::vector. */ ATTR_OLD_ROOT_SECRET = 100040, @@ -105,49 +113,80 @@ public: ATTR_OLD_CREDENTIAL_ID = 100041, /** Source role, the value type is int32_t. */ ATTR_SRC_ROLE = 100042, - /** Message seqence num, the value type is int32_t. */ - ATTR_MSG_SEQ_NUM = 100043, + /** User ID, the value type is int32_t. */ + ATTR_USER_ID = 100043, + /** Extra information, the value type is std::vector. */ + ATTR_EXTRA_INFO = 100044, + /** Executor ID, the value type is uint64_t. */ + ATTR_EXECUTOR_INDEX = 100045, + /** Executor sensor hint, the value type is uint32_t. */ + ATTR_EXECUTOR_SENSOR_HINT = 100046, + /** Executor matcher, the value type is uint32_t. */ + ATTR_EXECUTOR_MATCHER = 100047, + /** Access token ID, the value type is uint32_t. */ + ATTR_ACCESS_TOKEN_ID = 100048, + /** Template change reason, the value type is string. */ + ATTR_TEMPLATE_CHANGE_REASON = 100049, + /** Credential digest, the value type is uint16_t. */ + ATTR_CREDENTIAL_DIGEST = 100050, + /** Credential count, the value type is uint16_t. */ + ATTR_CREDENTIAL_COUNT = 100051, + /** Message sequence number, the value type is uint32_t. */ + ATTR_MSG_SEQ_NUM = 100052, /** Reply message, the value type is bool. */ - ATTR_MSG_ACK = 100044, - /** Device udid, the value type is string. */ - ATTR_MSG_SRC_UDID = 100045, - /** Source of messsage, the value type is string. */ - ATTR_MSG_SRC_END_POINT = 100046, + ATTR_MSG_ACK = 100053, + /** Message source UDID, the value type is string. */ + ATTR_MSG_SRC_UDID = 100054, + /** Source of message, the value type is string. */ + ATTR_MSG_SRC_END_POINT = 100055, /** Destination of message, the value type is string. */ - ATTR_MSG_DEST_END_POINT = 100047, - /** Connection count, the value type is string. */ - ATTR_CONNECTION_NAME = 100048, + ATTR_MSG_DEST_END_POINT = 100056, + /** Connection name, the value type is string. */ + ATTR_CONNECTION_NAME = 100057, /** Message version, the value type is uint32_t. */ - ATTR_MSG_VERSION = 100049, + ATTR_MSG_VERSION = 100058, + /** Message type, the value type is int32_t. */ + ATTR_MSG_TYPE = 100059, + /** Message reply sequence number, the value type is uint32_t. */ + ATTR_MSG_REPLY_SEQ_NUM = 100060, + /** Context ID, the value type is uint64_t. */ + ATTR_CONTEXT_ID = 100061, + /** Collector info, the value type is std::vector. */ + ATTR_COLLECTOR_INFO = 100062, + /** Executor role, the value type is int32_t. */ + ATTR_EXECUTOR_ROLE = 100063, + /** Schedule data, the value type is std::vector. */ + ATTR_SCHEDULE_DATA = 100064, + /** Signed authentication result, the value type is std::vector. */ + ATTR_SIGNED_AUTH_RESULT = 100065, + /** Destination role, the value type is int32_t. */ + ATTR_DEST_ROLE = 100066, + /** Local UDID, the value type is string. */ + ATTR_LOCAL_UDID = 100067, + /** Peer UDID, the value type is string. */ + ATTR_PEER_UDID = 100068, + /** Public key, the value type is std::vector. */ + ATTR_PUBLIC_KEY = 100069, + /** Executor info list, the value type is std::vector. */ + ATTR_EXECUTOR_REGISTER_INFO_LIST = 100070, + /** Executor secure level, the value type is int32_t. */ + ATTR_ESL = 100071, + /** Challenge, the value type is std::vector. */ + ATTR_CHALLENGE = 100072, + /** Remote executor info, the value type is std::vector. */ + ATTR_REMOTE_EXECUTOR_INFO = 100073, + /** Authentication types, the value type is std::vector. */ + ATTR_AUTH_TYPES = 100074, + /** Authentication trust level, the value type is int32_t. */ + ATTR_AUTH_TRUST_LEVEL = 100075, + /** Device UDID, the value type is string. */ + ATTR_DEVICE_UDID = 100080, /** Collector network id. */ - ATTR_COLLECTOR_NETWORK_ID = 100050, - /** Verifier message, the value type is string. */ - ATTR_VERIFIER_MESSAGE = 100051, - /** Collector message, the value type is string. */ - ATTR_COLLECTOR_MESSAGE = 100052, - /** - * Private attrs. - * User ID, the value type is int32_t. - */ - ATTR_USER_ID = 300000, - /** Extra infomation, the value type is std::vector. */ - ATTR_EXTRA_INFO, - /** Executor ID, the value type is uint64_t. */ - ATTR_EXECUTOR_INDEX, - /** ExecutorSensorHint, the value type is uint32_t. */ - ATTR_EXECUTOR_SENSOR_HINT, - /** ExecutorMatcher, the value type is uint32_t. */ - ATTR_EXECUTOR_MATCHER, - /** Access token ID, the value type is uint32_t. */ - ATTR_ACCESS_TOKEN_ID, - /** Template change reason, the value type is string */ - ATTR_TEMPLATE_CHANGE_REASON, - /** Credential digest, the value type is uint64_t. */ - ATTR_CREDENTIAL_DIGEST, - /** Credential count, the value type is uint16_t. */ - ATTR_CREDENTIAL_COUNT, + ATTR_COLLECTOR_NETWORK_ID = 100081, + /** Collector token id. */ + ATTR_COLLECTOR_TOKEN_ID = 100082, /** Pin expired info, the value type is int64_t and it's max value is 2^50. */ - ATTR_PIN_EXPIRED_INFO, + ATTR_PIN_EXPIRED_INFO = 100083, }; /** @@ -279,6 +318,7 @@ public: * @return Return success or not(true:success; false:failed). */ bool SetAttributesValue(AttributeKey key, const Attributes &value); + bool SetAttributesArrayValue(AttributeKey key, const std::vector &array); /** * @brief Set vector value. @@ -298,6 +338,15 @@ public: */ bool SetUint32ArrayValue(AttributeKey key, const std::vector &value); + /** + * @brief Set vector value. + * + * @param key The attribute key. + * @param value The vector value. + * @return Return success or not(true:success; false:failed). + */ + bool SetInt32ArrayValue(AttributeKey key, const std::vector &value); + /** * @brief Set vector value. * @@ -406,6 +455,15 @@ public: */ bool GetUint32ArrayValue(AttributeKey key, std::vector &value) const; + /** + * @brief Get vector value. + * + * @param key The attribute key. + * @param value Return vector value corresponding to key. + * @return Return success or not(true:success; false:failed). + */ + bool GetInt32ArrayValue(AttributeKey key, std::vector &value) const; + /** * @brief Get vector value. * @@ -433,6 +491,8 @@ public: */ bool GetAttributesValue(AttributeKey key, Attributes &value) const; + bool GetAttributesArrayValue(AttributeKey key, std::vector &array) const; + /** * @brief Serialize the Attribute object. * diff --git a/interfaces/inner_api/co_auth_client.h b/interfaces/inner_api/co_auth_client.h index 35640560194d88fb9e3692d219449fafcef4ad6d..1f23542ce55f891202c044191f871227a9b1b214 100644 --- a/interfaces/inner_api/co_auth_client.h +++ b/interfaces/inner_api/co_auth_client.h @@ -57,7 +57,7 @@ public: * * @param info Information about executor which need to unregister from coAuth. */ - virtual void Unregister(const ExecutorInfo &info) = 0; + virtual void Unregister(uint64_t executorIndex) = 0; }; } // namespace UserAuth } // namespace UserIam diff --git a/interfaces/inner_api/co_auth_client_callback.h b/interfaces/inner_api/co_auth_client_callback.h index bbcdb0cfd24d17f62653e0115fc45c07a12c4510..b3935cb582ba5c874e2433deed5a4846e9d978c2 100644 --- a/interfaces/inner_api/co_auth_client_callback.h +++ b/interfaces/inner_api/co_auth_client_callback.h @@ -39,8 +39,8 @@ public: * @param publicKey Public key of the framework. * @param templateIds Matched templateIds based on authType and executor info. */ - virtual void OnMessengerReady(const std::shared_ptr &messenger, - const std::vector &publicKey, const std::vector &templateIds) = 0; + virtual void OnMessengerReady(uint64_t executorIndex, const std::shared_ptr &messenger, + const std::vector &publicKey, const std::vector &templateIdList) = 0; /** * @brief Called by coAuth resource pool to tell the executor to begin. diff --git a/interfaces/inner_api/co_auth_client_defines.h b/interfaces/inner_api/co_auth_client_defines.h index 2ad3d5d48f5f6d20890fffccc0740dc7f0d7cff0..76b9252b2ab1303fa5aabb6aa984d6e92f06d607 100644 --- a/interfaces/inner_api/co_auth_client_defines.h +++ b/interfaces/inner_api/co_auth_client_defines.h @@ -50,6 +50,10 @@ struct ExecutorInfo { uint32_t maxTemplateAcl {0}; /** Used to verify the result issued by the authenticator. */ std::vector publicKey {}; + /**< Device udid. */ + std::string deviceUdid; + /**< signed remote executor info. */ + std::vector signedRemoteExecutorInfo; }; class AuthMessage { diff --git a/interfaces/inner_api/iam_common_defines.h b/interfaces/inner_api/iam_common_defines.h index d1319917d9eb6eb15d48889babffd000723a5f8d..4ee2ce001485d560e6cca967cdfcf6a71c1423b1 100644 --- a/interfaces/inner_api/iam_common_defines.h +++ b/interfaces/inner_api/iam_common_defines.h @@ -200,6 +200,18 @@ enum ResultCode : int32_t { /** The result is fail, because something wrong from vendor. */ VENDOR_ERROR_CODE_BEGIN = 10000, }; + +/** + * @brief The auth intent. + */ +enum AuthIntent : int { + /**< The auth intent is default. */ + DEFAULT = 0, + /**< The auth intent is unlock. */ + UNLOCK = 1, + /**< The auth intent is init. */ + INIT = 2, +}; } // namespace UserAuth } // namespace UserIam } // namespace OHOS diff --git a/interfaces/inner_api/iam_executor/iam_executor_framework_types.h b/interfaces/inner_api/iam_executor/iam_executor_framework_types.h index 0513f221cf36467a34170c10ee5ddb00c2e3745c..fcf897215987e69ec0f38a8954cf988a5c0b2318 100644 --- a/interfaces/inner_api/iam_executor/iam_executor_framework_types.h +++ b/interfaces/inner_api/iam_executor/iam_executor_framework_types.h @@ -71,6 +71,8 @@ struct AuthenticateParam { struct CollectParam { /** Token id. */ uint32_t tokenId; + /** Collector Token id. */ + uint32_t collectorTokenId; /** Extra info. */ std::vector extraInfo; }; diff --git a/interfaces/inner_api/user_auth_client.h b/interfaces/inner_api/user_auth_client.h index 970383416c4fa3f2c4f6676f6dc58e94de905f49..e8297e1767341d08be12950479ad63fd0324a2c0 100644 --- a/interfaces/inner_api/user_auth_client.h +++ b/interfaces/inner_api/user_auth_client.h @@ -70,15 +70,12 @@ public: /** * @brief Begin user authentication according to ATL and authType. * - * @param userId System userId, generated by account subsystem. - * @param challenge auth challenge which can prevent replay attacks. - * @param authType Auth type supported by executor. - * @param atl Auth trust level. + * @param authParam, authentication paramater. * @param callback Callback of user authentication result. * @return Return context ID of authentication. */ - virtual uint64_t BeginAuthentication(int32_t userId, const std::vector &challenge, AuthType authType, - AuthTrustLevel atl, const std::shared_ptr &callback) = 0; + virtual uint64_t BeginAuthentication(const AuthParam &authParam, + const std::shared_ptr &callback) = 0; /** * @brief Cancel user authentication. @@ -133,6 +130,15 @@ public: * @return Return set result(0:success; other:failed). */ virtual int32_t SetGlobalConfigParam(const GlobalConfigParam ¶m) = 0; + /** + * @brief Prepare remote authentication. + * @param networkId Network id of remote device. + * @param callback Callback of prepare remote authentication result. + * + * @return Return prepare remote authentication result(0:success; other:failed). + */ + virtual int32_t PrepareRemoteAuth(const std::string &networkId, + const std::shared_ptr &callback) = 0; }; } // namespace UserAuth } // namespace UserIam diff --git a/interfaces/inner_api/user_auth_client_callback.h b/interfaces/inner_api/user_auth_client_callback.h index 6480edbcb050083044152d3842d5883a21b41034..36dcb5c32fbe2a7730a43a33b20972e3681e647b 100644 --- a/interfaces/inner_api/user_auth_client_callback.h +++ b/interfaces/inner_api/user_auth_client_callback.h @@ -107,6 +107,16 @@ public: std::string &callerName) = 0; DECLARE_INTERFACE_DESCRIPTOR(u"ohos.UserIam.UserAuth.EventListenerCallback"); }; + +class PrepareRemoteAuthCallback { +public: + /** + * @brief The callback return prepare remote auth result. + * + * @param result The result success or error code{@link ResultCode}. + */ + virtual void OnResult(int32_t result) = 0; +}; } // namespace UserAuth } // namespace UserIam } // namespace OHOS diff --git a/interfaces/inner_api/user_auth_client_defines.h b/interfaces/inner_api/user_auth_client_defines.h index ef76bf9586a8b5c3b193c737d6f310cca4bd22e0..48d1805c291dac0f584bd8f347471e9373eaded0 100644 --- a/interfaces/inner_api/user_auth_client_defines.h +++ b/interfaces/inner_api/user_auth_client_defines.h @@ -24,12 +24,44 @@ #ifndef USER_AUTH_CLIENT_DEFINES_H #define USER_AUTH_CLIENT_DEFINES_H +#include + #include "attributes.h" #include "iam_common_defines.h" namespace OHOS { namespace UserIam { namespace UserAuth { +/** + * @brief Remote auth parameter. + */ +struct RemoteAuthParam { + /** verifier network id */ + std::optional verifierNetworkId; + /** collector network id */ + std::optional collectorNetworkId; + /** collector token id */ + std::optional collectorTokenId; +}; + +/** + * @brief Auth parameter. + */ +struct AuthParam { + /** user id */ + int32_t userId; + /** challenge value */ + std::vector challenge; + /** Credential type for authentication. */ + AuthType authType; + /** Trust level of authentication result. */ + AuthTrustLevel authTrustLevel; + /** Auth intent. */ + AuthIntent authIntent; + /** Remote auth parameter. */ + std::optional remoteAuthParam; +}; + /** * @brief Executor property needed to get. */ diff --git a/sa_profile/useriam.cfg b/sa_profile/useriam.cfg index f9addb4a168022f2714015e3b45a7164797ef6da..66be0a3c5d4cf269a80b5be9abb05c782d887e4c 100644 --- a/sa_profile/useriam.cfg +++ b/sa_profile/useriam.cfg @@ -16,7 +16,8 @@ "ohos.permission.CAMERA", "ohos.permission.GET_SUPER_PRIVACY", "ohos.permission.DISTRIBUTED_DATASYNC", - "ohos.permission.ACCESS_SERVICE_DM" + "ohos.permission.ACCESS_SERVICE_DM", + "ohos.permission.sec.ACCESS_UDID" ], "permission_acls" : [ "ohos.permission.ACCESS_AUTH_RESPOOL", diff --git a/services/context/BUILD.gn b/services/context/BUILD.gn index 630bdb953b07471e11069056f6c6bf1d6ad2f80c..c6d11180d5f7d7aeee765685c246d7a78db33e2c 100644 --- a/services/context/BUILD.gn +++ b/services/context/BUILD.gn @@ -45,6 +45,9 @@ ohos_source_set("userauth_service_context") { "src/context_pool_impl.cpp", "src/enroll_context.cpp", "src/identify_context.cpp", + "src/remote_auth_context.cpp", + "src/remote_auth_invoker_context.cpp", + "src/remote_iam_callback.cpp", "src/simple_auth_context.cpp", "src/trace.cpp", "src/ui_extension_ability_connection.cpp", @@ -69,6 +72,7 @@ ohos_source_set("userauth_service_context") { "ability_runtime:app_manager", "ability_runtime:extension_manager", "c_utils:utils", + "drivers_interface_user_auth:libuser_auth_proxy_2.0", "hilog:libhilog", "hitrace:hitrace_meter", "init:libbegetutil", @@ -83,6 +87,7 @@ ohos_source_set("userauth_service_context") { "../../common:iam_log_config", "../../common:iam_utils_config", "../../frameworks/native/ipc:userauth_client_ipc_config", + "../remote_connect:userauth_service_remote_connect_config", ] subsystem_name = "useriam" diff --git a/services/context/inc/context.h b/services/context/inc/context.h index d207105b7c657f2c3df595b172321de2e64e314f..805c5715871d84012ef40a13590a3b459d82f005 100644 --- a/services/context/inc/context.h +++ b/services/context/inc/context.h @@ -42,6 +42,8 @@ enum ContextType { CONTEXT_ENROLL, CONTEXT_IDENTIFY, WIDGET_AUTH_CONTEXT, + REMOTE_AUTH_CONTEXT, + REMOTE_AUTH_INVOKER_CONTEXT }; class Context { diff --git a/services/context/inc/context_factory.h b/services/context/inc/context_factory.h index 073662078a98174b907dc46efc5de533283217c9..5599b269c41755f2a14df0873550b6e9b5c039c9 100644 --- a/services/context/inc/context_factory.h +++ b/services/context/inc/context_factory.h @@ -27,6 +27,8 @@ #include "context.h" #include "context_callback.h" #include "identification_impl.h" +#include "remote_auth_context.h" +#include "remote_auth_invoker_context.h" namespace OHOS { namespace UserIam { @@ -55,6 +57,10 @@ public: }; static std::shared_ptr CreateSimpleAuthContext(const Authentication::AuthenticationPara ¶, const std::shared_ptr &callback); + static std::shared_ptr CreateRemoteAuthContext(const Authentication::AuthenticationPara ¶, + RemoteAuthContextParam &remoteAuthContextParam, const std::shared_ptr &callback); + static std::shared_ptr CreateRemoteAuthInvokerContext(AuthParamInner authParam, + RemoteAuthInvokerContextParam param, std::shared_ptr callback); static std::shared_ptr CreateIdentifyContext(const Identification::IdentificationPara ¶, const std::shared_ptr &callback); static std::shared_ptr CreateEnrollContext(const Enrollment::EnrollmentPara ¶, diff --git a/services/context/inc/context_pool.h b/services/context/inc/context_pool.h index a5a27936e8eca74e5b22f60adb45d3e0ca43b76c..089a095f880441ccbc635fafc8626e6ad2dfab66 100644 --- a/services/context/inc/context_pool.h +++ b/services/context/inc/context_pool.h @@ -37,6 +37,8 @@ public: virtual void CancelAll() const = 0; virtual std::weak_ptr Select(uint64_t contextId) const = 0; virtual std::vector> Select(ContextType contextType) const = 0; + virtual void InsertRemoteScheduleNode(std::shared_ptr scheduleNode) = 0; + virtual void RemoveRemoteScheduleNode(std::shared_ptr scheduleNode) = 0; virtual std::shared_ptr SelectScheduleNodeByScheduleId(uint64_t scheduleId) = 0; virtual bool RegisterContextPoolListener(const std::shared_ptr &listener) = 0; virtual bool DeregisterContextPoolListener(const std::shared_ptr &listener) = 0; diff --git a/services/context/inc/remote_auth_context.h b/services/context/inc/remote_auth_context.h new file mode 100644 index 0000000000000000000000000000000000000000..3a4ff423eee61b2c8555817d295ae21fd631fe26 --- /dev/null +++ b/services/context/inc/remote_auth_context.h @@ -0,0 +1,74 @@ +/* + * 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 REMOTE_AUTH_CONTEXT_H +#define REMOTE_AUTH_CONTEXT_H + +#include +#include +#include + +#include "authentication_impl.h" +#include "remote_executor_proxy.h" +#include "simple_auth_context.h" + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +struct RemoteAuthContextParam { + AuthType authType; + std::string connectionName; + std::string collectorNetworkId; + std::vector executorInfoMsg; +}; + +class RemoteAuthContext : public SimpleAuthContext { +public: + RemoteAuthContext(uint64_t contextId, std::shared_ptr auth, RemoteAuthContextParam ¶m, + std::shared_ptr callback); + ~RemoteAuthContext() override; + ContextType GetContextType() const override; + + void SetExecutorInfoMsg(std::vector msg); + + void OnMessage(const std::string &connectionName, const std::string &srcEndPoint, + const std::shared_ptr &request, std::shared_ptr &reply); + void OnConnectStatus(const std::string &connectionName, ConnectStatus connectStatus); + + void OnTimeOut(); + +protected: + bool OnStart() override; + +private: + bool StartAuth(); + void StartAuthDelayed(); + bool SetupConnection(); + bool SendQueryExecutorInfoMsg(); + + std::recursive_mutex mutex_; + AuthType authType_; + std::string connectionName_; + std::string collectorNetworkId_; + std::vector executorInfoMsg_; + + std::string endPointName_; + std::shared_ptr remoteExecutorProxy_ = nullptr; + std::optional cancelTimerId_; +}; +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS +#endif // REMOTE_AUTH_CONTEXT_H \ No newline at end of file diff --git a/services/context/inc/remote_auth_invoker_context.h b/services/context/inc/remote_auth_invoker_context.h new file mode 100644 index 0000000000000000000000000000000000000000..d2e967ea690eff34a239081acba78a744c0da2c6 --- /dev/null +++ b/services/context/inc/remote_auth_invoker_context.h @@ -0,0 +1,84 @@ +/* + * 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 REMOTE_AUTH_INVOKER_CONTEXT_H +#define REMOTE_AUTH_INVOKER_CONTEXT_H + +#include +#include +#include +#include + +#include "attributes.h" +#include "authentication_impl.h" +#include "base_context.h" +#include "remote_auth_context.h" + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +struct RemoteAuthInvokerContextParam { + std::string connectionName; + std::string verifierNetworkId; + std::string collectorNetworkId; + uint32_t tokenId; + uint32_t collectorTokenId; +}; + +class RemoteAuthInvokerContext : public BaseContext { +public: + RemoteAuthInvokerContext(uint64_t contextId, AuthParamInner authParam, RemoteAuthInvokerContextParam param, + std::shared_ptr callback); + ~RemoteAuthInvokerContext() override; + ContextType GetContextType() const override; + uint32_t GetTokenId() const override; + + void OnMessage(const std::string &connectionName, const std::string &srcEndPoint, + const std::shared_ptr &request, std::shared_ptr &reply); + void OnConnectStatus(const std::string &connectionName, ConnectStatus connectStatus); + + void SetVerifierContextId(uint64_t contextId); + void OnTimeOut(); + +protected: + bool OnStart() override; + void OnResult(int32_t resultCode, const std::shared_ptr &scheduleResultAttr) override; + bool OnStop() override; + +private: + int32_t ProcAuthTipMsg(Attributes &message); + int32_t ProcAuthResultMsg(Attributes &message); + + bool SendRequest(); + + AuthParamInner authParam_; + std::string connectionName_; + std::string verifierNetworkId_; + std::string collectorNetworkId_; + std::string verifierUdid_; + uint32_t tokenId_; + uint32_t collectorTokenId_; + std::shared_ptr callback_; + + std::recursive_mutex mutex_; + std::shared_ptr request_ = nullptr; + std::string endPointName_; + std::optional verifierContextId_; + std::optional cancelTimerId_; +}; +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS +#endif // REMOTE_AUTH_INVOKER_CONTEXT_H \ No newline at end of file diff --git a/services/context/inc/remote_iam_callback.h b/services/context/inc/remote_iam_callback.h new file mode 100644 index 0000000000000000000000000000000000000000..9b6aec03b4e5329276b49a76e5ed463ef1f85eda --- /dev/null +++ b/services/context/inc/remote_iam_callback.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022 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 REMOTE_IAM_CALLBACK_H +#define REMOTE_IAM_CALLBACK_H + +#include "attributes.h" +#include "iam_callback_interface.h" + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +class RemoteIamCallback : public IamCallbackInterface { +public: + RemoteIamCallback(std::string &connectionName); + ~RemoteIamCallback() override; + + bool Init(); + + void OnResult(int32_t result, const Attributes &extraInfo) override; + void OnAcquireInfo(int32_t module, int32_t acquireInfo, const Attributes &extraInfo) override; + + sptr AsObject() override; + +private: + std::string localEndPointName_; + std::string connectionName_; +}; +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS +#endif // REMOTE_IAM_CALLBACK_H \ No newline at end of file diff --git a/services/context/inc/simple_auth_context.h b/services/context/inc/simple_auth_context.h index c980a5f86562439f4b37714ad43bd157e19d644b..356773272b11a57c6da6280e0a985b9a4177ee20 100644 --- a/services/context/inc/simple_auth_context.h +++ b/services/context/inc/simple_auth_context.h @@ -29,6 +29,8 @@ class SimpleAuthContext : public BaseContext { public: SimpleAuthContext(uint64_t contextId, std::shared_ptr auth, std::shared_ptr callback); + SimpleAuthContext(const std::string &type, uint64_t contextId, std::shared_ptr auth, + std::shared_ptr callback); ~SimpleAuthContext() override = default; ContextType GetContextType() const override; uint32_t GetTokenId() const override; @@ -38,6 +40,8 @@ protected: void OnResult(int32_t resultCode, const std::shared_ptr &scheduleResultAttr) override; bool OnStop() override; + std::shared_ptr auth_ = nullptr; + private: bool UpdateScheduleResult(const std::shared_ptr &scheduleResultAttr, Authentication::AuthResultInfo &resultInfo); @@ -45,7 +49,6 @@ private: void InvokeResultCallback(const Authentication::AuthResultInfo &resultInfo) const; bool NeedSetFreezingTimeAndRemainTimes(int32_t result) const; ResultCode SetFreezingTimeAndRemainTimes(int32_t &freezingTime, int32_t &remainTimes); - std::shared_ptr auth_ = nullptr; }; } // namespace UserAuth } // namespace UserIam diff --git a/services/context/src/context_factory.cpp b/services/context/src/context_factory.cpp index 07f9c201cb3f8a4b3e223b5aa72070f9ea9f2b3d..3506780ebd932f68649a5ca1397ff53e6d0dcd13 100644 --- a/services/context/src/context_factory.cpp +++ b/services/context/src/context_factory.cpp @@ -23,6 +23,7 @@ #include "identify_context.h" #include "simple_auth_context.h" #include "widget_context.h" +#include "remote_msg_util.h" #define LOG_TAG "USER_AUTH_SA" @@ -80,6 +81,38 @@ std::shared_ptr ContextFactory::CreateWidgetContext(const AuthWidgetCon uint64_t newContextId = ContextPool::GetNewContextId(); return Common::MakeShared(newContextId, para, callback); } + +std::shared_ptr ContextFactory::CreateRemoteAuthContext(const Authentication::AuthenticationPara ¶, + RemoteAuthContextParam &remoteAuthContextParam, 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); + IF_FALSE_LOGE_AND_RETURN_VAL(auth != nullptr, nullptr); + auth->SetChallenge(para.challenge); + auth->SetAccessTokenId(para.tokenId); + + if (remoteAuthContextParam.connectionName == "") { + bool getConnectionNameRet = RemoteMsgUtil::GetConnectionName(newContextId, + remoteAuthContextParam.connectionName); + IF_FALSE_LOGE_AND_RETURN_VAL(getConnectionNameRet, nullptr); + } + + return Common::MakeShared(newContextId, auth, remoteAuthContextParam, callback); +} + +std::shared_ptr ContextFactory::CreateRemoteAuthInvokerContext(AuthParamInner authParam, + RemoteAuthInvokerContextParam param, std::shared_ptr callback) +{ + IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, nullptr); + + uint64_t newContextId = ContextPool::GetNewContextId(); + bool getConnectionNameRet = RemoteMsgUtil::GetConnectionName(newContextId, param.connectionName); + IF_FALSE_LOGE_AND_RETURN_VAL(getConnectionNameRet, nullptr); + + return Common::MakeShared(newContextId, authParam, param, callback); +} } // namespace UserAuth } // namespace UserIam } // namespace OHOS diff --git a/services/context/src/context_pool_impl.cpp b/services/context/src/context_pool_impl.cpp index 25b4a9b0cd5a5543b9be6052f1534215ef01c8fb..e6a98e01f566be029bc0ed4c2ac291b7f1e2ebc0 100644 --- a/services/context/src/context_pool_impl.cpp +++ b/services/context/src/context_pool_impl.cpp @@ -24,12 +24,16 @@ #include "iam_logger.h" #include "iam_para2str.h" +#include "iam_check.h" #define LOG_TAG "USER_AUTH_SA" namespace OHOS { namespace UserIam { namespace UserAuth { +namespace { +const uint32_t MAX_CONTEXT_NUM = 100; +} class ContextPoolImpl final : public ContextPool, public Singleton { public: bool Insert(const std::shared_ptr &context) override; @@ -37,6 +41,8 @@ public: void CancelAll() const override; std::weak_ptr Select(uint64_t contextId) const override; std::vector> Select(ContextType contextType) const override; + void InsertRemoteScheduleNode(std::shared_ptr scheduleNode) override; + void RemoveRemoteScheduleNode(std::shared_ptr scheduleNode) override; std::shared_ptr SelectScheduleNodeByScheduleId(uint64_t scheduleId) override; bool RegisterContextPoolListener(const std::shared_ptr &listener) override; bool DeregisterContextPoolListener(const std::shared_ptr &listener) override; @@ -45,6 +51,7 @@ private: mutable std::recursive_mutex poolMutex_; std::unordered_map> contextMap_; std::set> listenerSet_; + std::map> remoteScheduleNodeMap_; }; bool ContextPoolImpl::Insert(const std::shared_ptr &context) @@ -54,6 +61,10 @@ bool ContextPoolImpl::Insert(const std::shared_ptr &context) return false; } std::lock_guard lock(poolMutex_); + if (contextMap_.size() >= MAX_CONTEXT_NUM) { + IAM_LOGE("context pool is full"); + return false; + } uint64_t contextId = context->GetContextId(); auto result = contextMap_.try_emplace(contextId, context); if (!result.second) { @@ -126,6 +137,30 @@ std::vector> ContextPoolImpl::Select(ContextType contextT return result; } +void ContextPoolImpl::InsertRemoteScheduleNode(std::shared_ptr scheduleNode) +{ + std::lock_guard lock(poolMutex_); + IF_FALSE_LOGE_AND_RETURN(scheduleNode != nullptr); + + if (remoteScheduleNodeMap_.find(scheduleNode->GetScheduleId()) != remoteScheduleNodeMap_.end()) { + IAM_LOGE("scheduleNode already exists"); + return; + } + + remoteScheduleNodeMap_[scheduleNode->GetScheduleId()] = scheduleNode; +} + +void ContextPoolImpl::RemoveRemoteScheduleNode(std::shared_ptr scheduleNode) +{ + std::lock_guard lock(poolMutex_); + IF_FALSE_LOGE_AND_RETURN(scheduleNode != nullptr); + + auto it = remoteScheduleNodeMap_.find(scheduleNode->GetScheduleId()); + if (it != remoteScheduleNodeMap_.end()) { + remoteScheduleNodeMap_.erase(it); + } +} + std::shared_ptr ContextPoolImpl::SelectScheduleNodeByScheduleId(uint64_t scheduleId) { std::lock_guard lock(poolMutex_); @@ -138,6 +173,12 @@ std::shared_ptr ContextPoolImpl::SelectScheduleNodeByScheduleId(ui return node; } } + + auto it = remoteScheduleNodeMap_.find(scheduleId); + if (it != remoteScheduleNodeMap_.end()) { + return it->second; + } + IAM_LOGE("not found"); return nullptr; } diff --git a/services/context/src/enroll_context.cpp b/services/context/src/enroll_context.cpp index 0e2c5841cf7ffe1a4b2941d0eb1219c29f698961..58a71b5ed572647ade66a75f1ef52ae2f893fa35 100644 --- a/services/context/src/enroll_context.cpp +++ b/services/context/src/enroll_context.cpp @@ -18,7 +18,6 @@ #include "iam_check.h" #include "iam_logger.h" #include "iam_para2str.h" -#include "iam_ptr.h" #include "resource_node_utils.h" #include "schedule_node.h" #include "schedule_node_callback.h" diff --git a/services/context/src/identify_context.cpp b/services/context/src/identify_context.cpp index 1990c4a552a7b9bf70366fcb56118dad91e62c27..09703be3a35bd76be3a82d30943f6beb35faae44 100644 --- a/services/context/src/identify_context.cpp +++ b/services/context/src/identify_context.cpp @@ -16,7 +16,6 @@ #include "iam_check.h" #include "iam_logger.h" -#include "iam_ptr.h" #include "schedule_node.h" #include "schedule_node_callback.h" diff --git a/services/context/src/remote_auth_context.cpp b/services/context/src/remote_auth_context.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f1029e4984f8ff67f22bb99375313f03f80006ad --- /dev/null +++ b/services/context/src/remote_auth_context.cpp @@ -0,0 +1,290 @@ +/* + * 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 "remote_auth_context.h" + +#include "iam_check.h" +#include "iam_logger.h" +#include "iam_para2str.h" +#include "iam_ptr.h" + +#include "device_manager_util.h" +#include "relative_timer.h" +#include "remote_msg_util.h" +#include "resource_node_utils.h" +#include "thread_handler.h" + +#define LOG_TAG "USER_AUTH_SA" + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +namespace { +constexpr uint32_t TIME_OUT_MS = 3 * 60 * 1000; // 3min +} +class RemoteAuthContextMessageCallback : public ConnectionListener, public NoCopyable { +public: + explicit RemoteAuthContextMessageCallback(std::weak_ptr callbackWeakBase, RemoteAuthContext *callback) + : callbackWeakBase_(callbackWeakBase), + callback_(callback), + threadHandler_(ThreadHandler::GetSingleThreadInstance()) + { + } + + ~RemoteAuthContextMessageCallback() = default; + + void OnMessage(const std::string &connectionName, const std::string &srcEndPoint, + const std::shared_ptr &request, std::shared_ptr &reply) override + { + IF_FALSE_LOGE_AND_RETURN(request != nullptr); + IF_FALSE_LOGE_AND_RETURN(reply != nullptr); + + IAM_LOGI("connectionName: %{public}s, srcEndPoint: %{public}s", + RemoteMsgUtil::GetConnectionNameStr(connectionName).c_str(), srcEndPoint.c_str()); + } + + void OnConnectStatus(const std::string &connectionName, ConnectStatus connectStatus) override + { + IAM_LOGI("connectionName: %{public}s, connectStatus %{public}d", + RemoteMsgUtil::GetConnectionNameStr(connectionName).c_str(), connectStatus); + + IF_FALSE_LOGE_AND_RETURN(threadHandler_ != nullptr); + IF_FALSE_LOGE_AND_RETURN(connectStatus == ConnectStatus::DISCONNECT); + + threadHandler_->PostTask( + [connectionName, connectStatus, callbackWeakBase = callbackWeakBase_, callback = callback_, this]() { + IAM_LOGI("OnConnectStatus process begin"); + auto callbackSharedBase = callbackWeakBase.lock(); + IF_FALSE_LOGE_AND_RETURN(callbackSharedBase != nullptr); + + callback_->OnConnectStatus(connectionName, connectStatus); + IAM_LOGI("OnConnectStatus process success"); + }); + + IAM_LOGI("task posted"); + } + +private: + std::weak_ptr callbackWeakBase_; + RemoteAuthContext *callback_ = nullptr; + std::shared_ptr threadHandler_ = nullptr; +}; + +RemoteAuthContext::RemoteAuthContext(uint64_t contextId, std::shared_ptr auth, + RemoteAuthContextParam ¶m, std::shared_ptr callback) + : SimpleAuthContext("RemoteAuthContext", contextId, auth, callback), + authType_(param.authType), + connectionName_(param.connectionName), + collectorNetworkId_(param.collectorNetworkId), + executorInfoMsg_(param.executorInfoMsg) +{ + endPointName_ = RemoteMsgUtil::GetRemoteAuthContextEndPointName(); +} + +RemoteAuthContext::~RemoteAuthContext() +{ + std::lock_guard lock(mutex_); + if (cancelTimerId_.has_value()) { + RelativeTimer::GetInstance().Unregister(cancelTimerId_.value()); + } + RemoteConnectionManager::GetInstance().UnregisterConnectionListener(connectionName_, endPointName_); + RemoteConnectionManager::GetInstance().CloseConnection(connectionName_); +} + +ContextType RemoteAuthContext::GetContextType() const +{ + return REMOTE_AUTH_CONTEXT; +} + +void RemoteAuthContext::SetExecutorInfoMsg(std::vector msg) +{ + std::lock_guard lock(mutex_); + + executorInfoMsg_ = msg; + IAM_LOGI("executorInfoMsg_ size is %{public}zu", executorInfoMsg_.size()); +} + +bool RemoteAuthContext::OnStart() +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + cancelTimerId_ = RelativeTimer::GetInstance().Register( + [weak_ptr = weak_from_this(), this]() { + auto shared_ptr = weak_ptr.lock(); + IF_FALSE_LOGE_AND_RETURN(shared_ptr != nullptr); + OnTimeOut(); + }, + TIME_OUT_MS); + + if (executorInfoMsg_.size() == 0) { + IAM_LOGI("SetupConnection"); + return SetupConnection(); + } + + IAM_LOGI("StartAuth"); + return StartAuth(); +} + +bool RemoteAuthContext::StartAuth() +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + IF_FALSE_LOGE_AND_RETURN_VAL(executorInfoMsg_.size() > 0, false); + + std::vector executorInfos; + bool decodeRet = RemoteMsgUtil::DecodeQueryExecutorInfoReply(Attributes(executorInfoMsg_), executorInfos); + IF_FALSE_LOGE_AND_RETURN_VAL(decodeRet, false); + IF_FALSE_LOGE_AND_RETURN_VAL(executorInfos.size() > 0, false); + + IAM_LOGE("executorRole is %{public}d", executorInfos[0].executorRole); + executorInfos[0].executorRole = executorInfos[0].executorRole; + + remoteExecutorProxy_ = Common::MakeShared(connectionName_, executorInfos[0]); + IF_FALSE_LOGE_AND_RETURN_VAL(remoteExecutorProxy_ != nullptr, false); + + ResultCode startExecutorRet = remoteExecutorProxy_->Start(); + IF_FALSE_LOGE_AND_RETURN_VAL(startExecutorRet == SUCCESS, false); + + std::string collectorUdid; + bool getCollectorUdidRet = DeviceManagerUtil::GetInstance().GetUdidByNetworkId(collectorNetworkId_, collectorUdid); + IF_FALSE_LOGE_AND_RETURN_VAL(getCollectorUdidRet, false); + + auth_->SetCollectorUdid(collectorUdid); + + IAM_LOGI("StartAuth success"); + return SimpleAuthContext::OnStart(); +} + +void RemoteAuthContext::StartAuthDelayed() +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + bool ret = StartAuth(); + if (!ret) { + IAM_LOGE("StartAuth failed"); + Attributes attr; + callback_->OnResult(GENERAL_ERROR, attr); + } + IAM_LOGI("success"); +} + +bool RemoteAuthContext::SendQueryExecutorInfoMsg() +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + std::shared_ptr request = Common::MakeShared(); + IF_FALSE_LOGE_AND_RETURN_VAL(request != nullptr, false); + + bool setMsgTypeRet = request->SetInt32Value(Attributes::ATTR_MSG_TYPE, QUERY_EXECUTOR_INFO); + IF_FALSE_LOGE_AND_RETURN_VAL(setMsgTypeRet, false); + + std::vector authTypes = { static_cast(authType_) }; + bool setAuthTypesRet = request->SetInt32ArrayValue(Attributes::ATTR_AUTH_TYPES, authTypes); + IF_FALSE_LOGE_AND_RETURN_VAL(setAuthTypesRet, false); + + bool setExecutorRoleRet = request->SetInt32Value(Attributes::ATTR_EXECUTOR_ROLE, COLLECTOR); + IF_FALSE_LOGE_AND_RETURN_VAL(setExecutorRoleRet, false); + + std::string localUdid; + bool getLocalUdidRet = DeviceManagerUtil::GetInstance().GetLocalDeviceUdid(localUdid); + IF_FALSE_LOGE_AND_RETURN_VAL(getLocalUdidRet, false); + + MsgCallback msgCallback = [weak_ptr = weak_from_this(), this](const std::shared_ptr &reply) { + IF_FALSE_LOGE_AND_RETURN(reply != nullptr); + + auto shared_ptr = weak_ptr.lock(); + IF_FALSE_LOGE_AND_RETURN(shared_ptr != nullptr); + + int32_t resultCode; + bool getResultCodeRet = reply->GetInt32Value(Attributes::ATTR_RESULT_CODE, resultCode); + IF_FALSE_LOGE_AND_RETURN(getResultCodeRet); + + if (resultCode != SUCCESS) { + IAM_LOGE("query executor info failed"); + Attributes attr; + callback_->OnResult(GENERAL_ERROR, attr); + return; + } + + SetExecutorInfoMsg(reply->Serialize()); + + auto handler = ThreadHandler::GetSingleThreadInstance(); + IF_FALSE_LOGE_AND_RETURN(handler != nullptr); + handler->PostTask([weak_ptr = weak_from_this(), this]() { + auto shared_ptr = weak_ptr.lock(); + IF_FALSE_LOGE_AND_RETURN(shared_ptr != nullptr); + StartAuthDelayed(); + }); + }; + + ResultCode sendMsgRet = RemoteConnectionManager::GetInstance().SendMessage(connectionName_, endPointName_, + RemoteMsgUtil::GetRemoteServiceEndPointName(), request, msgCallback); + IF_FALSE_LOGE_AND_RETURN_VAL(sendMsgRet == SUCCESS, false); + + IAM_LOGI("success"); + return true; +} + +bool RemoteAuthContext::SetupConnection() +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + std::shared_ptr callback = + Common::MakeShared(shared_from_this(), this); + IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, false); + + ResultCode registerResult = + RemoteConnectionManager::GetInstance().RegisterConnectionListener(connectionName_, endPointName_, callback); + IF_FALSE_LOGE_AND_RETURN_VAL(registerResult == SUCCESS, false); + + ResultCode connectResult = + RemoteConnectionManager::GetInstance().OpenConnection(connectionName_, collectorNetworkId_, GetTokenId()); + IF_FALSE_LOGE_AND_RETURN_VAL(connectResult == SUCCESS, false); + + bool sendMsgRet = SendQueryExecutorInfoMsg(); + IF_FALSE_LOGE_AND_RETURN_VAL(sendMsgRet, false); + + IAM_LOGI("success"); + return true; +} + +void RemoteAuthContext::OnConnectStatus(const std::string &connectionName, ConnectStatus connectStatus) +{ + std::lock_guard lock(mutex_); + + IF_FALSE_LOGE_AND_RETURN(connectionName_ == connectionName); + + if (connectStatus == ConnectStatus::DISCONNECT) { + IAM_LOGI("connection is disconnected"); + Attributes attr; + callback_->OnResult(ResultCode::GENERAL_ERROR, attr); + return; + } +} + +void RemoteAuthContext::OnTimeOut() +{ + IAM_LOGI("timeout"); + Attributes attr; + callback_->OnResult(TIMEOUT, attr); +} +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS diff --git a/services/context/src/remote_auth_invoker_context.cpp b/services/context/src/remote_auth_invoker_context.cpp new file mode 100644 index 0000000000000000000000000000000000000000..48b1afb8d566b4cf33c8e749e0622815270a310e --- /dev/null +++ b/services/context/src/remote_auth_invoker_context.cpp @@ -0,0 +1,355 @@ +/* + * 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 "remote_auth_invoker_context.h" + +#include "device_manager_util.h" +#include "hdi_wrapper.h" +#include "iam_check.h" +#include "iam_logger.h" +#include "iam_ptr.h" +#include "relative_timer.h" +#include "remote_connect_manager.h" +#include "thread_handler.h" +#include "user_auth_hdi.h" + +#define LOG_TAG "USER_AUTH_SA" + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +namespace { +constexpr uint32_t TIME_OUT_MS = 3 * 60 * 1000; // 3min +} +class RemoteAuthInvokerContextMessageCallback : public ConnectionListener, public NoCopyable { +public: + explicit RemoteAuthInvokerContextMessageCallback(std::weak_ptr callbackWeakBase, + RemoteAuthInvokerContext *callback) + : callbackWeakBase_(callbackWeakBase), + callback_(callback), + threadHandler_(ThreadHandler::GetSingleThreadInstance()) + { + } + + ~RemoteAuthInvokerContextMessageCallback() = default; + + void OnMessage(const std::string &connectionName, const std::string &srcEndPoint, + const std::shared_ptr &request, std::shared_ptr &reply) override + { + IF_FALSE_LOGE_AND_RETURN(request != nullptr); + IF_FALSE_LOGE_AND_RETURN(reply != nullptr); + + IAM_LOGI("connectionName: %{public}s, srcEndPoint: %{public}s", + RemoteMsgUtil::GetConnectionNameStr(connectionName).c_str(), srcEndPoint.c_str()); + + std::shared_ptr callbackSharedBase = callbackWeakBase_.lock(); + IF_FALSE_LOGE_AND_RETURN(callbackSharedBase != nullptr); + + callback_->OnMessage(connectionName, srcEndPoint, request, reply); + } + + void OnConnectStatus(const std::string &connectionName, ConnectStatus connectStatus) override + { + IAM_LOGI("connectionName: %{public}s, connectStatus %{public}d", + RemoteMsgUtil::GetConnectionNameStr(connectionName).c_str(), connectStatus); + + IF_FALSE_LOGE_AND_RETURN(connectStatus == ConnectStatus::DISCONNECT); + IF_FALSE_LOGE_AND_RETURN(threadHandler_ != nullptr); + + threadHandler_->PostTask( + [connectionName, connectStatus, callbackWeakBase = callbackWeakBase_, callback = callback_, this]() { + IAM_LOGI("OnConnectStatus process begin"); + auto callbackSharedBase = callbackWeakBase.lock(); + IF_FALSE_LOGE_AND_RETURN(callbackSharedBase != nullptr); + + callback_->OnConnectStatus(connectionName, connectStatus); + IAM_LOGI("OnConnectStatus process success"); + }); + + IAM_LOGI("task posted"); + } + +private: + std::weak_ptr callbackWeakBase_; + RemoteAuthInvokerContext *callback_; + std::shared_ptr threadHandler_ = nullptr; +}; + +RemoteAuthInvokerContext::RemoteAuthInvokerContext(uint64_t contextId, AuthParamInner authParam, + RemoteAuthInvokerContextParam param, std::shared_ptr callback) + : BaseContext("RemoteAuthInvokerContext", contextId, callback), + authParam_(authParam), + connectionName_(param.connectionName), + verifierNetworkId_(param.verifierNetworkId), + collectorNetworkId_(param.collectorNetworkId), + tokenId_(param.tokenId), + collectorTokenId_(param.collectorTokenId), + callback_(callback) +{ + endPointName_ = RemoteMsgUtil::GetRemoteAuthInvokerContextEndPointName(); +} + +RemoteAuthInvokerContext::~RemoteAuthInvokerContext() +{ + std::lock_guard lock(mutex_); + if (cancelTimerId_.has_value()) { + RelativeTimer::GetInstance().Unregister(cancelTimerId_.value()); + } + RemoteConnectionManager::GetInstance().UnregisterConnectionListener(connectionName_, endPointName_); + RemoteConnectionManager::GetInstance().CloseConnection(connectionName_); +} + +ContextType RemoteAuthInvokerContext::GetContextType() const +{ + return ContextType::REMOTE_AUTH_INVOKER_CONTEXT; +} + +uint32_t RemoteAuthInvokerContext::GetTokenId() const +{ + return tokenId_; +} + +void RemoteAuthInvokerContext::OnMessage(const std::string &connectionName, const std::string &srcEndPoint, + const std::shared_ptr &request, std::shared_ptr &reply) +{ + std::lock_guard lock(mutex_); + + int32_t msgType; + IF_FALSE_LOGE_AND_RETURN(request->GetInt32Value(Attributes::ATTR_MSG_TYPE, msgType)); + + int32_t resultCode = ResultCode::GENERAL_ERROR; + switch (msgType) { + case SEND_REMOTE_AUTH_TIP: + resultCode = ProcAuthTipMsg(*request); + break; + case SEND_REMOTE_AUTH_RESULT: + resultCode = ProcAuthResultMsg(*request); + break; + default: + IAM_LOGE("invalid msgType:%{public}d", msgType); + break; + } + + IF_FALSE_LOGE_AND_RETURN(resultCode == ResultCode::SUCCESS); + bool setResultCodeRet = reply->SetInt32Value(Attributes::ATTR_RESULT_CODE, ResultCode::SUCCESS); + IF_FALSE_LOGE_AND_RETURN(setResultCodeRet); +} + +void RemoteAuthInvokerContext::OnConnectStatus(const std::string &connectionName, ConnectStatus connectStatus) +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + if (connectStatus == ConnectStatus::DISCONNECT) { + IAM_LOGI("connection is disconnected"); + Attributes attr; + callback_->OnResult(ResultCode::GENERAL_ERROR, attr); + return; + } +} + +void RemoteAuthInvokerContext::SetVerifierContextId(uint64_t contextId) +{ + std::lock_guard lock(mutex_); + verifierContextId_ = contextId; + IAM_LOGI("verifierContextId set success"); +} + +bool RemoteAuthInvokerContext::OnStart() +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + cancelTimerId_ = RelativeTimer::GetInstance().Register( + [weak_ptr = weak_from_this(), this]() { + auto shared_ptr = weak_ptr.lock(); + IF_FALSE_LOGE_AND_RETURN(shared_ptr != nullptr); + OnTimeOut(); + }, + TIME_OUT_MS); + + bool getUdidRet = DeviceManagerUtil::GetInstance().GetUdidByNetworkId(verifierNetworkId_, verifierUdid_); + IF_FALSE_LOGE_AND_RETURN_VAL(getUdidRet, false); + + endPointName_ = RemoteMsgUtil::GetRemoteAuthInvokerContextEndPointName(); + + std::shared_ptr callback = + Common::MakeShared(shared_from_this(), this); + IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, false); + + ResultCode registerResult = + RemoteConnectionManager::GetInstance().RegisterConnectionListener(connectionName_, endPointName_, callback); + IF_FALSE_LOGE_AND_RETURN_VAL(registerResult == SUCCESS, false); + + ResultCode connectResult = + RemoteConnectionManager::GetInstance().OpenConnection(connectionName_, verifierNetworkId_, GetTokenId()); + IF_FALSE_LOGE_AND_RETURN_VAL(connectResult == SUCCESS, false); + + bool sendRequestRet = SendRequest(); + IF_FALSE_LOGE_AND_RETURN_VAL(sendRequestRet, false); + + IAM_LOGI("success"); + return true; +} + +bool RemoteAuthInvokerContext::SendRequest() +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + request_ = Common::MakeShared(); + IF_FALSE_LOGE_AND_RETURN_VAL(request_ != nullptr, false); + + bool setMsgTypeRet = request_->SetInt32Value(Attributes::ATTR_MSG_TYPE, START_REMOTE_AUTH); + IF_FALSE_LOGE_AND_RETURN_VAL(setMsgTypeRet, false); + + std::vector authTypes = { static_cast(authParam_.authType) }; + bool getExecutorInfoRet = RemoteMsgUtil::GetQueryExecutorInfoReply(authTypes, COLLECTOR, verifierUdid_, *request_); + IF_FALSE_LOGE_AND_RETURN_VAL(getExecutorInfoRet, false); + + bool encodeAuthParamRet = RemoteMsgUtil::EncodeAuthParam(authParam_, *request_); + IF_FALSE_LOGE_AND_RETURN_VAL(encodeAuthParamRet, false); + + bool setTokenIdRet = request_->SetUint32Value(Attributes::ATTR_COLLECTOR_TOKEN_ID, collectorTokenId_); + IF_FALSE_LOGE_AND_RETURN_VAL(setTokenIdRet, false); + + bool setCollectorNetworkIdRet = + request_->SetStringValue(Attributes::ATTR_COLLECTOR_NETWORK_ID, collectorNetworkId_); + IF_FALSE_LOGE_AND_RETURN_VAL(setCollectorNetworkIdRet, false); + + MsgCallback msgCallback = [weak_ptr = weak_from_this(), this](const std::shared_ptr &reply) { + IF_FALSE_LOGE_AND_RETURN(reply != nullptr); + + auto shared_ptr = weak_ptr.lock(); + IF_FALSE_LOGE_AND_RETURN(shared_ptr != nullptr); + + int32_t resultCode; + bool getResultCodeRet = reply->GetInt32Value(Attributes::ATTR_RESULT_CODE, resultCode); + IF_FALSE_LOGE_AND_RETURN(getResultCodeRet); + + if (resultCode != ResultCode::SUCCESS) { + IAM_LOGE("get contextId failed"); + Attributes attr; + callback_->OnResult(ResultCode::GENERAL_ERROR, attr); + return; + } + + uint64_t contextId; + bool getContextIdRet = reply->GetUint64Value(Attributes::ATTR_CONTEXT_ID, contextId); + IF_FALSE_LOGE_AND_RETURN(getContextIdRet); + + this->SetVerifierContextId(contextId); + }; + IF_FALSE_LOGE_AND_RETURN_VAL(request_ != nullptr, false); + ResultCode sendMsgRet = RemoteConnectionManager::GetInstance().SendMessage(connectionName_, endPointName_, + RemoteMsgUtil::GetRemoteServiceEndPointName(), request_, msgCallback); + IF_FALSE_LOGE_AND_RETURN_VAL(sendMsgRet == SUCCESS, false); + + IAM_LOGI("success"); + return true; +} + +void RemoteAuthInvokerContext::OnResult(int32_t resultCode, const std::shared_ptr &scheduleResultAttr) +{ + IAM_LOGE("this method is not supported"); +} + +bool RemoteAuthInvokerContext::OnStop() +{ + std::lock_guard lock(mutex_); + IAM_LOGI("canceled"); + Attributes attr; + callback_->OnResult(ResultCode::CANCELED, attr); + // other module is canceled by disconnecting the connection + + IAM_LOGI("success"); + return true; +} + +int32_t RemoteAuthInvokerContext::ProcAuthTipMsg(Attributes &message) +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + int32_t destRole; + bool getDestRoleRet = message.GetInt32Value(Attributes::ATTR_DEST_ROLE, destRole); + IF_FALSE_LOGE_AND_RETURN_VAL(getDestRoleRet, ResultCode::GENERAL_ERROR); + + int32_t tipInfo; + bool getAcquireInfoRet = message.GetInt32Value(Attributes::ATTR_TIP_INFO, tipInfo); + IF_FALSE_LOGE_AND_RETURN_VAL(getAcquireInfoRet, ResultCode::GENERAL_ERROR); + + callback_->OnAcquireInfo(static_cast(destRole), tipInfo, message.Serialize()); + + IAM_LOGI("success"); + return ResultCode::SUCCESS; +} + +int32_t RemoteAuthInvokerContext::ProcAuthResultMsg(Attributes &message) +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + int32_t resultCode; + bool getResultCodeRet = message.GetInt32Value(Attributes::ATTR_RESULT, resultCode); + IF_FALSE_LOGE_AND_RETURN_VAL(getResultCodeRet, ResultCode::GENERAL_ERROR); + + Attributes attr; + std::vector remoteAuthResult; + bool getRemoteAuthResultRet = message.GetUint8ArrayValue(Attributes::ATTR_SIGNED_AUTH_RESULT, remoteAuthResult); + if (getRemoteAuthResultRet) { + auto hdi = HdiWrapper::GetHdiInstance(); + IF_FALSE_LOGE_AND_RETURN_VAL(hdi != nullptr, ResultCode::GENERAL_ERROR); + HdiAuthResultInfo authResultInfo; + int32_t hdiRet = hdi->GetAuthResultFromMessage(verifierUdid_, remoteAuthResult, authResultInfo); + IF_FALSE_LOGE_AND_RETURN_VAL(hdiRet == SUCCESS, ResultCode::GENERAL_ERROR); + + resultCode = authResultInfo.result; + bool setLockOutDurationRet = + attr.SetInt32Value(Attributes::ATTR_LOCKOUT_DURATION, authResultInfo.lockoutDuration); + IF_FALSE_LOGE_AND_RETURN_VAL(setLockOutDurationRet, ResultCode::GENERAL_ERROR); + bool setRemainAttemptsRet = attr.SetInt32Value(Attributes::ATTR_REMAIN_ATTEMPTS, authResultInfo.remainAttempts); + IF_FALSE_LOGE_AND_RETURN_VAL(setRemainAttemptsRet, ResultCode::GENERAL_ERROR); + bool setTokenRet = attr.SetUint8ArrayValue(Attributes::ATTR_SIGNATURE, authResultInfo.token); + IF_FALSE_LOGE_AND_RETURN_VAL(setTokenRet, ResultCode::GENERAL_ERROR); + bool setUserId = attr.SetInt32Value(Attributes::ATTR_USER_ID, authResultInfo.userId); + IF_FALSE_LOGE_AND_RETURN_VAL(setUserId, ResultCode::GENERAL_ERROR); + IAM_LOGI("parsed auth result: %{public}d, lockout duration %{public}d, remain attempts %{public}d, " + "token size %{public}zu, user id %{public}d", + resultCode, authResultInfo.lockoutDuration, authResultInfo.remainAttempts, authResultInfo.token.size(), + authResultInfo.userId); + } else if (resultCode == ResultCode::SUCCESS) { + IAM_LOGE("remote auth result is empty"); + resultCode = ResultCode::GENERAL_ERROR; + } + + bool setResultCodeRet = attr.SetInt32Value(Attributes::ATTR_RESULT, resultCode); + IF_FALSE_LOGE_AND_RETURN_VAL(setResultCodeRet, ResultCode::GENERAL_ERROR); + + callback_->OnResult(resultCode, attr); + + IAM_LOGI("success"); + return ResultCode::SUCCESS; +} + +void RemoteAuthInvokerContext::OnTimeOut() +{ + IAM_LOGI("timeout"); + Attributes attr; + callback_->OnResult(TIMEOUT, attr); +} +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS \ No newline at end of file diff --git a/services/context/src/remote_iam_callback.cpp b/services/context/src/remote_iam_callback.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a67526c3c06be0879fe032da5a03042aa1172fc6 --- /dev/null +++ b/services/context/src/remote_iam_callback.cpp @@ -0,0 +1,93 @@ +/* + * 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 "remote_iam_callback.h" + +#include "iam_check.h" +#include "iam_ptr.h" +#include "remote_connect_manager.h" +#include "remote_msg_util.h" + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +RemoteIamCallback::RemoteIamCallback(std::string &connectionName) : connectionName_(connectionName) +{ +} + +RemoteIamCallback::~RemoteIamCallback() +{ +} + +bool RemoteIamCallback::Init() +{ + localEndPointName_ = RemoteMsgUtil::GetRemoteCallbackEndPointName(); + return true; +} + +void RemoteIamCallback::OnResult(int32_t result, const Attributes &extraInfo) +{ + IAM_LOGI("result: %{public}d", result); + + std::shared_ptr request = Common::MakeShared(extraInfo.Serialize()); + IF_FALSE_LOGE_AND_RETURN(request != nullptr); + + bool setMsgTypeRet = request->SetInt32Value(Attributes::ATTR_MSG_TYPE, SEND_REMOTE_AUTH_RESULT); + IF_FALSE_LOGE_AND_RETURN(setMsgTypeRet); + + bool setResultRet = request->SetInt32Value(Attributes::ATTR_RESULT, result); + IF_FALSE_LOGE_AND_RETURN(setResultRet); + + MsgCallback msgCallback = [](const std::shared_ptr &) { IAM_LOGI("message sent"); }; + + ResultCode sendMsgRet = RemoteConnectionManager::GetInstance().SendMessage(connectionName_, localEndPointName_, + RemoteMsgUtil::GetRemoteAuthInvokerContextEndPointName(), request, msgCallback); + IF_FALSE_LOGE_AND_RETURN(sendMsgRet == ResultCode::SUCCESS); + + IAM_LOGI("success"); +} + +void RemoteIamCallback::OnAcquireInfo(int32_t module, int32_t acquireInfo, const Attributes &extraInfo) +{ + IAM_LOGI("module: %{public}d, acquireInfo: %{public}d", module, acquireInfo); + + std::shared_ptr request = Common::MakeShared(extraInfo.Serialize()); + IF_FALSE_LOGE_AND_RETURN(request != nullptr); + + bool setMsgTypeRet = request->SetInt32Value(Attributes::ATTR_MSG_TYPE, SEND_REMOTE_AUTH_TIP); + IF_FALSE_LOGE_AND_RETURN(setMsgTypeRet); + + bool setModuleRet = request->SetInt32Value(Attributes::ATTR_DEST_ROLE, module); + IF_FALSE_LOGE_AND_RETURN(setModuleRet); + + bool setAcquireInfoRet = request->SetInt32Value(Attributes::ATTR_TIP_INFO, acquireInfo); + IF_FALSE_LOGE_AND_RETURN(setAcquireInfoRet); + + MsgCallback msgCallback = [](const std::shared_ptr &) { IAM_LOGI("message sent"); }; + + ResultCode sendMsgRet = RemoteConnectionManager::GetInstance().SendMessage(connectionName_, localEndPointName_, + RemoteMsgUtil::GetRemoteAuthInvokerContextEndPointName(), request, msgCallback); + IF_FALSE_LOGE_AND_RETURN(sendMsgRet == ResultCode::SUCCESS); + + IAM_LOGI("success"); +} + +sptr RemoteIamCallback::AsObject() +{ + return nullptr; +} +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS \ No newline at end of file diff --git a/services/context/src/simple_auth_context.cpp b/services/context/src/simple_auth_context.cpp index 4903392d531447c7c52400abf813d28d1edc1d60..7b94eff959a7bb1e1d8d43a0191998064ce1d26b 100644 --- a/services/context/src/simple_auth_context.cpp +++ b/services/context/src/simple_auth_context.cpp @@ -21,7 +21,6 @@ #include "iam_check.h" #include "iam_logger.h" #include "iam_para2str.h" -#include "iam_ptr.h" #include "resource_node.h" #include "resource_node_utils.h" #include "schedule_node.h" @@ -78,6 +77,13 @@ SimpleAuthContext::SimpleAuthContext(uint64_t contextId, std::shared_ptr auth, + std::shared_ptr callback) + : BaseContext(type, contextId, callback), + auth_(auth) +{ +} + ContextType SimpleAuthContext::GetContextType() const { return CONTEXT_SIMPLE_AUTH; @@ -90,7 +96,7 @@ uint32_t SimpleAuthContext::GetTokenId() const bool SimpleAuthContext::OnStart() { - IAM_LOGI("%{public}s start", GetDescription()); + IAM_LOGI("%{public}s start should not", GetDescription()); IF_FALSE_LOGE_AND_RETURN_VAL(auth_ != nullptr, false); bool startRet = auth_->Start(scheduleList_, shared_from_this()); if (!startRet) { @@ -218,6 +224,11 @@ void SimpleAuthContext::InvokeResultCallback(const Authentication::AuthResultInf bool setRootSecret = finalResult.SetUint8ArrayValue(Attributes::ATTR_ROOT_SECRET, resultInfo.rootSecret); IF_FALSE_LOGE_AND_RETURN(setRootSecret == true); } + if (resultInfo.remoteAuthResultMsg.size() != 0) { + bool setRemoteAuthResultMsg = finalResult.SetUint8ArrayValue(Attributes::ATTR_SIGNED_AUTH_RESULT, + resultInfo.remoteAuthResultMsg); + IF_FALSE_LOGE_AND_RETURN(setRemoteAuthResultMsg == true); + } callback_->OnResult(resultInfo.result, finalResult); IAM_LOGI("%{public}s invoke result callback success", GetDescription()); } diff --git a/services/context/src/widget_client.cpp b/services/context/src/widget_client.cpp index 30810e95cff19b64ad8cb47fa08de2df31233f28..3bb4e10cb5da8e6e2a760b2b0f6751d06fdd218c 100644 --- a/services/context/src/widget_client.cpp +++ b/services/context/src/widget_client.cpp @@ -20,7 +20,6 @@ #include "auth_common.h" #include "iam_check.h" #include "iam_logger.h" -#include "iam_ptr.h" #include "iam_time.h" #include "nlohmann/json.hpp" #include "widget_callback_interface.h" diff --git a/services/core/BUILD.gn b/services/core/BUILD.gn index 5c9a58140e5ef0fdd27103dfa75b64b606f27d31..ac1daa0ddfde374784c5a5cffd5a2675262aedcd 100644 --- a/services/core/BUILD.gn +++ b/services/core/BUILD.gn @@ -56,6 +56,10 @@ ohos_source_set("userauth_service_core") { "src/enrollment_impl.cpp", "src/hdi_message_callback_service.cpp", "src/identification_impl.cpp", + "src/remote_auth_service.cpp", + "src/remote_executor_proxy.cpp", + "src/remote_executor_stub.cpp", + "src/remote_msg_util.cpp", "src/resource_node_impl.cpp", "src/resource_node_pool_impl.cpp", "src/resource_node_utils.cpp", @@ -73,6 +77,7 @@ ohos_source_set("userauth_service_core") { ] deps = [ + "../../frameworks/native/client:userauth_client", "../../frameworks/native/common:attributes", "../../frameworks/native/common:dfx", "../../services/base:userauth_service_base", @@ -81,6 +86,7 @@ ohos_source_set("userauth_service_core") { external_deps = [ "ability_runtime:app_manager", "c_utils:utils", + "device_manager:devicemanagersdk", "drivers_interface_user_auth:libuser_auth_proxy_2.0", "hdf_core:libhdi", "hilog:libhilog", @@ -102,6 +108,7 @@ ohos_source_set("userauth_service_core") { "../../common:iam_log_config", "../../common:iam_utils_config", "../../frameworks/native/ipc:userauth_client_ipc_config", + "../remote_connect:userauth_service_remote_connect_config", ] subsystem_name = "useriam" diff --git a/services/core/inc/auth_event_listener_manager.h b/services/core/inc/auth_event_listener_manager.h index d12e511b5ab4fb9a4b9088a873bd5e848d6f430d..bdb13c2bb28defb7e090144cfd0a202f58a4e818 100644 --- a/services/core/inc/auth_event_listener_manager.h +++ b/services/core/inc/auth_event_listener_manager.h @@ -16,10 +16,10 @@ #ifndef IAM_AUTH_EVENT_LISTENER_MANAGER_H #define IAM_AUTH_EVENT_LISTENER_MANAGER_H +#include "user_auth_interface.h" +#include #include #include -#include -#include "user_auth_interface.h" namespace OHOS { namespace UserIam { @@ -38,10 +38,10 @@ public: protected: class AuthEventListenerDeathRecipient : public IRemoteObject::DeathRecipient, public NoCopyable { - public: - AuthEventListenerDeathRecipient() = default; - ~AuthEventListenerDeathRecipient() override = default; - void OnRemoteDied(const wptr &remote) override; + public: + AuthEventListenerDeathRecipient() = default; + ~AuthEventListenerDeathRecipient() override = default; + void OnRemoteDied(const wptr &remote) override; }; AuthEventListenerManager() = default; @@ -55,7 +55,9 @@ protected: private: struct FinderSet { - explicit FinderSet(sptr remoteObject) : remoteObject_(remoteObject) {} + explicit FinderSet(sptr remoteObject) : remoteObject_(remoteObject) + { + } bool operator()(sptr listener) { return listener->AsObject() == remoteObject_; @@ -64,7 +66,9 @@ private: }; struct FinderMap { - explicit FinderMap(sptr remoteObject) : remoteObject_(remoteObject) {} + explicit FinderMap(sptr remoteObject) : remoteObject_(remoteObject) + { + } bool operator()(std::map, sptr>::value_type &pair) { return pair.first->AsObject() == remoteObject_; diff --git a/services/core/inc/auth_widget_helper.h b/services/core/inc/auth_widget_helper.h index 1797c0a39738b57ec09efbe1429695e6cc1c1e84..a7359b901ca74e150ccf7bf82350b4d352f0be6e 100644 --- a/services/core/inc/auth_widget_helper.h +++ b/services/core/inc/auth_widget_helper.h @@ -25,12 +25,12 @@ namespace UserIam { namespace UserAuth { class AuthWidgetHelper { public: - static bool InitWidgetContextParam(const AuthParam &authParam, std::vector &validType, + static bool InitWidgetContextParam(const AuthParamInner &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); static int32_t CheckReuseUnlockResult(const ContextFactory::AuthWidgetContextPara ¶, - const AuthParam &authParam, Attributes &extraInfo); + const AuthParamInner &authParam, Attributes &extraInfo); private: static const uint32_t USER_AUTH_TOKEN_LEN = 148; diff --git a/services/core/inc/authentication.h b/services/core/inc/authentication.h index fb7eacc7947b30415ea434f285d1174e521f8185..a0d030382df581ec543133816f50df4d755741e1 100644 --- a/services/core/inc/authentication.h +++ b/services/core/inc/authentication.h @@ -31,6 +31,7 @@ public: AuthType authType {ALL}; AuthTrustLevel atl {ATL1}; uint32_t tokenId {0}; + uint32_t collectorTokenId {0}; std::vector challenge; bool endAfterFirstFail; std::string callerName; @@ -49,6 +50,7 @@ public: int32_t sdkVersion{0}; int32_t userId; int64_t pinExpiredInfo; + std::vector remoteAuthResultMsg; }; struct AuthExecutorMsg { uint64_t executorIndex; @@ -61,6 +63,7 @@ public: virtual void SetChallenge(const std::vector &challenge) = 0; virtual void SetAccessTokenId(uint32_t tokenId) = 0; virtual void SetEndAfterFirstFail(bool endAfterFirstFail) = 0; + virtual void SetCollectorUdid(std::string collectorUdid) = 0; virtual bool Start(std::vector> &scheduleList, std::shared_ptr callback) = 0; diff --git a/services/core/inc/remote_auth_service.h b/services/core/inc/remote_auth_service.h new file mode 100644 index 0000000000000000000000000000000000000000..bb84c16302e09384eafe905b0dd8135f36af3e43 --- /dev/null +++ b/services/core/inc/remote_auth_service.h @@ -0,0 +1,52 @@ +/* + * 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 REMOTE_AUTH_SERVICE_H +#define REMOTE_AUTH_SERVICE_H + +#include +#include +#include + +#include "attributes.h" +#include "remote_connect_manager.h" + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +class RemoteAuthService { +public: + static RemoteAuthService &GetInstance(); + RemoteAuthService() = default; + virtual ~RemoteAuthService() = default; + + virtual bool Start() = 0; + virtual void OnMessage(const std::string &connectionName, const std::string &srcEndPoint, + const std::shared_ptr &request, std::shared_ptr &reply) = 0; + virtual void OnConnectStatus(const std::string &connectionName, ConnectStatus connectStatus) = 0; + + virtual int32_t ProcStartRemoteAuthRequest(std::string connectionName, const std::shared_ptr &request, + std::shared_ptr &reply) = 0; + virtual int32_t ProcQueryExecutorInfoRequest(const std::shared_ptr &request, + std::shared_ptr &reply) = 0; + virtual int32_t ProcBeginExecuteRequest(const std::shared_ptr &request, + std::shared_ptr &reply) = 0; + virtual int32_t ProcEndExecuteRequest(const std::shared_ptr &request, + std::shared_ptr &reply) = 0; +}; +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS +#endif // REMOTE_AUTH_SERVICE_H \ No newline at end of file diff --git a/services/core/inc/remote_executor_proxy.h b/services/core/inc/remote_executor_proxy.h new file mode 100644 index 0000000000000000000000000000000000000000..eb137b1087296a8c42987492f6058e9bdfec5a1a --- /dev/null +++ b/services/core/inc/remote_executor_proxy.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2022 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 REMOTE_EXECUTOR_PROXY_H +#define REMOTE_EXECUTOR_PROXY_H + +#include + +#include "attributes.h" +#include "co_auth_client_callback.h" +#include "co_auth_client_defines.h" +#include "executor_callback_interface.h" +#include "remote_connect_manager.h" +#include "remote_msg_util.h" + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +class RemoteExecutorProxy : public std::enable_shared_from_this { +public: + RemoteExecutorProxy(std::string connectionName, ExecutorInfo registerInfo); + virtual ~RemoteExecutorProxy(); + + ResultCode Start(); + + // ConnectionListener + void OnMessage(const std::string &connectionName, const std::string &srcEndPoint, + const std::shared_ptr &request, std::shared_ptr &reply); + void OnConnectStatus(const std::string &connectionName, ConnectStatus connectStatus); + + // ExecutorCallbackInterface + void OnMessengerReady(uint64_t executorIndex, const std::shared_ptr &messenger, + const std::vector &publicKey, const std::vector &templateIdList); + int32_t OnBeginExecute(uint64_t scheduleId, const std::vector &publicKey, const Attributes &command); + int32_t OnEndExecute(uint64_t scheduleId, const Attributes &command); + int32_t OnSendData(uint64_t scheduleId, const Attributes &data); + + void OnErrorFinish(); + +private: + // ExecutorMessengerInterface + int32_t ProcSendDataMsg(Attributes &data); + int32_t ProcFinishMsg(Attributes &data); + + std::recursive_mutex mutex_; + std::shared_ptr connectionCallback_ = nullptr; + std::shared_ptr executorCallback_ = nullptr; + std::shared_ptr messenger_ = nullptr; + + uint64_t executorIndex_ = 0; + std::string connectionName_; + ExecutorInfo registerInfo_; + std::string endPointName_; + uint64_t scheduleId_; +}; +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS +#endif // REMOTE_EXECUTOR_PROXY_H \ No newline at end of file diff --git a/services/core/inc/remote_executor_stub.h b/services/core/inc/remote_executor_stub.h new file mode 100644 index 0000000000000000000000000000000000000000..43525ee767d7fc162e140632c09585eff1b59dcb --- /dev/null +++ b/services/core/inc/remote_executor_stub.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2022 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 REMOTE_EXECUTOR_STUB_H +#define REMOTE_EXECUTOR_STUB_H + +#include "attributes.h" +#include "co_auth_client_defines.h" +#include "executor_callback_interface.h" +#include "nocopyable.h" +#include "remote_connect_manager.h" +#include "schedule_node.h" + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +class RemoteExecutorStub : public std::enable_shared_from_this { +public: +public: + RemoteExecutorStub(); + virtual ~RemoteExecutorStub(); + + // ConnectionListener + void OnMessage(const std::string &connectionName, const std::string &srcEndPoint, + const std::shared_ptr &request, std::shared_ptr &reply); + + // ScheduleNode + int32_t OnMessage(ExecutorRole dstRole, const std::vector &msg); + int32_t ContinueSchedule(ResultCode resultCode, const std::shared_ptr &finalResult); + + // ExecutorCallbackInterface + int32_t ProcBeginExecuteRequest(Attributes &attr); + +private: + int32_t ProcSendDataMsg(Attributes &attr); + + std::recursive_mutex mutex_; + std::shared_ptr connectionCallback_ = nullptr; + std::shared_ptr remoteScheduleNode_ = nullptr; + uint64_t executorIndex_; + std::string connectionName_; + std::string endPointName_; +}; +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS +#endif // REMOTE_EXECUTOR_STUB_H \ No newline at end of file diff --git a/services/core/inc/remote_msg_util.h b/services/core/inc/remote_msg_util.h new file mode 100644 index 0000000000000000000000000000000000000000..b14b710695eb4e9715cd5349f7426aef0bee8b81 --- /dev/null +++ b/services/core/inc/remote_msg_util.h @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2022 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 REMOTE_MSG_UTIL_H +#define REMOTE_MSG_UTIL_H + +#include "attributes.h" +#include "co_auth_client_defines.h" +#include "iam_logger.h" +#include "user_auth_common_defines.h" + +#define LOG_TAG "USER_AUTH_SA" + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +enum MessageType { + // collector remoteAuthService -> verifier remoteAuthService + START_REMOTE_AUTH = 1, + + // verifier remoteAuthService callback -> collector remoteAuthInvokerContext + SEND_REMOTE_AUTH_TIP = 2, + SEND_REMOTE_AUTH_RESULT = 3, + + // verifier remoteAuthInvokerContext -> collector remoteAuthService + QUERY_EXECUTOR_INFO = 4, + + // verifier executor proxy -> collector remoteAuthService + BEGIN_EXECUTE = 5, + END_EXECUTE = 6, + + // verifier executor proxy -> executor stub + SEND_DATA_TO_EXECUTOR = 7, + + // collector executor stub -> verifier executor proxy + EXECUTOR_FINISH = 8, + EXECUTOR_SEND_DATA = 9, +}; + +class RemoteMsgUtil { +public: + static bool GetConnectionName(uint64_t contextId, std::string &connectionName); + static std::string GetConnectionNameStr(const std::string &connectionName); + static std::string GetExecutorProxyEndPointName(); + static std::string GetExecutorStubEndPointName(); + static std::string GetRemoteServiceEndPointName(); + static std::string GetRemoteCallbackEndPointName(); + static std::string GetRemoteAuthContextEndPointName(); + static std::string GetRemoteAuthInvokerContextEndPointName(); + + // QUERY_EXECUTOR_INFO + static bool GetQueryExecutorInfoReply(const std::vector authTypes, int32_t executorRole, + std::string remoteUdid, Attributes &attr); + static bool DecodeQueryExecutorInfoReply(const Attributes &attr, std::vector &executorInfoArray); + + static bool EncodeAuthParam(const AuthParamInner &authParam, Attributes &attr); + static bool DecodeAuthParam(const Attributes &attr, AuthParamInner &authParam); + +private: + // QUERY_EXECUTOR_INFO + static bool EncodeQueryExecutorInfoReply(const std::vector &executorInfoArray, + const std::vector &signedRemoteExecutorInfo, Attributes &attr); + static bool SetExecutorInfoToAttributes(const ExecutorInfo &executorInfo, Attributes &attr); + static bool GetExecutorInfoFromAttributes(const Attributes &Attr, std::vector &signedRemoteExecutorInfo, + ExecutorInfo &executorInfo); + static bool SetExecutorInfoArrayToAttributes(const std::vector &executorInfoArray, Attributes &attr); + static bool GetExecutorInfoArrayFromAttributes(const Attributes &Attr, + std::vector &signedRemoteExecutorInfo, std::vector &executorInfoArray); +}; +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS +#endif // REMOTE_MSG_UTIL_H \ No newline at end of file diff --git a/services/core/inc/remote_template.h b/services/core/inc/remote_template.h new file mode 100644 index 0000000000000000000000000000000000000000..5eb950904ef0e8669479782852535436033b5016 --- /dev/null +++ b/services/core/inc/remote_template.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2022 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 IAM_RESOURCE_NODE_POOL_H +#define IAM_RESOURCE_NODE_POOL_H + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS +#endif // IAM_RESOURCE_NODE_POOL_H \ No newline at end of file diff --git a/services/core/inc/resource_node.h b/services/core/inc/resource_node.h index 5dd034edb5207ba66913fc864494329908d7b1b7..783f91db8869163047bc02f1cd49fdea886ae3e4 100644 --- a/services/core/inc/resource_node.h +++ b/services/core/inc/resource_node.h @@ -40,6 +40,7 @@ public: virtual uint64_t GetExecutorMatcher() const = 0; virtual ExecutorSecureLevel GetExecutorEsl() const = 0; virtual std::vector GetExecutorPublicKey() const = 0; + virtual std::string GetExecutorDeviceUdid() const = 0; virtual int32_t BeginExecute(uint64_t scheduleId, const std::vector &publicKey, const Attributes &command) = 0; virtual int32_t EndExecute(uint64_t scheduleId, const Attributes &command) = 0; diff --git a/services/core/inc/schedule_node.h b/services/core/inc/schedule_node.h index dce21d1d55be439185dbfca95bb6b008aff61d1b..4e469d187c23c6ed1b528de0cb650db592814710 100644 --- a/services/core/inc/schedule_node.h +++ b/services/core/inc/schedule_node.h @@ -81,6 +81,7 @@ public: virtual ~Builder() = default; virtual std::shared_ptr SetScheduleId(uint64_t scheduleId) = 0; virtual std::shared_ptr SetAccessTokenId(uint32_t tokenId) = 0; + virtual std::shared_ptr SetCollectorTokenId(uint32_t collectorTokenId) = 0; virtual std::shared_ptr SetPinSubType(PinSubType pinSubType) = 0; virtual std::shared_ptr SetTemplateIdList(const std::vector &templateIdList) = 0; virtual std::shared_ptr SetAuthType(AuthType authType) = 0; @@ -88,7 +89,6 @@ public: virtual std::shared_ptr SetScheduleMode(ScheduleMode scheduleMode) = 0; virtual std::shared_ptr SetScheduleCallback(const std::shared_ptr &callback) = 0; virtual std::shared_ptr SetExpiredTime(uint32_t ms) = 0; - virtual std::shared_ptr SetParametersAttributes(const std::shared_ptr ¶meters) = 0; virtual std::shared_ptr SetThreadHandler(const std::shared_ptr &threadHandler) = 0; virtual std::shared_ptr SetEndAfterFirstFail(const bool endAfterFirstFail) = 0; virtual std::shared_ptr SetCollectorMessage(const std::vector &message) = 0; diff --git a/services/core/inc/schedule_node_helper.h b/services/core/inc/schedule_node_helper.h index 29587e950261e20a479d82098dc7bb9e63d53e53..f1274a2a8e7db80dbf6c4fa283f883dc48baabac 100644 --- a/services/core/inc/schedule_node_helper.h +++ b/services/core/inc/schedule_node_helper.h @@ -22,6 +22,7 @@ #include "hdi_wrapper.h" #include "schedule_node.h" +#include "schedule_node_builder.h" namespace OHOS { namespace UserIam { @@ -31,6 +32,7 @@ public: struct NodeOptionalPara { std::optional expire; std::optional tokenId; + uint32_t collectorTokenId; std::optional pinSubType; std::optional endAfterFirstFail; }; diff --git a/services/core/src/auth_event_listener_manager.cpp b/services/core/src/auth_event_listener_manager.cpp index 38a791781ff7b66a043d8d9b08a8b566c279055b..f5a313652ad76117e984d3942b1dff28b6301606 100644 --- a/services/core/src/auth_event_listener_manager.cpp +++ b/services/core/src/auth_event_listener_manager.cpp @@ -54,8 +54,7 @@ int32_t AuthEventListenerManager::RegistUserAuthSuccessEventListener(const std:: return SUCCESS; } -int32_t AuthEventListenerManager::UnRegistUserAuthSuccessEventListener( - const sptr &listener) +int32_t AuthEventListenerManager::UnRegistUserAuthSuccessEventListener(const sptr &listener) { IAM_LOGI("start"); IF_FALSE_LOGE_AND_RETURN_VAL(listener != nullptr, GENERAL_ERROR); @@ -118,7 +117,8 @@ void AuthEventListenerManager::OnNotifyAuthSuccessEvent(int32_t userId, AuthType if (iter != nullptr) { iter->OnNotifyAuthSuccessEvent(userId, authType, callerType, callerName); IAM_LOGI("OnNotifyAuthSuccessEvent, userId: %{public}d, authType: %{public}d, callerName: %{public}s, " - "callerType: %{public}d", userId, static_cast(authType), callerName.c_str(), callerType); + "callerType: %{public}d", + userId, static_cast(authType), callerName.c_str(), callerType); } } } @@ -134,8 +134,7 @@ int32_t AuthEventListenerManager::AddDeathRecipient(const sptrAsObject())); + auto iter = std::find_if(deathRecipientMap_.begin(), deathRecipientMap_.end(), FinderMap(listener->AsObject())); if (iter != deathRecipientMap_.end()) { IAM_LOGE("deathRecipient is already registed"); return SUCCESS; @@ -163,8 +162,7 @@ int32_t AuthEventListenerManager::RemoveDeathRecipient(const sptrAsObject())); + auto iter = std::find_if(deathRecipientMap_.begin(), deathRecipientMap_.end(), FinderMap(listener->AsObject())); if (iter == deathRecipientMap_.end()) { IAM_LOGE("deathRecipient is not registed"); return SUCCESS; diff --git a/services/core/src/auth_widget_helper.cpp b/services/core/src/auth_widget_helper.cpp index 0a1f5f6a4e6eb169b5c32a321044df5eb70cb064..86bb5a2bc3a7af70a6cacec81f06290ff634622a 100644 --- a/services/core/src/auth_widget_helper.cpp +++ b/services/core/src/auth_widget_helper.cpp @@ -31,7 +31,7 @@ namespace OHOS { namespace UserIam { namespace UserAuth { -bool AuthWidgetHelper::InitWidgetContextParam(const AuthParam &authParam, std::vector &validType, +bool AuthWidgetHelper::InitWidgetContextParam(const AuthParamInner &authParam, std::vector &validType, const WidgetParam &widgetParam, ContextFactory::AuthWidgetContextPara ¶) { for (auto &authType : validType) { @@ -179,7 +179,7 @@ int32_t AuthWidgetHelper::SetReuseUnlockResult(int32_t apiVersion, const HdiReus } int32_t AuthWidgetHelper::CheckReuseUnlockResult(const ContextFactory::AuthWidgetContextPara ¶, - const AuthParam &authParam, Attributes &extraInfo) + const AuthParamInner &authParam, Attributes &extraInfo) { IAM_LOGI("start userId:%{public}d, reuseMode:%{public}u, reuseDuration: %{public}" PRIu64 ".", para.userId, authParam.reuseUnlockResult.reuseMode, authParam.reuseUnlockResult.reuseDuration); @@ -199,7 +199,7 @@ int32_t AuthWidgetHelper::CheckReuseUnlockResult(const ContextFactory::AuthWidge HdiReuseUnlockParam unlockParam = {}; unlockParam.baseParam.userId = para.userId; unlockParam.baseParam.authTrustLevel = authParam.authTrustLevel; - for (auto &type : authParam.authType) { + for (auto &type : authParam.authTypes) { unlockParam.authTypes.emplace_back(static_cast(type)); } unlockParam.baseParam.challenge = authParam.challenge; diff --git a/services/core/src/authentication_impl.cpp b/services/core/src/authentication_impl.cpp index 8b0cc4f82ff1be2971b4e3c448998d426ed69679..3dd1978be1ec5509d97424be6d4c68db2ff7072a 100644 --- a/services/core/src/authentication_impl.cpp +++ b/services/core/src/authentication_impl.cpp @@ -65,6 +65,11 @@ void AuthenticationImpl::SetEndAfterFirstFail(bool endAfterFirstFail) endAfterFirstFail_ = endAfterFirstFail; } +void AuthenticationImpl::SetCollectorUdid(std::string collectorUdid) +{ + collectorUdid_ = collectorUdid; +} + uint32_t AuthenticationImpl::GetAccessTokenId() const { return tokenId_; @@ -78,7 +83,7 @@ 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", authPara_.userId, authPara_.authType, + IAM_LOGI("UserId:%{public}d AuthType:%{public}d ATL:%{public}u", authPara_.userId, authPara_.authType, authPara_.atl); auto hdi = HdiWrapper::GetHdiInstance(); if (!hdi) { @@ -96,6 +101,7 @@ bool AuthenticationImpl::Start(std::vector> &sched .apiVersion = authPara_.sdkVersion, }, .authType = authPara_.authType, + .collectorUdid = collectorUdid_, }; std::vector infos; IamHitraceHelper traceHelper("hdi BeginAuthentication"); @@ -113,6 +119,7 @@ bool AuthenticationImpl::Start(std::vector> &sched ScheduleNodeHelper::NodeOptionalPara para; para.tokenId = tokenId_; para.endAfterFirstFail = endAfterFirstFail_; + para.collectorTokenId = authPara_.collectorTokenId; if (!ScheduleNodeHelper::BuildFromHdi(infos, callback, scheduleList, para)) { IAM_LOGE("BuildFromHdi failed"); @@ -154,6 +161,7 @@ bool AuthenticationImpl::Update(const std::vector &scheduleResult, Auth resultInfo.credentialCount = enrolledState.credentialCount; resultInfo.sdkVersion = authPara_.sdkVersion; resultInfo.userId = info.userId; + resultInfo.remoteAuthResultMsg = info.remoteAuthResultMsg; if (resultInfo.result != SUCCESS) { SetLatestError(resultInfo.result); diff --git a/services/core/src/authentication_impl.h b/services/core/src/authentication_impl.h index 6f4b36577fa4576098e73aff76d41342d0de4e02..cb0af0b58f9d06ab2c9382a2b546d94cfbb45611 100644 --- a/services/core/src/authentication_impl.h +++ b/services/core/src/authentication_impl.h @@ -34,6 +34,7 @@ public: void SetChallenge(const std::vector &challenge) override; void SetAccessTokenId(uint32_t tokenId) override; void SetEndAfterFirstFail(bool endAfterFirstFail) override; + void SetCollectorUdid(std::string collectorUdid) override; bool Start(std::vector> &scheduleList, std::shared_ptr callback) override; @@ -60,6 +61,7 @@ private: int32_t latestError_ = ResultCode::GENERAL_ERROR; std::vector authExecutorMsgs_ {}; + std::string collectorUdid_ {}; }; } // namespace UserAuth } // namespace UserIam diff --git a/services/core/src/remote_auth_service.cpp b/services/core/src/remote_auth_service.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4633d877cd9795834e64b365e0398e010e9224f4 --- /dev/null +++ b/services/core/src/remote_auth_service.cpp @@ -0,0 +1,234 @@ +/* + * 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 "remote_auth_service.h" + +#include "iam_check.h" +#include "iam_logger.h" +#include "iam_para2str.h" + +#include "device_manager_util.h" +#include "hdi_wrapper.h" +#include "iam_defines.h" +#include "iam_ptr.h" +#include "remote_executor_stub.h" +#include "remote_msg_util.h" +#include "user_auth_service.h" + +#define LOG_TAG "USER_AUTH_SA" + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +class RemoteAuthServiceImpl : public RemoteAuthService { +public: + static RemoteAuthServiceImpl &GetInstance(); + RemoteAuthServiceImpl() = default; + ~RemoteAuthServiceImpl() override = default; + + bool Start() override; + void OnMessage(const std::string &connectionName, const std::string &srcEndPoint, + const std::shared_ptr &request, std::shared_ptr &reply) override; + void OnConnectStatus(const std::string &connectionName, ConnectStatus connectStatus) override; + + int32_t ProcStartRemoteAuthRequest(std::string connectionName, const std::shared_ptr &request, + std::shared_ptr &reply) override; + int32_t ProcQueryExecutorInfoRequest(const std::shared_ptr &request, + std::shared_ptr &reply) override; + int32_t ProcBeginExecuteRequest(const std::shared_ptr &request, + std::shared_ptr &reply) override; + int32_t ProcEndExecuteRequest(const std::shared_ptr &request, + std::shared_ptr &reply) override; + +private: + std::recursive_mutex mutex_; + std::map> scheduleId2executorStub_; +}; + +class RemoteAuthServiceImplConnectionListener : public ConnectionListener { +public: + RemoteAuthServiceImplConnectionListener() = default; + ~RemoteAuthServiceImplConnectionListener() override = default; + + void OnMessage(const std::string &connectionName, const std::string &srcEndPoint, + const std::shared_ptr &request, std::shared_ptr &reply) override + { + IF_FALSE_LOGE_AND_RETURN(request != nullptr); + IF_FALSE_LOGE_AND_RETURN(reply != nullptr); + + IAM_LOGI("connectionName: %{public}s, srcEndPoint: %{public}s", + RemoteMsgUtil::GetConnectionNameStr(connectionName).c_str(), srcEndPoint.c_str()); + + RemoteAuthServiceImpl::GetInstance().OnMessage(connectionName, srcEndPoint, request, reply); + } + + void OnConnectStatus(const std::string &connectionName, ConnectStatus connectStatus) override + { + IAM_LOGI("connectionName: %{public}s, connectStatus %{public}d", + RemoteMsgUtil::GetConnectionNameStr(connectionName).c_str(), connectStatus); + + IF_FALSE_LOGE_AND_RETURN(connectStatus == ConnectStatus::DISCONNECT); + + RemoteAuthServiceImpl::GetInstance().OnConnectStatus(connectionName, connectStatus); + } +}; + +RemoteAuthServiceImpl &RemoteAuthServiceImpl::GetInstance() +{ + static RemoteAuthServiceImpl remoteAuthServiceImpl; + return remoteAuthServiceImpl; +} + +bool RemoteAuthServiceImpl::Start() +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + static auto callback = Common::MakeShared(); + IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, false); + ResultCode registerResult = RemoteConnectionManager::GetInstance().RegisterConnectionListener( + RemoteMsgUtil::GetRemoteServiceEndPointName(), callback); + IF_FALSE_LOGE_AND_RETURN_VAL(registerResult == SUCCESS, false); + IAM_LOGI("success"); + return true; +} + +void RemoteAuthServiceImpl::OnMessage(const std::string &connectionName, const std::string &srcEndPoint, + const std::shared_ptr &request, std::shared_ptr &reply) +{ + IAM_LOGI("start"); + std::lock_guard lock(mutex_); + + IF_FALSE_LOGE_AND_RETURN(request != nullptr); + + int32_t msgType; + bool getMsgTypeRet = request->GetInt32Value(Attributes::ATTR_MSG_TYPE, msgType); + IF_FALSE_LOGE_AND_RETURN(getMsgTypeRet); + + IAM_LOGI("msgType is %{public}d", msgType); + int32_t resultCode = ResultCode::GENERAL_ERROR; + switch (msgType) { + case START_REMOTE_AUTH: + resultCode = ProcStartRemoteAuthRequest(connectionName, request, reply); + break; + case QUERY_EXECUTOR_INFO: + resultCode = ProcQueryExecutorInfoRequest(request, reply); + break; + case BEGIN_EXECUTE: + resultCode = ProcBeginExecuteRequest(request, reply); + break; + case END_EXECUTE: + resultCode = ProcEndExecuteRequest(request, reply); + break; + default: + IAM_LOGE("unsupported request type: %{public}d", msgType); + break; + } + + IF_FALSE_LOGE_AND_RETURN(resultCode == ResultCode::SUCCESS); + + bool setResultCodeRet = reply->SetInt32Value(Attributes::ATTR_RESULT_CODE, ResultCode::SUCCESS); + IF_FALSE_LOGE_AND_RETURN(setResultCodeRet); + + IAM_LOGI("success"); +} + +void RemoteAuthServiceImpl::OnConnectStatus(const std::string &connectionName, ConnectStatus connectStatus) +{ +} + +int32_t RemoteAuthServiceImpl::ProcStartRemoteAuthRequest(std::string connectionName, + const std::shared_ptr &request, std::shared_ptr &reply) +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + auto service = UserAuthService::GetInstance(); + IF_FALSE_LOGE_AND_RETURN_VAL(service != nullptr, GENERAL_ERROR); + + return service->ProcStartRemoteAuthRequest(connectionName, request, reply); +} + +int32_t RemoteAuthServiceImpl::ProcQueryExecutorInfoRequest(const std::shared_ptr &request, + std::shared_ptr &reply) +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + std::vector authTypes; + bool getAuthTypesRet = request->GetInt32ArrayValue(Attributes::ATTR_AUTH_TYPES, authTypes); + IF_FALSE_LOGE_AND_RETURN_VAL(getAuthTypesRet, GENERAL_ERROR); + + int32_t executorRole; + bool getExecutorRoleRet = request->GetInt32Value(Attributes::ATTR_EXECUTOR_ROLE, executorRole); + IF_FALSE_LOGE_AND_RETURN_VAL(getExecutorRoleRet, GENERAL_ERROR); + + std::string srcUdid; + bool getSrcUdidRet = request->GetStringValue(Attributes::ATTR_MSG_SRC_UDID, srcUdid); + IF_FALSE_LOGE_AND_RETURN_VAL(getSrcUdidRet, GENERAL_ERROR); + + bool getQueryExecutorInfoRet = RemoteMsgUtil::GetQueryExecutorInfoReply(authTypes, executorRole, srcUdid, *reply); + IF_FALSE_LOGE_AND_RETURN_VAL(getQueryExecutorInfoRet, GENERAL_ERROR); + + IAM_LOGI("success"); + return SUCCESS; +} + +int32_t RemoteAuthServiceImpl::ProcBeginExecuteRequest(const std::shared_ptr &request, + std::shared_ptr &reply) +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + std::shared_ptr executorStub = Common::MakeShared(); + IF_FALSE_LOGE_AND_RETURN_VAL(executorStub != nullptr, GENERAL_ERROR); + + int32_t resultCode = executorStub->ProcBeginExecuteRequest(*request); + IF_FALSE_LOGE_AND_RETURN_VAL(resultCode == SUCCESS, GENERAL_ERROR); + + uint64_t scheduleId; + bool getScheduleIdRet = request->GetUint64Value(Attributes::ATTR_SCHEDULE_ID, scheduleId); + IF_FALSE_LOGE_AND_RETURN_VAL(getScheduleIdRet, GENERAL_ERROR); + + scheduleId2executorStub_.emplace(scheduleId, executorStub); + IAM_LOGI("success"); + return SUCCESS; +} + +int32_t RemoteAuthServiceImpl::ProcEndExecuteRequest(const std::shared_ptr &request, + std::shared_ptr &reply) +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + uint64_t scheduleId; + bool getScheduleIdRet = request->GetUint64Value(Attributes::ATTR_SCHEDULE_ID, scheduleId); + IF_FALSE_LOGE_AND_RETURN_VAL(getScheduleIdRet, GENERAL_ERROR); + + auto it = scheduleId2executorStub_.find(scheduleId); + IF_FALSE_LOGE_AND_RETURN_VAL(it != scheduleId2executorStub_.end(), GENERAL_ERROR); + scheduleId2executorStub_.erase(it); + IAM_LOGI("success"); + return SUCCESS; +} + +RemoteAuthService &RemoteAuthService::GetInstance() +{ + RemoteAuthServiceImpl &impl = RemoteAuthServiceImpl::GetInstance(); + return impl; +} +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS diff --git a/services/core/src/remote_executor_proxy.cpp b/services/core/src/remote_executor_proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d872623801c9f8085b9b0c71438e45ac832ccae1 --- /dev/null +++ b/services/core/src/remote_executor_proxy.cpp @@ -0,0 +1,387 @@ +/* + * 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 "remote_executor_proxy.h" + +#include +#include + +#include "co_auth_client.h" +#include "iam_check.h" +#include "iam_logger.h" +#include "iam_ptr.h" +#include "thread_handler.h" + +#define LOG_TAG "USER_AUTH_SA" + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +class RemoteExecutorProxyCallback : public ExecutorRegisterCallback, public NoCopyable { +public: + explicit RemoteExecutorProxyCallback(std::weak_ptr callback) : callback_(callback) + { + } + ~RemoteExecutorProxyCallback() override = default; + + void OnMessengerReady(uint64_t executorIndex, const std::shared_ptr &messenger, + const std::vector &publicKey, const std::vector &templateIdList) override + { + std::lock_guard lock(mutex_); + auto callback = callback_.lock(); + IF_FALSE_LOGE_AND_RETURN(callback != nullptr); + callback->OnMessengerReady(executorIndex, messenger, publicKey, templateIdList); + } + + int32_t OnBeginExecute(uint64_t scheduleId, const std::vector &publicKey, + const Attributes &commandAttrs) override + { + std::lock_guard lock(mutex_); + auto callback = callback_.lock(); + IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, GENERAL_ERROR); + return callback->OnBeginExecute(scheduleId, publicKey, commandAttrs); + } + int32_t OnEndExecute(uint64_t scheduleId, const Attributes &commandAttrs) override + { + std::lock_guard lock(mutex_); + auto callback = callback_.lock(); + IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, GENERAL_ERROR); + return callback->OnEndExecute(scheduleId, commandAttrs); + } + + int32_t OnSetProperty(const Attributes &properties) override + { + IAM_LOGE("OnSetProperty is not supported"); + return GENERAL_ERROR; + } + + int32_t OnGetProperty(const Attributes &conditions, Attributes &results) override + { + IAM_LOGE("OnGetProperty is not supported"); + return GENERAL_ERROR; + } + + int32_t OnSendData(uint64_t scheduleId, const Attributes &data) override + { + std::lock_guard lock(mutex_); + auto callback = callback_.lock(); + IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, GENERAL_ERROR); + return callback->OnSendData(scheduleId, data); + } + +private: + std::recursive_mutex mutex_; + std::weak_ptr callback_; +}; + +class RemoteExecutorProxyMessageCallback : public ConnectionListener, public NoCopyable { +public: + explicit RemoteExecutorProxyMessageCallback(std::weak_ptr callback) + : callback_(callback), + threadHandler_(ThreadHandler::GetSingleThreadInstance()) + { + } + ~RemoteExecutorProxyMessageCallback() = default; + + void OnMessage(const std::string &connectionName, const std::string &srcEndPoint, + const std::shared_ptr &request, std::shared_ptr &reply) override + { + IF_FALSE_LOGE_AND_RETURN(request != nullptr); + IF_FALSE_LOGE_AND_RETURN(reply != nullptr); + + IAM_LOGI("connectionName: %{public}s, srcEndPoint: %{public}s", + RemoteMsgUtil::GetConnectionNameStr(connectionName).c_str(), srcEndPoint.c_str()); + + auto callback = callback_.lock(); + IF_FALSE_LOGE_AND_RETURN(callback != nullptr); + callback->OnMessage(connectionName, srcEndPoint, request, reply); + } + + void OnConnectStatus(const std::string &connectionName, ConnectStatus connectStatus) override + { + IAM_LOGI("connectionName: %{public}s, connectStatus %{public}d", + RemoteMsgUtil::GetConnectionNameStr(connectionName).c_str(), connectStatus); + + IF_FALSE_LOGE_AND_RETURN(connectStatus == ConnectStatus::DISCONNECT); + IF_FALSE_LOGE_AND_RETURN(threadHandler_ != nullptr); + + threadHandler_->PostTask([connectionName, connectStatus, callback = callback_, this]() { + IAM_LOGI("OnConnectStatus process begin"); + auto callbackLocked = callback_.lock(); + IF_FALSE_LOGE_AND_RETURN(callbackLocked != nullptr); + callbackLocked->OnConnectStatus(connectionName, connectStatus); + IAM_LOGI("OnConnectStatus process success"); + }); + + IAM_LOGI("task posted"); + } + +private: + std::weak_ptr callback_; + std::shared_ptr threadHandler_ = nullptr; +}; + +RemoteExecutorProxy::RemoteExecutorProxy(std::string connectionName, ExecutorInfo registerInfo) + : connectionName_(connectionName), + registerInfo_(registerInfo), + endPointName_(RemoteMsgUtil::GetExecutorProxyEndPointName()) +{ +} + +RemoteExecutorProxy::~RemoteExecutorProxy() +{ + IAM_LOGI("start"); + + RemoteConnectionManager::GetInstance().UnregisterConnectionListener(connectionName_, endPointName_); + CoAuthClient::GetInstance().Unregister(executorIndex_); + + IAM_LOGI("success"); +} + +ResultCode RemoteExecutorProxy::Start() +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + connectionCallback_ = Common::MakeShared(weak_from_this()); + IF_FALSE_LOGE_AND_RETURN_VAL(connectionCallback_ != nullptr, GENERAL_ERROR); + + ResultCode registerResult = RemoteConnectionManager::GetInstance().RegisterConnectionListener(connectionName_, + endPointName_, connectionCallback_); + IF_FALSE_LOGE_AND_RETURN_VAL(registerResult == SUCCESS, GENERAL_ERROR); + + executorCallback_ = Common::MakeShared(weak_from_this()); + IF_FALSE_LOGE_AND_RETURN_VAL(executorCallback_ != nullptr, GENERAL_ERROR); + + CoAuthClient::GetInstance().Register(registerInfo_, executorCallback_); + + IAM_LOGI("success"); + return ResultCode::SUCCESS; +} + +void RemoteExecutorProxy::OnMessage(const std::string &connectionName, const std::string &srcEndPoint, + const std::shared_ptr &request, std::shared_ptr &reply) +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + IF_FALSE_LOGE_AND_RETURN(connectionName_ == connectionName); + + int32_t msgType; + bool getMsgTypeRet = request->GetInt32Value(Attributes::ATTR_MSG_TYPE, msgType); + IF_FALSE_LOGE_AND_RETURN(getMsgTypeRet); + + int32_t resultCode = ResultCode::GENERAL_ERROR; + switch (msgType) { + case MessageType::EXECUTOR_SEND_DATA: + resultCode = ProcSendDataMsg(*request); + break; + case MessageType::EXECUTOR_FINISH: + resultCode = ProcFinishMsg(*request); + break; + default: + IAM_LOGE("unsupported message type: %{public}d", msgType); + break; + } + + IF_FALSE_LOGE_AND_RETURN(resultCode == ResultCode::SUCCESS); + bool setResultCodeRet = reply->SetInt32Value(Attributes::ATTR_RESULT_CODE, ResultCode::SUCCESS); + IF_FALSE_LOGE_AND_RETURN(setResultCodeRet); + + IAM_LOGI("success"); +} + +void RemoteExecutorProxy::OnConnectStatus(const std::string &connectionName, ConnectStatus connectStatus) +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + if (connectStatus == ConnectStatus::DISCONNECT) { + OnErrorFinish(); + } + + IAM_LOGI("success"); +} + +void RemoteExecutorProxy::OnMessengerReady(uint64_t executorIndex, const std::shared_ptr &messenger, + const std::vector &publicKey, const std::vector &templateIdList) +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + executorIndex_ = executorIndex; + messenger_ = messenger; + IAM_LOGI("success"); +} + +int32_t RemoteExecutorProxy::OnBeginExecute(uint64_t scheduleId, const std::vector &publicKey, + const Attributes &command) +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + std::shared_ptr request = Common::MakeShared(command.Serialize()); + IF_FALSE_LOGE_AND_RETURN_VAL(request != nullptr, GENERAL_ERROR); + + bool setMessageTypeRet = request->SetInt32Value(Attributes::ATTR_MSG_TYPE, MessageType::BEGIN_EXECUTE); + IF_FALSE_LOGE_AND_RETURN_VAL(setMessageTypeRet, GENERAL_ERROR); + + bool setScheduleIdRet = request->SetUint64Value(Attributes::ATTR_SCHEDULE_ID, scheduleId); + IF_FALSE_LOGE_AND_RETURN_VAL(setScheduleIdRet, GENERAL_ERROR); + + std::vector collectorMessage; + bool getCollectorMessageRet = request->GetUint8ArrayValue(Attributes::ATTR_EXTRA_INFO, collectorMessage); + IF_FALSE_LOGE_AND_RETURN_VAL(getCollectorMessageRet, GENERAL_ERROR); + + bool setScheduleDataRet = request->SetUint8ArrayValue(Attributes::ATTR_SCHEDULE_DATA, collectorMessage); + IF_FALSE_LOGE_AND_RETURN_VAL(setScheduleDataRet, GENERAL_ERROR); + + MsgCallback msgCallback = [self = weak_from_this()](const std::shared_ptr &reply) { + IF_FALSE_LOGE_AND_RETURN(reply != nullptr); + + auto sharedSelf = self.lock(); + IF_FALSE_LOGE_AND_RETURN(sharedSelf != nullptr); + int32_t resultCode; + bool getResultCodeRet = reply->GetInt32Value(Attributes::ATTR_RESULT_CODE, resultCode); + IF_FALSE_LOGE_AND_RETURN(getResultCodeRet); + if (resultCode != ResultCode::SUCCESS) { + IAM_LOGE("begin execute failed"); + sharedSelf->OnErrorFinish(); + } + }; + + ResultCode sendMsgRet = RemoteConnectionManager::GetInstance().SendMessage(connectionName_, endPointName_, + RemoteMsgUtil::GetRemoteServiceEndPointName(), request, msgCallback); + IF_FALSE_LOGE_AND_RETURN_VAL(sendMsgRet == ResultCode::SUCCESS, GENERAL_ERROR); + + IAM_LOGI("success"); + return ResultCode::SUCCESS; +} + +int32_t RemoteExecutorProxy::OnEndExecute(uint64_t scheduleId, const Attributes &command) +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + std::shared_ptr request = Common::MakeShared(command.Serialize()); + IF_FALSE_LOGE_AND_RETURN_VAL(request != nullptr, GENERAL_ERROR); + + bool setMessageTypeRet = request->SetInt32Value(Attributes::ATTR_MSG_TYPE, MessageType::END_EXECUTE); + IF_FALSE_LOGE_AND_RETURN_VAL(setMessageTypeRet, GENERAL_ERROR); + + bool setScheduleIdRet = request->SetUint64Value(Attributes::ATTR_SCHEDULE_ID, scheduleId); + IF_FALSE_LOGE_AND_RETURN_VAL(setScheduleIdRet, GENERAL_ERROR); + + MsgCallback msgCallback = [](const std::shared_ptr &) { IAM_LOGI("message sent"); }; + + ResultCode sendMsgRet = RemoteConnectionManager::GetInstance().SendMessage(connectionName_, endPointName_, + RemoteMsgUtil::GetRemoteServiceEndPointName(), request, msgCallback); + IF_FALSE_LOGE_AND_RETURN_VAL(sendMsgRet == ResultCode::SUCCESS, GENERAL_ERROR); + + IAM_LOGI("success"); + return ResultCode::SUCCESS; +} + +int32_t RemoteExecutorProxy::OnSendData(uint64_t scheduleId, const Attributes &data) +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + std::shared_ptr request = Common::MakeShared(data.Serialize()); + IF_FALSE_LOGE_AND_RETURN_VAL(request != nullptr, GENERAL_ERROR); + + bool setMessageTypeRet = request->SetInt32Value(Attributes::ATTR_MSG_TYPE, MessageType::SEND_DATA_TO_EXECUTOR); + IF_FALSE_LOGE_AND_RETURN_VAL(setMessageTypeRet, GENERAL_ERROR); + + bool setScheduleIdRet = request->SetUint64Value(Attributes::ATTR_SCHEDULE_ID, scheduleId); + IF_FALSE_LOGE_AND_RETURN_VAL(setScheduleIdRet, GENERAL_ERROR); + + MsgCallback msgCallback = [](const std::shared_ptr &) { IAM_LOGI("message sent"); }; + + ResultCode sendMsgRet = RemoteConnectionManager::GetInstance().SendMessage(connectionName_, endPointName_, + RemoteMsgUtil::GetExecutorStubEndPointName(), request, msgCallback); + IF_FALSE_LOGE_AND_RETURN_VAL(sendMsgRet == ResultCode::SUCCESS, GENERAL_ERROR); + + IAM_LOGI("success"); + return ResultCode::SUCCESS; +} + +int32_t RemoteExecutorProxy::ProcSendDataMsg(Attributes &data) +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + uint64_t scheduleId; + bool getScheduleIdRet = data.GetUint64Value(Attributes::ATTR_SCHEDULE_ID, scheduleId); + IF_FALSE_LOGE_AND_RETURN_VAL(getScheduleIdRet, GENERAL_ERROR); + scheduleId_ = scheduleId; + + int32_t dstRole; + bool getDstRoleRet = data.GetInt32Value(Attributes::ATTR_DEST_ROLE, dstRole); + IF_FALSE_LOGE_AND_RETURN_VAL(getDstRoleRet, GENERAL_ERROR); + + auto msg = AuthMessage::As(data.Serialize()); + IF_FALSE_LOGE_AND_RETURN_VAL(msg != nullptr, GENERAL_ERROR); + + IF_FALSE_LOGE_AND_RETURN_VAL(messenger_ != nullptr, GENERAL_ERROR); + int32_t ret = messenger_->SendData(scheduleId, static_cast(dstRole), msg); + IF_FALSE_LOGE_AND_RETURN_VAL(ret == SUCCESS, GENERAL_ERROR); + + IAM_LOGI("success"); + return ret; +} + +int32_t RemoteExecutorProxy::ProcFinishMsg(Attributes &data) +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + uint64_t scheduleId; + bool getScheduleIdRet = data.GetUint64Value(Attributes::ATTR_SCHEDULE_ID, scheduleId); + IF_FALSE_LOGE_AND_RETURN_VAL(getScheduleIdRet, GENERAL_ERROR); + scheduleId_ = scheduleId; + + int32_t resultCode; + bool getResultCodeRet = data.GetInt32Value(Attributes::ATTR_RESULT_CODE, resultCode); + IF_FALSE_LOGE_AND_RETURN_VAL(getResultCodeRet, GENERAL_ERROR); + + IF_FALSE_LOGE_AND_RETURN_VAL(messenger_ != nullptr, GENERAL_ERROR); + + IAM_LOGI("receive result code %{public}d", resultCode); + int32_t ret = messenger_->Finish(scheduleId, static_cast(resultCode), data); + IF_FALSE_LOGE_AND_RETURN_VAL(ret == SUCCESS, GENERAL_ERROR); + IAM_LOGI("success"); + return ret; +} + +void RemoteExecutorProxy::OnErrorFinish() +{ + IAM_LOGI("start"); + std::lock_guard lock(mutex_); + + Attributes request; + + bool setScheduleIdRet = request.SetUint64Value(Attributes::ATTR_SCHEDULE_ID, scheduleId_); + IF_FALSE_LOGE_AND_RETURN(setScheduleIdRet); + + bool setResultCodeRet = request.SetInt32Value(Attributes::ATTR_RESULT_CODE, ResultCode::GENERAL_ERROR); + IF_FALSE_LOGE_AND_RETURN(setResultCodeRet); + + ProcFinishMsg(request); + IAM_LOGI("success"); +} +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS \ No newline at end of file diff --git a/services/core/src/remote_executor_stub.cpp b/services/core/src/remote_executor_stub.cpp new file mode 100644 index 0000000000000000000000000000000000000000..76d86ccc267c4a1aa3330640cfdbc957da7c7a00 --- /dev/null +++ b/services/core/src/remote_executor_stub.cpp @@ -0,0 +1,362 @@ +/* + * 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 "remote_executor_stub.h" + +#include "iam_check.h" +#include "schedule_node.h" + +#include "context_pool.h" +#include "device_manager_util.h" +#include "hdi_wrapper.h" +#include "iam_logger.h" +#include "iam_ptr.h" +#include "remote_auth_service.h" +#include "remote_msg_util.h" +#include "resource_node_pool.h" +#include "thread_handler.h" + +#define LOG_TAG "USER_AUTH_SA" + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +class RemoteExecutorStubScheduleNode : public ScheduleNode, public NoCopyable { +public: + RemoteExecutorStubScheduleNode(HdiScheduleInfo &scheduleInfo, std::weak_ptr callback) + : scheduleId_(scheduleInfo.scheduleId), + callback_(callback) + { + } + ~RemoteExecutorStubScheduleNode() + { + IAM_LOGI("start"); + std::lock_guard lock(mutex_); + IAM_LOGI("success"); + } + + uint64_t GetScheduleId() const override + { + return scheduleId_; + } + + uint64_t GetContextId() const override + { + return 0; + } + + AuthType GetAuthType() const override + { + return AuthType::ALL; + } + + uint64_t GetExecutorMatcher() const override + { + return 0; + } + ScheduleMode GetScheduleMode() const override + { + return ScheduleMode::AUTH; + } + std::weak_ptr GetCollectorExecutor() const override + { + static std::weak_ptr nullNode; + return nullNode; + } + std::weak_ptr GetVerifyExecutor() const override + { + static std::weak_ptr nullNode; + return nullNode; + } + std::optional> GetTemplateIdList() const override + { + return std::nullopt; + } + State GetCurrentScheduleState() const override + { + return State::S_INIT; + } + std::shared_ptr GetScheduleCallback() override + { + return nullptr; + } + void ClearScheduleCallback() override + { + return; + } + bool StartSchedule() override + { + return true; + } + bool StopSchedule() override + { + return true; + } + bool SendMessage(ExecutorRole dstRole, const std::vector &msg) override + { + std::lock_guard lock(mutex_); + auto callback = callback_.lock(); + IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, GENERAL_ERROR); + int32_t ret = callback->OnMessage(dstRole, msg); + return ret == ResultCode::SUCCESS; + } + bool ContinueSchedule(ResultCode resultCode, const std::shared_ptr &finalResult) override + { + std::lock_guard lock(mutex_); + auto callback = callback_.lock(); + IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, GENERAL_ERROR); + int32_t ret = callback->ContinueSchedule(resultCode, finalResult); + return ret == ResultCode::SUCCESS; + } + +private: + std::recursive_mutex mutex_; + uint64_t scheduleId_; + std::weak_ptr callback_; +}; + +class RemoteExecutorStubMessageCallback : public ConnectionListener, public NoCopyable { +public: + explicit RemoteExecutorStubMessageCallback(uint64_t scheduleId, std::weak_ptr callback) + : scheduleId_(scheduleId), + callback_(callback), + threadHandler_(ThreadHandler::GetSingleThreadInstance()) + { + } + ~RemoteExecutorStubMessageCallback() = default; + + void OnMessage(const std::string &connectionName, const std::string &srcEndPoint, + const std::shared_ptr &request, std::shared_ptr &reply) override + { + IF_FALSE_LOGE_AND_RETURN(request != nullptr); + IF_FALSE_LOGE_AND_RETURN(reply != nullptr); + + IAM_LOGI("connectionName: %{public}s, srcEndPoint: %{public}s", + RemoteMsgUtil::GetConnectionNameStr(connectionName).c_str(), srcEndPoint.c_str()); + + auto callback = callback_.lock(); + IF_FALSE_LOGE_AND_RETURN(callback != nullptr); + callback->OnMessage(connectionName, srcEndPoint, request, reply); + } + + void OnConnectStatus(const std::string &connectionName, ConnectStatus connectStatus) override + { + IAM_LOGI("connectionName: %{public}s, connectStatus %{public}d", + RemoteMsgUtil::GetConnectionNameStr(connectionName).c_str(), connectStatus); + + IF_FALSE_LOGE_AND_RETURN(connectStatus == ConnectStatus::DISCONNECT); + + IF_FALSE_LOGE_AND_RETURN(threadHandler_ != nullptr); + + threadHandler_->PostTask([scheduleId = scheduleId_]() { + IAM_LOGI("OnConnectStatus process begin"); + auto request = Common::MakeShared(); + IF_FALSE_LOGE_AND_RETURN(request != nullptr); + bool setScheduleIdRet = request->SetUint64Value(Attributes::ATTR_SCHEDULE_ID, scheduleId); + IF_FALSE_LOGE_AND_RETURN(setScheduleIdRet); + + auto reply = Common::MakeShared(); + RemoteAuthService::GetInstance().ProcEndExecuteRequest(request, reply); + IAM_LOGI("OnConnectStatus process success"); + }); + + IAM_LOGI("task posted"); + } + +private: + uint64_t scheduleId_; + std::weak_ptr callback_; + std::shared_ptr threadHandler_ = nullptr; +}; + +RemoteExecutorStub::RemoteExecutorStub() : endPointName_(RemoteMsgUtil::GetExecutorStubEndPointName()) +{ +} + +RemoteExecutorStub::~RemoteExecutorStub() +{ + std::lock_guard lock(mutex_); + if (connectionCallback_ != nullptr) { + RemoteConnectionManager::GetInstance().UnregisterConnectionListener(connectionName_, endPointName_); + } + if (remoteScheduleNode_ != nullptr) { + ContextPool::Instance().RemoveRemoteScheduleNode(remoteScheduleNode_); + remoteScheduleNode_ = nullptr; + } +} + +int32_t RemoteExecutorStub::ProcBeginExecuteRequest(Attributes &attr) +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + uint64_t scheduleId; + bool getScheduleIdRet = attr.GetUint64Value(Attributes::ATTR_SCHEDULE_ID, scheduleId); + IF_FALSE_LOGE_AND_RETURN_VAL(getScheduleIdRet, GENERAL_ERROR); + + connectionCallback_ = Common::MakeShared(scheduleId, shared_from_this()); + IF_FALSE_LOGE_AND_RETURN_VAL(connectionCallback_ != nullptr, GENERAL_ERROR); + + bool getConnectionName = attr.GetStringValue(Attributes::ATTR_CONNECTION_NAME, connectionName_); + IF_FALSE_LOGE_AND_RETURN_VAL(getConnectionName, GENERAL_ERROR); + + ResultCode registerResult = RemoteConnectionManager::GetInstance().RegisterConnectionListener(connectionName_, + endPointName_, connectionCallback_); + IF_FALSE_LOGE_AND_RETURN_VAL(registerResult == SUCCESS, GENERAL_ERROR); + + std::string srcUdid; + bool getSrcUdidRet = attr.GetStringValue(Attributes::ATTR_MSG_SRC_UDID, srcUdid); + IF_FALSE_LOGE_AND_RETURN_VAL(getSrcUdidRet, GENERAL_ERROR); + + std::vector scheduleData; + bool getScheduleDataRet = attr.GetUint8ArrayValue(Attributes::ATTR_SCHEDULE_DATA, scheduleData); + IF_FALSE_LOGE_AND_RETURN_VAL(getScheduleDataRet, GENERAL_ERROR); + + HdiScheduleInfo scheduleInfo; + auto hdi = HdiWrapper::GetHdiInstance(); + IF_FALSE_LOGE_AND_RETURN_VAL(hdi != nullptr, GENERAL_ERROR); + + int32_t ret = hdi->GetLocalScheduleFromMessage(srcUdid, scheduleData, scheduleInfo); + IF_FALSE_LOGE_AND_RETURN_VAL(ret == SUCCESS, GENERAL_ERROR); + IF_FALSE_LOGE_AND_RETURN_VAL(scheduleInfo.executorIndexes.size() == 1, GENERAL_ERROR); + IF_FALSE_LOGE_AND_RETURN_VAL(scheduleInfo.executorMessages.size() == 1, GENERAL_ERROR); + + remoteScheduleNode_ = Common::MakeShared(scheduleInfo, weak_from_this()); + IF_FALSE_LOGE_AND_RETURN_VAL(remoteScheduleNode_ != nullptr, GENERAL_ERROR); + + ContextPool::Instance().InsertRemoteScheduleNode(remoteScheduleNode_); + + bool setExtraInfo = attr.SetUint8ArrayValue(Attributes::ATTR_EXTRA_INFO, scheduleInfo.executorMessages[0]); + IF_FALSE_LOGE_AND_RETURN_VAL(setExtraInfo, GENERAL_ERROR); + + executorIndex_ = scheduleInfo.executorIndexes[0]; + std::weak_ptr weakNode = ResourceNodePool::Instance().Select(executorIndex_); + std::shared_ptr node = weakNode.lock(); + IF_FALSE_LOGE_AND_RETURN_VAL(node != nullptr, GENERAL_ERROR); + + std::vector publicKey; + node->BeginExecute(scheduleInfo.scheduleId, publicKey, attr); + + IAM_LOGI("success"); + return ResultCode::SUCCESS; +} + +void RemoteExecutorStub::OnMessage(const std::string &connectionName, const std::string &srcEndPoint, + const std::shared_ptr &request, std::shared_ptr &reply) +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + int32_t msgType; + bool getMsgTypeRet = request->GetInt32Value(Attributes::ATTR_MSG_TYPE, msgType); + IF_FALSE_LOGE_AND_RETURN(getMsgTypeRet); + + int32_t resultCode = ResultCode::GENERAL_ERROR; + switch (msgType) { + case MessageType::SEND_DATA_TO_EXECUTOR: + resultCode = ProcSendDataMsg(*request); + break; + default: + IAM_LOGE("unsupported message type: %{public}d", msgType); + break; + } + + IF_FALSE_LOGE_AND_RETURN(resultCode == ResultCode::SUCCESS); + bool setResultCodeRet = reply->SetInt32Value(Attributes::ATTR_RESULT_CODE, ResultCode::SUCCESS); + IF_FALSE_LOGE_AND_RETURN(setResultCodeRet); + + IAM_LOGI("success"); +} + +int32_t RemoteExecutorStub::OnMessage(ExecutorRole dstRole, const std::vector &msg) +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + std::shared_ptr request = Common::MakeShared(msg); + IF_FALSE_LOGE_AND_RETURN_VAL(request != nullptr, GENERAL_ERROR); + + bool setMsgTypeRet = request->SetInt32Value(Attributes::ATTR_MSG_TYPE, MessageType::EXECUTOR_SEND_DATA); + IF_FALSE_LOGE_AND_RETURN_VAL(setMsgTypeRet, GENERAL_ERROR); + + bool setScheduleIdRet = request->SetUint64Value(Attributes::ATTR_SCHEDULE_ID, remoteScheduleNode_->GetScheduleId()); + IF_FALSE_LOGE_AND_RETURN_VAL(setScheduleIdRet, GENERAL_ERROR); + + bool setDestRoleRet = request->SetInt32Value(Attributes::ATTR_DEST_ROLE, dstRole); + IF_FALSE_LOGE_AND_RETURN_VAL(setDestRoleRet, GENERAL_ERROR); + + MsgCallback msgCallback = [](const std::shared_ptr &) { IAM_LOGI("message sent"); }; + + ResultCode sendMsgRet = RemoteConnectionManager::GetInstance().SendMessage(connectionName_, endPointName_, + RemoteMsgUtil::GetExecutorProxyEndPointName(), request, msgCallback); + IF_FALSE_LOGE_AND_RETURN_VAL(sendMsgRet == ResultCode::SUCCESS, GENERAL_ERROR); + + IAM_LOGI("success"); + return SUCCESS; +} + +int32_t RemoteExecutorStub::ContinueSchedule(ResultCode resultCode, const std::shared_ptr &finalResult) +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + IF_FALSE_LOGE_AND_RETURN_VAL(finalResult != nullptr, GENERAL_ERROR); + IF_FALSE_LOGE_AND_RETURN_VAL(remoteScheduleNode_ != nullptr, GENERAL_ERROR); + + std::shared_ptr request = Common::MakeShared(finalResult->Serialize()); + IF_FALSE_LOGE_AND_RETURN_VAL(request != nullptr, GENERAL_ERROR); + + bool setMsgTypeRet = request->SetInt32Value(Attributes::ATTR_MSG_TYPE, MessageType::EXECUTOR_FINISH); + IF_FALSE_LOGE_AND_RETURN_VAL(setMsgTypeRet, GENERAL_ERROR); + + bool setScheduleIdRet = request->SetUint64Value(Attributes::ATTR_SCHEDULE_ID, remoteScheduleNode_->GetScheduleId()); + IF_FALSE_LOGE_AND_RETURN_VAL(setScheduleIdRet, GENERAL_ERROR); + + bool setResultCodeRet = request->SetInt32Value(Attributes::ATTR_RESULT_CODE, resultCode); + IF_FALSE_LOGE_AND_RETURN_VAL(setResultCodeRet, GENERAL_ERROR); + + MsgCallback msgCallback = [](const std::shared_ptr &) { IAM_LOGI("message sent"); }; + + ResultCode sendMsgRet = RemoteConnectionManager::GetInstance().SendMessage(connectionName_, endPointName_, + RemoteMsgUtil::GetExecutorProxyEndPointName(), request, msgCallback); + IF_FALSE_LOGE_AND_RETURN_VAL(sendMsgRet == ResultCode::SUCCESS, GENERAL_ERROR); + + IAM_LOGI("success"); + return SUCCESS; +} + +int32_t RemoteExecutorStub::ProcSendDataMsg(Attributes &attr) +{ + std::lock_guard lock(mutex_); + IAM_LOGI("start"); + + uint64_t scheduleId; + bool getScheduleIdRet = attr.GetUint64Value(Attributes::ATTR_SCHEDULE_ID, scheduleId); + IF_FALSE_LOGE_AND_RETURN_VAL(getScheduleIdRet, GENERAL_ERROR); + + std::weak_ptr weakNode = ResourceNodePool::Instance().Select(executorIndex_); + std::shared_ptr node = weakNode.lock(); + IF_FALSE_LOGE_AND_RETURN_VAL(node != nullptr, GENERAL_ERROR); + + int32_t ret = node->SendData(scheduleId, attr); + IF_FALSE_LOGE_AND_RETURN_VAL(ret == ResultCode::SUCCESS, GENERAL_ERROR); + + IAM_LOGI("success"); + return ret; +} + +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS \ No newline at end of file diff --git a/services/core/src/remote_msg_util.cpp b/services/core/src/remote_msg_util.cpp new file mode 100644 index 0000000000000000000000000000000000000000..37dd30e77bdf885cb0124742afbc7b5dae987296 --- /dev/null +++ b/services/core/src/remote_msg_util.cpp @@ -0,0 +1,294 @@ +/* + * 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 "remote_msg_util.h" + +#include +#include +#include + +#include "device_manager.h" + +#include "device_manager_util.h" +#include "hdi_wrapper.h" +#include "iam_check.h" +#include "iam_logger.h" +#include "parameter.h" +#include "resource_node_pool.h" + +#define LOG_TAG "USER_AUTH_SA" + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +bool RemoteMsgUtil::GetConnectionName(uint64_t contextId, std::string &connectionName) +{ + std::string udid; + bool getLocalUdidRet = DeviceManagerUtil::GetInstance().GetLocalDeviceUdid(udid); + IF_FALSE_LOGE_AND_RETURN_VAL(getLocalUdidRet, false); + + std::ostringstream oss; + oss << udid << "_Context_" << contextId; + connectionName = oss.str(); + return true; +} + +std::string RemoteMsgUtil::GetConnectionNameStr(const std::string &connectionName) +{ + static const std::string key = "ContextId"; + size_t pos = connectionName.find(key); + if (pos == std::string::npos) { + return "invalid"; + } + return connectionName.substr(pos); +} + +std::string RemoteMsgUtil::GetExecutorProxyEndPointName() +{ + return "RemoteExecutorProxy"; +} + +std::string RemoteMsgUtil::GetExecutorStubEndPointName() +{ + return "RemoteExecutorStub"; +} + +std::string RemoteMsgUtil::GetRemoteServiceEndPointName() +{ + return "RemoteService"; +} + +std::string RemoteMsgUtil::GetRemoteCallbackEndPointName() +{ + return "RemoteCallback"; +} + +std::string RemoteMsgUtil::GetRemoteAuthContextEndPointName() +{ + return "RemoteAuthContext"; +} + +std::string RemoteMsgUtil::GetRemoteAuthInvokerContextEndPointName() +{ + return "RemoteAuthInvokerContext"; +} + +bool RemoteMsgUtil::EncodeQueryExecutorInfoReply(const std::vector &executorInfoArray, + const std::vector &signedRemoteExecutorInfo, Attributes &attr) +{ + IF_FALSE_LOGE_AND_RETURN_VAL(executorInfoArray.size() != 0, false); + + bool setRemoteExecutorInfoRet = + attr.SetUint8ArrayValue(Attributes::ATTR_REMOTE_EXECUTOR_INFO, signedRemoteExecutorInfo); + IF_FALSE_LOGE_AND_RETURN_VAL(setRemoteExecutorInfoRet, false); + + return SetExecutorInfoArrayToAttributes(executorInfoArray, attr); +} + +bool RemoteMsgUtil::DecodeQueryExecutorInfoReply(const Attributes &attr, std::vector &executorInfoArray) +{ + std::vector signedRemoteExecutorInfo; + bool getRemoteExecutorInfoRet = + attr.GetUint8ArrayValue(Attributes::ATTR_REMOTE_EXECUTOR_INFO, signedRemoteExecutorInfo); + IF_FALSE_LOGE_AND_RETURN_VAL(getRemoteExecutorInfoRet, false); + + return GetExecutorInfoArrayFromAttributes(attr, signedRemoteExecutorInfo, executorInfoArray); +} + +bool RemoteMsgUtil::SetExecutorInfoToAttributes(const ExecutorInfo &executorInfo, Attributes &attr) +{ + bool setAuthTypeRet = attr.SetInt32Value(Attributes::ATTR_AUTH_TYPE, executorInfo.authType); + IF_FALSE_LOGE_AND_RETURN_VAL(setAuthTypeRet, false); + + bool setExecutorRoleRet = attr.SetInt32Value(Attributes::ATTR_EXECUTOR_ROLE, executorInfo.executorRole); + IF_FALSE_LOGE_AND_RETURN_VAL(setExecutorRoleRet, false); + + bool setExecutorSensorHintRet = + attr.SetUint32Value(Attributes::ATTR_EXECUTOR_SENSOR_HINT, executorInfo.executorSensorHint); + IF_FALSE_LOGE_AND_RETURN_VAL(setExecutorSensorHintRet, false); + + bool setExecutorMatcherRet = attr.SetUint32Value(Attributes::ATTR_EXECUTOR_MATCHER, executorInfo.executorMatcher); + IF_FALSE_LOGE_AND_RETURN_VAL(setExecutorMatcherRet, false); + + bool setEslRet = attr.SetInt32Value(Attributes::ATTR_ESL, executorInfo.esl); + IF_FALSE_LOGE_AND_RETURN_VAL(setEslRet, false); + + bool setPublicKeyRet = attr.SetUint8ArrayValue(Attributes::ATTR_PUBLIC_KEY, executorInfo.publicKey); + IF_FALSE_LOGE_AND_RETURN_VAL(setPublicKeyRet, false); + + bool setDeviceUdidRet = attr.SetStringValue(Attributes::ATTR_DEVICE_UDID, executorInfo.deviceUdid); + IF_FALSE_LOGE_AND_RETURN_VAL(setDeviceUdidRet, false); + + return true; +} + +bool RemoteMsgUtil::GetExecutorInfoFromAttributes(const Attributes &Attr, + std::vector &signedRemoteExecutorInfo, ExecutorInfo &executorInfo) +{ + int32_t authType = 0; + bool getAuthTypeRet = Attr.GetInt32Value(Attributes::ATTR_AUTH_TYPE, authType); + IF_FALSE_LOGE_AND_RETURN_VAL(getAuthTypeRet, false); + executorInfo.authType = static_cast(authType); + + int32_t executorRole = 0; + bool getExecutorRoleRet = Attr.GetInt32Value(Attributes::ATTR_EXECUTOR_ROLE, executorRole); + IF_FALSE_LOGE_AND_RETURN_VAL(getExecutorRoleRet, false); + executorInfo.executorRole = static_cast(executorRole); + + bool getExecutorSensorHintRet = + Attr.GetUint32Value(Attributes::ATTR_EXECUTOR_SENSOR_HINT, executorInfo.executorSensorHint); + IF_FALSE_LOGE_AND_RETURN_VAL(getExecutorSensorHintRet, false); + + bool getExecutorMatcherRet = Attr.GetUint32Value(Attributes::ATTR_EXECUTOR_MATCHER, executorInfo.executorMatcher); + IF_FALSE_LOGE_AND_RETURN_VAL(getExecutorMatcherRet, false); + + int32_t esl = 0; + bool getEslRet = Attr.GetInt32Value(Attributes::ATTR_ESL, esl); + IF_FALSE_LOGE_AND_RETURN_VAL(getEslRet, false); + executorInfo.esl = static_cast(esl); + + bool getPublicKeyRet = Attr.GetUint8ArrayValue(Attributes::ATTR_PUBLIC_KEY, executorInfo.publicKey); + IF_FALSE_LOGE_AND_RETURN_VAL(getPublicKeyRet, false); + + bool getDeviceUdidRet = Attr.GetStringValue(Attributes::ATTR_DEVICE_UDID, executorInfo.deviceUdid); + IF_FALSE_LOGE_AND_RETURN_VAL(getDeviceUdidRet, false); + + executorInfo.signedRemoteExecutorInfo = signedRemoteExecutorInfo; + return true; +} + +bool RemoteMsgUtil::SetExecutorInfoArrayToAttributes(const std::vector &executorInfoArray, + Attributes &attr) +{ + std::vector attributeArray; + for (auto &executorInfo : executorInfoArray) { + Attributes item; + if (!SetExecutorInfoToAttributes(executorInfo, item)) { + IAM_LOGE("SetExecutorInfoToAttributes failed"); + return false; + } + attributeArray.push_back(Attributes(item.Serialize())); + } + + bool setAttributeArrayRet = + attr.SetAttributesArrayValue(Attributes::ATTR_EXECUTOR_REGISTER_INFO_LIST, attributeArray); + IF_FALSE_LOGE_AND_RETURN_VAL(setAttributeArrayRet, false); + + return true; +} + +bool RemoteMsgUtil::GetExecutorInfoArrayFromAttributes(const Attributes &attr, + std::vector &signedRemoteExecutorInfo, std::vector &executorInfoArray) +{ + std::vector attributeArray; + bool getExecutorInfoRet = + attr.GetAttributesArrayValue(Attributes::ATTR_EXECUTOR_REGISTER_INFO_LIST, attributeArray); + IF_FALSE_LOGE_AND_RETURN_VAL(getExecutorInfoRet, false); + + for (auto &item : attributeArray) { + ExecutorInfo executorInfo; + if (!GetExecutorInfoFromAttributes(item, signedRemoteExecutorInfo, executorInfo)) { + IAM_LOGE("GetExecutorInfoFromAttributes failed"); + return false; + } + executorInfoArray.push_back(executorInfo); + } + + return true; +} + +bool RemoteMsgUtil::GetQueryExecutorInfoReply(const std::vector authTypes, int32_t executorRole, + std::string remoteUdid, Attributes &attr) +{ + auto hdi = HdiWrapper::GetHdiInstance(); + IF_FALSE_LOGE_AND_RETURN_VAL(hdi != nullptr, GENERAL_ERROR); + IF_FALSE_LOGE_AND_RETURN_VAL(authTypes.size() == 1, GENERAL_ERROR); + + std::vector signedExecutorInfo; + int32_t hdiRet = hdi->GetSignedExecutorInfo(authTypes, executorRole, remoteUdid, signedExecutorInfo); + IF_FALSE_LOGE_AND_RETURN_VAL(hdiRet == SUCCESS, GENERAL_ERROR); + + std::string localUdid; + bool getLocalUdidRet = DeviceManagerUtil::GetInstance().GetLocalDeviceUdid(localUdid); + IF_FALSE_LOGE_AND_RETURN_VAL(getLocalUdidRet, GENERAL_ERROR); + + std::vector executorInfoArray; + ResourceNodePool::Instance().Enumerate([&](const std::weak_ptr &weakNode) { + std::shared_ptr node = weakNode.lock(); + IF_FALSE_LOGE_AND_RETURN(node != nullptr); + + if (node->GetAuthType() != authTypes[0] || node->GetExecutorRole() != executorRole || + localUdid != node->GetExecutorDeviceUdid()) { + return; + } + + ExecutorInfo executorInfo; + executorInfo.authType = node->GetAuthType(); + executorInfo.executorRole = node->GetExecutorRole(); + executorInfo.executorSensorHint = node->GetExecutorSensorHint(); + executorInfo.executorMatcher = node->GetExecutorMatcher(); + executorInfo.esl = node->GetExecutorEsl(); + executorInfo.publicKey = node->GetExecutorPublicKey(); + executorInfo.deviceUdid = node->GetExecutorDeviceUdid(); + executorInfoArray.push_back(executorInfo); + }); + + bool encodeQueryExecutorInfoReplyRet = + RemoteMsgUtil::EncodeQueryExecutorInfoReply(executorInfoArray, signedExecutorInfo, attr); + IF_FALSE_LOGE_AND_RETURN_VAL(encodeQueryExecutorInfoReplyRet, GENERAL_ERROR); + + IAM_LOGI("success"); + return true; +} + +bool RemoteMsgUtil::EncodeAuthParam(const AuthParamInner &authParam, Attributes &attr) +{ + bool setUserIdRet = attr.SetInt32Value(Attributes::ATTR_USER_ID, authParam.userId); + IF_FALSE_LOGE_AND_RETURN_VAL(setUserIdRet, false); + + bool setChallengeRet = attr.SetUint8ArrayValue(Attributes::ATTR_CHALLENGE, authParam.challenge); + IF_FALSE_LOGE_AND_RETURN_VAL(setChallengeRet, false); + + bool setAuthTypeRet = attr.SetInt32Value(Attributes::ATTR_AUTH_TYPE, authParam.authType); + IF_FALSE_LOGE_AND_RETURN_VAL(setAuthTypeRet, false); + + bool setAuthTrustLevelRet = attr.SetInt32Value(Attributes::ATTR_AUTH_TRUST_LEVEL, authParam.authTrustLevel); + IF_FALSE_LOGE_AND_RETURN_VAL(setAuthTrustLevelRet, false); + return true; +} + +bool RemoteMsgUtil::DecodeAuthParam(const Attributes &attr, AuthParamInner &authParam) +{ + bool getUserIdRet = attr.GetInt32Value(Attributes::ATTR_USER_ID, authParam.userId); + IF_FALSE_LOGE_AND_RETURN_VAL(getUserIdRet, false); + + bool getChallengeRet = attr.GetUint8ArrayValue(Attributes::ATTR_CHALLENGE, authParam.challenge); + IF_FALSE_LOGE_AND_RETURN_VAL(getChallengeRet, false); + + int32_t authType; + bool getAuthTypeRet = attr.GetInt32Value(Attributes::ATTR_AUTH_TYPE, authType); + IF_FALSE_LOGE_AND_RETURN_VAL(getAuthTypeRet, false); + authParam.authType = static_cast(authType); + + int32_t authTrustLevel; + bool getAuthTrustLevelRet = attr.GetInt32Value(Attributes::ATTR_AUTH_TRUST_LEVEL, authTrustLevel); + IF_FALSE_LOGE_AND_RETURN_VAL(getAuthTrustLevelRet, false); + authParam.authTrustLevel = static_cast(authTrustLevel); + + return true; +} +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS \ No newline at end of file diff --git a/services/core/src/resource_node_impl.cpp b/services/core/src/resource_node_impl.cpp index 7e016fb2fdf0c4215bb8a28bea2b8fdccbea12f2..70f5de2a5523646c2f8b8d03a17d7675d8df398c 100644 --- a/services/core/src/resource_node_impl.cpp +++ b/services/core/src/resource_node_impl.cpp @@ -19,10 +19,13 @@ #include #include +#include "device_manager_util.h" #include "hdi_wrapper.h" +#include "iam_check.h" #include "iam_common_defines.h" #include "iam_logger.h" #include "iam_ptr.h" +#include "remote_msg_util.h" #define LOG_TAG "USER_AUTH_SA" @@ -43,6 +46,7 @@ public: uint64_t GetExecutorMatcher() const override; ExecutorSecureLevel GetExecutorEsl() const override; std::vector GetExecutorPublicKey() const override; + std::string GetExecutorDeviceUdid() const override; int32_t BeginExecute(uint64_t scheduleId, const std::vector &publicKey, const Attributes &command) override; @@ -66,6 +70,10 @@ ResourceNodeImpl::ResourceNodeImpl(ExecutorRegisterInfo info, std::shared_ptr ResourceNodeImpl::GetExecutorPublicKey() const return info_.publicKey; } +std::string ResourceNodeImpl::GetExecutorDeviceUdid() const +{ + return info_.deviceUdid; +} + int32_t ResourceNodeImpl::BeginExecute(uint64_t scheduleId, const std::vector &publicKey, const Attributes &command) { @@ -194,6 +207,8 @@ int32_t ResourceNodeImpl::SyncWithDriver(std::vector &templateIdList, .executorMatcher = info_.executorMatcher, .esl = static_cast(info_.esl), .publicKey = info_.publicKey, + .deviceUdid = info_.deviceUdid, + .signedRemoteExecutorInfo = info_.signedRemoteExecutorInfo, }; auto hdi = HdiWrapper::GetHdiInstance(); diff --git a/services/core/src/schedule_node_builder.cpp b/services/core/src/schedule_node_builder.cpp index 2bfdf4137dab5b8e6ba27e0c9819704b106e9e0d..c873aca721ee1f79437018da17a7dc1abcf5120b 100644 --- a/services/core/src/schedule_node_builder.cpp +++ b/services/core/src/schedule_node_builder.cpp @@ -52,6 +52,12 @@ std::shared_ptr ScheduleNodeBuilder::SetAccessTokenId(uint32_t tokenId) return shared_from_this(); } +std::shared_ptr ScheduleNodeBuilder::SetCollectorTokenId(uint32_t collectorTokenId) +{ + info_.collectorTokenId = collectorTokenId; + return shared_from_this(); +} + std::shared_ptr ScheduleNodeBuilder::SetPinSubType(PinSubType pinSubType) { info_.pinSubType = pinSubType; @@ -94,12 +100,6 @@ std::shared_ptr ScheduleNodeBuilder::SetExpiredTime(uint32_t ms) return shared_from_this(); } -std::shared_ptr ScheduleNodeBuilder::SetParametersAttributes(const std::shared_ptr ¶meters) -{ - info_.parameters = parameters; - return shared_from_this(); -} - std::shared_ptr ScheduleNodeBuilder::SetThreadHandler(const std::shared_ptr &threadHandler) { info_.threadHandler = threadHandler; diff --git a/services/core/src/schedule_node_builder.h b/services/core/src/schedule_node_builder.h index 8f75bab46567190d8e025fdeceb20ef4a00765e8..04b9d1e36a90d1930794584cb5fcb35e13b3e167 100644 --- a/services/core/src/schedule_node_builder.h +++ b/services/core/src/schedule_node_builder.h @@ -33,6 +33,7 @@ public: ~ScheduleNodeBuilder() override = default; std::shared_ptr SetScheduleId(uint64_t scheduleId) override; std::shared_ptr SetAccessTokenId(uint32_t tokenId) override; + std::shared_ptr SetCollectorTokenId(uint32_t collectorTokenId) override; std::shared_ptr SetPinSubType(PinSubType pinSubType) override; std::shared_ptr SetTemplateIdList(const std::vector &templateIdList) override; std::shared_ptr SetAuthType(AuthType authType) override; @@ -40,7 +41,6 @@ public: std::shared_ptr SetScheduleMode(ScheduleMode scheduleMode) override; std::shared_ptr SetScheduleCallback(const std::shared_ptr &callback) override; std::shared_ptr SetExpiredTime(uint32_t ms) override; - std::shared_ptr SetParametersAttributes(const std::shared_ptr ¶meters) override; std::shared_ptr SetThreadHandler(const std::shared_ptr &threadHandler) override; std::shared_ptr SetEndAfterFirstFail(const bool endAfterFirstFail) override; std::shared_ptr SetVerifierMessage(const std::vector &message) override; diff --git a/services/core/src/schedule_node_helper.cpp b/services/core/src/schedule_node_helper.cpp index 3599d75080929ad5210c813873e06cba606def28..84f958bbbbdd3eb0ec193ceb326e8a243851d7c9 100644 --- a/services/core/src/schedule_node_helper.cpp +++ b/services/core/src/schedule_node_helper.cpp @@ -59,6 +59,7 @@ bool ScheduleNodeHelper::ScheduleInfoToScheduleNode(const HdiScheduleInfo &info, } std::shared_ptr collector; std::shared_ptr verifier; + std::vector collectorMessage; std::vector verifierMessage; if (!ScheduleInfoToExecutors(info, collector, verifier, collectorMessage, verifierMessage)) { @@ -66,11 +67,15 @@ bool ScheduleNodeHelper::ScheduleInfoToScheduleNode(const HdiScheduleInfo &info, return false; } + IAM_LOGI("collectorMessage size: %{public}zu, verifierMessage size %{public}zu", + collectorMessage.size(), verifierMessage.size()); + auto builder = ScheduleNode::Builder::New(collector, verifier); if (builder == nullptr) { IAM_LOGE("invalid builder"); return false; } + if (para.tokenId.has_value()) { builder->SetAccessTokenId(para.tokenId.value()); } @@ -84,6 +89,7 @@ bool ScheduleNodeHelper::ScheduleInfoToScheduleNode(const HdiScheduleInfo &info, ->SetPinSubType(para.pinSubType.value_or(PinSubType::PIN_MAX)) ->SetScheduleCallback(callback) ->SetEndAfterFirstFail(para.endAfterFirstFail.value_or(false)) + ->SetCollectorTokenId(para.collectorTokenId) ->SetCollectorMessage(collectorMessage) ->SetVerifierMessage(verifierMessage) ->Build(); diff --git a/services/core/src/schedule_node_impl.cpp b/services/core/src/schedule_node_impl.cpp index ae6652b5bee7707bccec44f806ebf808b0d358c5..30ddaff5c611f63adbe9777542ec7e17bf5b1312 100644 --- a/services/core/src/schedule_node_impl.cpp +++ b/services/core/src/schedule_node_impl.cpp @@ -19,6 +19,7 @@ #include "nocopyable.h" +#include "attributes.h" #include "hdi_wrapper.h" #include "iam_check.h" #include "iam_logger.h" @@ -39,38 +40,36 @@ ScheduleNodeImpl::ScheduleNodeImpl(ScheduleInfo &info) : info_(std::move(info)) info_.threadHandler = ThreadHandler::GetSingleThreadInstance(); machine_->SetThreadHandler(info_.threadHandler); } - if (info_.parameters == nullptr) { - info_.parameters = Common::MakeShared(); - } - - if (info_.parameters == nullptr) { - return; - } +} - info_.parameters->SetInt32Value(Attributes::ATTR_SCHEDULE_MODE, info_.scheduleMode); +void ScheduleNodeImpl::GetScheduleAttribute(bool isVerifier, Attributes &attribute) const +{ + attribute.SetInt32Value(Attributes::ATTR_SCHEDULE_MODE, info_.scheduleMode); if (info_.tokenId.has_value()) { - info_.parameters->SetUint32Value(Attributes::ATTR_ACCESS_TOKEN_ID, info_.tokenId.value()); + attribute.SetUint32Value(Attributes::ATTR_ACCESS_TOKEN_ID, info_.tokenId.value()); } if (info_.pinSubType != 0) { - info_.parameters->SetInt32Value(Attributes::ATTR_PIN_SUB_TYPE, info_.pinSubType); + attribute.SetInt32Value(Attributes::ATTR_PIN_SUB_TYPE, info_.pinSubType); } - info_.parameters->SetBoolValue(Attributes::ATTR_END_AFTER_FIRST_FAIL, info_.endAfterFirstFail); - - info_.parameters->SetUint8ArrayValue(Attributes::ATTR_VERIFIER_MESSAGE, info_.verifierMessage); - info_.parameters->SetUint8ArrayValue(Attributes::ATTR_COLLECTOR_MESSAGE, info_.collectorMessage); - IAM_LOGI("verifer message length = %{public}zu, collector message length = %{public}zu", + attribute.SetUint32Value(Attributes::ATTR_COLLECTOR_TOKEN_ID, info_.collectorTokenId); + attribute.SetBoolValue(Attributes::ATTR_END_AFTER_FIRST_FAIL, info_.endAfterFirstFail); + IAM_LOGI("verifier message length = %{public}zu, collector message length = %{public}zu", info_.verifierMessage.size(), info_.collectorMessage.size()); - if (info_.templateIdList.empty()) { - return; + if (isVerifier) { + attribute.SetUint8ArrayValue(Attributes::ATTR_EXTRA_INFO, info_.verifierMessage); + } else { + attribute.SetUint8ArrayValue(Attributes::ATTR_EXTRA_INFO, info_.collectorMessage); } - info_.parameters->SetUint64ArrayValue(Attributes::ATTR_TEMPLATE_ID_LIST, info_.templateIdList); - if (info_.templateIdList.size() == 1) { - info_.parameters->SetUint64Value(Attributes::ATTR_TEMPLATE_ID, *info_.templateIdList.begin()); + if (!info_.templateIdList.empty()) { + attribute.SetUint64ArrayValue(Attributes::ATTR_TEMPLATE_ID_LIST, info_.templateIdList); + if (info_.templateIdList.size() == 1) { + attribute.SetUint64Value(Attributes::ATTR_TEMPLATE_ID, *info_.templateIdList.begin()); + } } } @@ -333,8 +332,9 @@ void ScheduleNodeImpl::ProcessBeginVerifier(FiniteStateMachine &machine, uint32_ return; } auto peerPk = collector->GetExecutorPublicKey(); - - auto result = verifier->BeginExecute(info_.scheduleId, peerPk, *info_.parameters); + Attributes attr; + GetScheduleAttribute(true, attr); + auto result = verifier->BeginExecute(info_.scheduleId, peerPk, attr); if (result != SUCCESS) { IAM_LOGE("start verify failed, result = %{public}d", result); SetExecutorResultCode(result); @@ -360,7 +360,39 @@ void ScheduleNodeImpl::ProcessBeginCollector(FiniteStateMachine &machine, uint32 machine.Schedule(E_COLLECT_STARTED_SUCCESS); return; } - IAM_LOGE("distributed auth not supported yet"); + + auto peerPk = collector->GetExecutorPublicKey(); + Attributes attr; + GetScheduleAttribute(false, attr); + auto result = collector->BeginExecute(info_.scheduleId, peerPk, attr); + if (result != SUCCESS) { + IAM_LOGE("start collect failed, result = %{public}d", result); + SetExecutorResultCode(result); + machine.Schedule(E_COLLECT_STARTED_FAILED); + return; + } + IAM_LOGI("start collect success"); + machine.Schedule(E_COLLECT_STARTED_SUCCESS); + NotifyCollectorReady(); +} + +void ScheduleNodeImpl::NotifyCollectorReady() +{ + auto verifier = info_.verifier.lock(); + if (verifier == nullptr) { + return; + } + + Attributes attr; + bool setPropertyModeRet = attr.SetInt32Value(Attributes::ATTR_PROPERTY_MODE, PROPERTY_MODE_NOTIFY_COLLECTOR_READY); + IF_FALSE_LOGE_AND_RETURN(setPropertyModeRet); + bool setScheduleIdRet = attr.SetUint64Value(Attributes::ATTR_SCHEDULE_ID, GetScheduleId()); + IF_FALSE_LOGE_AND_RETURN(setScheduleIdRet); + + int32_t ret = verifier->SetProperty(attr); + if (ret != SUCCESS) { + IAM_LOGE("notify collector ready failed, result = %{public}d", ret); + } } void ScheduleNodeImpl::ProcessVerifierBeginFailed(FiniteStateMachine &machine, uint32_t event) diff --git a/services/core/src/schedule_node_impl.h b/services/core/src/schedule_node_impl.h index c9b8a72d467daf71cc4c9c3543b5a61e8df4e318..ef35c736555eee62c39276f8d1cde33a26cfa682 100644 --- a/services/core/src/schedule_node_impl.h +++ b/services/core/src/schedule_node_impl.h @@ -40,6 +40,7 @@ public: struct ScheduleInfo { uint64_t scheduleId {0}; std::optional tokenId; + uint32_t collectorTokenId; PinSubType pinSubType {0}; uint64_t contextId {0}; uint64_t expiredTime {0}; @@ -51,7 +52,6 @@ public: std::weak_ptr verifier; std::shared_ptr threadHandler; std::shared_ptr callback; - std::shared_ptr parameters; bool endAfterFirstFail; std::vector collectorMessage; std::vector verifierMessage; @@ -97,6 +97,10 @@ private: void OnScheduleProcessing(FiniteStateMachine &machine, uint32_t event); void OnScheduleFinished(FiniteStateMachine &machine, uint32_t event); + + void GetScheduleAttribute(bool isVerifier, Attributes &attribute) const; + + void NotifyCollectorReady(); uint32_t timerId_ {0}; // members ScheduleInfo info_; diff --git a/services/ipc/inc/co_auth_service.h b/services/ipc/inc/co_auth_service.h index 8f73285c17ca4d5107135d476b02e4447622d568..a8b42a6c617b5a16c8b46f9c639da0d6a1a27c16 100644 --- a/services/ipc/inc/co_auth_service.h +++ b/services/ipc/inc/co_auth_service.h @@ -28,10 +28,13 @@ class CoAuthService : public SystemAbility, public CoAuthStub { public: static constexpr uint64_t DEFER_TIME = 2000; DECLARE_SYSTEM_ABILITY(CoAuthService); - explicit CoAuthService(int32_t systemAbilityId, bool runOnCreate = false); + static std::shared_ptr GetInstance(); + + CoAuthService(); ~CoAuthService() override = default; int Dump(int fd, const std::vector &args) override; uint64_t ExecutorRegister(const ExecutorRegisterInfo &info, sptr &callback) override; + void ExecutorUnregister(uint64_t executorIndex) override; protected: void OnStart() override; @@ -39,6 +42,9 @@ protected: private: static void Init(); + + static std::mutex mutex_; + static std::shared_ptr instance_; }; } // namespace UserAuth } // namespace UserIam diff --git a/services/ipc/inc/user_auth_service.h b/services/ipc/inc/user_auth_service.h index 8597108d8d54dae50c3cca330fddf5d01ea95528..52825856e8164e84c9b5eb4ced6cdee3b34715b2 100644 --- a/services/ipc/inc/user_auth_service.h +++ b/services/ipc/inc/user_auth_service.h @@ -27,6 +27,7 @@ #include "context_pool.h" #include "resource_node_pool.h" #include "user_idm_database.h" +#include "attributes.h" namespace OHOS { namespace UserIam { @@ -34,7 +35,9 @@ namespace UserAuth { class UserAuthService : public SystemAbility, public UserAuthStub, public NoCopyable { public: DECLARE_SYSTEM_ABILITY(UserAuthService); - explicit UserAuthService(int32_t systemAbilityId, bool runOnCreate = false); + static std::shared_ptr GetInstance(); + + UserAuthService(); ~UserAuthService() override = default; int32_t GetAvailableStatus(int32_t apiVersion, AuthType authType, AuthTrustLevel authTrustLevel) override; void GetProperty(int32_t userId, AuthType authType, @@ -42,11 +45,11 @@ public: sptr &callback) override; void SetProperty(int32_t userId, AuthType authType, const Attributes &attributes, sptr &callback) override; - uint64_t AuthUser(int32_t userId, const std::vector &challenge, AuthType authType, - AuthTrustLevel authTrustLevel, sptr &callback) override; + uint64_t AuthUser(AuthParamInner ¶m, std::optional &remoteAuthParam, + sptr &callback) override; uint64_t Auth(int32_t apiVersion, const std::vector &challenge, AuthType authType, AuthTrustLevel authTrustLevel, sptr &callback) override; - uint64_t AuthWidget(int32_t apiVersion, const AuthParam &authParam, + uint64_t AuthWidget(int32_t apiVersion, const AuthParamInner &authParam, const WidgetParam &widgetParam, sptr &callback) override; uint64_t Identify(const std::vector &challenge, AuthType authType, sptr &callback) override; @@ -59,6 +62,9 @@ public: const sptr &listener) override; int32_t UnRegistUserAuthSuccessEventListener(const sptr &listener) override; int32_t SetGlobalConfigParam(const GlobalConfigParam ¶m) override; + int32_t PrepareRemoteAuth(const std::string &networkId, sptr &callback) override; + int32_t ProcStartRemoteAuthRequest(std::string connectionName, const std::shared_ptr &request, + std::shared_ptr &reply); protected: void OnStart() override; @@ -69,16 +75,24 @@ private: const std::vector &challenge, AuthType authType, AuthTrustLevel authTrustLevel, sptr &callback); std::shared_ptr GetAuthContextCallback(int32_t apiVersion, - const AuthParam &authParam, const WidgetParam &widgetParam, sptr &callback); + const AuthParamInner &authParam, const WidgetParam &widgetParam, sptr &callback); bool CheckAuthTrustLevel(AuthTrustLevel authTrustLevel); bool CheckSingeFaceOrFinger(const std::vector &authType); int32_t CheckAuthWidgetType(const std::vector &authType); - int32_t CheckAuthPermissionAndParam(int32_t userId, const AuthParam &authParam, const WidgetParam &widgetParam); - uint64_t StartWidgetContext(const std::shared_ptr &contextCallback, const AuthParam &authParam, - const WidgetParam &widgetParam, std::vector &validType, + int32_t CheckAuthPermissionAndParam(int32_t userId, const AuthParamInner &authParam, + const WidgetParam &widgetParam); + uint64_t StartWidgetContext(const std::shared_ptr &contextCallback, + const AuthParamInner &authParam, const WidgetParam &widgetParam, std::vector &validType, ContextFactory::AuthWidgetContextPara ¶); uint64_t StartAuthContext(int32_t apiVersion, Authentication::AuthenticationPara para, const std::shared_ptr &contextCallback); + uint64_t AuthRemoteUser(AuthParamInner &authParam, Authentication::AuthenticationPara ¶, + RemoteAuthParam &remoteAuthParam, const std::shared_ptr &contextCallback); + uint64_t StartRemoteAuthContext(Authentication::AuthenticationPara para, + RemoteAuthContextParam remoteAuthContextParam, + const std::shared_ptr &contextCallback); + uint64_t StartRemoteAuthInvokerContext(AuthParamInner authParam, + RemoteAuthInvokerContextParam ¶m, const std::shared_ptr &contextCallback); bool Insert2ContextPool(const std::shared_ptr &context); bool CheckCallerIsSystemApp(); int32_t CheckAuthPermissionAndParam(int32_t authType, const int32_t &callerType, const std::string &callerName, @@ -86,10 +100,14 @@ private: bool CheckAuthPermissionAndParam(AuthType authType, AuthTrustLevel authTrustLevel, const std::shared_ptr &contextCallback, Attributes &extraInfo); bool CheckAuthTypeIsValid(std::vector authType); - int32_t CheckValidSolution(int32_t userId, const AuthParam &authParam, const WidgetParam &widgetParam, + int32_t CheckValidSolution(int32_t userId, const AuthParamInner &authParam, const WidgetParam &widgetParam, std::vector &validType); int32_t GetCallerNameAndUserId(ContextFactory::AuthWidgetContextPara ¶, std::shared_ptr &contextCallback); + bool CompleteRemoteAuthParam(RemoteAuthParam &remoteAuthParam, const std::string &localNetworkId); + + static std::mutex mutex_; + static std::shared_ptr instance_; }; } // namespace UserAuth } // namespace UserIam diff --git a/services/ipc/src/co_auth_service.cpp b/services/ipc/src/co_auth_service.cpp index 67b639de5c784d6bfa37484bb9e1047cfe7495dd..8a2a2bacfd06a0d62286162698b30e61c58dd288 100644 --- a/services/ipc/src/co_auth_service.cpp +++ b/services/ipc/src/co_auth_service.cpp @@ -21,6 +21,7 @@ #include "string_ex.h" +#include "device_manager_util.h" #include "executor_messenger_service.h" #include "hdi_message_callback_service.h" #include "hdi_wrapper.h" @@ -35,18 +36,39 @@ #include "ipc_skeleton.h" #include "parameter.h" #include "relative_timer.h" +#include "remote_connect_manager.h" #include "resource_node_pool.h" #include "template_cache_manager.h" +#include "remote_msg_util.h" #define LOG_TAG "USER_AUTH_SA" namespace OHOS { namespace UserIam { namespace UserAuth { -REGISTER_SYSTEM_ABILITY_BY_ID(CoAuthService, SUBSYS_USERIAM_SYS_ABILITY_AUTHEXECUTORMGR, true); +namespace { +const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(CoAuthService::GetInstance().get()); +} // namespace + constexpr int32_t USERIAM_IPC_THREAD_NUM = 4; +std::mutex CoAuthService::mutex_; +std::shared_ptr CoAuthService::instance_ = nullptr; + +std::shared_ptr CoAuthService::GetInstance() +{ + if (instance_ == nullptr) { + std::lock_guard guard(mutex_); + if (instance_ == nullptr) { + instance_ = Common::MakeShared(); + if (instance_ == nullptr) { + IAM_LOGE("make share failed"); + } + } + } + return instance_; +} -CoAuthService::CoAuthService(int32_t systemAbilityId, bool runOnCreate) : SystemAbility(systemAbilityId, runOnCreate) +CoAuthService::CoAuthService() : SystemAbility(SUBSYS_USERIAM_SYS_ABILITY_AUTHEXECUTORMGR, true) { IAM_LOGI("CoAuthService init"); } @@ -98,8 +120,8 @@ uint64_t CoAuthService::ExecutorRegister(const ExecutorRegisterInfo &info, sptr< } sptr messenger = ExecutorMessengerService::GetInstance(); - executorCallback->OnMessengerReady(messenger, fwkPublicKey, templateIdList); uint64_t executorIndex = resourceNode->GetExecutorIndex(); + executorCallback->OnMessengerReady(executorIndex, messenger, fwkPublicKey, templateIdList); int32_t executorType = resourceNode->GetAuthType(); IAM_LOGI("register successful, executorType is %{public}d, executorIndex is ****%{public}hx", executorType, static_cast(executorIndex)); @@ -117,6 +139,19 @@ uint64_t CoAuthService::ExecutorRegister(const ExecutorRegisterInfo &info, sptr< return executorIndex; } +void CoAuthService::ExecutorUnregister(uint64_t executorIndex) +{ + if (!IpcCommon::CheckPermission(*this, ACCESS_AUTH_RESPOOL)) { + IAM_LOGE("failed to check permission"); + return; + } + if (!ResourceNodePool::Instance().Delete(executorIndex)) { + IAM_LOGE("delete resource node failed"); + return; + } + IAM_LOGI("delete resource node success, executorIndex is ****%{public}hx", static_cast(executorIndex)); +} + void CoAuthService::Init() { auto hdi = HdiWrapper::GetHdiRemoteObjInstance(); @@ -127,6 +162,14 @@ void CoAuthService::Init() IAM_LOGI("delete all executors for hdi dead"); UserIam::UserAuth::ReportSystemFault(Common::GetNowTimeString(), "user_auth_hdi host"); })); + + std::string localUdid; + bool getLocalUdidRet = DeviceManagerUtil::GetInstance().GetLocalDeviceUdid(localUdid); + IF_FALSE_LOGE_AND_RETURN(getLocalUdidRet); + auto service = HdiWrapper::GetHdiInstance(); + IF_FALSE_LOGE_AND_RETURN(service != nullptr); + int32_t initRet = service->Init(localUdid); + IF_FALSE_LOGE_AND_RETURN(initRet == HDF_SUCCESS); auto callbackService = HdiMessageCallbackService::GetInstance(); IF_FALSE_LOGE_AND_RETURN(callbackService != nullptr); callbackService->OnHdiConnect(); diff --git a/services/ipc/src/user_auth_service.cpp b/services/ipc/src/user_auth_service.cpp index e99f5f5c852101fd41dbd3292af47c7ac3cd5aae..2f8af80038c0a5f5b2ea666e2a241fd7a1272cd6 100644 --- a/services/ipc/src/user_auth_service.cpp +++ b/services/ipc/src/user_auth_service.cpp @@ -29,6 +29,7 @@ #include "iam_check.h" #include "iam_common_defines.h" #include "iam_logger.h" +#include "iam_para2str.h" #include "iam_ptr.h" #include "iam_time.h" #include "ipc_common.h" @@ -36,7 +37,10 @@ #include "system_param_manager.h" #include "soft_bus_manager.h" #include "widget_client.h" -#include "remote_connect_manager.h" +#include "remote_msg_util.h" +#include "remote_iam_callback.h" +#include "remote_auth_service.h" +#include "device_manager_util.h" #define LOG_TAG "USER_AUTH_SA" @@ -49,7 +53,7 @@ const int32_t CURRENT_VERSION = 1; const uint32_t AUTH_TRUST_LEVEL_SYS = 1; const int32_t USERIAM_IPC_THREAD_NUM = 4; const uint32_t MAX_AUTH_TYPE_SIZE = 3; - +const bool REMOTE_AUTH_SERVICE_RESULT = RemoteAuthService::GetInstance().Start(); void GetTemplatesByAuthType(int32_t userId, AuthType authType, std::vector &templateIds) { templateIds.clear(); @@ -81,29 +85,48 @@ bool IsTemplateIdListRequired(const std::vector &keys) return false; } -void GetResourceNodeByType(AuthType authType, std::vector> &authTypeNodes) +void GetResourceNodeByTypeAndRole(AuthType authType, ExecutorRole role, + std::vector> &authTypeNodes) { authTypeNodes.clear(); ResourceNodePool::Instance().Enumerate( - [&authTypeNodes, authType](const std::weak_ptr &weakNode) { + [&authTypeNodes, role, authType](const std::weak_ptr &weakNode) { auto node = weakNode.lock(); if (node == nullptr) { return; } - if (node->GetAuthType() == authType) { - authTypeNodes.push_back(node); + if (node->GetAuthType() != authType) { + return; } + if (node->GetExecutorRole() != role) { + return; + } + authTypeNodes.push_back(node); }); } +const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(UserAuthService::GetInstance().get()); } // namespace +std::mutex UserAuthService::mutex_; +std::shared_ptr UserAuthService::instance_ = nullptr; -REGISTER_SYSTEM_ABILITY_BY_ID(UserAuthService, SUBSYS_USERIAM_SYS_ABILITY_USERAUTH, true); - -UserAuthService::UserAuthService(int32_t systemAbilityId, bool runOnCreate) - : SystemAbility(systemAbilityId, runOnCreate) +std::shared_ptr UserAuthService::GetInstance() { + if (instance_ == nullptr) { + std::lock_guard guard(mutex_); + if (instance_ == nullptr) { + instance_ = Common::MakeShared(); + if (instance_ == nullptr) { + IAM_LOGE("make share failed"); + } + } + } + return instance_; } +UserAuthService::UserAuthService() + : SystemAbility(SUBSYS_USERIAM_SYS_ABILITY_USERAUTH, true) +{} + void UserAuthService::OnStart() { IAM_LOGI("start service"); @@ -197,7 +220,7 @@ void UserAuthService::GetProperty(int32_t userId, AuthType authType, } std::vector> authTypeNodes; - GetResourceNodeByType(authType, authTypeNodes); + GetResourceNodeByTypeAndRole(authType, ALL_IN_ONE, authTypeNodes); if (authTypeNodes.size() != 1) { IAM_LOGE("auth type %{public}d resource node num %{public}zu is not expected", authType, authTypeNodes.size()); @@ -245,7 +268,7 @@ void UserAuthService::SetProperty(int32_t userId, AuthType authType, const Attri } std::vector> authTypeNodes; - GetResourceNodeByType(authType, authTypeNodes); + GetResourceNodeByTypeAndRole(authType, ALL_IN_ONE, authTypeNodes); if (authTypeNodes.size() != 1) { IAM_LOGE("auth type %{public}d resource node num %{public}zu is not expected", authType, authTypeNodes.size()); @@ -378,6 +401,52 @@ uint64_t UserAuthService::StartAuthContext(int32_t apiVersion, Authentication::A return context->GetContextId(); } +uint64_t UserAuthService::StartRemoteAuthContext(Authentication::AuthenticationPara para, + RemoteAuthContextParam remoteAuthContextParam, const std::shared_ptr &contextCallback) +{ + IAM_LOGI("start"); + Attributes extraInfo; + std::shared_ptr context = ContextFactory::CreateRemoteAuthContext(para, remoteAuthContextParam, + contextCallback); + if (context == nullptr || !ContextPool::Instance().Insert(context)) { + IAM_LOGE("failed to insert context"); + contextCallback->OnResult(GENERAL_ERROR, extraInfo); + return BAD_CONTEXT_ID; + } + contextCallback->SetCleaner(ContextHelper::Cleaner(context)); + + if (!context->Start()) { + int32_t errorCode = context->GetLatestError(); + IAM_LOGE("failed to start auth errorCode:%{public}d", errorCode); + contextCallback->OnResult(errorCode, extraInfo); + return BAD_CONTEXT_ID; + } + IAM_LOGI("success"); + return context->GetContextId(); +} + +uint64_t UserAuthService::StartRemoteAuthInvokerContext(AuthParamInner authParam, + RemoteAuthInvokerContextParam ¶m, const std::shared_ptr &contextCallback) +{ + Attributes extraInfo; + std::shared_ptr context = ContextFactory::CreateRemoteAuthInvokerContext(authParam, param, + contextCallback); + if (context == nullptr || !ContextPool::Instance().Insert(context)) { + IAM_LOGE("failed to insert context"); + contextCallback->OnResult(GENERAL_ERROR, extraInfo); + return BAD_CONTEXT_ID; + } + contextCallback->SetCleaner(ContextHelper::Cleaner(context)); + + if (!context->Start()) { + int32_t errorCode = context->GetLatestError(); + IAM_LOGE("failed to start auth errorCode:%{public}d", errorCode); + contextCallback->OnResult(errorCode, extraInfo); + return BAD_CONTEXT_ID; + } + return context->GetContextId(); +} + bool UserAuthService::CheckAuthPermissionAndParam(AuthType authType, AuthTrustLevel authTrustLevel, const std::shared_ptr &contextCallback, Attributes &extraInfo) { @@ -399,17 +468,19 @@ bool UserAuthService::CheckAuthPermissionAndParam(AuthType authType, AuthTrustLe return true; } -uint64_t UserAuthService::AuthUser(int32_t userId, const std::vector &challenge, - AuthType authType, AuthTrustLevel authTrustLevel, sptr &callback) +uint64_t UserAuthService::AuthUser(AuthParamInner &authParam, std::optional &remoteAuthParam, + sptr &callback) { - IAM_LOGI("start"); - auto contextCallback = GetAuthContextCallback(INNER_API_VERSION_10000, challenge, authType, authTrustLevel, - callback); + IAM_LOGI("start, userId:%{public}d authType:%{public}d atl:%{public}d remoteAuthParamHasValue:%{public}s", + authParam.userId, authParam.authType, authParam.authTrustLevel, + Common::GetBoolStr(remoteAuthParam.has_value())); + auto contextCallback = GetAuthContextCallback(INNER_API_VERSION_10000, authParam.challenge, authParam.authType, + authParam.authTrustLevel, callback); if (contextCallback == nullptr) { IAM_LOGE("contextCallback is nullptr"); return BAD_CONTEXT_ID; } - contextCallback->SetTraceUserId(userId); + contextCallback->SetTraceUserId(authParam.userId); Attributes extraInfo; std::string callerName = ""; int32_t callerType = 0; @@ -420,20 +491,105 @@ uint64_t UserAuthService::AuthUser(int32_t userId, const std::vector &c } contextCallback->SetTraceCallerName(callerName); contextCallback->SetTraceCallerType(callerType); - if (CheckAuthPermissionAndParam(authType, authTrustLevel, contextCallback, extraInfo) == false) { + if (CheckAuthPermissionAndParam(authParam.authType, authParam.authTrustLevel, contextCallback, + extraInfo) == false) { return BAD_CONTEXT_ID; } Authentication::AuthenticationPara para = {}; para.tokenId = IpcCommon::GetAccessTokenId(*this); - para.userId = userId; - para.authType = authType; - para.atl = authTrustLevel; - para.challenge = std::move(challenge); + para.userId = authParam.userId; + para.authType = authParam.authType; + para.atl = authParam.authTrustLevel; + para.challenge = std::move(authParam.challenge); para.endAfterFirstFail = false; para.callerName = callerName; para.callerType = callerType; para.sdkVersion = INNER_API_VERSION_10000; - return StartAuthContext(INNER_API_VERSION_10000, para, contextCallback); + + if (!remoteAuthParam.has_value()) { + return StartAuthContext(INNER_API_VERSION_10000, para, contextCallback); + } + + uint64_t contextId = AuthRemoteUser(authParam, para, remoteAuthParam.value(), contextCallback); + if (contextId == BAD_CONTEXT_ID) { + contextCallback->OnResult(GENERAL_ERROR, extraInfo); + return BAD_CONTEXT_ID; + } + + IAM_LOGI("success"); + return contextId; +} + +int32_t UserAuthService::PrepareRemoteAuth(const std::string &networkId, sptr &callback) +{ + IAM_LOGI("start"); + if (callback == nullptr) { + IAM_LOGE("callback is nullptr"); + return INVALID_PARAMETERS; + } + if (!IpcCommon::CheckPermission(*this, ACCESS_USER_AUTH_INTERNAL_PERMISSION)) { + IAM_LOGE("failed to check permission"); + return CHECK_PERMISSION_FAILED; + } + if (networkId.empty()) { + IAM_LOGE("networkId is empty"); + return INVALID_PARAMETERS; + } + + auto hdi = HdiWrapper::GetHdiInstance(); + IF_FALSE_LOGE_AND_RETURN_VAL(hdi != nullptr, GENERAL_ERROR); + + int32_t ret = hdi->PrepareRemoteAuth(networkId); + IF_FALSE_LOGE_AND_RETURN_VAL(ret == HDF_SUCCESS, GENERAL_ERROR); + + Attributes attr; + callback->OnResult(SUCCESS, attr); + + IAM_LOGI("success"); + return SUCCESS; +} + +uint64_t UserAuthService::AuthRemoteUser(AuthParamInner &authParam, Authentication::AuthenticationPara ¶, + RemoteAuthParam &remoteAuthParam, const std::shared_ptr &contextCallback) +{ + IAM_LOGI("start"); + + if (para.authType != PIN) { + IAM_LOGE("Remote auth only support pin auth"); + return BAD_CONTEXT_ID; + } + + std::string localNetworkId; + bool getNetworkIdRet = DeviceManagerUtil::GetInstance().GetLocalDeviceNetWorkId(localNetworkId); + IF_FALSE_LOGE_AND_RETURN_VAL(getNetworkIdRet, BAD_CONTEXT_ID); + + bool completeRet = CompleteRemoteAuthParam(remoteAuthParam, localNetworkId); + IF_FALSE_LOGE_AND_RETURN_VAL(completeRet, BAD_CONTEXT_ID); + + if (remoteAuthParam.collectorTokenId.has_value()) { + para.collectorTokenId = remoteAuthParam.collectorTokenId.value(); + } else { + para.collectorTokenId = para.tokenId; + } + + if (remoteAuthParam.collectorNetworkId.value() == localNetworkId) { + RemoteAuthInvokerContextParam remoteAuthInvokerContextParam; + remoteAuthInvokerContextParam.connectionName = ""; + remoteAuthInvokerContextParam.verifierNetworkId = remoteAuthParam.verifierNetworkId.value(); + remoteAuthInvokerContextParam.collectorNetworkId = remoteAuthParam.collectorNetworkId.value(); + remoteAuthInvokerContextParam.tokenId = para.tokenId; + remoteAuthInvokerContextParam.collectorTokenId = para.collectorTokenId; + IAM_LOGI("start remote auth invoker context"); + return StartRemoteAuthInvokerContext(authParam, remoteAuthInvokerContextParam, contextCallback); + } + + RemoteAuthContextParam remoteAuthContextParam; + remoteAuthContextParam.authType = authParam.authType; + remoteAuthContextParam.connectionName = ""; + remoteAuthContextParam.collectorNetworkId = remoteAuthParam.collectorNetworkId.value(); + remoteAuthContextParam.executorInfoMsg = {}; + IAM_LOGI("start remote auth context"); + return StartRemoteAuthContext(para, remoteAuthContextParam, contextCallback); } uint64_t UserAuthService::Identify(const std::vector &challenge, AuthType authType, @@ -562,7 +718,7 @@ bool UserAuthService::CheckSingeFaceOrFinger(const std::vector &authTy return false; } -int32_t UserAuthService::CheckAuthPermissionAndParam(int32_t userId, const AuthParam &authParam, +int32_t UserAuthService::CheckAuthPermissionAndParam(int32_t userId, const AuthParamInner &authParam, const WidgetParam &widgetParam) { if (!IpcCommon::CheckPermission(*this, IS_SYSTEM_APP) && @@ -574,7 +730,7 @@ int32_t UserAuthService::CheckAuthPermissionAndParam(int32_t userId, const AuthP IAM_LOGE("CheckPermission failed"); return CHECK_PERMISSION_FAILED; } - int32_t ret = CheckAuthWidgetType(authParam.authType); + int32_t ret = CheckAuthWidgetType(authParam.authTypes); if (ret != SUCCESS) { IAM_LOGE("CheckAuthWidgetType fail."); return ret; @@ -586,7 +742,7 @@ int32_t UserAuthService::CheckAuthPermissionAndParam(int32_t userId, const AuthP static const size_t authTypeTwo = 2; static const size_t authType0 = 0; static const size_t authType1 = 1; - std::vector authType = authParam.authType; + std::vector authType = authParam.authTypes; if (((authType.size() == authTypeTwo) && (authType[authType0] == AuthType::FACE) && (authType[authType1] == AuthType::FINGERPRINT)) || ((authType.size() == authTypeTwo) && @@ -602,7 +758,7 @@ int32_t UserAuthService::CheckAuthPermissionAndParam(int32_t userId, const AuthP } uint64_t UserAuthService::StartWidgetContext(const std::shared_ptr &contextCallback, - const AuthParam &authParam, const WidgetParam &widgetParam, std::vector &validType, + const AuthParamInner &authParam, const WidgetParam &widgetParam, std::vector &validType, ContextFactory::AuthWidgetContextPara ¶) { Attributes extraInfo; @@ -628,11 +784,11 @@ uint64_t UserAuthService::StartWidgetContext(const std::shared_ptrGetContextId(); } -int32_t UserAuthService::CheckValidSolution(int32_t userId, const AuthParam &authParam, +int32_t UserAuthService::CheckValidSolution(int32_t userId, const AuthParamInner &authParam, const WidgetParam &widgetParam, std::vector &validType) { int32_t ret = AuthWidgetHelper::CheckValidSolution( - userId, authParam.authType, authParam.authTrustLevel, validType); + userId, authParam.authTypes, authParam.authTrustLevel, validType); if (ret != SUCCESS) { IAM_LOGE("CheckValidSolution fail %{public}d", ret); return ret; @@ -672,7 +828,7 @@ int32_t UserAuthService::GetCallerNameAndUserId(ContextFactory::AuthWidgetContex return SUCCESS; } -uint64_t UserAuthService::AuthWidget(int32_t apiVersion, const AuthParam &authParam, +uint64_t UserAuthService::AuthWidget(int32_t apiVersion, const AuthParamInner &authParam, const WidgetParam &widgetParam, sptr &callback) { IAM_LOGI("start %{public}d authTrustLevel:%{public}u", apiVersion, authParam.authTrustLevel); @@ -691,7 +847,7 @@ uint64_t UserAuthService::AuthWidget(int32_t apiVersion, const AuthParam &authPa } checkRet = CheckAuthPermissionAndParam(para.userId, authParam, widgetParam); if (checkRet != SUCCESS) { - IAM_LOGE("check auth widget param failed"); + IAM_LOGE("check permission and auth widget param failed"); contextCallback->OnResult(checkRet, extraInfo); return BAD_CONTEXT_ID; } @@ -726,7 +882,7 @@ bool UserAuthService::Insert2ContextPool(const std::shared_ptr &context } std::shared_ptr UserAuthService::GetAuthContextCallback(int32_t apiVersion, - const AuthParam &authParam, const WidgetParam &widgetParam, sptr &callback) + const AuthParamInner &authParam, const WidgetParam &widgetParam, sptr &callback) { if (callback == nullptr) { IAM_LOGE("callback is nullptr"); @@ -743,7 +899,7 @@ std::shared_ptr UserAuthService::GetAuthContextCallback(int32_t contextCallback->SetTraceAuthTrustLevel(authParam.authTrustLevel); uint32_t authWidgetType = 0; - for (const auto authType : authParam.authType) { + for (const auto authType : authParam.authTypes) { authWidgetType |= static_cast(authType); } static const uint32_t bitWindowMode = 0x40000000; @@ -934,6 +1090,93 @@ int32_t UserAuthService::SetGlobalConfigParam(const GlobalConfigParam ¶m) IAM_LOGE("failed to Set global config param"); return result; } + + return SUCCESS; +} + +bool UserAuthService::CompleteRemoteAuthParam(RemoteAuthParam &remoteAuthParam, const std::string &localNetworkId) +{ + IAM_LOGI("start"); + + if (!remoteAuthParam.verifierNetworkId.has_value() && !remoteAuthParam.collectorNetworkId.has_value()) { + IAM_LOGE("neither verifierNetworkId nor collectorNetworkId is set"); + return false; + } else if (remoteAuthParam.verifierNetworkId.has_value() && !remoteAuthParam.collectorNetworkId.has_value()) { + IAM_LOGI("collectorNetworkId not set, verifierNetworkId set, use local networkId as collectorNetworkId"); + remoteAuthParam.collectorNetworkId = localNetworkId; + } else if (!remoteAuthParam.verifierNetworkId.has_value() && remoteAuthParam.collectorNetworkId.has_value()) { + IAM_LOGI("verifierNetworkId not set, collectorNetworkId set, use local networkId as verifierNetworkId"); + remoteAuthParam.verifierNetworkId = localNetworkId; + } + + if (remoteAuthParam.verifierNetworkId.value() != localNetworkId && + remoteAuthParam.collectorNetworkId.value() != localNetworkId) { + IAM_LOGE("both verifierNetworkId and collectorNetworkId are not local networkId"); + return false; + } + + if (remoteAuthParam.verifierNetworkId.value() == remoteAuthParam.collectorNetworkId.value()) { + IAM_LOGE("verifierNetworkId and collectorNetworkId are the same"); + return false; + } + + if (remoteAuthParam.verifierNetworkId == localNetworkId && !remoteAuthParam.collectorTokenId.has_value()) { + IAM_LOGE("this device is verifier, collectorTokenId not set"); + return false; + } + + if (remoteAuthParam.collectorNetworkId == localNetworkId && !remoteAuthParam.collectorTokenId.has_value()) { + IAM_LOGI("this device is collector, update collectorTokenId with caller token id"); + remoteAuthParam.collectorTokenId = IpcCommon::GetAccessTokenId(*this); + } + + IAM_LOGI("success"); + return true; +} + +int32_t UserAuthService::ProcStartRemoteAuthRequest(std::string connectionName, + const std::shared_ptr &request, std::shared_ptr &reply) +{ + IAM_LOGI("start"); + AuthParamInner authParam = {}; + bool getAuthParamRet = RemoteMsgUtil::DecodeAuthParam(*request, authParam); + IF_FALSE_LOGE_AND_RETURN_VAL(getAuthParamRet, GENERAL_ERROR); + + std::string collectorNetworkId; + bool getCollectorNetworkIdRet = request->GetStringValue(Attributes::ATTR_COLLECTOR_NETWORK_ID, collectorNetworkId); + IF_FALSE_LOGE_AND_RETURN_VAL(getCollectorNetworkIdRet, GENERAL_ERROR); + + uint32_t collectorTokenId; + bool getCollectorTokenIdRet = request->GetUint32Value(Attributes::ATTR_COLLECTOR_TOKEN_ID, collectorTokenId); + IF_FALSE_LOGE_AND_RETURN_VAL(getCollectorTokenIdRet, GENERAL_ERROR); + + Authentication::AuthenticationPara para = {}; + para.userId = authParam.userId; + para.authType = authParam.authType; + para.atl = authParam.authTrustLevel; + para.collectorTokenId = collectorTokenId; + para.challenge = authParam.challenge; + para.sdkVersion = INNER_API_VERSION_10000; + + RemoteAuthContextParam remoteAuthContextParam; + remoteAuthContextParam.authType = authParam.authType; + remoteAuthContextParam.connectionName = connectionName; + remoteAuthContextParam.collectorNetworkId = collectorNetworkId; + remoteAuthContextParam.executorInfoMsg = request->Serialize(); + + sptr callback(new RemoteIamCallback(connectionName)); + IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, GENERAL_ERROR); + + auto contextCallback = ContextCallback::NewInstance(callback, NO_NEED_TRACE); + IF_FALSE_LOGE_AND_RETURN_VAL(contextCallback != nullptr, GENERAL_ERROR); + + auto contextId = StartRemoteAuthContext(para, remoteAuthContextParam, contextCallback); + IF_FALSE_LOGE_AND_RETURN_VAL(contextId != BAD_CONTEXT_ID, GENERAL_ERROR); + + bool setContextIdRet = reply->SetUint64Value(Attributes::ATTR_CONTEXT_ID, contextId); + IF_FALSE_LOGE_AND_RETURN_VAL(setContextIdRet, GENERAL_ERROR); + + IAM_LOGI("success"); return SUCCESS; } } // namespace UserAuth diff --git a/services/remote_connect/inc/remote_connect_listener_manager.h b/services/remote_connect/inc/remote_connect_listener_manager.h index fd23e7dfe46f4c9e78637422033d4440887de0e3..04563c27e6a80025c14fb24197450140b3d3f4f2 100644 --- a/services/remote_connect/inc/remote_connect_listener_manager.h +++ b/services/remote_connect/inc/remote_connect_listener_manager.h @@ -52,7 +52,7 @@ public: private: std::vector listeners_; - std::mutex listenerMutex_; + std::recursive_mutex listenerMutex_; }; } // namespace UserAuth } // namespace UserIam diff --git a/services/remote_connect/src/remote_connect_listener_manager.cpp b/services/remote_connect/src/remote_connect_listener_manager.cpp index e6e7ae77b06a854c9bf48adc5f265cddbdf5ba60..243ddfc8531aa612bce1c315054acde29b3b73ca 100644 --- a/services/remote_connect/src/remote_connect_listener_manager.cpp +++ b/services/remote_connect/src/remote_connect_listener_manager.cpp @@ -27,8 +27,8 @@ const char *GLOBAL_CONNECTION_NAME = "GLOBAL"; } bool RemoteConnectListenerManager::ListenerInfo::operator==(const ListenerInfo &other) const { - bool compareRet = endPointName == other.endPointName || - (connectionName == other.connectionName && connectionName == GLOBAL_CONNECTION_NAME); + bool compareRet = endPointName == other.endPointName && + (connectionName == other.connectionName || connectionName == GLOBAL_CONNECTION_NAME); IAM_LOGI("Check listener connectionName:%{public}s, endPointName:%{public}s, compareRet:%{public}d", connectionName.c_str(), endPointName.c_str(), compareRet); return compareRet; @@ -43,7 +43,7 @@ RemoteConnectListenerManager &RemoteConnectListenerManager::GetInstance() ResultCode RemoteConnectListenerManager::RegisterListener(const std::string &connectionName, const std::string &endPointName, const std::shared_ptr &listener) { - std::lock_guard lock(listenerMutex_); + std::lock_guard lock(listenerMutex_); IF_FALSE_LOGE_AND_RETURN_VAL(listener != nullptr, GENERAL_ERROR); IAM_LOGI("RegisterListener connectionName:%{public}s, endPointName:%{public}s", connectionName.c_str(), endPointName.c_str()); @@ -62,14 +62,14 @@ ResultCode RemoteConnectListenerManager::RegisterListener(const std::string &con ResultCode RemoteConnectListenerManager::RegisterListener(const std::string &endPointName, const std::shared_ptr &listener) { - std::lock_guard lock(listenerMutex_); + std::lock_guard lock(listenerMutex_); return RegisterListener(GLOBAL_CONNECTION_NAME, endPointName, listener); } ResultCode RemoteConnectListenerManager::UnregisterListener(const std::string &connectionName, const std::string &endPointName) { - std::lock_guard lock(listenerMutex_); + std::lock_guard lock(listenerMutex_); IAM_LOGI("UnregisterListener connectionName:%{public}s, endPointName:%{public}s", connectionName.c_str(), endPointName.c_str()); ListenerInfo info = { connectionName, endPointName }; @@ -85,14 +85,14 @@ ResultCode RemoteConnectListenerManager::UnregisterListener(const std::string &c ResultCode RemoteConnectListenerManager::UnregisterListener(const std::string &endPointName) { - std::lock_guard lock(listenerMutex_); + std::lock_guard lock(listenerMutex_); return UnregisterListener(GLOBAL_CONNECTION_NAME, endPointName); } std::shared_ptr RemoteConnectListenerManager::FindListener(const std::string &connectionName, const std::string &endPointName) { - std::lock_guard lock(listenerMutex_); + std::lock_guard lock(listenerMutex_); IAM_LOGI("FindListener connectionName:%{public}s, endPointName:%{public}s", connectionName.c_str(), endPointName.c_str()); ListenerInfo info = { connectionName, endPointName }; @@ -107,7 +107,7 @@ std::shared_ptr RemoteConnectListenerManager::FindListener(c void RemoteConnectListenerManager::OnConnectionDown(const std::string &connectionName) { - std::lock_guard lock(listenerMutex_); + std::lock_guard lock(listenerMutex_); IAM_LOGI("OnConnectionDown connectionName:%{public}s", connectionName.c_str()); for (auto it = listeners_.begin(); it != listeners_.end(); ++it) { if (it->connectionName == connectionName) { diff --git a/services/remote_connect/src/soft_bus_manager.cpp b/services/remote_connect/src/soft_bus_manager.cpp index f2a674db5d5687c5a21507caa9d4a133849dcbe3..a572e698cfed0335f70a7cf76c68e4066eff334c 100644 --- a/services/remote_connect/src/soft_bus_manager.cpp +++ b/services/remote_connect/src/soft_bus_manager.cpp @@ -434,7 +434,7 @@ ResultCode SoftBusManager::OpenConnection(const std::string &connectionName, con IAM_LOGI("start."); int32_t ret = SetFirstCallerTokenID(tokenId); if (ret != SUCCESS) { - IAM_LOGI("SetFirstCallerTokenID fail"); + IAM_LOGE("SetFirstCallerTokenID fail"); } int32_t socketId = ClientSocketInit(connectionName, networkId); if (socketId <= INVALID_SOCKET_ID) { diff --git a/test/fuzztest/clients/coauthclient_fuzzer/co_auth_client_fuzzer.cpp b/test/fuzztest/clients/coauthclient_fuzzer/co_auth_client_fuzzer.cpp index 1f3d9612bfa53dc022ef474b2c574d11710a3060..54dfd268517f5f8a69d8300c946bb6d78274480d 100644 --- a/test/fuzztest/clients/coauthclient_fuzzer/co_auth_client_fuzzer.cpp +++ b/test/fuzztest/clients/coauthclient_fuzzer/co_auth_client_fuzzer.cpp @@ -32,10 +32,11 @@ namespace UserAuth { namespace { class DummyExecutorRegisterCallback final : public ExecutorRegisterCallback { public: - void OnMessengerReady(const std::shared_ptr &messenger, + void OnMessengerReady(uint64_t executorIndex, const std::shared_ptr &messenger, const std::vector &publicKey, const std::vector &templateIds) { IAM_LOGI("start"); + static_cast(executorIndex); static_cast(messenger); static_cast(publicKey); static_cast(templateIds); @@ -135,8 +136,8 @@ void FuzzCoAuthClientUnregister(Parcel &parcel) { IAM_LOGI("start"); ExecutorInfo info = {}; - FillExecutorInfo(parcel, info); - CoAuthClient::GetInstance().Unregister(info); + uint64_t executorId = parcel.ReadUint64(); + CoAuthClient::GetInstance().Unregister(executorId); IAM_LOGI("end"); } @@ -149,13 +150,14 @@ auto g_ExecutorMessengerClient = void FuzzExecutorCallbackServiceOnMessengerReady(Parcel &parcel) { IAM_LOGI("start"); + uint64_t executorIndex = parcel.ReadUint64(); sptr messenger(new (std::nothrow) DummyExecutorMessengerInterface()); std::vector publicKey; Common::FillFuzzUint8Vector(parcel, publicKey); std::vector templateIdList; Common::FillFuzzUint64Vector(parcel, templateIdList); if (g_ExecutorCallbackService != nullptr) { - g_ExecutorCallbackService->OnMessengerReady(messenger, publicKey, templateIdList); + g_ExecutorCallbackService->OnMessengerReady(executorIndex, messenger, publicKey, templateIdList); } IAM_LOGI("end"); } diff --git a/test/fuzztest/clients/executorcallbackstub_fuzzer/executor_callback_stub_fuzzer.cpp b/test/fuzztest/clients/executorcallbackstub_fuzzer/executor_callback_stub_fuzzer.cpp index f9c7782bf79a3b9bcc124571d49ce8232148d470..835df679fcdf87ea39a5a802b9f623f7d5e274be 100644 --- a/test/fuzztest/clients/executorcallbackstub_fuzzer/executor_callback_stub_fuzzer.cpp +++ b/test/fuzztest/clients/executorcallbackstub_fuzzer/executor_callback_stub_fuzzer.cpp @@ -36,10 +36,11 @@ const std::u16string EXECUTOR_CALLBACK_INTERFACE_TOKEN = u"ohos.UserIam.AuthResP class DummyExecutorRegisterCallback final : public ExecutorRegisterCallback { public: - void OnMessengerReady(const std::shared_ptr &messenger, + void OnMessengerReady(uint64_t executorIndex, const std::shared_ptr &messenger, const std::vector &publicKey, const std::vector &templateIds) { IAM_LOGI("start"); + static_cast(executorIndex); static_cast(messenger); static_cast(publicKey); static_cast(templateIds); diff --git a/test/fuzztest/clients/userauthclient_fuzzer/user_auth_client_fuzzer.cpp b/test/fuzztest/clients/userauthclient_fuzzer/user_auth_client_fuzzer.cpp index 50aa127962888f817b08e0882345ec1196bb6b9e..275d20d5456227d12c85613ca3bc42067b9febe5 100644 --- a/test/fuzztest/clients/userauthclient_fuzzer/user_auth_client_fuzzer.cpp +++ b/test/fuzztest/clients/userauthclient_fuzzer/user_auth_client_fuzzer.cpp @@ -140,13 +140,13 @@ void FuzzClientSetProperty(Parcel &parcel) void FuzzClientBeginAuthentication001(Parcel &parcel) { IAM_LOGI("start"); - int32_t userId = parcel.ReadInt32(); - std::vector challenge; - Common::FillFuzzUint8Vector(parcel, challenge); - auto authType = static_cast(parcel.ReadInt32()); - auto atl = static_cast(parcel.ReadUint32()); + AuthParam authParam = {}; + authParam.userId = parcel.ReadInt32(); + Common::FillFuzzUint8Vector(parcel, authParam.challenge); + authParam.authType = static_cast(parcel.ReadInt32()); + authParam.authTrustLevel = static_cast(parcel.ReadUint32()); auto callback = Common::MakeShared(); - UserAuthClient::GetInstance().BeginAuthentication(userId, challenge, authType, atl, callback); + UserAuthClient::GetInstance().BeginAuthentication(authParam, callback); IAM_LOGI("end"); } @@ -203,13 +203,13 @@ void FuzzBeginWidgetAuth(Parcel &parcel) { IAM_LOGI("start"); int32_t apiVersion = parcel.ReadInt32(); - AuthParam authParam; + AuthParamInner authParam; WidgetParam widgetParam; Common::FillFuzzUint8Vector(parcel, authParam.challenge); std::vector atList; parcel.ReadInt32Vector(&atList); for (auto at : atList) { - authParam.authType.push_back(static_cast(at)); + authParam.authTypes.push_back(static_cast(at)); } authParam.authTrustLevel = static_cast(parcel.ReadInt32()); widgetParam.title = parcel.ReadString(); diff --git a/test/fuzztest/common_fuzzer/BUILD.gn b/test/fuzztest/common_fuzzer/BUILD.gn index f81f83325906d3b5d2506e5b8257e989ec512c05..73731696a894242596dd3f4d817a0799bc3bdedb 100644 --- a/test/fuzztest/common_fuzzer/BUILD.gn +++ b/test/fuzztest/common_fuzzer/BUILD.gn @@ -158,6 +158,10 @@ ohos_source_set("userauth_service_core_fuzzer") { "../../../services/core/src/enrollment_impl.cpp", "../../../services/core/src/hdi_message_callback_service.cpp", "../../../services/core/src/identification_impl.cpp", + "../../../services/core/src/remote_auth_service.cpp", + "../../../services/core/src/remote_executor_proxy.cpp", + "../../../services/core/src/remote_executor_stub.cpp", + "../../../services/core/src/remote_msg_util.cpp", "../../../services/core/src/resource_node_impl.cpp", "../../../services/core/src/resource_node_pool_impl.cpp", "../../../services/core/src/resource_node_utils.cpp", @@ -175,13 +179,22 @@ ohos_source_set("userauth_service_core_fuzzer") { ] deps = [ + "../../../frameworks/native/client:userauth_client", "../common_fuzzer:attributes_fuzzer", "../common_fuzzer:dfx_fuzzer", "../common_fuzzer:userauth_service_base_fuzzer", ] external_deps = [ + "ability_base:base", + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_context_native", + "ability_runtime:abilitykit_native", + "ability_runtime:app_manager", + "ability_runtime:extension_manager", "c_utils:utils", + "device_manager:devicemanagersdk", "drivers_interface_user_auth:libuser_auth_proxy_2.0", "hilog:libhilog", "hitrace:hitrace_meter", @@ -203,6 +216,7 @@ ohos_source_set("userauth_service_core_fuzzer") { "../../../common:iam_log_config", "../../../common:iam_utils_config", "../../../frameworks/native/ipc:userauth_client_ipc_config", + "../../../services/remote_connect:userauth_service_remote_connect_config", ] subsystem_name = "useriam" @@ -228,6 +242,9 @@ ohos_source_set("userauth_service_context_fuzzer") { "../../../services/context/src/context_pool_impl.cpp", "../../../services/context/src/enroll_context.cpp", "../../../services/context/src/identify_context.cpp", + "../../../services/context/src/remote_auth_context.cpp", + "../../../services/context/src/remote_auth_invoker_context.cpp", + "../../../services/context/src/remote_iam_callback.cpp", "../../../services/context/src/simple_auth_context.cpp", "../../../services/context/src/trace.cpp", "../../../services/context/src/ui_extension_ability_connection.cpp", @@ -249,8 +266,10 @@ ohos_source_set("userauth_service_context_fuzzer") { "ability_base:zuri", "ability_runtime:ability_context_native", "ability_runtime:abilitykit_native", + "ability_runtime:app_manager", "ability_runtime:extension_manager", "c_utils:utils", + "drivers_interface_user_auth:libuser_auth_proxy_2.0", "hilog:libhilog", "hitrace:hitrace_meter", "init:libbegetutil", @@ -266,6 +285,7 @@ ohos_source_set("userauth_service_context_fuzzer") { "../../../common:iam_log_config", "../../../common:iam_utils_config", "../../../frameworks/native/ipc:userauth_client_ipc_config", + "../../../services/remote_connect:userauth_service_remote_connect_config", ] subsystem_name = "useriam" diff --git a/test/fuzztest/executors/userauthdrivermanager_fuzzer/BUILD.gn b/test/fuzztest/executors/userauthdrivermanager_fuzzer/BUILD.gn index 47a8668df430bcf15e6f0e0e4da0c3e23e48639b..e42586e69cec7cc9e4b0a286952e9b8a2de22713 100644 --- a/test/fuzztest/executors/userauthdrivermanager_fuzzer/BUILD.gn +++ b/test/fuzztest/executors/userauthdrivermanager_fuzzer/BUILD.gn @@ -36,6 +36,7 @@ ohos_fuzztest("UserAuthDriverManagerFuzzTest") { sources = [ "../../../../frameworks/native/executors/src/async_command/async_command_base.cpp", "../../../../frameworks/native/executors/src/async_command/auth_command.cpp", + "../../../../frameworks/native/executors/src/async_command/collect_command.cpp", "../../../../frameworks/native/executors/src/async_command/custom_command.cpp", "../../../../frameworks/native/executors/src/async_command/enroll_command.cpp", "../../../../frameworks/native/executors/src/async_command/identify_command.cpp", diff --git a/test/fuzztest/executors/userauthexecutor_fuzzer/BUILD.gn b/test/fuzztest/executors/userauthexecutor_fuzzer/BUILD.gn index 5bbbee3c02a050d7c3b934396889341aebd791ca..3daeed98407c33a87e0e9f78df690d50899f6e69 100644 --- a/test/fuzztest/executors/userauthexecutor_fuzzer/BUILD.gn +++ b/test/fuzztest/executors/userauthexecutor_fuzzer/BUILD.gn @@ -36,6 +36,7 @@ ohos_fuzztest("UserAuthExecutorFuzzTest") { sources = [ "../../../../frameworks/native/executors/src/async_command/async_command_base.cpp", "../../../../frameworks/native/executors/src/async_command/auth_command.cpp", + "../../../../frameworks/native/executors/src/async_command/collect_command.cpp", "../../../../frameworks/native/executors/src/async_command/custom_command.cpp", "../../../../frameworks/native/executors/src/async_command/enroll_command.cpp", "../../../../frameworks/native/executors/src/async_command/identify_command.cpp", diff --git a/test/fuzztest/executors/userauthexecutor_fuzzer/user_auth_executor_fuzzer.cpp b/test/fuzztest/executors/userauthexecutor_fuzzer/user_auth_executor_fuzzer.cpp index c91ed9094372bff55c03ecb632d3b8d86aeeea4b..d87d2f22273110d9c229a9d3e752957be944451d 100644 --- a/test/fuzztest/executors/userauthexecutor_fuzzer/user_auth_executor_fuzzer.cpp +++ b/test/fuzztest/executors/userauthexecutor_fuzzer/user_auth_executor_fuzzer.cpp @@ -332,13 +332,14 @@ void FuzzFrameworkOnMessengerReady(std::shared_ptr parcel) if (g_executorCallback == nullptr) { return; } + uint64_t executorIndex = parcel->ReadUint64(); shared_ptr messenger = nullptr; FillIExecutorMessenger(parcel, messenger); std::vector publicKey; FillFuzzUint8Vector(*parcel, publicKey); std::vector templateIds; FillFuzzUint64Vector(*parcel, templateIds); - g_executorCallback->OnMessengerReady(messenger, publicKey, templateIds); + g_executorCallback->OnMessengerReady(executorIndex, messenger, publicKey, templateIds); IAM_LOGI("end"); } diff --git a/test/fuzztest/services/coauthservice_fuzzer/co_auth_service_fuzzer.cpp b/test/fuzztest/services/coauthservice_fuzzer/co_auth_service_fuzzer.cpp index 4179cf1f61732f247c66831036695272a93d051c..49f622c668c9211f9283f5cfbc39eb10cc161149 100644 --- a/test/fuzztest/services/coauthservice_fuzzer/co_auth_service_fuzzer.cpp +++ b/test/fuzztest/services/coauthservice_fuzzer/co_auth_service_fuzzer.cpp @@ -56,8 +56,8 @@ public: virtual ~CoAuthServiceFuzzer() = default; - void OnMessengerReady(sptr &messenger, const std::vector &publicKey, - const std::vector &templateIdList) override + void OnMessengerReady(uint64_t executorIndex, sptr &messenger, + const std::vector &publicKey, const std::vector &templateIdList) override { IAM_LOGI("start"); return; @@ -119,7 +119,7 @@ void FillFuzzExecutorRegisterInfo(Parcel &parcel, ExecutorRegisterInfo &executor IAM_LOGI("FillFuzzExecutorRegisterInfo success"); } -CoAuthService g_coAuthService(SUBSYS_USERIAM_SYS_ABILITY_AUTHEXECUTORMGR, true); +CoAuthService g_coAuthService; sptr executorMessengerService = ExecutorMessengerService::GetInstance(); void FuzzRegister(Parcel &parcel) diff --git a/test/fuzztest/services/coauthstub_fuzzer/co_auth_stub_fuzzer.cpp b/test/fuzztest/services/coauthstub_fuzzer/co_auth_stub_fuzzer.cpp index eebfa680abeabfd1d6aeae6db40573bebadefa7c..06e751af2132d87364a29a34d738fe6aa711a1ab 100644 --- a/test/fuzztest/services/coauthstub_fuzzer/co_auth_stub_fuzzer.cpp +++ b/test/fuzztest/services/coauthstub_fuzzer/co_auth_stub_fuzzer.cpp @@ -48,7 +48,7 @@ bool FuzzCoAuthStub(const uint8_t *rawData, size_t size) return false; } - CoAuthService coAuthService(SUBSYS_USERIAM_SYS_ABILITY_AUTHEXECUTORMGR, true); + CoAuthService coAuthService; for (uint32_t code = CO_AUTH_CODE_MIN; code < CO_AUTH_CODE_MAX; code++) { MessageParcel data; MessageParcel reply; diff --git a/test/fuzztest/services/servicecore_fuzzer/inc/common_dummy.h b/test/fuzztest/services/servicecore_fuzzer/inc/common_dummy.h index cd27e052b0a959b085f29470bba4a456b5adefdd..d94f3a4bcac8e1c5fa8ba545f9988bcb34d210a3 100644 --- a/test/fuzztest/services/servicecore_fuzzer/inc/common_dummy.h +++ b/test/fuzztest/services/servicecore_fuzzer/inc/common_dummy.h @@ -83,6 +83,12 @@ public: return {}; } + std::string GetExecutorDeviceUdid() const + { + IAM_LOGI("start"); + return ""; + } + int32_t BeginExecute(uint64_t scheduleId, const std::vector &publicKey, const Attributes &command) { diff --git a/test/fuzztest/services/servicecore_fuzzer/src/resource_node_fuzzer.cpp b/test/fuzztest/services/servicecore_fuzzer/src/resource_node_fuzzer.cpp index b02a01d2085588d99e947b80c8bd8687937cf3c9..512d4f3d6a621e96a644774ac69e8fce0856ba4b 100644 --- a/test/fuzztest/services/servicecore_fuzzer/src/resource_node_fuzzer.cpp +++ b/test/fuzztest/services/servicecore_fuzzer/src/resource_node_fuzzer.cpp @@ -28,8 +28,8 @@ namespace UserAuth { namespace { class DummyExecutorCallbackInterface final : public ExecutorCallbackInterface { public: - void OnMessengerReady(sptr &messenger, const std::vector &publicKey, - const std::vector &templateIdList) override + void OnMessengerReady(uint64_t executorIndex, sptr &messenger, + const std::vector &publicKey, const std::vector &templateIdList) override { IAM_LOGI("start"); static_cast(messenger); diff --git a/test/fuzztest/services/userauthservice_fuzzer/BUILD.gn b/test/fuzztest/services/userauthservice_fuzzer/BUILD.gn index 048d6237d3be3cb3dab09bd6f42d75313699843e..c2c30328fa5f8b8e3327d530114627747f11b6c2 100644 --- a/test/fuzztest/services/userauthservice_fuzzer/BUILD.gn +++ b/test/fuzztest/services/userauthservice_fuzzer/BUILD.gn @@ -30,6 +30,7 @@ ohos_fuzztest("UserAuthServiceFuzzTest") { "../../../../services/core/src", "../../../../services/context/inc", "../../../../services/ipc/inc", + "../../../../services/remote_connect/inc", "../../../../frameworks/native/ipc/inc", "../../../../frameworks/native/ipc/common_defines", "../../../../common/utils", @@ -45,6 +46,10 @@ ohos_fuzztest("UserAuthServiceFuzzTest") { ] external_deps = [ + "ability_runtime:ability_context_native", + "ability_runtime:abilitykit_native", + "ability_runtime:app_manager", + "ability_runtime:extension_manager", "c_utils:utils", "drivers_interface_user_auth:libuser_auth_proxy_2.0", "eventhandler:libeventhandler", diff --git a/test/fuzztest/services/userauthservice_fuzzer/user_auth_service_fuzzer.cpp b/test/fuzztest/services/userauthservice_fuzzer/user_auth_service_fuzzer.cpp index d38bc0970900c4a8319f3375fe65e56e3fb6016e..a26e4017a8efcf4f6a9606141a773489b356f54e 100644 --- a/test/fuzztest/services/userauthservice_fuzzer/user_auth_service_fuzzer.cpp +++ b/test/fuzztest/services/userauthservice_fuzzer/user_auth_service_fuzzer.cpp @@ -136,7 +136,7 @@ public: } }; -UserAuthService g_userAuthService(SUBSYS_USERIAM_SYS_ABILITY_USERAUTH, true); +UserAuthService g_userAuthService; void FuzzGetEnrolledState(Parcel &parcel) { @@ -215,16 +215,20 @@ void FuzzAuth(Parcel &parcel) void FuzzAuthUser(Parcel &parcel) { IAM_LOGI("begin"); - int32_t userId = parcel.ReadInt32(); std::vector challenge; FillFuzzUint8Vector(parcel, challenge); - AuthType authType = static_cast(parcel.ReadInt32()); - AuthTrustLevel authTrustLevel = static_cast(parcel.ReadInt32()); sptr callback(nullptr); if (parcel.ReadBool()) { callback = sptr(new (nothrow) DummyUserAuthCallback()); } - g_userAuthService.AuthUser(userId, challenge, authType, authTrustLevel, callback); + AuthParamInner param = { + .userId = parcel.ReadInt32(), + .challenge = challenge, + .authType = static_cast(parcel.ReadInt32()), + .authTrustLevel = static_cast(parcel.ReadInt32()), + }; + std::optional remoteAuthParam = std::nullopt; + g_userAuthService.AuthUser(param, remoteAuthParam, callback); IAM_LOGI("end"); } @@ -262,13 +266,13 @@ void FuzzAuthWidget(Parcel &parcel) { IAM_LOGI("begin"); int32_t apiVersion = parcel.ReadInt32(); - AuthParam authParam; + AuthParamInner authParam; WidgetParam widgetParam; FillFuzzUint8Vector(parcel, authParam.challenge); std::vector atList; parcel.ReadInt32Vector(&atList); for (auto at : atList) { - authParam.authType.push_back(static_cast(at)); + authParam.authTypes.push_back(static_cast(at)); } authParam.authTrustLevel = static_cast(parcel.ReadInt32()); sptr callback(nullptr); diff --git a/test/fuzztest/services/userauthstub_fuzzer/BUILD.gn b/test/fuzztest/services/userauthstub_fuzzer/BUILD.gn index fa6a1ce6a7e8dec046d0ca45108aecac3e3d2006..41d63a01a84d643532afb87ab37adc8b26ef1ac4 100644 --- a/test/fuzztest/services/userauthstub_fuzzer/BUILD.gn +++ b/test/fuzztest/services/userauthstub_fuzzer/BUILD.gn @@ -30,6 +30,7 @@ ohos_fuzztest("UserAuthStubFuzzTest") { "../../../../services/core/src", "../../../../services/context/inc", "../../../../services/ipc/inc", + "../../../../services/remote_connect/inc", "../../../../frameworks/native/ipc/inc", "../../../../frameworks/native/ipc/common_defines", "../../../../common/utils", @@ -45,6 +46,10 @@ ohos_fuzztest("UserAuthStubFuzzTest") { ] external_deps = [ + "ability_runtime:ability_context_native", + "ability_runtime:abilitykit_native", + "ability_runtime:app_manager", + "ability_runtime:extension_manager", "c_utils:utils", "drivers_interface_user_auth:libuser_auth_proxy_2.0", "eventhandler:libeventhandler", diff --git a/test/fuzztest/services/userauthstub_fuzzer/user_auth_stub_fuzzer.cpp b/test/fuzztest/services/userauthstub_fuzzer/user_auth_stub_fuzzer.cpp index e0caa75a2c777163234f601793a4ee4ec6a8f6b5..8040b44dd6c384e9ad15ae890d27c69e23ae3325 100644 --- a/test/fuzztest/services/userauthstub_fuzzer/user_auth_stub_fuzzer.cpp +++ b/test/fuzztest/services/userauthstub_fuzzer/user_auth_stub_fuzzer.cpp @@ -44,7 +44,7 @@ bool UserAuthStubFuzzTest(const uint8_t *rawData, size_t size) return false; } - UserAuthService userAuthService(SUBSYS_USERIAM_SYS_ABILITY_USERAUTH, true); + auto service = UserAuthService::GetInstance(); for (uint32_t code = USER_AUTH_CODE_MIN; code < USER_AUTH_CODE_MAX; code++) { MessageParcel data; MessageParcel reply; @@ -54,12 +54,12 @@ bool UserAuthStubFuzzTest(const uint8_t *rawData, size_t size) data.WriteInterfaceToken(USER_AUTH_INTERFACE_TOKEN); data.WriteBuffer(rawData, size); data.RewindRead(0); - (void)userAuthService.OnRemoteRequest(code, data, reply, optionSync); + (void)service->OnRemoteRequest(code, data, reply, optionSync); // Async data.WriteInterfaceToken(USER_AUTH_INTERFACE_TOKEN); data.WriteBuffer(rawData, size); data.RewindRead(0); - (void)userAuthService.OnRemoteRequest(code, data, reply, optionAsync); + (void)service->OnRemoteRequest(code, data, reply, optionAsync); } return true; } diff --git a/test/fuzztest/services/useridmservice_fuzzer/BUILD.gn b/test/fuzztest/services/useridmservice_fuzzer/BUILD.gn index 4a7ec7f28405af48dc2e054cf261c5697a84bb34..0fb785f6f8f44220cd53a8b59db803ca49e30ba9 100644 --- a/test/fuzztest/services/useridmservice_fuzzer/BUILD.gn +++ b/test/fuzztest/services/useridmservice_fuzzer/BUILD.gn @@ -32,6 +32,7 @@ ohos_fuzztest("UserIdmServiceFuzzTest") { "../../../../services/core/src", "../../../../services/context/inc", "../../../../services/ipc/inc", + "../../../../services/remote_connect/inc", "../../../../frameworks/native/ipc/inc", "../../../../frameworks/native/ipc/common_defines", "../../../../common/utils", @@ -47,6 +48,10 @@ ohos_fuzztest("UserIdmServiceFuzzTest") { ] external_deps = [ + "ability_runtime:ability_context_native", + "ability_runtime:abilitykit_native", + "ability_runtime:app_manager", + "ability_runtime:extension_manager", "c_utils:utils", "hdf_core:libhdi", "hilog:libhilog", diff --git a/test/fuzztest/services/useridmstub_fuzzer/BUILD.gn b/test/fuzztest/services/useridmstub_fuzzer/BUILD.gn index ae1cfa99bdf320bf450d9e34f6561c3f2dbed24f..cbc2b18b5ae2ce085371b102bdae504a4a4d396d 100644 --- a/test/fuzztest/services/useridmstub_fuzzer/BUILD.gn +++ b/test/fuzztest/services/useridmstub_fuzzer/BUILD.gn @@ -30,6 +30,7 @@ ohos_fuzztest("UserIdmStubFuzzTest") { "../../../../services/core/src", "../../../../services/context/inc", "../../../../services/ipc/inc", + "../../../../services/remote_connect/inc", "../../../../frameworks/native/ipc/inc", "../../../../frameworks/native/ipc/common_defines", "../../../../common/utils", @@ -45,6 +46,10 @@ ohos_fuzztest("UserIdmStubFuzzTest") { ] external_deps = [ + "ability_runtime:ability_context_native", + "ability_runtime:abilitykit_native", + "ability_runtime:app_manager", + "ability_runtime:extension_manager", "c_utils:utils", "drivers_interface_user_auth:libuser_auth_proxy_2.0", "eventhandler:libeventhandler", diff --git a/test/unittest/executors/executor_unit_test.cpp b/test/unittest/executors/executor_unit_test.cpp index ed617e2423fd2531ebe0fbee190d356e0ac147a7..288546bdc7c13a32686679409ffccd43438ea371 100644 --- a/test/unittest/executors/executor_unit_test.cpp +++ b/test/unittest/executors/executor_unit_test.cpp @@ -270,11 +270,13 @@ HWTEST_F(ExecutorUnitTest, UserAuthExecutor_GetDescriptionTest_001, TestSize.Lev ASSERT_NE(executorHdi, nullptr); EXPECT_CALL(*executorHdi, GetExecutorInfo(_)).Times(Exactly(1)).WillOnce([&testExecutorId](ExecutorInfo &info) { info.executorSensorHint = testExecutorId; + info.executorRole = COLLECTOR; + info.authType = PIN; return ResultCode::SUCCESS; }); auto executor = MakeShared(nullptr, executorHdi, testHdiId); ASSERT_NE(executor, nullptr); - const string correctDescription = "Executor(Id:0x0005000a)"; + const string correctDescription = "Executor(Id:0x0005000a, role:1, authType:1)"; const char *description = executor->GetDescription(); ASSERT_NE(description, nullptr); ASSERT_PRED2([](const char *toTest, const char *correct) { return strcmp(toTest, correct) == 0; }, description, @@ -329,7 +331,7 @@ int32_t GetExecutorAndMockStub(shared_ptr &executor, shared_ptr(); EXPECT_NE(messenger, nullptr); mockMessenger = messenger; - executorCallback->OnMessengerReady(messenger, testPublicKey, testTemplateIdList); + executorCallback->OnMessengerReady(0, messenger, testPublicKey, testTemplateIdList); }); mockExecutorHdi = MakeShared(); @@ -460,7 +462,7 @@ HWTEST_F(ExecutorUnitTest, UserAuthExecutor_ExecutorDisconnectTest_001, TestSize ASSERT_NE(commandAttrs, nullptr); commandAttrs->SetUint32Value(Attributes::AttributeKey::ATTR_SCHEDULE_MODE, ENROLL); commandAttrs->SetUint32Value(Attributes::AttributeKey::ATTR_ACCESS_TOKEN_ID, testTokenId); - commandAttrs->SetUint8ArrayValue(Attributes::ATTR_VERIFIER_MESSAGE, testExtraInfo); + commandAttrs->SetUint8ArrayValue(Attributes::ATTR_EXTRA_INFO, testExtraInfo); ret = executorCallback->OnBeginExecute(testScheduleId, uselessPublicKey, *commandAttrs); ASSERT_EQ(ret, ResultCode::SUCCESS); ret = executorCallback->OnBeginExecute(testScheduleId, uselessPublicKey, *commandAttrs); @@ -504,7 +506,7 @@ HWTEST_F(ExecutorUnitTest, UserAuthExecutor_OnBeginExecute_EnrollTest_001, TestS ASSERT_NE(commandAttrs, nullptr); commandAttrs->SetUint32Value(Attributes::AttributeKey::ATTR_SCHEDULE_MODE, ENROLL); commandAttrs->SetUint32Value(Attributes::AttributeKey::ATTR_ACCESS_TOKEN_ID, testTokenId); - commandAttrs->SetUint8ArrayValue(Attributes::AttributeKey::ATTR_VERIFIER_MESSAGE, testExtraInfo); + commandAttrs->SetUint8ArrayValue(Attributes::AttributeKey::ATTR_EXTRA_INFO, testExtraInfo); ret = executorCallback->OnBeginExecute(testScheduleId, uselessPublicKey, *commandAttrs); ASSERT_NE(cmdCallback, nullptr); ASSERT_EQ(ret, ResultCode::SUCCESS); @@ -602,7 +604,7 @@ HWTEST_F(ExecutorUnitTest, UserAuthExecutor_OnBeginExecute_AuthTest_001, TestSiz commandAttrs->SetUint32Value(Attributes::AttributeKey::ATTR_SCHEDULE_MODE, AUTH); commandAttrs->SetUint64ArrayValue(Attributes::AttributeKey::ATTR_TEMPLATE_ID_LIST, testTemplateIdList); commandAttrs->SetUint32Value(Attributes::AttributeKey::ATTR_ACCESS_TOKEN_ID, testTokenId); - commandAttrs->SetUint8ArrayValue(Attributes::ATTR_VERIFIER_MESSAGE, testExtraInfo); + commandAttrs->SetUint8ArrayValue(Attributes::ATTR_EXTRA_INFO, testExtraInfo); commandAttrs->SetBoolValue(Attributes::ATTR_END_AFTER_FIRST_FAIL, endAfterFirstFail); ret = executorCallback->OnBeginExecute(testScheduleId, uselessPublicKey, *commandAttrs); ASSERT_NE(cmdCallback, nullptr); @@ -724,7 +726,7 @@ HWTEST_F(ExecutorUnitTest, UserAuthExecutor_OnBeginExecute_IdentifyTest_001, Tes ASSERT_NE(commandAttrs, nullptr); commandAttrs->SetUint32Value(Attributes::AttributeKey::ATTR_SCHEDULE_MODE, IDENTIFY); commandAttrs->SetUint32Value(Attributes::AttributeKey::ATTR_ACCESS_TOKEN_ID, testTokenId); - commandAttrs->SetUint8ArrayValue(Attributes::ATTR_VERIFIER_MESSAGE, testExtraInfo); + commandAttrs->SetUint8ArrayValue(Attributes::ATTR_EXTRA_INFO, testExtraInfo); ret = executorCallback->OnBeginExecute(testScheduleId, uselessPublicKey, *commandAttrs); ASSERT_NE(cmdCallback, nullptr); ASSERT_EQ(ret, ResultCode::SUCCESS); diff --git a/test/unittest/inner_api/mocks/mock_executor_callback_service.h b/test/unittest/inner_api/mocks/mock_executor_callback_service.h index 88087ed43ab40fda1d50c5ad9aaff100d77be166..923bdbfee794506cec6da9b0f1f98d686f00d5de 100644 --- a/test/unittest/inner_api/mocks/mock_executor_callback_service.h +++ b/test/unittest/inner_api/mocks/mock_executor_callback_service.h @@ -25,7 +25,7 @@ namespace UserIam { namespace UserAuth { class MockExecutorCallbackService final : public ExecutorCallbackStub { public: - MOCK_METHOD3(OnMessengerReady, void(sptr &messenger, + MOCK_METHOD4(OnMessengerReady, void(uint64_t executorIndex, sptr &messenger, const std::vector &publicKey, const std::vector &templateIdList)); MOCK_METHOD3(OnBeginExecute, int32_t(uint64_t scheduleId, const std::vector &publicKey, const Attributes &command)); diff --git a/test/unittest/inner_api/mocks/mock_executor_register_callback.h b/test/unittest/inner_api/mocks/mock_executor_register_callback.h index 87f51aad692402772e3f635dd4de5eb40c4c7bf4..1cac1ad3ab2f5042d23f6866c5aa002b65ca05ff 100644 --- a/test/unittest/inner_api/mocks/mock_executor_register_callback.h +++ b/test/unittest/inner_api/mocks/mock_executor_register_callback.h @@ -27,8 +27,8 @@ namespace UserIam { namespace UserAuth { class MockExecutorRegisterCallback final : public ExecutorRegisterCallback { public: - MOCK_METHOD3(OnMessengerReady, void(const std::shared_ptr &messenger, - const std::vector &publicKey, const std::vector &templateIds)); + MOCK_METHOD4(OnMessengerReady, void(uint64_t executorIndex, const std::shared_ptr &messenger, + const std::vector &publicKey, const std::vector &templateIdList)); MOCK_METHOD3(OnBeginExecute, int32_t(uint64_t scheduleId, const std::vector &publicKey, const Attributes &commandAttrs)); MOCK_METHOD2(OnEndExecute, int32_t(uint64_t scheduleId, const Attributes &commandAttrs)); diff --git a/test/unittest/inner_api/src/executor_callback_proxy_test.cpp b/test/unittest/inner_api/src/executor_callback_proxy_test.cpp index 7acd9af657a46ea1e6d2954dddb513509d33ee66..93934fda2ef34c9c5f985ab70eeac672893ecea9 100644 --- a/test/unittest/inner_api/src/executor_callback_proxy_test.cpp +++ b/test/unittest/inner_api/src/executor_callback_proxy_test.cpp @@ -53,7 +53,7 @@ HWTEST_F(ExecutorCallbackProxyTest, TestOnMessengerReady_001, TestSize.Level0) auto proxy = Common::MakeShared(obj); EXPECT_NE(proxy, nullptr); - proxy->OnMessengerReady(messenger, publicKey, templateIdList); + proxy->OnMessengerReady(0, messenger, publicKey, templateIdList); } HWTEST_F(ExecutorCallbackProxyTest, TestOnMessengerReady_002, TestSize.Level0) @@ -75,7 +75,7 @@ HWTEST_F(ExecutorCallbackProxyTest, TestOnMessengerReady_002, TestSize.Level0) EXPECT_NE(messenger, nullptr); std::vector publicKey; std::vector templateIdList; - proxy->OnMessengerReady(messenger, publicKey, templateIdList); + proxy->OnMessengerReady(0, messenger, publicKey, templateIdList); } HWTEST_F(ExecutorCallbackProxyTest, TestOnBeginExecute_001, TestSize.Level0) diff --git a/test/unittest/inner_api/src/executor_callback_service_test.cpp b/test/unittest/inner_api/src/executor_callback_service_test.cpp index 2776f56b013d06cba66afbaf67cfbc51e4d9d777..4f1f284f0befe0e9792fef69607232b30049c8e7 100644 --- a/test/unittest/inner_api/src/executor_callback_service_test.cpp +++ b/test/unittest/inner_api/src/executor_callback_service_test.cpp @@ -50,7 +50,7 @@ HWTEST_F(ExecutorCallbackServiceTest, ExecutorCallbackServiceTestOnMessengerRead std::shared_ptr testCallback = nullptr; auto service = Common::MakeShared(testCallback); EXPECT_NE(service, nullptr); - service->OnMessengerReady(testMessenger, testPublicKey, testTemplateIdList); + service->OnMessengerReady(0, testMessenger, testPublicKey, testTemplateIdList); } HWTEST_F(ExecutorCallbackServiceTest, ExecutorCallbackServiceTestOnMessengerReady002, TestSize.Level0) @@ -61,19 +61,20 @@ HWTEST_F(ExecutorCallbackServiceTest, ExecutorCallbackServiceTestOnMessengerRead auto testCallback = Common::MakeShared(); EXPECT_NE(testCallback, nullptr); - EXPECT_CALL(*testCallback, OnMessengerReady(_, _, _)).Times(1); + EXPECT_CALL(*testCallback, OnMessengerReady(_, _, _, _)).Times(1); ON_CALL(*testCallback, OnMessengerReady) .WillByDefault( - [&testPublicKey, &testTemplateIdList](const std::shared_ptr &messenger, - const std::vector &publicKey, const std::vector &templateIds) { + [&testPublicKey, &testTemplateIdList](uint64_t executorIndex, + const std::shared_ptr &messenger, const std::vector &publicKey, + const std::vector &templateIdList) { EXPECT_NE(messenger, nullptr); EXPECT_THAT(publicKey, ElementsAreArray(testPublicKey)); - EXPECT_THAT(templateIds, ElementsAreArray(testTemplateIdList)); + EXPECT_THAT(templateIdList, ElementsAreArray(testTemplateIdList)); } ); auto service = Common::MakeShared(testCallback); EXPECT_NE(service, nullptr); - service->OnMessengerReady(testMessenger, testPublicKey, testTemplateIdList); + service->OnMessengerReady(0, testMessenger, testPublicKey, testTemplateIdList); } HWTEST_F(ExecutorCallbackServiceTest, ExecutorCallbackServiceTestOnBeginExecute001, TestSize.Level0) diff --git a/test/unittest/inner_api/src/executor_callback_stub_test.cpp b/test/unittest/inner_api/src/executor_callback_stub_test.cpp index f16f1709520633486e67258e0c916a52aa11f8f9..fcf6b1a253a1cc3863de575f9b2dc2b964713b4d 100644 --- a/test/unittest/inner_api/src/executor_callback_stub_test.cpp +++ b/test/unittest/inner_api/src/executor_callback_stub_test.cpp @@ -45,6 +45,7 @@ void ExecutorCallbackStubTest::TearDown() HWTEST_F(ExecutorCallbackStubTest, TestOnMessengerReadyStub_001, TestSize.Level0) { + uint64_t executorIndex = 0; sptr messenger(new (std::nothrow) MockExecutorMessengerService()); EXPECT_NE(messenger, nullptr); std::vector publicKey; @@ -56,13 +57,14 @@ HWTEST_F(ExecutorCallbackStubTest, TestOnMessengerReadyStub_001, TestSize.Level0 uint32_t code = ExecutorCallbackInterfaceCode::ON_MESSENGER_READY; EXPECT_TRUE(data.WriteInterfaceToken(ExecutorCallbackInterface::GetDescriptor())); + EXPECT_TRUE(data.WriteUint64(executorIndex)); EXPECT_TRUE(data.WriteRemoteObject(messenger->AsObject())); EXPECT_TRUE(data.WriteUInt8Vector(publicKey)); EXPECT_TRUE(data.WriteUInt64Vector(templateIdList)); auto service = Common::MakeShared(); EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, OnMessengerReady(_, _, _)).Times(1); + EXPECT_CALL(*service, OnMessengerReady(_, _, _, _)).Times(1); EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS); } diff --git a/test/unittest/inner_api/src/user_auth_client_test.cpp b/test/unittest/inner_api/src/user_auth_client_test.cpp index 18c4b7e56f38e36ada036b2ee3372aa6db25a91a..e53c9a8bcb02c1998be2fa96bc39b89ffefd7d91 100644 --- a/test/unittest/inner_api/src/user_auth_client_test.cpp +++ b/test/unittest/inner_api/src/user_auth_client_test.cpp @@ -294,30 +294,32 @@ HWTEST_F(UserAuthClientTest, UserAuthClientBeginNorthAuthentication002, TestSize HWTEST_F(UserAuthClientTest, UserAuthClientBeginAuthentication001, TestSize.Level0) { - int32_t testUserId = 84548; - std::vector testChallenge = {1, 2, 3, 4, 8, 7, 5, 4}; - AuthType testAuthType = PIN; - AuthTrustLevel testAtl = ATL1; + AuthParam testAuthParam = { + .userId = 84548, + .challenge = {1, 2, 3, 4, 8, 7, 5, 4}, + .authType = PIN, + .authTrustLevel = ATL1 + }; std::shared_ptr testCallback = nullptr; - uint64_t contextId = UserAuthClient::GetInstance().BeginAuthentication(testUserId, testChallenge, - testAuthType, testAtl, testCallback); + uint64_t contextId = UserAuthClient::GetInstance().BeginAuthentication(testAuthParam, testCallback); EXPECT_EQ(contextId, 0); IpcClientUtils::ResetObj(); testCallback = Common::MakeShared(); EXPECT_NE(testCallback, nullptr); EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1); - contextId = UserAuthClient::GetInstance().BeginAuthentication(testUserId, testChallenge, - testAuthType, testAtl, testCallback); + contextId = UserAuthClient::GetInstance().BeginAuthentication(testAuthParam, testCallback); EXPECT_EQ(contextId, 0); } HWTEST_F(UserAuthClientTest, UserAuthClientBeginAuthentication002, TestSize.Level0) { - int32_t testUserId = 84548; - std::vector testChallenge = {1, 2, 3, 4, 8, 7, 5, 4}; - AuthType testAuthType = PIN; - AuthTrustLevel testAtl = ATL1; + AuthParam testAuthParam = { + .userId = 84548, + .challenge = {1, 2, 3, 4, 8, 7, 5, 4}, + .authType = PIN, + .authTrustLevel = ATL1, + }; auto testCallback = Common::MakeShared(); EXPECT_NE(testCallback, nullptr); EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1); @@ -326,16 +328,15 @@ HWTEST_F(UserAuthClientTest, UserAuthClientBeginAuthentication002, TestSize.Leve auto service = Common::MakeShared(); EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, AuthUser(_, _, _, _, _)).Times(1); + EXPECT_CALL(*service, AuthUser(_, _, _)).Times(1); ON_CALL(*service, AuthUser) .WillByDefault( - [&testUserId, &testChallenge, &testAuthType, &testAtl, &testContextId](int32_t userId, - const std::vector &challenge, AuthType authType, AuthTrustLevel authTrustLevel, - sptr &callback) { - EXPECT_EQ(userId, testUserId); - EXPECT_THAT(challenge, ElementsAreArray(testChallenge)); - EXPECT_EQ(authType, testAuthType); - EXPECT_EQ(authTrustLevel, testAtl); + [&testAuthParam, &testContextId](AuthParamInner &authParam, + std::optional &remoteAuthParam, sptr &callback) { + EXPECT_EQ(authParam.userId, testAuthParam.userId); + EXPECT_THAT(authParam.challenge, ElementsAreArray(testAuthParam.challenge)); + EXPECT_EQ(authParam.authType, testAuthParam.authType); + EXPECT_EQ(authParam.authTrustLevel, testAuthParam.authTrustLevel); if (callback != nullptr) { Attributes extraInfo; callback->OnResult(SUCCESS, extraInfo); @@ -347,8 +348,7 @@ HWTEST_F(UserAuthClientTest, UserAuthClientBeginAuthentication002, TestSize.Leve sptr dr(nullptr); CallRemoteObject(service, obj, dr); - uint64_t contextId = UserAuthClient::GetInstance().BeginAuthentication(testUserId, testChallenge, - testAuthType, testAtl, testCallback); + uint64_t contextId = UserAuthClient::GetInstance().BeginAuthentication(testAuthParam, testCallback); EXPECT_EQ(contextId, testContextId); EXPECT_NE(dr, nullptr); dr->OnRemoteDied(obj); @@ -546,7 +546,7 @@ HWTEST_F(UserAuthClientTest, UserAuthClientGetVersion003, TestSize.Level0) HWTEST_F(UserAuthClientTest, UserAuthClientBeginWidgetAuth001, TestSize.Level0) { static const int32_t apiVersion = 0; - AuthParam authParam; + AuthParamInner authParam; WidgetParam widgetParam; std::shared_ptr testCallback = nullptr; testCallback = Common::MakeShared(); @@ -558,7 +558,7 @@ HWTEST_F(UserAuthClientTest, UserAuthClientBeginWidgetAuth001, TestSize.Level0) HWTEST_F(UserAuthClientTest, UserAuthClientBeginWidgetAuth002, TestSize.Level0) { static const int32_t apiVersion = 0; - AuthParam authParam; + AuthParamInner authParam; WidgetParam widgetParam; std::shared_ptr testCallback = nullptr; uint64_t widgetAuth = UserAuthClientImpl::Instance().BeginWidgetAuth(apiVersion, authParam, @@ -569,7 +569,7 @@ HWTEST_F(UserAuthClientTest, UserAuthClientBeginWidgetAuth002, TestSize.Level0) HWTEST_F(UserAuthClientTest, UserAuthClientBeginWidgetAuth003, TestSize.Level0) { int32_t testVersion = 0; - AuthParam testParam = {}; + AuthParamInner testParam = {}; testParam.challenge = {0}; testParam.authType = {ALL}; WidgetParam testWidgetParam = {}; @@ -584,7 +584,7 @@ HWTEST_F(UserAuthClientTest, UserAuthClientBeginWidgetAuth003, TestSize.Level0) ON_CALL(*service, AuthWidget) .WillByDefault( [&testVersion, &testParam, &testWidgetParam, &testContextVersion](int32_t apiVersion, - const AuthParam &authParam, const WidgetParam &widgetParam, + const AuthParamInner &authParam, const WidgetParam &widgetParam, sptr &callback) { EXPECT_EQ(apiVersion, testVersion); EXPECT_EQ(authParam.authType, testParam.authType); diff --git a/test/unittest/inner_api/src/user_auth_proxy_test.cpp b/test/unittest/inner_api/src/user_auth_proxy_test.cpp index 6cf9ad600d6f0437125df388350c5e0bc51f9ac5..1c3f510db2962e0b0e30f2ad71d564d09bcf5513 100644 --- a/test/unittest/inner_api/src/user_auth_proxy_test.cpp +++ b/test/unittest/inner_api/src/user_auth_proxy_test.cpp @@ -222,10 +222,13 @@ HWTEST_F(UserAuthProxyTest, UserAuthProxyAuth, TestSize.Level0) HWTEST_F(UserAuthProxyTest, UserAuthProxyAuthUser, TestSize.Level0) { - static const int32_t testUserId = 200; - static const AuthType testAuthType = FACE; - static const AuthTrustLevel testAtl = ATL1; - const std::vector testChallenge = {1, 2, 3, 4}; + AuthParamInner testAuthParamInner = { + .userId = 200, + .challenge = {1, 2, 3, 4}, + .authType = FACE, + .authTrustLevel = ATL1, + }; + std::optional testRemoteAuthParam = std::nullopt; sptr obj(new (std::nothrow) MockRemoteObject()); EXPECT_NE(obj, nullptr); @@ -236,14 +239,14 @@ HWTEST_F(UserAuthProxyTest, UserAuthProxyAuthUser, TestSize.Level0) sptr testCallback(new (std::nothrow) UserAuthCallbackService(authCallback)); auto service = Common::MakeShared(); EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, AuthUser(_, _, _, _, _)) + EXPECT_CALL(*service, AuthUser(_, _, _)) .Times(Exactly(1)) - .WillOnce([&testCallback](int32_t userId, const std::vector &challenge, - AuthType authType, AuthTrustLevel authTrustLevel, sptr &callback) { - EXPECT_EQ(userId, testUserId); - EXPECT_THAT(challenge, ElementsAre(1, 2, 3, 4)); - EXPECT_EQ(authType, testAuthType); - EXPECT_EQ(authTrustLevel, testAtl); + .WillOnce([&testCallback, &testAuthParamInner](AuthParamInner &authParam, + std::optional &remoteAuthParam, sptr &callback) { + EXPECT_EQ(authParam.userId, testAuthParamInner.userId); + EXPECT_THAT(authParam.challenge, ElementsAre(1, 2, 3, 4)); + EXPECT_EQ(authParam.authType, testAuthParamInner.authType); + EXPECT_EQ(authParam.authTrustLevel, testAuthParamInner.authTrustLevel); EXPECT_EQ(callback, testCallback); return 0; }); @@ -253,7 +256,7 @@ HWTEST_F(UserAuthProxyTest, UserAuthProxyAuthUser, TestSize.Level0) service->OnRemoteRequest(code, data, reply, option); return SUCCESS; }); - proxy->AuthUser(testUserId, testChallenge, testAuthType, testAtl, testCallback); + proxy->AuthUser(testAuthParamInner, testRemoteAuthParam, testCallback); } HWTEST_F(UserAuthProxyTest, UserAuthProxyCancelAuthOrIdentify, TestSize.Level0) @@ -316,7 +319,7 @@ HWTEST_F(UserAuthProxyTest, UserAuthProxyIdentify, TestSize.Level0) HWTEST_F(UserAuthProxyTest, UserAuthProxyAuthWidget001, TestSize.Level0) { static const int32_t testApiVersion = 0; - AuthParam authParam; + AuthParamInner authParam; WidgetParam widgetParam; sptr obj(new (std::nothrow) MockRemoteObject()); @@ -331,7 +334,7 @@ HWTEST_F(UserAuthProxyTest, UserAuthProxyAuthWidget001, TestSize.Level0) EXPECT_NE(service, nullptr); EXPECT_CALL(*service, AuthWidget(_, _, _, _)) .Times(Exactly(1)) - .WillOnce([&testCallback](int32_t apiVersion, const AuthParam &authParam, const WidgetParam &widgetParam, + .WillOnce([&testCallback](int32_t apiVersion, const AuthParamInner &authParam, const WidgetParam &widgetParam, sptr &callback) { EXPECT_EQ(apiVersion, testApiVersion); EXPECT_EQ(callback, testCallback); @@ -349,7 +352,7 @@ HWTEST_F(UserAuthProxyTest, UserAuthProxyAuthWidget001, TestSize.Level0) HWTEST_F(UserAuthProxyTest, UserAuthProxyAuthWidget002, TestSize.Level0) { static const int32_t testApiVersion = 0; - AuthParam authParam; + AuthParamInner authParam; WidgetParam widgetParam; sptr obj(new (std::nothrow) MockRemoteObject()); diff --git a/test/unittest/services/BUILD.gn b/test/unittest/services/BUILD.gn index 912d9de5a0edca567e17980541dbce0304a1150b..3e6be75921358a92f4fd070951bdb5b7e909558c 100644 --- a/test/unittest/services/BUILD.gn +++ b/test/unittest/services/BUILD.gn @@ -55,6 +55,9 @@ ohos_unittest("iam_services_test") { "../../../services/context/src/context_pool_impl.cpp", "../../../services/context/src/enroll_context.cpp", "../../../services/context/src/identify_context.cpp", + "../../../services/context/src/remote_auth_context.cpp", + "../../../services/context/src/remote_auth_invoker_context.cpp", + "../../../services/context/src/remote_iam_callback.cpp", "../../../services/context/src/simple_auth_context.cpp", "../../../services/context/src/trace.cpp", "../../../services/context/src/ui_extension_ability_connection.cpp", @@ -70,6 +73,10 @@ ohos_unittest("iam_services_test") { "../../../services/core/src/enrollment_impl.cpp", "../../../services/core/src/hdi_message_callback_service.cpp", "../../../services/core/src/identification_impl.cpp", + "../../../services/core/src/remote_auth_service.cpp", + "../../../services/core/src/remote_executor_proxy.cpp", + "../../../services/core/src/remote_executor_stub.cpp", + "../../../services/core/src/remote_msg_util.cpp", "../../../services/core/src/resource_node_impl.cpp", "../../../services/core/src/resource_node_pool_impl.cpp", "../../../services/core/src/resource_node_utils.cpp", @@ -147,6 +154,7 @@ ohos_unittest("iam_services_test") { deps = [ "../../../common:iam_utils", + "../../../frameworks/native/client:userauth_client", "../../../frameworks/native/common:attributes", "../../../frameworks/native/common:dfx", "../../../frameworks/native/ipc:userauth_service_ipc", diff --git a/test/unittest/services/mocks/mock_authentication.h b/test/unittest/services/mocks/mock_authentication.h index 0791392ec7b7fe8273a42036c11b0fdc097075b4..7690cb5877de6f55dbe2f8bf8d1a8acfea442a38 100644 --- a/test/unittest/services/mocks/mock_authentication.h +++ b/test/unittest/services/mocks/mock_authentication.h @@ -29,6 +29,8 @@ public: MOCK_METHOD1(SetChallenge, void(const std::vector &challenge)); MOCK_METHOD1(SetAccessTokenId, void(uint32_t tokenId)); MOCK_METHOD1(SetEndAfterFirstFail, void(bool endAfterFirstFail)); + MOCK_METHOD1(SetCollectorUdid, void(std::string collectorUdid)); + MOCK_METHOD2(Start, bool(std::vector> &scheduleList, std::shared_ptr callback)); MOCK_METHOD2(Update, bool(const std::vector &scheduleResult, AuthResultInfo &resultInfo)); diff --git a/test/unittest/services/mocks/mock_co_auth_service.h b/test/unittest/services/mocks/mock_co_auth_service.h index 4137f3ecd31bb26c84c6ca70586c264fe436ce13..695ca45a15670b850ddfcd776de6bb95b9c2b4f5 100644 --- a/test/unittest/services/mocks/mock_co_auth_service.h +++ b/test/unittest/services/mocks/mock_co_auth_service.h @@ -27,6 +27,7 @@ class MockCoAuthService final : public CoAuthStub { public: MOCK_METHOD2(ExecutorRegister, uint64_t(const ExecutorRegisterInfo &info, sptr &callback)); + MOCK_METHOD1(ExecutorUnregister, void(uint64_t executorIndex)); }; } // namespace UserAuth } // namespace UserIam diff --git a/test/unittest/services/mocks/mock_context.h b/test/unittest/services/mocks/mock_context.h index 6fa39d64354528328349da595f21d9da991ddecd..166246ef9a94f20557969e8986dcda79a3f225f8 100644 --- a/test/unittest/services/mocks/mock_context.h +++ b/test/unittest/services/mocks/mock_context.h @@ -45,8 +45,8 @@ public: MOCK_METHOD1(SetTraceFreezingTime, void(int32_t freezingTime)); MOCK_METHOD1(SetTraceSdkVersion, void(int32_t version)); MOCK_METHOD1(SetTraceAuthType, void(int32_t authType)); - MOCK_METHOD1(SetTraceAuthTrustLevel, void(AuthTrustLevel atl)); MOCK_METHOD1(SetTraceAuthWidgetType, void(uint32_t authWidgetType)); + MOCK_METHOD1(SetTraceAuthTrustLevel, void(AuthTrustLevel atl)); MOCK_METHOD1(SetTraceReuseUnlockResultMode, void(uint32_t reuseUnlockResultMode)); MOCK_METHOD1(SetTraceReuseUnlockResultDuration, void(uint64_t reuseUnlockResultDuration)); MOCK_METHOD1(SetCleaner, void(Context::ContextStopCallback callback)); diff --git a/test/unittest/services/mocks/mock_executor_callback.h b/test/unittest/services/mocks/mock_executor_callback.h index 313651c53f28a34dacc3be5b45656bf847fd4214..573af97d3907d9980ed73439a049899f5152fac9 100644 --- a/test/unittest/services/mocks/mock_executor_callback.h +++ b/test/unittest/services/mocks/mock_executor_callback.h @@ -27,9 +27,8 @@ class MockExecutorCallback final : public IRemoteStub public: MOCK_METHOD4(OnRemoteRequest, int32_t(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); - MOCK_METHOD3(OnMessengerReady, - void(sptr &messenger, const std::vector &publicKey, - const std::vector &templateIdList)); + MOCK_METHOD4(OnMessengerReady, void(uint64_t executorIndex, sptr &messenger, + const std::vector &publicKey, const std::vector &templateIdList)); MOCK_METHOD3(OnBeginExecute, int32_t(uint64_t scheduleId, const std::vector &publicKey, const Attributes &command)); MOCK_METHOD2(OnEndExecute, int32_t(uint64_t scheduleId, const Attributes &command)); diff --git a/test/unittest/services/mocks/mock_iuser_auth_interface.h b/test/unittest/services/mocks/mock_iuser_auth_interface.h index 28ff9f1774f0c3c61b8350c45a37a83b0a9f8e86..419e9652f2d5a3266ea0ce2572c3962580bdc2df 100644 --- a/test/unittest/services/mocks/mock_iuser_auth_interface.h +++ b/test/unittest/services/mocks/mock_iuser_auth_interface.h @@ -31,7 +31,7 @@ namespace UserAuth { class MockIUserAuthInterface final : public IUserAuthInterface { public: class Holder; - MOCK_METHOD1(Init, int32_t(const std::string& deviceUdid)); + MOCK_METHOD1(Init, int32_t(const std::string &deviceUdid)); MOCK_METHOD4(AddExecutor, int32_t(const HdiExecutorRegisterInfo &info, uint64_t &index, std::vector &publicKey, std::vector &templateIds)); @@ -54,9 +54,9 @@ public: MOCK_METHOD3(UpdateIdentificationResult, int32_t(uint64_t contextId, const std::vector &scheduleResult, HdiIdentifyResultInfo &info)); MOCK_METHOD1(CancelIdentification, int32_t(uint64_t contextId)); - MOCK_METHOD3(GetAuthTrustLevel, int32_t(int32_t userId, int32_t authType, uint32_t& authTrustLevel)); - MOCK_METHOD4(GetValidSolution, int32_t(int32_t userId, const std::vector& authTypes, - uint32_t authTrustLevel, std::vector& validTypes)); + MOCK_METHOD3(GetAuthTrustLevel, int32_t(int32_t userId, int32_t authType, uint32_t &authTrustLevel)); + MOCK_METHOD4(GetValidSolution, int32_t(int32_t userId, const std::vector &authTypes, + uint32_t authTrustLevel, std::vector &validTypes)); MOCK_METHOD5(BeginIdentification, int32_t(uint64_t contextId, int32_t authType, const std::vector &challenge, uint32_t executorId, HdiScheduleInfo &scheduleInfo)); @@ -69,17 +69,17 @@ public: MOCK_METHOD3(GetEnrolledState, int32_t(int32_t userId, int32_t authType, HdiEnrolledState &hdiEnrolledState)); MOCK_METHOD4(UpdateAuthenticationResult, int32_t(uint64_t contextId, const std::vector &scheduleResult, HdiAuthResultInfo &info, HdiEnrolledState &enrolledState)); - MOCK_METHOD2(CheckReuseUnlockResult, int32_t(const HdiReuseUnlockParam& reuseParam, HdiReuseUnlockInfo& reuseInfo)); - MOCK_METHOD3(SendMessage, int32_t(uint64_t scheduleId, int32_t srcRole, const std::vector& msg)); - MOCK_METHOD1(RegisterMessageCallback, int32_t(const sptr& messageCallback)); - MOCK_METHOD3(GetLocalScheduleFromMessage, int32_t(const std::string& remoteUdid, - const std::vector& message, HdiScheduleInfo &scheduleInfo)); - MOCK_METHOD4(GetSignedExecutorInfo, int32_t(const std::vector& authTypes, int32_t executorRole, - const std::string& remoteUdid, std::vector& signedExecutorInfo)); - MOCK_METHOD1(PrepareRemoteAuth, int32_t(const std::string& remoteUdid)); - MOCK_METHOD3(GetAuthResultFromMessage, int32_t(const std::string& remoteUdid, const std::vector& message, - HdiAuthResultInfo &authResultInfo)); + MOCK_METHOD2(CheckReuseUnlockResult, int32_t(const HdiReuseUnlockParam &reuseParam, HdiReuseUnlockInfo &reuseInfo)); + MOCK_METHOD3(SendMessage, int32_t(uint64_t scheduleId, int32_t srcRole, const std::vector &msg)); + MOCK_METHOD1(RegisterMessageCallback, int32_t(const sptr &messageCallback)); + MOCK_METHOD1(PrepareRemoteAuth, int32_t(const std::string &remoteUdid)); + MOCK_METHOD3(GetLocalScheduleFromMessage, int32_t(const std::string &remoteUdid, + const std::vector &message, HdiScheduleInfo &scheduleInfo)); + MOCK_METHOD4(GetSignedExecutorInfo, int32_t(const std::vector &authTypes, int32_t executorRole, + const std::string &remoteUdid, std::vector &signedExecutorInfo)); MOCK_METHOD1(SetGlobalConfigParam, int32_t(const HdiGlobalConfigParam ¶m)); + MOCK_METHOD3(GetAuthResultFromMessage, int32_t( + const std::string &remoteUdid, const std::vector &message, HdiAuthResultInfo &authResultInfo)); }; class MockIUserAuthInterface::Holder : public Singleton { diff --git a/test/unittest/services/mocks/mock_resource_node.h b/test/unittest/services/mocks/mock_resource_node.h index f871ba4352a65b4a3acf5417cb6f72b396839d66..95e43e25287a5b230a258c009dcce669c4421eaf 100644 --- a/test/unittest/services/mocks/mock_resource_node.h +++ b/test/unittest/services/mocks/mock_resource_node.h @@ -31,10 +31,11 @@ public: MOCK_CONST_METHOD0(GetOwnerPid, uint32_t()); MOCK_CONST_METHOD0(GetAuthType, AuthType()); MOCK_CONST_METHOD0(GetExecutorRole, ExecutorRole()); - MOCK_CONST_METHOD0(GetExecutorMatcher, uint64_t()); MOCK_CONST_METHOD0(GetExecutorSensorHint, uint64_t()); + MOCK_CONST_METHOD0(GetExecutorMatcher, uint64_t()); MOCK_CONST_METHOD0(GetExecutorEsl, ExecutorSecureLevel()); MOCK_CONST_METHOD0(GetExecutorPublicKey, std::vector()); + MOCK_CONST_METHOD0(GetExecutorDeviceUdid, std::string()); MOCK_METHOD3(BeginExecute, int32_t(uint64_t scheduleId, const std::vector &publicKey, const Attributes &command)); @@ -42,7 +43,6 @@ public: MOCK_METHOD1(SetProperty, int32_t(const Attributes &properties)); MOCK_METHOD2(GetProperty, int32_t(const Attributes &condition, Attributes &values)); MOCK_METHOD2(SendData, int32_t(uint64_t scheduleId, const Attributes &data)); - MOCK_METHOD0(OnRegisterFinish, int32_t()); MOCK_METHOD0(Detach, void()); static std::shared_ptr CreateWithExecuteIndex(uint64_t executorId, bool detach = false) diff --git a/test/unittest/services/mocks/mock_user_auth_service.h b/test/unittest/services/mocks/mock_user_auth_service.h index 61048d5e912d7fb14d14bb8d58bd0d1d849d2ad4..f21a6910d149b0accd4c9fd2c6ff6f3fe2ee8288 100644 --- a/test/unittest/services/mocks/mock_user_auth_service.h +++ b/test/unittest/services/mocks/mock_user_auth_service.h @@ -35,15 +35,14 @@ public: MOCK_METHOD4(SetProperty, void(int32_t userId, AuthType authType, const Attributes &attributes, sptr &callback)); - MOCK_METHOD5(AuthUser, - uint64_t(int32_t userId, const std::vector &challenge, AuthType authType, - AuthTrustLevel authTrustLevel, sptr &callback)); + MOCK_METHOD3(AuthUser, uint64_t(AuthParamInner ¶m, std::optional &remoteAuthParam, + sptr &callback)); MOCK_METHOD5(Auth, uint64_t(int32_t apiVersion, const std::vector &challenge, AuthType authType, AuthTrustLevel authTrustLevel, sptr &callback)); - MOCK_METHOD4(AuthWidget, uint64_t(int32_t apiVersion, const AuthParam &authParam, + MOCK_METHOD4(AuthWidget, uint64_t(int32_t apiVersion, const AuthParamInner &authParam, const WidgetParam &widgetParam, sptr &callback)); MOCK_METHOD3(Identify, @@ -57,6 +56,7 @@ public: const sptr &callback)); MOCK_METHOD1(UnRegistUserAuthSuccessEventListener, int32_t(const sptr &callback)); MOCK_METHOD1(SetGlobalConfigParam, int32_t(const GlobalConfigParam ¶m)); + MOCK_METHOD2(PrepareRemoteAuth, int32_t(const std::string &networkId, sptr &callback)); }; } // namespace UserAuth } // namespace UserIam diff --git a/test/unittest/services/src/attributes_test.cpp b/test/unittest/services/src/attributes_test.cpp index d704146dd5296850b25330bcfbf8652349170797..931b948fe8387859f7855a62018504ed31e85aa4 100644 --- a/test/unittest/services/src/attributes_test.cpp +++ b/test/unittest/services/src/attributes_test.cpp @@ -19,6 +19,11 @@ #include "attributes.h" +#include "iam_logger.h" +#include "securec.h" + +#define LOG_TAG "USER_AUTH_SA" + namespace OHOS { namespace UserIam { namespace UserAuth { @@ -288,84 +293,6 @@ HWTEST_F(AttributesTest, AttributesUint8ByteArray, TestSize.Level0) } } -HWTEST_F(AttributesTest, AttributesDeserialize, TestSize.Level0) -{ - const std::vector desired = {Attributes::ATTR_RESULT_CODE, Attributes::ATTR_SIGNATURE, - Attributes::ATTR_TEMPLATE_ID_LIST, Attributes::ATTR_REMAIN_TIMES, Attributes::ATTR_FREEZING_TIME, - Attributes::ATTR_SCHEDULE_ID, Attributes::ATTR_SCHEDULE_MODE}; - - const std::vector raw = {161, 134, 1, 0, 1, 0, 0, 0, 1, 164, 134, 1, 0, 1, 0, 0, 0, 0, 167, 134, 1, 0, 4, - 0, 0, 0, 105, 97, 109, 0, 169, 134, 1, 0, 20, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 5, 0, 0, 0, 7, 0, 0, 0, 9, 0, 0, - 0, 170, 134, 1, 0, 40, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, - 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 180, 134, 1, 0, 8, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 182, - 134, 1, 0, 4, 0, 0, 0, 255, 255, 255, 255}; - - Attributes attrs(raw); - EXPECT_THAT(attrs.GetKeys(), ElementsAreArray(desired)); - { - bool value; - EXPECT_TRUE(attrs.GetBoolValue(Attributes::ATTR_RESULT_CODE, value)); - EXPECT_EQ(value, true); - } - { - bool value; - EXPECT_TRUE(attrs.GetBoolValue(Attributes::ATTR_SIGNATURE, value)); - EXPECT_EQ(value, false); - } - { - uint64_t value; - EXPECT_TRUE(attrs.GetUint64Value(Attributes::ATTR_SCHEDULE_ID, value)); - EXPECT_EQ(value, UINT64_MAX); - } - { - std::vector value; - EXPECT_TRUE(attrs.GetUint32ArrayValue(Attributes::ATTR_REMAIN_TIMES, value)); - EXPECT_THAT(value, ElementsAre(1, 3, 5, 7, 9)); - } - { - uint32_t value; - EXPECT_TRUE(attrs.GetUint32Value(Attributes::ATTR_SCHEDULE_MODE, value)); - EXPECT_EQ(value, UINT32_MAX); - } - { - std::vector value; - EXPECT_TRUE(attrs.GetUint64ArrayValue(Attributes::ATTR_FREEZING_TIME, value)); - EXPECT_THAT(value, ElementsAre(2, 4, 6, 8, 10)); - } - { - std::string value; - EXPECT_TRUE(attrs.GetStringValue(Attributes::ATTR_TEMPLATE_ID_LIST, value)); - EXPECT_EQ(value, "iam"); - } -} - -HWTEST_F(AttributesTest, AttributesInAttribute, TestSize.Level0) -{ - const std::vector raw = {161, 134, 1, 0, 1, 0, 0, 0, 1, 164, 134, 1, 0, 1, 0, 0, 0, 0, 167, 134, 1, 0, 4, - 0, 0, 0, 105, 97, 109, 0, 169, 134, 1, 0, 20, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 5, 0, 0, 0, 7, 0, 0, 0, 9, 0, 0, - 0, 170, 134, 1, 0, 40, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, - 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 180, 134, 1, 0, 8, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 182, - 134, 1, 0, 4, 0, 0, 0, 255, 255, 255, 255}; - - Attributes attrs1; - EXPECT_TRUE(attrs1.SetBoolValue(Attributes::ATTR_RESULT_CODE, true)); - EXPECT_TRUE(attrs1.SetBoolValue(Attributes::ATTR_SIGNATURE, false)); - EXPECT_TRUE(attrs1.SetUint64Value(Attributes::ATTR_SCHEDULE_ID, UINT64_MAX)); - EXPECT_TRUE(attrs1.SetUint32ArrayValue(Attributes::ATTR_REMAIN_TIMES, {1, 3, 5, 7, 9})); - EXPECT_TRUE(attrs1.SetUint32Value(Attributes::ATTR_SCHEDULE_MODE, UINT32_MAX)); - EXPECT_TRUE(attrs1.SetUint64ArrayValue(Attributes::ATTR_FREEZING_TIME, {2, 4, 6, 8, 10})); - EXPECT_TRUE(attrs1.SetStringValue(Attributes::ATTR_TEMPLATE_ID_LIST, "iam")); - - Attributes attrs2; - EXPECT_TRUE(attrs2.SetAttributesValue(Attributes::ATTR_RESULT_CODE, attrs1)); - - Attributes attrs3(attrs2.Serialize()); - - Attributes attrs4; - EXPECT_TRUE(attrs3.GetAttributesValue(Attributes::ATTR_RESULT_CODE, attrs4)); - EXPECT_THAT(attrs4.Serialize(), ElementsAreArray(raw)); -} - HWTEST_F(AttributesTest, AttributesDeserializeMismatch, TestSize.Level0) { const std::vector raw = {0, 0, 0, 0, 1, 0, 0, 0, 1, 2, 0, 0, 0, 20, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 5, 0, @@ -441,6 +368,40 @@ HWTEST_F(AttributesTest, AttributesCopyAndMove, TestSize.Level0) EXPECT_EQ(attrs1.Serialize().size(), 0U); EXPECT_THAT(attrs2.Serialize(), ElementsAreArray(raw)); } + +HWTEST_F(AttributesTest, AttributesSetAndGetAttributesArray, TestSize.Level0) +{ + Attributes attrs1; + Attributes attrs2; + EXPECT_TRUE(attrs1.SetBoolValue(Attributes::ATTR_RESULT_CODE, true)); + EXPECT_TRUE(attrs1.SetBoolValue(Attributes::ATTR_SCHEDULE_ID, false)); + EXPECT_TRUE(attrs2.SetBoolValue(Attributes::ATTR_RESULT_CODE, true)); + EXPECT_TRUE(attrs2.SetBoolValue(Attributes::ATTR_SCHEDULE_ID, false)); + + std::vector attrsArray; + attrsArray.push_back(Attributes(attrs1.Serialize())); + attrsArray.push_back(Attributes(attrs2.Serialize())); + + Attributes setAttrs; + EXPECT_TRUE(setAttrs.SetAttributesArrayValue(Attributes::ATTR_EXECUTOR_REGISTER_INFO_LIST, attrsArray)); + + std::vector data = setAttrs.Serialize(); + EXPECT_TRUE(data.size() > 0); + + Attributes getAttrs(data); + std::vector getAttrsArray; + EXPECT_TRUE(getAttrs.GetAttributesArrayValue(Attributes::ATTR_EXECUTOR_REGISTER_INFO_LIST, getAttrsArray)); + + ASSERT_EQ(getAttrsArray.size(), 2); + std::vector serializedAttrs1 = attrs1.Serialize(); + std::vector serializedAttrs2 = attrs2.Serialize(); + + std::vector serializedOutAttrs1 = getAttrsArray[0].Serialize(); + std::vector serializedOutAttrs2 = getAttrsArray[1].Serialize(); + + EXPECT_TRUE(serializedAttrs1 == serializedOutAttrs1); + EXPECT_TRUE(serializedAttrs2 == serializedOutAttrs2); +} } // namespace UserAuth } // namespace UserIam } // namespace OHOS diff --git a/test/unittest/services/src/auth_widget_helper_test.cpp b/test/unittest/services/src/auth_widget_helper_test.cpp index 32342c0c1f42f4740cad593be0dd401a7bdb22e5..784b4aacc2c4acdc4b09446131ef1c74a9da9488 100644 --- a/test/unittest/services/src/auth_widget_helper_test.cpp +++ b/test/unittest/services/src/auth_widget_helper_test.cpp @@ -57,11 +57,11 @@ void AuthWidgetHelperTest::TearDown() HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestInitWidgetContextParam001, TestSize.Level0) { - AuthParam authParam; - authParam.authType.push_back(FACE); - authParam.authType.push_back(ALL); - authParam.authType.push_back(PIN); - authParam.authType.push_back(FINGERPRINT); + AuthParamInner authParam; + authParam.authTypes.push_back(FACE); + authParam.authTypes.push_back(ALL); + authParam.authTypes.push_back(PIN); + authParam.authTypes.push_back(FINGERPRINT); authParam.authTrustLevel = ATL2; WidgetParam widgetParam; widgetParam.title = "使用密码验证"; @@ -74,18 +74,18 @@ HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestInitWidgetContextParam001, Te HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestInitWidgetContextParam002, TestSize.Level0) { - AuthParam authParam; - authParam.authType.push_back(FACE); - authParam.authType.push_back(ALL); - authParam.authType.push_back(PIN); - authParam.authType.push_back(FINGERPRINT); + AuthParamInner authParam; + authParam.authTypes.push_back(FACE); + authParam.authTypes.push_back(ALL); + authParam.authTypes.push_back(PIN); + authParam.authTypes.push_back(FINGERPRINT); authParam.authTrustLevel = ATL2; WidgetParam widgetParam; widgetParam.title = "使用密码验证"; widgetParam.navigationButtonText = "确定"; ContextFactory::AuthWidgetContextPara para; para.userId = 1; - std::vector validType = authParam.authType; + std::vector validType = authParam.authTypes; EXPECT_FALSE(AuthWidgetHelper::InitWidgetContextParam(authParam, validType, widgetParam, para)); } @@ -107,7 +107,7 @@ HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestCheckReuseUnlockResult001, Te ContextFactory::AuthWidgetContextPara para; para.userId = 1; Attributes extraInfo; - AuthParam authParam; + AuthParamInner authParam; authParam.reuseUnlockResult.isReuse = false; EXPECT_EQ(AuthWidgetHelper::CheckReuseUnlockResult(para, authParam, extraInfo), INVALID_PARAMETERS); @@ -124,7 +124,7 @@ HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestCheckReuseUnlockResult002, Te ContextFactory::AuthWidgetContextPara para; para.userId = 1; Attributes extraInfo; - AuthParam authParam; + AuthParamInner authParam; authParam.reuseUnlockResult.isReuse = true; authParam.reuseUnlockResult.reuseDuration = 5 * 60 * 1000; authParam.reuseUnlockResult.reuseMode = AUTH_TYPE_RELEVANT; @@ -146,7 +146,7 @@ HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestCheckReuseUnlockResult002, Te EXPECT_EQ(AuthWidgetHelper::CheckReuseUnlockResult(para, authParam, extraInfo), HDF_SUCCESS); ON_CALL(*mockHdi, CheckReuseUnlockResult) .WillByDefault(Return(HDF_SUCCESS)); - EXPECT_EQ(AuthWidgetHelper::CheckReuseUnlockResult(para, authParam, extraInfo), GENERAL_ERROR); + EXPECT_EQ(AuthWidgetHelper::CheckReuseUnlockResult(para, authParam, extraInfo), SUCCESS); MockIUserAuthInterface::Holder::GetInstance().Reset(); } } // namespace UserAuth diff --git a/test/unittest/services/src/authentication_impl_test.cpp b/test/unittest/services/src/authentication_impl_test.cpp index 3ec23740bff3471439e7a0172b032a151ead6f51..f76ecdc348a722c9ae8d08327255949366cb16c7 100644 --- a/test/unittest/services/src/authentication_impl_test.cpp +++ b/test/unittest/services/src/authentication_impl_test.cpp @@ -257,19 +257,15 @@ HWTEST_F(AuthenticationImplTest, AuthenticationImplTestStart, TestSize.Level0) auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); - EXPECT_CALL(*mockHdi, CancelAuthentication(_)).Times(2) + EXPECT_CALL(*mockHdi, CancelAuthentication(_)).Times(0) .WillOnce(Return(HDF_SUCCESS)).WillOnce(Return(HDF_FAILURE)); EXPECT_CALL(*mockHdi, BeginAuthentication(_, _, _)) .WillRepeatedly( [](uint64_t contextId, const HdiAuthParam ¶m, std::vector &scheduleInfos) { HdiScheduleInfo scheduleInfo = {}; - constexpr uint64_t executorIndex = 60; scheduleInfo.authType = HdiAuthType::FACE; scheduleInfo.executorMatcher = 10; - scheduleInfo.executorIndexes.push_back(executorIndex); - std::vector executorMessages; - executorMessages.resize(1); - scheduleInfo.executorMessages.push_back(executorMessages); + scheduleInfo.executorIndexes.push_back(60); scheduleInfo.scheduleId = 20; scheduleInfo.scheduleMode = HdiScheduleMode::AUTH; scheduleInfo.templateIds.push_back(30); @@ -285,10 +281,10 @@ HWTEST_F(AuthenticationImplTest, AuthenticationImplTestStart, TestSize.Level0) std::vector> scheduleList; auto callback = Common::MakeShared(); EXPECT_NE(callback, nullptr); - EXPECT_TRUE(authentication->Start(scheduleList, callback)); - EXPECT_TRUE(authentication->Cancel()); + EXPECT_FALSE(authentication->Start(scheduleList, callback)); + EXPECT_FALSE(authentication->Cancel()); - EXPECT_TRUE(authentication->Start(scheduleList, callback)); + EXPECT_FALSE(authentication->Start(scheduleList, callback)); EXPECT_FALSE(authentication->Cancel()); EXPECT_TRUE(ResourceNodePool::Instance().Delete(executorIndex)); diff --git a/test/unittest/services/src/co_auth_service_test.cpp b/test/unittest/services/src/co_auth_service_test.cpp index eb54253d43be8cdcf057ea997ca9d994390f5c45..48a00e5c369fdac532ed2ecccb3ced0b658d9d95 100644 --- a/test/unittest/services/src/co_auth_service_test.cpp +++ b/test/unittest/services/src/co_auth_service_test.cpp @@ -60,11 +60,11 @@ HWTEST_F(CoAuthServiceTest, CoAuthServiceTest001, TestSize.Level0) info.esl = ESL1; info.publicKey = {'a', 'b', 'c', 'd'}; - auto service = Common::MakeShared(1, true); + auto service = Common::MakeShared(); EXPECT_NE(service, nullptr); auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); - EXPECT_CALL(*testCallback, OnMessengerReady(_, _, _)).Times(1); + EXPECT_CALL(*testCallback, OnMessengerReady(_, _, _, _)).Times(1); EXPECT_CALL(*mockHdi, AddExecutor(_, _, _, _)) .Times(2) .WillOnce(Return(HDF_FAILURE)) @@ -88,7 +88,7 @@ HWTEST_F(CoAuthServiceTest, CoAuthServiceTest001, TestSize.Level0) HWTEST_F(CoAuthServiceTest, CoAuthServiceTest002, TestSize.Level0) { - auto service = Common::MakeShared(1, true); + auto service = Common::MakeShared(); EXPECT_NE(service, nullptr); CoAuthInterface::ExecutorRegisterInfo info = {}; @@ -103,7 +103,7 @@ HWTEST_F(CoAuthServiceTest, CoAuthServiceTest003, TestSize.Level0) int testFd2 = 1; std::vector testArgs; - auto service = Common::MakeShared(1, true); + auto service = Common::MakeShared(); EXPECT_NE(service, nullptr); auto node = MockResourceNode::CreateWithExecuteIndex(20); diff --git a/test/unittest/services/src/co_auth_stub_test.cpp b/test/unittest/services/src/co_auth_stub_test.cpp index 175ae5c33e74acdf7d1c9ce42b5b28c91f1f2305..4982565983945534453d642e073d030235fb8992 100644 --- a/test/unittest/services/src/co_auth_stub_test.cpp +++ b/test/unittest/services/src/co_auth_stub_test.cpp @@ -59,7 +59,7 @@ HWTEST_F(CoAuthStubTest, CoAuthStubTestExecutorRegister001, TestSize.Level0) sptr callback(new (std::nothrow) MockExecutorCallback()); EXPECT_NE(callback, nullptr); MockCoAuthService service; - EXPECT_CALL(service, ExecutorRegister(_, _)).Times(1); + EXPECT_CALL(service, ExecutorRegister(_, _)).Times(0); ON_CALL(service, ExecutorRegister) .WillByDefault( [&testInfo, &testContextId](const CoAuthInterface::ExecutorRegisterInfo &info, @@ -87,10 +87,10 @@ HWTEST_F(CoAuthStubTest, CoAuthStubTestExecutorRegister001, TestSize.Level0) uint32_t code = CoAuthInterfaceCode::CO_AUTH_EXECUTOR_REGISTER; MessageOption option(MessageOption::TF_SYNC); - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); + EXPECT_NE(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); uint64_t contextId = -1; - EXPECT_TRUE(reply.ReadUint64(contextId)); - EXPECT_EQ(contextId, testContextId); + EXPECT_FALSE(reply.ReadUint64(contextId)); + EXPECT_NE(contextId, testContextId); } HWTEST_F(CoAuthStubTest, CoAuthStubTestExecutorRegister002, TestSize.Level0) diff --git a/test/unittest/services/src/context_pool_test.cpp b/test/unittest/services/src/context_pool_test.cpp index 6bd034f214c17e1f519ad221c000839ff6ba591e..ae230fa4695f0fe1a771946b8f787e9a9de2e46c 100644 --- a/test/unittest/services/src/context_pool_test.cpp +++ b/test/unittest/services/src/context_pool_test.cpp @@ -250,7 +250,7 @@ HWTEST_F(ContextPoolTest, ContextPoolTestSelect, TestSize.Level0) HWTEST_F(ContextPoolTest, ContextPoolTestGetNewContextId, TestSize.Level0) { - const int32_t COUNT = 1000; + const int32_t COUNT = 10; std::vector contextIdVector(COUNT); for (int32_t i = 0; i < COUNT; ++i) { diff --git a/test/unittest/services/src/enrollment_impl_test.cpp b/test/unittest/services/src/enrollment_impl_test.cpp index 874be81b7688d6f4b0405a070d0d09f51226969d..329ae98853358f641843582e472bc0b752f05730 100644 --- a/test/unittest/services/src/enrollment_impl_test.cpp +++ b/test/unittest/services/src/enrollment_impl_test.cpp @@ -216,20 +216,16 @@ HWTEST_F(EnrollmentImplTest, EnrollmentImplTestStart_001, TestSize.Level0) auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); EXPECT_CALL(*mockHdi, CancelEnrollment(_)) - .Times(2) + .Times(0) .WillOnce(Return(HDF_SUCCESS)) .WillOnce(Return(HDF_FAILURE)); EXPECT_CALL(*mockHdi, BeginEnrollment(_, _, _)) .WillRepeatedly( [](const std::vector &authToken, const HdiEnrollParam ¶m, HdiScheduleInfo &info) { - constexpr uint64_t executorIndex = 60; info.authType = HdiAuthType::FACE; info.executorMatcher = 10; - info.executorIndexes.push_back(executorIndex); - std::vector executorMessages; - executorMessages.resize(1); - info.executorMessages.push_back(executorMessages); + info.executorIndexes.push_back(60); info.scheduleId = 20; info.scheduleMode = HdiScheduleMode::IDENTIFY; info.templateIds.push_back(30); @@ -244,10 +240,10 @@ HWTEST_F(EnrollmentImplTest, EnrollmentImplTestStart_001, TestSize.Level0) std::vector> scheduleList; auto callback = Common::MakeShared(); EXPECT_NE(callback, nullptr); - EXPECT_TRUE(enroll->Start(scheduleList, callback)); - EXPECT_TRUE(enroll->Cancel()); + EXPECT_FALSE(enroll->Start(scheduleList, callback)); + EXPECT_FALSE(enroll->Cancel()); - EXPECT_TRUE(enroll->Start(scheduleList, callback)); + EXPECT_FALSE(enroll->Start(scheduleList, callback)); EXPECT_FALSE(enroll->Cancel()); EXPECT_TRUE(ResourceNodePool::Instance().Delete(executorIndex)); diff --git a/test/unittest/services/src/identification_impl_test.cpp b/test/unittest/services/src/identification_impl_test.cpp index c1da0ad0e126147662a61cf4416fdbddaec2a3e7..f10e2a6fd86ff92195ecf7f3c3e63b703175bb20 100644 --- a/test/unittest/services/src/identification_impl_test.cpp +++ b/test/unittest/services/src/identification_impl_test.cpp @@ -125,20 +125,16 @@ HWTEST_F(IdentificationImplTest, IdentificationTestStart, TestSize.Level0) auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); EXPECT_CALL(*mockHdi, CancelIdentification(_)) - .Times(2) + .Times(0) .WillOnce(Return(HDF_SUCCESS)) .WillOnce(Return(HDF_FAILURE)); EXPECT_CALL(*mockHdi, BeginIdentification(_, _, _, _, _)) .WillRepeatedly( [](uint64_t contextId, int32_t authType, const std::vector &challenge, uint32_t executorId, HdiScheduleInfo &scheduleInfo) { - constexpr uint64_t executorIndex = 60; scheduleInfo.authType = HdiAuthType::FACE; scheduleInfo.executorMatcher = 10; - scheduleInfo.executorIndexes.push_back(executorIndex); - std::vector executorMessages; - executorMessages.resize(1); - scheduleInfo.executorMessages.push_back(executorMessages); + scheduleInfo.executorIndexes.push_back(60); scheduleInfo.scheduleId = 20; scheduleInfo.scheduleMode = HdiScheduleMode::IDENTIFY; scheduleInfo.templateIds.push_back(30); @@ -153,10 +149,10 @@ HWTEST_F(IdentificationImplTest, IdentificationTestStart, TestSize.Level0) std::vector> scheduleList; auto callback = Common::MakeShared(); EXPECT_NE(callback, nullptr); - EXPECT_TRUE(identification->Start(scheduleList, callback)); - EXPECT_TRUE(identification->Cancel()); + EXPECT_FALSE(identification->Start(scheduleList, callback)); + EXPECT_FALSE(identification->Cancel()); - EXPECT_TRUE(identification->Start(scheduleList, callback)); + EXPECT_FALSE(identification->Start(scheduleList, callback)); EXPECT_FALSE(identification->Cancel()); EXPECT_TRUE(ResourceNodePool::Instance().Delete(executorIndex)); diff --git a/test/unittest/services/src/ipc_common_test.cpp b/test/unittest/services/src/ipc_common_test.cpp index c2df81d5204595d7968d16a4020df1c94183ae25..1cf3d02b9c4d933651558bc210a8eeb5d434e390 100644 --- a/test/unittest/services/src/ipc_common_test.cpp +++ b/test/unittest/services/src/ipc_common_test.cpp @@ -69,7 +69,7 @@ void IpcCommonTest::TearDown() HWTEST_F(IpcCommonTest, IpcCommonTestGetTokenId, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; service.Notice(NoticeType::WIDGET_NOTICE, "PIN"); EXPECT_NE(IpcCommon::GetTokenId(service), (uint32_t)0); } diff --git a/test/unittest/services/src/schedule_node_helper_test.cpp b/test/unittest/services/src/schedule_node_helper_test.cpp index 1875e32378f88aabe879e3c38f6da55f0065d81b..08373e49f37cd309054d82b01384fec75d24200b 100644 --- a/test/unittest/services/src/schedule_node_helper_test.cpp +++ b/test/unittest/services/src/schedule_node_helper_test.cpp @@ -56,13 +56,12 @@ HWTEST_F(ScheduleNodeHelperTest, ScheduleNodeHelperTest_001, TestSize.Level0) HWTEST_F(ScheduleNodeHelperTest, ScheduleNodeHelperTest_002, TestSize.Level0) { std::vector scheduleInfoList; - constexpr uint64_t executorIndex1 = 60; - constexpr uint64_t executorIndex2 = 90; HdiScheduleInfo scheduleInfo = {}; scheduleInfo.authType = HdiAuthType::FACE; scheduleInfo.executorMatcher = 10; - scheduleInfo.executorIndexes.push_back(executorIndex1); - scheduleInfo.executorIndexes.push_back(executorIndex2); + scheduleInfo.executorIndexes.push_back(60); + + scheduleInfo.executorIndexes.push_back(90); scheduleInfo.scheduleId = 20; scheduleInfo.scheduleMode = HdiScheduleMode::AUTH; diff --git a/test/unittest/services/src/schedule_node_test.cpp b/test/unittest/services/src/schedule_node_test.cpp index 8ca69c348bf93712237730ceb896c8513e25758f..b18c944e0648c0629bc71a3b31f85a11ce1dc0e6 100644 --- a/test/unittest/services/src/schedule_node_test.cpp +++ b/test/unittest/services/src/schedule_node_test.cpp @@ -383,7 +383,6 @@ HWTEST_F(ScheduleNodeTest, ScheduleNodeStartAllInOneSuccessButTimeoutAndEndFail, builder->SetScheduleCallback(callback); auto parameters = Common::MakeShared(); EXPECT_NE(parameters, nullptr); - builder->SetParametersAttributes(parameters); builder->SetTemplateIdList(TEMPLATE_LIST); auto scheduleNode = builder->Build(); @@ -433,8 +432,6 @@ HWTEST_F(ScheduleNodeTest, ScheduleNodeStartAllInOneSuccessGetResult, TestSize.L builder->SetScheduleId(SCHEDULE_ID); builder->SetScheduleMode(IDENTIFY); builder->SetScheduleCallback(callback); - std::shared_ptr parameters = nullptr; - builder->SetParametersAttributes(parameters); auto scheduleNode = builder->Build(); ASSERT_NE(scheduleNode, nullptr); diff --git a/test/unittest/services/src/user_auth_service_test.cpp b/test/unittest/services/src/user_auth_service_test.cpp index bc40bb45d72abfcb55a47d95ea2b60232319e580..15e12c456aa79237373205dbd81b92c3d209bfb5 100644 --- a/test/unittest/services/src/user_auth_service_test.cpp +++ b/test/unittest/services/src/user_auth_service_test.cpp @@ -57,7 +57,7 @@ void UserAuthServiceTest::TearDown() HWTEST_F(UserAuthServiceTest, UserAuthServiceGetEnrolledState001, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t testApiVersion = 12; AuthType testAuthType = FACE; EnrolledState testEnrolledState; @@ -84,7 +84,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetEnrolledState001, TestSize.Level HWTEST_F(UserAuthServiceTest, UserAuthServiceGetEnrolledState002, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t testApiVersion = 12; AuthType testAuthType = FACE; EnrolledState testEnrolledState; @@ -102,7 +102,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetEnrolledState002, TestSize.Level HWTEST_F(UserAuthServiceTest, UserAuthServiceGetEnrolledState003, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t testApiVersion = 10; AuthType testAuthType = FACE; EnrolledState testEnrolledState; @@ -117,7 +117,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetEnrolledState003, TestSize.Level HWTEST_F(UserAuthServiceTest, UserAuthServiceGetEnrolledState004, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t testApiVersion = 10; AuthType testAuthType = FACE; EnrolledState testEnrolledState; @@ -130,7 +130,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetEnrolledState004, TestSize.Level HWTEST_F(UserAuthServiceTest, UserAuthServiceGetAvailableStatus001, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t testApiVersion = 8; AuthType testAuthType = FACE; AuthTrustLevel testAuthTrustLevel = ATL3; @@ -151,7 +151,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetAvailableStatus001, TestSize.Lev HWTEST_F(UserAuthServiceTest, UserAuthServiceGetAvailableStatus002, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t testApiVersion = 8; AuthType testAuthType = FACE; AuthTrustLevel testAuthTrustLevel = static_cast(90000); @@ -176,7 +176,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetAvailableStatus002, TestSize.Lev HWTEST_F(UserAuthServiceTest, UserAuthServiceGetAvailableStatus003, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t testApiVersion = 8; AuthType testAuthType = FACE; AuthTrustLevel testAuthTrustLevel = ATL2; @@ -200,7 +200,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetAvailableStatus004, TestSize.Lev AuthType testAuthType = PIN; AuthTrustLevel testAuthTrustLevel = ATL2; - auto service = Common::MakeShared(100, true); + auto service = Common::MakeShared(); EXPECT_NE(service, nullptr); int32_t ret = service->GetAvailableStatus(testApiVersion, testAuthType, testAuthTrustLevel); EXPECT_EQ(ret, CHECK_PERMISSION_FAILED); @@ -218,7 +218,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetAvailableStatus004, TestSize.Lev HWTEST_F(UserAuthServiceTest, UserAuthServiceGetProperty001, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t testUserId = 123; AuthType testAuthType = PIN; std::vector testKeys = {Attributes::ATTR_PIN_SUB_TYPE, Attributes::ATTR_SIGNATURE}; @@ -237,7 +237,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetProperty001, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceGetProperty002, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t testUserId = 123; AuthType testAuthType = PIN; std::vector testKeys = {Attributes::ATTR_PIN_SUB_TYPE, Attributes::ATTR_SIGNATURE}; @@ -268,7 +268,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetProperty002, TestSize.Level0) EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode)); MockResourceNode *node = static_cast(resourceNode.get()); EXPECT_CALL(*node, GetProperty(_, _)) - .Times(2) + .Times(0) .WillOnce(Return(FAIL)) .WillOnce(Return(SUCCESS)); testCallback = sptr(new (std::nothrow) MockGetExecutorPropertyCallback()); @@ -284,7 +284,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetProperty002, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceSetProperty001, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t testUserId = 124; AuthType testAuthType = PIN; Attributes testAttr; @@ -300,7 +300,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceSetProperty001, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceSetProperty002, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t testUserId = 124; AuthType testAuthType = PIN; Attributes testAttr; @@ -313,7 +313,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceSetProperty002, TestSize.Level0) EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode)); MockResourceNode *node = static_cast(resourceNode.get()); EXPECT_CALL(*node, SetProperty(_)) - .Times(2) + .Times(0) .WillOnce(Return(FAIL)) .WillOnce(Return(SUCCESS)); testCallback = sptr(new (std::nothrow) MockSetExecutorPropertyCallback()); @@ -329,7 +329,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceSetProperty002, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuth001, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t testApiVersion = 9; std::vector testChallenge = {1, 2, 3, 4}; AuthType testAuthType = FACE; @@ -357,7 +357,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuth001, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuth002, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t testApiVersion = 9; std::vector testChallenge = {1, 2, 3, 4}; AuthType testAuthType = FACE; @@ -386,7 +386,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuth002, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuth003, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t testApiVersion = 9; std::vector testChallenge = {1, 2, 3, 4}; AuthType testAuthType = PIN; @@ -431,9 +431,6 @@ static void MockForUserAuthHdi(std::shared_ptr &context, std::promise executorMessages; - executorMessages.resize(1); - scheduleInfo.executorMessages.push_back(executorMessages); scheduleInfos.push_back(scheduleInfo); context = ContextPool::Instance().Select(contextId).lock(); return HDF_SUCCESS; @@ -471,7 +468,7 @@ static void MockForAuthResourceNode(std::shared_ptr &resourceN HWTEST_F(UserAuthServiceTest, UserAuthServiceAuth004, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t testApiVersion = 9; std::vector testChallenge = {1, 2, 3, 4}; AuthType testAuthType = FACE; @@ -510,11 +507,14 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuth004, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser001, TestSize.Level0) { - UserAuthService service(100, true); - int32_t testUserId = 125; - std::vector testChallenge = {1, 2, 3, 4}; - AuthType testAuthType = FACE; - AuthTrustLevel testAuthTrustLevel = ATL2; + UserAuthService service; + AuthParamInner authParam = { + .userId = 125, + .challenge = {1, 2, 3, 4}, + .authType = FACE, + .authTrustLevel = ATL2, + }; + std::optional remoteAuthParam = std::nullopt; sptr testCallback(new (std::nothrow) MockUserAuthCallback()); EXPECT_NE(testCallback, nullptr); auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); @@ -523,43 +523,47 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser001, TestSize.Level0) EXPECT_CALL(*mockHdi, BeginAuthentication(_, _, _)).Times(1); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); sptr callbackInterface = testCallback; - uint64_t contextId = service.AuthUser(testUserId, testChallenge, testAuthType, - testAuthTrustLevel, callbackInterface); + uint64_t contextId = service.AuthUser(authParam, remoteAuthParam, callbackInterface); EXPECT_EQ(contextId, 0); IpcCommon::DeleteAllPermission(); } HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser002, TestSize.Level0) { - UserAuthService service(100, true); - int32_t testUserId = 125; - std::vector testChallenge = {1, 2, 3, 4}; - AuthType testAuthType = FACE; - AuthTrustLevel testAuthTrustLevel = ATL2; + UserAuthService service; + AuthParamInner authParam = { + .userId = 125, + .challenge = {1, 2, 3, 4}, + .authType = FACE, + .authTrustLevel = ATL2, + }; + std::optional remoteAuthParam = std::nullopt; sptr testCallback(nullptr); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); sptr callbackInterface = testCallback; - uint64_t contextId = service.AuthUser(testUserId, testChallenge, testAuthType, - testAuthTrustLevel, callbackInterface); + uint64_t contextId = service.AuthUser(authParam, remoteAuthParam, callbackInterface); EXPECT_EQ(contextId, 0); testCallback = sptr(new (std::nothrow) MockUserAuthCallback()); EXPECT_NE(testCallback, nullptr); EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1); - testAuthTrustLevel = static_cast(90000); + authParam.authTrustLevel = static_cast(90000); callbackInterface = testCallback; - contextId = service.AuthUser(testUserId, testChallenge, testAuthType, testAuthTrustLevel, callbackInterface); + contextId = service.AuthUser(authParam, remoteAuthParam, callbackInterface); EXPECT_EQ(contextId, 0); IpcCommon::DeleteAllPermission(); } HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser003, TestSize.Level0) { - UserAuthService service(100, true); - int32_t testUserId = 125; - std::vector testChallenge = {1, 2, 3, 4}; - AuthType testAuthType = FACE; - AuthTrustLevel testAuthTrustLevel = ATL2; + UserAuthService service; + AuthParamInner authParam = { + .userId = 125, + .challenge = {1, 2, 3, 4}, + .authType = FACE, + .authTrustLevel = ATL2, + }; + std::optional remoteAuthParam = std::nullopt; std::shared_ptr context = nullptr; sptr testCallback(new (std::nothrow) MockUserAuthCallback()); @@ -581,8 +585,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser003, TestSize.Level0) ); sptr callbackInterface = testCallback; - uint64_t contextId = service.AuthUser(testUserId, testChallenge, testAuthType, - testAuthTrustLevel, callbackInterface); + uint64_t contextId = service.AuthUser(authParam, remoteAuthParam, callbackInterface); EXPECT_EQ(contextId, 0); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); @@ -595,7 +598,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser003, TestSize.Level0) EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode)); - contextId = service.AuthUser(testUserId, testChallenge, testAuthType, testAuthTrustLevel, callbackInterface); + contextId = service.AuthUser(authParam, remoteAuthParam, callbackInterface); promise.get_future().get(); EXPECT_TRUE(ResourceNodePool::Instance().Delete(60)); @@ -604,7 +607,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser003, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceIdentify001, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; std::vector testChallenge = {1, 2, 3, 4}; AuthType testAuthType = FACE; sptr testCallback(new (std::nothrow) MockUserAuthCallback()); @@ -622,7 +625,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceIdentify001, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceIdentify002, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; std::vector testChallenge = {1, 2, 3, 4}; AuthType testAuthType = FACE; sptr testCallback(nullptr); @@ -653,9 +656,6 @@ static void MockForIdentifyHdi(std::shared_ptr &context, std::promise executorMessages; - executorMessages.resize(1); - scheduleInfo.executorMessages.push_back(executorMessages); context = ContextPool::Instance().Select(contextId).lock(); return HDF_SUCCESS; }); @@ -670,7 +670,7 @@ static void MockForIdentifyHdi(std::shared_ptr &context, std::promise testChallenge = {1, 2, 3, 4}; AuthType testAuthType = FACE; std::shared_ptr context = nullptr; @@ -716,7 +716,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceIdentify003, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceCancelAuthOrIdentify_001, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; uint64_t testContextId = 12355236; EXPECT_EQ(service.CancelAuthOrIdentify(testContextId), CHECK_PERMISSION_FAILED); @@ -727,7 +727,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceCancelAuthOrIdentify_001, TestSize. HWTEST_F(UserAuthServiceTest, UserAuthServiceCancelAuthOrIdentify_002, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; uint64_t testContextId = 0x5678; uint32_t tokenId = 0x1234; @@ -755,7 +755,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceCancelAuthOrIdentify_002, TestSize. HWTEST_F(UserAuthServiceTest, UserAuthServiceGetVersion, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t version = -1; EXPECT_EQ(service.GetVersion(version), CHECK_PERMISSION_FAILED); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); @@ -766,14 +766,14 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetVersion, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_001, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t apiVersion = 10; - AuthParam authParam; + AuthParamInner authParam; authParam.challenge.push_back(1); authParam.challenge.push_back(2); authParam.challenge.push_back(3); authParam.challenge.push_back(4); - authParam.authType.push_back(FACE); + authParam.authTypes.push_back(FACE); authParam.authTrustLevel = ATL2; WidgetParam widgetParam; widgetParam.title = "使用密码验证"; @@ -785,14 +785,14 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_001, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_002, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t apiVersion = 10; - AuthParam authParam; + AuthParamInner authParam; authParam.challenge.push_back(1); authParam.challenge.push_back(2); authParam.challenge.push_back(3); authParam.challenge.push_back(4); - authParam.authType.push_back(FACE); + authParam.authTypes.push_back(FACE); authParam.authTrustLevel = ATL2; WidgetParam widgetParam; widgetParam.title = "使用密码验证"; @@ -810,14 +810,14 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_002, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_003, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t apiVersion = 10; - AuthParam authParam; + AuthParamInner authParam; authParam.challenge.push_back(1); authParam.challenge.push_back(2); authParam.challenge.push_back(3); authParam.challenge.push_back(4); - authParam.authType.push_back(FACE); + authParam.authTypes.push_back(FACE); authParam.authTrustLevel = ATL2; WidgetParam widgetParam; widgetParam.title = "使用密码验证"; @@ -835,14 +835,14 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_003, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_004, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t apiVersion = 10; - AuthParam authParam; + AuthParamInner authParam; authParam.challenge.push_back(1); authParam.challenge.push_back(2); authParam.challenge.push_back(3); authParam.challenge.push_back(4); - authParam.authType.push_back(FACE); + authParam.authTypes.push_back(FACE); authParam.authTrustLevel = ATL2; WidgetParam widgetParam; widgetParam.title = "使用密码验证"; @@ -860,14 +860,14 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_004, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_005, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t apiVersion = 10; - AuthParam authParam; + AuthParamInner authParam; authParam.challenge.push_back(1); authParam.challenge.push_back(2); authParam.challenge.push_back(3); authParam.challenge.push_back(4); - authParam.authType.push_back(FACE); + authParam.authTypes.push_back(FACE); authParam.authTrustLevel = ATL2; WidgetParam widgetParam; widgetParam.title = "使用密码验证"; @@ -886,14 +886,14 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_005, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_006, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t apiVersion = 10; - AuthParam authParam; + AuthParamInner authParam; authParam.challenge.push_back(1); authParam.challenge.push_back(2); authParam.challenge.push_back(3); authParam.challenge.push_back(4); - authParam.authType.push_back(FACE); + authParam.authTypes.push_back(FACE); authParam.authTrustLevel = ATL2; WidgetParam widgetParam; widgetParam.title = "使用密码验证"; @@ -912,9 +912,9 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_006, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_007, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t apiVersion = 10; - AuthParam authParam; + AuthParamInner authParam; authParam.challenge.push_back(1); authParam.challenge.push_back(2); authParam.challenge.push_back(3); @@ -935,10 +935,10 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_007, TestSize.Level0) uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface); EXPECT_NE(conxtId, INVALID_CONTEXT_ID); - authParam.authType.push_back(FACE); - authParam.authType.push_back(FACE); - authParam.authType.push_back(FACE); - authParam.authType.push_back(FACE); + authParam.authTypes.push_back(FACE); + authParam.authTypes.push_back(FACE); + authParam.authTypes.push_back(FACE); + authParam.authTypes.push_back(FACE); conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface); EXPECT_NE(conxtId, INVALID_CONTEXT_ID); IpcCommon::DeleteAllPermission(); @@ -946,14 +946,14 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_007, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_008, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t apiVersion = 10; - AuthParam authParam; + AuthParamInner authParam; authParam.challenge.push_back(1); authParam.challenge.push_back(2); authParam.challenge.push_back(3); authParam.challenge.push_back(4); - authParam.authType.push_back(static_cast(5)); + authParam.authTypes.push_back(static_cast(5)); authParam.authTrustLevel = ATL2; WidgetParam widgetParam; widgetParam.title = "使用密码验证"; @@ -972,14 +972,14 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_008, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_009, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t apiVersion = 10; - AuthParam authParam; + AuthParamInner authParam; authParam.challenge.push_back(1); authParam.challenge.push_back(2); authParam.challenge.push_back(3); authParam.challenge.push_back(4); - authParam.authType.push_back(AuthType::ALL); + authParam.authTypes.push_back(AuthType::ALL); authParam.authTrustLevel = ATL2; WidgetParam widgetParam; widgetParam.title = "使用密码验证"; @@ -998,14 +998,14 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_009, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_010, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t apiVersion = 10; - AuthParam authParam; + AuthParamInner authParam; authParam.challenge.push_back(1); authParam.challenge.push_back(2); authParam.challenge.push_back(3); authParam.challenge.push_back(4); - authParam.authType.push_back(AuthType::PIN); + authParam.authTypes.push_back(AuthType::PIN); authParam.authTrustLevel = (AuthTrustLevel)50000; WidgetParam widgetParam; widgetParam.title = "使用密码验证"; @@ -1024,14 +1024,14 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_010, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_011, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t apiVersion = 10; - AuthParam authParam; + AuthParamInner authParam; authParam.challenge.push_back(1); authParam.challenge.push_back(2); authParam.challenge.push_back(3); authParam.challenge.push_back(4); - authParam.authType.push_back(AuthType::PIN); + authParam.authTypes.push_back(AuthType::PIN); authParam.authTrustLevel = ATL1; WidgetParam widgetParam; widgetParam.title = ""; @@ -1050,14 +1050,14 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_011, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_012, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t apiVersion = 10; - AuthParam authParam; + AuthParamInner authParam; authParam.challenge.push_back(1); authParam.challenge.push_back(2); authParam.challenge.push_back(3); authParam.challenge.push_back(4); - authParam.authType.push_back(AuthType::PIN); + authParam.authTypes.push_back(AuthType::PIN); authParam.authTrustLevel = ATL1; WidgetParam widgetParam; widgetParam.title = "WidgetParamTitle"; @@ -1076,14 +1076,14 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_012, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_013, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t apiVersion = 10; - AuthParam authParam; + AuthParamInner authParam; authParam.challenge.push_back(1); authParam.challenge.push_back(2); authParam.challenge.push_back(3); authParam.challenge.push_back(4); - authParam.authType.push_back(FACE); + authParam.authTypes.push_back(FACE); authParam.authTrustLevel = ATL2; WidgetParam widgetParam; widgetParam.title = "使用密码验证"; @@ -1106,14 +1106,14 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_013, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_014, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t apiVersion = 10; - AuthParam authParam; + AuthParamInner authParam; authParam.challenge.push_back(1); authParam.challenge.push_back(2); authParam.challenge.push_back(3); authParam.challenge.push_back(4); - authParam.authType.push_back(FACE); + authParam.authTypes.push_back(FACE); authParam.authTrustLevel = (AuthTrustLevel)50000; WidgetParam widgetParam; widgetParam.title = "使用密码验证"; @@ -1133,14 +1133,14 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_014, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_015, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t apiVersion = 10; - AuthParam authParam; + AuthParamInner authParam; authParam.challenge.push_back(1); authParam.challenge.push_back(2); authParam.challenge.push_back(3); authParam.challenge.push_back(4); - authParam.authType.push_back(AuthType::FINGERPRINT); + authParam.authTypes.push_back(AuthType::FINGERPRINT); authParam.authTrustLevel = ATL2; WidgetParam widgetParam; widgetParam.title = "使用密码验证"; @@ -1177,11 +1177,11 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_015, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_016, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t apiVersion = 10; - AuthParam authParam; + AuthParamInner authParam; authParam.challenge.push_back(1); - authParam.authType.push_back(AuthType::PIN); + authParam.authTypes.push_back(AuthType::PIN); authParam.authTrustLevel = ATL2; WidgetParam widgetParam; widgetParam.title = "使用密码验证"; @@ -1227,11 +1227,11 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_016, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0017, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t apiVersion = 10; - AuthParam authParam; + AuthParamInner authParam; authParam.challenge.push_back(1); - authParam.authType.push_back(AuthType::FINGERPRINT); + authParam.authTypes.push_back(AuthType::FINGERPRINT); authParam.authTrustLevel = ATL2; WidgetParam widgetParam; widgetParam.title = "使用密码验证"; @@ -1278,11 +1278,11 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0017, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0018, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t apiVersion = 10; - AuthParam authParam; + AuthParamInner authParam; authParam.challenge.push_back(1); - authParam.authType.push_back(AuthType::FINGERPRINT); + authParam.authTypes.push_back(AuthType::FINGERPRINT); authParam.authTrustLevel = ATL2; WidgetParam widgetParam; widgetParam.title = "使用密码验证"; @@ -1328,11 +1328,11 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0018, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0019, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t apiVersion = 10; - AuthParam authParam; + AuthParamInner authParam; authParam.challenge.push_back(1); - authParam.authType.push_back(AuthType::FINGERPRINT); + authParam.authTypes.push_back(AuthType::FINGERPRINT); authParam.authTrustLevel = ATL2; WidgetParam widgetParam; widgetParam.title = "使用密码验证"; @@ -1379,11 +1379,11 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0019, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0020, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t apiVersion = 10; - AuthParam authParam; + AuthParamInner authParam; authParam.challenge.push_back(1); - authParam.authType.push_back(AuthType::PIN); + authParam.authTypes.push_back(AuthType::PIN); authParam.authTrustLevel = ATL2; WidgetParam widgetParam; widgetParam.title = "使用密码验证"; @@ -1428,11 +1428,11 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0020, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0021, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t apiVersion = 10; - AuthParam authParam; + AuthParamInner authParam; authParam.challenge.push_back(1); - authParam.authType.push_back(AuthType::ALL); + authParam.authTypes.push_back(AuthType::ALL); authParam.authTrustLevel = ATL2; WidgetParam widgetParam; widgetParam.title = "使用密码验证"; @@ -1477,11 +1477,11 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0021, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_022, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t apiVersion = 10; - AuthParam authParam; + AuthParamInner authParam; authParam.challenge.push_back(1); - authParam.authType.push_back(AuthType::FINGERPRINT); + authParam.authTypes.push_back(AuthType::FINGERPRINT); authParam.authTrustLevel = ATL2; WidgetParam widgetParam; widgetParam.title = "使用密码验证"; @@ -1526,11 +1526,11 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_022, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_023, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; int32_t apiVersion = 10; - AuthParam authParam; + AuthParamInner authParam; authParam.challenge.push_back(1); - authParam.authType.push_back(AuthType::FINGERPRINT); + authParam.authTypes.push_back(AuthType::FINGERPRINT); authParam.authTrustLevel = ATL2; authParam.reuseUnlockResult.isReuse = true; authParam.reuseUnlockResult.reuseMode = AUTH_TYPE_IRRELEVANT; @@ -1563,7 +1563,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_023, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceNotice_001, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; IpcCommon::AddPermission(SUPPORT_USER_AUTH); int32_t ret = service.Notice(NoticeType::WIDGET_NOTICE, "PIN"); EXPECT_NE(ret, ResultCode::SUCCESS); @@ -1572,7 +1572,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceNotice_001, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceNotice_002, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; IpcCommon::AddPermission(IS_SYSTEM_APP); int32_t ret = service.Notice(NoticeType::WIDGET_NOTICE, "PIN"); EXPECT_EQ(ret, ResultCode::CHECK_PERMISSION_FAILED); @@ -1581,7 +1581,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceNotice_002, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceNotice_003, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(SUPPORT_USER_AUTH); int32_t ret = service.Notice(NoticeType::WIDGET_NOTICE, "PIN"); @@ -1591,14 +1591,14 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceNotice_003, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceRegisterWidgetCallback_001, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; sptr testCallback = nullptr; EXPECT_EQ(service.RegisterWidgetCallback(1, testCallback), ResultCode::CHECK_SYSTEM_APP_FAILED); } HWTEST_F(UserAuthServiceTest, UserAuthServiceRegisterWidgetCallback_002, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; sptr testCallback = nullptr; IpcCommon::AddPermission(IS_SYSTEM_APP); EXPECT_EQ(service.RegisterWidgetCallback(1, testCallback), ResultCode::CHECK_PERMISSION_FAILED); @@ -1607,7 +1607,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceRegisterWidgetCallback_002, TestSiz HWTEST_F(UserAuthServiceTest, UserAuthServiceRegisterWidgetCallback_003, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; sptr testCallback = nullptr; IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(SUPPORT_USER_AUTH); @@ -1617,7 +1617,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceRegisterWidgetCallback_003, TestSiz HWTEST_F(UserAuthServiceTest, UserAuthServiceRegisterWidgetCallback_004, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; sptr testCallback = nullptr; IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(SUPPORT_USER_AUTH); @@ -1627,7 +1627,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceRegisterWidgetCallback_004, TestSiz HWTEST_F(UserAuthServiceTest, UserAuthServiceRegisterWidgetCallback_005, TestSize.Level0) { - UserAuthService service(100, true); + UserAuthService service; sptr testCallback = new MockWidgetCallbackInterface(); IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(SUPPORT_USER_AUTH); @@ -1637,7 +1637,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceRegisterWidgetCallback_005, TestSiz HWTEST_F(UserAuthServiceTest, UserAuthServiceRegisterWidgetCallback_006, TestSize.Level0) { - UserAuthService service(200, true); + UserAuthService service; sptr testCallback = nullptr; IpcCommon::AddPermission(IS_SYSTEM_APP); EXPECT_EQ(service.RegisterWidgetCallback(1, testCallback), ResultCode::CHECK_PERMISSION_FAILED); @@ -1646,7 +1646,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceRegisterWidgetCallback_006, TestSiz HWTEST_F(UserAuthServiceTest, UserAuthServiceRegistEventListerner_001, TestSize.Level0) { - UserAuthService service(200, true); + UserAuthService service; sptr testCallback = nullptr; std::vector authTypeList; IpcCommon::AddPermission(IS_SYSTEM_APP); @@ -1656,7 +1656,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceRegistEventListerner_001, TestSize. HWTEST_F(UserAuthServiceTest, UserAuthServiceRegistEventListerner_002, TestSize.Level0) { - UserAuthService service(200, true); + UserAuthService service; sptr testCallback = new MockAuthEventListener(); std::vector authTypeList; IpcCommon::AddPermission(IS_SYSTEM_APP); @@ -1667,7 +1667,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceRegistEventListerner_002, TestSize. HWTEST_F(UserAuthServiceTest, UserAuthServiceRegistEventListerner_003, TestSize.Level0) { - UserAuthService service(200, true); + UserAuthService service; sptr testCallback = new MockAuthEventListener(); std::vector authTypeList; authTypeList.push_back(AuthType::PIN); @@ -1681,7 +1681,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceRegistEventListerner_003, TestSize. HWTEST_F(UserAuthServiceTest, UserAuthServiceRegistEventListerner_004, TestSize.Level0) { - UserAuthService service(200, true); + UserAuthService service; sptr testCallback = new MockAuthEventListener(); std::vector authTypeList; authTypeList.push_back(AuthType::PIN); @@ -1694,7 +1694,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceRegistEventListerner_004, TestSize. HWTEST_F(UserAuthServiceTest, UserAuthServiceUnRegistEventListerner_001, TestSize.Level0) { - UserAuthService service(200, true); + UserAuthService service; sptr testCallback = nullptr; IpcCommon::AddPermission(IS_SYSTEM_APP); EXPECT_EQ(service.UnRegistUserAuthSuccessEventListener(testCallback), ResultCode::INVALID_PARAMETERS); @@ -1703,7 +1703,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceUnRegistEventListerner_001, TestSiz HWTEST_F(UserAuthServiceTest, UserAuthServiceUnRegistEventListerner_002, TestSize.Level0) { - UserAuthService service(200, true); + UserAuthService service; sptr testCallback = new MockAuthEventListener(); IpcCommon::AddPermission(IS_SYSTEM_APP); EXPECT_EQ(service.UnRegistUserAuthSuccessEventListener(testCallback), ResultCode::CHECK_PERMISSION_FAILED); @@ -1712,7 +1712,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceUnRegistEventListerner_002, TestSiz HWTEST_F(UserAuthServiceTest, UserAuthServiceUnRegistEventListerner_003, TestSize.Level0) { - UserAuthService service(200, true); + UserAuthService service; sptr testCallback = new MockAuthEventListener(); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); EXPECT_EQ(service.UnRegistUserAuthSuccessEventListener(testCallback), ResultCode::GENERAL_ERROR); @@ -1721,7 +1721,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceUnRegistEventListerner_003, TestSiz HWTEST_F(UserAuthServiceTest, UserAuthServiceUnRegistEventListerner_004, TestSize.Level0) { - UserAuthService service(200, true); + UserAuthService service; sptr testCallback = new MockAuthEventListener(); std::vector authTypeList; authTypeList.push_back(AuthType::PIN); @@ -1735,7 +1735,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceUnRegistEventListerner_004, TestSiz HWTEST_F(UserAuthServiceTest, UserAuthServiceSetGlobalConfigParam, TestSize.Level0) { - UserAuthService service(200, true); + UserAuthService service; GlobalConfigParam param = {}; EXPECT_EQ(service.SetGlobalConfigParam(param), ResultCode::CHECK_PERMISSION_FAILED); diff --git a/test/unittest/services/src/user_auth_stub_test.cpp b/test/unittest/services/src/user_auth_stub_test.cpp index a43ed87c14fe6542b6c8af01f4abab80f93eebd7..0bf75de169adb151b9907cc7fd2056835a4ed081 100644 --- a/test/unittest/services/src/user_auth_stub_test.cpp +++ b/test/unittest/services/src/user_auth_stub_test.cpp @@ -344,16 +344,15 @@ HWTEST_F(UserAuthStubTest, UserAuthStubAuthUserStub002, TestSize.Level0) sptr callback(new (std::nothrow) MockUserAuthCallback()); EXPECT_NE(callback, nullptr); MockUserAuthService service; - EXPECT_CALL(service, AuthUser(_, _, _, _, _)).Times(1); + EXPECT_CALL(service, AuthUser(_, _, _)).Times(1); ON_CALL(service, AuthUser) .WillByDefault( - [&testUserId, &testChallenge, &testAuthType, &testAtl, &testContextId](int32_t userId, - const std::vector &challenge, AuthType authType, AuthTrustLevel authTrustLevel, - sptr &callback) { - EXPECT_EQ(userId, testUserId); - EXPECT_THAT(challenge, ElementsAreArray(testChallenge)); - EXPECT_EQ(authType, testAuthType); - EXPECT_EQ(authTrustLevel, testAtl); + [&testUserId, &testChallenge, &testAuthType, &testAtl, &testContextId](AuthParamInner &authParam, + std::optional &remoteAuthParam, sptr &callback) { + EXPECT_EQ(authParam.userId, testUserId); + EXPECT_THAT(authParam.challenge, ElementsAreArray(testChallenge)); + EXPECT_EQ(authParam.authType, testAuthType); + EXPECT_EQ(authParam.authTrustLevel, testAtl); if (callback != nullptr) { Attributes attr; callback->OnResult(SUCCESS, attr); diff --git a/test/unittest/services/src/user_idm_service_test.cpp b/test/unittest/services/src/user_idm_service_test.cpp index f39a05f4baf1ffd84e8dd53b178e505916b67d91..a1caec0aeb0241ca4879ab248f404800ddd8b3ad 100644 --- a/test/unittest/services/src/user_idm_service_test.cpp +++ b/test/unittest/services/src/user_idm_service_test.cpp @@ -354,9 +354,6 @@ static void MockForAddCredentialHdi(std::shared_ptr &context, std::prom .WillOnce([&context](const std::vector &authToken, const HdiEnrollParam ¶m, HdiScheduleInfo &info) { info.executorIndexes.push_back(testExecutorIndex); - std::vector executorMessages; - executorMessages.resize(1); - info.executorMessages.push_back(executorMessages); info.scheduleId = testscheduleId; info.authType = HdiAuthType::FACE; auto contextList = ContextPool::Instance().Select(CONTEXT_ENROLL);