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