blob: c69a75bfec9becb44362410e25f58a91fdf988cb [file] [log] [blame]
vlm7d576b32004-08-20 13:37:45 +00001
2/*** <<< INCLUDES [Certificate] >>> ***/
3
4#include <OBJECT_IDENTIFIER.h>
5#include <BIT_STRING.h>
6#include <INTEGER.h>
7#include <Name.h>
8#include <constr_SEQUENCE.h>
9
10/*** <<< DEPS [Certificate] >>> ***/
11
12extern asn1_TYPE_descriptor_t asn1_DEF_Certificate;
13
14/*** <<< TYPE-DECLS [Certificate] >>> ***/
15
16
17typedef struct Certificate {
18 struct toBeSigned {
19 INTEGER_t version;
20 OBJECT_IDENTIFIER_t signature;
21 Name_t issuer;
22
23 /* Context for parsing across buffer boundaries */
24 ber_dec_ctx_t _ber_dec_ctx;
25 } toBeSigned;
26 OBJECT_IDENTIFIER_t algorithm;
27 BIT_STRING_t signature;
28
29 /* Context for parsing across buffer boundaries */
30 ber_dec_ctx_t _ber_dec_ctx;
31} Certificate_t;
32
vlmff3a6772004-09-05 10:37:18 +000033/*** <<< CODE [Certificate] >>> ***/
34
35static int
36memb_signature_1_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
37 asn_app_consume_bytes_f *app_errlog, void *app_key) {
38 const BIT_STRING_t *st = sptr;
39 size_t size;
40
41 if(!sptr) {
42 _ASN_ERRLOG(app_errlog, app_key,
43 "%s: value not given (%s:%d)",
44 td->name, __FILE__, __LINE__);
45 return -1;
46 }
47
48 if(st->size > 0) {
49 /* Size in bits */
50 size = 8 * (st->size - 1) - (st->buf[0] & 0x7);
51 } else {
52 size = 0;
53 }
54
55 if((size <= 256)) {
56 /* Constraint check succeeded */
57 return 0;
58 } else {
59 _ASN_ERRLOG(app_errlog, app_key,
60 "%s: constraint failed (%s:%d)",
61 td->name, __FILE__, __LINE__);
62 return -1;
63 }
64}
65
66
vlm7d576b32004-08-20 13:37:45 +000067/*** <<< STAT-DEFS [Certificate] >>> ***/
68
69static asn1_TYPE_member_t asn1_MBR_toBeSigned[] = {
70 { 0, offsetof(struct toBeSigned, version),
71 .tag = (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)),
72 .tag_mode = 0,
73 .type = (void *)&asn1_DEF_INTEGER,
74 .memb_constraints = 0, /* Defer to actual type */
75 .name = "version"
76 },
77 { 0, offsetof(struct toBeSigned, signature),
78 .tag = (ASN_TAG_CLASS_UNIVERSAL | (6 << 2)),
79 .tag_mode = 0,
80 .type = (void *)&asn1_DEF_OBJECT_IDENTIFIER,
81 .memb_constraints = 0, /* Defer to actual type */
82 .name = "signature"
83 },
84 { 0, offsetof(struct toBeSigned, issuer),
85 .tag = (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)),
86 .tag_mode = 0,
87 .type = (void *)&asn1_DEF_Name,
88 .memb_constraints = 0, /* Defer to actual type */
89 .name = "issuer"
90 },
91};
92static ber_tlv_tag_t asn1_DEF_toBeSigned_tags[] = {
93 (ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
94};
95static asn1_TYPE_tag2member_t asn1_DEF_toBeSigned_tag2el[] = {
96 { (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 0, 0, 0 }, /* version at 21 */
97 { (ASN_TAG_CLASS_UNIVERSAL | (6 << 2)), 1, 0, 0 }, /* signature at 22 */
98 { (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)), 2, 0, 0 }, /* issuer at 24 */
99};
100static asn1_SEQUENCE_specifics_t asn1_DEF_toBeSigned_specs = {
101 sizeof(struct toBeSigned),
102 offsetof(struct toBeSigned, _ber_dec_ctx),
103 asn1_DEF_toBeSigned_tag2el,
104 3, /* Count of tags in the map */
105 -1, /* Start extensions */
106 -1 /* Stop extensions */
107};
108asn1_TYPE_descriptor_t asn1_DEF_toBeSigned = {
109 "toBeSigned",
110 SEQUENCE_constraint,
111 SEQUENCE_decode_ber,
112 SEQUENCE_encode_der,
113 SEQUENCE_print,
114 SEQUENCE_free,
115 0, /* Use generic outmost tag fetcher */
116 asn1_DEF_toBeSigned_tags,
117 sizeof(asn1_DEF_toBeSigned_tags)
118 /sizeof(asn1_DEF_toBeSigned_tags[0]), /* 1 */
119 1, /* Tags to skip */
120 1, /* Whether CONSTRUCTED */
121 asn1_MBR_toBeSigned,
122 3, /* Elements count */
123 &asn1_DEF_toBeSigned_specs /* Additional specs */
124};
125
126static asn1_TYPE_member_t asn1_MBR_Certificate[] = {
127 { 0, offsetof(struct Certificate, toBeSigned),
128 .tag = (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)),
129 .tag_mode = 0,
130 .type = (void *)&asn1_DEF_toBeSigned,
131 .memb_constraints = 0, /* Defer to actual type */
132 .name = "toBeSigned"
133 },
134 { 0, offsetof(struct Certificate, algorithm),
135 .tag = (ASN_TAG_CLASS_UNIVERSAL | (6 << 2)),
136 .tag_mode = 0,
137 .type = (void *)&asn1_DEF_OBJECT_IDENTIFIER,
138 .memb_constraints = 0, /* Defer to actual type */
139 .name = "algorithm"
140 },
141 { 0, offsetof(struct Certificate, signature),
142 .tag = (ASN_TAG_CLASS_UNIVERSAL | (3 << 2)),
143 .tag_mode = 0,
144 .type = (void *)&asn1_DEF_BIT_STRING,
vlmff3a6772004-09-05 10:37:18 +0000145 .memb_constraints = memb_signature_1_constraint,
vlm7d576b32004-08-20 13:37:45 +0000146 .name = "signature"
147 },
148};
149static ber_tlv_tag_t asn1_DEF_Certificate_tags[] = {
150 (ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
151};
152static asn1_TYPE_tag2member_t asn1_DEF_Certificate_tag2el[] = {
vlmff3a6772004-09-05 10:37:18 +0000153 { (ASN_TAG_CLASS_UNIVERSAL | (3 << 2)), 2, 0, 0 }, /* signature at 17 */
vlm7d576b32004-08-20 13:37:45 +0000154 { (ASN_TAG_CLASS_UNIVERSAL | (6 << 2)), 1, 0, 0 }, /* algorithm at 16 */
155 { (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)), 0, 0, 0 }, /* toBeSigned at 21 */
156};
157static asn1_SEQUENCE_specifics_t asn1_DEF_Certificate_specs = {
158 sizeof(struct Certificate),
159 offsetof(struct Certificate, _ber_dec_ctx),
160 asn1_DEF_Certificate_tag2el,
161 3, /* Count of tags in the map */
162 -1, /* Start extensions */
163 -1 /* Stop extensions */
164};
165asn1_TYPE_descriptor_t asn1_DEF_Certificate = {
166 "Certificate",
167 SEQUENCE_constraint,
168 SEQUENCE_decode_ber,
169 SEQUENCE_encode_der,
170 SEQUENCE_print,
171 SEQUENCE_free,
172 0, /* Use generic outmost tag fetcher */
173 asn1_DEF_Certificate_tags,
174 sizeof(asn1_DEF_Certificate_tags)
175 /sizeof(asn1_DEF_Certificate_tags[0]), /* 1 */
176 1, /* Tags to skip */
177 1, /* Whether CONSTRUCTED */
178 asn1_MBR_Certificate,
179 3, /* Elements count */
180 &asn1_DEF_Certificate_specs /* Additional specs */
181};
182
183
184/*** <<< INCLUDES [Name] >>> ***/
185
186#include <RelativeDistinguishedName.h>
187#include <asn_SEQUENCE_OF.h>
188#include <constr_SEQUENCE_OF.h>
189
190/*** <<< DEPS [Name] >>> ***/
191
192extern asn1_TYPE_descriptor_t asn1_DEF_Name;
193
194/*** <<< TYPE-DECLS [Name] >>> ***/
195
196
197typedef struct Name {
198 A_SEQUENCE_OF(struct RelativeDistinguishedName) list;
199
200 /* Context for parsing across buffer boundaries */
201 ber_dec_ctx_t _ber_dec_ctx;
202} Name_t;
203
204/*** <<< STAT-DEFS [Name] >>> ***/
205
206static asn1_TYPE_member_t asn1_MBR_Name[] = {
207 { 0, 0,
208 .tag = (ASN_TAG_CLASS_UNIVERSAL | (17 << 2)),
209 .tag_mode = 0,
210 .type = (void *)&asn1_DEF_RelativeDistinguishedName,
211 .memb_constraints = 0, /* Defer to actual type */
212 .name = ""
213 },
214};
215static ber_tlv_tag_t asn1_DEF_Name_tags[] = {
216 (ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
217};
218static asn1_SET_OF_specifics_t asn1_DEF_Name_specs = {
219 sizeof(struct Name),
220 offsetof(struct Name, _ber_dec_ctx),
221};
222asn1_TYPE_descriptor_t asn1_DEF_Name = {
223 "Name",
224 SEQUENCE_OF_constraint,
225 SEQUENCE_OF_decode_ber,
226 SEQUENCE_OF_encode_der,
227 SEQUENCE_OF_print,
228 SEQUENCE_OF_free,
229 0, /* Use generic outmost tag fetcher */
230 asn1_DEF_Name_tags,
231 sizeof(asn1_DEF_Name_tags)
232 /sizeof(asn1_DEF_Name_tags[0]), /* 1 */
233 1, /* Tags to skip */
234 1, /* Whether CONSTRUCTED */
235 asn1_MBR_Name,
236 1, /* Single element */
237 &asn1_DEF_Name_specs /* Additional specs */
238};
239
240
241/*** <<< INCLUDES [RelativeDistinguishedName] >>> ***/
242
243#include <IA5String.h>
244#include <asn_SET_OF.h>
245#include <constr_SET_OF.h>
246
247/*** <<< DEPS [RelativeDistinguishedName] >>> ***/
248
249extern asn1_TYPE_descriptor_t asn1_DEF_RelativeDistinguishedName;
250
251/*** <<< TYPE-DECLS [RelativeDistinguishedName] >>> ***/
252
253
254typedef struct RelativeDistinguishedName {
255 A_SET_OF(IA5String_t) list;
256
257 /* Context for parsing across buffer boundaries */
258 ber_dec_ctx_t _ber_dec_ctx;
259} RelativeDistinguishedName_t;
260
261/*** <<< CTABLES [RelativeDistinguishedName] >>> ***/
262
263static int permitted_alphabet_table_1[256] = {
2640,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* */
2650,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* */
2660,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0, /* ,-. */
2671,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0, /* 0 9 */
2680,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* ABCDEFGHIJKLMNO */
2691,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, /* PQRSTUVWXYZ */
2700,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* abcdefghijklmno */
2711,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, /* pqrstuvwxyz */
272};
273
274static int check_permitted_alphabet_1(const void *sptr) {
275 int *table = permitted_alphabet_table_1;
276 /* The underlying type is IA5String */
vlm4fdaead2004-08-21 07:34:17 +0000277 const IA5String_t *st = sptr;
vlm824aefc2004-08-22 03:19:00 +0000278 const uint8_t *ch = st->buf;
279 const uint8_t *end = ch + st->size;
vlm7d576b32004-08-20 13:37:45 +0000280
281 for(; ch < end; ch++) {
282 uint8_t cv = *ch;
vlmcdf661b2004-08-22 12:47:03 +0000283 if(!table[cv]) return -1;
vlm7d576b32004-08-20 13:37:45 +0000284 }
vlmcdf661b2004-08-22 12:47:03 +0000285 return 0;
vlm7d576b32004-08-20 13:37:45 +0000286}
287
288
289/*** <<< CODE [RelativeDistinguishedName] >>> ***/
290
291static int
vlmff3a6772004-09-05 10:37:18 +0000292memb_IA5String_2_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
vlm7d576b32004-08-20 13:37:45 +0000293 asn_app_consume_bytes_f *app_errlog, void *app_key) {
vlm824aefc2004-08-22 03:19:00 +0000294 const IA5String_t *st = sptr;
vlm7d576b32004-08-20 13:37:45 +0000295
296 if(!sptr) {
297 _ASN_ERRLOG(app_errlog, app_key,
vlm758530a2004-08-22 13:47:59 +0000298 "%s: value not given (%s:%d)",
299 td->name, __FILE__, __LINE__);
vlm7d576b32004-08-20 13:37:45 +0000300 return -1;
301 }
302
303
vlm7e20dfc2004-08-22 13:11:40 +0000304 if(!check_permitted_alphabet_1(sptr)) {
vlm7d576b32004-08-20 13:37:45 +0000305 /* Constraint check succeeded */
vlmcdf661b2004-08-22 12:47:03 +0000306 return 0;
vlm7d576b32004-08-20 13:37:45 +0000307 } else {
308 _ASN_ERRLOG(app_errlog, app_key,
vlm758530a2004-08-22 13:47:59 +0000309 "%s: constraint failed (%s:%d)",
310 td->name, __FILE__, __LINE__);
vlm7d576b32004-08-20 13:37:45 +0000311 return -1;
312 }
313}
314
315
316/*** <<< STAT-DEFS [RelativeDistinguishedName] >>> ***/
317
318static asn1_TYPE_member_t asn1_MBR_RelativeDistinguishedName[] = {
319 { 0, 0,
320 .tag = (ASN_TAG_CLASS_UNIVERSAL | (22 << 2)),
321 .tag_mode = 0,
322 .type = (void *)&asn1_DEF_IA5String,
vlmff3a6772004-09-05 10:37:18 +0000323 .memb_constraints = memb_IA5String_2_constraint,
vlm7d576b32004-08-20 13:37:45 +0000324 .name = ""
325 },
326};
327static ber_tlv_tag_t asn1_DEF_RelativeDistinguishedName_tags[] = {
328 (ASN_TAG_CLASS_UNIVERSAL | (17 << 2))
329};
330static asn1_SET_OF_specifics_t asn1_DEF_RelativeDistinguishedName_specs = {
331 sizeof(struct RelativeDistinguishedName),
332 offsetof(struct RelativeDistinguishedName, _ber_dec_ctx),
333};
334asn1_TYPE_descriptor_t asn1_DEF_RelativeDistinguishedName = {
335 "RelativeDistinguishedName",
336 SET_OF_constraint,
337 SET_OF_decode_ber,
338 SET_OF_encode_der,
339 SET_OF_print,
340 SET_OF_free,
341 0, /* Use generic outmost tag fetcher */
342 asn1_DEF_RelativeDistinguishedName_tags,
343 sizeof(asn1_DEF_RelativeDistinguishedName_tags)
344 /sizeof(asn1_DEF_RelativeDistinguishedName_tags[0]), /* 1 */
345 1, /* Tags to skip */
346 1, /* Whether CONSTRUCTED */
347 asn1_MBR_RelativeDistinguishedName,
348 1, /* Single element */
349 &asn1_DEF_RelativeDistinguishedName_specs /* Additional specs */
350};
351