• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef CODE_SIGNATURE_INFO_H
17 #define CODE_SIGNATURE_INFO_H
18 
19 #include <stdint.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #define CODE_SIGNATURE_ERROR_TYPE_SIZE 5
26 
27 #define APPLICATION_RISK_OF_CODE_SIGNATURE "code_signature"
28 
29 #define APPLICATION_RISK_EVENT_ID 10110150100
30 
31 #define CODE_SIGNATURE_ERROR_EVENT_ID 10110150101
32 
33 #define INVALID_TOKEN_ID 0
34 
35 #ifndef MAX_CODE_SIGNATURE_ERROR_NUM
36 #define MAX_CODE_SIGNATURE_ERROR_NUM 10
37 #endif
38 
39 #ifndef MAX_CODE_SIGNATURE_ERROR_FREQUENCY
40 #define MAX_CODE_SIGNATURE_ERROR_FREQUENCY 10
41 #endif
42 
43 #define MAX_BUNDLE_NAME_LENGTH 256
44 #define STATUS_CHANGED 1
45 #define STATUS_NOT_CHANGED 0
46 
47 typedef enum  OperErrorCode {
48     OPER_SUCCESS = 0,
49     MEMORY_OPER_FAILED = 5501,
50     INPUT_POINT_NULL = 5502,
51     INPUT_TOKEN_ID_INVALID = 5503,
52     INPUT_EVENT_TYPE_INVALID = 5504,
53     INPUT_OPER_TYPE_INVALID = 5505,
54     INIT_OPER_REPEAT = 5506,
55     INVALID_POINT_LENGTH = 5507,
56     MODEL_INIT_NOT_COMPLETED = 5508,
57     SHORT_OF_MEMORY = 5509,
58 } OperErrorCode;
59 
60 typedef enum DataChangeTypeCode {
61     EVENT_REPORTED = 0,
62     OUT_OF_STORAGE_LIFE = 1,
63     DATA_CHANGE_TYPE_BUFF,
64 } DataChangeTypeCode;
65 
66 typedef enum CodeSignatureErrorType {
67     SIGNATURE_MISSING = 0, // Signature is missing.
68     SIGNATURE_INVALID, // Signature is invalid.
69     ABC_FILE_TAMPERED, // abc file is tampered.
70     BINARY_FILE_TAMPERED, // binary file is tampered.
71     ELF_FORMAT_DAMAGED, // ELF of the file is damaged.
72     CODE_SIGNATURE_ERROR_TYPE_BUFF,
73 } CodeSignatureErrorType;
74 
75 typedef enum RiskPolicyType {
76     NO_SECURITY_RISK = 0,
77     LOG_REPORT,
78     ENFORCED_PERMISSION_CONTROL,
79     RISK_POLICY_TYPE_BUFF,
80 } RiskPolicyType;
81 
82 typedef union TimeStampInfo {
83     int64_t timeStampMs;
84     int32_t timeStampCount;
85 } TimeStampInfo;
86 
87 typedef struct TimeStampInfoNode {
88     TimeStampInfo timeStamp;
89     struct TimeStampInfoNode *next;
90 } TimeStampNode;
91 
92 /* Code signature event infomation reported from security_guard */
93 typedef struct CodeSignatureReportedInfo {
94     uint32_t tokenId;
95     CodeSignatureErrorType errorType;
96     int64_t timeStampMs;
97     char bundleName[MAX_BUNDLE_NAME_LENGTH];
98 } CodeSignatureReportedInfo;
99 
100 typedef struct CodeSignatureErrorInfo {
101     CodeSignatureErrorType errorType;
102     TimeStampNode *timeStampChain;
103 } CodeSignatureErrorInfo;
104 
105 typedef struct AppRiskStatus {
106     RiskPolicyType policy;
107     int32_t eventCount;
108     int64_t totalCount;
109 } AppRiskStatus;
110 
111 typedef struct AppRiskInfo {
112     uint32_t tokenId;
113     AppRiskStatus status;
114     char bundleName[MAX_BUNDLE_NAME_LENGTH];
115     struct AppRiskInfo *next;
116     CodeSignatureErrorInfo errInfoList[CODE_SIGNATURE_ERROR_TYPE_SIZE];
117 } AppRiskInfo;
118 
119 typedef struct NotifyRiskResultInfo {
120     int64_t eventId;
121     RiskPolicyType policy;
122     uint32_t tokenId;
123 } NotifyRiskResultInfo;
124 
125 #ifdef __cplusplus
126 }
127 #endif
128 
129 #endif // CODE_SIGNATURE_INFO_H
130