• 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 CF_TYPE_H
17 #define CF_TYPE_H
18 
19 #include <stdbool.h>
20 #include <stdint.h>
21 #include <stdlib.h>
22 
23 #include "cf_blob.h"
24 
25 #define CF_API_EXPORT __attribute__ ((visibility("default")))
26 
27 typedef enum {
28     CF_OBJ_TYPE_CERT,
29     CF_OBJ_TYPE_EXTENSION,
30     CF_OBJ_TYPE_CRL,
31     CF_OBJ_TYPE_LIST,
32 } CfObjectType;
33 
34 typedef struct {
35     unsigned long type;
36 } CfBase;
37 
38 typedef enum {
39     CF_ITEM_TBS = 0, /* TBS Certificate */
40     CF_ITEM_PUBLIC_KEY,  /* Subject Public Key */
41     CF_ITEM_ISSUER_UNIQUE_ID, /* Issuer Unique Identifier */
42     CF_ITEM_SUBJECT_UNIQUE_ID, /* Subject Unique Identifier */
43     CF_ITEM_EXTENSIONS, /* Extensions */
44 
45     CF_ITEM_ENCODED,
46     CF_ITEM_VERSION,
47     CF_ITEM_SERIAL_NUMBER,
48     CF_ITEM_ISSUE_NAME,
49     CF_ITEM_SUBJECT_NAME,
50     CF_ITEM_NOT_BEFORE,
51     CF_ITEM_NOT_AFTER,
52     CF_ITEM_SIGNATURE,
53     CF_ITEM_SIGNATURE_ALG_NAME,
54 
55     CF_ITEM_INVALID,
56 } CfItemId;
57 
58 typedef enum {
59     CF_EXT_TYPE_ALL_OIDS,
60     CF_EXT_TYPE_CRITICAL_OIDS,
61     CF_EXT_TYPE_UNCRITICAL_OIDS,
62 } CfExtensionOidType;
63 
64 typedef enum {
65     CF_EXT_ENTRY_TYPE_ENTRY,
66     CF_EXT_ENTRY_TYPE_ENTRY_CRITICAL,
67     CF_EXT_ENTRY_TYPE_ENTRY_VALUE,
68 } CfExtensionEntryType;
69 
70 typedef enum {
71     CF_GET_TYPE_CERT_ITEM,
72     CF_GET_TYPE_EXT_ITEM,
73     CF_GET_TYPE_EXT_OIDS,
74     CF_GET_TYPE_EXT_ENTRY,
75 } CfGetType;
76 
77 typedef enum {
78     CF_CHECK_TYPE_EXT_CA,
79 } CfCheckType;
80 
81 typedef enum {
82     CF_TAG_TYPE_INVALID = 0 << 28,
83     CF_TAG_TYPE_INT = 1 << 28,
84     CF_TAG_TYPE_UINT = 2 << 28,
85     CF_TAG_TYPE_ULONG = 3 << 28,
86     CF_TAG_TYPE_BOOL = 4 << 28,
87     CF_TAG_TYPE_BYTES = 5 << 28,
88 } CfTagType;
89 
90 typedef enum {
91     CF_TAG_INVALID = CF_TAG_TYPE_INVALID | 0,
92 
93     CF_TAG_RESULT_TYPE = CF_TAG_TYPE_INT | 1, /* choose from CfTagType */
94     CF_TAG_RESULT_INT = CF_TAG_TYPE_INT | 2,
95     CF_TAG_RESULT_UINT = CF_TAG_TYPE_UINT | 3,
96     CF_TAG_RESULT_ULONG = CF_TAG_TYPE_ULONG | 4,
97     CF_TAG_RESULT_BOOL = CF_TAG_TYPE_BOOL | 5,
98     CF_TAG_RESULT_BYTES = CF_TAG_TYPE_BYTES | 6,
99 
100     CF_TAG_GET_TYPE = CF_TAG_TYPE_INT | 1001, /* choose from CfGetType */
101     CF_TAG_CHECK_TYPE = CF_TAG_TYPE_INT | 1002, /* choose from CfCheckType */
102 
103     CF_TAG_PARAM0_BUFFER = CF_TAG_TYPE_BYTES | 30001,
104     CF_TAG_PARAM1_BUFFER = CF_TAG_TYPE_BYTES | 30002,
105     CF_TAG_PARAM2_BUFFER = CF_TAG_TYPE_BYTES | 30003,
106     CF_TAG_PARAM3_BUFFER = CF_TAG_TYPE_BYTES | 30004,
107     CF_TAG_PARAM4_BUFFER = CF_TAG_TYPE_BYTES | 30005,
108     CF_TAG_PARAM0_INT32 = CF_TAG_TYPE_INT | 30006,
109     CF_TAG_PARAM1_INT32 = CF_TAG_TYPE_INT | 30007,
110     CF_TAG_PARAM2_INT32 = CF_TAG_TYPE_INT | 30008,
111     CF_TAG_PARAM3_INT32 = CF_TAG_TYPE_INT | 30009,
112     CF_TAG_PARAM4_INT32 = CF_TAG_TYPE_INT | 30010,
113 } CfTag;
114 
115 typedef struct {
116     uint32_t tag;
117     union {
118         bool boolParam;
119         int32_t int32Param;
120         uint32_t uint32Param;
121         uint64_t uint64Param;
122         CfBlob blob;
123     };
124 } CfParam;
125 
126 typedef struct {
127     uint32_t paramSetSize;
128     uint32_t paramsCnt;
129     CfParam params[];
130 } CfParamSet;
131 
CfIsAdditionOverflow(uint32_t a,uint32_t b)132 static inline bool CfIsAdditionOverflow(uint32_t a, uint32_t b)
133 {
134     return (UINT32_MAX - a) < b;
135 }
136 
137 #define MAX_COUNT_OID          100
138 #define MAX_LEN_OID            128
139 #define MAX_COUNT_NID          1195
140 
141 #define MAX_LEN_CERTIFICATE    65536
142 #define MAX_LEN_EXTENSIONS     65536
143 
144 #define BASIC_CONSTRAINTS_NO_CA             (-1)
145 #define BASIC_CONSTRAINTS_PATHLEN_NO_LIMIT  (-2)
146 #endif /* CF_TYPE_H */
147