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_utils_log.h"
17 #include "attest_adapter_oem.h"
18 #include "attest_adapter_os.h"
19 #include "attest_adapter_mock.h"
20 #include "attest_adapter.h"
21
22 // 是否存在重置标记
AttestIsResetFlagExist(void)23 bool AttestIsResetFlagExist(void)
24 {
25 bool isExist = OEMIsFlagExist(OEM_FLAG_RESET);
26 if (!isExist) {
27 return false;
28 }
29 #if !defined(__ATTEST_ENABLE_PRESET_TOKEN__)
30 TokenInfo tokenInfo;
31 if (AttestReadToken(&tokenInfo) == TOKEN_UNPRESET) {
32 return false;
33 }
34 #endif
35 return true;
36 }
37
38 // 创建重置标记
AttestCreateResetFlag(void)39 int32_t AttestCreateResetFlag(void)
40 {
41 return OEMCreateFlag(OEM_FLAG_RESET);
42 }
43
44 // 写入认证结果
AttestWriteAuthStatus(const char * data,uint32_t len)45 int32_t AttestWriteAuthStatus(const char* data, uint32_t len)
46 {
47 return OEMWriteAuthStatus(data, len);
48 }
49
50 // 读取认证结果
AttestReadAuthStatus(char * buffer,uint32_t bufferLen)51 int32_t AttestReadAuthStatus(char* buffer, uint32_t bufferLen)
52 {
53 return OEMReadAuthStatus(buffer, bufferLen);
54 }
55
56 // 读取认证结果长度
AttestGetAuthStatusFileSize(uint32_t * len)57 int32_t AttestGetAuthStatusFileSize(uint32_t* len)
58 {
59 return OEMGetAuthStatusFileSize(len);
60 }
61
62 // 读取凭据
AttestReadTicket(TicketInfo * ticketInfo)63 int32_t AttestReadTicket(TicketInfo* ticketInfo)
64 {
65 return OEMReadTicket(ticketInfo);
66 }
67
68 // 写入凭据
AttestWriteTicket(const TicketInfo * ticketInfo)69 int32_t AttestWriteTicket(const TicketInfo* ticketInfo)
70 {
71 return OEMWriteTicket(ticketInfo);
72 }
73
AttestSetParameter(const char * key,const char * value)74 int32_t AttestSetParameter(const char *key, const char *value)
75 {
76 return OsSetParameter(key, value);
77 }
78
AttestGetParameter(const char * key,const char * def,char * value,uint32_t len)79 int32_t AttestGetParameter(const char *key, const char *def, char *value, uint32_t len)
80 {
81 return OsGetParameter(key, def, value, len);
82 }
83
AttestNetworkConfigExist(void)84 bool AttestNetworkConfigExist(void)
85 {
86 return OEMIsNetworkConfigExist();
87 }
88
AttestWriteNetworkConfig(const char * buffer,uint32_t bufferLen)89 int32_t AttestWriteNetworkConfig(const char* buffer, uint32_t bufferLen)
90 {
91 return OEMWriteNetworkConfig(buffer, bufferLen);
92 }
93
AttestReadNetworkConfig(char * buffer,uint32_t bufferLen)94 int32_t AttestReadNetworkConfig(char* buffer, uint32_t bufferLen)
95 {
96 return OEMReadNetworkConfig(buffer, bufferLen);
97 }
98
AttestReadDefaultNetworkConfig(char * buffer,uint32_t bufferLen)99 int32_t AttestReadDefaultNetworkConfig(char* buffer, uint32_t bufferLen)
100 {
101 return OEMReadDefaultNetworkConfig(buffer, bufferLen);
102 }
103
AttestWriteAuthResultCode(const char * data,uint32_t len)104 int32_t AttestWriteAuthResultCode(const char* data, uint32_t len)
105 {
106 return OEMWriteAuthResultCode(data, len);
107 }
108
AttestReadAuthResultCode(char * buffer,uint32_t bufferLen)109 int32_t AttestReadAuthResultCode(char* buffer, uint32_t bufferLen)
110 {
111 return OEMReadAuthResultCode(buffer, bufferLen);
112 }
113
AttestWriteFullLoadStatus(const char * data,uint32_t len)114 int32_t AttestWriteFullLoadStatus(const char* data, uint32_t len)
115 {
116 return OEMWriteFullLoadStatus(data, len);
117 }
118
AttestReadFullLoadStatus(char * buffer,uint32_t bufferLen)119 int32_t AttestReadFullLoadStatus(char* buffer, uint32_t bufferLen)
120 {
121 return OEMReadFullLoadStatus(buffer, bufferLen);
122 }
123