• 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 #ifndef OS_ACCOUNT_INTERFACES_INNERKITS_ACCOUNT_IAM_NATIVE_INCLUDE_ACCOUNT_IAM_CLIENT_H
17 #define OS_ACCOUNT_INTERFACES_INNERKITS_ACCOUNT_IAM_NATIVE_INCLUDE_ACCOUNT_IAM_CLIENT_H
18 
19 #include <map>
20 #include <mutex>
21 #include <vector>
22 #include <set>
23 #include "account_iam_client_callback.h"
24 #include "account_iam_info.h"
25 #include "account_error_no.h"
26 #include "iaccount_iam.h"
27 #include "singleton.h"
28 
29 namespace OHOS {
30 namespace AccountSA {
31 class AccountIAMClient : public DelayedRefSingleton<AccountIAMClient> {
32 public:
33     AccountIAMClient();
34     int32_t OpenSession(int32_t userId, std::vector<uint8_t> &challenge);
35     int32_t CloseSession(int32_t userId);
36     void AddCredential(
37         int32_t userId, const CredentialParameters& credInfo, const std::shared_ptr<IDMCallback> &callback);
38     void UpdateCredential(
39         int32_t userId, const CredentialParameters& credInfo, const std::shared_ptr<IDMCallback> &callback);
40     int32_t Cancel(int32_t userId);
41     void DelCred(int32_t userId, uint64_t credentialId, const std::vector<uint8_t> &authToken,
42         const std::shared_ptr<IDMCallback>& callback);
43     void DelUser(int32_t userId, const std::vector<uint8_t> &authToken, const std::shared_ptr<IDMCallback> &callback);
44     int32_t GetCredentialInfo(int32_t userId, AuthType authType, const std::shared_ptr<GetCredInfoCallback> &callback);
45     uint64_t Auth(const std::vector<uint8_t> &challenge, AuthType authType, AuthTrustLevel authTrustLevel,
46         const std::shared_ptr<IDMCallback> &callback);
47     uint64_t AuthUser(int32_t userId, const std::vector<uint8_t> &challenge, AuthType authType,
48         AuthTrustLevel authTrustLevel, const std::shared_ptr<IDMCallback> &callback);
49     int32_t CancelAuth(uint64_t contextId);
50     int32_t GetAvailableStatus(AuthType authType, AuthTrustLevel authTrustLevel, int32_t &status);
51     void GetProperty(
52         int32_t userId, const GetPropertyRequest &request, const std::shared_ptr<GetSetPropCallback> &callback);
53     void SetProperty(
54         int32_t userId, const SetPropertyRequest &request, const std::shared_ptr<GetSetPropCallback> &callback);
55     ErrCode RegisterPINInputer(const std::shared_ptr<IInputer> &inputer);
56     void UnregisterPINInputer();
57     ErrCode RegisterInputer(int32_t authType, const std::shared_ptr<IInputer> &inputer);
58     ErrCode UnregisterInputer(int32_t authType);
59     IAMState GetAccountState(int32_t userId);
60     void SetAuthSubType(int32_t userId, int32_t authSubType);
61     int32_t GetAuthSubType(int32_t userId);
62     void SetCredential(int32_t userId, const std::vector<uint8_t> &credential);
63     void GetCredential(int32_t userId, CredentialItem &credItem);
64     void ClearCredential(int32_t userId);
65 
66 private:
67     class AccountIAMDeathRecipient : public IRemoteObject::DeathRecipient {
68     public:
69         AccountIAMDeathRecipient() = default;
70         ~AccountIAMDeathRecipient() = default;
71         void OnRemoteDied(const wptr<IRemoteObject>& remote) override;
72 
73     private:
74         DISALLOW_COPY_AND_MOVE(AccountIAMDeathRecipient);
75     };
76     ErrCode GetAccountIAMProxy();
77     void ResetAccountIAMProxy(const wptr<IRemoteObject>& remote);
78     bool GetCurrentUserId(int32_t &userId);
79     uint64_t StartDomainAuth(int32_t userId, const std::shared_ptr<IDMCallback> &callback);
80     ErrCode RegisterDomainInputer(const std::shared_ptr<IInputer> &inputer);
81     ErrCode UnregisterDomainInputer();
82     bool CheckSelfPermission(const std::string &permissionName);
83 
84 private:
85     std::mutex mutex_;
86     std::mutex pinMutex_;
87     std::mutex domainMutex_;
88     std::map<int32_t, CredentialItem> credentialMap_;
89     sptr<IAccountIAM> proxy_ = nullptr;
90     sptr<AccountIAMDeathRecipient> deathRecipient_ = nullptr;
91     std::shared_ptr<IInputer> pinInputer_ = nullptr;
92     std::shared_ptr<IInputer> domainInputer_ = nullptr;
93 };
94 }  // namespace AccountSA
95 }  // namespace OHOS
96 #endif  // OS_ACCOUNT_INTERFACES_INNERKITS_ACCOUNT_IAM_NATIVE_INCLUDE_ACCOUNT_IAM_CLIENT_H