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 struct AccountCredentialInfo { 35 uint64_t oldSecureUid = 0; 36 uint64_t secureUid = 0; 37 std::vector<uint8_t> oldSecret; 38 std::vector<uint8_t> secret; 39 }; 40 41 class InnerAccountIAMManager { 42 public: 43 static InnerAccountIAMManager &GetInstance(); 44 void OpenSession(int32_t userId, std::vector<uint8_t> &challenge); 45 void CloseSession(int32_t userId); 46 void AddCredential( 47 int32_t userId, const CredentialParameters &credInfo, const sptr<IIDMCallback> &callback); 48 void UpdateCredential( 49 int32_t userId, const CredentialParameters &credInfo, const sptr<IIDMCallback> &callback); 50 void DelCred(int32_t userId, uint64_t credentialId, const std::vector<uint8_t> &authToken, 51 const sptr<IIDMCallback> &callback); 52 void DelUser(int32_t userId, const std::vector<uint8_t> &authToken, 53 const sptr<IIDMCallback> &callback); 54 void GetCredentialInfo( 55 int32_t userId, AuthType authType, const sptr<IGetCredInfoCallback> &callback); 56 int32_t Cancel(int32_t userId); 57 int32_t PrepareRemoteAuth( 58 const std::string &remoteNetworkId, const sptr<IPreRemoteAuthCallback> &callback); 59 int32_t AuthUser(AuthParam &authParam, const sptr<IIDMCallback> &callback, uint64_t &contextId); 60 int32_t CancelAuth(uint64_t contextId); 61 int32_t GetAvailableStatus(AuthType authType, AuthTrustLevel authTrustLevel, int32_t &status); 62 void GetProperty( 63 int32_t userId, const GetPropertyRequest &request, const sptr<IGetSetPropCallback> &callback); 64 void SetProperty( 65 int32_t userId, const SetPropertyRequest &request, const sptr<IGetSetPropCallback> &callback); 66 void GetEnrolledId(int32_t accountId, AuthType authType, const sptr<IGetEnrolledIdCallback> &callback); 67 IAMState GetState(int32_t userId); 68 void SetState(int32_t userId, IAMState state); 69 void GetChallenge(int32_t userId, std::vector<uint8_t> &challenge); 70 ErrCode ActivateUserKey(int32_t userId, const std::vector<uint8_t> &token, const std::vector<uint8_t> &secret); 71 72 ErrCode UnlockUserScreen(int32_t userId); 73 ErrCode GetLockScreenStatus(uint32_t userId, bool &lockScreenStatus); 74 bool CheckDomainAuthAvailable(int32_t userId); 75 ErrCode UpdateStorageKey(int32_t userId, uint64_t secureUid, const std::vector<uint8_t> &token, 76 const std::vector<uint8_t> &oldSecret, const std::vector<uint8_t> &newSecret); 77 ErrCode UpdateStorageKeyContext(const int32_t userId); 78 ErrCode UpdateStorageUserAuth(int32_t userId, uint64_t secureUid, const std::vector<uint8_t> &token, 79 const std::vector<uint8_t> &oldSecret, const std::vector<uint8_t> &newSecret); 80 81 private: 82 InnerAccountIAMManager(); 83 ~InnerAccountIAMManager() = default; 84 DISALLOW_COPY_AND_MOVE(InnerAccountIAMManager); 85 ErrCode GetStorageManagerProxy(); 86 ErrCode GetDomainAuthStatusInfo( 87 int32_t userId, const GetPropertyRequest &request, const sptr<IGetSetPropCallback> &callback); 88 void CopyAuthParam(const AuthParam &authParam, UserIam::UserAuth::AuthParam &iamAuthParam); 89 90 private: 91 std::mutex mutex_; 92 std::map<int32_t, IAMState> userStateMap_; 93 std::map<int32_t, std::vector<uint8_t>> userChallengeMap_; 94 std::map<int32_t, AccountCredentialInfo> credInfoMap_; 95 #ifdef HAS_STORAGE_PART 96 sptr<StorageManager::IStorageManager> storageMgrProxy_; 97 #endif 98 }; 99 } // namespace AccountSA 100 } // namespace OHOS 101 #endif // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_INNER_ACCOUNT_IAM_MANAGER_H 102