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 SetProperty( 58 int32_t userId, const SetPropertyRequest &request, const sptr<IGetSetPropCallback> &callback); 59 void GetEnrolledId(int32_t accountId, AuthType authType, const sptr<IGetEnrolledIdCallback> &callback); 60 void HandleFileKeyException(int32_t userId, const std::vector<uint8_t> &secret, 61 const std::vector<uint8_t> &token); 62 IAMState GetState(int32_t userId); 63 void SetState(int32_t userId, IAMState state); 64 ErrCode ActivateUserKey(int32_t userId, const std::vector<uint8_t> &token, const std::vector<uint8_t> &secret); 65 66 ErrCode UnlockUserScreen(int32_t userId, const std::vector<uint8_t> &token, const std::vector<uint8_t> &secret); 67 ErrCode GetLockScreenStatus(uint32_t userId, bool &lockScreenStatus); 68 bool CheckDomainAuthAvailable(int32_t userId); 69 ErrCode UpdateStorageKey(int32_t userId, uint64_t secureUid, const std::vector<uint8_t> &token, 70 const std::vector<uint8_t> &oldSecret, const std::vector<uint8_t> &newSecret); 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 78 private: 79 InnerAccountIAMManager(); 80 ~InnerAccountIAMManager() = default; 81 DISALLOW_COPY_AND_MOVE(InnerAccountIAMManager); 82 #ifdef HAS_STORAGE_PART 83 sptr<StorageManager::IStorageManager> GetStorageManagerProxy(); 84 #endif 85 ErrCode InnerUpdateStorageKey(int32_t userId, uint64_t secureUid, const std::vector<uint8_t> &token, 86 const std::vector<uint8_t> &oldSecret, const std::vector<uint8_t> &newSecret); 87 ErrCode InnerUpdateStorageKeyContext(const int32_t userId); 88 ErrCode InnerUpdateStorageUserAuth(int32_t userId, uint64_t secureUid, 89 const std::vector<uint8_t> &token, const std::vector<uint8_t> &oldSecret, const std::vector<uint8_t> &newSecret); 90 ErrCode InnerGetLockScreenStatus(uint32_t userId, bool &lockScreenStatus); 91 ErrCode InnerUnlockUserScreen( 92 int32_t userId, const std::vector<uint8_t> &token, const std::vector<uint8_t> &secret); 93 ErrCode InnerActivateUserKey( 94 int32_t userId, const std::vector<uint8_t> &token, const std::vector<uint8_t> &secret); 95 96 ErrCode GetDomainAuthStatusInfo( 97 int32_t userId, const GetPropertyRequest &request, const sptr<IGetSetPropCallback> &callback); 98 void CopyAuthParam(const AuthParam &authParam, UserIam::UserAuth::AuthParam &iamAuthParam); 99 100 private: 101 std::mutex mutex_; 102 std::map<int32_t, IAMState> userStateMap_; 103 #ifdef HAS_PIN_AUTH_PART 104 std::mutex delUserInputerMutex_; 105 std::vector<std::shared_ptr<DelUserInputer>> delUserInputerVec_; 106 #endif // HAS_PIN_AUTH_PART 107 }; 108 } // namespace AccountSA 109 } // namespace OHOS 110 #endif // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_INNER_ACCOUNT_IAM_MANAGER_H 111