diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/asn1_par.c')
| -rw-r--r-- | src/lib/libcrypto/asn1/asn1_par.c | 198 |
1 files changed, 114 insertions, 84 deletions
diff --git a/src/lib/libcrypto/asn1/asn1_par.c b/src/lib/libcrypto/asn1/asn1_par.c index 3906227d21..facfdd27fc 100644 --- a/src/lib/libcrypto/asn1/asn1_par.c +++ b/src/lib/libcrypto/asn1/asn1_par.c | |||
| @@ -58,30 +58,21 @@ | |||
| 58 | 58 | ||
| 59 | #include <stdio.h> | 59 | #include <stdio.h> |
| 60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
| 61 | #include "buffer.h" | 61 | #include <openssl/buffer.h> |
| 62 | #include "objects.h" | 62 | #include <openssl/objects.h> |
| 63 | #include "x509.h" | 63 | #include <openssl/asn1.h> |
| 64 | 64 | ||
| 65 | #ifndef NOPROTO | ||
| 66 | static int asn1_print_info(BIO *bp, int tag, int xclass,int constructed, | 65 | static int asn1_print_info(BIO *bp, int tag, int xclass,int constructed, |
| 67 | int indent); | 66 | int indent); |
| 68 | static int asn1_parse2(BIO *bp, unsigned char **pp, long length, | 67 | static int asn1_parse2(BIO *bp, unsigned char **pp, long length, |
| 69 | int offset, int depth, int indent); | 68 | int offset, int depth, int indent, int dump); |
| 70 | #else | 69 | static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed, |
| 71 | static int asn1_print_info(); | 70 | int indent) |
| 72 | static int asn1_parse2(); | ||
| 73 | #endif | ||
| 74 | |||
| 75 | static int asn1_print_info(bp, tag, xclass, constructed,indent) | ||
| 76 | BIO *bp; | ||
| 77 | int tag; | ||
| 78 | int xclass; | ||
| 79 | int constructed; | ||
| 80 | int indent; | ||
| 81 | { | 71 | { |
| 82 | static char *fmt="%-18s"; | 72 | static const char fmt[]="%-18s"; |
| 83 | static char *fmt2="%2d %-15s"; | 73 | static const char fmt2[]="%2d %-15s"; |
| 84 | char *p,str[128],*p2=NULL; | 74 | char str[128]; |
| 75 | const char *p,*p2=NULL; | ||
| 85 | 76 | ||
| 86 | if (constructed & V_ASN1_CONSTRUCTED) | 77 | if (constructed & V_ASN1_CONSTRUCTED) |
| 87 | p="cons: "; | 78 | p="cons: "; |
| @@ -102,53 +93,8 @@ int indent; | |||
| 102 | sprintf(str,"cont [ %d ]",tag); | 93 | sprintf(str,"cont [ %d ]",tag); |
| 103 | else if ((xclass & V_ASN1_APPLICATION) == V_ASN1_APPLICATION) | 94 | else if ((xclass & V_ASN1_APPLICATION) == V_ASN1_APPLICATION) |
| 104 | sprintf(str,"appl [ %d ]",tag); | 95 | sprintf(str,"appl [ %d ]",tag); |
| 105 | else if ((tag == V_ASN1_EOC) /* && (xclass == V_ASN1_UNIVERSAL) */) | 96 | else p = ASN1_tag2str(tag); |
| 106 | p="EOC"; | ||
| 107 | else if (tag == V_ASN1_BOOLEAN) | ||
| 108 | p="BOOLEAN"; | ||
| 109 | else if (tag == V_ASN1_INTEGER) | ||
| 110 | p="INTEGER"; | ||
| 111 | else if (tag == V_ASN1_BIT_STRING) | ||
| 112 | p="BIT STRING"; | ||
| 113 | else if (tag == V_ASN1_OCTET_STRING) | ||
| 114 | p="OCTET STRING"; | ||
| 115 | else if (tag == V_ASN1_NULL) | ||
| 116 | p="NULL"; | ||
| 117 | else if (tag == V_ASN1_OBJECT) | ||
| 118 | p="OBJECT"; | ||
| 119 | else if (tag == V_ASN1_SEQUENCE) | ||
| 120 | p="SEQUENCE"; | ||
| 121 | else if (tag == V_ASN1_SET) | ||
| 122 | p="SET"; | ||
| 123 | else if (tag == V_ASN1_PRINTABLESTRING) | ||
| 124 | p="PRINTABLESTRING"; | ||
| 125 | else if (tag == V_ASN1_T61STRING) | ||
| 126 | p="T61STRING"; | ||
| 127 | else if (tag == V_ASN1_IA5STRING) | ||
| 128 | p="IA5STRING"; | ||
| 129 | else if (tag == V_ASN1_UTCTIME) | ||
| 130 | p="UTCTIME"; | ||
| 131 | 97 | ||
| 132 | /* extras */ | ||
| 133 | else if (tag == V_ASN1_NUMERICSTRING) | ||
| 134 | p="NUMERICSTRING"; | ||
| 135 | else if (tag == V_ASN1_VIDEOTEXSTRING) | ||
| 136 | p="VIDEOTEXSTRING"; | ||
| 137 | else if (tag == V_ASN1_GENERALIZEDTIME) | ||
| 138 | p="GENERALIZEDTIME"; | ||
| 139 | else if (tag == V_ASN1_GRAPHICSTRING) | ||
| 140 | p="GRAPHICSTRING"; | ||
| 141 | else if (tag == V_ASN1_ISO64STRING) | ||
| 142 | p="ISO64STRING"; | ||
| 143 | else if (tag == V_ASN1_GENERALSTRING) | ||
| 144 | p="GENERALSTRING"; | ||
| 145 | else if (tag == V_ASN1_UNIVERSALSTRING) | ||
| 146 | p="UNIVERSALSTRING"; | ||
| 147 | else if (tag == V_ASN1_BMPSTRING) | ||
| 148 | p="BMPSTRING"; | ||
| 149 | else | ||
| 150 | p2="(unknown)"; | ||
| 151 | |||
| 152 | if (p2 != NULL) | 98 | if (p2 != NULL) |
| 153 | { | 99 | { |
| 154 | if (BIO_printf(bp,fmt2,tag,p2) <= 0) goto err; | 100 | if (BIO_printf(bp,fmt2,tag,p2) <= 0) goto err; |
| @@ -162,22 +108,18 @@ err: | |||
| 162 | return(0); | 108 | return(0); |
| 163 | } | 109 | } |
| 164 | 110 | ||
| 165 | int ASN1_parse(bp, pp, len, indent) | 111 | int ASN1_parse(BIO *bp, unsigned char *pp, long len, int indent) |
| 166 | BIO *bp; | 112 | { |
| 167 | unsigned char *pp; | 113 | return(asn1_parse2(bp,&pp,len,0,0,indent,0)); |
| 168 | long len; | 114 | } |
| 169 | int indent; | 115 | |
| 116 | int ASN1_parse_dump(BIO *bp, unsigned char *pp, long len, int indent, int dump) | ||
| 170 | { | 117 | { |
| 171 | return(asn1_parse2(bp,&pp,len,0,0,indent)); | 118 | return(asn1_parse2(bp,&pp,len,0,0,indent,dump)); |
| 172 | } | 119 | } |
| 173 | 120 | ||
| 174 | static int asn1_parse2(bp, pp, length, offset, depth, indent) | 121 | static int asn1_parse2(BIO *bp, unsigned char **pp, long length, int offset, |
| 175 | BIO *bp; | 122 | int depth, int indent, int dump) |
| 176 | unsigned char **pp; | ||
| 177 | long length; | ||
| 178 | int offset; | ||
| 179 | int depth; | ||
| 180 | int indent; | ||
| 181 | { | 123 | { |
| 182 | unsigned char *p,*ep,*tot,*op,*opp; | 124 | unsigned char *p,*ep,*tot,*op,*opp; |
| 183 | long len; | 125 | long len; |
| @@ -186,7 +128,13 @@ int indent; | |||
| 186 | ASN1_OBJECT *o=NULL; | 128 | ASN1_OBJECT *o=NULL; |
| 187 | ASN1_OCTET_STRING *os=NULL; | 129 | ASN1_OCTET_STRING *os=NULL; |
| 188 | /* ASN1_BMPSTRING *bmp=NULL;*/ | 130 | /* ASN1_BMPSTRING *bmp=NULL;*/ |
| 131 | int dump_indent; | ||
| 189 | 132 | ||
| 133 | #if 0 | ||
| 134 | dump_indent = indent; | ||
| 135 | #else | ||
| 136 | dump_indent = 6; /* Because we know BIO_dump_indent() */ | ||
| 137 | #endif | ||
| 190 | p= *pp; | 138 | p= *pp; |
| 191 | tot=p+length; | 139 | tot=p+length; |
| 192 | op=p-1; | 140 | op=p-1; |
| @@ -241,7 +189,7 @@ int indent; | |||
| 241 | { | 189 | { |
| 242 | r=asn1_parse2(bp,&p,(long)(tot-p), | 190 | r=asn1_parse2(bp,&p,(long)(tot-p), |
| 243 | offset+(p - *pp),depth+1, | 191 | offset+(p - *pp),depth+1, |
| 244 | indent); | 192 | indent,dump); |
| 245 | if (r == 0) { ret=0; goto end; } | 193 | if (r == 0) { ret=0; goto end; } |
| 246 | if ((r == 2) || (p >= tot)) break; | 194 | if ((r == 2) || (p >= tot)) break; |
| 247 | } | 195 | } |
| @@ -251,7 +199,7 @@ int indent; | |||
| 251 | { | 199 | { |
| 252 | r=asn1_parse2(bp,&p,(long)len, | 200 | r=asn1_parse2(bp,&p,(long)len, |
| 253 | offset+(p - *pp),depth+1, | 201 | offset+(p - *pp),depth+1, |
| 254 | indent); | 202 | indent,dump); |
| 255 | if (r == 0) { ret=0; goto end; } | 203 | if (r == 0) { ret=0; goto end; } |
| 256 | } | 204 | } |
| 257 | } | 205 | } |
| @@ -266,7 +214,9 @@ int indent; | |||
| 266 | if ( (tag == V_ASN1_PRINTABLESTRING) || | 214 | if ( (tag == V_ASN1_PRINTABLESTRING) || |
| 267 | (tag == V_ASN1_T61STRING) || | 215 | (tag == V_ASN1_T61STRING) || |
| 268 | (tag == V_ASN1_IA5STRING) || | 216 | (tag == V_ASN1_IA5STRING) || |
| 269 | (tag == V_ASN1_UTCTIME)) | 217 | (tag == V_ASN1_VISIBLESTRING) || |
| 218 | (tag == V_ASN1_UTCTIME) || | ||
| 219 | (tag == V_ASN1_GENERALIZEDTIME)) | ||
| 270 | { | 220 | { |
| 271 | if (BIO_write(bp,":",1) <= 0) goto end; | 221 | if (BIO_write(bp,":",1) <= 0) goto end; |
| 272 | if ((len > 0) && | 222 | if ((len > 0) && |
| @@ -334,7 +284,21 @@ int indent; | |||
| 334 | os->length) <= 0) | 284 | os->length) <= 0) |
| 335 | goto end; | 285 | goto end; |
| 336 | } | 286 | } |
| 337 | ASN1_OCTET_STRING_free(os); | 287 | if (!printable && (os->length > 0) |
| 288 | && dump) | ||
| 289 | { | ||
| 290 | if (!nl) | ||
| 291 | { | ||
| 292 | if (BIO_write(bp,"\n",1) <= 0) | ||
| 293 | goto end; | ||
| 294 | } | ||
| 295 | if (BIO_dump_indent(bp,(char *)opp, | ||
| 296 | ((dump == -1 || dump > os->length)?os->length:dump), | ||
| 297 | dump_indent) <= 0) | ||
| 298 | goto end; | ||
| 299 | nl=1; | ||
| 300 | } | ||
| 301 | M_ASN1_OCTET_STRING_free(os); | ||
| 338 | os=NULL; | 302 | os=NULL; |
| 339 | } | 303 | } |
| 340 | } | 304 | } |
| @@ -368,7 +332,52 @@ int indent; | |||
| 368 | if (BIO_write(bp,"BAD INTEGER",11) <= 0) | 332 | if (BIO_write(bp,"BAD INTEGER",11) <= 0) |
| 369 | goto end; | 333 | goto end; |
| 370 | } | 334 | } |
| 371 | ASN1_INTEGER_free(bs); | 335 | M_ASN1_INTEGER_free(bs); |
| 336 | } | ||
| 337 | else if (tag == V_ASN1_ENUMERATED) | ||
| 338 | { | ||
| 339 | ASN1_ENUMERATED *bs; | ||
| 340 | int i; | ||
| 341 | |||
| 342 | opp=op; | ||
| 343 | bs=d2i_ASN1_ENUMERATED(NULL,&opp,len+hl); | ||
| 344 | if (bs != NULL) | ||
| 345 | { | ||
| 346 | if (BIO_write(bp,":",1) <= 0) goto end; | ||
| 347 | if (bs->type == V_ASN1_NEG_ENUMERATED) | ||
| 348 | if (BIO_write(bp,"-",1) <= 0) | ||
| 349 | goto end; | ||
| 350 | for (i=0; i<bs->length; i++) | ||
| 351 | { | ||
| 352 | if (BIO_printf(bp,"%02X", | ||
| 353 | bs->data[i]) <= 0) | ||
| 354 | goto end; | ||
| 355 | } | ||
| 356 | if (bs->length == 0) | ||
| 357 | { | ||
| 358 | if (BIO_write(bp,"00",2) <= 0) | ||
| 359 | goto end; | ||
| 360 | } | ||
| 361 | } | ||
| 362 | else | ||
| 363 | { | ||
| 364 | if (BIO_write(bp,"BAD ENUMERATED",11) <= 0) | ||
| 365 | goto end; | ||
| 366 | } | ||
| 367 | M_ASN1_ENUMERATED_free(bs); | ||
| 368 | } | ||
| 369 | else if (len > 0 && dump) | ||
| 370 | { | ||
| 371 | if (!nl) | ||
| 372 | { | ||
| 373 | if (BIO_write(bp,"\n",1) <= 0) | ||
| 374 | goto end; | ||
| 375 | } | ||
| 376 | if (BIO_dump_indent(bp,(char *)p, | ||
| 377 | ((dump == -1 || dump > len)?len:dump), | ||
| 378 | dump_indent) <= 0) | ||
| 379 | goto end; | ||
| 380 | nl=1; | ||
| 372 | } | 381 | } |
| 373 | 382 | ||
| 374 | if (!nl) | 383 | if (!nl) |
| @@ -387,7 +396,28 @@ int indent; | |||
| 387 | ret=1; | 396 | ret=1; |
| 388 | end: | 397 | end: |
| 389 | if (o != NULL) ASN1_OBJECT_free(o); | 398 | if (o != NULL) ASN1_OBJECT_free(o); |
| 390 | if (os != NULL) ASN1_OCTET_STRING_free(os); | 399 | if (os != NULL) M_ASN1_OCTET_STRING_free(os); |
| 391 | *pp=p; | 400 | *pp=p; |
| 392 | return(ret); | 401 | return(ret); |
| 393 | } | 402 | } |
| 403 | |||
| 404 | const char *ASN1_tag2str(int tag) | ||
| 405 | { | ||
| 406 | const static char *tag2str[] = { | ||
| 407 | "EOC", "BOOLEAN", "INTEGER", "BIT STRING", "OCTET STRING", /* 0-4 */ | ||
| 408 | "NULL", "OBJECT", "OBJECT DESCRIPTOR", "EXTERNAL", "REAL", /* 5-9 */ | ||
| 409 | "ENUMERATED", "<ASN1 11>", "UTF8STRING", "<ASN1 13>", /* 10-13 */ | ||
| 410 | "<ASN1 14>", "<ASN1 15>", "SEQUENCE", "SET", /* 15-17 */ | ||
| 411 | "NUMERICSTRING", "PRINTABLESTRING", "T61STRING", /* 18-20 */ | ||
| 412 | "VIDEOTEXSTRING", "IA5STRING", "UTCTIME","GENERALIZEDTIME", /* 21-24 */ | ||
| 413 | "GRAPHICSTRING", "VISIBLESTRING", "GENERALSTRING", /* 25-27 */ | ||
| 414 | "UNIVERSALSTRING", "<ASN1 29>", "BMPSTRING" /* 28-30 */ | ||
| 415 | }; | ||
| 416 | |||
| 417 | if((tag == V_ASN1_NEG_INTEGER) || (tag == V_ASN1_NEG_ENUMERATED)) | ||
| 418 | tag &= ~0x100; | ||
| 419 | |||
| 420 | if(tag < 0 || tag > 30) return "(unknown)"; | ||
| 421 | return tag2str[tag]; | ||
| 422 | } | ||
| 423 | |||
