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 UpdateStorageKey(int32_t userId, uint64_t secureUid, const std::vector<uint8_t> &token, 72 const std::vector<uint8_t> &oldSecret, const std::vector<uint8_t> &newSecret); 73 ErrCode UpdateStorageKeyContext(const int32_t userId); 74 ErrCode UpdateStorageUserAuth(int32_t userId, uint64_t secureUid, const std::vector<uint8_t> &token, 75 const std::vector<uint8_t> &oldSecret, const std::vector<uint8_t> &newSecret); 76 #ifdef HAS_PIN_AUTH_PART 77 void OnDelUserDone(int32_t userId); 78 #endif // HAS_PIN_AUTH_PART 79 80 private: 81 InnerAccountIAMManager(); 82 ~InnerAccountIAMManager() = default; 83 DISALLOW_COPY_AND_MOVE(InnerAccountIAMManager); 84 #ifdef HAS_STORAGE_PART 85 sptr<StorageManager::IStorageManager> GetStorageManagerProxy(); 86 #endif 87 ErrCode InnerUpdateStorageKey(int32_t userId, uint64_t secureUid, const std::vector<uint8_t> &token, 88 const std::vector<uint8_t> &oldSecret, const std::vector<uint8_t> &newSecret); 89 ErrCode InnerUpdateStorageKeyContext(const int32_t userId); 90 ErrCode InnerUpdateStorageUserAuth(int32_t userId, uint64_t secureUid, 91 const std::vector<uint8_t> &token, const std::vector<uint8_t> &oldSecret, const std::vector<uint8_t> &newSecret); 92 ErrCode InnerGetLockScreenStatus(uint32_t userId, bool &lockScreenStatus); 93 ErrCode InnerUnlockUserScreen( 94 int32_t userId, const std::vector<uint8_t> &token, const std::vector<uint8_t> &secret); 95 ErrCode InnerActivateUserKey( 96 int32_t userId, const std::vector<uint8_t> &token, const std::vector<uint8_t> &secret); 97 98 ErrCode GetDomainAuthStatusInfo( 99 int32_t userId, const GetPropertyRequest &request, const sptr<IGetSetPropCallback> &callback); 100 void CopyAuthParam(const AuthParam &authParam, UserIam::UserAuth::AuthParam &iamAuthParam); 101 102 private: 103 std::mutex mutex_; 104 std::map<int32_t, IAMState> userStateMap_; 105 #ifdef HAS_PIN_AUTH_PART 106 std::mutex delUserInputerMutex_; 107 std::vector<std::shared_ptr<DelUserInputer>> delUserInputerVec_; 108 #endif // HAS_PIN_AUTH_PART 109 }; 110 } // namespace AccountSA 111 } // namespace OHOS 112 #endif // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_INNER_ACCOUNT_IAM_MANAGER_H 113