1 /* 2 * Copyright (c) 2022-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 OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_INNER_ACCOUNT_IAM_MANAGER_H 17 #define OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_INNER_ACCOUNT_IAM_MANAGER_H 18 19 #include <map> 20 #include <vector> 21 #include "account_iam_callback.h" 22 #include "account_iam_info.h" 23 #include "account_error_no.h" 24 #include "domain_account_common.h" 25 #include "iaccount_iam.h" 26 #include "singleton.h" 27 #ifdef HAS_STORAGE_PART 28 #include "istorage_manager.h" 29 #include "storage_manager_proxy.h" 30 #endif 31 32 namespace OHOS { 33 namespace AccountSA { 34 class InnerAccountIAMManager { 35 public: 36 static InnerAccountIAMManager &GetInstance(); 37 void OpenSession(int32_t userId, std::vector<uint8_t> &challenge); 38 void CloseSession(int32_t userId); 39 void AddCredential( 40 int32_t userId, const CredentialParameters &credInfo, const sptr<IIDMCallback> &callback); 41 void UpdateCredential( 42 int32_t userId, const CredentialParameters &credInfo, const sptr<IIDMCallback> &callback); 43 void DelCred(int32_t userId, uint64_t credentialId, const std::vector<uint8_t> &authToken, 44 const sptr<IIDMCallback> &callback); 45 void DelUser(int32_t userId, const std::vector<uint8_t> &authToken, 46 const sptr<IIDMCallback> &callback); 47 void GetCredentialInfo( 48 int32_t userId, AuthType authType, const sptr<IGetCredInfoCallback> &callback); 49 int32_t Cancel(int32_t userId); 50 int32_t PrepareRemoteAuth( 51 const std::string &remoteNetworkId, const sptr<IPreRemoteAuthCallback> &callback); 52 int32_t AuthUser(AuthParam &authParam, const sptr<IIDMCallback> &callback, uint64_t &contextId); 53 int32_t CancelAuth(uint64_t contextId); 54 int32_t GetAvailableStatus(AuthType authType, AuthTrustLevel authTrustLevel, int32_t &status); 55 void GetProperty( 56 int32_t userId, const GetPropertyRequest &request, const sptr<IGetSetPropCallback> &callback); 57 void GetPropertyByCredentialId(uint64_t credentialId, 58 std::vector<Attributes::AttributeKey> &keys, const sptr<IGetSetPropCallback> &callback); 59 void SetProperty( 60 int32_t userId, const SetPropertyRequest &request, const sptr<IGetSetPropCallback> &callback); 61 void GetEnrolledId(int32_t accountId, AuthType authType, const sptr<IGetEnrolledIdCallback> &callback); 62 void HandleFileKeyException(int32_t userId, const std::vector<uint8_t> &secret, 63 const std::vector<uint8_t> &token); 64 IAMState GetState(int32_t userId); 65 void SetState(int32_t userId, IAMState state); 66 ErrCode ActivateUserKey(int32_t userId, const std::vector<uint8_t> &token, const std::vector<uint8_t> &secret); 67 68 ErrCode UnlockUserScreen(int32_t userId, const std::vector<uint8_t> &token, const std::vector<uint8_t> &secret); 69 ErrCode GetLockScreenStatus(uint32_t userId, bool &lockScreenStatus); 70 bool CheckDomainAuthAvailable(int32_t userId); 71 ErrCode UpdateStorageKeyContext(const int32_t userId); 72 ErrCode UpdateStorageUserAuth(int32_t userId, uint64_t secureUid, const std::vector<uint8_t> &token, 73 const std::vector<uint8_t> &oldSecret, const std::vector<uint8_t> &newSecret); 74 #ifdef HAS_PIN_AUTH_PART 75 void OnDelUserDone(int32_t userId); 76 #endif // HAS_PIN_AUTH_PART 77 ErrCode CheckNeedReactivateUserKey(int32_t userId, bool &needReactivateKey); 78 79 private: 80 InnerAccountIAMManager(); 81 ~InnerAccountIAMManager() = default; 82 DISALLOW_COPY_AND_MOVE(InnerAccountIAMManager); 83 #ifdef HAS_STORAGE_PART 84 sptr<StorageManager::IStorageManager> GetStorageManagerProxy(); 85 #endif 86 ErrCode InnerUpdateStorageKeyContext(const int32_t userId); 87 ErrCode InnerUpdateStorageUserAuth(int32_t userId, uint64_t secureUid, 88 const std::vector<uint8_t> &token, const std::vector<uint8_t> &oldSecret, const std::vector<uint8_t> &newSecret); 89 ErrCode InnerGetLockScreenStatus(uint32_t userId, bool &lockScreenStatus); 90 ErrCode InnerUnlockUserScreen( 91 int32_t userId, const std::vector<uint8_t> &token, const std::vector<uint8_t> &secret); 92 ErrCode InnerActivateUserKey( 93 int32_t userId, const std::vector<uint8_t> &token, const std::vector<uint8_t> &secret); 94 95 ErrCode GetDomainAuthStatusInfo( 96 int32_t userId, const GetPropertyRequest &request, const sptr<IGetSetPropCallback> &callback); 97 void CopyAuthParam(const AuthParam &authParam, UserIam::UserAuth::AuthParam &iamAuthParam); 98 99 private: 100 std::mutex mutex_; 101 std::map<int32_t, IAMState> userStateMap_; 102 #ifdef HAS_PIN_AUTH_PART 103 std::mutex delUserInputerMutex_; 104 std::vector<std::shared_ptr<DelUserInputer>> delUserInputerVec_; 105 #endif // HAS_PIN_AUTH_PART 106 }; 107 } // namespace AccountSA 108 } // namespace OHOS 109 #endif // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_INNER_ACCOUNT_IAM_MANAGER_H 110