/* * Copyright (c) 2022-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 USER_AUTH_SERVICE_H #define USER_AUTH_SERVICE_H #include "user_auth_stub.h" #include #include #include #include "context_callback.h" #include "context_factory.h" #include "context_pool.h" #include "resource_node_pool.h" #include "user_idm_database.h" #include "attributes.h" namespace OHOS { namespace UserIam { namespace UserAuth { class UserAuthService : public SystemAbility, public UserAuthStub, public NoCopyable { public: DECLARE_SYSTEM_ABILITY(UserAuthService); static std::shared_ptr GetInstance(); UserAuthService(); ~UserAuthService() override = default; int32_t GetAvailableStatus(int32_t apiVersion, int32_t userId, AuthType authType, AuthTrustLevel authTrustLevel) override; int32_t GetAvailableStatus(int32_t apiVersion, AuthType authType, AuthTrustLevel authTrustLevel) override; void GetProperty(int32_t userId, AuthType authType, const std::vector &keys, sptr &callback) override; void GetPropertyById(uint64_t credentialId, const std::vector &keys, sptr &callback) override; void SetProperty(int32_t userId, AuthType authType, const Attributes &attributes, 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 AuthParamInner &authParam, const WidgetParam &widgetParam, sptr &callback) override; uint64_t Identify(const std::vector &challenge, AuthType authType, sptr &callback) override; int32_t CancelAuthOrIdentify(uint64_t contextId) override; int32_t GetVersion(int32_t &version) override; int32_t Notice(NoticeType noticeType, const std::string &eventData) override; int32_t RegisterWidgetCallback(int32_t version, sptr &callback) override; int32_t GetEnrolledState(int32_t apiVersion, AuthType authType, EnrolledState &enrolledState) override; int32_t RegistUserAuthSuccessEventListener(const std::vector &authType, 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; protected: void OnStart() override; void OnStop() override; private: std::shared_ptr GetAuthContextCallback(int32_t apiVersion, const std::vector &challenge, AuthType authType, AuthTrustLevel authTrustLevel, sptr &callback); std::shared_ptr GetAuthContextCallback(int32_t apiVersion, const AuthParamInner &authParam, const WidgetParam &widgetParam, sptr &callback); bool CheckAuthTrustLevel(AuthTrustLevel authTrustLevel); bool CheckSingeFaceOrFinger(const std::vector &authType); bool CheckPrivatePinEnroll(const std::vector &authType, std::vector &validType); int32_t CheckAuthWidgetType(const std::vector &authType); int32_t CheckAuthPermissionAndParam(const AuthParamInner &authParam, const WidgetParam &widgetParam, bool isBackgroundApplication); 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, ResultCode &failReason); 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, AuthTrustLevel authTrustLevel); 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 AuthParamInner &authParam, const WidgetParam &widgetParam, std::vector &validType); int32_t GetCallerInfo(bool isUserIdSpecified, int32_t userId, ContextFactory::AuthWidgetContextPara ¶, bool &isBackgroundApplication, std::shared_ptr &contextCallback); int32_t CheckCallerPermissionForPrivatePin(const AuthParamInner &authParam); void FillGetPropertyKeys(AuthType authType, const std::vector &keys, std::vector &uint32Keys); void FillGetPropertyValue(AuthType authType, const std::vector &keys, Attributes &values); bool CompleteRemoteAuthParam(RemoteAuthParam &remoteAuthParam, const std::string &localNetworkId); int32_t PrepareRemoteAuthInner(const std::string &networkId); bool GetAndUpateOsAccountVerifiedState(int32_t userId); std::shared_ptr GetResourseNode(AuthType authType); int32_t GetAvailableStatusInner(int32_t apiVersion, int32_t userId, AuthType authType, AuthTrustLevel authTrustLevel); void ProcessPinExpired(int32_t ret, const AuthParamInner &authParam, std::vector &validType, ContextFactory::AuthWidgetContextPara ¶); void GetPropertyInner(AuthType authType, const std::vector &keys, sptr &callback, std::vector &templateIds); static std::mutex mutex_; static std::shared_ptr instance_; bool osAccountVerifiedState_ = false; }; } // namespace UserAuth } // namespace UserIam } // namespace OHOS #endif // USER_AUTH_SERVICE_H