blob: e980f1c5f750ad6ef8c34b20f0df65249522dbe7 [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[] = {
vlmddd5a7d2004-09-10 09:18:20 +000070 { ATF_NOFLAGS, 0, offsetof(struct toBeSigned, version),
vlm7d576b32004-08-20 13:37:45 +000071 .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 },
vlmddd5a7d2004-09-10 09:18:20 +000077 { ATF_NOFLAGS, 0, offsetof(struct toBeSigned, signature),
vlm7d576b32004-08-20 13:37:45 +000078 .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 },
vlmddd5a7d2004-09-10 09:18:20 +000084 { ATF_NOFLAGS, 0, offsetof(struct toBeSigned, issuer),
vlm7d576b32004-08-20 13:37:45 +000085 .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};
vlm1dc848e2004-09-07 06:44:29 +0000108static /* Use -fall-defs-global to expose */
vlm7d576b32004-08-20 13:37:45 +0000109asn1_TYPE_descriptor_t asn1_DEF_toBeSigned = {
110 "toBeSigned",
111 SEQUENCE_constraint,
112 SEQUENCE_decode_ber,
113 SEQUENCE_encode_der,
114 SEQUENCE_print,
115 SEQUENCE_free,
116 0, /* Use generic outmost tag fetcher */
117 asn1_DEF_toBeSigned_tags,
118 sizeof(asn1_DEF_toBeSigned_tags)
119 /sizeof(asn1_DEF_toBeSigned_tags[0]), /* 1 */
vlm72425de2004-09-13 08:31:01 +0000120 asn1_DEF_toBeSigned_tags, /* Same as above */
121 sizeof(asn1_DEF_toBeSigned_tags)
122 /sizeof(asn1_DEF_toBeSigned_tags[0]), /* 1 */
vlm7d576b32004-08-20 13:37:45 +0000123 1, /* Whether CONSTRUCTED */
124 asn1_MBR_toBeSigned,
125 3, /* Elements count */
126 &asn1_DEF_toBeSigned_specs /* Additional specs */
127};
128
129static asn1_TYPE_member_t asn1_MBR_Certificate[] = {
vlmddd5a7d2004-09-10 09:18:20 +0000130 { ATF_NOFLAGS, 0, offsetof(struct Certificate, toBeSigned),
vlm7d576b32004-08-20 13:37:45 +0000131 .tag = (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)),
132 .tag_mode = 0,
133 .type = (void *)&asn1_DEF_toBeSigned,
134 .memb_constraints = 0, /* Defer to actual type */
135 .name = "toBeSigned"
136 },
vlmddd5a7d2004-09-10 09:18:20 +0000137 { ATF_NOFLAGS, 0, offsetof(struct Certificate, algorithm),
vlm7d576b32004-08-20 13:37:45 +0000138 .tag = (ASN_TAG_CLASS_UNIVERSAL | (6 << 2)),
139 .tag_mode = 0,
140 .type = (void *)&asn1_DEF_OBJECT_IDENTIFIER,
141 .memb_constraints = 0, /* Defer to actual type */
142 .name = "algorithm"
143 },
vlmddd5a7d2004-09-10 09:18:20 +0000144 { ATF_NOFLAGS, 0, offsetof(struct Certificate, signature),
vlm7d576b32004-08-20 13:37:45 +0000145 .tag = (ASN_TAG_CLASS_UNIVERSAL | (3 << 2)),
146 .tag_mode = 0,
147 .type = (void *)&asn1_DEF_BIT_STRING,
vlmff3a6772004-09-05 10:37:18 +0000148 .memb_constraints = memb_signature_1_constraint,
vlm7d576b32004-08-20 13:37:45 +0000149 .name = "signature"
150 },
151};
152static ber_tlv_tag_t asn1_DEF_Certificate_tags[] = {
153 (ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
154};
155static asn1_TYPE_tag2member_t asn1_DEF_Certificate_tag2el[] = {
vlmff3a6772004-09-05 10:37:18 +0000156 { (ASN_TAG_CLASS_UNIVERSAL | (3 << 2)), 2, 0, 0 }, /* signature at 17 */
vlm7d576b32004-08-20 13:37:45 +0000157 { (ASN_TAG_CLASS_UNIVERSAL | (6 << 2)), 1, 0, 0 }, /* algorithm at 16 */
158 { (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)), 0, 0, 0 }, /* toBeSigned at 21 */
159};
160static asn1_SEQUENCE_specifics_t asn1_DEF_Certificate_specs = {
161 sizeof(struct Certificate),
162 offsetof(struct Certificate, _ber_dec_ctx),
163 asn1_DEF_Certificate_tag2el,
164 3, /* Count of tags in the map */
165 -1, /* Start extensions */
166 -1 /* Stop extensions */
167};
168asn1_TYPE_descriptor_t asn1_DEF_Certificate = {
169 "Certificate",
170 SEQUENCE_constraint,
171 SEQUENCE_decode_ber,
172 SEQUENCE_encode_der,
173 SEQUENCE_print,
174 SEQUENCE_free,
175 0, /* Use generic outmost tag fetcher */
176 asn1_DEF_Certificate_tags,
177 sizeof(asn1_DEF_Certificate_tags)
178 /sizeof(asn1_DEF_Certificate_tags[0]), /* 1 */
vlm72425de2004-09-13 08:31:01 +0000179 asn1_DEF_Certificate_tags, /* Same as above */
180 sizeof(asn1_DEF_Certificate_tags)
181 /sizeof(asn1_DEF_Certificate_tags[0]), /* 1 */
vlm7d576b32004-08-20 13:37:45 +0000182 1, /* Whether CONSTRUCTED */
183 asn1_MBR_Certificate,
184 3, /* Elements count */
185 &asn1_DEF_Certificate_specs /* Additional specs */
186};
187
188
189/*** <<< INCLUDES [Name] >>> ***/
190
191#include <RelativeDistinguishedName.h>
192#include <asn_SEQUENCE_OF.h>
193#include <constr_SEQUENCE_OF.h>
194
195/*** <<< DEPS [Name] >>> ***/
196
197extern asn1_TYPE_descriptor_t asn1_DEF_Name;
198
199/*** <<< TYPE-DECLS [Name] >>> ***/
200
201
202typedef struct Name {
vlmb47f48e2004-09-17 06:32:12 +0000203 A_SEQUENCE_OF(RelativeDistinguishedName_t) list;
vlm7d576b32004-08-20 13:37:45 +0000204
205 /* Context for parsing across buffer boundaries */
206 ber_dec_ctx_t _ber_dec_ctx;
207} Name_t;
208
209/*** <<< STAT-DEFS [Name] >>> ***/
210
211static asn1_TYPE_member_t asn1_MBR_Name[] = {
vlmddd5a7d2004-09-10 09:18:20 +0000212 { ATF_NOFLAGS, 0, 0,
vlm7d576b32004-08-20 13:37:45 +0000213 .tag = (ASN_TAG_CLASS_UNIVERSAL | (17 << 2)),
214 .tag_mode = 0,
215 .type = (void *)&asn1_DEF_RelativeDistinguishedName,
216 .memb_constraints = 0, /* Defer to actual type */
217 .name = ""
218 },
219};
220static ber_tlv_tag_t asn1_DEF_Name_tags[] = {
221 (ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
222};
223static asn1_SET_OF_specifics_t asn1_DEF_Name_specs = {
224 sizeof(struct Name),
225 offsetof(struct Name, _ber_dec_ctx),
226};
227asn1_TYPE_descriptor_t asn1_DEF_Name = {
228 "Name",
229 SEQUENCE_OF_constraint,
230 SEQUENCE_OF_decode_ber,
231 SEQUENCE_OF_encode_der,
232 SEQUENCE_OF_print,
233 SEQUENCE_OF_free,
234 0, /* Use generic outmost tag fetcher */
235 asn1_DEF_Name_tags,
236 sizeof(asn1_DEF_Name_tags)
237 /sizeof(asn1_DEF_Name_tags[0]), /* 1 */
vlm72425de2004-09-13 08:31:01 +0000238 asn1_DEF_Name_tags, /* Same as above */
239 sizeof(asn1_DEF_Name_tags)
240 /sizeof(asn1_DEF_Name_tags[0]), /* 1 */
vlm7d576b32004-08-20 13:37:45 +0000241 1, /* Whether CONSTRUCTED */
242 asn1_MBR_Name,
243 1, /* Single element */
244 &asn1_DEF_Name_specs /* Additional specs */
245};
246
247
248/*** <<< INCLUDES [RelativeDistinguishedName] >>> ***/
249
250#include <IA5String.h>
251#include <asn_SET_OF.h>
252#include <constr_SET_OF.h>
253
254/*** <<< DEPS [RelativeDistinguishedName] >>> ***/
255
256extern asn1_TYPE_descriptor_t asn1_DEF_RelativeDistinguishedName;
257
258/*** <<< TYPE-DECLS [RelativeDistinguishedName] >>> ***/
259
260
261typedef struct RelativeDistinguishedName {
262 A_SET_OF(IA5String_t) list;
263
264 /* Context for parsing across buffer boundaries */
265 ber_dec_ctx_t _ber_dec_ctx;
266} RelativeDistinguishedName_t;
267
268/*** <<< CTABLES [RelativeDistinguishedName] >>> ***/
269
270static int permitted_alphabet_table_1[256] = {
2710,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* */
2720,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* */
2730,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0, /* ,-. */
2741,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0, /* 0 9 */
2750,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* ABCDEFGHIJKLMNO */
2761,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, /* PQRSTUVWXYZ */
2770,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* abcdefghijklmno */
2781,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, /* pqrstuvwxyz */
279};
280
281static int check_permitted_alphabet_1(const void *sptr) {
282 int *table = permitted_alphabet_table_1;
283 /* The underlying type is IA5String */
vlm4fdaead2004-08-21 07:34:17 +0000284 const IA5String_t *st = sptr;
vlm824aefc2004-08-22 03:19:00 +0000285 const uint8_t *ch = st->buf;
286 const uint8_t *end = ch + st->size;
vlm7d576b32004-08-20 13:37:45 +0000287
288 for(; ch < end; ch++) {
289 uint8_t cv = *ch;
vlmcdf661b2004-08-22 12:47:03 +0000290 if(!table[cv]) return -1;
vlm7d576b32004-08-20 13:37:45 +0000291 }
vlmcdf661b2004-08-22 12:47:03 +0000292 return 0;
vlm7d576b32004-08-20 13:37:45 +0000293}
294
295
296/*** <<< CODE [RelativeDistinguishedName] >>> ***/
297
298static int
vlmff3a6772004-09-05 10:37:18 +0000299memb_IA5String_2_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
vlm7d576b32004-08-20 13:37:45 +0000300 asn_app_consume_bytes_f *app_errlog, void *app_key) {
vlm824aefc2004-08-22 03:19:00 +0000301 const IA5String_t *st = sptr;
vlm7d576b32004-08-20 13:37:45 +0000302
303 if(!sptr) {
304 _ASN_ERRLOG(app_errlog, app_key,
vlm758530a2004-08-22 13:47:59 +0000305 "%s: value not given (%s:%d)",
306 td->name, __FILE__, __LINE__);
vlm7d576b32004-08-20 13:37:45 +0000307 return -1;
308 }
309
310
vlm7e20dfc2004-08-22 13:11:40 +0000311 if(!check_permitted_alphabet_1(sptr)) {
vlm7d576b32004-08-20 13:37:45 +0000312 /* Constraint check succeeded */
vlmcdf661b2004-08-22 12:47:03 +0000313 return 0;
vlm7d576b32004-08-20 13:37:45 +0000314 } else {
315 _ASN_ERRLOG(app_errlog, app_key,
vlm758530a2004-08-22 13:47:59 +0000316 "%s: constraint failed (%s:%d)",
317 td->name, __FILE__, __LINE__);
vlm7d576b32004-08-20 13:37:45 +0000318 return -1;
319 }
320}
321
322
323/*** <<< STAT-DEFS [RelativeDistinguishedName] >>> ***/
324
325static asn1_TYPE_member_t asn1_MBR_RelativeDistinguishedName[] = {
vlmddd5a7d2004-09-10 09:18:20 +0000326 { ATF_NOFLAGS, 0, 0,
vlm7d576b32004-08-20 13:37:45 +0000327 .tag = (ASN_TAG_CLASS_UNIVERSAL | (22 << 2)),
328 .tag_mode = 0,
329 .type = (void *)&asn1_DEF_IA5String,
vlmff3a6772004-09-05 10:37:18 +0000330 .memb_constraints = memb_IA5String_2_constraint,
vlm7d576b32004-08-20 13:37:45 +0000331 .name = ""
332 },
333};
334static ber_tlv_tag_t asn1_DEF_RelativeDistinguishedName_tags[] = {
335 (ASN_TAG_CLASS_UNIVERSAL | (17 << 2))
336};
337static asn1_SET_OF_specifics_t asn1_DEF_RelativeDistinguishedName_specs = {
338 sizeof(struct RelativeDistinguishedName),
339 offsetof(struct RelativeDistinguishedName, _ber_dec_ctx),
340};
341asn1_TYPE_descriptor_t asn1_DEF_RelativeDistinguishedName = {
342 "RelativeDistinguishedName",
343 SET_OF_constraint,
344 SET_OF_decode_ber,
345 SET_OF_encode_der,
346 SET_OF_print,
347 SET_OF_free,
348 0, /* Use generic outmost tag fetcher */
349 asn1_DEF_RelativeDistinguishedName_tags,
350 sizeof(asn1_DEF_RelativeDistinguishedName_tags)
351 /sizeof(asn1_DEF_RelativeDistinguishedName_tags[0]), /* 1 */
vlm72425de2004-09-13 08:31:01 +0000352 asn1_DEF_RelativeDistinguishedName_tags, /* Same as above */
353 sizeof(asn1_DEF_RelativeDistinguishedName_tags)
354 /sizeof(asn1_DEF_RelativeDistinguishedName_tags[0]), /* 1 */
vlm7d576b32004-08-20 13:37:45 +0000355 1, /* Whether CONSTRUCTED */
356 asn1_MBR_RelativeDistinguishedName,
357 1, /* Single element */
358 &asn1_DEF_RelativeDistinguishedName_specs /* Additional specs */
359};
360