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 <securec.h>
17 #include "devattest_configuration.h"
18 #include "attest_type.h"
19 #include "attest_error.h"
20 #include "attest_utils_log.h"
21 #include "attest_utils_timer.h"
22 #include "attest_service.h"
23 #include "attest_entry.h"
24
25 static ATTEST_TIMER_ID g_ProcAttestTimerId = NULL;
26
27
AttestTask(void)28 int32_t AttestTask(void)
29 {
30 ATTEST_LOG_INFO("[AttestTask] Begin.");
31 // 执行主流程代码
32 int32_t ret = ProcAttest();
33 if (ret != ATTEST_OK) {
34 ATTEST_LOG_ERROR("[AttestTask] Proc failed ret = %d.", ret);
35 }
36 ret = AttestCreateTimerTask();
37 if (ret != ATTEST_OK) {
38 ATTEST_LOG_ERROR("[AttestTask] TimerTask failed ret = %d.", ret);
39 }
40 ATTEST_LOG_INFO("[AttestTask] End.");
41 return ret;
42 }
43
CopyAttestResult(int32_t * resultArray,AttestResultInfo * attestResultInfo)44 static int32_t CopyAttestResult(int32_t *resultArray, AttestResultInfo *attestResultInfo)
45 {
46 if (resultArray == NULL) {
47 return ATTEST_ERR;
48 }
49 int32_t *head = resultArray;
50 attestResultInfo->authResult = *head;
51 head++;
52 attestResultInfo->softwareResult = *head;
53 for (int i = 0; i < SOFTWARE_RESULT_DETAIL_SIZE; i++) {
54 attestResultInfo->softwareResultDetail[i] = *(++head);
55 }
56 return ATTEST_OK;
57 }
58
EntryGetAttestStatus(AttestResultInfo * attestResultInfo)59 int32_t EntryGetAttestStatus(AttestResultInfo* attestResultInfo)
60 {
61 if (attestResultInfo == NULL) {
62 return ATTEST_ERR;
63 }
64 int32_t resultArraySize = MAX_ATTEST_RESULT_SIZE * sizeof(int32_t);
65 int32_t *resultArray = (int32_t *)malloc(resultArraySize);
66 if (resultArray == NULL) {
67 ATTEST_LOG_ERROR("malloc resultArray failed");
68 return ATTEST_ERR;
69 }
70 (void)memset_s(resultArray, resultArraySize, 0, resultArraySize);
71 int32_t ticketLength = 0;
72 char* ticketStr = NULL;
73 int32_t ret = ATTEST_OK;
74 do {
75 ret = QueryAttestStatus(&resultArray, MAX_ATTEST_RESULT_SIZE, &ticketStr, &ticketLength);
76 if (ret != ATTEST_OK) {
77 ATTEST_LOG_ERROR("QueryAttest failed");
78 break;
79 }
80 ret = CopyAttestResult(resultArray, attestResultInfo);
81 if (ret != ATTEST_OK) {
82 ATTEST_LOG_ERROR("copy attest result failed");
83 break;
84 }
85 attestResultInfo->ticketLength = ticketLength;
86 attestResultInfo->ticket = ticketStr;
87 } while (0);
88 free(resultArray);
89 resultArray = NULL;
90 ATTEST_LOG_INFO("GetAttestStatus end success");
91 return ret;
92 }
93
AttestCreateTimerTask(void)94 int32_t AttestCreateTimerTask(void)
95 {
96 return 0;
97 }
98
AttestDestroyTimerTask(void)99 int32_t AttestDestroyTimerTask(void)
100 {
101 return AttestStopTimerTask(g_ProcAttestTimerId);
102 }
103