1 /*
2  * Copyright (c) 2024 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 FSS_SECURITY_MERGE_IAMCLIENT_H
17 #define FSS_SECURITY_MERGE_IAMCLIENT_H
18 
19 #include <condition_variable>
20 #include <mutex>
21 
22 #ifdef USER_AUTH_FRAMEWORK
23 #include "iam_common_defines.h"
24 #include "user_idm_client.h"
25 #include "user_idm_client_callback.h"
26 #include "user_idm_client_defines.h"
27 #endif
28 
29 namespace OHOS {
30 namespace StorageDaemon {
31 
32 const int8_t GET_SEC_TIMEOUT = 10;
33 
34 enum UserSecStatus {
35     SUCCESS,
36     FAILED
37 };
38 
39 enum SecUserInfoState {
40     SEC_USER_INFO_SUCCESS,
41     SEC_USER_INFO_FAILED
42 };
43 
44 #ifdef USER_AUTH_FRAMEWORK
45 class UserSecCallback : public UserIam::UserAuth::GetSecUserInfoCallback {
46 public:
UserSecCallback()47     UserSecCallback()
48     {
49         secureUid_ = { 0 };
50     }
~UserSecCallback()51     virtual ~UserSecCallback()
52     {
53         secureUid_ = { 0 };
54     }
55     void OnSecUserInfo(const UserIam::UserAuth::SecUserInfo &info) override;
56     uint64_t GetSecureUid();
57 
58 private:
59     uint64_t secureUid_;
60 };
61 
62 class UserEnrollCallback : public UserIam::UserAuth::GetSecUserInfoCallback {
63 public:
UserEnrollCallback()64     UserEnrollCallback()
65     {
66         info_ = {};
67     }
~UserEnrollCallback()68     virtual ~UserEnrollCallback()
69     {
70         info_ = {};
71     }
72     void OnSecUserInfo(const UserIam::UserAuth::SecUserInfo &info) override;
73     UserIam::UserAuth::SecUserInfo GetSecUserInfo();
74 
75 private:
76     UserIam::UserAuth::SecUserInfo info_;
77 };
78 
79 #endif
80 
81 class IamClient {
82 public:
GetInstance()83     static IamClient &GetInstance()
84     {
85         static IamClient instance;
86         return instance;
87     }
88 
89     bool GetSecureUid(uint32_t userId, uint64_t &secureUid);
90     bool GetSecUserInfo(uint32_t userId, UserIam::UserAuth::SecUserInfo &info);
91     bool HasPinProtect(uint32_t userId);
92     int HasFaceFinger(uint32_t userId, bool &isExist);
93 
94     int32_t NotifyGetSecureUid();
95     int32_t NotifyGetSecUserInfo();
96 
97 private:
98     IamClient();
99     ~IamClient();
100     IamClient(const IamClient &) = delete;
101     IamClient &operator=(const IamClient &) = delete;
102 
103     SecUserInfoState secUserInfoState_ = SEC_USER_INFO_FAILED;
104     UserSecStatus secureUidStatus_ = FAILED;
105     std::condition_variable iamCon_;
106     std::mutex iamMutex_;
107 };
108 } // namespace StorageDaemon
109 } // namespace OHOS
110 
111 #endif // FSS_SECURITY_MERGE_IAMCLIENT_H
112