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.
119      *
120      * @param authType Auth type list supported by executor, auth type include PIN, FACE, FINGERPRINT.
121      * @param listener Callback of authentication success event.
122      * @return Return regist result(0:success; other:failed).
123      */
124     virtual int32_t RegistUserAuthSuccessEventListener(const std::vector<AuthType> &authType,
125         const sptr<AuthEventListenerInterface> &listener) = 0;
126 
127     /**
128      * @brief unRegist authentication success event listener.
129      *
130      * @param listener Callback of authentication success event.
131      * @return Return unregist result(0:success; other:failed).
132      */
133     virtual int32_t UnRegistUserAuthSuccessEventListener(
134         const sptr<AuthEventListenerInterface> &listener) = 0;
135 
136     /**
137      * @brief Set global config param.
138      *
139      * @param param The value of global config parameter.
140      * @return Return set result(0:success; other:failed).
141      */
142     virtual int32_t SetGlobalConfigParam(const GlobalConfigParam &param) = 0;
143 
144     /**
145      * @brief Prepare remote authentication.
146      * @param networkId Network id of remote device.
147      * @param callback Callback of prepare remote authentication result.
148      *
149      * @return Return prepare remote authentication result(0:success; other:failed).
150      */
151     virtual int32_t PrepareRemoteAuth(const std::string &networkId,
152         const std::shared_ptr<PrepareRemoteAuthCallback> &callback) = 0;
153 
154     /**
155      * @brief Begin widget authentication.
156      *
157      * @param authParam, authentication paramater for widgetAuth.
158      * @param widgetParam, widget paramater for widgetAuth.
159      * @param callback Callback of user authentication result.
160      *
161      * @return Return context ID of authentication.
162      */
163     virtual uint64_t BeginWidgetAuth(const WidgetAuthParam &authParam, const WidgetParam &widgetParam,
164          const std::shared_ptr<AuthenticationCallback> &callback) = 0;
165 
166     /**
167      * @brief Get available status.
168      *
169      * @param userId System userId, generated by account subsystem.
170      * @param authType Auth type supported by executor.
171      * @param authTrustLevel, auth trust level.
172      *
173      * @return Return get result(0:success; other:failed).
174      */
175     virtual int32_t GetAvailableStatus(int32_t userId, AuthType authType, AuthTrustLevel authTrustLevel) = 0;
176 };
177 } // namespace UserAuth
178 } // namespace UserIam
179 } // namespace OHOS
180 #endif // USER_AUTH_CLIENT_H