diff options
| author | jsing <> | 2014-04-19 10:54:26 +0000 |
|---|---|---|
| committer | jsing <> | 2014-04-19 10:54:26 +0000 |
| commit | 8d4d96cab2825d9fa38670dff817d2e68c7c19b6 (patch) | |
| tree | 24d09976bf238ec468bfeede0dda2a22cf15c427 /src/lib/libcrypto/asn1/asn1_gen.c | |
| parent | 477ba749eb2f6a85489fad91d659947091401217 (diff) | |
| download | openbsd-8d4d96cab2825d9fa38670dff817d2e68c7c19b6.tar.gz openbsd-8d4d96cab2825d9fa38670dff817d2e68c7c19b6.tar.bz2 openbsd-8d4d96cab2825d9fa38670dff817d2e68c7c19b6.zip | |
More KNF.
Diffstat (limited to 'src/lib/libcrypto/asn1/asn1_gen.c')
| -rw-r--r-- | src/lib/libcrypto/asn1/asn1_gen.c | 193 |
1 files changed, 98 insertions, 95 deletions
diff --git a/src/lib/libcrypto/asn1/asn1_gen.c b/src/lib/libcrypto/asn1/asn1_gen.c index 314df379f9..c66bea2ab4 100644 --- a/src/lib/libcrypto/asn1/asn1_gen.c +++ b/src/lib/libcrypto/asn1/asn1_gen.c | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | * are met: | 10 | * are met: |
| 11 | * | 11 | * |
| 12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * | 14 | * |
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer in | 16 | * notice, this list of conditions and the following disclaimer in |
| @@ -85,16 +85,13 @@ | |||
| 85 | /* List of bits */ | 85 | /* List of bits */ |
| 86 | #define ASN1_GEN_FORMAT_BITLIST 4 | 86 | #define ASN1_GEN_FORMAT_BITLIST 4 |
| 87 | 87 | ||
| 88 | 88 | struct tag_name_st { | |
| 89 | struct tag_name_st | ||
| 90 | { | ||
| 91 | const char *strnam; | 89 | const char *strnam; |
| 92 | int len; | 90 | int len; |
| 93 | int tag; | 91 | int tag; |
| 94 | }; | 92 | }; |
| 95 | 93 | ||
| 96 | typedef struct | 94 | typedef struct { |
| 97 | { | ||
| 98 | int exp_tag; | 95 | int exp_tag; |
| 99 | int exp_class; | 96 | int exp_class; |
| 100 | int exp_constructed; | 97 | int exp_constructed; |
| @@ -102,8 +99,7 @@ typedef struct | |||
| 102 | long exp_len; | 99 | long exp_len; |
| 103 | } tag_exp_type; | 100 | } tag_exp_type; |
| 104 | 101 | ||
| 105 | typedef struct | 102 | typedef struct { |
| 106 | { | ||
| 107 | int imp_tag; | 103 | int imp_tag; |
| 108 | int imp_class; | 104 | int imp_class; |
| 109 | int utype; | 105 | int utype; |
| @@ -115,13 +111,15 @@ typedef struct | |||
| 115 | 111 | ||
| 116 | static int bitstr_cb(const char *elem, int len, void *bitstr); | 112 | static int bitstr_cb(const char *elem, int len, void *bitstr); |
| 117 | static int asn1_cb(const char *elem, int len, void *bitstr); | 113 | static int asn1_cb(const char *elem, int len, void *bitstr); |
| 118 | static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_constructed, int exp_pad, int imp_ok); | 114 | static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, |
| 115 | int exp_constructed, int exp_pad, int imp_ok); | ||
| 119 | static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass); | 116 | static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass); |
| 120 | static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf); | 117 | static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf); |
| 121 | static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype); | 118 | static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype); |
| 122 | static int asn1_str2tag(const char *tagstr, int len); | 119 | static int asn1_str2tag(const char *tagstr, int len); |
| 123 | 120 | ||
| 124 | ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf) | 121 | ASN1_TYPE * |
| 122 | ASN1_generate_nconf(char *str, CONF *nconf) | ||
| 125 | { | 123 | { |
| 126 | X509V3_CTX cnf; | 124 | X509V3_CTX cnf; |
| 127 | 125 | ||
| @@ -132,7 +130,8 @@ ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf) | |||
| 132 | return ASN1_generate_v3(str, &cnf); | 130 | return ASN1_generate_v3(str, &cnf); |
| 133 | } | 131 | } |
| 134 | 132 | ||
| 135 | ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | 133 | ASN1_TYPE * |
| 134 | ASN1_generate_v3(char *str, X509V3_CTX *cnf) | ||
| 136 | { | 135 | { |
| 137 | ASN1_TYPE *ret; | 136 | ASN1_TYPE *ret; |
| 138 | tag_exp_arg asn1_tags; | 137 | tag_exp_arg asn1_tags; |
| @@ -156,15 +155,17 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | |||
| 156 | if (CONF_parse_list(str, ',', 1, asn1_cb, &asn1_tags) != 0) | 155 | if (CONF_parse_list(str, ',', 1, asn1_cb, &asn1_tags) != 0) |
| 157 | return NULL; | 156 | return NULL; |
| 158 | 157 | ||
| 159 | if ((asn1_tags.utype == V_ASN1_SEQUENCE) || (asn1_tags.utype == V_ASN1_SET)) { | 158 | if ((asn1_tags.utype == V_ASN1_SEQUENCE) || |
| 159 | (asn1_tags.utype == V_ASN1_SET)) { | ||
| 160 | if (!cnf) { | 160 | if (!cnf) { |
| 161 | ASN1err(ASN1_F_ASN1_GENERATE_V3, ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG); | 161 | ASN1err(ASN1_F_ASN1_GENERATE_V3, |
| 162 | ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG); | ||
| 162 | return NULL; | 163 | return NULL; |
| 163 | } | 164 | } |
| 164 | ret = asn1_multi(asn1_tags.utype, asn1_tags.str, cnf); | 165 | ret = asn1_multi(asn1_tags.utype, asn1_tags.str, cnf); |
| 165 | } | 166 | } else |
| 166 | else | 167 | ret = asn1_str2type(asn1_tags.str, asn1_tags.format, |
| 167 | ret = asn1_str2type(asn1_tags.str, asn1_tags.format, asn1_tags.utype); | 168 | asn1_tags.utype); |
| 168 | 169 | ||
| 169 | if (!ret) | 170 | if (!ret) |
| 170 | return NULL; | 171 | return NULL; |
| @@ -184,7 +185,8 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | |||
| 184 | if (asn1_tags.imp_tag != -1) { | 185 | if (asn1_tags.imp_tag != -1) { |
| 185 | /* If IMPLICIT we will replace the underlying tag */ | 186 | /* If IMPLICIT we will replace the underlying tag */ |
| 186 | /* Skip existing tag+len */ | 187 | /* Skip existing tag+len */ |
| 187 | r = ASN1_get_object(&cpy_start, &hdr_len, &hdr_tag, &hdr_class, cpy_len); | 188 | r = ASN1_get_object(&cpy_start, &hdr_len, &hdr_tag, |
| 189 | &hdr_class, cpy_len); | ||
| 188 | if (r & 0x80) | 190 | if (r & 0x80) |
| 189 | goto err; | 191 | goto err; |
| 190 | /* Update copy length */ | 192 | /* Update copy length */ |
| @@ -197,21 +199,20 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | |||
| 197 | /* Indefinite length constructed */ | 199 | /* Indefinite length constructed */ |
| 198 | hdr_constructed = 2; | 200 | hdr_constructed = 2; |
| 199 | hdr_len = 0; | 201 | hdr_len = 0; |
| 200 | } | 202 | } else |
| 201 | else | ||
| 202 | /* Just retain constructed flag */ | 203 | /* Just retain constructed flag */ |
| 203 | hdr_constructed = r & V_ASN1_CONSTRUCTED; | 204 | hdr_constructed = r & V_ASN1_CONSTRUCTED; |
| 204 | /* Work out new length with IMPLICIT tag: ignore constructed | 205 | /* Work out new length with IMPLICIT tag: ignore constructed |
| 205 | * because it will mess up if indefinite length | 206 | * because it will mess up if indefinite length |
| 206 | */ | 207 | */ |
| 207 | len = ASN1_object_size(0, hdr_len, asn1_tags.imp_tag); | 208 | len = ASN1_object_size(0, hdr_len, asn1_tags.imp_tag); |
| 208 | } | 209 | } else |
| 209 | else | ||
| 210 | len = cpy_len; | 210 | len = cpy_len; |
| 211 | 211 | ||
| 212 | /* Work out length in any EXPLICIT, starting from end */ | 212 | /* Work out length in any EXPLICIT, starting from end */ |
| 213 | 213 | ||
| 214 | for(i = 0, etmp = asn1_tags.exp_list + asn1_tags.exp_count - 1; i < asn1_tags.exp_count; i++, etmp--) { | 214 | for (i = 0, etmp = asn1_tags.exp_list + asn1_tags.exp_count - 1; |
| 215 | i < asn1_tags.exp_count; i++, etmp--) { | ||
| 215 | /* Content length: number of content octets + any padding */ | 216 | /* Content length: number of content octets + any padding */ |
| 216 | len += etmp->exp_pad; | 217 | len += etmp->exp_pad; |
| 217 | etmp->exp_len = len; | 218 | etmp->exp_len = len; |
| @@ -226,14 +227,13 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | |||
| 226 | goto err; | 227 | goto err; |
| 227 | 228 | ||
| 228 | /* Generate tagged encoding */ | 229 | /* Generate tagged encoding */ |
| 229 | |||
| 230 | p = new_der; | 230 | p = new_der; |
| 231 | 231 | ||
| 232 | /* Output explicit tags first */ | 232 | /* Output explicit tags first */ |
| 233 | 233 | for (i = 0, etmp = asn1_tags.exp_list; i < asn1_tags.exp_count; | |
| 234 | for (i = 0, etmp = asn1_tags.exp_list; i < asn1_tags.exp_count; i++, etmp++) { | 234 | i++, etmp++) { |
| 235 | ASN1_put_object(&p, etmp->exp_constructed, etmp->exp_len, | 235 | ASN1_put_object(&p, etmp->exp_constructed, etmp->exp_len, |
| 236 | etmp->exp_tag, etmp->exp_class); | 236 | etmp->exp_tag, etmp->exp_class); |
| 237 | if (etmp->exp_pad) | 237 | if (etmp->exp_pad) |
| 238 | *p++ = 0; | 238 | *p++ = 0; |
| 239 | } | 239 | } |
| @@ -241,12 +241,12 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | |||
| 241 | /* If IMPLICIT, output tag */ | 241 | /* If IMPLICIT, output tag */ |
| 242 | 242 | ||
| 243 | if (asn1_tags.imp_tag != -1) { | 243 | if (asn1_tags.imp_tag != -1) { |
| 244 | if (asn1_tags.imp_class == V_ASN1_UNIVERSAL | 244 | if (asn1_tags.imp_class == V_ASN1_UNIVERSAL && |
| 245 | && (asn1_tags.imp_tag == V_ASN1_SEQUENCE | 245 | (asn1_tags.imp_tag == V_ASN1_SEQUENCE || |
| 246 | || asn1_tags.imp_tag == V_ASN1_SET) ) | 246 | asn1_tags.imp_tag == V_ASN1_SET)) |
| 247 | hdr_constructed = V_ASN1_CONSTRUCTED; | 247 | hdr_constructed = V_ASN1_CONSTRUCTED; |
| 248 | ASN1_put_object(&p, hdr_constructed, hdr_len, | 248 | ASN1_put_object(&p, hdr_constructed, hdr_len, |
| 249 | asn1_tags.imp_tag, asn1_tags.imp_class); | 249 | asn1_tags.imp_tag, asn1_tags.imp_class); |
| 250 | } | 250 | } |
| 251 | 251 | ||
| 252 | /* Copy across original encoding */ | 252 | /* Copy across original encoding */ |
| @@ -257,17 +257,17 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | |||
| 257 | /* Obtain new ASN1_TYPE structure */ | 257 | /* Obtain new ASN1_TYPE structure */ |
| 258 | ret = d2i_ASN1_TYPE(NULL, &cp, len); | 258 | ret = d2i_ASN1_TYPE(NULL, &cp, len); |
| 259 | 259 | ||
| 260 | err: | 260 | err: |
| 261 | if (orig_der) | 261 | if (orig_der) |
| 262 | free(orig_der); | 262 | free(orig_der); |
| 263 | if (new_der) | 263 | if (new_der) |
| 264 | free(new_der); | 264 | free(new_der); |
| 265 | 265 | ||
| 266 | return ret; | 266 | return ret; |
| 267 | |||
| 268 | } | 267 | } |
| 269 | 268 | ||
| 270 | static int asn1_cb(const char *elem, int len, void *bitstr) | 269 | static int |
| 270 | asn1_cb(const char *elem, int len, void *bitstr) | ||
| 271 | { | 271 | { |
| 272 | tag_exp_arg *arg = bitstr; | 272 | tag_exp_arg *arg = bitstr; |
| 273 | int i; | 273 | int i; |
| @@ -277,7 +277,7 @@ static int asn1_cb(const char *elem, int len, void *bitstr) | |||
| 277 | 277 | ||
| 278 | int tmp_tag, tmp_class; | 278 | int tmp_tag, tmp_class; |
| 279 | 279 | ||
| 280 | for(i = 0, p = elem; i < len; p++, i++) { | 280 | for (i = 0, p = elem; i < len; p++, i++) { |
| 281 | /* Look for the ':' in name value pairs */ | 281 | /* Look for the ':' in name value pairs */ |
| 282 | if (*p == ':') { | 282 | if (*p == ':') { |
| 283 | vstart = p + 1; | 283 | vstart = p + 1; |
| @@ -307,7 +307,7 @@ static int asn1_cb(const char *elem, int len, void *bitstr) | |||
| 307 | return 0; | 307 | return 0; |
| 308 | } | 308 | } |
| 309 | 309 | ||
| 310 | switch(utype) { | 310 | switch (utype) { |
| 311 | 311 | ||
| 312 | case ASN1_GEN_FLAG_IMP: | 312 | case ASN1_GEN_FLAG_IMP: |
| 313 | /* Check for illegal multiple IMPLICIT tagging */ | 313 | /* Check for illegal multiple IMPLICIT tagging */ |
| @@ -315,12 +315,12 @@ static int asn1_cb(const char *elem, int len, void *bitstr) | |||
| 315 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_ILLEGAL_NESTED_TAGGING); | 315 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_ILLEGAL_NESTED_TAGGING); |
| 316 | return -1; | 316 | return -1; |
| 317 | } | 317 | } |
| 318 | if (!parse_tagging(vstart, vlen, &arg->imp_tag, &arg->imp_class)) | 318 | if (!parse_tagging(vstart, vlen, &arg->imp_tag, |
| 319 | &arg->imp_class)) | ||
| 319 | return -1; | 320 | return -1; |
| 320 | break; | 321 | break; |
| 321 | 322 | ||
| 322 | case ASN1_GEN_FLAG_EXP: | 323 | case ASN1_GEN_FLAG_EXP: |
| 323 | |||
| 324 | if (!parse_tagging(vstart, vlen, &tmp_tag, &tmp_class)) | 324 | if (!parse_tagging(vstart, vlen, &tmp_tag, &tmp_class)) |
| 325 | return -1; | 325 | return -1; |
| 326 | if (!append_exp(arg, tmp_tag, tmp_class, 1, 0, 0)) | 326 | if (!append_exp(arg, tmp_tag, tmp_class, 1, 0, 0)) |
| @@ -365,14 +365,15 @@ static int asn1_cb(const char *elem, int len, void *bitstr) | |||
| 365 | } | 365 | } |
| 366 | 366 | ||
| 367 | return 1; | 367 | return 1; |
| 368 | |||
| 369 | } | 368 | } |
| 370 | 369 | ||
| 371 | static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass) | 370 | static int |
| 371 | parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass) | ||
| 372 | { | 372 | { |
| 373 | char erch[2]; | 373 | char erch[2]; |
| 374 | long tag_num; | 374 | long tag_num; |
| 375 | char *eptr; | 375 | char *eptr; |
| 376 | |||
| 376 | if (!vstart) | 377 | if (!vstart) |
| 377 | return 0; | 378 | return 0; |
| 378 | tag_num = strtoul(vstart, &eptr, 10); | 379 | tag_num = strtoul(vstart, &eptr, 10); |
| @@ -387,7 +388,7 @@ static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass) | |||
| 387 | /* If we have non numeric characters, parse them */ | 388 | /* If we have non numeric characters, parse them */ |
| 388 | if (eptr) | 389 | if (eptr) |
| 389 | vlen -= eptr - vstart; | 390 | vlen -= eptr - vstart; |
| 390 | else | 391 | else |
| 391 | vlen = 0; | 392 | vlen = 0; |
| 392 | if (vlen) { | 393 | if (vlen) { |
| 393 | switch (*eptr) { | 394 | switch (*eptr) { |
| @@ -408,7 +409,7 @@ static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass) | |||
| 408 | *pclass = V_ASN1_CONTEXT_SPECIFIC; | 409 | *pclass = V_ASN1_CONTEXT_SPECIFIC; |
| 409 | break; | 410 | break; |
| 410 | 411 | ||
| 411 | default: | 412 | default: |
| 412 | erch[0] = *eptr; | 413 | erch[0] = *eptr; |
| 413 | erch[1] = 0; | 414 | erch[1] = 0; |
| 414 | ASN1err(ASN1_F_PARSE_TAGGING, ASN1_R_INVALID_MODIFIER); | 415 | ASN1err(ASN1_F_PARSE_TAGGING, ASN1_R_INVALID_MODIFIER); |
| @@ -417,8 +418,7 @@ static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass) | |||
| 417 | break; | 418 | break; |
| 418 | 419 | ||
| 419 | } | 420 | } |
| 420 | } | 421 | } else |
| 421 | else | ||
| 422 | *pclass = V_ASN1_CONTEXT_SPECIFIC; | 422 | *pclass = V_ASN1_CONTEXT_SPECIFIC; |
| 423 | 423 | ||
| 424 | return 1; | 424 | return 1; |
| @@ -427,7 +427,8 @@ static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass) | |||
| 427 | 427 | ||
| 428 | /* Handle multiple types: SET and SEQUENCE */ | 428 | /* Handle multiple types: SET and SEQUENCE */ |
| 429 | 429 | ||
| 430 | static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf) | 430 | static ASN1_TYPE * |
| 431 | asn1_multi(int utype, const char *section, X509V3_CTX *cnf) | ||
| 431 | { | 432 | { |
| 432 | ASN1_TYPE *ret = NULL; | 433 | ASN1_TYPE *ret = NULL; |
| 433 | STACK_OF(ASN1_TYPE) *sk = NULL; | 434 | STACK_OF(ASN1_TYPE) *sk = NULL; |
| @@ -445,7 +446,8 @@ static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf) | |||
| 445 | if (!sect) | 446 | if (!sect) |
| 446 | goto bad; | 447 | goto bad; |
| 447 | for (i = 0; i < sk_CONF_VALUE_num(sect); i++) { | 448 | for (i = 0; i < sk_CONF_VALUE_num(sect); i++) { |
| 448 | ASN1_TYPE *typ = ASN1_generate_v3(sk_CONF_VALUE_value(sect, i)->value, cnf); | 449 | ASN1_TYPE *typ = ASN1_generate_v3( |
| 450 | sk_CONF_VALUE_value(sect, i)->value, cnf); | ||
| 449 | if (!typ) | 451 | if (!typ) |
| 450 | goto bad; | 452 | goto bad; |
| 451 | if (!sk_ASN1_TYPE_push(sk, typ)) | 453 | if (!sk_ASN1_TYPE_push(sk, typ)) |
| @@ -476,11 +478,9 @@ static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf) | |||
| 476 | 478 | ||
| 477 | der = NULL; | 479 | der = NULL; |
| 478 | 480 | ||
| 479 | bad: | 481 | bad: |
| 480 | |||
| 481 | if (der) | 482 | if (der) |
| 482 | free(der); | 483 | free(der); |
| 483 | |||
| 484 | if (sk) | 484 | if (sk) |
| 485 | sk_ASN1_TYPE_pop_free(sk, ASN1_TYPE_free); | 485 | sk_ASN1_TYPE_pop_free(sk, ASN1_TYPE_free); |
| 486 | if (sect) | 486 | if (sect) |
| @@ -489,9 +489,12 @@ static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf) | |||
| 489 | return ret; | 489 | return ret; |
| 490 | } | 490 | } |
| 491 | 491 | ||
| 492 | static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_constructed, int exp_pad, int imp_ok) | 492 | static int |
| 493 | append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_constructed, | ||
| 494 | int exp_pad, int imp_ok) | ||
| 493 | { | 495 | { |
| 494 | tag_exp_type *exp_tmp; | 496 | tag_exp_type *exp_tmp; |
| 497 | |||
| 495 | /* Can only have IMPLICIT if permitted */ | 498 | /* Can only have IMPLICIT if permitted */ |
| 496 | if ((arg->imp_tag != -1) && !imp_ok) { | 499 | if ((arg->imp_tag != -1) && !imp_ok) { |
| 497 | ASN1err(ASN1_F_APPEND_EXP, ASN1_R_ILLEGAL_IMPLICIT_TAG); | 500 | ASN1err(ASN1_F_APPEND_EXP, ASN1_R_ILLEGAL_IMPLICIT_TAG); |
| @@ -523,8 +526,8 @@ static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_cons | |||
| 523 | return 1; | 526 | return 1; |
| 524 | } | 527 | } |
| 525 | 528 | ||
| 526 | 529 | static int | |
| 527 | static int asn1_str2tag(const char *tagstr, int len) | 530 | asn1_str2tag(const char *tagstr, int len) |
| 528 | { | 531 | { |
| 529 | unsigned int i; | 532 | unsigned int i; |
| 530 | static const struct tag_name_st *tntmp, tnst [] = { | 533 | static const struct tag_name_st *tntmp, tnst [] = { |
| @@ -586,29 +589,28 @@ static int asn1_str2tag(const char *tagstr, int len) | |||
| 586 | ASN1_GEN_STR("BITWRAP", ASN1_GEN_FLAG_BITWRAP), | 589 | ASN1_GEN_STR("BITWRAP", ASN1_GEN_FLAG_BITWRAP), |
| 587 | ASN1_GEN_STR("FORM", ASN1_GEN_FLAG_FORMAT), | 590 | ASN1_GEN_STR("FORM", ASN1_GEN_FLAG_FORMAT), |
| 588 | ASN1_GEN_STR("FORMAT", ASN1_GEN_FLAG_FORMAT), | 591 | ASN1_GEN_STR("FORMAT", ASN1_GEN_FLAG_FORMAT), |
| 589 | }; | 592 | }; |
| 590 | 593 | ||
| 591 | if (len == -1) | 594 | if (len == -1) |
| 592 | len = strlen(tagstr); | 595 | len = strlen(tagstr); |
| 593 | 596 | ||
| 594 | tntmp = tnst; | 597 | tntmp = tnst; |
| 595 | for (i = 0; i < sizeof(tnst) / sizeof(struct tag_name_st); i++, tntmp++) { | 598 | for (i = 0; i < sizeof(tnst) / sizeof(struct tag_name_st); |
| 599 | i++, tntmp++) { | ||
| 596 | if ((len == tntmp->len) && !strncmp(tntmp->strnam, tagstr, len)) | 600 | if ((len == tntmp->len) && !strncmp(tntmp->strnam, tagstr, len)) |
| 597 | return tntmp->tag; | 601 | return tntmp->tag; |
| 598 | } | 602 | } |
| 599 | 603 | ||
| 600 | return -1; | 604 | return -1; |
| 601 | } | 605 | } |
| 602 | 606 | ||
| 603 | static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | 607 | static ASN1_TYPE * |
| 608 | asn1_str2type(const char *str, int format, int utype) | ||
| 604 | { | 609 | { |
| 605 | ASN1_TYPE *atmp = NULL; | 610 | ASN1_TYPE *atmp = NULL; |
| 606 | |||
| 607 | CONF_VALUE vtmp; | 611 | CONF_VALUE vtmp; |
| 608 | |||
| 609 | unsigned char *rdata; | 612 | unsigned char *rdata; |
| 610 | long rdlen; | 613 | long rdlen; |
| 611 | |||
| 612 | int no_unused = 1; | 614 | int no_unused = 1; |
| 613 | 615 | ||
| 614 | if (!(atmp = ASN1_TYPE_new())) { | 616 | if (!(atmp = ASN1_TYPE_new())) { |
| @@ -619,15 +621,16 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | |||
| 619 | if (!str) | 621 | if (!str) |
| 620 | str = ""; | 622 | str = ""; |
| 621 | 623 | ||
| 622 | switch(utype) { | 624 | switch (utype) { |
| 623 | 625 | ||
| 624 | case V_ASN1_NULL: | 626 | case V_ASN1_NULL: |
| 625 | if (str && *str) { | 627 | if (str && *str) { |
| 626 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_NULL_VALUE); | 628 | ASN1err(ASN1_F_ASN1_STR2TYPE, |
| 629 | ASN1_R_ILLEGAL_NULL_VALUE); | ||
| 627 | goto bad_form; | 630 | goto bad_form; |
| 628 | } | 631 | } |
| 629 | break; | 632 | break; |
| 630 | 633 | ||
| 631 | case V_ASN1_BOOLEAN: | 634 | case V_ASN1_BOOLEAN: |
| 632 | if (format != ASN1_GEN_FORMAT_ASCII) { | 635 | if (format != ASN1_GEN_FORMAT_ASCII) { |
| 633 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_NOT_ASCII_FORMAT); | 636 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_NOT_ASCII_FORMAT); |
| @@ -645,10 +648,12 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | |||
| 645 | case V_ASN1_INTEGER: | 648 | case V_ASN1_INTEGER: |
| 646 | case V_ASN1_ENUMERATED: | 649 | case V_ASN1_ENUMERATED: |
| 647 | if (format != ASN1_GEN_FORMAT_ASCII) { | 650 | if (format != ASN1_GEN_FORMAT_ASCII) { |
| 648 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_INTEGER_NOT_ASCII_FORMAT); | 651 | ASN1err(ASN1_F_ASN1_STR2TYPE, |
| 652 | ASN1_R_INTEGER_NOT_ASCII_FORMAT); | ||
| 649 | goto bad_form; | 653 | goto bad_form; |
| 650 | } | 654 | } |
| 651 | if (!(atmp->value.integer = s2i_ASN1_INTEGER(NULL, (char *)str))) { | 655 | if (!(atmp->value.integer = |
| 656 | s2i_ASN1_INTEGER(NULL, (char *)str))) { | ||
| 652 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_INTEGER); | 657 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_INTEGER); |
| 653 | goto bad_str; | 658 | goto bad_str; |
| 654 | } | 659 | } |
| @@ -656,7 +661,8 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | |||
| 656 | 661 | ||
| 657 | case V_ASN1_OBJECT: | 662 | case V_ASN1_OBJECT: |
| 658 | if (format != ASN1_GEN_FORMAT_ASCII) { | 663 | if (format != ASN1_GEN_FORMAT_ASCII) { |
| 659 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_OBJECT_NOT_ASCII_FORMAT); | 664 | ASN1err(ASN1_F_ASN1_STR2TYPE, |
| 665 | ASN1_R_OBJECT_NOT_ASCII_FORMAT); | ||
| 660 | goto bad_form; | 666 | goto bad_form; |
| 661 | } | 667 | } |
| 662 | if (!(atmp->value.object = OBJ_txt2obj(str, 0))) { | 668 | if (!(atmp->value.object = OBJ_txt2obj(str, 0))) { |
| @@ -668,7 +674,8 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | |||
| 668 | case V_ASN1_UTCTIME: | 674 | case V_ASN1_UTCTIME: |
| 669 | case V_ASN1_GENERALIZEDTIME: | 675 | case V_ASN1_GENERALIZEDTIME: |
| 670 | if (format != ASN1_GEN_FORMAT_ASCII) { | 676 | if (format != ASN1_GEN_FORMAT_ASCII) { |
| 671 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_TIME_NOT_ASCII_FORMAT); | 677 | ASN1err(ASN1_F_ASN1_STR2TYPE, |
| 678 | ASN1_R_TIME_NOT_ASCII_FORMAT); | ||
| 672 | goto bad_form; | 679 | goto bad_form; |
| 673 | } | 680 | } |
| 674 | if (!(atmp->value.asn1_string = ASN1_STRING_new())) { | 681 | if (!(atmp->value.asn1_string = ASN1_STRING_new())) { |
| @@ -681,10 +688,10 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | |||
| 681 | } | 688 | } |
| 682 | atmp->value.asn1_string->type = utype; | 689 | atmp->value.asn1_string->type = utype; |
| 683 | if (!ASN1_TIME_check(atmp->value.asn1_string)) { | 690 | if (!ASN1_TIME_check(atmp->value.asn1_string)) { |
| 684 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_TIME_VALUE); | 691 | ASN1err(ASN1_F_ASN1_STR2TYPE, |
| 692 | ASN1_R_ILLEGAL_TIME_VALUE); | ||
| 685 | goto bad_str; | 693 | goto bad_str; |
| 686 | } | 694 | } |
| 687 | |||
| 688 | break; | 695 | break; |
| 689 | 696 | ||
| 690 | case V_ASN1_BMPSTRING: | 697 | case V_ASN1_BMPSTRING: |
| @@ -706,20 +713,16 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | |||
| 706 | goto bad_form; | 713 | goto bad_form; |
| 707 | } | 714 | } |
| 708 | 715 | ||
| 709 | 716 | if (ASN1_mbstring_copy(&atmp->value.asn1_string, | |
| 710 | if (ASN1_mbstring_copy(&atmp->value.asn1_string, (unsigned char *)str, | 717 | (unsigned char *)str, -1, format, |
| 711 | -1, format, ASN1_tag2bit(utype)) <= 0) { | 718 | ASN1_tag2bit(utype)) <= 0) { |
| 712 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); | 719 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); |
| 713 | goto bad_str; | 720 | goto bad_str; |
| 714 | } | 721 | } |
| 715 | |||
| 716 | |||
| 717 | break; | 722 | break; |
| 718 | 723 | ||
| 719 | case V_ASN1_BIT_STRING: | 724 | case V_ASN1_BIT_STRING: |
| 720 | |||
| 721 | case V_ASN1_OCTET_STRING: | 725 | case V_ASN1_OCTET_STRING: |
| 722 | |||
| 723 | if (!(atmp->value.asn1_string = ASN1_STRING_new())) { | 726 | if (!(atmp->value.asn1_string = ASN1_STRING_new())) { |
| 724 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); | 727 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); |
| 725 | goto bad_form; | 728 | goto bad_form; |
| @@ -728,7 +731,8 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | |||
| 728 | if (format == ASN1_GEN_FORMAT_HEX) { | 731 | if (format == ASN1_GEN_FORMAT_HEX) { |
| 729 | 732 | ||
| 730 | if (!(rdata = string_to_hex((char *)str, &rdlen))) { | 733 | if (!(rdata = string_to_hex((char *)str, &rdlen))) { |
| 731 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_HEX); | 734 | ASN1err(ASN1_F_ASN1_STR2TYPE, |
| 735 | ASN1_R_ILLEGAL_HEX); | ||
| 732 | goto bad_str; | 736 | goto bad_str; |
| 733 | } | 737 | } |
| 734 | 738 | ||
| @@ -736,29 +740,31 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | |||
| 736 | atmp->value.asn1_string->length = rdlen; | 740 | atmp->value.asn1_string->length = rdlen; |
| 737 | atmp->value.asn1_string->type = utype; | 741 | atmp->value.asn1_string->type = utype; |
| 738 | 742 | ||
| 739 | } | 743 | } else if (format == ASN1_GEN_FORMAT_ASCII) |
| 740 | else if (format == ASN1_GEN_FORMAT_ASCII) | ||
| 741 | ASN1_STRING_set(atmp->value.asn1_string, str, -1); | 744 | ASN1_STRING_set(atmp->value.asn1_string, str, -1); |
| 742 | else if ((format == ASN1_GEN_FORMAT_BITLIST) && (utype == V_ASN1_BIT_STRING)) { | 745 | else if ((format == ASN1_GEN_FORMAT_BITLIST) && |
| 743 | if (!CONF_parse_list(str, ',', 1, bitstr_cb, atmp->value.bit_string)) { | 746 | (utype == V_ASN1_BIT_STRING)) { |
| 744 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_LIST_ERROR); | 747 | if (!CONF_parse_list(str, ',', 1, bitstr_cb, |
| 748 | atmp->value.bit_string)) { | ||
| 749 | ASN1err(ASN1_F_ASN1_STR2TYPE, | ||
| 750 | ASN1_R_LIST_ERROR); | ||
| 745 | goto bad_str; | 751 | goto bad_str; |
| 746 | } | 752 | } |
| 747 | no_unused = 0; | 753 | no_unused = 0; |
| 748 | 754 | ||
| 749 | } else { | 755 | } else { |
| 750 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BITSTRING_FORMAT); | 756 | ASN1err(ASN1_F_ASN1_STR2TYPE, |
| 757 | ASN1_R_ILLEGAL_BITSTRING_FORMAT); | ||
| 751 | goto bad_form; | 758 | goto bad_form; |
| 752 | } | 759 | } |
| 753 | 760 | ||
| 754 | if ((utype == V_ASN1_BIT_STRING) && no_unused) { | 761 | if ((utype == V_ASN1_BIT_STRING) && no_unused) { |
| 755 | atmp->value.asn1_string->flags | 762 | atmp->value.asn1_string->flags &= |
| 756 | &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); | 763 | ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); |
| 757 | atmp->value.asn1_string->flags | 764 | atmp->value.asn1_string->flags |= |
| 758 | |= ASN1_STRING_FLAG_BITS_LEFT; | 765 | ASN1_STRING_FLAG_BITS_LEFT; |
| 759 | } | 766 | } |
| 760 | 767 | ||
| 761 | |||
| 762 | break; | 768 | break; |
| 763 | 769 | ||
| 764 | default: | 770 | default: |
| @@ -767,24 +773,22 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | |||
| 767 | break; | 773 | break; |
| 768 | } | 774 | } |
| 769 | 775 | ||
| 770 | |||
| 771 | atmp->type = utype; | 776 | atmp->type = utype; |
| 772 | return atmp; | 777 | return atmp; |
| 773 | 778 | ||
| 774 | |||
| 775 | bad_str: | 779 | bad_str: |
| 776 | ERR_add_error_data(2, "string=", str); | 780 | ERR_add_error_data(2, "string=", str); |
| 777 | bad_form: | 781 | bad_form: |
| 778 | |||
| 779 | ASN1_TYPE_free(atmp); | 782 | ASN1_TYPE_free(atmp); |
| 780 | return NULL; | 783 | return NULL; |
| 781 | |||
| 782 | } | 784 | } |
| 783 | 785 | ||
| 784 | static int bitstr_cb(const char *elem, int len, void *bitstr) | 786 | static int |
| 787 | bitstr_cb(const char *elem, int len, void *bitstr) | ||
| 785 | { | 788 | { |
| 786 | long bitnum; | 789 | long bitnum; |
| 787 | char *eptr; | 790 | char *eptr; |
| 791 | |||
| 788 | if (!elem) | 792 | if (!elem) |
| 789 | return 0; | 793 | return 0; |
| 790 | bitnum = strtoul(elem, &eptr, 10); | 794 | bitnum = strtoul(elem, &eptr, 10); |
| @@ -800,4 +804,3 @@ static int bitstr_cb(const char *elem, int len, void *bitstr) | |||
| 800 | } | 804 | } |
| 801 | return 1; | 805 | return 1; |
| 802 | } | 806 | } |
| 803 | |||
