1 /* 2 * Copyright (c) 2020-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 #ifndef SECURITY_APP_VERIFY_PUB_H 17 #define SECURITY_APP_VERIFY_PUB_H 18 19 #include <stdbool.h> 20 #include <stdint.h> 21 22 #ifdef __cplusplus 23 #if __cplusplus 24 extern "C" { 25 #endif 26 #endif 27 28 typedef enum { 29 V_OK = 0, 30 31 /* begin app sign parse */ 32 V_ERR_GET_CERT_INFO = 0xef000002, 33 V_ERR_UNTRUSTED_CERT = 0xef000003, 34 V_ERR_INTEGRITY = 0xef000004, 35 V_ERR_GET_SIGNHEAD = 0xef000005, 36 V_ERR_GET_SIGN_BLOCK = 0xef000006, 37 V_ERR_GET_HASH_DIFF = 0xef000007, 38 V_ERR_INVALID_CONTENT_TAG = 0xef000008, 39 V_ERR_INVALID_HASH_ALG = 0xef000009, 40 V_ERR_GET_ROOT_HASH = 0xef00000a, 41 V_ERR_CALC_BLOCK_HASH = 0xef00000c, 42 V_ERR_PARSE_PKC7_DATA = 0xef00000d, 43 V_ERR_VERIFY_CERT_CHAIN = 0xef00000e, 44 V_ERR_VERIFY_SIGNATURE = 0xef00000f, 45 V_ERR_GET_CERT_TYPE = 0xef000010, 46 47 /* begin profile signparse */ 48 V_ERR_GET_PROFILE_DATA = 0xef000011, 49 V_ERR_GET_PARSE_PROFILE = 0xef000012, 50 V_ERR_PROF_CONTENT_INVALID = 0xef000013, 51 V_ERR_VERFIY_PROF_CERT = 0xef000014, 52 V_ERR_GET_CERT_PK = 0xef000015, 53 V_ERR_GET_APPID = 0xef000016, 54 V_ERR_INVALID_DISP_TYPE = 0xef000017, 55 V_ERR_INVALID_APP_BUNDLE = 0xef000018, 56 V_ERR_INVALID_DATE = 0xef000019, 57 V_ERR_INVALID_DEVID = 0xef00001a, 58 59 /* begin file operation */ 60 V_ERR_FILE_OPEN = 0xef00001b, 61 V_ERR_FILE_STAT = 0xef00001c, 62 V_ERR_FILE_LENGTH = 0xef00001d, 63 64 /* begin memory operation */ 65 V_ERR_MEMSET = 0xef00001e, 66 V_ERR_MEMCPY = 0xef00001f, 67 V_ERR_MALLOC = 0xef000020, 68 69 /* default error */ 70 V_ERR = 0xffffffff, 71 } AppVErrCode; 72 73 typedef struct { 74 int32_t notBefore; 75 int32_t notAfter; 76 } ProfValidity; 77 78 typedef struct { 79 char *developerId; /* developer-id */ 80 unsigned char *devCert; /* development-certificate */ 81 unsigned char *releaseCert; /* distribution-certificate */ 82 char *bundleName; /* bundle-name */ 83 char *appFeature; /* app-feature : hos_system_app/hos_normal_app */ 84 } ProfBundleInfo; 85 86 typedef struct { 87 int32_t restricNum; 88 char **restricPermission; 89 int32_t permissionNum; 90 char **permission; 91 } ProfPermission; 92 93 typedef struct { 94 char *devIdType; 95 int32_t devidNum; 96 char **deviceId; 97 } ProfDebugInfo; 98 99 typedef struct { 100 int32_t versionCode; /* version */ 101 char *versionName; /* version description */ 102 char *uuid; /* uuid */ 103 char *type; /* debug/release */ 104 char *appDistType; /* app-distribution-type */ 105 ProfValidity validity; /* validity */ 106 ProfBundleInfo bundleInfo; /* bundle-info */ 107 ProfPermission permission; /* permissions */ 108 ProfDebugInfo debugInfo; /* debug-info */ 109 char *issuer; /* issuer */ 110 char *appid; /* bundle_name_pk(base64) */ 111 } ProfileProf; 112 113 typedef struct { 114 char *pk; 115 int32_t len; 116 } AppSignPk; 117 118 struct VfyRst; 119 typedef int32_t (*GetSignPk)(struct VfyRst *verifyRst, AppSignPk *pk); 120 typedef void (*FreeSignPK)(AppSignPk *pk); 121 typedef int32_t (*MessageFunc)(unsigned char operationResult, const char *bundleName, unsigned char errCode); 122 123 typedef struct VfyRst { 124 ProfileProf profile; /* profile */ 125 } VerifyResult; 126 127 /* verify app integrity, return 0 if OK, otherwise errcode AppVErrCode */ 128 int32_t APPVERI_AppVerify(const char *filePath, VerifyResult *verifyRst); 129 130 /* free the verify result of APPVERI_AppVerify returned */ 131 void APPVERI_FreeVerifyRst(VerifyResult *verifyRst); 132 133 /* set debugmode */ 134 int32_t APPVERI_SetDebugMode(bool mode); 135 136 /* get unsigned file len without verify, return V_ERR if not OK */ 137 int32_t APPVERI_GetUnsignedFileLength(const char *filePath); 138 139 /* register msg func */ 140 void APPVERI_RegisterMsgFunc(MessageFunc messageFunc); 141 void APPVERI_SetActsMode(bool mode); 142 int32_t APPVERI_IsActsMode(void); 143 144 #ifdef __cplusplus 145 #if __cplusplus 146 } 147 #endif 148 #endif 149 150 #endif 151