1 /*
2 * Copyright (C) 2022 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 "attest_type.h"
17 #include "attest_utils.h"
18 #include "attest_utils_log.h"
19 #include "attest_dfx.h"
20
21 // 写到buffer,统一输出。
PrintChallengeResult(ChallengeResult * challengeResult)22 void PrintChallengeResult(ChallengeResult* challengeResult)
23 {
24 if (challengeResult == NULL) {
25 ATTEST_LOG_ERROR("[PrintChallengeResult] ChallengeResult is null.");
26 return;
27 }
28
29 uint32_t curBuffLen = 0;
30 char* buffer = (char *)ATTEST_MEM_MALLOC(MAX_ATTEST_BUFF_LEN);
31 if (buffer == NULL) {
32 return;
33 }
34 char* curBuffer = buffer;
35 ATTEST_LOG_NSPRINT(curBuffer, curBuffLen, MAX_ATTEST_BUFF_LEN, "------ChallengeResult--------\n");
36 ATTEST_LOG_NSPRINT(curBuffer, curBuffLen, MAX_ATTEST_BUFF_LEN, "challenge = %s;\n", challengeResult->challenge);
37 ATTEST_LOG_NSPRINT(curBuffer, curBuffLen, MAX_ATTEST_BUFF_LEN, "currentTime = %I64u;\n",
38 challengeResult->currentTime);
39 ATTEST_LOG_NSPRINT(curBuffer, curBuffLen, MAX_ATTEST_BUFF_LEN, "----------------------------\n");
40 ATTEST_LOG_INFO("%s", buffer);
41 ATTEST_MEM_FREE(buffer);
42 }
PrintDevicePacket(DevicePacket * devicePacket)43 void PrintDevicePacket(DevicePacket* devicePacket)
44 {
45 ATTEST_LOG_INFO("------DevicePacket--------");
46 if (devicePacket == NULL) {
47 ATTEST_LOG_ERROR("DevicePacket is null.");
48 return;
49 }
50
51 if (devicePacket->tenantId == NULL) {
52 ATTEST_LOG_WARN("tenantId = null;");
53 } else {
54 ATTEST_LOG_INFO("tenantId = %s;", devicePacket->tenantId);
55 }
56
57 if (devicePacket->udid == NULL) {
58 ATTEST_LOG_WARN("udid = null;");
59 } else {
60 ATTEST_LOG_INFO_ANONY("udid = %s;", devicePacket->udid);
61 }
62
63 if (devicePacket->ticket == NULL) {
64 ATTEST_LOG_WARN("ticket = null;");
65 } else {
66 ATTEST_LOG_INFO_ANONY("ticket = %s;", devicePacket->ticket);
67 }
68
69 if (devicePacket->randomUuid == NULL) {
70 ATTEST_LOG_WARN("randomUuid = null;");
71 } else {
72 ATTEST_LOG_INFO("randomUuid = %s;", devicePacket->randomUuid);
73 }
74
75 if (devicePacket->kitinfo == NULL) {
76 ATTEST_LOG_WARN("kitinfo = null;");
77 } else {
78 ATTEST_LOG_INFO("kitinfo = %s;", devicePacket->kitinfo);
79 }
80 PrintDeviceTokenInfo(&(devicePacket->tokenInfo));
81 PrintDeviceProductInfo(&(devicePacket->productInfo));
82 ATTEST_LOG_INFO("----------------------------");
83 }
84
PrintDeviceTokenInfo(DeviceTokenInfo * tokenInfo)85 void PrintDeviceTokenInfo(DeviceTokenInfo* tokenInfo)
86 {
87 ATTEST_LOG_INFO("--------DeviceTokenInfo-------");
88 if (tokenInfo == NULL) {
89 ATTEST_LOG_ERROR("tokenInfo is null.");
90 return;
91 }
92 ATTEST_LOG_INFO("tokenInfo (addr = %p):", tokenInfo);
93 if (tokenInfo->token == NULL) {
94 ATTEST_LOG_WARN("token = null;");
95 } else {
96 ATTEST_LOG_INFO_ANONY("token = %s;", tokenInfo->token);
97 }
98
99 if (tokenInfo->uuid == NULL) {
100 ATTEST_LOG_WARN("uuid = null;");
101 } else {
102 ATTEST_LOG_INFO_ANONY("uuid = %s;", tokenInfo->uuid);
103 }
104 ATTEST_LOG_INFO("----------------------------");
105 }
106
PrintDeviceProductInfo(DeviceProductInfo * productInfo)107 void PrintDeviceProductInfo(DeviceProductInfo *productInfo)
108 {
109 ATTEST_LOG_INFO("-------DeviceProductInfo----");
110 if (productInfo == NULL) {
111 ATTEST_LOG_ERROR("productInfo is null.");
112 return;
113 }
114 if (productInfo->model == NULL) {
115 ATTEST_LOG_WARN("model = null;");
116 } else {
117 ATTEST_LOG_INFO_ANONY("model = %s;", productInfo->model);
118 }
119
120 if (productInfo->brand == NULL) {
121 ATTEST_LOG_WARN("brand = null;");
122 } else {
123 ATTEST_LOG_INFO_ANONY("brand = %s;", productInfo->brand);
124 }
125
126 if (productInfo->manu == NULL) {
127 ATTEST_LOG_WARN("manu = null;");
128 } else {
129 ATTEST_LOG_INFO_ANONY("manu = %s;", productInfo->manu);
130 }
131
132 if (productInfo->versionId == NULL) {
133 ATTEST_LOG_WARN("versionId = null;");
134 } else {
135 ATTEST_LOG_INFO_ANONY("versionId = %s;", productInfo->versionId);
136 }
137
138 if (productInfo->displayVersion == NULL) {
139 ATTEST_LOG_WARN("displayVersion = null;");
140 } else {
141 ATTEST_LOG_INFO_ANONY("displayVersion = %s;", productInfo->displayVersion);
142 }
143
144 if (productInfo->rootHash == NULL) {
145 ATTEST_LOG_WARN("rootHash = null;");
146 } else {
147 ATTEST_LOG_INFO_ANONY("rootHash = %s;", productInfo->rootHash);
148 }
149
150 if (productInfo->patchTag == NULL) {
151 ATTEST_LOG_WARN("patchTag = null;");
152 } else {
153 ATTEST_LOG_INFO_ANONY("patchTag = %s;", productInfo->patchTag);
154 }
155
156 ATTEST_LOG_INFO("----------------------------");
157 }
158
PrintAuthResult(AuthResult * authResult)159 void PrintAuthResult(AuthResult* authResult)
160 {
161 ATTEST_LOG_INFO("----------AuthResult--------");
162 if (authResult == NULL) {
163 ATTEST_LOG_ERROR("authResult is null.");
164 return;
165 }
166 ATTEST_LOG_INFO("errorCode = %d;", authResult->errorCode);
167
168 if (authResult->ticket == NULL) {
169 ATTEST_LOG_WARN("ticket = null;");
170 } else {
171 ATTEST_LOG_INFO_ANONY("ticket = %s;", authResult->ticket);
172 }
173 if (authResult->tokenValue == NULL) {
174 ATTEST_LOG_WARN("tokenValue = null;");
175 } else {
176 ATTEST_LOG_INFO_ANONY("tokenValue = %s;", authResult->tokenValue);
177 }
178 if (authResult->tokenId == NULL) {
179 ATTEST_LOG_WARN("tokenId = null;");
180 } else {
181 ATTEST_LOG_INFO_ANONY("tokenId = %s;", authResult->tokenId);
182 }
183 if (authResult->authStatus == NULL) {
184 ATTEST_LOG_WARN("authStatus = null;");
185 } else {
186 // authResult->authStatus 内容过长,不在打印
187 }
188 ATTEST_LOG_INFO("----------------------------");
189 }
190
PrintAuthStatus(AuthStatus * authStatus)191 void PrintAuthStatus(AuthStatus* authStatus)
192 {
193 ATTEST_LOG_INFO("-------AuthStatus-----------");
194 if (authStatus == NULL) {
195 ATTEST_LOG_ERROR("authResult is null.");
196 return;
197 }
198 if (authStatus->versionId == NULL) {
199 ATTEST_LOG_WARN("versionId = null;");
200 } else {
201 ATTEST_LOG_INFO("versionId = %s;", authStatus->versionId);
202 }
203 ATTEST_LOG_INFO("softwareResult = %d;", authStatus->softwareResult);
204 ATTEST_LOG_INFO("hardwareResult = %d;", authStatus->hardwareResult);
205 if (authStatus->authType == NULL) {
206 ATTEST_LOG_WARN("authType = null;");
207 } else {
208 ATTEST_LOG_INFO("authType = %s;", authStatus->authType);
209 }
210 ATTEST_LOG_INFO("expireTime = %I64u;", authStatus->expireTime);
211 ATTEST_LOG_INFO("----------------------------");
212 }
213
PrintTokenInfo(TokenInfo * tokenInfo)214 void PrintTokenInfo(TokenInfo* tokenInfo)
215 {
216 ATTEST_LOG_INFO("-------TokenInfo-----------");
217 if (tokenInfo == NULL) {
218 ATTEST_LOG_ERROR("tokenInfo is null.");
219 return;
220 }
221 if (tokenInfo->tokenId[0] == '\0') {
222 ATTEST_LOG_WARN("tokenId = null;");
223 } else {
224 ATTEST_LOG_INFO_ANONY("tokenId = %s;", (char*)(tokenInfo->tokenId));
225 }
226 if (tokenInfo->tokenValue[0] == '\0') {
227 ATTEST_LOG_WARN("tokenValue = null;");
228 } else {
229 ATTEST_LOG_INFO_ANONY("tokenValue = %s;", (char*)(tokenInfo->tokenValue));
230 }
231 if (tokenInfo->salt[0] == '\0') {
232 ATTEST_LOG_WARN("salt = null;");
233 } else {
234 ATTEST_LOG_INFO("salt = %s;", (char*)(tokenInfo->salt));
235 }
236 if (tokenInfo->version[0] == '\0') {
237 ATTEST_LOG_WARN("version = null;");
238 } else {
239 ATTEST_LOG_INFO("version = %s;", (char*)(tokenInfo->version));
240 }
241 ATTEST_LOG_INFO("----------------------------");
242 }
243
PrintTicketInfo(TicketInfo * ticketInfo)244 void PrintTicketInfo(TicketInfo* ticketInfo)
245 {
246 ATTEST_LOG_INFO("-------TicketInfo-----------");
247 if (ticketInfo == NULL) {
248 ATTEST_LOG_ERROR("ticketInfo is null.");
249 return;
250 }
251 if (ticketInfo->ticket[0] == '\0') {
252 ATTEST_LOG_WARN("ticket = null;");
253 } else {
254 ATTEST_LOG_INFO_ANONY("ticket = %s;", (char*)(ticketInfo->ticket));
255 }
256 if (ticketInfo->salt[0] == '\0') {
257 ATTEST_LOG_WARN("salt = null;");
258 } else {
259 ATTEST_LOG_INFO("salt = %s;", (char*)(ticketInfo->salt));
260 }
261 ATTEST_LOG_INFO("----------------------------");
262 }
263