1 /* 2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef USER_AUTH_SERVICE_H 17 #define USER_AUTH_SERVICE_H 18 19 #include "user_auth_stub.h" 20 21 #include <string> 22 #include <system_ability.h> 23 #include <system_ability_definition.h> 24 25 #include "context_callback.h" 26 #include "context_factory.h" 27 #include "context_pool.h" 28 #include "resource_node_pool.h" 29 #include "user_idm_database.h" 30 31 namespace OHOS { 32 namespace UserIam { 33 namespace UserAuth { 34 class UserAuthService : public SystemAbility, public UserAuthStub, public NoCopyable { 35 public: 36 DECLARE_SYSTEM_ABILITY(UserAuthService); 37 explicit UserAuthService(int32_t systemAbilityId, bool runOnCreate = false); 38 ~UserAuthService() override = default; 39 int32_t GetAvailableStatus(int32_t apiVersion, AuthType authType, AuthTrustLevel authTrustLevel) override; 40 void GetProperty(int32_t userId, AuthType authType, 41 const std::vector<Attributes::AttributeKey> &keys, 42 sptr<GetExecutorPropertyCallbackInterface> &callback) override; 43 void SetProperty(int32_t userId, AuthType authType, const Attributes &attributes, 44 sptr<SetExecutorPropertyCallbackInterface> &callback) override; 45 uint64_t AuthUser(int32_t userId, const std::vector<uint8_t> &challenge, AuthType authType, 46 AuthTrustLevel authTrustLevel, sptr<UserAuthCallbackInterface> &callback) override; 47 uint64_t Auth(int32_t apiVersion, const std::vector<uint8_t> &challenge, AuthType authType, 48 AuthTrustLevel authTrustLevel, sptr<UserAuthCallbackInterface> &callback) override; 49 uint64_t AuthWidget(int32_t apiVersion, const AuthParam &authParam, 50 const WidgetParam &widgetParam, sptr<UserAuthCallbackInterface> &callback) override; 51 uint64_t Identify(const std::vector<uint8_t> &challenge, AuthType authType, 52 sptr<UserAuthCallbackInterface> &callback) override; 53 int32_t CancelAuthOrIdentify(uint64_t contextId) override; 54 int32_t GetVersion(int32_t &version) override; 55 int32_t Notice(NoticeType noticeType, const std::string &eventData) override; 56 int32_t RegisterWidgetCallback(int32_t version, sptr<WidgetCallbackInterface> &callback) override; 57 58 protected: 59 void OnStart() override; 60 void OnStop() override; 61 62 private: 63 std::shared_ptr<ContextCallback> GetAuthContextCallback(int32_t apiVersion, 64 const std::vector<uint8_t> &challenge, AuthType authType, AuthTrustLevel authTrustLevel, 65 sptr<UserAuthCallbackInterface> &callback); 66 std::shared_ptr<ContextCallback> GetAuthContextCallback(int32_t apiVersion, 67 const AuthParam &authParam, const WidgetParam &widgetParam, sptr<UserAuthCallbackInterface> &callback); 68 bool CheckAuthTrustLevel(AuthTrustLevel authTrustLevel); 69 bool CheckSingeFaceOrFinger(const std::vector<AuthType> &authType); 70 int32_t CheckAuthWidgetType(const std::vector<AuthType> &authType); 71 int32_t CheckAuthWidgetParam( 72 int32_t userId, const AuthParam &authParam, const WidgetParam &widgetParam, std::vector<AuthType> &validType); 73 uint64_t StartWidgetContext(const std::shared_ptr<ContextCallback> &contextCallback, const AuthParam &authParam, 74 const WidgetParam &widgetParam, std::vector<AuthType> &validType, 75 ContextFactory::AuthWidgetContextPara ¶); 76 uint64_t StartAuthContext(int32_t apiVersion, Authentication::AuthenticationPara para, 77 const std::shared_ptr<ContextCallback> &contextCallback); 78 bool Insert2ContextPool(const std::shared_ptr<Context> &context); 79 bool CheckCallerIsSystemApp(); 80 int32_t CheckAuthPermissionAndParam(int32_t authType, bool isBundleName, const std::string &callerName, 81 AuthTrustLevel authTrustLevel); 82 }; 83 } // namespace UserAuth 84 } // namespace UserIam 85 } // namespace OHOS 86 #endif // USER_AUTH_SERVICE_H