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_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.h" 30 #include "storage_manager_proxy.h" 31 #endif 32 33 namespace OHOS { 34 namespace AccountSA { 35 struct AccountCredentialInfo { 36 uint64_t credentialId = 0; 37 std::vector<uint8_t> oldSecret; 38 std::vector<uint8_t> secret; 39 }; 40 41 class InnerAccountIAMManager : public DelayedRefSingleton<InnerAccountIAMManager> { 42 public: 43 InnerAccountIAMManager(); 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 uint64_t AuthUser(int32_t userId, const std::vector<uint8_t> &challenge, AuthType authType, 58 AuthTrustLevel authTrustLevel, const sptr<IIDMCallback> &callback); 59 int32_t CancelAuth(uint64_t contextId); 60 int32_t GetAvailableStatus(AuthType authType, const AuthTrustLevel authTrustLevel, int32_t &status); 61 void GetProperty( 62 int32_t userId, const GetPropertyRequest &request, const sptr<IGetSetPropCallback> &callback); 63 void SetProperty( 64 int32_t userId, const SetPropertyRequest &request, const sptr<IGetSetPropCallback> &callback); 65 IAMState GetState(int32_t userId); 66 void SetState(int32_t userId, IAMState state); 67 void GetChallenge(int32_t userId, std::vector<uint8_t> &challenge); 68 ErrCode ActivateUserKey(int32_t userId, const std::vector<uint8_t> &token, const std::vector<uint8_t> &secret); 69 ErrCode UpdateUserKey(int32_t userId, uint64_t credentialId, 70 const std::vector<uint8_t> &token, const std::vector<uint8_t> &newSecret); 71 ErrCode RemoveUserKey(int32_t userId, const std::vector<uint8_t> &token); 72 ErrCode RestoreUserKey(int32_t userId, uint64_t credentialId, const std::vector<uint8_t> &token); 73 bool CheckDomainAuthAvailable(int32_t userId); 74 75 private: 76 ErrCode UpdateStorageKey(int32_t userId, const std::vector<uint8_t> &token, 77 const std::vector<uint8_t> &oldSecret, const std::vector<uint8_t> &newSecret); 78 ErrCode GetStorageManagerProxy(); 79 ErrCode GetDomainAuthProperty(int32_t userId, DomainAuthProperty &property); 80 81 private: 82 std::mutex mutex_; 83 std::map<int32_t, IAMState> userStateMap_; 84 std::map<int32_t, std::vector<uint8_t>> userChallengeMap_; 85 std::map<int32_t, AccountCredentialInfo> credInfoMap_; 86 #ifdef HAS_STORAGE_PART 87 sptr<StorageManager::IStorageManager> storageMgrProxy_; 88 #endif 89 }; 90 } // namespace AccountSA 91 } // namespace OHOS 92 #endif // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_INNER_ACCOUNT_IAM_MANAGER_H 93