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 Set executor property.
62      *
63      * @param userId System userId, generated by account subsystem.
64      * @param request AuthType, propertyMode and attributes to set property.
65      * @param callback Callback of set property result.
66      */
67     virtual void SetProperty(int32_t userId, const SetPropertyRequest &request,
68         const std::shared_ptr<SetPropCallback> &callback) = 0;
69 
70     /**
71      * @brief Begin user authentication according to ATL and authType.
72      *
73      * @param authParam, authentication paramater.
74      * @param callback Callback of user authentication result.
75      * @return Return context ID of authentication.
76      */
77     virtual uint64_t BeginAuthentication(const AuthParam &authParam,
78         const std::shared_ptr<AuthenticationCallback> &callback) = 0;
79 
80     /**
81      * @brief Cancel user authentication.
82      *
83      * @param contextId Indicates the authenticate context index.
84      * @return Return cancelAuthentication result(0:success; other:failed).
85      */
86     virtual int32_t CancelAuthentication(uint64_t contextId) = 0;
87 
88     /**
89      * @brief Begin user identification according to authType.
90      *
91      * @param challenge auth challenge which can prevent replay attacks.
92      * @param authType Auth type supported by executor.
93      * @param callback Callback of user identification result.
94      * @return Return context ID of authentication.
95      */
96     virtual uint64_t BeginIdentification(const std::vector<uint8_t> &challenge, AuthType authType,
97         const std::shared_ptr<IdentificationCallback> &callback) = 0;
98 
99     /**
100      * @brief Cancel user identification.
101      *
102      * @param contextId Indicates the identification context index.
103      * @return Return CancelIdentification result(0:success; other:failed).
104      */
105     virtual int32_t CancelIdentification(uint64_t contextId) = 0;
106 
107     /**
108      * @brief Regist authentication success event listener, support repeated registration.
109      *
110      * @param authType Auth type list supported by executor, auth type include PIN, FACE, FINGERPRINT.
111      * @param listener Callback of authentication success event.
112      * @return Return regist result(0:success; other:failed).
113      */
114     virtual int32_t RegistUserAuthSuccessEventListener(const std::vector<AuthType> &authType,
115         const sptr<AuthEventListenerInterface> &listener) = 0;
116 
117     /**
118      * @brief unRegist authentication success event listener.
119      *
120      * @param listener Callback of authentication success event.
121      * @return Return unregist result(0:success; other:failed).
122      */
123     virtual int32_t UnRegistUserAuthSuccessEventListener(
124         const sptr<AuthEventListenerInterface> &listener) = 0;
125 
126     /**
127      * @brief Set global config param.
128      *
129      * @param param The value of global config parameter.
130      * @return Return set result(0:success; other:failed).
131      */
132     virtual int32_t SetGlobalConfigParam(const GlobalConfigParam &param) = 0;
133 
134     /**
135      * @brief Prepare remote authentication.
136      * @param networkId Network id of remote device.
137      * @param callback Callback of prepare remote authentication result.
138      *
139      * @return Return prepare remote authentication result(0:success; other:failed).
140      */
141     virtual int32_t PrepareRemoteAuth(const std::string &networkId,
142         const std::shared_ptr<PrepareRemoteAuthCallback> &callback) = 0;
143 
144     /**
145      * @brief Begin widget authentication.
146      *
147      * @param authParam, authentication paramater for widgetAuth.
148      * @param widgetParam, widget paramater for widgetAuth.
149      * @param callback Callback of user authentication result.
150      *
151      * @return Return context ID of authentication.
152      */
153     virtual uint64_t BeginWidgetAuth(const WidgetAuthParam &authParam, const WidgetParam &widgetParam,
154          const std::shared_ptr<AuthenticationCallback> &callback) = 0;
155 
156     /**
157      * @brief Get available status.
158      *
159      * @param userId System userId, generated by account subsystem.
160      * @param authType Auth type supported by executor.
161      * @param authTrustLevel, auth trust level.
162      *
163      * @return Return get result(0:success; other:failed).
164      */
165     virtual int32_t GetAvailableStatus(int32_t userId, AuthType authType, AuthTrustLevel authTrustLevel) = 0;
166 };
167 } // namespace UserAuth
168 } // namespace UserIam
169 } // namespace OHOS
170 #endif // USER_AUTH_CLIENT_H