Lev Walkin | 006de1c | 2004-08-20 13:37:45 +0000 | [diff] [blame] | 1 | |
| 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 | |
| 12 | extern asn1_TYPE_descriptor_t asn1_DEF_Certificate; |
| 13 | |
| 14 | /*** <<< TYPE-DECLS [Certificate] >>> ***/ |
| 15 | |
| 16 | |
| 17 | typedef 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 Walkin | daa7d2b | 2004-09-05 10:37:18 +0000 | [diff] [blame] | 33 | /*** <<< CODE [Certificate] >>> ***/ |
| 34 | |
| 35 | static int |
| 36 | memb_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 Walkin | 006de1c | 2004-08-20 13:37:45 +0000 | [diff] [blame] | 67 | /*** <<< STAT-DEFS [Certificate] >>> ***/ |
| 68 | |
| 69 | static 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 | }; |
| 92 | static ber_tlv_tag_t asn1_DEF_toBeSigned_tags[] = { |
| 93 | (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) |
| 94 | }; |
| 95 | static 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 | }; |
| 100 | static 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 Walkin | d04430c | 2004-09-07 06:44:29 +0000 | [diff] [blame] | 108 | static /* Use -fall-defs-global to expose */ |
Lev Walkin | 006de1c | 2004-08-20 13:37:45 +0000 | [diff] [blame] | 109 | asn1_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 */ |
| 120 | 1, /* Tags to skip */ |
| 121 | 1, /* Whether CONSTRUCTED */ |
| 122 | asn1_MBR_toBeSigned, |
| 123 | 3, /* Elements count */ |
| 124 | &asn1_DEF_toBeSigned_specs /* Additional specs */ |
| 125 | }; |
| 126 | |
| 127 | static asn1_TYPE_member_t asn1_MBR_Certificate[] = { |
| 128 | { 0, offsetof(struct Certificate, toBeSigned), |
| 129 | .tag = (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)), |
| 130 | .tag_mode = 0, |
| 131 | .type = (void *)&asn1_DEF_toBeSigned, |
| 132 | .memb_constraints = 0, /* Defer to actual type */ |
| 133 | .name = "toBeSigned" |
| 134 | }, |
| 135 | { 0, offsetof(struct Certificate, algorithm), |
| 136 | .tag = (ASN_TAG_CLASS_UNIVERSAL | (6 << 2)), |
| 137 | .tag_mode = 0, |
| 138 | .type = (void *)&asn1_DEF_OBJECT_IDENTIFIER, |
| 139 | .memb_constraints = 0, /* Defer to actual type */ |
| 140 | .name = "algorithm" |
| 141 | }, |
| 142 | { 0, offsetof(struct Certificate, signature), |
| 143 | .tag = (ASN_TAG_CLASS_UNIVERSAL | (3 << 2)), |
| 144 | .tag_mode = 0, |
| 145 | .type = (void *)&asn1_DEF_BIT_STRING, |
Lev Walkin | daa7d2b | 2004-09-05 10:37:18 +0000 | [diff] [blame] | 146 | .memb_constraints = memb_signature_1_constraint, |
Lev Walkin | 006de1c | 2004-08-20 13:37:45 +0000 | [diff] [blame] | 147 | .name = "signature" |
| 148 | }, |
| 149 | }; |
| 150 | static ber_tlv_tag_t asn1_DEF_Certificate_tags[] = { |
| 151 | (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) |
| 152 | }; |
| 153 | static asn1_TYPE_tag2member_t asn1_DEF_Certificate_tag2el[] = { |
Lev Walkin | daa7d2b | 2004-09-05 10:37:18 +0000 | [diff] [blame] | 154 | { (ASN_TAG_CLASS_UNIVERSAL | (3 << 2)), 2, 0, 0 }, /* signature at 17 */ |
Lev Walkin | 006de1c | 2004-08-20 13:37:45 +0000 | [diff] [blame] | 155 | { (ASN_TAG_CLASS_UNIVERSAL | (6 << 2)), 1, 0, 0 }, /* algorithm at 16 */ |
| 156 | { (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)), 0, 0, 0 }, /* toBeSigned at 21 */ |
| 157 | }; |
| 158 | static asn1_SEQUENCE_specifics_t asn1_DEF_Certificate_specs = { |
| 159 | sizeof(struct Certificate), |
| 160 | offsetof(struct Certificate, _ber_dec_ctx), |
| 161 | asn1_DEF_Certificate_tag2el, |
| 162 | 3, /* Count of tags in the map */ |
| 163 | -1, /* Start extensions */ |
| 164 | -1 /* Stop extensions */ |
| 165 | }; |
| 166 | asn1_TYPE_descriptor_t asn1_DEF_Certificate = { |
| 167 | "Certificate", |
| 168 | SEQUENCE_constraint, |
| 169 | SEQUENCE_decode_ber, |
| 170 | SEQUENCE_encode_der, |
| 171 | SEQUENCE_print, |
| 172 | SEQUENCE_free, |
| 173 | 0, /* Use generic outmost tag fetcher */ |
| 174 | asn1_DEF_Certificate_tags, |
| 175 | sizeof(asn1_DEF_Certificate_tags) |
| 176 | /sizeof(asn1_DEF_Certificate_tags[0]), /* 1 */ |
| 177 | 1, /* Tags to skip */ |
| 178 | 1, /* Whether CONSTRUCTED */ |
| 179 | asn1_MBR_Certificate, |
| 180 | 3, /* Elements count */ |
| 181 | &asn1_DEF_Certificate_specs /* Additional specs */ |
| 182 | }; |
| 183 | |
| 184 | |
| 185 | /*** <<< INCLUDES [Name] >>> ***/ |
| 186 | |
| 187 | #include <RelativeDistinguishedName.h> |
| 188 | #include <asn_SEQUENCE_OF.h> |
| 189 | #include <constr_SEQUENCE_OF.h> |
| 190 | |
| 191 | /*** <<< DEPS [Name] >>> ***/ |
| 192 | |
| 193 | extern asn1_TYPE_descriptor_t asn1_DEF_Name; |
| 194 | |
| 195 | /*** <<< TYPE-DECLS [Name] >>> ***/ |
| 196 | |
| 197 | |
| 198 | typedef struct Name { |
| 199 | A_SEQUENCE_OF(struct RelativeDistinguishedName) list; |
| 200 | |
| 201 | /* Context for parsing across buffer boundaries */ |
| 202 | ber_dec_ctx_t _ber_dec_ctx; |
| 203 | } Name_t; |
| 204 | |
| 205 | /*** <<< STAT-DEFS [Name] >>> ***/ |
| 206 | |
| 207 | static asn1_TYPE_member_t asn1_MBR_Name[] = { |
| 208 | { 0, 0, |
| 209 | .tag = (ASN_TAG_CLASS_UNIVERSAL | (17 << 2)), |
| 210 | .tag_mode = 0, |
| 211 | .type = (void *)&asn1_DEF_RelativeDistinguishedName, |
| 212 | .memb_constraints = 0, /* Defer to actual type */ |
| 213 | .name = "" |
| 214 | }, |
| 215 | }; |
| 216 | static ber_tlv_tag_t asn1_DEF_Name_tags[] = { |
| 217 | (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) |
| 218 | }; |
| 219 | static asn1_SET_OF_specifics_t asn1_DEF_Name_specs = { |
| 220 | sizeof(struct Name), |
| 221 | offsetof(struct Name, _ber_dec_ctx), |
| 222 | }; |
| 223 | asn1_TYPE_descriptor_t asn1_DEF_Name = { |
| 224 | "Name", |
| 225 | SEQUENCE_OF_constraint, |
| 226 | SEQUENCE_OF_decode_ber, |
| 227 | SEQUENCE_OF_encode_der, |
| 228 | SEQUENCE_OF_print, |
| 229 | SEQUENCE_OF_free, |
| 230 | 0, /* Use generic outmost tag fetcher */ |
| 231 | asn1_DEF_Name_tags, |
| 232 | sizeof(asn1_DEF_Name_tags) |
| 233 | /sizeof(asn1_DEF_Name_tags[0]), /* 1 */ |
| 234 | 1, /* Tags to skip */ |
| 235 | 1, /* Whether CONSTRUCTED */ |
| 236 | asn1_MBR_Name, |
| 237 | 1, /* Single element */ |
| 238 | &asn1_DEF_Name_specs /* Additional specs */ |
| 239 | }; |
| 240 | |
| 241 | |
| 242 | /*** <<< INCLUDES [RelativeDistinguishedName] >>> ***/ |
| 243 | |
| 244 | #include <IA5String.h> |
| 245 | #include <asn_SET_OF.h> |
| 246 | #include <constr_SET_OF.h> |
| 247 | |
| 248 | /*** <<< DEPS [RelativeDistinguishedName] >>> ***/ |
| 249 | |
| 250 | extern asn1_TYPE_descriptor_t asn1_DEF_RelativeDistinguishedName; |
| 251 | |
| 252 | /*** <<< TYPE-DECLS [RelativeDistinguishedName] >>> ***/ |
| 253 | |
| 254 | |
| 255 | typedef struct RelativeDistinguishedName { |
| 256 | A_SET_OF(IA5String_t) list; |
| 257 | |
| 258 | /* Context for parsing across buffer boundaries */ |
| 259 | ber_dec_ctx_t _ber_dec_ctx; |
| 260 | } RelativeDistinguishedName_t; |
| 261 | |
| 262 | /*** <<< CTABLES [RelativeDistinguishedName] >>> ***/ |
| 263 | |
| 264 | static int permitted_alphabet_table_1[256] = { |
| 265 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* */ |
| 266 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* */ |
| 267 | 0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0, /* ,-. */ |
| 268 | 1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0, /* 0 9 */ |
| 269 | 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* ABCDEFGHIJKLMNO */ |
| 270 | 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, /* PQRSTUVWXYZ */ |
| 271 | 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* abcdefghijklmno */ |
| 272 | 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, /* pqrstuvwxyz */ |
| 273 | }; |
| 274 | |
| 275 | static int check_permitted_alphabet_1(const void *sptr) { |
| 276 | int *table = permitted_alphabet_table_1; |
| 277 | /* The underlying type is IA5String */ |
Lev Walkin | d1e5494 | 2004-08-21 07:34:17 +0000 | [diff] [blame] | 278 | const IA5String_t *st = sptr; |
Lev Walkin | a09e5da | 2004-08-22 03:19:00 +0000 | [diff] [blame] | 279 | const uint8_t *ch = st->buf; |
| 280 | const uint8_t *end = ch + st->size; |
Lev Walkin | 006de1c | 2004-08-20 13:37:45 +0000 | [diff] [blame] | 281 | |
| 282 | for(; ch < end; ch++) { |
| 283 | uint8_t cv = *ch; |
Lev Walkin | 775885e | 2004-08-22 12:47:03 +0000 | [diff] [blame] | 284 | if(!table[cv]) return -1; |
Lev Walkin | 006de1c | 2004-08-20 13:37:45 +0000 | [diff] [blame] | 285 | } |
Lev Walkin | 775885e | 2004-08-22 12:47:03 +0000 | [diff] [blame] | 286 | return 0; |
Lev Walkin | 006de1c | 2004-08-20 13:37:45 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | |
| 290 | /*** <<< CODE [RelativeDistinguishedName] >>> ***/ |
| 291 | |
| 292 | static int |
Lev Walkin | daa7d2b | 2004-09-05 10:37:18 +0000 | [diff] [blame] | 293 | memb_IA5String_2_constraint(asn1_TYPE_descriptor_t *td, const void *sptr, |
Lev Walkin | 006de1c | 2004-08-20 13:37:45 +0000 | [diff] [blame] | 294 | asn_app_consume_bytes_f *app_errlog, void *app_key) { |
Lev Walkin | a09e5da | 2004-08-22 03:19:00 +0000 | [diff] [blame] | 295 | const IA5String_t *st = sptr; |
Lev Walkin | 006de1c | 2004-08-20 13:37:45 +0000 | [diff] [blame] | 296 | |
| 297 | if(!sptr) { |
| 298 | _ASN_ERRLOG(app_errlog, app_key, |
Lev Walkin | 16835b6 | 2004-08-22 13:47:59 +0000 | [diff] [blame] | 299 | "%s: value not given (%s:%d)", |
| 300 | td->name, __FILE__, __LINE__); |
Lev Walkin | 006de1c | 2004-08-20 13:37:45 +0000 | [diff] [blame] | 301 | return -1; |
| 302 | } |
| 303 | |
| 304 | |
Lev Walkin | 730b15a | 2004-08-22 13:11:40 +0000 | [diff] [blame] | 305 | if(!check_permitted_alphabet_1(sptr)) { |
Lev Walkin | 006de1c | 2004-08-20 13:37:45 +0000 | [diff] [blame] | 306 | /* Constraint check succeeded */ |
Lev Walkin | 775885e | 2004-08-22 12:47:03 +0000 | [diff] [blame] | 307 | return 0; |
Lev Walkin | 006de1c | 2004-08-20 13:37:45 +0000 | [diff] [blame] | 308 | } else { |
| 309 | _ASN_ERRLOG(app_errlog, app_key, |
Lev Walkin | 16835b6 | 2004-08-22 13:47:59 +0000 | [diff] [blame] | 310 | "%s: constraint failed (%s:%d)", |
| 311 | td->name, __FILE__, __LINE__); |
Lev Walkin | 006de1c | 2004-08-20 13:37:45 +0000 | [diff] [blame] | 312 | return -1; |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | |
| 317 | /*** <<< STAT-DEFS [RelativeDistinguishedName] >>> ***/ |
| 318 | |
| 319 | static asn1_TYPE_member_t asn1_MBR_RelativeDistinguishedName[] = { |
| 320 | { 0, 0, |
| 321 | .tag = (ASN_TAG_CLASS_UNIVERSAL | (22 << 2)), |
| 322 | .tag_mode = 0, |
| 323 | .type = (void *)&asn1_DEF_IA5String, |
Lev Walkin | daa7d2b | 2004-09-05 10:37:18 +0000 | [diff] [blame] | 324 | .memb_constraints = memb_IA5String_2_constraint, |
Lev Walkin | 006de1c | 2004-08-20 13:37:45 +0000 | [diff] [blame] | 325 | .name = "" |
| 326 | }, |
| 327 | }; |
| 328 | static ber_tlv_tag_t asn1_DEF_RelativeDistinguishedName_tags[] = { |
| 329 | (ASN_TAG_CLASS_UNIVERSAL | (17 << 2)) |
| 330 | }; |
| 331 | static asn1_SET_OF_specifics_t asn1_DEF_RelativeDistinguishedName_specs = { |
| 332 | sizeof(struct RelativeDistinguishedName), |
| 333 | offsetof(struct RelativeDistinguishedName, _ber_dec_ctx), |
| 334 | }; |
| 335 | asn1_TYPE_descriptor_t asn1_DEF_RelativeDistinguishedName = { |
| 336 | "RelativeDistinguishedName", |
| 337 | SET_OF_constraint, |
| 338 | SET_OF_decode_ber, |
| 339 | SET_OF_encode_der, |
| 340 | SET_OF_print, |
| 341 | SET_OF_free, |
| 342 | 0, /* Use generic outmost tag fetcher */ |
| 343 | asn1_DEF_RelativeDistinguishedName_tags, |
| 344 | sizeof(asn1_DEF_RelativeDistinguishedName_tags) |
| 345 | /sizeof(asn1_DEF_RelativeDistinguishedName_tags[0]), /* 1 */ |
| 346 | 1, /* Tags to skip */ |
| 347 | 1, /* Whether CONSTRUCTED */ |
| 348 | asn1_MBR_RelativeDistinguishedName, |
| 349 | 1, /* Single element */ |
| 350 | &asn1_DEF_RelativeDistinguishedName_specs /* Additional specs */ |
| 351 | }; |
| 352 | |