1 /*
2 * Copyright (c) 2025 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 "devauthinterface_fuzzer.h"
17
18 #include <cstddef>
19 #include <cstdint>
20 #include <string>
21
22 #include "device_auth.h"
23 #include "device_auth_defines.h"
24 #include "device_auth_ext.h"
25 #include "account_auth_plugin_proxy.h"
26 #include "pake_protocol_dl_common.h"
27 #include "pake_v1_protocol_task_common.h"
28 #include "ipc_adapt.h"
29 #include "json_utils.h"
30 #include "alg_loader.h"
31 #include "mk_agree_task.h"
32 #include "ext_plugin_manager.h"
33 #include "channel_manager.h"
34 #include "soft_bus_channel.h"
35 #include "dev_auth_module_manager.h"
36 #include "mbedtls_ec_adapter.h"
37 #include "account_task_main.h"
38 #include "account_version_util.h"
39 #include "account_module.h"
40 #include "account_multi_task_manager.h"
41 #include "account_task_manager.h"
42 #include "identical_account_group.h"
43 #include "broadcast_manager.h"
44 #include "iso_protocol_common.h"
45 #include "das_lite_token_manager.h"
46 #include "das_standard_token_manager.h"
47 #include "key_manager.h"
48 #include "group_auth_data_operation.h"
49 #include "compatible_bind_sub_session_util.h"
50 #include "compatible_bind_sub_session.h"
51 #include "compatible_auth_sub_session_common.h"
52 #include "compatible_auth_sub_session_util.h"
53 #include "account_unrelated_group_auth.h"
54 #include "das_task_common.h"
55 #include "das_version_util.h"
56 #include "pake_v1_protocol_common.h"
57 #include "dev_session_util.h"
58 #include "pake_v2_protocol_common.h"
59 #include "iso_task_common.h"
60 #include "base/security/device_auth/services/legacy/authenticators/src/account_unrelated/pake_task/pake_v1_task/pake_v1_protocol_task/pake_v1_protocol_task_common.c"
61 #include "base/security/device_auth/services/session_manager/src/session/v2/dev_session_util.c"
62 #include "base/security/device_auth/services/legacy/group_manager/src/group_operation/identical_account_group/identical_account_group.c"
63
64
65 namespace OHOS {
66 #define TEST_PSEUDONYM_ID "5420459D93FE773F9945FD64277FBA2CAB8FB996DDC1D0B97676FBB1242B3930"
67 #define TEST_PSEUDONYM_CHALLENGE "5420459D93FE773F9945FD64277FBA2CAB8FB996DDC1D0B97676FBB1242B3930"
68 #define TEST_CONNECT_PARAMS "TestConnectParams"
69 #define TEST_TRANSMIT_DATA "TestTransmitData"
70 #define TEST_APP_ID "TestAppId"
71 #define TEST_GROUP_ID "E2EE6F830B176B2C96A9F99BFAE2A61F5D1490B9F4A090E9D8C2874C230C7C21"
72 #define TEST_USER_ID "testUserId"
73 #define TEST_DEVICE_ID "testDeviceId"
74 #define TEST_PK_INFO "TestPkInfo"
75 #define TEST_PK_INFO_SIGN "TestPkInfoSign"
76 #define TEST_AUTH_ID "TestAuthId"
77 #define TEST_KEY_LEN_1 10
78 #define TEST_KEY_LEN_2 40
79 #define TEST_KEY_LEN_3 256
80 #define TEST_KEY_LEN_4 128
81 #define TEST_KEY_LEN_5 32
82 #define TEST_LEN 16
83 #define TEST_OS_ACCOUNT_ID 0
84 #define TEST_DEVICE_PK "testDevicePk"
85 #define TEST_VERSION 0
86 #define TEST_RANDOM_LEN 16
87 #define TEST_METHOD_ID 1
88 #define TEST_REQ_ID 123
89 #define TEST_REQ_ID_STR "123"
90 #define TEST_VERSION_ID "1.2.3"
91 #define TEST_PROTOCOL_TYPE 2
92 #define TEST_FAULT_STATUS 3
93 #define TEST_TYPE_ONE 1
94 #define TEST_TYPE_TWO 2
95 static const char *EXT_INFO =
96 "{\"credType\":1,\"keyFormat\":4,\"algorithmType\":3,\"subject\":1,\"issuer\":1,"
97 "\"proofType\":1,\"method\":1,\"authorizedScope\":1,\"userId\":\"TestUserId\","
98 "\"deviceId\":\"TestDeviceId\",\"credOwner\":\"TestAppId\","
99 "\"authorizedAccoutList\":[\"TestName1\",\"TestName2\",\"TestName3\"],"
100 "\"peerUserSpaceId\":100,\"extendInfo\":\"\"}";
101 static const char *CRED_DATA =
102 "{\"keyFormat\":4,\"algorithmType\":3,\"subject\":1,\"issuer\":1,"
103 "\"proofType\":1,\"method\":1,\"authorizedScope\":1,\"userId\":\"TestUserId\","
104 "\"peerUserSpaceId\":100,\"extendInfo\":\"\"}";
105 static const char *TEST_CLIENT_PK = "3059301306072A8648CE3D020106082A8648CE3D030107034200042CFE425AB037B9E6F"
106 "837AED32F0CD4460D509E8C6AEC3A5D49DB25F2DDC133A87434BFDD34";
107 static const char *TEST_SERVER_PK = "020106082A8648CE3D030107034200042CFE425AB037B9E6F837AED32F0CD4460D509E8"
108 "C6AEC3A5D49DB25F2DDC133A87434BFDD34563C2226F838D3951C0F3D";
109
110
CreateSessionTest(int32_t * sessionId,const cJSON * in,cJSON * out)111 static int32_t CreateSessionTest(int32_t *sessionId, const cJSON *in, cJSON *out)
112 {
113 (void)sessionId;
114 (void)in;
115 (void)out;
116 return HC_SUCCESS;
117 }
118
ExcuteCredMgrCmdTest(int32_t osAccount,int32_t cmdId,const cJSON * in,cJSON * out)119 static int32_t ExcuteCredMgrCmdTest(int32_t osAccount, int32_t cmdId, const cJSON *in, cJSON *out)
120 {
121 (void)osAccount;
122 (void)cmdId;
123 (void)in;
124 (void)out;
125 return HC_SUCCESS;
126 }
127
ProcessSessionTest(int32_t * sessionId,const cJSON * in,cJSON * out,int32_t * status)128 static int32_t ProcessSessionTest(int32_t *sessionId, const cJSON *in, cJSON *out, int32_t *status)
129 {
130 (void)sessionId;
131 (void)in;
132 (void)out;
133 (void)status;
134 return HC_SUCCESS;
135 }
136
DestroySessionTest(int32_t sessionId)137 static int32_t DestroySessionTest(int32_t sessionId)
138 {
139 (void)sessionId;
140 return HC_SUCCESS;
141 }
142
InitTest(struct ExtPlugin * extPlugin,const cJSON * params,const struct ExtPluginCtx * context)143 static int32_t InitTest(struct ExtPlugin *extPlugin, const cJSON *params, const struct ExtPluginCtx *context)
144 {
145 (void)extPlugin;
146 (void)params;
147 (void)context;
148 return HC_SUCCESS;
149 }
150
Destroy(struct ExtPlugin * extPlugin)151 static void Destroy(struct ExtPlugin *extPlugin)
152 {
153 (void)extPlugin;
154 }
155
DevAuthInterfaceTestCase001()156 static void DevAuthInterfaceTestCase001()
157 {
158 // account_auth_plugin_proxy.c interface test
159 (void)SetAccountAuthPlugin(nullptr, nullptr);
160 (void)ExcuteCredMgrCmd(DEFAULT_OS_ACCOUNT, 0, nullptr, nullptr);
161 (void)CreateAuthSession(0, nullptr, nullptr);
162 (void)ProcessAuthSession(0, nullptr, nullptr, nullptr);
163 (void)DestroyAuthSession(0);
164 AccountAuthExtPlug plugin = { { 0 }, nullptr, nullptr, nullptr, nullptr };
165 (void)SetAccountAuthPlugin(nullptr, &plugin);
166 (void)ExcuteCredMgrCmd(DEFAULT_OS_ACCOUNT, 0, nullptr, nullptr);
167 (void)CreateAuthSession(0, nullptr, nullptr);
168 (void)ProcessAuthSession(0, nullptr, nullptr, nullptr);
169 (void)DestroyAuthSession(0);
170 plugin.createSession = CreateSessionTest;
171 (void)SetAccountAuthPlugin(nullptr, &plugin);
172 (void)CreateAuthSession(0, nullptr, nullptr);
173 plugin.excuteCredMgrCmd = ExcuteCredMgrCmdTest;
174 (void)SetAccountAuthPlugin(nullptr, &plugin);
175 (void)ExcuteCredMgrCmd(DEFAULT_OS_ACCOUNT, 0, nullptr, nullptr);
176 plugin.processSession = ProcessSessionTest;
177 (void)SetAccountAuthPlugin(nullptr, &plugin);
178 (void)ProcessAuthSession(0, nullptr, nullptr, nullptr);
179 plugin.destroySession = DestroySessionTest;
180 plugin.base.init = InitTest;
181 (void)SetAccountAuthPlugin(nullptr, &plugin);
182 (void)DestroyAuthSession(0);
183 DestoryAccountAuthPlugin();
184 }
185
DevAuthInterfaceTestCase002()186 static void DevAuthInterfaceTestCase002()
187 {
188 // account_auth_plugin_proxy.c interface test
189 (void)SetAccountAuthPlugin(nullptr, nullptr);
190 DestoryAccountAuthPlugin();
191 AccountAuthExtPlug plugin = { { 0 }, nullptr, nullptr, nullptr, nullptr };
192 (void)SetAccountAuthPlugin(nullptr, &plugin);
193 DestoryAccountAuthPlugin();
194 plugin.base.destroy = Destroy;
195 (void)SetAccountAuthPlugin(nullptr, &plugin);
196 DestoryAccountAuthPlugin();
197 }
198
DevAuthInterfaceTestCase003()199 static void DevAuthInterfaceTestCase003()
200 {
201 // pake_protocol_dl_common.c interface test
202 (void)GetPakeDlAlg();
203 PakeBaseParams *baseParams = (PakeBaseParams *)HcMalloc(sizeof(PakeBaseParams), 0);
204 baseParams->loader = GetLoaderInstance();
205 baseParams->isClient = true;
206 (void)GenerateDlPakeParams(baseParams, nullptr);
207 baseParams->epkPeer.length = PAKE_DL_PRIME_LEN;
208 baseParams->supportedDlPrimeMod = DL_PRIME_MOD_384;
209 (void)GenerateDlPakeParams(baseParams, nullptr);
210 baseParams->epkPeer.length = PAKE_DL_PRIME_SMALL_LEN;
211 baseParams->supportedDlPrimeMod = DL_PRIME_MOD_256;
212 baseParams->isClient = false;
213 baseParams->supportedDlPrimeMod = DL_PRIME_MOD_384;
214 (void)GenerateDlPakeParams(baseParams, nullptr);
215 baseParams->supportedDlPrimeMod = DL_PRIME_MOD_256;
216 (void)GenerateDlPakeParams(baseParams, nullptr);
217 baseParams->supportedDlPrimeMod = DL_PRIME_MOD_NONE;
218 (void)GenerateDlPakeParams(baseParams, nullptr);
219 baseParams->supportedDlPrimeMod = DL_PRIME_MOD_256;
220 uint8_t secretVal[TEST_LEN] = { 0 };
221 Uint8Buff secret = { secretVal, TEST_LEN };
222 (void)GenerateDlPakeParams(baseParams, &secret);
223 baseParams->supportedDlPrimeMod = DL_PRIME_MOD_NONE;
224 (void)AgreeDlSharedSecret(baseParams, nullptr);
225 baseParams->epkPeer.length = PAKE_DL_PRIME_LEN;
226 baseParams->supportedDlPrimeMod = DL_PRIME_MOD_384;
227 (void)AgreeDlSharedSecret(baseParams, nullptr);
228 baseParams->epkPeer.length = PAKE_DL_PRIME_SMALL_LEN;
229 baseParams->supportedDlPrimeMod = DL_PRIME_MOD_256;
230 (void)AgreeDlSharedSecret(baseParams, nullptr);
231 HcFree(baseParams);
232 }
233
ConstructPakeV1InParams(CJson * in)234 static void ConstructPakeV1InParams(CJson *in)
235 {
236 (void)AddIntToJson(in, FIELD_OS_ACCOUNT_ID, DEFAULT_OS_ACCOUNT);
237 (void)AddBoolToJson(in, FIELD_IS_CLIENT, true);
238 (void)AddIntToJson(in, FIELD_SELF_TYPE, 0);
239 (void)AddStringToJson(in, FIELD_PKG_NAME, "testPkgName");
240 (void)AddStringToJson(in, FIELD_SERVICE_TYPE, "TestServiceType");
241 (void)AddStringToJson(in, FIELD_SELF_AUTH_ID, "TestAuthId");
242 (void)AddStringToJson(in, FIELD_PEER_AUTH_ID, "TestPeerAuthId");
243 (void)AddBoolToJson(in, FIELD_IS_SELF_FROM_UPGRADE, true);
244 (void)AddBoolToJson(in, FIELD_IS_PEER_FROM_UPGRADE, true);
245 }
246
DevAuthInterfaceTestCase004()247 static void DevAuthInterfaceTestCase004()
248 {
249 // pake_v1_protocol_task_common.c interface test
250 DestroyDasPakeV1Params(nullptr);
251 PakeParams *params = (PakeParams *)HcMalloc(sizeof(PakeParams), 0);
252 params->pseudonymExtInfo.selfNextPseudonymId.val = (uint8_t *)HcMalloc(TEST_LEN, 0);
253 params->pseudonymExtInfo.selfNextPseudonymChallenge.val = (uint8_t *)HcMalloc(TEST_LEN, 0);
254 params->pseudonymExtInfo.peerNextPseudonymId.val = (uint8_t *)HcMalloc(TEST_LEN, 0);
255 DestroyDasPakeV1Params(params);
256 CJson *in = CreateJson();
257 (void)InitDasPakeV1Params(params, in);
258 ConstructPakeV1InParams(in);
259 (void)InitDasPakeV1Params(params, in);
260 (void)LoadPseudonymExtInfoIfNeed(nullptr);
261 (void)LoadPseudonymExtInfoIfNeed(params);
262 (void)AddPseudonymIdAndChallenge(nullptr, nullptr);
263 (void)AddPseudonymIdAndChallenge(params, nullptr);
264 CJson *payload = CreateJson();
265 (void)AddPseudonymIdAndChallenge(params, payload);
266 (void)CheckPseudonymId(nullptr, nullptr);
267 (void)CheckPseudonymId(params, nullptr);
268 (void)AddObjToJson(in, FIELD_PAYLOAD, payload);
269 (void)CheckPseudonymId(params, in);
270 (void)AddStringToJson(payload, FIELD_P2P_PSEUDONYM_ID, TEST_PSEUDONYM_ID);
271 (void)AddObjToJson(in, FIELD_PAYLOAD, payload);
272 (void)CheckPseudonymId(params, in);
273 (void)AddStringToJson(payload, FIELD_PSEUDONYM_CHALLENGE, TEST_PSEUDONYM_CHALLENGE);
274 (void)AddObjToJson(in, FIELD_PAYLOAD, payload);
275 (void)CheckPseudonymId(params, in);
276 FreeJson(in);
277 FreeJson(payload);
278 DestroyDasPakeV1Params(params);
279 HcFree(params);
280 }
281
DevAuthInterfaceTestCase0041()282 static void DevAuthInterfaceTestCase0041()
283 {
284 // pake_v1_protocol_task_common.c static interface test
285 PakeParams *params = (PakeParams *)HcMalloc(sizeof(PakeParams), 0);
286 params->opCode = OP_UNBIND;
287 CJson *in = CreateJson();
288 (void)AddIntToJson(in, FIELD_KEY_LENGTH, TEST_KEY_LEN_1);
289 (void)AllocReturnKey(params, in);
290 params->opCode = CODE_NULL;
291 (void)AddIntToJson(in, FIELD_KEY_LENGTH, TEST_KEY_LEN_1);
292 (void)AllocReturnKey(params, in);
293 (void)AddIntToJson(in, FIELD_KEY_LENGTH, TEST_KEY_LEN_2);
294 (void)AllocReturnKey(params, in);
295 DestroyDasPakeV1Params(params);
296 HcFree(params);
297 FreeJson(in);
298 }
299
DevAuthInterfaceTestCase0042()300 static void DevAuthInterfaceTestCase0042()
301 {
302 // pake_v1_protocol_task_common.c static interface test
303 char *outStr = nullptr;
304 (void)RemoveEscapeForExtInfo(EXT_INFO, &outStr);
305 }
306
DevAuthInterfaceTestCase0043()307 static void DevAuthInterfaceTestCase0043()
308 {
309 // pake_v1_protocol_task_common.c static interface test
310 PakeParams *params = (PakeParams *)HcMalloc(sizeof(PakeParams), 0);
311 params->pseudonymExtInfo.selfNextPseudonymId.val = (uint8_t *)HcMalloc(TEST_LEN, 0);
312 params->pseudonymExtInfo.selfNextPseudonymChallenge.val = (uint8_t *)HcMalloc(TEST_LEN, 0);
313 params->pseudonymExtInfo.peerNextPseudonymId.val = (uint8_t *)HcMalloc(TEST_LEN, 0);
314 CJson *in = CreateJson();
315 uint8_t *selfNextIdVal = reinterpret_cast<uint8_t *>(HcMalloc(PSEUDONYM_ID_LEN, 0));
316 (void)AddByteToJson(in, FIELD_SELF_NEXT_PSEUDONYM_ID, selfNextIdVal, PSEUDONYM_ID_LEN);
317 (void)FillPseudonymPskExtInfo(¶ms->pseudonymExtInfo, in);
318 HcFree(selfNextIdVal);
319 DestroyDasPakeV1Params(params);
320 HcFree(params);
321 FreeJson(in);
322 }
323
DevAuthInterfaceTestCase0044()324 static void DevAuthInterfaceTestCase0044()
325 {
326 // pake_v1_protocol_task_common.c static interface test
327 PakeParams *params = (PakeParams *)HcMalloc(sizeof(PakeParams), 0);
328 CJson *in = CreateJson();
329 (void)CheckPseudonymId(params, in);
330 FreeJson(in);
331 DestroyDasPakeV1Params(params);
332 HcFree(params);
333 }
334
DevAuthInterfaceTestCase0045()335 static void DevAuthInterfaceTestCase0045()
336 {
337 // pake_v1_protocol_task_common.c static interface test
338 PakeParams *params = (PakeParams *)HcMalloc(sizeof(PakeParams), 0);
339 params->pseudonymExtInfo.selfNextPseudonymId.val = (uint8_t *)HcMalloc(TEST_LEN, 0);
340 params->pseudonymExtInfo.selfNextPseudonymChallenge.val = (uint8_t *)HcMalloc(TEST_LEN, 0);
341 params->pseudonymExtInfo.peerNextPseudonymId.val = (uint8_t *)HcMalloc(TEST_LEN, 0);
342 (void)SaveNextPseudonymIdAndChallenge(params);
343 DestroyDasPakeV1Params(params);
344 HcFree(params);
345 }
346
DevAuthInterfaceTestCase005()347 static void DevAuthInterfaceTestCase005()
348 {
349 // ipc_adapt.cpp interface test
350 (void)InitIpcCallBackList();
351 (void)InitIpcCallBackList();
352 DeInitIpcCallBackList();
353 DeInitIpcCallBackList();
354 ResetIpcCallBackNodeByNodeId(-1);
355 ResetIpcCallBackNodeByNodeId(TEST_REQ_ID);
356 ResetIpcCallBackNodeByNodeId(1);
357 (void)InitIpcCallBackList();
358 ResetIpcCallBackNodeByNodeId(1);
359 DeInitIpcCallBackList();
360 AddIpcCbObjByAppId(TEST_APP_ID, 0, 0);
361 (void)InitIpcCallBackList();
362 AddIpcCbObjByAppId(TEST_APP_ID, 0, 0);
363 DeInitIpcCallBackList();
364 AddIpcCallBackByAppId(TEST_APP_ID, nullptr, 0, 0);
365 (void)InitIpcCallBackList();
366 AddIpcCallBackByAppId(TEST_APP_ID, nullptr, 0, 0);
367 DeInitIpcCallBackList();
368 DelIpcCallBackByAppId(TEST_APP_ID, 0);
369 (void)InitIpcCallBackList();
370 DelIpcCallBackByAppId(TEST_APP_ID, 0);
371 DeInitIpcCallBackList();
372 (void)AddReqIdByAppId(TEST_APP_ID, TEST_REQ_ID);
373 (void)InitIpcCallBackList();
374 (void)AddReqIdByAppId(TEST_APP_ID, TEST_REQ_ID);
375 DeInitIpcCallBackList();
376 AddIpcCbObjByReqId(TEST_REQ_ID, 0, 0);
377 (void)InitIpcCallBackList();
378 AddIpcCbObjByReqId(TEST_REQ_ID, 0, 0);
379 DeInitIpcCallBackList();
380 (void)AddIpcCallBackByReqId(TEST_REQ_ID, nullptr, 0, 0);
381 (void)InitIpcCallBackList();
382 (void)AddIpcCallBackByReqId(TEST_REQ_ID, nullptr, 0, 0);
383 DeInitIpcCallBackList();
384 DelIpcCallBackByReqId(TEST_REQ_ID, 0, true);
385 DelIpcCallBackByReqId(TEST_REQ_ID, 0, false);
386 }
387
DevAuthInterfaceTestCase006()388 static void DevAuthInterfaceTestCase006()
389 {
390 // ipc_adapt.cpp interface test
391 InitDeviceAuthCbCtx(nullptr, 0);
392 DeviceAuthCallback callback = { 0 };
393 InitDeviceAuthCbCtx(&callback, TEST_TYPE_ONE);
394 InitDeviceAuthCbCtx(&callback, TEST_TYPE_TWO);
395 InitDevAuthListenerCbCtx(nullptr);
396 DataChangeListener listener = { 0 };
397 InitDevAuthListenerCbCtx(&listener);
398 uintptr_t ptr = 0;
399 (void)CreateServiceInstance(&ptr);
400 DestroyServiceInstance(ptr);
401 bool isCallback = IsCallbackMethod(0);
402 isCallback = IsCallbackMethod(TEST_METHOD_ID);
403 }
404
DevAuthInterfaceTestCase007()405 static void DevAuthInterfaceTestCase007()
406 {
407 // mk_agree_task.c interface test
408 (void)CreateMkAgreeTask(0, nullptr, nullptr);
409 CJson *in = CreateJson();
410 (void)CreateMkAgreeTask(0, in, nullptr);
411 MkAgreeTaskBase *task = nullptr;
412 (void)CreateMkAgreeTask(0, in, &task);
413 (void)AddBoolToJson(in, FIELD_IS_CLIENT, true);
414 (void)CreateMkAgreeTask(TASK_TYPE_ISO, in, &task);
415 (void)CreateMkAgreeTask(TEST_PROTOCOL_TYPE, in, &task);
416 FreeJson(in);
417 }
418
InitCredPlugin(void)419 static int32_t InitCredPlugin(void)
420 {
421 return HC_SUCCESS;
422 }
423
InitCredPluginFail(void)424 static int32_t InitCredPluginFail(void)
425 {
426 return HC_ERROR;
427 }
428
DestroyCredPlugin(void)429 static void DestroyCredPlugin(void) {}
430
ProcessCredTest(int32_t osAccountId,int32_t cmdId,CJson * in,CJson * out)431 static int32_t ProcessCredTest(int32_t osAccountId, int32_t cmdId, CJson *in, CJson *out)
432 {
433 (void)osAccountId;
434 (void)cmdId;
435 (void)in;
436 (void)out;
437 return HC_SUCCESS;
438 }
439
DevAuthInterfaceTestCase008()440 static void DevAuthInterfaceTestCase008()
441 {
442 // ext_plugin_manager.c interface test
443 (void)InitCredMgr();
444 (void)ProcCred(0, DEFAULT_OS_ACCOUNT, 0, nullptr, nullptr);
445 (void)AddCredPlugin(nullptr);
446 CredPlugin plugin = { 0 };
447 (void)AddCredPlugin(&plugin);
448 plugin.init = InitCredPlugin;
449 (void)AddCredPlugin(&plugin);
450 plugin.destroy = DestroyCredPlugin;
451 (void)AddCredPlugin(&plugin);
452 plugin.procCred = ProcessCredTest;
453 (void)AddCredPlugin(&plugin);
454 plugin.init = InitCredPluginFail;
455 (void)AddCredPlugin(&plugin);
456 DelCredPlugin(0);
457 DestroyCredMgr();
458 }
459
OnChannelOpenedTest(int64_t requestId,int result)460 static int OnChannelOpenedTest(int64_t requestId, int result)
461 {
462 (void)requestId;
463 (void)result;
464 return 0;
465 }
466
OnChannelClosedTest(void)467 static void OnChannelClosedTest(void) {}
468
OnBytesReceivedTest(int64_t requestId,uint8_t * data,uint32_t dataLen)469 static void OnBytesReceivedTest(int64_t requestId, uint8_t *data, uint32_t dataLen)
470 {
471 (void)requestId;
472 (void)data;
473 (void)dataLen;
474 }
475
OnTransmit(int64_t requestId,const uint8_t * data,uint32_t dataLen)476 static bool OnTransmit(int64_t requestId, const uint8_t *data, uint32_t dataLen)
477 {
478 (void)requestId;
479 (void)data;
480 (void)dataLen;
481 return true;
482 }
483
DevAuthInterfaceTestCase009()484 static void DevAuthInterfaceTestCase009()
485 {
486 // channel_manager.c interface test
487 ChannelProxy proxy = { 0 };
488 proxy.onBytesReceived = OnBytesReceivedTest;
489 proxy.onChannelClosed = OnChannelClosedTest;
490 proxy.onChannelOpened = OnChannelOpenedTest;
491 (void)InitChannelManager(&proxy);
492 DeviceAuthCallback callback = { 0 };
493 CJson *jsonParams = CreateJson();
494 ChannelType type = GetChannelType(&callback, jsonParams);
495 (void)AddStringToJson(jsonParams, FIELD_CONNECT_PARAMS, TEST_CONNECT_PARAMS);
496 type = GetChannelType(&callback, jsonParams);
497 FreeJson(jsonParams);
498 jsonParams = CreateJson();
499 callback.onTransmit = OnTransmit;
500 type = GetChannelType(&callback, jsonParams);
501 FreeJson(jsonParams);
502 (void)OpenChannel(SERVICE_CHANNEL, nullptr, TEST_REQ_ID, nullptr);
503 jsonParams = CreateJson();
504 int64_t returnChannelId = 0;
505 (void)OpenChannel(SOFT_BUS, jsonParams, TEST_REQ_ID, &returnChannelId);
506 (void)AddStringToJson(jsonParams, FIELD_CONNECT_PARAMS, TEST_CONNECT_PARAMS);
507 (void)OpenChannel(SOFT_BUS, jsonParams, TEST_REQ_ID, &returnChannelId);
508 FreeJson(jsonParams);
509 (void)OpenChannel(NO_CHANNEL, nullptr, TEST_REQ_ID, &returnChannelId);
510 CloseChannel(SOFT_BUS, 0);
511 (void)HcSendMsg(SOFT_BUS, TEST_REQ_ID, 0, nullptr, TEST_TRANSMIT_DATA);
512 (void)HcSendMsg(NO_CHANNEL, TEST_REQ_ID, 0, nullptr, nullptr);
513 (void)HcSendMsg(SERVICE_CHANNEL, TEST_REQ_ID, 0, nullptr, nullptr);
514 NotifyBindResult(SOFT_BUS, 0);
515 DestroyChannelManager();
516 }
517
InitModuleTest(void)518 static int32_t InitModuleTest(void)
519 {
520 return HC_SUCCESS;
521 }
522
InitModuleFail(void)523 static int32_t InitModuleFail(void)
524 {
525 return HC_ERROR;
526 }
527
DestroyModuleTest(void)528 static void DestroyModuleTest(void) {}
529
CreateTaskTest(int32_t * taskId,const CJson * in,CJson * out)530 static int CreateTaskTest(int32_t *taskId, const CJson *in, CJson *out)
531 {
532 (void)taskId;
533 (void)in;
534 (void)out;
535 return HC_SUCCESS;
536 }
537
ProcessTaskTest(int32_t taskId,const CJson * in,CJson * out,int32_t * status)538 static int ProcessTaskTest(int32_t taskId, const CJson *in, CJson *out, int32_t *status)
539 {
540 (void)taskId;
541 (void)in;
542 (void)out;
543 (void)status;
544 return HC_SUCCESS;
545 }
546
DestroyTaskTest(int taskId)547 static void DestroyTaskTest(int taskId)
548 {
549 (void)taskId;
550 }
551
DevAuthInterfaceTestCase010()552 static void DevAuthInterfaceTestCase010()
553 {
554 // dev_auth_module_manager.c interface test
555 AuthModuleParams params = { DEFAULT_OS_ACCOUNT, TEST_APP_ID, TEST_GROUP_ID, nullptr, 0 };
556 (void)UnregisterLocalIdentity(¶ms, ACCOUNT_MODULE);
557 InitModules();
558 Uint8Buff authIdBuff = { (uint8_t *)TEST_AUTH_ID, strlen(TEST_AUTH_ID) };
559 params.authId = &authIdBuff;
560 (void)UnregisterLocalIdentity(¶ms, DAS_MODULE);
561 CJson *in = CreateJson();
562 (void)CheckMsgRepeatability(in, DAS_MODULE);
563 (void)UnregisterLocalIdentity(¶ms, DAS_MODULE);
564 (void)CheckMsgRepeatability(nullptr, DAS_MODULE);
565 (void)CheckMsgRepeatability(in, DAS_MODULE);
566 FreeJson(in);
567 in = CreateJson();
568 CJson *out = CreateJson();
569 int32_t taskId = 0;
570 (void)CreateTask(&taskId, in, out, DAS_MODULE);
571 FreeJson(in);
572 FreeJson(out);
573 DestroyTask(0, 0);
574 (void)AddAuthModulePlugin(nullptr);
575 AuthModuleBase plugin = { 0 };
576 (void)AddAuthModulePlugin(&plugin);
577 plugin.init = InitModuleTest;
578 (void)AddAuthModulePlugin(&plugin);
579 plugin.destroy = DestroyModuleTest;
580 (void)AddAuthModulePlugin(&plugin);
581 plugin.createTask = CreateTaskTest;
582 (void)AddAuthModulePlugin(&plugin);
583 plugin.processTask = ProcessTaskTest;
584 (void)AddAuthModulePlugin(&plugin);
585 plugin.destroyTask = DestroyTaskTest;
586 (void)AddAuthModulePlugin(&plugin);
587 plugin.init = InitModuleFail;
588 (void)AddAuthModulePlugin(&plugin);
589 plugin.init = InitModuleTest;
590 (void)AddAuthModulePlugin(&plugin);
591 DelAuthModulePlugin(0);
592 DestroyModules();
593 }
594
DevAuthInterfaceTestCase011()595 static void DevAuthInterfaceTestCase011()
596 {
597 // mbedtls_ec_adapter.c interface test
598 (void)MbedtlsHashToPoint25519(nullptr, nullptr);
599 uint8_t hashVal[64] = { 0 };
600 Uint8Buff hashBuff = { hashVal, 64 };
601 (void)MbedtlsHashToPoint25519(&hashBuff, nullptr);
602 uint8_t outEcPointVal[TEST_KEY_LEN_5] = { 0 };
603 Uint8Buff outEcPointBuff = { outEcPointVal, TEST_KEY_LEN_5 };
604 (void)MbedtlsHashToPoint25519(&hashBuff, &outEcPointBuff);
605 uint8_t validHashVal[TEST_KEY_LEN_5] = { 0 };
606 hashBuff.val = validHashVal;
607 hashBuff.length = TEST_KEY_LEN_5;
608 (void)MbedtlsHashToPoint25519(&hashBuff, &outEcPointBuff);
609 }
610
DevAuthInterfaceTestCase012()611 static void DevAuthInterfaceTestCase012()
612 {
613 // account_task_main.c interface test
614 int32_t taskId = 0;
615 AccountTask *task = CreateAccountTaskT(&taskId, nullptr, nullptr);
616 CJson *in = CreateJson();
617 (void)AddIntToJson(in, FIELD_OPERATION_CODE, MEMBER_JOIN);
618 task = CreateAccountTaskT(&taskId, in, nullptr);
619 (void)AddIntToJson(in, FIELD_CREDENTIAL_TYPE, 0);
620 task = CreateAccountTaskT(&taskId, in, nullptr);
621 InitVersionInfos();
622 (void)AddIntToJson(in, FIELD_OPERATION_CODE, AUTHENTICATE);
623 (void)AddIntToJson(in, FIELD_CREDENTIAL_TYPE, ASYMMETRIC_CRED);
624 task = CreateAccountTaskT(&taskId, in, nullptr);
625 CJson *out = CreateJson();
626 (void)AddIntToJson(in, FIELD_IS_CLIENT, true);
627 task = CreateAccountTaskT(&taskId, in, out);
628 (void)AddIntToJson(in, FIELD_IS_CLIENT, false);
629 task = CreateAccountTaskT(&taskId, in, out);
630 DestroyVersionInfos();
631 FreeJson(in);
632 FreeJson(out);
633 }
634
DevAuthInterfaceTestCase013()635 static void DevAuthInterfaceTestCase013()
636 {
637 // account_module.c interface test
638 const AuthModuleBase *accountModule = GetAccountModule();
639 (void)accountModule->init();
640 bool isIgnored = accountModule->isMsgNeedIgnore(nullptr);
641 CJson *in = CreateJson();
642 (void)AddIntToJson(in, FIELD_OPERATION_CODE, AUTHENTICATE);
643 isIgnored = accountModule->isMsgNeedIgnore(in);
644 (void)AddIntToJson(in, FIELD_OPERATION_CODE, OP_BIND);
645 isIgnored = accountModule->isMsgNeedIgnore(in);
646 (void)AddIntToJson(in, FIELD_OPERATION_CODE, OP_UNBIND);
647 isIgnored = accountModule->isMsgNeedIgnore(in);
648 (void)AddIntToJson(in, FIELD_OPERATION_CODE, AUTHENTICATE);
649 (void)AddIntToJson(in, FIELD_STEP, 1);
650 isIgnored = accountModule->isMsgNeedIgnore(in);
651 FreeJson(in);
652 (void)accountModule->createTask(nullptr, nullptr, nullptr);
653 int32_t taskId = 0;
654 (void)accountModule->createTask(&taskId, nullptr, nullptr);
655 in = CreateJson();
656 (void)accountModule->createTask(&taskId, in, nullptr);
657 CJson *out = CreateJson();
658 (void)accountModule->createTask(&taskId, in, out);
659 (void)AddIntToJson(in, FIELD_OPERATION_CODE, AUTHENTICATE);
660 (void)AddIntToJson(in, FIELD_STEP, 0);
661 (void)accountModule->createTask(&taskId, in, out);
662 FreeJson(in);
663 FreeJson(out);
664 (void)accountModule->processTask(0, nullptr, nullptr, nullptr);
665 accountModule->destroyTask(0);
666 AccountMultiTaskManager *manager = GetAccountMultiTaskManager();
667 (void)manager->addTaskToManager(nullptr);
668 (void)manager->getTaskFromManager(1);
669 accountModule->destroy();
670 }
671
DevAuthInterfaceTestCase014()672 static void DevAuthInterfaceTestCase014()
673 {
674 // identical_account_group.c interface test
675 (void)InitDatabase();
676 (void)InitBroadcastManager();
677 IdenticalAccountGroup *group = (IdenticalAccountGroup *)GetIdenticalAccountGroupInstance();
678 (void)group->delMultiMembersFromGroup(DEFAULT_OS_ACCOUNT, nullptr, nullptr);
679 (void)group->delMultiMembersFromGroup(DEFAULT_OS_ACCOUNT, TEST_APP_ID, nullptr);
680 CJson *jsonParams = CreateJson();
681 (void)group->delMultiMembersFromGroup(DEFAULT_OS_ACCOUNT, TEST_APP_ID, jsonParams);
682 (void)group->addMultiMembersToGroup(DEFAULT_OS_ACCOUNT, nullptr, nullptr);
683 (void)group->addMultiMembersToGroup(DEFAULT_OS_ACCOUNT, TEST_APP_ID, nullptr);
684 (void)group->addMultiMembersToGroup(DEFAULT_OS_ACCOUNT, TEST_APP_ID, jsonParams);
685 (void)group->base.deleteGroup(DEFAULT_OS_ACCOUNT, nullptr, nullptr);
686 (void)group->base.deleteGroup(DEFAULT_OS_ACCOUNT, jsonParams, nullptr);
687 char *returnJsonStr = nullptr;
688 (void)group->base.deleteGroup(DEFAULT_OS_ACCOUNT, jsonParams, &returnJsonStr);
689 (void)group->base.createGroup(DEFAULT_OS_ACCOUNT, nullptr, nullptr);
690 (void)group->base.createGroup(DEFAULT_OS_ACCOUNT, jsonParams, nullptr);
691 (void)group->base.createGroup(DEFAULT_OS_ACCOUNT, jsonParams, &returnJsonStr);
692 (void)AddStringToJson(jsonParams, FIELD_APP_ID, TEST_APP_ID);
693 (void)group->base.createGroup(DEFAULT_OS_ACCOUNT, jsonParams, &returnJsonStr);
694 (void)AddStringToJson(jsonParams, FIELD_USER_ID, TEST_GROUP_ID);
695 (void)group->base.createGroup(DEFAULT_OS_ACCOUNT, jsonParams, &returnJsonStr);
696 (void)AddStringToJson(jsonParams, FIELD_GROUP_ID, TEST_GROUP_ID);
697 (void)group->base.deleteGroup(DEFAULT_OS_ACCOUNT, jsonParams, &returnJsonStr);
698 DestroyDatabase();
699 DestroyBroadcastManager();
700 }
701
DevAuthInterfaceTestCase0141()702 static void DevAuthInterfaceTestCase0141()
703 {
704 // identical_account_group.c static interface test
705 (void)InitDatabase();
706 (void)InitBroadcastManager();
707 (void)GenerateGroupParams(nullptr, nullptr, nullptr);
708 (void)GenerateGroupId(nullptr, nullptr);
709 (void)GenerateIdenticalGroupId(nullptr, nullptr);
710 CJson *in = CreateJson();
711 (void)AddStringToJson(in, FIELD_USER_ID, TEST_USER_ID);
712 (void)GenerateIdenticalGroupId(in, nullptr);
713 FreeJson(in);
714 DestroyDatabase();
715 DestroyBroadcastManager();
716 }
717
DevAuthInterfaceTestCase0142()718 static void DevAuthInterfaceTestCase0142()
719 {
720 // identical_account_group.c static interface test
721 (void)InitDatabase();
722 (void)InitBroadcastManager();
723 CJson *in = CreateJson();
724 (void)ImportSelfToken(TEST_OS_ACCOUNT_ID, in);
725 (void)AddStringToJson(in, FIELD_USER_ID, TEST_USER_ID);
726 (void)ImportSelfToken(TEST_OS_ACCOUNT_ID, in);
727 (void)DelSelfToken(TEST_OS_ACCOUNT_ID, nullptr);
728 FreeJson(in);
729 DestroyDatabase();
730 DestroyBroadcastManager();
731 }
732
DevAuthInterfaceTestCase0143()733 static void DevAuthInterfaceTestCase0143()
734 {
735 // identical_account_group.c static interface test
736 (void)InitDatabase();
737 (void)InitBroadcastManager();
738 CJson *in = CreateJson();
739 (void)GenerateAddTokenParams(in, in);
740 (void)CheckUserIdValid(TEST_OS_ACCOUNT_ID, in, in);
741 (void)AddStringToJson(in, FIELD_USER_ID, TEST_USER_ID);
742 (void)GenerateAddTokenParams(in, in);
743 (void)CheckUserIdValid(TEST_OS_ACCOUNT_ID, in, in);
744 (void)GenerateTrustedDevParams(nullptr, nullptr, nullptr);
745 (void)AddStringToJson(in, FIELD_GROUP_ID, TEST_GROUP_ID);
746 (void)CheckUserIdValid(TEST_OS_ACCOUNT_ID, in, in);
747
748 FreeJson(in);
749 DestroyDatabase();
750 DestroyBroadcastManager();
751 }
752
DevAuthInterfaceTestCase0144()753 static void DevAuthInterfaceTestCase0144()
754 {
755 // identical_account_group.c static interface test
756 (void)InitDatabase();
757 (void)InitBroadcastManager();
758 (void)CheckPeerDeviceNotSelf(nullptr);
759 CJson *in = CreateJson();
760 (void)AddDeviceAndToken(TEST_OS_ACCOUNT_ID, in, in);
761 (void)DelPeerDevice(TEST_OS_ACCOUNT_ID, in, in, true);
762 UpdateTrustedDeviceForMetaNode(TEST_OS_ACCOUNT_ID, nullptr, nullptr);
763
764 (void)AddStringToJson(in, FIELD_GROUP_ID, TEST_GROUP_ID);
765 (void)AddDeviceAndToken(TEST_OS_ACCOUNT_ID, in, in);
766 UpdateTrustedDeviceForMetaNode(TEST_OS_ACCOUNT_ID, in, nullptr);
767
768 (void)DelPeerDevice(TEST_OS_ACCOUNT_ID, in, in, true);
769 FreeJson(in);
770 DestroyDatabase();
771 DestroyBroadcastManager();
772 }
773
774
OnGroupCreated(const char * groupInfo)775 static void OnGroupCreated(const char *groupInfo)
776 {
777 (void)groupInfo;
778 }
779
OnGroupDeleted(const char * groupInfo)780 static void OnGroupDeleted(const char *groupInfo)
781 {
782 (void)groupInfo;
783 }
784
OnDeviceBound(const char * peerUdid,const char * groupInfo)785 static void OnDeviceBound(const char *peerUdid, const char *groupInfo)
786 {
787 (void)peerUdid;
788 (void)groupInfo;
789 }
790
OnDeviceUnBound(const char * peerUdid,const char * groupInfo)791 static void OnDeviceUnBound(const char *peerUdid, const char *groupInfo)
792 {
793 (void)peerUdid;
794 (void)groupInfo;
795 }
796
OnDeviceNotTrusted(const char * peerUdid)797 static void OnDeviceNotTrusted(const char *peerUdid)
798 {
799 (void)peerUdid;
800 }
801
OnLastGroupDeleted(const char * peerUdid,int groupType)802 static void OnLastGroupDeleted(const char *peerUdid, int groupType)
803 {
804 (void)peerUdid;
805 (void)groupType;
806 }
807
OnTrustedDeviceNumChanged(int curTrustedDeviceNum)808 static void OnTrustedDeviceNumChanged(int curTrustedDeviceNum)
809 {
810 (void)curTrustedDeviceNum;
811 }
812
DevAuthInterfaceTestCase015()813 static void DevAuthInterfaceTestCase015()
814 {
815 // broadcast_manager.c interface test
816 (void)InitBroadcastManager();
817 (void)AddListener(nullptr, nullptr);
818 (void)AddListener(TEST_APP_ID, nullptr);
819 DataChangeListener listener = { 0 };
820 (void)AddListener(TEST_APP_ID, &listener);
821 (void)RemoveListener(nullptr);
822 (void)RemoveListener(TEST_APP_ID);
823 const Broadcaster *broadcaster = GetBroadcaster();
824 listener.onDeviceBound = OnDeviceBound;
825 listener.onDeviceNotTrusted = OnDeviceNotTrusted;
826 listener.onDeviceUnBound = OnDeviceUnBound;
827 listener.onGroupCreated = OnGroupCreated;
828 listener.onGroupDeleted = OnGroupDeleted;
829 listener.onLastGroupDeleted = OnLastGroupDeleted;
830 listener.onTrustedDeviceNumChanged = OnTrustedDeviceNumChanged;
831 (void)AddListener(TEST_APP_ID, &listener);
832 broadcaster->postOnTrustedDeviceNumChanged(1);
833 broadcaster->postOnLastGroupDeleted(nullptr, PEER_TO_PEER_GROUP);
834 broadcaster->postOnLastGroupDeleted(TEST_AUTH_ID, PEER_TO_PEER_GROUP);
835 broadcaster->postOnGroupDeleted(nullptr);
836 broadcaster->postOnGroupDeleted("test");
837 broadcaster->postOnGroupCreated(nullptr);
838 broadcaster->postOnGroupCreated("test");
839 broadcaster->postOnDeviceUnBound(nullptr, nullptr);
840 broadcaster->postOnDeviceUnBound(TEST_AUTH_ID, nullptr);
841 broadcaster->postOnDeviceUnBound(TEST_AUTH_ID, "test");
842 broadcaster->postOnDeviceNotTrusted(nullptr);
843 broadcaster->postOnDeviceNotTrusted(TEST_AUTH_ID);
844 broadcaster->postOnDeviceBound(nullptr, nullptr);
845 broadcaster->postOnDeviceBound(TEST_AUTH_ID, nullptr);
846 broadcaster->postOnDeviceBound(TEST_AUTH_ID, "test");
847 (void)RemoveListener(TEST_APP_ID);
848 DestroyBroadcastManager();
849 }
850
DevAuthInterfaceTestCase016()851 static void DevAuthInterfaceTestCase016()
852 {
853 // iso_protocol_common.c interface test
854 (void)IsoServerGenSessionKeyAndCalToken(nullptr, nullptr, nullptr);
855 IsoBaseParams *baseParams = (IsoBaseParams *)HcMalloc(sizeof(IsoBaseParams), 0);
856 baseParams->loader = GetLoaderInstance();
857 (void)IsoServerGenSessionKeyAndCalToken(baseParams, nullptr, nullptr);
858 Uint8Buff tokenFromPeer = { 0 };
859 (void)IsoServerGenSessionKeyAndCalToken(baseParams, &tokenFromPeer, nullptr);
860 Uint8Buff tokenToPeer = { 0 };
861 (void)IsoServerGenSessionKeyAndCalToken(baseParams, &tokenFromPeer, &tokenToPeer);
862 (void)IsoServerGenRandomAndToken(nullptr, nullptr);
863 (void)IsoServerGenRandomAndToken(baseParams, nullptr);
864 (void)IsoClientGenSessionKey(nullptr, 0, nullptr, 0);
865 (void)IsoClientGenSessionKey(baseParams, 0, nullptr, 0);
866 uint8_t hmacVal[TEST_KEY_LEN_5] = { 0 };
867 (void)IsoClientGenSessionKey(baseParams, 0, hmacVal, TEST_KEY_LEN_5);
868 (void)IsoClientCheckAndGenToken(nullptr, nullptr, nullptr);
869 (void)IsoClientCheckAndGenToken(baseParams, nullptr, nullptr);
870 Uint8Buff peerToken = { 0 };
871 (void)IsoClientCheckAndGenToken(baseParams, &peerToken, nullptr);
872 Uint8Buff selfToken = { 0 };
873 (void)IsoClientCheckAndGenToken(baseParams, &peerToken, &selfToken);
874 (void)IsoClientGenRandom(nullptr);
875 HcFree(baseParams);
876 }
877
DevAuthInterfaceTestCase0161()878 static void DevAuthInterfaceTestCase0161()
879 {
880 // iso_protocol_common.c static interface test
881 (void)InitIsoBaseParams(nullptr, nullptr);
882 CJson *in = CreateJson();
883 (void)InitIsoBaseParams(in, nullptr);
884 FreeJson(in);
885 }
886
DevAuthInterfaceTestCase017()887 static void DevAuthInterfaceTestCase017()
888 {
889 // das_lite_token_manager.c interface test
890 const TokenManager *liteManager = GetLiteTokenManagerInstance();
891 Uint8Buff authIdBuff = { (uint8_t *)TEST_AUTH_ID, strlen(TEST_AUTH_ID) };
892 TokenManagerParams params = {
893 .osAccountId = DEFAULT_OS_ACCOUNT,
894 .peerOsAccountId = DEFAULT_OS_ACCOUNT,
895 .pkgName = { (uint8_t *)TEST_APP_ID, HcStrlen(TEST_APP_ID) },
896 .serviceType = { (uint8_t *)TEST_GROUP_ID, HcStrlen(TEST_GROUP_ID) },
897 .authId = authIdBuff,
898 .userType = 0,
899 .isDirectAuthToken = false
900 };
901 (void)liteManager->unregisterLocalIdentity(¶ms);
902 // das_standard_token_manager.c interface test
903 const TokenManager *standardMgr = GetStandardTokenManagerInstance();
904 params.pkgName.val = (uint8_t *)GROUP_MANAGER_PACKAGE_NAME;
905 params.pkgName.length = HcStrlen(GROUP_MANAGER_PACKAGE_NAME);
906 (void)standardMgr->unregisterLocalIdentity(¶ms);
907 params.pkgName.val = (uint8_t *)TEST_APP_ID;
908 params.pkgName.length = HcStrlen(TEST_APP_ID);
909 (void)standardMgr->deletePeerAuthInfo(¶ms);
910 PakeParams *pakeParams = (PakeParams *)HcMalloc(sizeof(PakeParams), 0);
911 pakeParams->baseParams.loader = GetLoaderInstance();
912 char appId[TEST_KEY_LEN_3] = TEST_APP_ID;
913 char groupId[TEST_KEY_LEN_3] = TEST_GROUP_ID;
914 pakeParams->packageName = appId;
915 pakeParams->serviceType = groupId;
916 pakeParams->baseParams.idSelf.val = (uint8_t *)TEST_AUTH_ID;
917 pakeParams->baseParams.idSelf.length = strlen(TEST_AUTH_ID);
918 pakeParams->isSelfFromUpgrade = true;
919 pakeParams->baseParams.idPeer.val = (uint8_t *)TEST_AUTH_ID;
920 pakeParams->baseParams.idPeer.length = strlen(TEST_AUTH_ID);
921 (void)standardMgr->computeAndSavePsk(pakeParams);
922 Uint8Buff returnPkBuff = { 0 };
923 (void)standardMgr->getPublicKey(¶ms, &returnPkBuff);
924 HcFree(pakeParams);
925 }
926
DevAuthInterfaceTestCase018()927 static void DevAuthInterfaceTestCase018()
928 {
929 // key_manager.c interface test
930 (void)GetDevicePubKey(DEFAULT_OS_ACCOUNT, nullptr);
931 (void)DeletePseudonymPsk(DEFAULT_OS_ACCOUNT, nullptr);
932 }
933
DevAuthInterfaceTestCase019()934 static void DevAuthInterfaceTestCase019()
935 {
936 // group_auth_data_operation.c interface test
937 (void)InitDatabase();
938 int32_t authForm = GroupTypeToAuthForm(ACROSS_ACCOUNT_AUTHORIZE_GROUP);
939 authForm = GroupTypeToAuthForm(0);
940 int32_t groupType = AuthFormToGroupType(AUTH_FORM_ACCOUNT_UNRELATED);
941 groupType = AuthFormToGroupType(AUTH_FORM_ACROSS_ACCOUNT);
942 groupType = AuthFormToGroupType(-1);
943 (void)GaGetTrustedDeviceEntryById(DEFAULT_OS_ACCOUNT, nullptr, true, nullptr, nullptr);
944 bool isAccessiblle = GaIsGroupAccessible(DEFAULT_OS_ACCOUNT, nullptr, nullptr);
945 isAccessiblle = GaIsGroupAccessible(DEFAULT_OS_ACCOUNT, TEST_GROUP_ID, nullptr);
946 isAccessiblle = GaIsGroupAccessible(DEFAULT_OS_ACCOUNT, TEST_GROUP_ID, TEST_APP_ID);
947 DestroyDatabase();
948 }
949
DevAuthInterfaceTestCase020()950 static void DevAuthInterfaceTestCase020()
951 {
952 // compatible_bind_sub_session_util.c interface test
953 InformPeerProcessError(TEST_REQ_ID, nullptr, nullptr, -1);
954 CJson *jsonParams = CreateJson();
955 (void)AddStringToJson(jsonParams, FIELD_CHANNEL_ID, "0");
956 InformPeerProcessError(TEST_REQ_ID, jsonParams, nullptr, -1);
957 (void)AddStringToJson(jsonParams, FIELD_APP_ID, TEST_APP_ID);
958 InformPeerProcessError(TEST_REQ_ID, jsonParams, nullptr, -1);
959 FreeJson(jsonParams);
960 (void)CombineConfirmData(MEMBER_JOIN, nullptr, nullptr);
961 (void)CombineConfirmData(MEMBER_INVITE, nullptr, nullptr);
962 // compatible_bind_sub_session.c interface test
963 DestroyCompatibleBindSubSession(nullptr);
964 (void)CreateServerBindSubSession(nullptr, nullptr, nullptr);
965 jsonParams = CreateJson();
966 (void)AddStringToJson(jsonParams, FIELD_REQUEST_ID, TEST_REQ_ID_STR);
967 (void)CreateServerBindSubSession(jsonParams, nullptr, nullptr);
968 (void)AddIntToJson(jsonParams, FIELD_GROUP_OP, MEMBER_INVITE);
969 (void)CreateServerBindSubSession(jsonParams, nullptr, nullptr);
970 FreeJson(jsonParams);
971 (void)CreateClientBindSubSession(nullptr, nullptr, nullptr);
972 jsonParams = CreateJson();
973 (void)AddStringToJson(jsonParams, FIELD_REQUEST_ID, TEST_REQ_ID_STR);
974 (void)CreateClientBindSubSession(jsonParams, nullptr, nullptr);
975 (void)AddIntToJson(jsonParams, FIELD_GROUP_OP, MEMBER_INVITE);
976 (void)CreateClientBindSubSession(jsonParams, nullptr, nullptr);
977 (void)AddIntToJson(jsonParams, FIELD_GROUP_OP, MEMBER_JOIN);
978 (void)CreateClientBindSubSession(jsonParams, nullptr, nullptr);
979 (void)AddIntToJson(jsonParams, FIELD_GROUP_TYPE, IDENTICAL_ACCOUNT_GROUP);
980 (void)CreateClientBindSubSession(jsonParams, nullptr, nullptr);
981 (void)AddIntToJson(jsonParams, FIELD_GROUP_TYPE, PEER_TO_PEER_GROUP);
982 (void)CreateClientBindSubSession(jsonParams, nullptr, nullptr);
983 (void)AddIntToJson(jsonParams, FIELD_GROUP_OP, MEMBER_DELETE);
984 (void)CreateClientBindSubSession(jsonParams, nullptr, nullptr);
985 FreeJson(jsonParams);
986 }
987
DevAuthInterfaceTestCase021()988 static void DevAuthInterfaceTestCase021()
989 {
990 // compatible_auth_sub_session_common.c interface test
991 NotifyPeerAuthError(nullptr, nullptr);
992 (void)HandleAuthTaskStatus(nullptr, nullptr, IGNORE_MSG, true);
993 (void)HandleAuthTaskStatus(nullptr, nullptr, CONTINUE, true);
994 (void)HandleAuthTaskStatus(nullptr, nullptr, TEST_FAULT_STATUS, true);
995 // compatible_auth_sub_session_util.c interface test
996 int32_t authType = GetAuthType(AUTH_FORM_ACROSS_ACCOUNT);
997 authType = GetAuthType(AUTH_FORM_INVALID_TYPE);
998 CJson *confirmJsonParams = CreateJson();
999 (void)AddIntToJson(confirmJsonParams, FIELD_OS_ACCOUNT_ID, INVALID_OS_ACCOUNT);
1000 (void)CombineAuthConfirmData(confirmJsonParams, nullptr);
1001 FreeJson(confirmJsonParams);
1002 int32_t moduleType = GetAuthModuleType(nullptr);
1003 CJson *in = CreateJson();
1004 (void)AddIntToJson(in, FIELD_AUTH_FORM, AUTH_FORM_INVALID_TYPE);
1005 moduleType = GetAuthModuleType(in);
1006 FreeJson(in);
1007 }
1008
DevAuthInterfaceTestCase022()1009 static void DevAuthInterfaceTestCase022()
1010 {
1011 // account_unrelated_group_auth.c interface test
1012 BaseGroupAuth *groupAuth = GetAccountUnrelatedGroupAuth();
1013 groupAuth->onFinish(TEST_REQ_ID, nullptr, nullptr, nullptr);
1014 (void)groupAuth->getAuthParamsVecForServer(nullptr, nullptr);
1015 }
1016
DevAuthInterfaceTestCase023()1017 static void DevAuthInterfaceTestCase023()
1018 {
1019 // das_task_common.c interface test
1020 (void)GetAndCheckKeyLenOnServer(nullptr, 0);
1021 CJson *in = CreateJson();
1022 CJson *payload = CreateJson();
1023 (void)AddObjToJson(in, FIELD_PAYLOAD, payload);
1024 (void)GetAndCheckKeyLenOnServer(in, 0);
1025 (void)AddIntToJson(payload, FIELD_KEY_LENGTH, 1);
1026 (void)AddObjToJson(in, FIELD_PAYLOAD, payload);
1027 (void)GetAndCheckKeyLenOnServer(in, 0);
1028 FreeJson(payload);
1029 FreeJson(in);
1030 (void)GetAuthIdPeerFromPayload(nullptr, nullptr, nullptr);
1031 in = CreateJson();
1032 payload = CreateJson();
1033 (void)AddObjToJson(in, FIELD_PAYLOAD, payload);
1034 (void)GetAuthIdPeerFromPayload(in, nullptr, nullptr);
1035 FreeJson(payload);
1036 FreeJson(in);
1037
1038 Uint8Buff authId = { nullptr, 0 };
1039 (void)GetAndCheckAuthIdPeer(nullptr, nullptr, nullptr);
1040 in = CreateJson();
1041 (void)GetAndCheckAuthIdPeer(in, &authId, &authId);
1042 payload = CreateJson();
1043 (void)AddObjToJson(in, FIELD_PAYLOAD, payload);
1044 (void)GetAndCheckAuthIdPeer(in, &authId, &authId);
1045 (void)AddStringToJson(payload, FIELD_PEER_AUTH_ID, "");
1046 (void)AddObjToJson(in, FIELD_PAYLOAD, payload);
1047 (void)GetAndCheckAuthIdPeer(in, &authId, &authId);
1048 FreeJson(payload);
1049 FreeJson(in);
1050 (void)GetIdPeer(nullptr, nullptr, nullptr, nullptr);
1051 in = CreateJson();
1052 (void)AddStringToJson(in, FIELD_PEER_AUTH_ID, "");
1053 (void)GetIdPeer(in, FIELD_PEER_AUTH_ID, nullptr, nullptr);
1054 FreeJson(in);
1055 (void)GeneratePseudonymPskAlias(nullptr, nullptr, nullptr);
1056 }
1057
DevAuthInterfaceTestCase024()1058 static void DevAuthInterfaceTestCase024()
1059 {
1060 // das_task_common.c interface test
1061 Uint8Buff serviceTypeBuff = { (uint8_t *)TEST_GROUP_ID, 0 };
1062 Uint8Buff authIdBuff = { (uint8_t *)TEST_AUTH_ID, 0 };
1063 uint8_t outKeyAliasVal[TEST_KEY_LEN_3] = { 0 };
1064 Uint8Buff outKeyAliasBuff = { outKeyAliasVal, 0 };
1065 (void)GeneratePseudonymPskAlias(&serviceTypeBuff, &authIdBuff, &outKeyAliasBuff);
1066 serviceTypeBuff.length = HcStrlen(TEST_GROUP_ID);
1067 (void)GeneratePseudonymPskAlias(&serviceTypeBuff, &authIdBuff, &outKeyAliasBuff);
1068 authIdBuff.length = HcStrlen(TEST_AUTH_ID);
1069 (void)GeneratePseudonymPskAlias(&serviceTypeBuff, &authIdBuff, &outKeyAliasBuff);
1070 outKeyAliasBuff.length = TEST_KEY_LEN_3;
1071 serviceTypeBuff.length = SERVICE_TYPE_MAX_LEN + 1;
1072 (void)GeneratePseudonymPskAlias(&serviceTypeBuff, &authIdBuff, &outKeyAliasBuff);
1073 serviceTypeBuff.length = HcStrlen(TEST_GROUP_ID);
1074 authIdBuff.length = AUTH_ID_MAX_LEN + 1;
1075 (void)GeneratePseudonymPskAlias(&serviceTypeBuff, &authIdBuff, &outKeyAliasBuff);
1076 authIdBuff.length = HcStrlen(TEST_AUTH_ID);
1077 (void)GeneratePseudonymPskAlias(&serviceTypeBuff, &authIdBuff, &outKeyAliasBuff);
1078 }
1079
DevAuthInterfaceTestCase025()1080 static void DevAuthInterfaceTestCase025()
1081 {
1082 // das_version_util.c interface test
1083 VersionStruct version = { 0 };
1084 PakeAlgType type = GetSupportedPakeAlg(&version, PAKE_V2);
1085 type = GetSupportedPakeAlg(&version, ISO);
1086 ProtocolType protocolType = GetPrototolType(&version, CODE_NULL);
1087 version.first = 1;
1088 protocolType = GetPrototolType(&version, AUTHENTICATE);
1089 protocolType = GetPrototolType(&version, OP_BIND);
1090 VersionStruct versionSelf = { 0 };
1091 (void)NegotiateVersion(nullptr, &version, &versionSelf);
1092 version.first = 0;
1093 (void)NegotiateVersion(nullptr, &version, &versionSelf);
1094 (void)GetSingleVersionFromJson(nullptr, nullptr);
1095 CJson *jsonObj = CreateJson();
1096 (void)GetSingleVersionFromJson(jsonObj, nullptr);
1097 (void)GetSingleVersionFromJson(jsonObj, &version);
1098 (void)AddStringToJson(jsonObj, FIELD_GROUP_AND_MODULE_VERSION, TEST_REQ_ID_STR);
1099 (void)GetSingleVersionFromJson(jsonObj, &version);
1100 (void)AddStringToJson(jsonObj, FIELD_GROUP_AND_MODULE_VERSION, TEST_VERSION_ID);
1101 (void)GetSingleVersionFromJson(jsonObj, &version);
1102 }
1103
DevAuthInterfaceTestCase026()1104 static void DevAuthInterfaceTestCase026()
1105 {
1106 // pake_v1_protocol_common.c interface test
1107 DestroyPakeV1BaseParams(nullptr);
1108 (void)InitPakeV1BaseParams(DEFAULT_OS_ACCOUNT, nullptr);
1109 (void)ClientConfirmPakeV1Protocol(nullptr);
1110 PakeBaseParams *params = (PakeBaseParams *)HcMalloc(sizeof(PakeBaseParams), 0);
1111 params->loader = GetLoaderInstance();
1112 (void)ClientConfirmPakeV1Protocol(params);
1113 (void)ClientVerifyConfirmPakeV1Protocol(nullptr);
1114 (void)ClientVerifyConfirmPakeV1Protocol(params);
1115 (void)ServerResponsePakeV1Protocol(nullptr);
1116 (void)ServerResponsePakeV1Protocol(params);
1117 (void)ServerConfirmPakeV1Protocol(nullptr);
1118 (void)ServerConfirmPakeV1Protocol(params);
1119 HcFree(params);
1120 }
1121
DevAuthInterfaceTestCase027()1122 static void DevAuthInterfaceTestCase027()
1123 {
1124 // huks_adapter.c interface test
1125 const AlgLoader *loader = GetLoaderInstance();
1126 (void)loader->importSymmetricKey(nullptr, nullptr, KEY_PURPOSE_SIGN_VERIFY, nullptr);
1127 bool ret = loader->checkDlPublicKey(nullptr, nullptr);
1128 Uint8Buff key = { 0 };
1129 ret = loader->checkDlPublicKey(&key, nullptr);
1130 uint8_t keyVal[TEST_KEY_LEN_3] = { 0 };
1131 key.val = keyVal;
1132 key.length = TEST_KEY_LEN_3;
1133 ret = loader->checkDlPublicKey(&key, nullptr);
1134 ret = loader->checkDlPublicKey(&key, "TestPrimeHex");
1135 (void)loader->bigNumCompare(nullptr, nullptr);
1136 Uint8Buff aBuff = { 0 };
1137 Uint8Buff bBuff = { 0 };
1138 (void)loader->bigNumCompare(&aBuff, &bBuff);
1139 (void)loader->sign(nullptr, nullptr, ED25519, nullptr);
1140 (void)loader->generateKeyPair(ED25519, nullptr, nullptr);
1141 Uint8Buff outPrivKey = { 0 };
1142 (void)loader->generateKeyPair(ED25519, &outPrivKey, nullptr);
1143 uint8_t outPrivKeyVal[TEST_KEY_LEN_3] = { 0 };
1144 outPrivKey.val = outPrivKeyVal;
1145 (void)loader->generateKeyPair(ED25519, &outPrivKey, nullptr);
1146 outPrivKey.length = TEST_KEY_LEN_3;
1147 (void)loader->generateKeyPair(ED25519, &outPrivKey, nullptr);
1148 Uint8Buff outPubKey = { 0 };
1149 (void)loader->generateKeyPair(ED25519, &outPrivKey, &outPubKey);
1150 uint8_t outPubKeyVal[TEST_KEY_LEN_3] = { 0 };
1151 outPubKey.val = outPubKeyVal;
1152 (void)loader->generateKeyPair(ED25519, &outPrivKey, &outPubKey);
1153 outPubKey.length = TEST_KEY_LEN_4;
1154 (void)loader->generateKeyPair(ED25519, &outPrivKey, &outPubKey);
1155 }
1156
DevAuthInterfaceTestCase028()1157 static void DevAuthInterfaceTestCase028()
1158 {
1159 // dev_session_util.c interface test
1160 (void)AddPkInfoWithPdid(nullptr, nullptr, false, nullptr);
1161 CJson *context = CreateJson();
1162 (void)AddPkInfoWithPdid(context, nullptr, false, nullptr);
1163 CJson *credJson = CreateJson();
1164 (void)AddPkInfoWithPdid(context, credJson, false, nullptr);
1165 (void)AddPkInfoWithPdid(context, credJson, false, "TestRealPkInfo");
1166 CJson *realPkInfoJson = CreateJson();
1167 (void)AddStringToJson(realPkInfoJson, FIELD_USER_ID, TEST_GROUP_ID);
1168 (void)AddStringToJson(realPkInfoJson, FIELD_DEVICE_ID, TEST_AUTH_ID);
1169 char *realPkInfoStr = PackJsonToString(realPkInfoJson);
1170 FreeJson(realPkInfoJson);
1171 (void)AddPkInfoWithPdid(context, credJson, false, realPkInfoStr);
1172 FreeJsonString(realPkInfoStr);
1173 FreeJson(context);
1174 FreeJson(credJson);
1175 (void)GetRealPkInfoStr(DEFAULT_OS_ACCOUNT, nullptr, nullptr, nullptr);
1176 credJson = CreateJson();
1177 (void)AddStringToJson(credJson, FIELD_PK_INFO, "TestPkInfo");
1178 (void)GetRealPkInfoStr(DEFAULT_OS_ACCOUNT, credJson, nullptr, nullptr);
1179 CJson *pkInfoJson = CreateJson();
1180 (void)AddStringToJson(pkInfoJson, FIELD_USER_ID, TEST_GROUP_ID);
1181 (void)AddStringToJson(pkInfoJson, FIELD_DEVICE_ID, TEST_AUTH_ID);
1182 char *pkInfoStr = PackJsonToString(pkInfoJson);
1183 FreeJson(pkInfoJson);
1184 (void)AddStringToJson(credJson, FIELD_PK_INFO, pkInfoStr);
1185 FreeJsonString(pkInfoStr);
1186 (void)GetRealPkInfoStr(DEFAULT_OS_ACCOUNT, credJson, nullptr, nullptr);
1187 FreeJson(credJson);
1188 }
1189
DevAuthInterfaceTestCase0281()1190 static void DevAuthInterfaceTestCase0281()
1191 {
1192 // dev_session_util.c static interface test
1193 CJson *in = CreateJson();
1194 TrustedDeviceEntry *entry = GetPeerDeviceEntryByContext(TEST_OS_ACCOUNT_ID, in);
1195 (void)AddStringToJson(in, FIELD_GROUP_ID, TEST_GROUP_ID);
1196 entry = GetPeerDeviceEntryByContext(TEST_OS_ACCOUNT_ID, in);
1197 (void)AddStringToJson(in, FIELD_PEER_AUTH_ID, TEST_AUTH_ID);
1198 entry = GetPeerDeviceEntryByContext(TEST_OS_ACCOUNT_ID, in);
1199 FreeJson(in);
1200 }
1201
DevAuthInterfaceTestCase0282()1202 static void DevAuthInterfaceTestCase0282()
1203 {
1204 // dev_session_util.c static interface test
1205 CJson *in = CreateJson();
1206 (void)SetPeerAuthIdByDb(in, TEST_GROUP_ID);
1207 (void)AddIntToJson(in, FIELD_OS_ACCOUNT_ID, TEST_OS_ACCOUNT_ID);
1208 (void)SetPeerAuthIdByDb(in, TEST_GROUP_ID);
1209 (void)AddStringToJson(in, FIELD_PEER_UDID, TEST_AUTH_ID);
1210 (void)SetPeerAuthIdByDb(in, TEST_GROUP_ID);
1211 FreeJson(in);
1212 }
1213
DevAuthInterfaceTestCase0283()1214 static void DevAuthInterfaceTestCase0283()
1215 {
1216 // dev_session_util.c static interface test
1217 CJson *in = CreateJson();
1218 CJson *inputData = CreateJson();
1219 (void)AddStringToJson(in, FIELD_PEER_AUTH_ID, TEST_AUTH_ID);
1220 (void)FillPeerAuthIdIfNeeded(true, in, inputData);
1221 FreeJson(in);
1222 FreeJson(inputData);
1223 }
1224
DevAuthInterfaceTestCase0284()1225 static void DevAuthInterfaceTestCase0284()
1226 {
1227 // dev_session_util.c static interface test
1228 (void)BuildPeerCertInfo(nullptr, nullptr, 0, nullptr);
1229 (void)BuildPeerCertInfo(TEST_PK_INFO, nullptr, 0, nullptr);
1230 (void)BuildPeerCertInfo(TEST_PK_INFO, TEST_PK_INFO_SIGN, 0, nullptr);
1231 }
1232
DevAuthInterfaceTestCase0285()1233 static void DevAuthInterfaceTestCase0285()
1234 {
1235 // dev_session_util.c static interface test
1236 CJson *in = CreateJson();
1237 (void)GetPeerCertInfo(nullptr, nullptr, nullptr);
1238 (void)GetPeerCertInfo(in, nullptr, nullptr);
1239 (void)GetPeerCertInfo(in, in, nullptr);
1240 (void)AddIntToJson(in, FIELD_OS_ACCOUNT_ID, TEST_OS_ACCOUNT_ID);
1241 CertInfo certInfo = { { nullptr, 0 }, { nullptr, 0 }, P256 };
1242 (void)GetPeerCertInfo(in, in, &certInfo);
1243 FreeJson(in);
1244 }
1245
DevAuthInterfaceTestCase0286()1246 static void DevAuthInterfaceTestCase0286()
1247 {
1248 // dev_session_util.c static interface test
1249 CJson *in = CreateJson();
1250 (void)AddMsgToSessionMsg(0, nullptr, nullptr);
1251 (void)AddMsgToSessionMsg(0, in, nullptr);
1252 FreeJson(in);
1253 }
1254
DevAuthInterfaceTestCase0287()1255 static void DevAuthInterfaceTestCase0287()
1256 {
1257 // dev_session_util.c static interface test
1258 (void)IsPeerSameUserId(TEST_OS_ACCOUNT_ID, nullptr);
1259 (void)GeneratePeerInfoJson(nullptr, nullptr);
1260 CJson *in = CreateJson();
1261 (void)AddStringToJson(in, FIELD_USER_ID, TEST_USER_ID);
1262 (void)GeneratePeerInfoJson(in, nullptr);
1263 (void)SetPeerAuthIdByCredAuthInfo(nullptr);
1264 CJson *credDataJson = CreateJsonFromString(CRED_DATA);
1265 (void)AddObjToJson(in, FIELD_CREDENTIAL_OBJ, credDataJson);
1266 FreeJson(credDataJson);
1267 (void)SetPeerAuthIdByCredAuthInfo(in);
1268 FreeJson(in);
1269 }
1270
DevAuthInterfaceTestCase0288()1271 static void DevAuthInterfaceTestCase0288()
1272 {
1273 // dev_session_util.c static interface test
1274 CJson *in = CreateJson();
1275 (void)GetPdidIndexByISInfo(in, nullptr);
1276 (void)AddStringToJson(in, FIELD_USER_ID, TEST_USER_ID);
1277 (void)GetPdidIndexByISInfo(in, nullptr);
1278 FreeJson(in);
1279 }
1280
DevAuthInterfaceTestCase0289()1281 static void DevAuthInterfaceTestCase0289()
1282 {
1283 // dev_session_util.c static interface test
1284 CJson *in = CreateJson();
1285 (void)BuildRealPkInfoJson(nullptr, nullptr, nullptr);
1286 (void)AddStringToJson(in, FIELD_DEVICE_PK, TEST_DEVICE_PK);
1287 (void)BuildRealPkInfoJson(in, nullptr, nullptr);
1288 (void)AddStringToJson(in, FIELD_VERSION, TEST_VERSION);
1289 (void)BuildRealPkInfoJson(in, nullptr, nullptr);
1290 (void)AddStringToJson(in, FIELD_USER_ID, TEST_USER_ID);
1291 (void)BuildRealPkInfoJson(in, in, nullptr);
1292 (void)AddStringToJson(in, FIELD_DEVICE_ID, TEST_DEVICE_ID);
1293 (void)BuildRealPkInfoJson(in, in, nullptr);
1294 FreeJson(in);
1295 }
1296
DevAuthInterfaceTestCase029()1297 static void DevAuthInterfaceTestCase029()
1298 {
1299 // pake_v2_protocol_common.c interface test
1300 DestroyPakeV2BaseParams(nullptr);
1301 (void)ServerConfirmPakeV2Protocol(nullptr);
1302 PakeBaseParams *params = (PakeBaseParams *)HcMalloc(sizeof(PakeBaseParams), 0);
1303 params->loader = GetLoaderInstance();
1304 (void)ServerConfirmPakeV2Protocol(params);
1305 (void)ServerResponsePakeV2Protocol(nullptr);
1306 (void)ServerResponsePakeV2Protocol(params);
1307 (void)ClientVerifyConfirmPakeV2Protocol(nullptr);
1308 (void)ClientVerifyConfirmPakeV2Protocol(params);
1309 (void)ClientConfirmPakeV2Protocol(nullptr);
1310 (void)ClientConfirmPakeV2Protocol(params);
1311 (void)InitPakeV2BaseParams(DEFAULT_OS_ACCOUNT, nullptr);
1312 HcFree(params);
1313 }
1314
DevAuthInterfaceTestCase030()1315 static void DevAuthInterfaceTestCase030()
1316 {
1317 // iso_task_common.c interface test
1318 IsoParams *params = (IsoParams *)HcMalloc(sizeof(IsoParams), 0);
1319 (void)GeneratePsk(nullptr, params);
1320 (void)GenerateKeyAliasInIso(nullptr, nullptr, 0, false);
1321 (void)GenerateKeyAliasInIso(params, nullptr, 0, false);
1322 uint8_t keyAliasVal[TEST_KEY_LEN_3] = { 0 };
1323 (void)GenerateKeyAliasInIso(params, keyAliasVal, 0, false);
1324 params->packageName = (char *)HcMalloc(HcStrlen(TEST_APP_ID) + 1, 0);
1325 (void)memcpy_s(params->packageName, HcStrlen(TEST_APP_ID) + 1, TEST_APP_ID, HcStrlen(TEST_APP_ID));
1326 params->serviceType = (char *)HcMalloc(HcStrlen(TEST_GROUP_ID) + 1, 0);
1327 (void)memcpy_s(params->serviceType, HcStrlen(TEST_GROUP_ID) + 1, TEST_GROUP_ID, HcStrlen(TEST_GROUP_ID));
1328 (void)GenerateKeyAliasInIso(params, keyAliasVal, TEST_KEY_LEN_3, false);
1329 (void)InitIsoParams(params, nullptr);
1330 CJson *in = CreateJson();
1331 (void)AddIntToJson(in, FIELD_OPERATION_CODE, CODE_NULL);
1332 (void)InitIsoParams(params, in);
1333 (void)AddIntToJson(in, FIELD_OPERATION_CODE, AUTHENTICATE);
1334 (void)InitIsoParams(params, in);
1335 (void)AddBoolToJson(in, FIELD_IS_CLIENT, true);
1336 (void)InitIsoParams(params, in);
1337 DestroyIsoParams(nullptr);
1338 HcFree(params);
1339 }
1340
DevAuthInterfaceTestCase031()1341 static void DevAuthInterfaceTestCase031()
1342 {
1343 // das_task_common.c interface test
1344 (void)ServerProtocolMessageOut(nullptr, 0, 0);
1345 CJson *out = CreateJson();
1346 CJson *sendToPeer = CreateJson();
1347 (void)AddObjToJson(out, FIELD_SEND_TO_PEER, sendToPeer);
1348 (void)ServerProtocolMessageOut(out, CODE_NULL, 0);
1349 (void)ClientProtocolMessageOut(nullptr, 0, 0);
1350 (void)ClientProtocolMessageOut(out, CODE_NULL, 0);
1351 FreeJson(sendToPeer);
1352 FreeJson(out);
1353 CJson *in = CreateJson();
1354 (void)AddIntToJson(in, FIELD_MESSAGE, ERR_MESSAGE);
1355 (void)ProtocolMessageIn(in);
1356 FreeJson(in);
1357 }
1358
DevAuthInterfaceTestCase032()1359 static void DevAuthInterfaceTestCase032()
1360 {
1361 // dev_session_util.c interface test
1362 (void)CheckPeerPkInfoForPdid(nullptr, nullptr);
1363 CJson *context = CreateJson();
1364 (void)AddIntToJson(context, FIELD_OS_ACCOUNT_ID, DEFAULT_OS_ACCOUNT);
1365 (void)CheckPeerPkInfoForPdid(context, nullptr);
1366 CJson *inputDataJson = CreateJson();
1367 (void)AddStringToJson(inputDataJson, FIELD_PK_INFO, "TestPkInfo");
1368 (void)CheckPeerPkInfoForPdid(context, inputDataJson);
1369 CJson *pkInfoJson = CreateJson();
1370 (void)AddStringToJson(pkInfoJson, FIELD_PSEUDONYM_ID, "TestPseudonymId");
1371 char *pkInfoStr = PackJsonToString(pkInfoJson);
1372 FreeJson(pkInfoJson);
1373 (void)AddStringToJson(inputDataJson, FIELD_PK_INFO, pkInfoStr);
1374 FreeJsonString(pkInfoStr);
1375 (void)CheckPeerPkInfoForPdid(context, inputDataJson);
1376 FreeJson(context);
1377 FreeJson(inputDataJson);
1378 (void)SetPeerInfoToContext(nullptr, false, nullptr);
1379 inputDataJson = CreateJson();
1380 (void)AddStringToJson(inputDataJson, FIELD_PK_INFO, "TestPkInfo");
1381 (void)SetPeerInfoToContext(nullptr, false, inputDataJson);
1382 pkInfoJson = CreateJson();
1383 pkInfoStr = PackJsonToString(pkInfoJson);
1384 FreeJson(pkInfoJson);
1385 (void)AddStringToJson(inputDataJson, FIELD_PK_INFO, pkInfoStr);
1386 FreeJsonString(pkInfoStr);
1387 (void)SetPeerInfoToContext(nullptr, false, inputDataJson);
1388 FreeJson(inputDataJson);
1389 }
1390
DevAuthInterfaceTestCase0321()1391 static void DevAuthInterfaceTestCase0321()
1392 {
1393 // dev_session_util.c interface test
1394 (void)GetSelfUserId(DEFAULT_OS_ACCOUNT, nullptr, TEST_LEN);
1395 char userId[TEST_LEN];
1396 (void)GetSelfUserId(DEFAULT_OS_ACCOUNT, userId, TEST_LEN);
1397 }
1398
DevAuthInterfaceTestCase033()1399 static void DevAuthInterfaceTestCase033()
1400 {
1401 // huks_adapter.c interface test
1402 const AlgLoader *loader = GetLoaderInstance();
1403 (void)loader->agreeSharedSecretWithStorage(nullptr, nullptr, X25519, 0, nullptr);
1404 (void)loader->getKeyExtInfo(nullptr, nullptr);
1405 KeyParams keyParams = { { nullptr, 0, true }, true, DEFAULT_OS_ACCOUNT };
1406 (void)loader->getKeyExtInfo(&keyParams, nullptr);
1407 uint8_t keyAliasVal[TEST_KEY_LEN_3] = { 0 };
1408 keyParams.keyBuff.key = keyAliasVal;
1409 keyParams.keyBuff.keyLen = TEST_KEY_LEN_3;
1410 (void)loader->getKeyExtInfo(&keyParams, nullptr);
1411 Uint8Buff outExtInfo = { 0 };
1412 (void)loader->getKeyExtInfo(&keyParams, &outExtInfo);
1413 keyParams.isDeStorage = false;
1414 (void)loader->getKeyExtInfo(&keyParams, &outExtInfo);
1415 (void)loader->computePseudonymPsk(nullptr, nullptr, nullptr, nullptr);
1416 KeyParams params = { { 0 }, false, DEFAULT_OS_ACCOUNT };
1417 uint8_t keyValue[TEST_KEY_LEN_3] = { 0 };
1418 params.keyBuff.key = keyValue;
1419 params.keyBuff.keyLen = TEST_KEY_LEN_3;
1420 params.keyBuff.isAlias = true;
1421 params.isDeStorage = true;
1422 (void)loader->computePseudonymPsk(¶ms, nullptr, nullptr, nullptr);
1423 uint8_t pskAliasVal[TEST_KEY_LEN_3] = { 0 };
1424 Uint8Buff pskAlias = { pskAliasVal, TEST_KEY_LEN_3 };
1425 uint8_t outPskVal[TEST_KEY_LEN_5] = { 0 };
1426 Uint8Buff outPsk = { outPskVal, TEST_KEY_LEN_5 };
1427 (void)loader->computePseudonymPsk(¶ms, &pskAlias, nullptr, &outPsk);
1428 Uint8Buff extInfo = { 0 };
1429 (void)loader->computePseudonymPsk(¶ms, &pskAlias, &extInfo, &outPsk);
1430 (void)loader->computeHkdf(nullptr, nullptr, nullptr, nullptr);
1431 (void)loader->computeHmacWithThreeStage(nullptr, nullptr, nullptr);
1432 }
1433
DevAuthInterfaceTestCase034()1434 static void DevAuthInterfaceTestCase034()
1435 {
1436 // account_task_manager.c interface test
1437 DestroyAccountTaskManager();
1438 (void)HasAccountPlugin();
1439 (void)ExecuteAccountAuthCmd(DEFAULT_OS_ACCOUNT, IMPORT_SELF_CREDENTIAL, nullptr, nullptr);
1440 int32_t sessionId = 0;
1441 (void)CreateAccountAuthSession(&sessionId, nullptr, nullptr);
1442 (void)ProcessAccountAuthSession(&sessionId, nullptr, nullptr, nullptr);
1443 (void)DestroyAccountAuthSession(sessionId);
1444 (void)InitAccountTaskManager();
1445 (void)InitAccountTaskManager();
1446 (void)ExecuteAccountAuthCmd(DEFAULT_OS_ACCOUNT, IMPORT_SELF_CREDENTIAL, nullptr, nullptr);
1447 (void)CreateAccountAuthSession(&sessionId, nullptr, nullptr);
1448 (void)ProcessAccountAuthSession(&sessionId, nullptr, nullptr, nullptr);
1449 (void)DestroyAccountAuthSession(sessionId);
1450 DestroyAccountTaskManager();
1451 }
1452
DevAuthInterfaceTestCase035()1453 static void DevAuthInterfaceTestCase035()
1454 {
1455 Uint8Buff pkgNameBuff = { (uint8_t *)TEST_APP_ID, 0 };
1456 Uint8Buff serviceTypeBuff = { (uint8_t *)TEST_GROUP_ID, HcStrlen(TEST_GROUP_ID) };
1457 Uint8Buff authIdBuff = { (uint8_t *)TEST_AUTH_ID, HcStrlen(TEST_AUTH_ID) };
1458 uint8_t outKeyAliasVal[TEST_KEY_LEN_3] = { 0 };
1459 Uint8Buff outKeyAliasBuff = { outKeyAliasVal, TEST_KEY_LEN_3 };
1460 TokenManagerParams tokenParams = { 0 };
1461 tokenParams.pkgName = pkgNameBuff;
1462 tokenParams.serviceType = serviceTypeBuff;
1463 tokenParams.userType = KEY_ALIAS_ACCESSOR_PK;
1464 tokenParams.authId = authIdBuff;
1465 (void)GenerateKeyAlias(&tokenParams, &outKeyAliasBuff);
1466 tokenParams.pkgName.length = HcStrlen(TEST_APP_ID);
1467 tokenParams.serviceType.length = 0;
1468 (void)GenerateKeyAlias(&tokenParams, &outKeyAliasBuff);
1469 tokenParams.serviceType.length = HcStrlen(TEST_GROUP_ID);
1470 tokenParams.authId.length = 0;
1471 (void)GenerateKeyAlias(&tokenParams, &outKeyAliasBuff);
1472 tokenParams.authId.length = HcStrlen(TEST_AUTH_ID);
1473 outKeyAliasBuff.length = 0;
1474 (void)GenerateKeyAlias(&tokenParams, &outKeyAliasBuff);
1475 outKeyAliasBuff.length = TEST_KEY_LEN_3;
1476 tokenParams.pkgName.length = PACKAGE_NAME_MAX_LEN + 1;
1477 (void)GenerateKeyAlias(&tokenParams, &outKeyAliasBuff);
1478 tokenParams.pkgName.length = HcStrlen(TEST_APP_ID);
1479 tokenParams.serviceType.length = SERVICE_TYPE_MAX_LEN + 1;
1480 (void)GenerateKeyAlias(&tokenParams, &outKeyAliasBuff);
1481 tokenParams.serviceType.length = HcStrlen(TEST_GROUP_ID);
1482 tokenParams.authId.length = AUTH_ID_MAX_LEN + 1;
1483 (void)GenerateKeyAlias(&tokenParams, &outKeyAliasBuff);
1484 tokenParams.authId.length = HcStrlen(TEST_AUTH_ID);
1485 tokenParams.userType = KEY_ALIAS_TYPE_END;
1486 (void)GenerateKeyAlias(&tokenParams, &outKeyAliasBuff);
1487 tokenParams.userType = KEY_ALIAS_PSK;
1488 (void)GenerateKeyAlias(&tokenParams, &outKeyAliasBuff);
1489 tokenParams.userType = KEY_ALIAS_AUTH_TOKEN;
1490 (void)GenerateKeyAlias(&tokenParams, &outKeyAliasBuff);
1491 }
1492
DevAuthInterfaceTestCase036()1493 static void DevAuthInterfaceTestCase036()
1494 {
1495 (void)InitDeviceAuthService();
1496 const AccountVerifier *verifier = GetAccountVerifierInstance();
1497 (void)verifier->getClientSharedKey(nullptr, nullptr, nullptr, nullptr);
1498 (void)verifier->getClientSharedKey(TEST_SERVER_PK, nullptr, nullptr, nullptr);
1499 (void)verifier->getClientSharedKey(TEST_SERVER_PK, TEST_APP_ID, nullptr, nullptr);
1500 DataBuff sharedKeyBuff = { nullptr, 0 };
1501 (void)verifier->getClientSharedKey(TEST_SERVER_PK, TEST_APP_ID, &sharedKeyBuff, nullptr);
1502 DataBuff randomBuff = { nullptr, 0 };
1503 (void)verifier->getClientSharedKey(TEST_SERVER_PK, TEST_APP_ID, &sharedKeyBuff, &randomBuff);
1504 (void)verifier->getServerSharedKey(nullptr, nullptr, nullptr, nullptr);
1505 (void)verifier->getServerSharedKey(TEST_CLIENT_PK, nullptr, nullptr, nullptr);
1506 (void)verifier->getServerSharedKey(TEST_CLIENT_PK, TEST_APP_ID, nullptr, nullptr);
1507 (void)verifier->getServerSharedKey(TEST_CLIENT_PK, TEST_APP_ID, &randomBuff, nullptr);
1508 uint8_t randomVal[TEST_RANDOM_LEN] = { 0 };
1509 randomBuff.data = randomVal;
1510 (void)verifier->getServerSharedKey(TEST_CLIENT_PK, TEST_APP_ID, &randomBuff, nullptr);
1511 (void)verifier->getServerSharedKey(TEST_CLIENT_PK, TEST_APP_ID, &randomBuff, &sharedKeyBuff);
1512 randomBuff.length = TEST_RANDOM_LEN;
1513 (void)verifier->getServerSharedKey(TEST_CLIENT_PK, TEST_APP_ID, &randomBuff, &sharedKeyBuff);
1514 verifier->destroyDataBuff(nullptr);
1515 verifier->destroyDataBuff(&sharedKeyBuff);
1516 DestroyDeviceAuthService();
1517 }
1518
DevAuthInterfaceTestCasePart1()1519 static void DevAuthInterfaceTestCasePart1()
1520 {
1521 (void)DevAuthInterfaceTestCase001();
1522 (void)DevAuthInterfaceTestCase002();
1523 (void)DevAuthInterfaceTestCase003();
1524 (void)DevAuthInterfaceTestCase004();
1525 (void)DevAuthInterfaceTestCase0041();
1526 (void)DevAuthInterfaceTestCase0042();
1527 (void)DevAuthInterfaceTestCase0043();
1528 (void)DevAuthInterfaceTestCase0044();
1529 (void)DevAuthInterfaceTestCase0045();
1530 (void)DevAuthInterfaceTestCase005();
1531 (void)DevAuthInterfaceTestCase006();
1532 (void)DevAuthInterfaceTestCase007();
1533 (void)DevAuthInterfaceTestCase008();
1534 (void)DevAuthInterfaceTestCase009();
1535 (void)DevAuthInterfaceTestCase010();
1536 (void)DevAuthInterfaceTestCase011();
1537 (void)DevAuthInterfaceTestCase012();
1538 (void)DevAuthInterfaceTestCase013();
1539 (void)DevAuthInterfaceTestCase014();
1540 (void)DevAuthInterfaceTestCase0141();
1541 (void)DevAuthInterfaceTestCase0142();
1542 (void)DevAuthInterfaceTestCase0143();
1543 (void)DevAuthInterfaceTestCase0144();
1544 (void)DevAuthInterfaceTestCase015();
1545 (void)DevAuthInterfaceTestCase016();
1546 (void)DevAuthInterfaceTestCase0161();
1547 (void)DevAuthInterfaceTestCase017();
1548 }
1549
DevAuthInterfaceTestCasePart2()1550 static void DevAuthInterfaceTestCasePart2()
1551 {
1552 (void)DevAuthInterfaceTestCase018();
1553 (void)DevAuthInterfaceTestCase019();
1554 (void)DevAuthInterfaceTestCase020();
1555 (void)DevAuthInterfaceTestCase021();
1556 (void)DevAuthInterfaceTestCase022();
1557 (void)DevAuthInterfaceTestCase023();
1558 (void)DevAuthInterfaceTestCase024();
1559 (void)DevAuthInterfaceTestCase025();
1560 (void)DevAuthInterfaceTestCase026();
1561 (void)DevAuthInterfaceTestCase027();
1562 (void)DevAuthInterfaceTestCase028();
1563 (void)DevAuthInterfaceTestCase0281();
1564 (void)DevAuthInterfaceTestCase0282();
1565 (void)DevAuthInterfaceTestCase0283();
1566 (void)DevAuthInterfaceTestCase0284();
1567 (void)DevAuthInterfaceTestCase0285();
1568 (void)DevAuthInterfaceTestCase0286();
1569 (void)DevAuthInterfaceTestCase0287();
1570 (void)DevAuthInterfaceTestCase0288();
1571 (void)DevAuthInterfaceTestCase0289();
1572 (void)DevAuthInterfaceTestCase029();
1573 (void)DevAuthInterfaceTestCase030();
1574 (void)DevAuthInterfaceTestCase031();
1575 (void)DevAuthInterfaceTestCase032();
1576 (void)DevAuthInterfaceTestCase0321();
1577 (void)DevAuthInterfaceTestCase033();
1578 (void)DevAuthInterfaceTestCase034();
1579 (void)DevAuthInterfaceTestCase035();
1580 (void)DevAuthInterfaceTestCase036();
1581 }
1582
FuzzDoDevAuthInterfaceFuzz(const uint8_t * data,size_t size)1583 bool FuzzDoDevAuthInterfaceFuzz(const uint8_t* data, size_t size)
1584 {
1585 (void)data;
1586 (void)size;
1587 DevAuthInterfaceTestCasePart1();
1588 DevAuthInterfaceTestCasePart2();
1589 return true;
1590 }
1591 }
1592
1593 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)1594 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
1595 {
1596 /* Run your code on data */
1597 OHOS::FuzzDoDevAuthInterfaceFuzz(data, size);
1598 return 0;
1599 }
1600
1601