1 /*
2 * Copyright (c) 2021-2023 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 "app_account_stub.h"
17
18 #include "account_error_no.h"
19 #include "account_hisysevent_adapter.h"
20 #include "account_log_wrapper.h"
21 #include "app_account_constants.h"
22 #include "account_constants.h"
23 #include "ipc_skeleton.h"
24 #include "memory_guard.h"
25 #include "os_account_constants.h"
26 #ifdef HICOLLIE_ENABLE
27 #include "xcollie/xcollie.h"
28 #endif // HICOLLIE_ENABLE
29
30 namespace OHOS {
31 namespace AccountSA {
32 #define RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(str, reply) \
33 if (CheckSpecialCharacters(str) != ERR_OK) { \
34 ACCOUNT_LOGE("fail to check special characters"); \
35 if (!(reply).WriteInt32(ERR_ACCOUNT_COMMON_INVALID_PARAMETER)) { \
36 ACCOUNT_LOGE("failed to write reply"); \
37 return IPC_STUB_WRITE_PARCEL_ERR; \
38 } \
39 return ERR_NONE; \
40 } \
41
42 #define RETURN_IF_STRING_IS_OVERSIZE(str, maxSize, msg, reply) \
43 if ((str).size() > (maxSize)) { \
44 ACCOUNT_LOGE("%{public}s, input size: %{public}zu, max size: %{public}zu", msg, (str).size(), maxSize); \
45 if (!(reply).WriteInt32(ERR_ACCOUNT_COMMON_INVALID_PARAMETER)) { \
46 ACCOUNT_LOGE("failed to write reply"); \
47 return IPC_STUB_WRITE_PARCEL_ERR; \
48 } \
49 return ERR_NONE; \
50 } \
51
52 #define RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(str, maxSize, msg, reply) \
53 if ((str).empty() || ((str).size() > (maxSize))) { \
54 ACCOUNT_LOGE("%{public}s, input size: %{public}zu, max size: %{public}zu", msg, (str).size(), maxSize); \
55 if (!(reply).WriteInt32(ERR_ACCOUNT_COMMON_INVALID_PARAMETER)) { \
56 ACCOUNT_LOGE("failed to write reply"); \
57 return IPC_STUB_WRITE_PARCEL_ERR; \
58 } \
59 return ERR_NONE; \
60 } \
61
62 static const std::map<uint32_t, AppAccountStub::MessageProcFunction> messageProcMap = {
63 {
64 static_cast<uint32_t>(AppAccountInterfaceCode::ADD_ACCOUNT),
__anonafd58db00102() 65 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
66 return ptr->ProcAddAccount(code, data, reply); }
67 },
68 {
69 static_cast<uint32_t>(AppAccountInterfaceCode::ADD_ACCOUNT_IMPLICITLY),
__anonafd58db00202() 70 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
71 return ptr->ProcAddAccountImplicitly(code, data, reply); }
72 },
73 {
74 static_cast<uint32_t>(AppAccountInterfaceCode::CREATE_ACCOUNT),
__anonafd58db00302() 75 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
76 return ptr->ProcCreateAccount(code, data, reply); }
77 },
78 {
79 static_cast<uint32_t>(AppAccountInterfaceCode::CREATE_ACCOUNT_IMPLICITLY),
__anonafd58db00402() 80 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
81 return ptr->ProcCreateAccountImplicitly(code, data, reply); }
82 },
83 {
84 static_cast<uint32_t>(AppAccountInterfaceCode::DELETE_ACCOUNT),
__anonafd58db00502() 85 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
86 return ptr->ProcDeleteAccount(code, data, reply); }
87 },
88 {
89 static_cast<uint32_t>(AppAccountInterfaceCode::GET_ACCOUNT_EXTRA_INFO),
__anonafd58db00602() 90 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
91 return ptr->ProcGetAccountExtraInfo(code, data, reply); }
92 },
93 {
94 static_cast<uint32_t>(AppAccountInterfaceCode::SET_ACCOUNT_EXTRA_INFO),
__anonafd58db00702() 95 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
96 return ptr->ProcSetAccountExtraInfo(code, data, reply); }
97 },
98 {
99 static_cast<uint32_t>(AppAccountInterfaceCode::ENABLE_APP_ACCESS),
__anonafd58db00802() 100 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
101 return ptr->ProcSetAppAccess(code, data, reply); }
102 },
103 {
104 static_cast<uint32_t>(AppAccountInterfaceCode::DISABLE_APP_ACCESS),
__anonafd58db00902() 105 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
106 return ptr->ProcSetAppAccess(code, data, reply); }
107 },
108 {
109 static_cast<uint32_t>(AppAccountInterfaceCode::SET_APP_ACCESS),
__anonafd58db00a02() 110 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
111 return ptr->ProcSetAppAccess(code, data, reply); }
112 },
113 {
114 static_cast<uint32_t>(AppAccountInterfaceCode::CHECK_APP_ACCESS),
__anonafd58db00b02() 115 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
116 return ptr->ProcCheckAppAccess(code, data, reply); }
117 },
118 {
119 static_cast<uint32_t>(AppAccountInterfaceCode::CHECK_APP_ACCOUNT_SYNC_ENABLE),
__anonafd58db00c02() 120 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
121 return ptr->ProcCheckAppAccountSyncEnable(code, data, reply); }
122 },
123 {
124 static_cast<uint32_t>(AppAccountInterfaceCode::SET_APP_ACCOUNT_SYNC_ENABLE),
__anonafd58db00d02() 125 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
126 return ptr->ProcSetAppAccountSyncEnable(code, data, reply); }
127 },
128 {
129 static_cast<uint32_t>(AppAccountInterfaceCode::GET_ASSOCIATED_DATA),
__anonafd58db00e02() 130 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
131 return ptr->ProcGetAssociatedData(code, data, reply); }
132 },
133 {
134 static_cast<uint32_t>(AppAccountInterfaceCode::SET_ASSOCIATED_DATA),
__anonafd58db00f02() 135 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
136 return ptr->ProcSetAssociatedData(code, data, reply); }
137 },
138 {
139 static_cast<uint32_t>(AppAccountInterfaceCode::GET_ACCOUNT_CREDENTIAL),
__anonafd58db01002() 140 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
141 return ptr->ProcGetAccountCredential(code, data, reply); }
142 },
143 {
144 static_cast<uint32_t>(AppAccountInterfaceCode::SET_ACCOUNT_CREDENTIAL),
__anonafd58db01102() 145 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
146 return ptr->ProcSetAccountCredential(code, data, reply); }
147 },
148 {
149 static_cast<uint32_t>(AppAccountInterfaceCode::DELETE_ACCOUNT_CREDENTIAL),
__anonafd58db01202() 150 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
151 return ptr->ProcDeleteAccountCredential(code, data, reply); }
152 },
153 {
154 static_cast<uint32_t>(AppAccountInterfaceCode::AUTHENTICATE),
__anonafd58db01302() 155 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
156 return ptr->ProcAuthenticate(code, data, reply); }
157 },
158 {
159 static_cast<uint32_t>(AppAccountInterfaceCode::GET_OAUTH_TOKEN),
__anonafd58db01402() 160 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
161 return ptr->ProcGetAuthToken(code, data, reply); }
162 },
163 {
164 static_cast<uint32_t>(AppAccountInterfaceCode::GET_AUTH_TOKEN),
__anonafd58db01502() 165 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
166 return ptr->ProcGetAuthToken(code, data, reply); }
167 },
168 {
169 static_cast<uint32_t>(AppAccountInterfaceCode::SET_OAUTH_TOKEN),
__anonafd58db01602() 170 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
171 return ptr->ProcSetOAuthToken(code, data, reply); }
172 },
173 {
174 static_cast<uint32_t>(AppAccountInterfaceCode::DELETE_OAUTH_TOKEN),
__anonafd58db01702() 175 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
176 return ptr->ProcDeleteAuthToken(code, data, reply); }
177 },
178 {
179 static_cast<uint32_t>(AppAccountInterfaceCode::DELETE_AUTH_TOKEN),
__anonafd58db01802() 180 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
181 return ptr->ProcDeleteAuthToken(code, data, reply); }
182 },
183 {
184 static_cast<uint32_t>(AppAccountInterfaceCode::SET_OAUTH_TOKEN_VISIBILITY),
__anonafd58db01902() 185 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
186 return ptr->ProcSetAuthTokenVisibility(code, data, reply); }
187 },
188 {
189 static_cast<uint32_t>(AppAccountInterfaceCode::SET_AUTH_TOKEN_VISIBILITY),
__anonafd58db01a02() 190 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
191 return ptr->ProcSetAuthTokenVisibility(code, data, reply); }
192 },
193 {
194 static_cast<uint32_t>(AppAccountInterfaceCode::CHECK_OAUTH_TOKEN_VISIBILITY),
__anonafd58db01b02() 195 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
196 return ptr->ProcCheckAuthTokenVisibility(code, data, reply); }
197 },
198 {
199 static_cast<uint32_t>(AppAccountInterfaceCode::CHECK_AUTH_TOKEN_VISIBILITY),
__anonafd58db01c02() 200 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
201 return ptr->ProcCheckAuthTokenVisibility(code, data, reply); }
202 },
203 {
204 static_cast<uint32_t>(AppAccountInterfaceCode::GET_AUTHENTICATOR_CALLBACK),
__anonafd58db01d02() 205 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
206 return ptr->ProcGetAuthenticatorCallback(code, data, reply); }
207 },
208 {
209 static_cast<uint32_t>(AppAccountInterfaceCode::GET_AUTHENTICATOR_INFO),
__anonafd58db01e02() 210 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
211 return ptr->ProcGetAuthenticatorInfo(code, data, reply); }
212 },
213 {
214 static_cast<uint32_t>(AppAccountInterfaceCode::GET_ALL_OAUTH_TOKENS),
__anonafd58db01f02() 215 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
216 return ptr->ProcGetAllOAuthTokens(code, data, reply); }
217 },
218 {
219 static_cast<uint32_t>(AppAccountInterfaceCode::GET_OAUTH_LIST),
__anonafd58db02002() 220 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
221 return ptr->ProcGetAuthList(code, data, reply); }
222 },
223 {
224 static_cast<uint32_t>(AppAccountInterfaceCode::GET_AUTH_LIST),
__anonafd58db02102() 225 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
226 return ptr->ProcGetAuthList(code, data, reply); }
227 },
228 {
229 static_cast<uint32_t>(AppAccountInterfaceCode::GET_ALL_ACCOUNTS),
__anonafd58db02202() 230 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
231 return ptr->ProcGetAllAccounts(code, data, reply); }
232 },
233 {
234 static_cast<uint32_t>(AppAccountInterfaceCode::GET_ALL_ACCESSIBLE_ACCOUNTS),
__anonafd58db02302() 235 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
236 return ptr->ProcGetAllAccessibleAccounts(code, data, reply); }
237 },
238 {
239 static_cast<uint32_t>(AppAccountInterfaceCode::QUERY_ALL_ACCESSIBLE_ACCOUNTS),
__anonafd58db02402() 240 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
241 return ptr->ProcGetAllAccessibleAccounts(code, data, reply); }
242 },
243 {
244 static_cast<uint32_t>(AppAccountInterfaceCode::SELECT_ACCOUNTS_BY_OPTIONS),
__anonafd58db02502() 245 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
246 return ptr->ProcSelectAccountsByOptions(code, data, reply); }
247 },
248 {
249 static_cast<uint32_t>(AppAccountInterfaceCode::VERIFY_CREDENTIAL),
__anonafd58db02602() 250 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
251 return ptr->ProcVerifyCredential(code, data, reply); }
252 },
253 {
254 static_cast<uint32_t>(AppAccountInterfaceCode::CHECK_ACCOUNT_LABELS),
__anonafd58db02702() 255 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
256 return ptr->ProcCheckAccountLabels(code, data, reply); }
257 },
258 {
259 static_cast<uint32_t>(AppAccountInterfaceCode::SET_AUTHENTICATOR_PROPERTIES),
__anonafd58db02802() 260 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
261 return ptr->ProcSetAuthenticatorProperties(code, data, reply); }
262 },
263 {
264 static_cast<uint32_t>(AppAccountInterfaceCode::SUBSCRIBE_ACCOUNT),
__anonafd58db02902() 265 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
266 return ptr->ProcSubscribeAccount(code, data, reply); }
267 },
268 {
269 static_cast<uint32_t>(AppAccountInterfaceCode::UNSUBSCRIBE_ACCOUNT),
__anonafd58db02a02() 270 [] (AppAccountStub *ptr, uint32_t code, MessageParcel &data, MessageParcel &reply) {
271 return ptr->ProcUnsubscribeAccount(code, data, reply); }
272 },
273 };
274
AppAccountStub()275 AppAccountStub::AppAccountStub()
276 {}
277
~AppAccountStub()278 AppAccountStub::~AppAccountStub()
279 {}
280
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)281 int AppAccountStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
282 {
283 ACCOUNT_LOGD("Received stub message: %{public}d, callingUid: %{public}d", code, IPCSkeleton::GetCallingUid());
284 MemoryGuard cacheGuard;
285 if (data.ReadInterfaceToken() != GetDescriptor()) {
286 ACCOUNT_LOGE("failed to check descriptor! code %{public}u.", code);
287 return ERR_ACCOUNT_COMMON_CHECK_DESCRIPTOR_ERROR;
288 }
289
290 #ifdef HICOLLIE_ENABLE
291 XCollieCallback callbackFunc = [code = code](void *) {
292 ACCOUNT_LOGE("Call app account interface timeout, code = %{public}d.", code);
293 std::string errMsg = "Call app account interface timeout, code = " + std::to_string(code) + ".";
294 REPORT_APP_ACCOUNT_FAIL("", "", Constants::OPERATION_LOG_ERROR,
295 ERR_ACCOUNT_COMMON_OPERATION_TIMEOUT, errMsg);
296 };
297 int32_t timerId = HiviewDFX::XCollie::GetInstance().SetTimer(
298 TIMER_NAME, TIMEOUT, callbackFunc, nullptr, HiviewDFX::XCOLLIE_FLAG_LOG);
299 #endif // HICOLLIE_ENABLE
300
301 auto messageProc = messageProcMap.find(code);
302 if (messageProc != messageProcMap.end()) {
303 auto messageProcFunction = messageProc->second;
304 if (messageProcFunction != nullptr) {
305 int ret = (messageProcFunction)(this, code, data, reply);
306 #ifdef HICOLLIE_ENABLE
307 HiviewDFX::XCollie::GetInstance().CancelTimer(timerId);
308 #endif // HICOLLIE_ENABLE
309 return ret;
310 }
311 }
312
313 ACCOUNT_LOGD("end, code = %{public}u, flags = %{public}u", code, option.GetFlags());
314 #ifdef HICOLLIE_ENABLE
315 HiviewDFX::XCollie::GetInstance().CancelTimer(timerId);
316 #endif // HICOLLIE_ENABLE
317
318 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
319 }
320
321 template<typename T>
WriteParcelableVector(const std::vector<T> & parcelableVector,MessageParcel & data)322 bool AppAccountStub::WriteParcelableVector(const std::vector<T> &parcelableVector, MessageParcel &data)
323 {
324 if (!data.WriteUint32(parcelableVector.size())) {
325 ACCOUNT_LOGE("failed to WriteInt32 for parcelableVector.size()");
326 return false;
327 }
328
329 for (const auto &parcelable : parcelableVector) {
330 if (!data.WriteParcelable(&parcelable)) {
331 ACCOUNT_LOGE("failed to WriteParcelable for parcelable");
332 return false;
333 }
334 }
335
336 return true;
337 }
338
CheckSpecialCharacters(const std::string & str)339 static ErrCode CheckSpecialCharacters(const std::string &str)
340 {
341 for (auto specialCharacter : Constants::SPECIAL_CHARACTERS) {
342 std::size_t found = str.find(specialCharacter);
343 if (found != std::string::npos) {
344 ACCOUNT_LOGE("found a special character, specialCharacter = %{public}c", specialCharacter);
345 return ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
346 }
347 }
348 return ERR_OK;
349 }
350
ProcAddAccount(uint32_t code,MessageParcel & data,MessageParcel & reply)351 ErrCode AppAccountStub::ProcAddAccount(uint32_t code, MessageParcel &data, MessageParcel &reply)
352 {
353 std::string name = data.ReadString();
354 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize", reply);
355 RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name, reply);
356 std::string extraInfo = data.ReadString();
357 RETURN_IF_STRING_IS_OVERSIZE(extraInfo, Constants::EXTRA_INFO_MAX_SIZE, "extraInfo is oversize", reply);
358 ErrCode result = AddAccount(name, extraInfo);
359 if (!reply.WriteInt32(result)) {
360 ACCOUNT_LOGE("failed to write reply");
361 return IPC_STUB_WRITE_PARCEL_ERR;
362 }
363 return ERR_NONE;
364 }
365
ProcAddAccountImplicitly(uint32_t code,MessageParcel & data,MessageParcel & reply)366 ErrCode AppAccountStub::ProcAddAccountImplicitly(uint32_t code, MessageParcel &data, MessageParcel &reply)
367 {
368 std::string owner = data.ReadString();
369 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize", reply);
370 std::string authType = data.ReadString();
371 RETURN_IF_STRING_IS_OVERSIZE(authType, Constants::AUTH_TYPE_MAX_SIZE, "authType is oversize", reply);
372 std::shared_ptr<AAFwk::Want> options(data.ReadParcelable<AAFwk::Want>());
373 auto callback = iface_cast<IAppAccountAuthenticatorCallback>(data.ReadRemoteObject());
374 ErrCode result = ERR_OK;
375 if ((options == nullptr) || (callback == nullptr)) {
376 ACCOUNT_LOGE("invalid options");
377 result = ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
378 } else {
379 result = AddAccountImplicitly(owner, authType, *options, callback);
380 }
381 if (!reply.WriteInt32(result)) {
382 ACCOUNT_LOGE("failed to write reply");
383 return IPC_STUB_WRITE_PARCEL_ERR;
384 }
385 return ERR_NONE;
386 }
387
ProcCreateAccount(uint32_t code,MessageParcel & data,MessageParcel & reply)388 ErrCode AppAccountStub::ProcCreateAccount(uint32_t code, MessageParcel &data, MessageParcel &reply)
389 {
390 std::string name = data.ReadString();
391 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize", reply);
392 sptr<CreateAccountOptions> options = data.ReadParcelable<CreateAccountOptions>();
393 ErrCode result = ERR_OK;
394 if (options == nullptr) {
395 ACCOUNT_LOGE("invalid options");
396 result = ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
397 } else {
398 RETURN_IF_STRING_IS_OVERSIZE(
399 options->customData, Constants::MAX_CUSTOM_DATA_SIZE, "customData is oversize", reply);
400 for (const auto &it : options->customData) {
401 RETURN_IF_STRING_IS_OVERSIZE(
402 it.first, Constants::ASSOCIATED_KEY_MAX_SIZE, "customData key is oversize", reply);
403 RETURN_IF_STRING_IS_OVERSIZE(
404 it.second, Constants::ASSOCIATED_VALUE_MAX_SIZE, "customData value is oversize", reply);
405 }
406 result = CreateAccount(name, *options);
407 }
408 if (!reply.WriteInt32(result)) {
409 ACCOUNT_LOGE("failed to write reply");
410 return IPC_STUB_WRITE_PARCEL_ERR;
411 }
412 return ERR_NONE;
413 }
414
ProcCreateAccountImplicitly(uint32_t code,MessageParcel & data,MessageParcel & reply)415 ErrCode AppAccountStub::ProcCreateAccountImplicitly(uint32_t code, MessageParcel &data, MessageParcel &reply)
416 {
417 std::string owner = data.ReadString();
418 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize", reply);
419 sptr<CreateAccountImplicitlyOptions> options = data.ReadParcelable<CreateAccountImplicitlyOptions>();
420 auto callback = iface_cast<IAppAccountAuthenticatorCallback>(data.ReadRemoteObject());
421 ErrCode result = ERR_OK;
422 if ((options == nullptr) || (callback == nullptr)) {
423 ACCOUNT_LOGE("invalid options");
424 result = ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
425 } else {
426 RETURN_IF_STRING_IS_OVERSIZE(
427 options->authType, Constants::AUTH_TYPE_MAX_SIZE, "authType is empty or oversize", reply);
428 RETURN_IF_STRING_IS_OVERSIZE(options->requiredLabels,
429 Constants::MAX_ALLOWED_ARRAY_SIZE_INPUT, "requiredLabels array is oversize", reply);
430 result = CreateAccountImplicitly(owner, *options, callback);
431 }
432 if (!reply.WriteInt32(result)) {
433 ACCOUNT_LOGE("failed to write reply");
434 return IPC_STUB_WRITE_PARCEL_ERR;
435 }
436 return ERR_NONE;
437 }
438
ProcDeleteAccount(uint32_t code,MessageParcel & data,MessageParcel & reply)439 ErrCode AppAccountStub::ProcDeleteAccount(uint32_t code, MessageParcel &data, MessageParcel &reply)
440 {
441 std::string name = data.ReadString();
442 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize", reply);
443 ErrCode result = DeleteAccount(name);
444 if (!reply.WriteInt32(result)) {
445 ACCOUNT_LOGE("failed to write reply");
446 return IPC_STUB_WRITE_PARCEL_ERR;
447 }
448
449 return ERR_NONE;
450 }
451
ProcGetAccountExtraInfo(uint32_t code,MessageParcel & data,MessageParcel & reply)452 ErrCode AppAccountStub::ProcGetAccountExtraInfo(uint32_t code, MessageParcel &data, MessageParcel &reply)
453 {
454 std::string name = data.ReadString();
455 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize", reply);
456 RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name, reply);
457 std::string extraInfo;
458 ErrCode result = GetAccountExtraInfo(name, extraInfo);
459 if (!reply.WriteInt32(result)) {
460 ACCOUNT_LOGE("failed to write reply");
461 return IPC_STUB_WRITE_PARCEL_ERR;
462 }
463 if (!reply.WriteString(extraInfo)) {
464 ACCOUNT_LOGE("failed to write string for extra info");
465 return IPC_STUB_WRITE_PARCEL_ERR;
466 }
467 return ERR_NONE;
468 }
469
ProcSetAccountExtraInfo(uint32_t code,MessageParcel & data,MessageParcel & reply)470 ErrCode AppAccountStub::ProcSetAccountExtraInfo(uint32_t code, MessageParcel &data, MessageParcel &reply)
471 {
472 std::string name = data.ReadString();
473 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize", reply);
474 RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name, reply);
475 std::string extraInfo = data.ReadString();
476 RETURN_IF_STRING_IS_OVERSIZE(extraInfo, Constants::EXTRA_INFO_MAX_SIZE, "extraInfo is oversize", reply);
477 ErrCode result = SetAccountExtraInfo(name, extraInfo);
478 if (!reply.WriteInt32(result)) {
479 ACCOUNT_LOGE("failed to write reply");
480 return IPC_STUB_WRITE_PARCEL_ERR;
481 }
482 return ERR_NONE;
483 }
484
ProcSetAppAccess(uint32_t code,MessageParcel & data,MessageParcel & reply)485 ErrCode AppAccountStub::ProcSetAppAccess(uint32_t code, MessageParcel &data, MessageParcel &reply)
486 {
487 std::string name = data.ReadString();
488 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize", reply);
489 if (code != static_cast<uint32_t>(AppAccountInterfaceCode::SET_APP_ACCESS)) {
490 RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name, reply);
491 }
492
493 std::string authorizedApp = data.ReadString();
494 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(authorizedApp, Constants::BUNDLE_NAME_MAX_SIZE,
495 "bundleName is empty or oversize", reply);
496
497 ErrCode result = ERR_OK;
498 if (code == static_cast<uint32_t>(AppAccountInterfaceCode::ENABLE_APP_ACCESS)) {
499 result = EnableAppAccess(name, authorizedApp);
500 } else if (code == static_cast<uint32_t>(AppAccountInterfaceCode::DISABLE_APP_ACCESS)) {
501 result = DisableAppAccess(name, authorizedApp);
502 } else if (code == static_cast<uint32_t>(AppAccountInterfaceCode::SET_APP_ACCESS)) {
503 bool isAccessible = data.ReadBool();
504 result = SetAppAccess(name, authorizedApp, isAccessible);
505 } else {
506 ACCOUNT_LOGE("Stub code is invalid, code = %{public}u", code);
507 return IPC_INVOKER_ERR;
508 }
509
510 if (!reply.WriteInt32(result)) {
511 ACCOUNT_LOGE("failed to write result");
512 return IPC_STUB_WRITE_PARCEL_ERR;
513 }
514 return ERR_NONE;
515 }
516
ProcCheckAppAccountSyncEnable(uint32_t code,MessageParcel & data,MessageParcel & reply)517 ErrCode AppAccountStub::ProcCheckAppAccountSyncEnable(uint32_t code, MessageParcel &data, MessageParcel &reply)
518 {
519 std::string name = data.ReadString();
520 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize", reply);
521 bool syncEnable = false;
522 ErrCode result = CheckAppAccountSyncEnable(name, syncEnable);
523 if (!reply.WriteInt32(result)) {
524 ACCOUNT_LOGE("failed to write reply");
525 return IPC_STUB_WRITE_PARCEL_ERR;
526 }
527 if (!reply.WriteBool(syncEnable)) {
528 ACCOUNT_LOGE("failed to write bool for syncEnable");
529 return IPC_STUB_WRITE_PARCEL_ERR;
530 }
531 return ERR_NONE;
532 }
533
ProcSetAppAccountSyncEnable(uint32_t code,MessageParcel & data,MessageParcel & reply)534 ErrCode AppAccountStub::ProcSetAppAccountSyncEnable(uint32_t code, MessageParcel &data, MessageParcel &reply)
535 {
536 std::string name = data.ReadString();
537 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize", reply);
538 bool syncEnable = data.ReadBool();
539 ErrCode result = SetAppAccountSyncEnable(name, syncEnable);
540 if (!reply.WriteInt32(result)) {
541 ACCOUNT_LOGE("failed to write reply");
542 return IPC_STUB_WRITE_PARCEL_ERR;
543 }
544 return ERR_NONE;
545 }
546
ProcGetAssociatedData(uint32_t code,MessageParcel & data,MessageParcel & reply)547 ErrCode AppAccountStub::ProcGetAssociatedData(uint32_t code, MessageParcel &data, MessageParcel &reply)
548 {
549 std::string name = data.ReadString();
550 std::string key = data.ReadString();
551 std::string value;
552 ErrCode result = GetAssociatedData(name, key, value);
553 if (!reply.WriteInt32(result)) {
554 ACCOUNT_LOGE("failed to write reply");
555 return IPC_STUB_WRITE_PARCEL_ERR;
556 }
557 if (!reply.WriteString(value)) {
558 ACCOUNT_LOGE("failed to write string for value");
559 return IPC_STUB_WRITE_PARCEL_ERR;
560 }
561 return ERR_NONE;
562 }
563
ProcSetAssociatedData(uint32_t code,MessageParcel & data,MessageParcel & reply)564 ErrCode AppAccountStub::ProcSetAssociatedData(uint32_t code, MessageParcel &data, MessageParcel &reply)
565 {
566 std::string name = data.ReadString();
567 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize", reply);
568 std::string key = data.ReadString();
569 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(key, Constants::ASSOCIATED_KEY_MAX_SIZE, "key is empty or oversize", reply);
570 std::string value = data.ReadString();
571 RETURN_IF_STRING_IS_OVERSIZE(value, Constants::ASSOCIATED_VALUE_MAX_SIZE, "value is oversize", reply);
572 ErrCode result = SetAssociatedData(name, key, value);
573 if (!reply.WriteInt32(result)) {
574 ACCOUNT_LOGE("failed to write reply");
575 return IPC_STUB_WRITE_PARCEL_ERR;
576 }
577 return ERR_NONE;
578 }
579
ProcGetAccountCredential(uint32_t code,MessageParcel & data,MessageParcel & reply)580 ErrCode AppAccountStub::ProcGetAccountCredential(uint32_t code, MessageParcel &data, MessageParcel &reply)
581 {
582 std::string name = data.ReadString();
583 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize", reply);
584 std::string credentialType = data.ReadString();
585 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(credentialType, Constants::CREDENTIAL_TYPE_MAX_SIZE,
586 "credentialType is empty or oversize", reply);
587 std::string credential;
588 ErrCode result = GetAccountCredential(name, credentialType, credential);
589 if (!reply.WriteInt32(result)) {
590 ACCOUNT_LOGE("failed to write reply");
591 return IPC_STUB_WRITE_PARCEL_ERR;
592 }
593 if (!reply.WriteString(credential)) {
594 ACCOUNT_LOGE("failed to write string for credential");
595 return IPC_STUB_WRITE_PARCEL_ERR;
596 }
597 return ERR_NONE;
598 }
599
ProcSetAccountCredential(uint32_t code,MessageParcel & data,MessageParcel & reply)600 ErrCode AppAccountStub::ProcSetAccountCredential(uint32_t code, MessageParcel &data, MessageParcel &reply)
601 {
602 std::string name = data.ReadString();
603 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize", reply);
604 std::string credentialType = data.ReadString();
605 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(credentialType, Constants::CREDENTIAL_TYPE_MAX_SIZE,
606 "credentialType is empty or oversize", reply);
607 std::string credential = data.ReadString();
608 RETURN_IF_STRING_IS_OVERSIZE(credential, Constants::CREDENTIAL_MAX_SIZE, "credential is oversize", reply);
609 ErrCode result = SetAccountCredential(name, credentialType, credential);
610 if (!reply.WriteInt32(result)) {
611 ACCOUNT_LOGE("failed to write reply");
612 return IPC_STUB_WRITE_PARCEL_ERR;
613 }
614 return ERR_NONE;
615 }
616
ProcAuthenticate(uint32_t code,MessageParcel & data,MessageParcel & reply)617 ErrCode AppAccountStub::ProcAuthenticate(uint32_t code, MessageParcel &data, MessageParcel &reply)
618 {
619 std::string name = data.ReadString();
620 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize", reply);
621 std::string owner = data.ReadString();
622 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize", reply);
623 std::string authType = data.ReadString();
624 RETURN_IF_STRING_IS_OVERSIZE(authType, Constants::AUTH_TYPE_MAX_SIZE, "authType is oversize", reply);
625 std::shared_ptr<AAFwk::Want> options(data.ReadParcelable<AAFwk::Want>());
626 auto callback = iface_cast<IAppAccountAuthenticatorCallback>(data.ReadRemoteObject());
627 ErrCode result = ERR_OK;
628 if ((options == nullptr) || (callback == nullptr)) {
629 ACCOUNT_LOGE("invalid options");
630 result = ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
631 } else {
632 result = Authenticate(name, owner, authType, *options, callback);
633 }
634 if (!reply.WriteInt32(result)) {
635 ACCOUNT_LOGE("failed to write reply");
636 return IPC_STUB_WRITE_PARCEL_ERR;
637 }
638 return ERR_NONE;
639 }
640
ProcGetAuthToken(uint32_t code,MessageParcel & data,MessageParcel & reply)641 ErrCode AppAccountStub::ProcGetAuthToken(uint32_t code, MessageParcel &data, MessageParcel &reply)
642 {
643 std::string name = data.ReadString();
644 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize", reply);
645 std::string owner = data.ReadString();
646 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize", reply);
647 std::string authType = data.ReadString();
648 RETURN_IF_STRING_IS_OVERSIZE(authType, Constants::AUTH_TYPE_MAX_SIZE, "authType is oversize", reply);
649 std::string token;
650 ErrCode result = ERR_OK;
651 if (code == static_cast<uint32_t>(AppAccountInterfaceCode::GET_OAUTH_TOKEN)) {
652 RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name, reply);
653 result = GetOAuthToken(name, owner, authType, token);
654 } else if (code == static_cast<uint32_t>(AppAccountInterfaceCode::GET_AUTH_TOKEN)) {
655 result = GetAuthToken(name, owner, authType, token);
656 } else {
657 ACCOUNT_LOGE("stub code is invalid");
658 return IPC_INVOKER_ERR;
659 }
660 if ((!reply.WriteInt32(result)) || (!reply.WriteString(token))) {
661 ACCOUNT_LOGE("failed to write reply");
662 return IPC_STUB_WRITE_PARCEL_ERR;
663 }
664 return ERR_NONE;
665 }
666
ProcSetOAuthToken(uint32_t code,MessageParcel & data,MessageParcel & reply)667 ErrCode AppAccountStub::ProcSetOAuthToken(uint32_t code, MessageParcel &data, MessageParcel &reply)
668 {
669 std::string name = data.ReadString();
670 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize", reply);
671 std::string authType = data.ReadString();
672 RETURN_IF_STRING_IS_OVERSIZE(authType, Constants::AUTH_TYPE_MAX_SIZE, "authType is oversize", reply);
673 std::string token = data.ReadString();
674 RETURN_IF_STRING_IS_OVERSIZE(token, Constants::TOKEN_MAX_SIZE, "token is oversize", reply);
675 ErrCode result = SetOAuthToken(name, authType, token);
676 if (!reply.WriteInt32(result)) {
677 ACCOUNT_LOGE("failed to write reply");
678 return IPC_STUB_WRITE_PARCEL_ERR;
679 }
680 return ERR_NONE;
681 }
682
ProcDeleteAuthToken(uint32_t code,MessageParcel & data,MessageParcel & reply)683 ErrCode AppAccountStub::ProcDeleteAuthToken(uint32_t code, MessageParcel &data, MessageParcel &reply)
684 {
685 std::string name = data.ReadString();
686 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize", reply);
687 std::string owner = data.ReadString();
688 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize", reply);
689 std::string authType = data.ReadString();
690 RETURN_IF_STRING_IS_OVERSIZE(authType, Constants::AUTH_TYPE_MAX_SIZE, "authType is oversize", reply);
691 std::string token = data.ReadString();
692 RETURN_IF_STRING_IS_OVERSIZE(token, Constants::TOKEN_MAX_SIZE, "token is oversize", reply);
693
694 ErrCode result = ERR_OK;
695 if (code == static_cast<uint32_t>(AppAccountInterfaceCode::DELETE_OAUTH_TOKEN)) {
696 RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name, reply);
697 result = DeleteOAuthToken(name, owner, authType, token);
698 } else if (code == static_cast<uint32_t>(AppAccountInterfaceCode::DELETE_AUTH_TOKEN)) {
699 result = DeleteAuthToken(name, owner, authType, token);
700 } else {
701 ACCOUNT_LOGE("Stub code is invalid, code = %{public}u", code);
702 return IPC_INVOKER_ERR;
703 }
704
705 if (!reply.WriteInt32(result)) {
706 ACCOUNT_LOGE("failed to write result");
707 return IPC_STUB_WRITE_PARCEL_ERR;
708 }
709 return ERR_NONE;
710 }
711
ProcSetAuthTokenVisibility(uint32_t code,MessageParcel & data,MessageParcel & reply)712 ErrCode AppAccountStub::ProcSetAuthTokenVisibility(uint32_t code, MessageParcel &data, MessageParcel &reply)
713 {
714 std::string name = data.ReadString();
715 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize", reply);
716 std::string authType = data.ReadString();
717 RETURN_IF_STRING_IS_OVERSIZE(authType, Constants::AUTH_TYPE_MAX_SIZE, "authType is oversize", reply);
718 std::string bundleName = data.ReadString();
719 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(bundleName, Constants::BUNDLE_NAME_MAX_SIZE,
720 "bundleName is empty or oversize", reply);
721 bool isVisible = data.ReadBool();
722 ErrCode result = ERR_OK;
723 if (code == static_cast<uint32_t>(AppAccountInterfaceCode::SET_OAUTH_TOKEN_VISIBILITY)) {
724 RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name, reply);
725 result = SetOAuthTokenVisibility(name, authType, bundleName, isVisible);
726 } else if (code == static_cast<uint32_t>(AppAccountInterfaceCode::SET_AUTH_TOKEN_VISIBILITY)) {
727 result = SetAuthTokenVisibility(name, authType, bundleName, isVisible);
728 } else {
729 ACCOUNT_LOGE("Stub code is invalid, code = %{public}u", code);
730 return IPC_INVOKER_ERR;
731 }
732
733 if (!reply.WriteInt32(result)) {
734 ACCOUNT_LOGE("failed to write result");
735 return IPC_STUB_WRITE_PARCEL_ERR;
736 }
737 return ERR_NONE;
738 }
739
ProcCheckAuthTokenVisibility(uint32_t code,MessageParcel & data,MessageParcel & reply)740 ErrCode AppAccountStub::ProcCheckAuthTokenVisibility(uint32_t code, MessageParcel &data, MessageParcel &reply)
741 {
742 std::string name = data.ReadString();
743 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize", reply);
744 std::string authType = data.ReadString();
745 RETURN_IF_STRING_IS_OVERSIZE(authType, Constants::AUTH_TYPE_MAX_SIZE, "authType is oversize", reply);
746 std::string bundleName = data.ReadString();
747 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(bundleName, Constants::BUNDLE_NAME_MAX_SIZE,
748 "bundleName is empty or oversize", reply);
749 bool isVisible = false;
750 ErrCode result = ERR_OK;
751 if (code == static_cast<uint32_t>(AppAccountInterfaceCode::CHECK_OAUTH_TOKEN_VISIBILITY)) {
752 RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name, reply);
753 result = CheckOAuthTokenVisibility(name, authType, bundleName, isVisible);
754 } else if (code == static_cast<uint32_t>(AppAccountInterfaceCode::CHECK_AUTH_TOKEN_VISIBILITY)) {
755 result = CheckAuthTokenVisibility(name, authType, bundleName, isVisible);
756 } else {
757 ACCOUNT_LOGE("stub code is invalid");
758 return IPC_INVOKER_ERR;
759 }
760
761 if ((!reply.WriteInt32(result)) || (!reply.WriteBool(isVisible))) {
762 ACCOUNT_LOGE("failed to write reply");
763 return IPC_STUB_WRITE_PARCEL_ERR;
764 }
765 return ERR_NONE;
766 }
767
ProcGetAuthenticatorInfo(uint32_t code,MessageParcel & data,MessageParcel & reply)768 ErrCode AppAccountStub::ProcGetAuthenticatorInfo(uint32_t code, MessageParcel &data, MessageParcel &reply)
769 {
770 std::string owner = data.ReadString();
771 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize", reply);
772 AuthenticatorInfo info;
773 ErrCode result = GetAuthenticatorInfo(owner, info);
774 if ((!reply.WriteInt32(result)) || (!reply.WriteString(info.owner)) ||
775 (!reply.WriteUint32(info.iconId)) || (!reply.WriteUint32(info.labelId))) {
776 ACCOUNT_LOGE("failed to write reply");
777 return IPC_STUB_WRITE_PARCEL_ERR;
778 }
779 return ERR_NONE;
780 }
781
ProcGetAllOAuthTokens(uint32_t code,MessageParcel & data,MessageParcel & reply)782 ErrCode AppAccountStub::ProcGetAllOAuthTokens(uint32_t code, MessageParcel &data, MessageParcel &reply)
783 {
784 std::string name = data.ReadString();
785 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize", reply);
786 std::string owner = data.ReadString();
787 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize", reply);
788 std::vector<OAuthTokenInfo> tokenInfos;
789 ErrCode result = GetAllOAuthTokens(name, owner, tokenInfos);
790 if ((!reply.WriteInt32(result)) || (!reply.WriteUint32(tokenInfos.size()))) {
791 ACCOUNT_LOGE("failed to write reply");
792 return IPC_STUB_WRITE_PARCEL_ERR;
793 }
794 for (auto tokenInfo : tokenInfos) {
795 if ((!reply.WriteString(tokenInfo.token)) || (!reply.WriteString(tokenInfo.authType))) {
796 ACCOUNT_LOGE("failed to write reply");
797 return IPC_STUB_WRITE_PARCEL_ERR;
798 }
799 }
800 return ERR_NONE;
801 }
802
ProcGetAuthList(uint32_t code,MessageParcel & data,MessageParcel & reply)803 ErrCode AppAccountStub::ProcGetAuthList(uint32_t code, MessageParcel &data, MessageParcel &reply)
804 {
805 std::string name = data.ReadString();
806 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize", reply);
807 std::string authType = data.ReadString();
808 RETURN_IF_STRING_IS_OVERSIZE(authType, Constants::OWNER_MAX_SIZE, "authType is oversize", reply);
809 std::set<std::string> oauthList;
810 ErrCode result = ERR_OK;
811 if (code == static_cast<uint32_t>(AppAccountInterfaceCode::GET_OAUTH_LIST)) {
812 RETURN_IF_STRING_CONTAINS_SPECIAL_CHAR(name, reply);
813 result = GetOAuthList(name, authType, oauthList);
814 } else if (code == static_cast<uint32_t>(AppAccountInterfaceCode::GET_AUTH_LIST)) {
815 result = GetAuthList(name, authType, oauthList);
816 } else {
817 ACCOUNT_LOGE("stub code is invalid");
818 return IPC_INVOKER_ERR;
819 }
820 if ((!reply.WriteInt32(result)) || (!reply.WriteUint32(oauthList.size()))) {
821 ACCOUNT_LOGE("failed to write reply");
822 return IPC_STUB_WRITE_PARCEL_ERR;
823 }
824 for (auto bundleName : oauthList) {
825 if (!reply.WriteString(bundleName)) {
826 ACCOUNT_LOGE("failed to WriteString for bundleName");
827 return IPC_STUB_WRITE_PARCEL_ERR;
828 }
829 }
830 return ERR_NONE;
831 }
832
ProcGetAuthenticatorCallback(uint32_t code,MessageParcel & data,MessageParcel & reply)833 ErrCode AppAccountStub::ProcGetAuthenticatorCallback(uint32_t code, MessageParcel &data, MessageParcel &reply)
834 {
835 std::string sessionId = data.ReadString();
836 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(sessionId, Constants::SESSION_ID_MAX_SIZE,
837 "sessionId is empty or oversize", reply);
838 sptr<IRemoteObject> callback;
839 ErrCode result = GetAuthenticatorCallback(sessionId, callback);
840 if ((!reply.WriteInt32(result)) || (!reply.WriteRemoteObject(callback))) {
841 ACCOUNT_LOGE("failed to write reply");
842 return IPC_STUB_WRITE_PARCEL_ERR;
843 }
844 return ERR_NONE;
845 }
846
ProcGetAllAccounts(uint32_t code,MessageParcel & data,MessageParcel & reply)847 ErrCode AppAccountStub::ProcGetAllAccounts(uint32_t code, MessageParcel &data, MessageParcel &reply)
848 {
849 std::string owner = data.ReadString();
850 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize", reply);
851 std::vector<AppAccountInfo> appAccounts;
852 ErrCode result = GetAllAccounts(owner, appAccounts);
853 if (!reply.WriteInt32(result)) {
854 ACCOUNT_LOGE("failed to write reply");
855 return IPC_STUB_WRITE_PARCEL_ERR;
856 }
857 if (!WriteParcelableVector(appAccounts, reply)) {
858 ACCOUNT_LOGE("failed to write accounts");
859 return IPC_STUB_WRITE_PARCEL_ERR;
860 }
861 return ERR_NONE;
862 }
863
ProcGetAllAccessibleAccounts(uint32_t code,MessageParcel & data,MessageParcel & reply)864 ErrCode AppAccountStub::ProcGetAllAccessibleAccounts(uint32_t code, MessageParcel &data, MessageParcel &reply)
865 {
866 std::vector<AppAccountInfo> appAccounts;
867 ErrCode result = ERR_OK;
868 if (code == static_cast<uint32_t>(AppAccountInterfaceCode::GET_ALL_ACCESSIBLE_ACCOUNTS)) {
869 result = GetAllAccessibleAccounts(appAccounts);
870 } else if (code == static_cast<uint32_t>(AppAccountInterfaceCode::QUERY_ALL_ACCESSIBLE_ACCOUNTS)) {
871 std::string owner = data.ReadString();
872 RETURN_IF_STRING_IS_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is or oversize", reply);
873 result = QueryAllAccessibleAccounts(owner, appAccounts);
874 } else {
875 ACCOUNT_LOGE("Stub code is invalid, code = %{public}u", code);
876 return IPC_INVOKER_ERR;
877 }
878 if (!reply.WriteInt32(result)) {
879 ACCOUNT_LOGE("failed to write result");
880 return IPC_STUB_WRITE_PARCEL_ERR;
881 }
882 if (!WriteParcelableVector(appAccounts, reply)) {
883 ACCOUNT_LOGE("failed to write accessible accounts");
884 return IPC_STUB_WRITE_PARCEL_ERR;
885 }
886 return ERR_NONE;
887 }
888
ProcCheckAppAccess(uint32_t code,MessageParcel & data,MessageParcel & reply)889 ErrCode AppAccountStub::ProcCheckAppAccess(uint32_t code, MessageParcel &data, MessageParcel &reply)
890 {
891 std::string name = data.ReadString();
892 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize", reply);
893 std::string bundleName = data.ReadString();
894 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(bundleName, Constants::BUNDLE_NAME_MAX_SIZE,
895 "bundleName is empty or oversize", reply);
896 bool isAccessible = false;
897 ErrCode result = CheckAppAccess(name, bundleName, isAccessible);
898 if ((!reply.WriteInt32(result)) || (!reply.WriteBool(isAccessible))) {
899 ACCOUNT_LOGE("failed to write reply");
900 return IPC_STUB_WRITE_PARCEL_ERR;
901 }
902 return ERR_NONE;
903 }
904
ProcDeleteAccountCredential(uint32_t code,MessageParcel & data,MessageParcel & reply)905 ErrCode AppAccountStub::ProcDeleteAccountCredential(uint32_t code, MessageParcel &data, MessageParcel &reply)
906 {
907 std::string name = data.ReadString();
908 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize", reply);
909 std::string credentialType = data.ReadString();
910 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(credentialType, Constants::CREDENTIAL_TYPE_MAX_SIZE,
911 "credentialType is empty or oversize", reply);
912 ErrCode result = DeleteAccountCredential(name, credentialType);
913 if (!reply.WriteInt32(result)) {
914 ACCOUNT_LOGE("failed to write reply");
915 return IPC_STUB_WRITE_PARCEL_ERR;
916 }
917 return ERR_NONE;
918 }
919
ProcSelectAccountsByOptions(uint32_t code,MessageParcel & data,MessageParcel & reply)920 ErrCode AppAccountStub::ProcSelectAccountsByOptions(uint32_t code, MessageParcel &data, MessageParcel &reply)
921 {
922 std::shared_ptr<SelectAccountsOptions> options(data.ReadParcelable<SelectAccountsOptions>());
923 auto callback = iface_cast<IAppAccountAuthenticatorCallback>(data.ReadRemoteObject());
924 ErrCode result = ERR_OK;
925 if ((options == nullptr) || (callback == nullptr)) {
926 ACCOUNT_LOGE("invalid parameters");
927 result = ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
928 } else {
929 RETURN_IF_STRING_IS_OVERSIZE(options->allowedAccounts,
930 Constants::MAX_ALLOWED_ARRAY_SIZE_INPUT, "allowedAccounts array is oversize", reply);
931 RETURN_IF_STRING_IS_OVERSIZE(options->allowedOwners,
932 Constants::MAX_ALLOWED_ARRAY_SIZE_INPUT, "allowedOwners array is oversize", reply);
933 RETURN_IF_STRING_IS_OVERSIZE(options->requiredLabels,
934 Constants::MAX_ALLOWED_ARRAY_SIZE_INPUT, "requiredLabels array is oversize", reply);
935 result = SelectAccountsByOptions(*options, callback);
936 }
937 if (!reply.WriteInt32(result)) {
938 ACCOUNT_LOGE("failed to write reply");
939 return IPC_STUB_WRITE_PARCEL_ERR;
940 }
941 return ERR_NONE;
942 }
943
ProcVerifyCredential(uint32_t code,MessageParcel & data,MessageParcel & reply)944 ErrCode AppAccountStub::ProcVerifyCredential(uint32_t code, MessageParcel &data, MessageParcel &reply)
945 {
946 std::string name = data.ReadString();
947 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize", reply);
948 std::string owner = data.ReadString();
949 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize", reply);
950 std::shared_ptr<VerifyCredentialOptions> options(data.ReadParcelable<VerifyCredentialOptions>());
951 auto callback = iface_cast<IAppAccountAuthenticatorCallback>(data.ReadRemoteObject());
952 ErrCode result = ERR_OK;
953 if ((options == nullptr) || (callback == nullptr)) {
954 ACCOUNT_LOGE("invalid parameters");
955 result = ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
956 } else {
957 RETURN_IF_STRING_IS_OVERSIZE(
958 options->credentialType, Constants::CREDENTIAL_TYPE_MAX_SIZE, "the credential type is oversize", reply);
959 RETURN_IF_STRING_IS_OVERSIZE(
960 options->credential, Constants::CREDENTIAL_MAX_SIZE, "the credential is oversize", reply);
961 result = VerifyCredential(name, owner, *options, callback);
962 }
963 if (!reply.WriteInt32(result)) {
964 ACCOUNT_LOGE("failed to write reply");
965 return IPC_STUB_WRITE_PARCEL_ERR;
966 }
967 return ERR_NONE;
968 }
969
ProcCheckAccountLabels(uint32_t code,MessageParcel & data,MessageParcel & reply)970 ErrCode AppAccountStub::ProcCheckAccountLabels(uint32_t code, MessageParcel &data, MessageParcel &reply)
971 {
972 std::string name = data.ReadString();
973 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(name, Constants::NAME_MAX_SIZE, "name is empty or oversize", reply);
974 std::string owner = data.ReadString();
975 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize", reply);
976 std::vector<std::string> labels;
977 data.ReadStringVector(&labels);
978 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(
979 labels, Constants::MAX_ALLOWED_ARRAY_SIZE_INPUT, "labels array is empty or oversize", reply);
980 auto callback = iface_cast<IAppAccountAuthenticatorCallback>(data.ReadRemoteObject());
981 ErrCode result = ERR_OK;
982 if (callback == nullptr) {
983 ACCOUNT_LOGE("invalid options");
984 result = ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
985 } else {
986 result = CheckAccountLabels(name, owner, labels, callback);
987 }
988 if (!reply.WriteInt32(result)) {
989 ACCOUNT_LOGE("failed to write reply");
990 return IPC_STUB_WRITE_PARCEL_ERR;
991 }
992 return ERR_NONE;
993 }
994
ProcSetAuthenticatorProperties(uint32_t code,MessageParcel & data,MessageParcel & reply)995 ErrCode AppAccountStub::ProcSetAuthenticatorProperties(uint32_t code, MessageParcel &data, MessageParcel &reply)
996 {
997 std::string owner = data.ReadString();
998 RETURN_IF_STRING_IS_EMPTY_OR_OVERSIZE(owner, Constants::OWNER_MAX_SIZE, "owner is empty or oversize", reply);
999 std::shared_ptr<SetPropertiesOptions> options(data.ReadParcelable<SetPropertiesOptions>());
1000 auto callback = iface_cast<IAppAccountAuthenticatorCallback>(data.ReadRemoteObject());
1001 ErrCode result = ERR_OK;
1002 if ((options == nullptr) || (callback == nullptr)) {
1003 ACCOUNT_LOGE("invalid parameters");
1004 result = ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
1005 } else {
1006 result = SetAuthenticatorProperties(owner, *options, callback);
1007 }
1008 if (!reply.WriteInt32(result)) {
1009 ACCOUNT_LOGE("failed to write reply");
1010 return IPC_STUB_WRITE_PARCEL_ERR;
1011 }
1012 return ERR_NONE;
1013 }
1014
ProcSubscribeAccount(uint32_t code,MessageParcel & data,MessageParcel & reply)1015 ErrCode AppAccountStub::ProcSubscribeAccount(uint32_t code, MessageParcel &data, MessageParcel &reply)
1016 {
1017 std::unique_ptr<AppAccountSubscribeInfo> subscribeInfo(data.ReadParcelable<AppAccountSubscribeInfo>());
1018 if (!subscribeInfo) {
1019 ACCOUNT_LOGE("failed to read parcelable for subscribeInfo");
1020 return IPC_STUB_INVALID_DATA_ERR;
1021 }
1022 sptr<IRemoteObject> eventListener = data.ReadRemoteObject();
1023 if (eventListener == nullptr) {
1024 ACCOUNT_LOGE("failed to read remote object for eventListener");
1025 return IPC_STUB_INVALID_DATA_ERR;
1026 }
1027 ErrCode result = SubscribeAppAccount(*subscribeInfo, eventListener);
1028 if (!reply.WriteInt32(result)) {
1029 ACCOUNT_LOGE("failed to write reply");
1030 return IPC_STUB_WRITE_PARCEL_ERR;
1031 }
1032 return ERR_NONE;
1033 }
1034
ProcUnsubscribeAccount(uint32_t code,MessageParcel & data,MessageParcel & reply)1035 ErrCode AppAccountStub::ProcUnsubscribeAccount(uint32_t code, MessageParcel &data, MessageParcel &reply)
1036 {
1037 sptr<IRemoteObject> eventListener = data.ReadRemoteObject();
1038 if (eventListener == nullptr) {
1039 ACCOUNT_LOGE("failed to read remote object for eventListener");
1040 return IPC_STUB_INVALID_DATA_ERR;
1041 }
1042 ErrCode result = UnsubscribeAppAccount(eventListener);
1043 if (!reply.WriteInt32(result)) {
1044 ACCOUNT_LOGE("failed to write reply");
1045 return IPC_STUB_WRITE_PARCEL_ERR;
1046 }
1047 return ERR_NONE;
1048 }
1049 } // namespace AccountSA
1050 } // namespace OHOS
1051