• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SERVICE_H
17 #define USER_IDM_SERVICE_H
18 
19 #include "user_idm_stub.h"
20 
21 #include <memory>
22 #include <string>
23 #include <vector>
24 
25 #include "system_ability.h"
26 #include "system_ability_definition.h"
27 
28 #include "context.h"
29 #include "context_factory.h"
30 #include "credential_info_interface.h"
31 #include "user_idm_client_defines.h"
32 
33 namespace OHOS {
34 namespace UserIam {
35 namespace UserAuth {
36 class UserIdmService : public SystemAbility, public UserIdmStub, public NoCopyable {
37 public:
38     DECLARE_SYSTEM_ABILITY(UserIdmService);
39     explicit UserIdmService(int32_t systemAbilityId, bool runOnCreate = false);
40     ~UserIdmService() override = default;
41     int Dump(int fd, const std::vector<std::u16string> &args) override;
42     int32_t OpenSession(int32_t userId, std::vector<uint8_t> &challenge) override;
43     int32_t CloseSession(int32_t userId) override;
44     int32_t GetCredentialInfo(int32_t userId, int32_t authType,
45         const sptr<IIdmGetCredInfoCallback> &idmGetCredInfoCallback, int32_t &funcResult) override;
46     int32_t GetSecInfo(int32_t userId,
47         const sptr<IIdmGetSecureUserInfoCallback> &idmGetSecureUserInfoCallback) override;
48     int32_t AddCredential(int32_t userId, const IpcCredentialPara &ipcCredentialPara,
49         const sptr<IIamCallback> &IdmCallback, bool isUpdate) override;
50     int32_t UpdateCredential(int32_t userId, const IpcCredentialPara &ipcCredentialPara,
51         const sptr<IIamCallback> &IdmCallback) override;
52     int32_t Cancel(int32_t userId) override;
53     int32_t EnforceDelUser(int32_t userId, const sptr<IIamCallback> &IdmCallback) override;
54     int32_t DelUser(int32_t userId, const std::vector<uint8_t> &authToken,
55         const sptr<IIamCallback> &IdmCallback) override;
56     int32_t DelCredential(int32_t userId, uint64_t credentialId, const std::vector<uint8_t> &authToken,
57         const sptr<IIamCallback> &IdmCallback) override;
58     int32_t ClearRedundancyCredential(const sptr<IIamCallback> &IdmCallback) override;
59     int32_t RegistCredChangeEventListener(const sptr<IEventListenerCallback> &listener) override;
60     int32_t UnRegistCredChangeEventListener(const sptr<IEventListenerCallback> &listener) override;
61     int32_t GetCredentialInfoSync(int32_t userId, int32_t authType,
62         std::vector<IpcCredentialInfo> &ipcCredentialInfoList) override;
63     int32_t CallbackEnter([[maybe_unused]] uint32_t code) override;
64     int32_t CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) override;
65 
66 protected:
67     void OnStart() override;
68     void OnStop() override;
69 
70 private:
71     int32_t GetCredentialInfoImpl(int32_t userId, int32_t authType,
72         const sptr<IIdmGetCredInfoCallback> &idmGetCredInfoCallback);
73 
74 private:
75     void CancelCurrentEnrollIfExist();
76     int32_t GetSecInfoInner(int32_t userId, SecUserInfo &secUserInfo);
77     int32_t GetCredentialInfoInner(int32_t userId, AuthType authType, std::vector<CredentialInfo> &credInfoList);
78     int32_t EnforceDelUserInner(int32_t userId, std::shared_ptr<ContextCallback> callbackForTrace,
79         std::string changeReasonTrace, const CredChangeEventInfo &changeInfo);
80     int32_t ClearRedundancyCredentialInner(const std::string &callerName, int32_t callerType);
81     void SetAuthTypeTrace(const std::vector<std::shared_ptr<CredentialInfoInterface>> &credInfos,
82         const std::shared_ptr<ContextCallback> &contextCallback);
83     int32_t StartEnroll(Enrollment::EnrollmentPara &para,
84         const std::shared_ptr<ContextCallback> &contextCallback, Attributes &extraInfo, bool needSubscribeAppState);
85     int32_t StartDelete(Deletion::DeleteParam &para, const std::shared_ptr<ContextCallback> &contextCallback,
86         Attributes &extraInfo);
87     void ClearUnavailableCredential(int32_t userId);
88     std::mutex mutex_;
89 };
90 } // namespace UserAuth
91 } // namespace UserIam
92 } // namespace OHOS
93 #endif // USER_IDM_SERVICE_H