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 #include "account_iam_callback.h"
17
18 #include <securec.h>
19 #include <string>
20 #include "account_iam_info.h"
21 #include "account_info_report.h"
22 #include "account_log_wrapper.h"
23 #include "account_hisysevent_adapter.h"
24 #include "iinner_os_account_manager.h"
25 #include "inner_account_iam_manager.h"
26 #include "inner_domain_account_manager.h"
27 #include "user_auth_client.h"
28 #include "user_idm_client.h"
29
30 namespace OHOS {
31 namespace AccountSA {
32 using UserIDMClient = UserIam::UserAuth::UserIdmClient;
33 using UserAuthClient = UserIam::UserAuth::UserAuthClient;
34
SetContextId(uint16_t contextId)35 void AuthCallbackDeathRecipient::SetContextId(uint16_t contextId)
36 {
37 contextId_ = contextId;
38 }
39
OnRemoteDied(const wptr<IRemoteObject> & remote)40 void AuthCallbackDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
41 {
42 ACCOUNT_LOGI("remote callback died, cancel authentication");
43 if (contextId_ > 0) {
44 UserAuthClient::GetInstance().CancelAuthentication(contextId_);
45 }
46 }
47
AuthCallback(uint32_t userId,uint64_t credentialId,AuthType authType,const sptr<IIDMCallback> & callback)48 AuthCallback::AuthCallback(
49 uint32_t userId, uint64_t credentialId, AuthType authType, const sptr<IIDMCallback> &callback)
50 : userId_(userId), credentialId_(credentialId), authType_(authType), innerCallback_(callback)
51 {}
52
HandleAuthResult(const Attributes & extraInfo)53 ErrCode AuthCallback::HandleAuthResult(const Attributes &extraInfo)
54 {
55 bool lockScreenStatus = false;
56 ErrCode ret = InnerAccountIAMManager::GetInstance().GetLockScreenStatus(userId_, lockScreenStatus);
57 if (ret != 0) {
58 ReportOsAccountOperationFail(userId_, "getLockScreenStatus", ret, "failed to get lock status msg from storage");
59 }
60 if (!lockScreenStatus) {
61 ACCOUNT_LOGI("start unlock user screen");
62 // el3\4 file decryption
63 ret = InnerAccountIAMManager::GetInstance().UnlockUserScreen(userId_);
64 if (ret != 0) {
65 ReportOsAccountOperationFail(userId_, "unlockUserScreen", ret, "failed to send unlock msg for storage");
66 return ret;
67 }
68 }
69 if (authType_ == static_cast<AuthType>(IAMAuthType::DOMAIN)) {
70 return ERR_OK;
71 }
72 std::vector<uint8_t> token;
73 extraInfo.GetUint8ArrayValue(Attributes::ATTR_SIGNATURE, token);
74 std::vector<uint8_t> secret;
75 extraInfo.GetUint8ArrayValue(Attributes::ATTR_ROOT_SECRET, secret);
76 if (authType_ == AuthType::PIN) {
77 bool isVerified = false;
78 (void)IInnerOsAccountManager::GetInstance().IsOsAccountVerified(userId_, isVerified);
79 if (!isVerified) {
80 // el2 file decryption
81 ret = InnerAccountIAMManager::GetInstance().ActivateUserKey(userId_, token, secret);
82 if (ret != 0) {
83 ACCOUNT_LOGE("failed to activate user key");
84 ReportOsAccountOperationFail(userId_, "activateUserKey", ret,
85 "failed to notice storage to activate user key");
86 return ret;
87 }
88 }
89 }
90 // domain account authentication
91 InnerDomainAccountManager::GetInstance().AuthWithToken(userId_, token);
92 return ret;
93 }
94
SetDeathRecipient(const sptr<AuthCallbackDeathRecipient> & deathRecipient)95 void AuthCallback::SetDeathRecipient(const sptr<AuthCallbackDeathRecipient> &deathRecipient)
96 {
97 deathRecipient_ = deathRecipient;
98 }
99
GenerateAttributesInfo(const Attributes & extraInfo,Attributes & extraAuthInfo)100 static void GenerateAttributesInfo(const Attributes &extraInfo, Attributes &extraAuthInfo)
101 {
102 std::vector<uint8_t> token;
103 if (extraInfo.GetUint8ArrayValue(Attributes::AttributeKey::ATTR_SIGNATURE, token)) {
104 extraAuthInfo.SetUint8ArrayValue(Attributes::AttributeKey::ATTR_SIGNATURE, token);
105 }
106 int32_t remainTimes = 0;
107 if (extraInfo.GetInt32Value(Attributes::AttributeKey::ATTR_REMAIN_TIMES, remainTimes)) {
108 extraAuthInfo.SetInt32Value(Attributes::AttributeKey::ATTR_REMAIN_TIMES, remainTimes);
109 }
110 int32_t freezingTime = 0;
111 if (extraInfo.GetInt32Value(Attributes::AttributeKey::ATTR_FREEZING_TIME, freezingTime)) {
112 extraAuthInfo.SetInt32Value(Attributes::AttributeKey::ATTR_FREEZING_TIME, freezingTime);
113 }
114 int32_t nextPhaseFreezingTime = 0;
115 if (extraInfo.GetInt32Value(Attributes::AttributeKey::ATTR_NEXT_FAIL_LOCKOUT_DURATION, nextPhaseFreezingTime)) {
116 extraAuthInfo.SetInt32Value(Attributes::AttributeKey::ATTR_NEXT_FAIL_LOCKOUT_DURATION, nextPhaseFreezingTime);
117 }
118 int32_t accountId = 0;
119 if (extraInfo.GetInt32Value(Attributes::AttributeKey::ATTR_USER_ID, accountId)) {
120 extraAuthInfo.SetInt32Value(Attributes::AttributeKey::ATTR_USER_ID, accountId);
121 }
122 // pinValidityPeriod
123 int64_t pinValidityPeriod = 0;
124 if (extraInfo.GetInt64Value(Attributes::AttributeKey::ATTR_PIN_EXPIRED_INFO, pinValidityPeriod)) {
125 extraAuthInfo.SetInt64Value(Attributes::AttributeKey::ATTR_PIN_EXPIRED_INFO, pinValidityPeriod);
126 }
127 }
128
OnResult(int32_t result,const Attributes & extraInfo)129 void AuthCallback::OnResult(int32_t result, const Attributes &extraInfo)
130 {
131 ACCOUNT_LOGI("AuthCallback::OnResult, result=%{public}d", result);
132 InnerAccountIAMManager::GetInstance().SetState(userId_, AFTER_OPEN_SESSION);
133 if (innerCallback_ == nullptr) {
134 ACCOUNT_LOGE("innerCallback_ is nullptr");
135 return;
136 }
137 innerCallback_->AsObject()->RemoveDeathRecipient(deathRecipient_);
138 if (result != 0) {
139 ACCOUNT_LOGE("authentication failed");
140 innerCallback_->OnResult(result, extraInfo);
141 ReportOsAccountOperationFail(userId_, "authUser", result, "auth user failed");
142 return AccountInfoReport::ReportSecurityInfo("", userId_, ReportEvent::EVENT_LOGIN, result);
143 }
144 if (HandleAuthResult(extraInfo) != ERR_OK) {
145 int32_t remainTimes = 0;
146 int32_t freezingTime = 0;
147 extraInfo.GetInt32Value(Attributes::AttributeKey::ATTR_REMAIN_TIMES, remainTimes);
148 extraInfo.GetInt32Value(Attributes::AttributeKey::ATTR_FREEZING_TIME, freezingTime);
149 Attributes errInfo;
150 errInfo.SetInt32Value(Attributes::AttributeKey::ATTR_REMAIN_TIMES, remainTimes);
151 errInfo.SetInt32Value(Attributes::AttributeKey::ATTR_FREEZING_TIME, freezingTime);
152 innerCallback_->OnResult(ResultCode::FAIL, errInfo);
153 return AccountInfoReport::ReportSecurityInfo("", userId_, ReportEvent::EVENT_LOGIN, ResultCode::FAIL);
154 }
155 Attributes extraAuthInfo;
156 GenerateAttributesInfo(extraInfo, extraAuthInfo);
157 uint64_t credentialId = 0;
158 if (!extraInfo.GetUint64Value(Attributes::AttributeKey::ATTR_CREDENTIAL_ID, credentialId) && (credentialId_ != 0)) {
159 extraAuthInfo.SetUint64Value(Attributes::AttributeKey::ATTR_CREDENTIAL_ID, credentialId_);
160 }
161 innerCallback_->OnResult(result, extraAuthInfo);
162 (void)IInnerOsAccountManager::GetInstance().SetOsAccountIsVerified(userId_, true);
163 (void)IInnerOsAccountManager::GetInstance().SetOsAccountIsLoggedIn(userId_, true);
164 AccountInfoReport::ReportSecurityInfo("", userId_, ReportEvent::EVENT_LOGIN, result);
165 }
166
OnAcquireInfo(int32_t module,uint32_t acquireInfo,const Attributes & extraInfo)167 void AuthCallback::OnAcquireInfo(int32_t module, uint32_t acquireInfo, const Attributes &extraInfo)
168 {
169 if (innerCallback_ == nullptr) {
170 ACCOUNT_LOGE("innerCallback_ is nullptr");
171 return;
172 }
173 innerCallback_->OnAcquireInfo(module, acquireInfo, extraInfo);
174 }
175
OnRemoteDied(const wptr<IRemoteObject> & remote)176 void IDMCallbackDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
177 {
178 ACCOUNT_LOGI("Remote callback died, cancel cred");
179 if (userId_ > 0) {
180 UserIDMClient::GetInstance().Cancel(userId_);
181 }
182 }
183
IDMCallbackDeathRecipient(uint32_t userId)184 IDMCallbackDeathRecipient::IDMCallbackDeathRecipient(uint32_t userId) : userId_(userId)
185 {}
186
AddCredCallback(uint32_t userId,const CredentialParameters & credInfo,const sptr<IIDMCallback> & callback)187 AddCredCallback::AddCredCallback(uint32_t userId, const CredentialParameters &credInfo,
188 const sptr<IIDMCallback> &callback)
189 : userId_(userId), credInfo_(credInfo), innerCallback_(callback)
190 {}
191
SetDeathRecipient(const sptr<IDMCallbackDeathRecipient> & deathRecipient)192 void AddCredCallback::SetDeathRecipient(const sptr<IDMCallbackDeathRecipient> &deathRecipient)
193 {
194 deathRecipient_ = deathRecipient;
195 }
196
OnResult(int32_t result,const Attributes & extraInfo)197 void AddCredCallback::OnResult(int32_t result, const Attributes &extraInfo)
198 {
199 ACCOUNT_LOGI("AddCredCallback, result=%{public}d.", result);
200 if (innerCallback_ == nullptr || innerCallback_->AsObject() == nullptr) {
201 ACCOUNT_LOGE("innerCallback_ is nullptr");
202 return;
203 }
204 innerCallback_->AsObject()->RemoveDeathRecipient(deathRecipient_);
205 auto &innerIamMgr_ = InnerAccountIAMManager::GetInstance();
206 if ((result == 0) && (credInfo_.authType == AuthType::PIN)) {
207 InnerAccountIAMManager::GetInstance().SetState(userId_, AFTER_ADD_CRED);
208 uint64_t credentialId = 0;
209 extraInfo.GetUint64Value(Attributes::AttributeKey::ATTR_CREDENTIAL_ID, credentialId);
210 (void)IInnerOsAccountManager::GetInstance().SetOsAccountCredentialId(userId_, credentialId);
211
212 uint64_t secureUid = 0;
213 extraInfo.GetUint64Value(Attributes::AttributeKey::ATTR_SEC_USER_ID, secureUid);
214 std::vector<uint8_t> newSecret;
215 extraInfo.GetUint8ArrayValue(Attributes::ATTR_ROOT_SECRET, newSecret);
216 std::vector<uint8_t> token;
217 extraInfo.GetUint8ArrayValue(Attributes::ATTR_AUTH_TOKEN, token);
218 std::vector<uint8_t> oldSecret;
219 (void) innerIamMgr_.UpdateStorageKey(userId_, secureUid, token, oldSecret, newSecret);
220 }
221 if (result != 0) {
222 ReportOsAccountOperationFail(userId_, "addCredential", result, "Add credential failed");
223 }
224 innerIamMgr_.SetState(userId_, AFTER_OPEN_SESSION);
225 innerCallback_->OnResult(result, extraInfo);
226 }
227
OnAcquireInfo(int32_t module,uint32_t acquireInfo,const Attributes & extraInfo)228 void AddCredCallback::OnAcquireInfo(int32_t module, uint32_t acquireInfo, const Attributes &extraInfo)
229 {
230 if (innerCallback_ == nullptr) {
231 ACCOUNT_LOGE("innerCallback_ is nullptr");
232 return;
233 }
234 innerCallback_->OnAcquireInfo(module, acquireInfo, extraInfo);
235 }
236
UpdateCredCallback(uint32_t userId,const CredentialParameters & credInfo,const sptr<IIDMCallback> & callback)237 UpdateCredCallback::UpdateCredCallback(
238 uint32_t userId, const CredentialParameters &credInfo, const sptr<IIDMCallback> &callback)
239 : userId_(userId), credInfo_(credInfo), innerCallback_(callback)
240 {}
241
SetDeathRecipient(const sptr<IDMCallbackDeathRecipient> & deathRecipient)242 void UpdateCredCallback::SetDeathRecipient(const sptr<IDMCallbackDeathRecipient> &deathRecipient)
243 {
244 deathRecipient_ = deathRecipient;
245 }
246
OnResult(int32_t result,const Attributes & extraInfo)247 void UpdateCredCallback::OnResult(int32_t result, const Attributes &extraInfo)
248 {
249 ACCOUNT_LOGI("UpdateCredCallback, userId=%{public}d, result=%{public}d.", userId_, result);
250 if (innerCallback_ == nullptr || innerCallback_->AsObject() == nullptr) {
251 ACCOUNT_LOGE("inner callback is nullptr");
252 return;
253 }
254 innerCallback_->AsObject()->RemoveDeathRecipient(deathRecipient_);
255 auto &innerIamMgr_ = InnerAccountIAMManager::GetInstance();
256 if ((result != 0) || (credInfo_.authType != AuthType::PIN)) {
257 ACCOUNT_LOGE("UpdateCredCallback fail code=%{public}d, authType=%{public}d", result, credInfo_.authType);
258 innerIamMgr_.SetState(userId_, AFTER_OPEN_SESSION);
259 innerCallback_->OnResult(result, extraInfo);
260 return;
261 }
262
263 uint64_t secureUid = 0;
264 extraInfo.GetUint64Value(Attributes::AttributeKey::ATTR_SEC_USER_ID, secureUid);
265 std::vector<uint8_t> newSecret;
266 extraInfo.GetUint8ArrayValue(Attributes::ATTR_ROOT_SECRET, newSecret);
267 std::vector<uint8_t> oldSecret;
268 extraInfo.GetUint8ArrayValue(Attributes::ATTR_OLD_ROOT_SECRET, oldSecret);
269 ErrCode code = innerIamMgr_.UpdateStorageUserAuth(userId_, secureUid, credInfo_.token, oldSecret, newSecret);
270 if (code != ERR_OK) {
271 ACCOUNT_LOGE("Fail to update user auth, userId=%{public}d, code=%{public}d", userId_, code);
272 innerIamMgr_.SetState(userId_, AFTER_OPEN_SESSION);
273 innerCallback_->OnResult(code, extraInfo);
274 return;
275 }
276 innerIamMgr_.SetState(userId_, AFTER_UPDATE_CRED);
277 auto idmCallback = std::make_shared<CommitCredUpdateCallback>(userId_, innerCallback_);
278 uint64_t oldCredentialId = 0;
279 extraInfo.GetUint64Value(Attributes::AttributeKey::ATTR_OLD_CREDENTIAL_ID, oldCredentialId);
280 UserIDMClient::GetInstance().DeleteCredential(userId_, oldCredentialId, credInfo_.token, idmCallback);
281 }
282
OnAcquireInfo(int32_t module,uint32_t acquireInfo,const Attributes & extraInfo)283 void UpdateCredCallback::OnAcquireInfo(int32_t module, uint32_t acquireInfo, const Attributes &extraInfo)
284 {
285 if (innerCallback_ == nullptr) {
286 ACCOUNT_LOGE("innerCallback_ is nullptr");
287 return;
288 }
289 innerCallback_->OnAcquireInfo(module, acquireInfo, extraInfo);
290 }
291
CommitCredUpdateCallback(int32_t userId,const sptr<IIDMCallback> & callback)292 CommitCredUpdateCallback::CommitCredUpdateCallback(int32_t userId, const sptr<IIDMCallback> &callback)
293 : userId_(userId), innerCallback_(callback)
294 {}
295
OnResult(int32_t result,const Attributes & extraInfo)296 void CommitCredUpdateCallback::OnResult(int32_t result, const Attributes &extraInfo)
297 {
298 ACCOUNT_LOGI("CommitCredUpdateCallback, result=%{public}d.", result);
299 if (innerCallback_ == nullptr) {
300 ACCOUNT_LOGE("innerCallback_ is nullptr");
301 return;
302 }
303
304 auto &innerIamMgr_ = InnerAccountIAMManager::GetInstance();
305 if (result != 0) {
306 ACCOUNT_LOGE("CommitCredUpdateCallback fail code=%{public}d", result);
307 ReportOsAccountOperationFail(userId_, "CommitCredUpdated", result, "Fail to commit cred updated");
308 innerCallback_->OnResult(result, extraInfo);
309 innerIamMgr_.SetState(userId_, AFTER_OPEN_SESSION);
310 return;
311 }
312 innerIamMgr_.UpdateStorageKeyContext(userId_);
313 innerIamMgr_.SetState(userId_, AFTER_OPEN_SESSION);
314 innerCallback_->OnResult(result, extraInfo);
315 }
316
OnAcquireInfo(int32_t module,uint32_t acquireInfo,const Attributes & extraInfo)317 void CommitCredUpdateCallback::OnAcquireInfo(int32_t module, uint32_t acquireInfo, const Attributes &extraInfo)
318 {
319 ACCOUNT_LOGE("CommitCredUpdateCallback OnAcquireInfo");
320 }
321
DelCredCallback(int32_t userId,bool isPIN,std::vector<uint8_t> token,const sptr<IIDMCallback> & callback)322 DelCredCallback::DelCredCallback(int32_t userId, bool isPIN, std::vector<uint8_t> token,
323 const sptr<IIDMCallback> &callback)
324 : userId_(userId), isPIN_(isPIN), token_(token), innerCallback_(callback)
325 {}
326
OnResult(int32_t result,const Attributes & extraInfo)327 void DelCredCallback::OnResult(int32_t result, const Attributes &extraInfo)
328 {
329 ACCOUNT_LOGI("DelCredCallback, result=%{public}d, userId=%{public}d", result, userId_);
330 if (innerCallback_ == nullptr) {
331 ACCOUNT_LOGE("innerCallback_ is nullptr");
332 return;
333 }
334 auto &innerIamMgr_ = InnerAccountIAMManager::GetInstance();
335 if ((result == 0) && isPIN_) {
336 (void)IInnerOsAccountManager::GetInstance().SetOsAccountCredentialId(userId_, 0); // 0-invalid credentialId
337 std::vector<uint8_t> newSecret;
338 std::vector<uint8_t> oldSecret;
339 extraInfo.GetUint8ArrayValue(Attributes::ATTR_OLD_ROOT_SECRET, oldSecret);
340 uint64_t secureUid = 0;
341 extraInfo.GetUint64Value(Attributes::AttributeKey::ATTR_SEC_USER_ID, secureUid);
342 (void) innerIamMgr_.UpdateStorageKey(userId_, secureUid, token_, oldSecret, newSecret);
343 }
344 if (result != 0) {
345 ACCOUNT_LOGE("DelCredCallback fail code=%{public}d, userId=%{public}d", result, userId_);
346 ReportOsAccountOperationFail(userId_, "deleteCredential", result, "fail to delete credential");
347 }
348
349 innerIamMgr_.SetState(userId_, AFTER_OPEN_SESSION);
350 innerCallback_->OnResult(result, extraInfo);
351 }
352
OnAcquireInfo(int32_t module,uint32_t acquireInfo,const Attributes & extraInfo)353 void DelCredCallback::OnAcquireInfo(int32_t module, uint32_t acquireInfo, const Attributes &extraInfo)
354 {
355 if (innerCallback_ == nullptr) {
356 ACCOUNT_LOGE("innerCallback_ is nullptr");
357 return;
358 }
359 innerCallback_->OnAcquireInfo(module, acquireInfo, extraInfo);
360 }
361
GetCredInfoCallbackWrapper(int32_t userId,int32_t authType,const sptr<IGetCredInfoCallback> & callback)362 GetCredInfoCallbackWrapper::GetCredInfoCallbackWrapper(
363 int32_t userId, int32_t authType, const sptr<IGetCredInfoCallback> &callback)
364 : userId_(userId), authType_(authType), innerCallback_(callback)
365 {}
366
OnCredentialInfo(const std::vector<CredentialInfo> & infoList)367 void GetCredInfoCallbackWrapper::OnCredentialInfo(const std::vector<CredentialInfo> &infoList)
368 {
369 if (innerCallback_ == nullptr) {
370 return;
371 }
372 if (authType_ == 0) {
373 bool isAvailable = InnerAccountIAMManager::GetInstance().CheckDomainAuthAvailable(userId_);
374 if (isAvailable) {
375 std::vector<CredentialInfo> newInfoList = infoList;
376 CredentialInfo info;
377 info.authType = static_cast<AuthType>(IAMAuthType::DOMAIN);
378 info.pinType = static_cast<PinSubType>(IAMAuthSubType::DOMAIN_MIXED);
379 newInfoList.emplace_back(info);
380 return innerCallback_->OnCredentialInfo(newInfoList);
381 }
382 }
383 return innerCallback_->OnCredentialInfo(infoList);
384 }
385
GetPropCallbackWrapper(int32_t userId,const sptr<IGetSetPropCallback> & callback)386 GetPropCallbackWrapper::GetPropCallbackWrapper(int32_t userId, const sptr<IGetSetPropCallback> &callback)
387 : userId_(userId), innerCallback_(callback)
388 {}
389
OnResult(int32_t result,const Attributes & extraInfo)390 void GetPropCallbackWrapper::OnResult(int32_t result, const Attributes &extraInfo)
391 {
392 if (innerCallback_ == nullptr) {
393 ACCOUNT_LOGE("inner callback is nullptr");
394 return;
395 }
396 if (result != 0) {
397 ReportOsAccountOperationFail(userId_, "getProperty", result, "fail to get property");
398 }
399 innerCallback_->OnResult(result, extraInfo);
400 }
401
SetPropCallbackWrapper(int32_t userId,const sptr<IGetSetPropCallback> & callback)402 SetPropCallbackWrapper::SetPropCallbackWrapper(int32_t userId, const sptr<IGetSetPropCallback> &callback)
403 : userId_(userId), innerCallback_(callback)
404 {}
405
OnResult(int32_t result,const Attributes & extraInfo)406 void SetPropCallbackWrapper::OnResult(int32_t result, const Attributes &extraInfo)
407 {
408 if (innerCallback_ == nullptr) {
409 ACCOUNT_LOGE("inner callback is nullptr");
410 return;
411 }
412 if (result != 0) {
413 ReportOsAccountOperationFail(userId_, "setProperty", result, "fail to set property");
414 }
415 innerCallback_->OnResult(result, extraInfo);
416 }
417
GetSecUserInfoCallbackWrapper(AuthType authType,const sptr<IGetEnrolledIdCallback> & callback)418 GetSecUserInfoCallbackWrapper::GetSecUserInfoCallbackWrapper(
419 AuthType authType, const sptr<IGetEnrolledIdCallback> &callback)
420 : authType_(authType), innerCallback_(callback)
421 {}
422
OnSecUserInfo(const SecUserInfo & info)423 void GetSecUserInfoCallbackWrapper::OnSecUserInfo(const SecUserInfo &info)
424 {
425 if (innerCallback_ == nullptr) {
426 return;
427 }
428 auto it = std::find_if(info.enrolledInfo.begin(), info.enrolledInfo.end(), [this](const auto& item) {
429 return item.authType == authType_;
430 });
431 if (it != info.enrolledInfo.end()) {
432 return innerCallback_->OnEnrolledId(ERR_OK, it->enrolledId);
433 } else {
434 return innerCallback_->OnEnrolledId(ERR_IAM_NOT_ENROLLED, 0);
435 }
436 }
437
PrepareRemoteAuthCallbackWrapper(const sptr<IPreRemoteAuthCallback> & callback)438 PrepareRemoteAuthCallbackWrapper::PrepareRemoteAuthCallbackWrapper(const sptr<IPreRemoteAuthCallback> &callback)
439 : innerCallback_(callback)
440 {}
441
OnResult(int32_t result)442 void PrepareRemoteAuthCallbackWrapper::OnResult(int32_t result)
443 {
444 if (innerCallback_ == nullptr) {
445 ACCOUNT_LOGE("Inner callback is nullptr.");
446 return;
447 }
448 if (result != 0) {
449 ACCOUNT_LOGE("PrepareRemoteAuth, result=%{public}d fail to prepare remote auth.", result);
450 }
451 innerCallback_->OnResult(result);
452 }
453
GetDomainAuthStatusInfoCallback(const GetPropertyRequest & request,const sptr<IGetSetPropCallback> & callback)454 GetDomainAuthStatusInfoCallback::GetDomainAuthStatusInfoCallback(
455 const GetPropertyRequest &request, const sptr<IGetSetPropCallback> &callback)
456 : request_(request), innerCallback_(callback)
457 {}
458
OnResult(int32_t result,Parcel & parcel)459 void GetDomainAuthStatusInfoCallback::OnResult(int32_t result, Parcel &parcel)
460 {
461 if (innerCallback_ == nullptr) {
462 ACCOUNT_LOGE("inner callback is nullptr");
463 return;
464 }
465 Attributes attributes;
466 std::shared_ptr<AuthStatusInfo> infoPtr(AuthStatusInfo::Unmarshalling(parcel));
467 if (infoPtr == nullptr) {
468 innerCallback_->OnResult(result, attributes);
469 return;
470 }
471 attributes.SetInt32Value(Attributes::ATTR_PIN_SUB_TYPE, static_cast<int32_t>(IAMAuthSubType::DOMAIN_MIXED));
472 attributes.SetInt32Value(Attributes::ATTR_REMAIN_TIMES, infoPtr->remainingTimes);
473 attributes.SetInt32Value(Attributes::ATTR_FREEZING_TIME, infoPtr->freezingTime);
474 innerCallback_->OnResult(result, attributes);
475 }
476 } // namespace AccountSA
477 } // namespace OHOS
478