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 RISK_APP_NUM_EXCEEDED = 5510, 59 } OperErrorCode; 60 61 typedef enum DataChangeTypeCode { 62 EVENT_REPORTED = 0, 63 OUT_OF_STORAGE_LIFE = 1, 64 DATA_CHANGE_TYPE_BUFF, 65 } DataChangeTypeCode; 66 67 typedef enum CodeSignatureErrorType { 68 SIGNATURE_MISSING = 0, // Signature is missing. 69 SIGNATURE_INVALID, // Signature is invalid. 70 ABC_FILE_TAMPERED, // abc file is tampered. 71 BINARY_FILE_TAMPERED, // binary file is tampered. 72 ELF_FORMAT_DAMAGED, // ELF of the file is damaged. 73 CODE_SIGNATURE_ERROR_TYPE_BUFF, 74 } CodeSignatureErrorType; 75 76 typedef enum RiskPolicyType { 77 NO_SECURITY_RISK = 0, 78 LOG_REPORT, 79 ENFORCED_PERMISSION_CONTROL, 80 RISK_POLICY_TYPE_BUFF, 81 } RiskPolicyType; 82 83 typedef union TimeStampInfo { 84 int64_t timeStampMs; 85 int32_t timeStampCount; 86 } TimeStampInfo; 87 88 typedef struct TimeStampInfoNode { 89 TimeStampInfo timeStamp; 90 struct TimeStampInfoNode *next; 91 } TimeStampNode; 92 93 /* Code signature event infomation reported from security_guard */ 94 typedef struct CodeSignatureReportedInfo { 95 uint32_t tokenId; 96 CodeSignatureErrorType errorType; 97 int64_t timeStampMs; 98 char bundleName[MAX_BUNDLE_NAME_LENGTH]; 99 } CodeSignatureReportedInfo; 100 101 typedef struct CodeSignatureErrorInfo { 102 CodeSignatureErrorType errorType; 103 TimeStampNode *timeStampChain; 104 } CodeSignatureErrorInfo; 105 106 typedef struct AppRiskStatus { 107 RiskPolicyType policy; 108 int32_t eventCount; 109 int64_t totalCount; 110 } AppRiskStatus; 111 112 typedef struct AppRiskInfo { 113 uint32_t tokenId; 114 AppRiskStatus status; 115 char bundleName[MAX_BUNDLE_NAME_LENGTH]; 116 struct AppRiskInfo *next; 117 CodeSignatureErrorInfo errInfoList[CODE_SIGNATURE_ERROR_TYPE_SIZE]; 118 } AppRiskInfo; 119 120 typedef struct NotifyRiskResultInfo { 121 int64_t eventId; 122 RiskPolicyType policy; 123 uint32_t tokenId; 124 } NotifyRiskResultInfo; 125 126 #ifdef __cplusplus 127 } 128 #endif 129 130 #endif // CODE_SIGNATURE_INFO_H 131