diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/asn1_par.c')
-rw-r--r-- | src/lib/libcrypto/asn1/asn1_par.c | 58 |
1 files changed, 17 insertions, 41 deletions
diff --git a/src/lib/libcrypto/asn1/asn1_par.c b/src/lib/libcrypto/asn1/asn1_par.c index 501b62a4b1..676d434f03 100644 --- a/src/lib/libcrypto/asn1/asn1_par.c +++ b/src/lib/libcrypto/asn1/asn1_par.c | |||
@@ -64,7 +64,7 @@ | |||
64 | 64 | ||
65 | 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, |
66 | int indent); | 66 | int indent); |
67 | static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, | 67 | static int asn1_parse2(BIO *bp, unsigned char **pp, long length, |
68 | int offset, int depth, int indent, int dump); | 68 | int offset, int depth, int indent, int dump); |
69 | static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed, | 69 | static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed, |
70 | int indent) | 70 | int indent) |
@@ -88,10 +88,7 @@ static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed, | |||
88 | BIO_snprintf(str,sizeof str,"cont [ %d ]",tag); | 88 | BIO_snprintf(str,sizeof str,"cont [ %d ]",tag); |
89 | else if ((xclass & V_ASN1_APPLICATION) == V_ASN1_APPLICATION) | 89 | else if ((xclass & V_ASN1_APPLICATION) == V_ASN1_APPLICATION) |
90 | BIO_snprintf(str,sizeof str,"appl [ %d ]",tag); | 90 | BIO_snprintf(str,sizeof str,"appl [ %d ]",tag); |
91 | else if (tag > 30) | 91 | else p = ASN1_tag2str(tag); |
92 | BIO_snprintf(str,sizeof str,"<ASN1 %d>",tag); | ||
93 | else | ||
94 | p = ASN1_tag2str(tag); | ||
95 | 92 | ||
96 | if (p2 != NULL) | 93 | if (p2 != NULL) |
97 | { | 94 | { |
@@ -106,20 +103,20 @@ err: | |||
106 | return(0); | 103 | return(0); |
107 | } | 104 | } |
108 | 105 | ||
109 | int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent) | 106 | int ASN1_parse(BIO *bp, unsigned char *pp, long len, int indent) |
110 | { | 107 | { |
111 | return(asn1_parse2(bp,&pp,len,0,0,indent,0)); | 108 | return(asn1_parse2(bp,&pp,len,0,0,indent,0)); |
112 | } | 109 | } |
113 | 110 | ||
114 | int ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent, int dump) | 111 | int ASN1_parse_dump(BIO *bp, unsigned char *pp, long len, int indent, int dump) |
115 | { | 112 | { |
116 | return(asn1_parse2(bp,&pp,len,0,0,indent,dump)); | 113 | return(asn1_parse2(bp,&pp,len,0,0,indent,dump)); |
117 | } | 114 | } |
118 | 115 | ||
119 | static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offset, | 116 | static int asn1_parse2(BIO *bp, unsigned char **pp, long length, int offset, |
120 | int depth, int indent, int dump) | 117 | int depth, int indent, int dump) |
121 | { | 118 | { |
122 | const unsigned char *p,*ep,*tot,*op,*opp; | 119 | unsigned char *p,*ep,*tot,*op,*opp; |
123 | long len; | 120 | long len; |
124 | int tag,xclass,ret=0; | 121 | int tag,xclass,ret=0; |
125 | int nl,hl,j,r; | 122 | int nl,hl,j,r; |
@@ -218,7 +215,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse | |||
218 | { | 215 | { |
219 | if (BIO_write(bp,":",1) <= 0) goto end; | 216 | if (BIO_write(bp,":",1) <= 0) goto end; |
220 | if ((len > 0) && | 217 | if ((len > 0) && |
221 | BIO_write(bp,(const char *)p,(int)len) | 218 | BIO_write(bp,(char *)p,(int)len) |
222 | != (int)len) | 219 | != (int)len) |
223 | goto end; | 220 | goto end; |
224 | } | 221 | } |
@@ -259,11 +256,9 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse | |||
259 | 256 | ||
260 | opp=op; | 257 | opp=op; |
261 | os=d2i_ASN1_OCTET_STRING(NULL,&opp,len+hl); | 258 | os=d2i_ASN1_OCTET_STRING(NULL,&opp,len+hl); |
262 | if (os != NULL && os->length > 0) | 259 | if (os != NULL) |
263 | { | 260 | { |
264 | opp = os->data; | 261 | opp=os->data; |
265 | /* testing whether the octet string is | ||
266 | * printable */ | ||
267 | for (i=0; i<os->length; i++) | 262 | for (i=0; i<os->length; i++) |
268 | { | 263 | { |
269 | if (( (opp[i] < ' ') && | 264 | if (( (opp[i] < ' ') && |
@@ -276,47 +271,28 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse | |||
276 | break; | 271 | break; |
277 | } | 272 | } |
278 | } | 273 | } |
279 | if (printable) | 274 | if (printable && (os->length > 0)) |
280 | /* printable string */ | ||
281 | { | 275 | { |
282 | if (BIO_write(bp,":",1) <= 0) | 276 | if (BIO_write(bp,":",1) <= 0) |
283 | goto end; | 277 | goto end; |
284 | if (BIO_write(bp,(const char *)opp, | 278 | if (BIO_write(bp,(char *)opp, |
285 | os->length) <= 0) | 279 | os->length) <= 0) |
286 | goto end; | 280 | goto end; |
287 | } | 281 | } |
288 | else if (!dump) | 282 | if (!printable && (os->length > 0) |
289 | /* not printable => print octet string | 283 | && dump) |
290 | * as hex dump */ | ||
291 | { | ||
292 | if (BIO_write(bp,"[HEX DUMP]:",11) <= 0) | ||
293 | goto end; | ||
294 | for (i=0; i<os->length; i++) | ||
295 | { | ||
296 | if (BIO_printf(bp,"%02X" | ||
297 | , opp[i]) <= 0) | ||
298 | goto end; | ||
299 | } | ||
300 | } | ||
301 | else | ||
302 | /* print the normal dump */ | ||
303 | { | 284 | { |
304 | if (!nl) | 285 | if (!nl) |
305 | { | 286 | { |
306 | if (BIO_write(bp,"\n",1) <= 0) | 287 | if (BIO_write(bp,"\n",1) <= 0) |
307 | goto end; | 288 | goto end; |
308 | } | 289 | } |
309 | if (BIO_dump_indent(bp, | 290 | if (BIO_dump_indent(bp,(char *)opp, |
310 | (const char *)opp, | 291 | ((dump == -1 || dump > os->length)?os->length:dump), |
311 | ((dump == -1 || dump > | ||
312 | os->length)?os->length:dump), | ||
313 | dump_indent) <= 0) | 292 | dump_indent) <= 0) |
314 | goto end; | 293 | goto end; |
315 | nl=1; | 294 | nl=1; |
316 | } | 295 | } |
317 | } | ||
318 | if (os != NULL) | ||
319 | { | ||
320 | M_ASN1_OCTET_STRING_free(os); | 296 | M_ASN1_OCTET_STRING_free(os); |
321 | os=NULL; | 297 | os=NULL; |
322 | } | 298 | } |
@@ -392,7 +368,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse | |||
392 | if (BIO_write(bp,"\n",1) <= 0) | 368 | if (BIO_write(bp,"\n",1) <= 0) |
393 | goto end; | 369 | goto end; |
394 | } | 370 | } |
395 | if (BIO_dump_indent(bp,(const char *)p, | 371 | if (BIO_dump_indent(bp,(char *)p, |
396 | ((dump == -1 || dump > len)?len:dump), | 372 | ((dump == -1 || dump > len)?len:dump), |
397 | dump_indent) <= 0) | 373 | dump_indent) <= 0) |
398 | goto end; | 374 | goto end; |
@@ -422,7 +398,7 @@ end: | |||
422 | 398 | ||
423 | const char *ASN1_tag2str(int tag) | 399 | const char *ASN1_tag2str(int tag) |
424 | { | 400 | { |
425 | static const char *tag2str[] = { | 401 | const static char *tag2str[] = { |
426 | "EOC", "BOOLEAN", "INTEGER", "BIT STRING", "OCTET STRING", /* 0-4 */ | 402 | "EOC", "BOOLEAN", "INTEGER", "BIT STRING", "OCTET STRING", /* 0-4 */ |
427 | "NULL", "OBJECT", "OBJECT DESCRIPTOR", "EXTERNAL", "REAL", /* 5-9 */ | 403 | "NULL", "OBJECT", "OBJECT DESCRIPTOR", "EXTERNAL", "REAL", /* 5-9 */ |
428 | "ENUMERATED", "<ASN1 11>", "UTF8STRING", "<ASN1 13>", /* 10-13 */ | 404 | "ENUMERATED", "<ASN1 11>", "UTF8STRING", "<ASN1 13>", /* 10-13 */ |