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