1 /* 2 * Copyright (c) 2022 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 /** 17 * @file user_auth_client.h 18 * 19 * @brief The definition of user auth client. 20 * @since 3.1 21 * @version 3.2 22 */ 23 24 #ifndef USER_AUTH_CLIENT_H 25 #define USER_AUTH_CLIENT_H 26 27 #include <memory> 28 #include <vector> 29 30 #include "user_auth_client_callback.h" 31 #include "user_auth_client_defines.h" 32 33 namespace OHOS { 34 namespace UserIam { 35 namespace UserAuth { 36 class UserAuthClient { 37 public: 38 /** 39 * @brief Get userAuth client's instance. 40 * 41 * @return UserAuthClient's instance. 42 */ 43 static UserAuthClient &GetInstance(); 44 45 /** 46 * @brief Deconstructor. 47 */ 48 virtual ~UserAuthClient() = default; 49 50 /** 51 * @brief Get executor property. 52 * 53 * @param userId System userId, generated by account subsystem. 54 * @param request AuthType and AttributeKey to get property. 55 * @param callback Callback of get property result. 56 */ 57 virtual void GetProperty(int32_t userId, const GetPropertyRequest &request, 58 const std::shared_ptr<GetPropCallback> &callback) = 0; 59 60 /** 61 * @brief Get executor property. 62 * 63 * @param credentialId credential id, generated by useriam subsystem. 64 * @param key AttributeKey to get property. 65 * @param callback Callback of get property result. 66 */ 67 virtual void GetPropertyById(uint64_t credentialId, const std::vector<Attributes::AttributeKey> &keys, 68 const std::shared_ptr<GetPropCallback> &callback) = 0; 69 70 /** 71 * @brief Set executor property. 72 * 73 * @param userId System userId, generated by account subsystem. 74 * @param request AuthType, propertyMode and attributes to set property. 75 * @param callback Callback of set property result. 76 */ 77 virtual void SetProperty(int32_t userId, const SetPropertyRequest &request, 78 const std::shared_ptr<SetPropCallback> &callback) = 0; 79 80 /** 81 * @brief Begin user authentication according to ATL and authType. 82 * 83 * @param authParam, authentication paramater. 84 * @param callback Callback of user authentication result. 85 * @return Return context ID of authentication. 86 */ 87 virtual uint64_t BeginAuthentication(const AuthParam &authParam, 88 const std::shared_ptr<AuthenticationCallback> &callback) = 0; 89 90 /** 91 * @brief Cancel user authentication. 92 * 93 * @param contextId Indicates the authenticate context index. 94 * @return Return cancelAuthentication result(0:success; other:failed). 95 */ 96 virtual int32_t CancelAuthentication(uint64_t contextId) = 0; 97 98 /** 99 * @brief Begin user identification according to authType. 100 * 101 * @param challenge auth challenge which can prevent replay attacks. 102 * @param authType Auth type supported by executor. 103 * @param callback Callback of user identification result. 104 * @return Return context ID of authentication. 105 */ 106 virtual uint64_t BeginIdentification(const std::vector<uint8_t> &challenge, AuthType authType, 107 const std::shared_ptr<IdentificationCallback> &callback) = 0; 108 109 /** 110 * @brief Cancel user identification. 111 * 112 * @param contextId Indicates the identification context index. 113 * @return Return CancelIdentification result(0:success; other:failed). 114 */ 115 virtual int32_t CancelIdentification(uint64_t contextId) = 0; 116 117 /** 118 * @brief Regist authentication success event listener, support repeated registration. Note that you need to listen 119 * useriam process status, and if the process is restarted abnormally, need to re-register the listener. 120 * 121 * @param authTypes Auth type list supported by executor, auth type include PIN, FACE, FINGERPRINT. 122 * @param listener Callback of authentication success event. 123 * @return Return regist result(0:success; other:failed). 124 */ 125 virtual int32_t RegistUserAuthSuccessEventListener(const std::vector<AuthType> &authTypes, 126 const std::shared_ptr<AuthSuccessEventListener> &listener) = 0; 127 128 /** 129 * @brief unRegist authentication success event listener. 130 * 131 * @param listener Callback of authentication success event. 132 * @return Return unregist result(0:success; other:failed). 133 */ 134 virtual int32_t UnRegistUserAuthSuccessEventListener( 135 const std::shared_ptr<AuthSuccessEventListener> &listener) = 0; 136 137 /** 138 * @brief Set global config param. 139 * 140 * @param param The value of global config parameter. 141 * @return Return set result(0:success; other:failed). 142 */ 143 virtual int32_t SetGlobalConfigParam(const GlobalConfigParam ¶m) = 0; 144 145 /** 146 * @brief Prepare remote authentication. 147 * @param networkId Network id of remote device. 148 * @param callback Callback of prepare remote authentication result. 149 * 150 * @return Return prepare remote authentication result(0:success; other:failed). 151 */ 152 virtual int32_t PrepareRemoteAuth(const std::string &networkId, 153 const std::shared_ptr<PrepareRemoteAuthCallback> &callback) = 0; 154 155 /** 156 * @brief Begin widget authentication. 157 * 158 * @param authParam, authentication paramater for widgetAuth. 159 * @param widgetParam, widget paramater for widgetAuth. 160 * @param callback Callback of user authentication result. 161 * 162 * @return Return context ID of authentication. 163 */ 164 virtual uint64_t BeginWidgetAuth(const WidgetAuthParam &authParam, const WidgetParam &widgetParam, 165 const std::shared_ptr<AuthenticationCallback> &callback) = 0; 166 167 /** 168 * @brief Get available status. 169 * 170 * @param userId System userId, generated by account subsystem. 171 * @param authType Auth type supported by executor. 172 * @param authTrustLevel, auth trust level. 173 * 174 * @return Return get result(0:success; other:failed). 175 */ 176 virtual int32_t GetAvailableStatus(int32_t userId, AuthType authType, AuthTrustLevel authTrustLevel) = 0; 177 178 /** 179 * @brief Query reusable authentication result. 180 * @param authParam, authentication paramater for widgetAuth. 181 * @param extraInfo reuse authentication token. 182 * 183 * @return Return query result(0:success; other:failed). 184 */ 185 virtual int32_t QueryReusableAuthResult(const WidgetAuthParam &authParam, std::vector<uint8_t> &token) = 0; 186 }; 187 } // namespace UserAuth 188 } // namespace UserIam 189 } // namespace OHOS 190 #endif // USER_AUTH_CLIENT_H