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_IDM_INTERFACE_H
17 #define USER_IDM_INTERFACE_H
18 
19 #include <cstdint>
20 
21 #include "refbase.h"
22 #include "user_idm_callback_interface.h"
23 #include "user_idm_interface_ipc_interface_code.h"
24 
25 namespace OHOS {
26 namespace UserIam {
27 namespace UserAuth {
28 class UserIdmInterface : public IRemoteBroker {
29 public:
30     struct CredentialPara {
31         AuthType authType {ALL};
32         PinSubType pinType {PIN_SIX};
33         std::vector<uint8_t> token;
34     };
35 
36     /*
37      * start an IDM operation to obtain challenge value, a challenge value of 0 indicates that open session failed.
38      *
39      * param userId user id.
40      * return challenge value.
41      */
42     virtual int32_t OpenSession(int32_t userId, std::vector<uint8_t> &challenge) = 0;
43 
44     /*
45      * end an IDM operation.
46      *
47      * param userId user id.
48      */
49     virtual void CloseSession(int32_t userId) = 0;
50 
51     /*
52      * get authentication information.
53      *
54      * param userId current user id.
55      * param authType credential type.
56      * param callback returns all registered credential information of this type for the specific user.
57      */
58     virtual int32_t GetCredentialInfo(int32_t userId, AuthType authType,
59         const sptr<IdmGetCredInfoCallbackInterface> &callback) = 0;
60 
61     /*
62      * get user security ID.
63      *
64      * param userId current user id.
65      * param callback returns all registered security information for the specific user.
66      */
67     virtual int32_t GetSecInfo(int32_t userId, const sptr<IdmGetSecureUserInfoCallbackInterface> &callback) = 0;
68 
69     /**
70      * add user credential information, pass in credential addition method and credential information
71      * (credential type, subtype, if adding user's non password credentials, pass in password authentication token),
72      * and get the result / acquire info callback.
73      *
74      * param userId user id.
75      * param credInfo Incoming credential addition method and credential information
76      * (credential type, subtype, password authentication token).
77      * param callback get results / acquire info callback.
78      */
79     virtual void AddCredential(int32_t userId, const CredentialPara &credPara,
80         const sptr<IdmCallbackInterface> &callback, bool isUpdate) = 0;
81     /*
82      * update user credential information.
83      *
84      * param userId user id.
85      * param credInfo Incoming credential addition method and credential information
86      * (credential type, subtype, password authentication token).
87      * param callback update results / acquire info callback.
88      */
89     virtual void UpdateCredential(int32_t userId, const CredentialPara &credPara,
90         const sptr<IdmCallbackInterface> &callback) = 0;
91 
92     /*
93      * Cancel entry and pass in user id.
94      *
95      * param userId user id.
96      */
97     virtual int32_t Cancel(int32_t userId) = 0;
98 
99     /*
100      * enforce delete the user credential information, pass in the callback,
101      * and obtain the deletion result through the callback.
102      *
103      * param authToken user password authentication token.
104      * param callback get deletion result through callback.
105      */
106     virtual int32_t EnforceDelUser(int32_t userId, const sptr<IdmCallbackInterface> &callback) = 0;
107 
108     /*
109      * delete all users credential information, pass in the user password authentication token and callback,
110      * and obtain the deletion result through the callback.
111      *
112      * param userId user id.
113      * param authToken user password authentication token.
114      * param callback get deletion result through callback.
115      */
116     virtual void DelUser(int32_t userId, const std::vector<uint8_t> authToken,
117         const sptr<IdmCallbackInterface> &callback) = 0;
118 
119     /*
120      * delete the user credential information, pass in the credential id, password authentication token and callback,
121      * and obtain the deletion result through the callback.
122      * Only deleting non password credentials is supported.
123      *
124      * param userId user id.
125      * param credentialId credential index.
126      * param authToken password authentication token.
127      * param callback get deletion result through callback.
128      */
129     virtual void DelCredential(int32_t userId, uint64_t credentialId,
130         const std::vector<uint8_t> &authToken, const sptr<IdmCallbackInterface> &callback) = 0;
131 
132     /*
133      * delete the user redundancy credential information, pass in callback,
134      * and obtain the deletion result through the callback.
135      * Only deleting the credential without account information is supported.
136      *
137      * param callback get deletion result through callback.
138      */
139     virtual void ClearRedundancyCredential(const sptr<IdmCallbackInterface> &callback) = 0;
140     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.useridm.IUserIDM");
141 };
142 } // namespace UserAuth
143 } // namespace UserIam
144 } // namespace OHOS
145 #endif // USER_IDM_INTERFACE_H