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 | |
| 33 | /*** <<< STAT-DEFS [Certificate] >>> ***/ |
| 34 | |
| 35 | static asn1_TYPE_member_t asn1_MBR_toBeSigned[] = { |
| 36 | { 0, offsetof(struct toBeSigned, version), |
| 37 | .tag = (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), |
| 38 | .tag_mode = 0, |
| 39 | .type = (void *)&asn1_DEF_INTEGER, |
| 40 | .memb_constraints = 0, /* Defer to actual type */ |
| 41 | .name = "version" |
| 42 | }, |
| 43 | { 0, offsetof(struct toBeSigned, signature), |
| 44 | .tag = (ASN_TAG_CLASS_UNIVERSAL | (6 << 2)), |
| 45 | .tag_mode = 0, |
| 46 | .type = (void *)&asn1_DEF_OBJECT_IDENTIFIER, |
| 47 | .memb_constraints = 0, /* Defer to actual type */ |
| 48 | .name = "signature" |
| 49 | }, |
| 50 | { 0, offsetof(struct toBeSigned, issuer), |
| 51 | .tag = (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)), |
| 52 | .tag_mode = 0, |
| 53 | .type = (void *)&asn1_DEF_Name, |
| 54 | .memb_constraints = 0, /* Defer to actual type */ |
| 55 | .name = "issuer" |
| 56 | }, |
| 57 | }; |
| 58 | static ber_tlv_tag_t asn1_DEF_toBeSigned_tags[] = { |
| 59 | (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) |
| 60 | }; |
| 61 | static asn1_TYPE_tag2member_t asn1_DEF_toBeSigned_tag2el[] = { |
| 62 | { (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 0, 0, 0 }, /* version at 21 */ |
| 63 | { (ASN_TAG_CLASS_UNIVERSAL | (6 << 2)), 1, 0, 0 }, /* signature at 22 */ |
| 64 | { (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)), 2, 0, 0 }, /* issuer at 24 */ |
| 65 | }; |
| 66 | static asn1_SEQUENCE_specifics_t asn1_DEF_toBeSigned_specs = { |
| 67 | sizeof(struct toBeSigned), |
| 68 | offsetof(struct toBeSigned, _ber_dec_ctx), |
| 69 | asn1_DEF_toBeSigned_tag2el, |
| 70 | 3, /* Count of tags in the map */ |
| 71 | -1, /* Start extensions */ |
| 72 | -1 /* Stop extensions */ |
| 73 | }; |
| 74 | asn1_TYPE_descriptor_t asn1_DEF_toBeSigned = { |
| 75 | "toBeSigned", |
| 76 | SEQUENCE_constraint, |
| 77 | SEQUENCE_decode_ber, |
| 78 | SEQUENCE_encode_der, |
| 79 | SEQUENCE_print, |
| 80 | SEQUENCE_free, |
| 81 | 0, /* Use generic outmost tag fetcher */ |
| 82 | asn1_DEF_toBeSigned_tags, |
| 83 | sizeof(asn1_DEF_toBeSigned_tags) |
| 84 | /sizeof(asn1_DEF_toBeSigned_tags[0]), /* 1 */ |
| 85 | 1, /* Tags to skip */ |
| 86 | 1, /* Whether CONSTRUCTED */ |
| 87 | asn1_MBR_toBeSigned, |
| 88 | 3, /* Elements count */ |
| 89 | &asn1_DEF_toBeSigned_specs /* Additional specs */ |
| 90 | }; |
| 91 | |
| 92 | static asn1_TYPE_member_t asn1_MBR_Certificate[] = { |
| 93 | { 0, offsetof(struct Certificate, toBeSigned), |
| 94 | .tag = (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)), |
| 95 | .tag_mode = 0, |
| 96 | .type = (void *)&asn1_DEF_toBeSigned, |
| 97 | .memb_constraints = 0, /* Defer to actual type */ |
| 98 | .name = "toBeSigned" |
| 99 | }, |
| 100 | { 0, offsetof(struct Certificate, algorithm), |
| 101 | .tag = (ASN_TAG_CLASS_UNIVERSAL | (6 << 2)), |
| 102 | .tag_mode = 0, |
| 103 | .type = (void *)&asn1_DEF_OBJECT_IDENTIFIER, |
| 104 | .memb_constraints = 0, /* Defer to actual type */ |
| 105 | .name = "algorithm" |
| 106 | }, |
| 107 | { 0, offsetof(struct Certificate, signature), |
| 108 | .tag = (ASN_TAG_CLASS_UNIVERSAL | (3 << 2)), |
| 109 | .tag_mode = 0, |
| 110 | .type = (void *)&asn1_DEF_BIT_STRING, |
| 111 | .memb_constraints = 0, /* Defer to actual type */ |
| 112 | .name = "signature" |
| 113 | }, |
| 114 | }; |
| 115 | static ber_tlv_tag_t asn1_DEF_Certificate_tags[] = { |
| 116 | (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) |
| 117 | }; |
| 118 | static asn1_TYPE_tag2member_t asn1_DEF_Certificate_tag2el[] = { |
| 119 | { (ASN_TAG_CLASS_UNIVERSAL | (3 << 2)), 2, 0, 0 }, /* signature at 18 */ |
| 120 | { (ASN_TAG_CLASS_UNIVERSAL | (6 << 2)), 1, 0, 0 }, /* algorithm at 16 */ |
| 121 | { (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)), 0, 0, 0 }, /* toBeSigned at 21 */ |
| 122 | }; |
| 123 | static asn1_SEQUENCE_specifics_t asn1_DEF_Certificate_specs = { |
| 124 | sizeof(struct Certificate), |
| 125 | offsetof(struct Certificate, _ber_dec_ctx), |
| 126 | asn1_DEF_Certificate_tag2el, |
| 127 | 3, /* Count of tags in the map */ |
| 128 | -1, /* Start extensions */ |
| 129 | -1 /* Stop extensions */ |
| 130 | }; |
| 131 | asn1_TYPE_descriptor_t asn1_DEF_Certificate = { |
| 132 | "Certificate", |
| 133 | SEQUENCE_constraint, |
| 134 | SEQUENCE_decode_ber, |
| 135 | SEQUENCE_encode_der, |
| 136 | SEQUENCE_print, |
| 137 | SEQUENCE_free, |
| 138 | 0, /* Use generic outmost tag fetcher */ |
| 139 | asn1_DEF_Certificate_tags, |
| 140 | sizeof(asn1_DEF_Certificate_tags) |
| 141 | /sizeof(asn1_DEF_Certificate_tags[0]), /* 1 */ |
| 142 | 1, /* Tags to skip */ |
| 143 | 1, /* Whether CONSTRUCTED */ |
| 144 | asn1_MBR_Certificate, |
| 145 | 3, /* Elements count */ |
| 146 | &asn1_DEF_Certificate_specs /* Additional specs */ |
| 147 | }; |
| 148 | |
| 149 | |
| 150 | /*** <<< INCLUDES [Name] >>> ***/ |
| 151 | |
| 152 | #include <RelativeDistinguishedName.h> |
| 153 | #include <asn_SEQUENCE_OF.h> |
| 154 | #include <constr_SEQUENCE_OF.h> |
| 155 | |
| 156 | /*** <<< DEPS [Name] >>> ***/ |
| 157 | |
| 158 | extern asn1_TYPE_descriptor_t asn1_DEF_Name; |
| 159 | |
| 160 | /*** <<< TYPE-DECLS [Name] >>> ***/ |
| 161 | |
| 162 | |
| 163 | typedef struct Name { |
| 164 | A_SEQUENCE_OF(struct RelativeDistinguishedName) list; |
| 165 | |
| 166 | /* Context for parsing across buffer boundaries */ |
| 167 | ber_dec_ctx_t _ber_dec_ctx; |
| 168 | } Name_t; |
| 169 | |
| 170 | /*** <<< STAT-DEFS [Name] >>> ***/ |
| 171 | |
| 172 | static asn1_TYPE_member_t asn1_MBR_Name[] = { |
| 173 | { 0, 0, |
| 174 | .tag = (ASN_TAG_CLASS_UNIVERSAL | (17 << 2)), |
| 175 | .tag_mode = 0, |
| 176 | .type = (void *)&asn1_DEF_RelativeDistinguishedName, |
| 177 | .memb_constraints = 0, /* Defer to actual type */ |
| 178 | .name = "" |
| 179 | }, |
| 180 | }; |
| 181 | static ber_tlv_tag_t asn1_DEF_Name_tags[] = { |
| 182 | (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) |
| 183 | }; |
| 184 | static asn1_SET_OF_specifics_t asn1_DEF_Name_specs = { |
| 185 | sizeof(struct Name), |
| 186 | offsetof(struct Name, _ber_dec_ctx), |
| 187 | }; |
| 188 | asn1_TYPE_descriptor_t asn1_DEF_Name = { |
| 189 | "Name", |
| 190 | SEQUENCE_OF_constraint, |
| 191 | SEQUENCE_OF_decode_ber, |
| 192 | SEQUENCE_OF_encode_der, |
| 193 | SEQUENCE_OF_print, |
| 194 | SEQUENCE_OF_free, |
| 195 | 0, /* Use generic outmost tag fetcher */ |
| 196 | asn1_DEF_Name_tags, |
| 197 | sizeof(asn1_DEF_Name_tags) |
| 198 | /sizeof(asn1_DEF_Name_tags[0]), /* 1 */ |
| 199 | 1, /* Tags to skip */ |
| 200 | 1, /* Whether CONSTRUCTED */ |
| 201 | asn1_MBR_Name, |
| 202 | 1, /* Single element */ |
| 203 | &asn1_DEF_Name_specs /* Additional specs */ |
| 204 | }; |
| 205 | |
| 206 | |
| 207 | /*** <<< INCLUDES [RelativeDistinguishedName] >>> ***/ |
| 208 | |
| 209 | #include <IA5String.h> |
| 210 | #include <asn_SET_OF.h> |
| 211 | #include <constr_SET_OF.h> |
| 212 | |
| 213 | /*** <<< DEPS [RelativeDistinguishedName] >>> ***/ |
| 214 | |
| 215 | extern asn1_TYPE_descriptor_t asn1_DEF_RelativeDistinguishedName; |
| 216 | |
| 217 | /*** <<< TYPE-DECLS [RelativeDistinguishedName] >>> ***/ |
| 218 | |
| 219 | |
| 220 | typedef struct RelativeDistinguishedName { |
| 221 | A_SET_OF(IA5String_t) list; |
| 222 | |
| 223 | /* Context for parsing across buffer boundaries */ |
| 224 | ber_dec_ctx_t _ber_dec_ctx; |
| 225 | } RelativeDistinguishedName_t; |
| 226 | |
| 227 | /*** <<< CTABLES [RelativeDistinguishedName] >>> ***/ |
| 228 | |
| 229 | static int permitted_alphabet_table_1[256] = { |
| 230 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* */ |
| 231 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* */ |
| 232 | 0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0, /* ,-. */ |
| 233 | 1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0, /* 0 9 */ |
| 234 | 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* ABCDEFGHIJKLMNO */ |
| 235 | 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, /* PQRSTUVWXYZ */ |
| 236 | 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* abcdefghijklmno */ |
| 237 | 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, /* pqrstuvwxyz */ |
| 238 | }; |
| 239 | |
| 240 | static int check_permitted_alphabet_1(const void *sptr) { |
| 241 | int *table = permitted_alphabet_table_1; |
| 242 | /* The underlying type is IA5String */ |
Lev Walkin | d1e5494 | 2004-08-21 07:34:17 +0000 | [diff] [blame] | 243 | const IA5String_t *st = sptr; |
Lev Walkin | a09e5da | 2004-08-22 03:19:00 +0000 | [diff] [blame] | 244 | const uint8_t *ch = st->buf; |
| 245 | const uint8_t *end = ch + st->size; |
Lev Walkin | 006de1c | 2004-08-20 13:37:45 +0000 | [diff] [blame] | 246 | |
| 247 | for(; ch < end; ch++) { |
| 248 | uint8_t cv = *ch; |
Lev Walkin | 775885e | 2004-08-22 12:47:03 +0000 | [diff] [blame^] | 249 | if(!table[cv]) return -1; |
Lev Walkin | 006de1c | 2004-08-20 13:37:45 +0000 | [diff] [blame] | 250 | } |
Lev Walkin | 775885e | 2004-08-22 12:47:03 +0000 | [diff] [blame^] | 251 | return 0; |
Lev Walkin | 006de1c | 2004-08-20 13:37:45 +0000 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | |
| 255 | /*** <<< CODE [RelativeDistinguishedName] >>> ***/ |
| 256 | |
| 257 | static int |
Lev Walkin | a09e5da | 2004-08-22 03:19:00 +0000 | [diff] [blame] | 258 | memb_IA5String_1_constraint(asn1_TYPE_descriptor_t *td, const void *sptr, |
Lev Walkin | 006de1c | 2004-08-20 13:37:45 +0000 | [diff] [blame] | 259 | asn_app_consume_bytes_f *app_errlog, void *app_key) { |
Lev Walkin | a09e5da | 2004-08-22 03:19:00 +0000 | [diff] [blame] | 260 | const IA5String_t *st = sptr; |
Lev Walkin | 006de1c | 2004-08-20 13:37:45 +0000 | [diff] [blame] | 261 | |
| 262 | if(!sptr) { |
| 263 | _ASN_ERRLOG(app_errlog, app_key, |
| 264 | "%s: value not given", td->name); |
| 265 | return -1; |
| 266 | } |
| 267 | |
| 268 | |
| 269 | if(check_permitted_alphabet_1(sptr)) { |
| 270 | /* Constraint check succeeded */ |
Lev Walkin | 775885e | 2004-08-22 12:47:03 +0000 | [diff] [blame^] | 271 | return 0; |
Lev Walkin | 006de1c | 2004-08-20 13:37:45 +0000 | [diff] [blame] | 272 | } else { |
| 273 | _ASN_ERRLOG(app_errlog, app_key, |
| 274 | "%s: constraint failed", td->name); |
| 275 | return -1; |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | |
| 280 | /*** <<< STAT-DEFS [RelativeDistinguishedName] >>> ***/ |
| 281 | |
| 282 | static asn1_TYPE_member_t asn1_MBR_RelativeDistinguishedName[] = { |
| 283 | { 0, 0, |
| 284 | .tag = (ASN_TAG_CLASS_UNIVERSAL | (22 << 2)), |
| 285 | .tag_mode = 0, |
| 286 | .type = (void *)&asn1_DEF_IA5String, |
Lev Walkin | a09e5da | 2004-08-22 03:19:00 +0000 | [diff] [blame] | 287 | .memb_constraints = memb_IA5String_1_constraint, |
Lev Walkin | 006de1c | 2004-08-20 13:37:45 +0000 | [diff] [blame] | 288 | .name = "" |
| 289 | }, |
| 290 | }; |
| 291 | static ber_tlv_tag_t asn1_DEF_RelativeDistinguishedName_tags[] = { |
| 292 | (ASN_TAG_CLASS_UNIVERSAL | (17 << 2)) |
| 293 | }; |
| 294 | static asn1_SET_OF_specifics_t asn1_DEF_RelativeDistinguishedName_specs = { |
| 295 | sizeof(struct RelativeDistinguishedName), |
| 296 | offsetof(struct RelativeDistinguishedName, _ber_dec_ctx), |
| 297 | }; |
| 298 | asn1_TYPE_descriptor_t asn1_DEF_RelativeDistinguishedName = { |
| 299 | "RelativeDistinguishedName", |
| 300 | SET_OF_constraint, |
| 301 | SET_OF_decode_ber, |
| 302 | SET_OF_encode_der, |
| 303 | SET_OF_print, |
| 304 | SET_OF_free, |
| 305 | 0, /* Use generic outmost tag fetcher */ |
| 306 | asn1_DEF_RelativeDistinguishedName_tags, |
| 307 | sizeof(asn1_DEF_RelativeDistinguishedName_tags) |
| 308 | /sizeof(asn1_DEF_RelativeDistinguishedName_tags[0]), /* 1 */ |
| 309 | 1, /* Tags to skip */ |
| 310 | 1, /* Whether CONSTRUCTED */ |
| 311 | asn1_MBR_RelativeDistinguishedName, |
| 312 | 1, /* Single element */ |
| 313 | &asn1_DEF_RelativeDistinguishedName_specs /* Additional specs */ |
| 314 | }; |
| 315 | |