• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 userId System userId, generated by account subsystem.
74      * @param challenge auth challenge which can prevent replay attacks.
75      * @param authType Auth type supported by executor.
76      * @param atl Auth trust level.
77      * @param callback Callback of user authentication result.
78      * @return Return context ID of authentication.
79      */
80     virtual uint64_t BeginAuthentication(int32_t userId, const std::vector<uint8_t> &challenge, AuthType authType,
81         AuthTrustLevel atl, const std::shared_ptr<AuthenticationCallback> &callback) = 0;
82 
83     /**
84      * @brief Cancel user authentication.
85      *
86      * @param contextId Indicates the authenticate context index.
87      * @return Return cancelAuthentication result(0:success; other:failed).
88      */
89     virtual int32_t CancelAuthentication(uint64_t contextId) = 0;
90 
91     /**
92      * @brief Begin user identification according to authType.
93      *
94      * @param challenge auth challenge which can prevent replay attacks.
95      * @param authType Auth type supported by executor.
96      * @param callback Callback of user identification result.
97      * @return Return context ID of authentication.
98      */
99     virtual uint64_t BeginIdentification(const std::vector<uint8_t> &challenge, AuthType authType,
100         const std::shared_ptr<IdentificationCallback> &callback) = 0;
101 
102     /**
103      * @brief Cancel user identification.
104      *
105      * @param contextId Indicates the identification context index.
106      * @return Return CancelIdentification result(0:success; other:failed).
107      */
108     virtual int32_t CancelIdentification(uint64_t contextId) = 0;
109 };
110 } // namespace UserAuth
111 } // namespace UserIam
112 } // namespace OHOS
113 #endif // USER_AUTH_CLIENT_H