• 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 "i_inputer.h"
18 #include "user_auth_client_callback.h"
19 
20 using namespace OHOS::UserIam::PinAuth;
21 using namespace OHOS::UserIam::UserAuth;
22 
23 std::condition_variable g_condVarForAuth;
24 bool g_authFinish;
25 std::mutex g_mutexForAuth;
26 
27 namespace OHOS {
28 namespace UserIam {
29 namespace PinAuth {
30 
OnGetData(int32_t authSubType,std::vector<uint8_t> challenge,std::shared_ptr<IInputerData> inputerData)31 void SudoIInputer::OnGetData(int32_t authSubType, std::vector<uint8_t> challenge,
32     std::shared_ptr<IInputerData> inputerData)
33 {
34     inputerData->OnSetData(authSubType, passwd_);
35 }
36 
SetPasswd(char * pwd,int len)37 void SudoIInputer::SetPasswd(char *pwd, int len)
38 {
39     passwd_.resize(len);
40     for (int i = 0; i < len; i++) {
41         passwd_[i] = *pwd++;
42     }
43 }
44 
~SudoIInputer()45 SudoIInputer::~SudoIInputer()
46 {
47     for (int i = 0; i < (int)passwd_.size(); i++) {
48         passwd_[i] = 0;
49     }
50 }
51 
52 } // PinAuth
53 
54 namespace UserAuth {
SudoIDMCallback()55 SudoIDMCallback::SudoIDMCallback()
56 {
57     verifyResult_ = false;
58 }
59 
OnAcquireInfo(int32_t module,uint32_t acquireInfo,const Attributes & extraInfo)60 void SudoIDMCallback::OnAcquireInfo(int32_t module, uint32_t acquireInfo, const Attributes &extraInfo)
61 {
62     return;
63 }
64 
OnResult(int32_t result,const Attributes & extraInfo)65 void SudoIDMCallback::OnResult(int32_t result, const Attributes &extraInfo)
66 {
67     verifyResult_ = false;
68     if (result == 0) {
69         verifyResult_ = true;
70     }
71     if (!extraInfo.GetUint8ArrayValue(Attributes::ATTR_SIGNATURE, authToken_)) {
72         verifyResult_ = false;
73     }
74 
75     std::unique_lock<std::mutex> lock { g_mutexForAuth };
76     g_authFinish = true;
77     g_condVarForAuth.notify_all();
78 }
79 
GetVerifyResult(void)80 bool SudoIDMCallback::GetVerifyResult(void)
81 {
82     return verifyResult_;
83 }
84 
GetAuthToken()85 std::vector<uint8_t> SudoIDMCallback::GetAuthToken()
86 {
87     return authToken_;
88 }
89 
~SudoIDMCallback()90 SudoIDMCallback::~SudoIDMCallback()
91 {
92     authToken_.assign(authToken_.size(), 0);
93 }
94 
95 } // UserAuth
96 } // UserIam
97 } // OHOS
98