• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_stub.h"
17 
18 #include "account_error_no.h"
19 #include "account_log_wrapper.h"
20 #include "ipc_skeleton.h"
21 
22 namespace OHOS {
23 namespace AccountSA {
24 namespace {
25 constexpr uint32_t MAX_VEC_SIZE = 1024;
26 }
27 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)28 int IDMCallbackStub::OnRemoteRequest(
29     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
30 {
31     ACCOUNT_LOGD("Received stub message: %{public}d, callingUid: %{public}d, callingPid: %{public}d",
32         code, IPCSkeleton::GetCallingUid(), IPCSkeleton::GetCallingRealPid());
33     if (data.ReadInterfaceToken() != GetDescriptor()) {
34         ACCOUNT_LOGE("check IDMCallbackStub descriptor failed! code %{public}u.", code);
35         return ERR_ACCOUNT_COMMON_CHECK_DESCRIPTOR_ERROR;
36     }
37     switch (code) {
38         case static_cast<uint32_t>(IDMCallbackInterfaceCode::ON_ACQUIRE_INFO):
39             return ProcOnAcquireInfo(data, reply);
40         case static_cast<uint32_t>(IDMCallbackInterfaceCode::ON_RESULT):
41             return ProcOnResult(data, reply);
42         default:
43             break;
44     }
45     ACCOUNT_LOGW("remote request unhandled: %{public}d", code);
46     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
47 }
48 
ProcOnAcquireInfo(MessageParcel & data,MessageParcel & reply)49 ErrCode IDMCallbackStub::ProcOnAcquireInfo(MessageParcel &data, MessageParcel &reply)
50 {
51     int32_t module;
52     int32_t acquireInfo;
53     std::vector<uint8_t> buffer;
54     if (!data.ReadInt32(module)) {
55         ACCOUNT_LOGE("failed to read module");
56         return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
57     }
58     if (!data.ReadInt32(acquireInfo)) {
59         ACCOUNT_LOGE("failed to read acquireInfo");
60         return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
61     }
62     if (!data.ReadUInt8Vector(&buffer)) {
63         ACCOUNT_LOGE("failed to read buffer");
64         return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
65     }
66     Attributes extraInfo(buffer);
67     OnAcquireInfo(module, acquireInfo, extraInfo);
68     return ERR_OK;
69 }
70 
ProcOnResult(MessageParcel & data,MessageParcel & reply)71 ErrCode IDMCallbackStub::ProcOnResult(MessageParcel &data, MessageParcel &reply)
72 {
73     int32_t result;
74     if (!data.ReadInt32(result)) {
75         ACCOUNT_LOGE("failed to read result for IDMCallback OnResult");
76         return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
77     }
78     std::vector<uint8_t> buffer;
79     if (!data.ReadUInt8Vector(&buffer)) {
80         ACCOUNT_LOGE("failed to read result for IDMCallback OnResult");
81         return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
82     }
83     Attributes extraInfo(buffer);
84     OnResult(result, extraInfo);
85     return ERR_OK;
86 }
87 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)88 int GetCredInfoCallbackStub::OnRemoteRequest(
89     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
90 {
91     ACCOUNT_LOGD("Received stub message: %{public}d, callingUid: %{public}d, callingPid: %{public}d",
92         code, IPCSkeleton::GetCallingUid(), IPCSkeleton::GetCallingRealPid());
93     if (data.ReadInterfaceToken() != GetDescriptor()) {
94         ACCOUNT_LOGE("check GetCredInfoCallbackStub descriptor failed! code %{public}u.", code);
95         return ERR_ACCOUNT_COMMON_CHECK_DESCRIPTOR_ERROR;
96     }
97     switch (code) {
98         case static_cast<uint32_t>(GetCredInfoCallbackInterfaceCode::ON_CREDENTIAL_INFO):
99             return ProcOnCredentialInfo(data, reply);
100         default:
101             break;
102     }
103     ACCOUNT_LOGW("remote request unhandled: %{public}d", code);
104     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
105 }
106 
ProcOnCredentialInfo(MessageParcel & data,MessageParcel & reply)107 ErrCode GetCredInfoCallbackStub::ProcOnCredentialInfo(MessageParcel &data, MessageParcel &reply)
108 {
109     int32_t result;
110     if (!data.ReadInt32(result)) {
111         ACCOUNT_LOGE("Failed to read result for IDMCallback OnResult");
112         return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
113     }
114     uint32_t vectorSize = 0;
115     std::vector<CredentialInfo> infoList;
116     if (!data.ReadUint32(vectorSize)) {
117         ACCOUNT_LOGE("Read size fail");
118         return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
119     }
120     if (vectorSize > MAX_VEC_SIZE) {
121         ACCOUNT_LOGE("Credential info list is oversize, the limit is %{public}d", MAX_VEC_SIZE);
122         return ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
123     }
124     for (uint32_t i = 0; i < vectorSize; ++i) {
125         CredentialInfo info;
126         int32_t authType = 0;
127         int32_t pinType = 0;
128         if (!data.ReadUint64(info.credentialId)) {
129             ACCOUNT_LOGE("Failed to read credentialId");
130             return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
131         }
132         if (!data.ReadInt32(authType)) {
133             ACCOUNT_LOGE("Failed to read authType");
134             return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
135         }
136         if (!data.ReadInt32(pinType)) {
137             ACCOUNT_LOGE("Failed to read pinSubType");
138             return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
139         }
140         if (!data.ReadUint64(info.templateId)) {
141             ACCOUNT_LOGE("Failed to read templateId");
142             return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
143         }
144         info.authType = static_cast<AuthType>(authType);
145         info.pinType = static_cast<PinSubType>(pinType);
146         infoList.push_back(info);
147     }
148     OnCredentialInfo(result, infoList);
149     return ERR_OK;
150 }
151 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)152 int GetSetPropCallbackStub::OnRemoteRequest(
153     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
154 {
155     ACCOUNT_LOGD("Received stub message: %{public}d, callingUid: %{public}d, callingPid: %{public}d",
156         code, IPCSkeleton::GetCallingUid(), IPCSkeleton::GetCallingRealPid());
157     if (data.ReadInterfaceToken() != GetDescriptor()) {
158         ACCOUNT_LOGE("check GetSetPropCallbackStub descriptor failed! code %{public}u.", code);
159         return ERR_ACCOUNT_COMMON_CHECK_DESCRIPTOR_ERROR;
160     }
161     switch (code) {
162         case static_cast<uint32_t>(GetSetPropCallbackInterfaceCode::ON_RESULT):
163             return ProcOnResult(data, reply);
164         default:
165             break;
166     }
167     ACCOUNT_LOGW("remote request unhandled: %{public}d", code);
168     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
169 }
170 
ProcOnResult(MessageParcel & data,MessageParcel & reply)171 ErrCode GetSetPropCallbackStub::ProcOnResult(MessageParcel &data, MessageParcel &reply)
172 {
173     int32_t result;
174     if (!data.ReadInt32(result)) {
175         ACCOUNT_LOGE("failed to read result for GetSetPropCallback OnResult");
176         return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
177     }
178     std::vector<uint8_t> buffer;
179     if (!data.ReadUInt8Vector(&buffer)) {
180         ACCOUNT_LOGE("failed to read result for GetSetPropCallback OnResult");
181         return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
182     }
183     Attributes extraInfo(buffer);
184     OnResult(result, extraInfo);
185     return ERR_OK;
186 }
187 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)188 int GetEnrolledIdCallbackStub::OnRemoteRequest(
189     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
190 {
191     ACCOUNT_LOGD("Received stub message: %{public}d, callingUid: %{public}d, callingPid: %{public}d",
192         code, IPCSkeleton::GetCallingUid(), IPCSkeleton::GetCallingRealPid());
193     if (data.ReadInterfaceToken() != GetDescriptor()) {
194         ACCOUNT_LOGE("Check GetEnrolledIdCallbackStub descriptor failed! code %{public}u.", code);
195         return ERR_ACCOUNT_COMMON_CHECK_DESCRIPTOR_ERROR;
196     }
197     switch (code) {
198         case static_cast<uint32_t>(GetEnrolledIdCallbackInterfaceCode::ON_ENROLLED_ID):
199             return ProcOnEnrolledId(data, reply);
200         default:
201             break;
202     }
203     ACCOUNT_LOGW("Remote request unhandled: %{public}d", code);
204     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
205 }
206 
ProcOnEnrolledId(MessageParcel & data,MessageParcel & reply)207 ErrCode GetEnrolledIdCallbackStub::ProcOnEnrolledId(MessageParcel &data, MessageParcel &reply)
208 {
209     int32_t result;
210     if (!data.ReadInt32(result)) {
211         ACCOUNT_LOGE("Failed to read result");
212         return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
213     }
214     uint64_t enrolledId;
215     if (!data.ReadUint64(enrolledId)) {
216         ACCOUNT_LOGE("Failed to read enrolledId");
217         return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
218     }
219     OnEnrolledId(result, enrolledId);
220     return ERR_OK;
221 }
222 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)223 int PreRemoteAuthCallbackStub::OnRemoteRequest(
224     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
225 {
226     ACCOUNT_LOGD("Received stub message: %{public}d, callingUid: %{public}d, callingPid: %{public}d",
227         code, IPCSkeleton::GetCallingUid(), IPCSkeleton::GetCallingRealPid());
228     if (data.ReadInterfaceToken() != GetDescriptor()) {
229         ACCOUNT_LOGE("Check PreRemoteAuthCallbackStub descriptor failed, code=%{public}u.", code);
230         return ERR_ACCOUNT_COMMON_CHECK_DESCRIPTOR_ERROR;
231     }
232     switch (code) {
233         case static_cast<uint32_t>(PreRemoteAuthCallbackInterfaceCode::ON_RESULT):
234             return ProcOnResult(data, reply);
235         default:
236             break;
237     }
238     ACCOUNT_LOGW("Remote request unhandled: %{public}d.", code);
239     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
240 }
241 
ProcOnResult(MessageParcel & data,MessageParcel & reply)242 ErrCode PreRemoteAuthCallbackStub::ProcOnResult(MessageParcel &data, MessageParcel &reply)
243 {
244     int32_t result;
245     if (!data.ReadInt32(result)) {
246         ACCOUNT_LOGE("Read result for PreRemoteAuthCallbackStub OnResult failed.");
247         return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR;
248     }
249     OnResult(result);
250     return ERR_OK;
251 }
252 }  // namespace AccountSA
253 }  // namespace OHOS
254