1 /*
2  * Copyright (C) 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 "hc_dev_info_mock.h"
17 #include "hal_error.h"
18 #include "hc_log.h"
19 #include "securec.h"
20 
21 #define MOCK_STORAGE_FILE "/data/service/el1/public/deviceauthMock/hcgroup.dat"
22 #define MOCK_STORAGE_DIR "/data/service/el1/public/deviceauthMock"
23 #define MOCK_STORAGE_DIR_CE "/data/service/el1/public/deviceauthMock/ce"
24 #define MOCK_ACCOUNT_STORAGE_DIR "/data/service/el1/public/deviceauthMock/account"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 static bool g_isClient = true;
31 static char *g_clientDevUdid = "5420459D93FE773F9945FD64277FBA2CAB8FB996DDC1D0B97676FBB1242B3930";
32 static char *g_serverDevUdid = "52E2706717D5C39D736E134CC1E3BE1BAA2AA52DB7C76A37C749558BD2E6492C";
33 
34 static bool g_isAccountStorageTest = false;
35 
SetDeviceStatus(bool isClient)36 void SetDeviceStatus(bool isClient)
37 {
38     g_isClient = isClient;
39 }
40 
SetAccountStorageTest(bool isAccountStorageTest)41 void SetAccountStorageTest(bool isAccountStorageTest)
42 {
43     g_isAccountStorageTest = isAccountStorageTest;
44 }
45 
HcGetUdid(uint8_t * udid,int32_t udidLen)46 int32_t HcGetUdid(uint8_t *udid, int32_t udidLen)
47 {
48     if (udid == NULL || udidLen < INPUT_UDID_LEN || udidLen > MAX_INPUT_UDID_LEN) {
49         return HAL_ERR_INVALID_PARAM;
50     }
51     char *devUdid;
52     if (g_isClient) {
53         devUdid = g_clientDevUdid;
54         LOGI("Use mock client device udid.");
55     } else {
56         devUdid = g_serverDevUdid;
57         LOGI("Use mock server device udid.");
58     }
59     if (memcpy_s(udid, udidLen, devUdid, INPUT_UDID_LEN) != EOK) {
60         LOGE("Failed to copy udid!");
61         return HAL_FAILED;
62     }
63     return HAL_SUCCESS;
64 }
65 
GetStoragePath(void)66 const char *GetStoragePath(void)
67 {
68     return MOCK_STORAGE_FILE;
69 }
70 
GetStorageDirPathCe(void)71 const char *GetStorageDirPathCe(void)
72 {
73     return MOCK_STORAGE_DIR_CE;
74 }
75 
GetStorageDirPath(void)76 const char *GetStorageDirPath(void)
77 {
78     return MOCK_STORAGE_DIR;
79 }
80 
GetAccountStoragePath(void)81 const char *GetAccountStoragePath(void)
82 {
83     if (g_isAccountStorageTest) {
84         return NULL;
85     }
86     return MOCK_ACCOUNT_STORAGE_DIR;
87 }
88 
GetPseudonymStoragePath(void)89 const char *GetPseudonymStoragePath(void)
90 {
91 #ifndef LITE_DEVICE
92     const char *storageFile = "/data/service/el1/public/deviceauth/pseudonym";
93 #else
94     const char *storageFile = "/storage/deviceauth/pseudonym";
95 #endif
96     return storageFile;
97 }
98 
99 #ifdef __cplusplus
100 }
101 #endif
102