• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 "sudo_iam.h"
17 #include "account_iam_client.h"
18 #include "account_iam_info.h"
19 #include "account_iam_client_callback.h"
20 #include "i_inputer.h"
21 
22 std::condition_variable g_condVarForAuth;
23 bool g_authFinish;
24 std::mutex g_mutexForAuth;
25 
26 namespace OHOS {
27 namespace UserIam {
28 namespace PinAuth {
29 
OnGetData(int32_t authSubType,std::vector<uint8_t> challenge,std::shared_ptr<IInputerData> inputerData)30 void SudoIInputer::OnGetData(int32_t authSubType, std::vector<uint8_t> challenge,
31     std::shared_ptr<IInputerData> inputerData)
32 {
33     inputerData->OnSetData(authSubType, passwd_);
34 }
35 
SetPasswd(char * pwd,int len)36 void SudoIInputer::SetPasswd(char *pwd, int len)
37 {
38     passwd_.resize(len);
39     for (int i = 0; i < len; i++) {
40         passwd_[i] = *pwd++;
41     }
42 }
43 
~SudoIInputer()44 SudoIInputer::~SudoIInputer()
45 {
46     for (int i = 0; i < (int)passwd_.size(); i++) {
47         passwd_[i] = 0;
48     }
49 }
50 
51 } //PinAuth
52 } //UserIam
53 
54 namespace AccountSA {
55 
SudoIDMCallback()56 SudoIDMCallback::SudoIDMCallback()
57 {
58     verifyResult_ = false;
59 }
60 
OnAcquireInfo(int32_t module,uint32_t acquireInfo,const Attributes & extraInfo)61 void SudoIDMCallback::OnAcquireInfo(int32_t module, uint32_t acquireInfo, const Attributes &extraInfo)
62 {
63     return;
64 }
65 
OnResult(int32_t result,const Attributes & extraInfo)66 void SudoIDMCallback::OnResult(int32_t result, const Attributes &extraInfo)
67 {
68     verifyResult_ = false;
69     if (result == 0) {
70         verifyResult_ = true;
71     }
72 
73     std::unique_lock<std::mutex> lock { g_mutexForAuth };
74     g_authFinish = true;
75     g_condVarForAuth.notify_all();
76 }
77 
GetVerifyResult(void)78 bool SudoIDMCallback::GetVerifyResult(void)
79 {
80     return verifyResult_;
81 }
82 
83 } // AccountSA
84 } //OHOS
85