blob: fa6aaf31ef717abcdefdc9c089aa7c5d73edb574 [file] [log] [blame]
Lev Walkin006de1c2004-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
Lev Walkindaa7d2b2004-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
Lev Walkin006de1c2004-08-20 13:37:45 +000067/*** <<< STAT-DEFS [Certificate] >>> ***/
68
69static asn1_TYPE_member_t asn1_MBR_toBeSigned[] = {
Lev Walkincc93b0f2004-09-10 09:18:20 +000070 { ATF_NOFLAGS, 0, offsetof(struct toBeSigned, version),
Lev Walkin006de1c2004-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 },
Lev Walkincc93b0f2004-09-10 09:18:20 +000077 { ATF_NOFLAGS, 0, offsetof(struct toBeSigned, signature),
Lev Walkin006de1c2004-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 },
Lev Walkincc93b0f2004-09-10 09:18:20 +000084 { ATF_NOFLAGS, 0, offsetof(struct toBeSigned, issuer),
Lev Walkin006de1c2004-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};
Lev Walkind04430c2004-09-07 06:44:29 +0000108static /* Use -fall-defs-global to expose */
Lev Walkin006de1c2004-08-20 13:37:45 +0000109asn1_TYPE_descriptor_t asn1_DEF_toBeSigned = {
110 "toBeSigned",
Lev Walkina9cc46e2004-09-22 16:06:28 +0000111 SEQUENCE_free,
112 SEQUENCE_print,
Lev Walkin006de1c2004-08-20 13:37:45 +0000113 SEQUENCE_constraint,
114 SEQUENCE_decode_ber,
115 SEQUENCE_encode_der,
Lev Walkina9cc46e2004-09-22 16:06:28 +0000116 0, /* Not implemented yet */
117 SEQUENCE_encode_xer,
Lev Walkin006de1c2004-08-20 13:37:45 +0000118 0, /* Use generic outmost tag fetcher */
119 asn1_DEF_toBeSigned_tags,
120 sizeof(asn1_DEF_toBeSigned_tags)
121 /sizeof(asn1_DEF_toBeSigned_tags[0]), /* 1 */
Lev Walkin188ed2c2004-09-13 08:31:01 +0000122 asn1_DEF_toBeSigned_tags, /* Same as above */
123 sizeof(asn1_DEF_toBeSigned_tags)
124 /sizeof(asn1_DEF_toBeSigned_tags[0]), /* 1 */
Lev Walkin006de1c2004-08-20 13:37:45 +0000125 1, /* Whether CONSTRUCTED */
126 asn1_MBR_toBeSigned,
127 3, /* Elements count */
128 &asn1_DEF_toBeSigned_specs /* Additional specs */
129};
130
131static asn1_TYPE_member_t asn1_MBR_Certificate[] = {
Lev Walkincc93b0f2004-09-10 09:18:20 +0000132 { ATF_NOFLAGS, 0, offsetof(struct Certificate, toBeSigned),
Lev Walkin006de1c2004-08-20 13:37:45 +0000133 .tag = (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)),
134 .tag_mode = 0,
135 .type = (void *)&asn1_DEF_toBeSigned,
136 .memb_constraints = 0, /* Defer to actual type */
137 .name = "toBeSigned"
138 },
Lev Walkincc93b0f2004-09-10 09:18:20 +0000139 { ATF_NOFLAGS, 0, offsetof(struct Certificate, algorithm),
Lev Walkin006de1c2004-08-20 13:37:45 +0000140 .tag = (ASN_TAG_CLASS_UNIVERSAL | (6 << 2)),
141 .tag_mode = 0,
142 .type = (void *)&asn1_DEF_OBJECT_IDENTIFIER,
143 .memb_constraints = 0, /* Defer to actual type */
144 .name = "algorithm"
145 },
Lev Walkincc93b0f2004-09-10 09:18:20 +0000146 { ATF_NOFLAGS, 0, offsetof(struct Certificate, signature),
Lev Walkin006de1c2004-08-20 13:37:45 +0000147 .tag = (ASN_TAG_CLASS_UNIVERSAL | (3 << 2)),
148 .tag_mode = 0,
149 .type = (void *)&asn1_DEF_BIT_STRING,
Lev Walkindaa7d2b2004-09-05 10:37:18 +0000150 .memb_constraints = memb_signature_1_constraint,
Lev Walkin006de1c2004-08-20 13:37:45 +0000151 .name = "signature"
152 },
153};
154static ber_tlv_tag_t asn1_DEF_Certificate_tags[] = {
155 (ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
156};
157static asn1_TYPE_tag2member_t asn1_DEF_Certificate_tag2el[] = {
Lev Walkindaa7d2b2004-09-05 10:37:18 +0000158 { (ASN_TAG_CLASS_UNIVERSAL | (3 << 2)), 2, 0, 0 }, /* signature at 17 */
Lev Walkin006de1c2004-08-20 13:37:45 +0000159 { (ASN_TAG_CLASS_UNIVERSAL | (6 << 2)), 1, 0, 0 }, /* algorithm at 16 */
160 { (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)), 0, 0, 0 }, /* toBeSigned at 21 */
161};
162static asn1_SEQUENCE_specifics_t asn1_DEF_Certificate_specs = {
163 sizeof(struct Certificate),
164 offsetof(struct Certificate, _ber_dec_ctx),
165 asn1_DEF_Certificate_tag2el,
166 3, /* Count of tags in the map */
167 -1, /* Start extensions */
168 -1 /* Stop extensions */
169};
170asn1_TYPE_descriptor_t asn1_DEF_Certificate = {
171 "Certificate",
Lev Walkina9cc46e2004-09-22 16:06:28 +0000172 SEQUENCE_free,
173 SEQUENCE_print,
Lev Walkin006de1c2004-08-20 13:37:45 +0000174 SEQUENCE_constraint,
175 SEQUENCE_decode_ber,
176 SEQUENCE_encode_der,
Lev Walkina9cc46e2004-09-22 16:06:28 +0000177 0, /* Not implemented yet */
178 SEQUENCE_encode_xer,
Lev Walkin006de1c2004-08-20 13:37:45 +0000179 0, /* Use generic outmost tag fetcher */
180 asn1_DEF_Certificate_tags,
181 sizeof(asn1_DEF_Certificate_tags)
182 /sizeof(asn1_DEF_Certificate_tags[0]), /* 1 */
Lev Walkin188ed2c2004-09-13 08:31:01 +0000183 asn1_DEF_Certificate_tags, /* Same as above */
184 sizeof(asn1_DEF_Certificate_tags)
185 /sizeof(asn1_DEF_Certificate_tags[0]), /* 1 */
Lev Walkin006de1c2004-08-20 13:37:45 +0000186 1, /* Whether CONSTRUCTED */
187 asn1_MBR_Certificate,
188 3, /* Elements count */
189 &asn1_DEF_Certificate_specs /* Additional specs */
190};
191
192
193/*** <<< INCLUDES [Name] >>> ***/
194
195#include <RelativeDistinguishedName.h>
196#include <asn_SEQUENCE_OF.h>
197#include <constr_SEQUENCE_OF.h>
198
199/*** <<< DEPS [Name] >>> ***/
200
201extern asn1_TYPE_descriptor_t asn1_DEF_Name;
202
203/*** <<< TYPE-DECLS [Name] >>> ***/
204
205
206typedef struct Name {
Lev Walkin8dd0eed2004-09-17 06:32:12 +0000207 A_SEQUENCE_OF(RelativeDistinguishedName_t) list;
Lev Walkin006de1c2004-08-20 13:37:45 +0000208
209 /* Context for parsing across buffer boundaries */
210 ber_dec_ctx_t _ber_dec_ctx;
211} Name_t;
212
213/*** <<< STAT-DEFS [Name] >>> ***/
214
215static asn1_TYPE_member_t asn1_MBR_Name[] = {
Lev Walkincc93b0f2004-09-10 09:18:20 +0000216 { ATF_NOFLAGS, 0, 0,
Lev Walkin006de1c2004-08-20 13:37:45 +0000217 .tag = (ASN_TAG_CLASS_UNIVERSAL | (17 << 2)),
218 .tag_mode = 0,
219 .type = (void *)&asn1_DEF_RelativeDistinguishedName,
220 .memb_constraints = 0, /* Defer to actual type */
221 .name = ""
222 },
223};
224static ber_tlv_tag_t asn1_DEF_Name_tags[] = {
225 (ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
226};
227static asn1_SET_OF_specifics_t asn1_DEF_Name_specs = {
228 sizeof(struct Name),
229 offsetof(struct Name, _ber_dec_ctx),
Lev Walkina9cc46e2004-09-22 16:06:28 +0000230 0, /* XER encoding is XMLDelimitedItemList */
Lev Walkin006de1c2004-08-20 13:37:45 +0000231};
232asn1_TYPE_descriptor_t asn1_DEF_Name = {
233 "Name",
Lev Walkina9cc46e2004-09-22 16:06:28 +0000234 SEQUENCE_OF_free,
235 SEQUENCE_OF_print,
Lev Walkin006de1c2004-08-20 13:37:45 +0000236 SEQUENCE_OF_constraint,
237 SEQUENCE_OF_decode_ber,
238 SEQUENCE_OF_encode_der,
Lev Walkina9cc46e2004-09-22 16:06:28 +0000239 0, /* Not implemented yet */
240 SEQUENCE_OF_encode_xer,
Lev Walkin006de1c2004-08-20 13:37:45 +0000241 0, /* Use generic outmost tag fetcher */
242 asn1_DEF_Name_tags,
243 sizeof(asn1_DEF_Name_tags)
244 /sizeof(asn1_DEF_Name_tags[0]), /* 1 */
Lev Walkin188ed2c2004-09-13 08:31:01 +0000245 asn1_DEF_Name_tags, /* Same as above */
246 sizeof(asn1_DEF_Name_tags)
247 /sizeof(asn1_DEF_Name_tags[0]), /* 1 */
Lev Walkin006de1c2004-08-20 13:37:45 +0000248 1, /* Whether CONSTRUCTED */
249 asn1_MBR_Name,
250 1, /* Single element */
251 &asn1_DEF_Name_specs /* Additional specs */
252};
253
254
255/*** <<< INCLUDES [RelativeDistinguishedName] >>> ***/
256
257#include <IA5String.h>
258#include <asn_SET_OF.h>
259#include <constr_SET_OF.h>
260
261/*** <<< DEPS [RelativeDistinguishedName] >>> ***/
262
263extern asn1_TYPE_descriptor_t asn1_DEF_RelativeDistinguishedName;
264
265/*** <<< TYPE-DECLS [RelativeDistinguishedName] >>> ***/
266
267
268typedef struct RelativeDistinguishedName {
269 A_SET_OF(IA5String_t) list;
270
271 /* Context for parsing across buffer boundaries */
272 ber_dec_ctx_t _ber_dec_ctx;
273} RelativeDistinguishedName_t;
274
275/*** <<< CTABLES [RelativeDistinguishedName] >>> ***/
276
277static int permitted_alphabet_table_1[256] = {
2780,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* */
2790,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* */
2800,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0, /* ,-. */
2811,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0, /* 0 9 */
2820,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* ABCDEFGHIJKLMNO */
2831,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, /* PQRSTUVWXYZ */
2840,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* abcdefghijklmno */
2851,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, /* pqrstuvwxyz */
286};
287
288static int check_permitted_alphabet_1(const void *sptr) {
289 int *table = permitted_alphabet_table_1;
290 /* The underlying type is IA5String */
Lev Walkind1e54942004-08-21 07:34:17 +0000291 const IA5String_t *st = sptr;
Lev Walkina09e5da2004-08-22 03:19:00 +0000292 const uint8_t *ch = st->buf;
293 const uint8_t *end = ch + st->size;
Lev Walkin006de1c2004-08-20 13:37:45 +0000294
295 for(; ch < end; ch++) {
296 uint8_t cv = *ch;
Lev Walkin775885e2004-08-22 12:47:03 +0000297 if(!table[cv]) return -1;
Lev Walkin006de1c2004-08-20 13:37:45 +0000298 }
Lev Walkin775885e2004-08-22 12:47:03 +0000299 return 0;
Lev Walkin006de1c2004-08-20 13:37:45 +0000300}
301
302
303/*** <<< CODE [RelativeDistinguishedName] >>> ***/
304
305static int
Lev Walkindaa7d2b2004-09-05 10:37:18 +0000306memb_IA5String_2_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
Lev Walkin006de1c2004-08-20 13:37:45 +0000307 asn_app_consume_bytes_f *app_errlog, void *app_key) {
Lev Walkina09e5da2004-08-22 03:19:00 +0000308 const IA5String_t *st = sptr;
Lev Walkin006de1c2004-08-20 13:37:45 +0000309
310 if(!sptr) {
311 _ASN_ERRLOG(app_errlog, app_key,
Lev Walkin16835b62004-08-22 13:47:59 +0000312 "%s: value not given (%s:%d)",
313 td->name, __FILE__, __LINE__);
Lev Walkin006de1c2004-08-20 13:37:45 +0000314 return -1;
315 }
316
317
Lev Walkin730b15a2004-08-22 13:11:40 +0000318 if(!check_permitted_alphabet_1(sptr)) {
Lev Walkin006de1c2004-08-20 13:37:45 +0000319 /* Constraint check succeeded */
Lev Walkin775885e2004-08-22 12:47:03 +0000320 return 0;
Lev Walkin006de1c2004-08-20 13:37:45 +0000321 } else {
322 _ASN_ERRLOG(app_errlog, app_key,
Lev Walkin16835b62004-08-22 13:47:59 +0000323 "%s: constraint failed (%s:%d)",
324 td->name, __FILE__, __LINE__);
Lev Walkin006de1c2004-08-20 13:37:45 +0000325 return -1;
326 }
327}
328
329
330/*** <<< STAT-DEFS [RelativeDistinguishedName] >>> ***/
331
332static asn1_TYPE_member_t asn1_MBR_RelativeDistinguishedName[] = {
Lev Walkincc93b0f2004-09-10 09:18:20 +0000333 { ATF_NOFLAGS, 0, 0,
Lev Walkin006de1c2004-08-20 13:37:45 +0000334 .tag = (ASN_TAG_CLASS_UNIVERSAL | (22 << 2)),
335 .tag_mode = 0,
336 .type = (void *)&asn1_DEF_IA5String,
Lev Walkindaa7d2b2004-09-05 10:37:18 +0000337 .memb_constraints = memb_IA5String_2_constraint,
Lev Walkin006de1c2004-08-20 13:37:45 +0000338 .name = ""
339 },
340};
341static ber_tlv_tag_t asn1_DEF_RelativeDistinguishedName_tags[] = {
342 (ASN_TAG_CLASS_UNIVERSAL | (17 << 2))
343};
344static asn1_SET_OF_specifics_t asn1_DEF_RelativeDistinguishedName_specs = {
345 sizeof(struct RelativeDistinguishedName),
346 offsetof(struct RelativeDistinguishedName, _ber_dec_ctx),
Lev Walkina9cc46e2004-09-22 16:06:28 +0000347 0, /* XER encoding is XMLDelimitedItemList */
Lev Walkin006de1c2004-08-20 13:37:45 +0000348};
349asn1_TYPE_descriptor_t asn1_DEF_RelativeDistinguishedName = {
350 "RelativeDistinguishedName",
Lev Walkina9cc46e2004-09-22 16:06:28 +0000351 SET_OF_free,
352 SET_OF_print,
Lev Walkin006de1c2004-08-20 13:37:45 +0000353 SET_OF_constraint,
354 SET_OF_decode_ber,
355 SET_OF_encode_der,
Lev Walkina9cc46e2004-09-22 16:06:28 +0000356 0, /* Not implemented yet */
357 SET_OF_encode_xer,
Lev Walkin006de1c2004-08-20 13:37:45 +0000358 0, /* Use generic outmost tag fetcher */
359 asn1_DEF_RelativeDistinguishedName_tags,
360 sizeof(asn1_DEF_RelativeDistinguishedName_tags)
361 /sizeof(asn1_DEF_RelativeDistinguishedName_tags[0]), /* 1 */
Lev Walkin188ed2c2004-09-13 08:31:01 +0000362 asn1_DEF_RelativeDistinguishedName_tags, /* Same as above */
363 sizeof(asn1_DEF_RelativeDistinguishedName_tags)
364 /sizeof(asn1_DEF_RelativeDistinguishedName_tags[0]), /* 1 */
Lev Walkin006de1c2004-08-20 13:37:45 +0000365 1, /* Whether CONSTRUCTED */
366 asn1_MBR_RelativeDistinguishedName,
367 1, /* Single element */
368 &asn1_DEF_RelativeDistinguishedName_specs /* Additional specs */
369};
370