diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/asn1_par.c')
-rw-r--r-- | src/lib/libcrypto/asn1/asn1_par.c | 168 |
1 files changed, 84 insertions, 84 deletions
diff --git a/src/lib/libcrypto/asn1/asn1_par.c b/src/lib/libcrypto/asn1/asn1_par.c index e34c75a418..d68d4a8298 100644 --- a/src/lib/libcrypto/asn1/asn1_par.c +++ b/src/lib/libcrypto/asn1/asn1_par.c | |||
@@ -68,7 +68,7 @@ static 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); |
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) |
71 | { | 71 | { |
72 | static const char fmt[]="%-18s"; | 72 | static const char fmt[]="%-18s"; |
73 | char str[128]; | 73 | char str[128]; |
74 | const char *p; | 74 | const char *p; |
@@ -97,21 +97,21 @@ static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed, | |||
97 | return(1); | 97 | return(1); |
98 | err: | 98 | err: |
99 | return(0); | 99 | return(0); |
100 | } | 100 | } |
101 | 101 | ||
102 | int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent) | 102 | int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent) |
103 | { | 103 | { |
104 | return(asn1_parse2(bp,&pp,len,0,0,indent,0)); | 104 | return(asn1_parse2(bp,&pp,len,0,0,indent,0)); |
105 | } | 105 | } |
106 | 106 | ||
107 | int ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent, int dump) | 107 | int ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent, int dump) |
108 | { | 108 | { |
109 | return(asn1_parse2(bp,&pp,len,0,0,indent,dump)); | 109 | return(asn1_parse2(bp,&pp,len,0,0,indent,dump)); |
110 | } | 110 | } |
111 | 111 | ||
112 | static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offset, | 112 | static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offset, |
113 | int depth, int indent, int dump) | 113 | int depth, int indent, int dump) |
114 | { | 114 | { |
115 | const unsigned char *p,*ep,*tot,*op,*opp; | 115 | const unsigned char *p,*ep,*tot,*op,*opp; |
116 | long len; | 116 | long len; |
117 | int tag,xclass,ret=0; | 117 | int tag,xclass,ret=0; |
@@ -130,19 +130,19 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse | |||
130 | tot=p+length; | 130 | tot=p+length; |
131 | op=p-1; | 131 | op=p-1; |
132 | while ((p < tot) && (op < p)) | 132 | while ((p < tot) && (op < p)) |
133 | { | 133 | { |
134 | op=p; | 134 | op=p; |
135 | j=ASN1_get_object(&p,&len,&tag,&xclass,length); | 135 | j=ASN1_get_object(&p,&len,&tag,&xclass,length); |
136 | #ifdef LINT | 136 | #ifdef LINT |
137 | j=j; | 137 | j=j; |
138 | #endif | 138 | #endif |
139 | if (j & 0x80) | 139 | if (j & 0x80) |
140 | { | 140 | { |
141 | if (BIO_write(bp,"Error in encoding\n",18) <= 0) | 141 | if (BIO_write(bp,"Error in encoding\n",18) <= 0) |
142 | goto end; | 142 | goto end; |
143 | ret=0; | 143 | ret=0; |
144 | goto end; | 144 | goto end; |
145 | } | 145 | } |
146 | hl=(p-op); | 146 | hl=(p-op); |
147 | length-=hl; | 147 | length-=hl; |
148 | /* if j == 0x21 it is a constructed indefinite length object */ | 148 | /* if j == 0x21 it is a constructed indefinite length object */ |
@@ -150,57 +150,57 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse | |||
150 | <= 0) goto end; | 150 | <= 0) goto end; |
151 | 151 | ||
152 | if (j != (V_ASN1_CONSTRUCTED | 1)) | 152 | if (j != (V_ASN1_CONSTRUCTED | 1)) |
153 | { | 153 | { |
154 | if (BIO_printf(bp,"d=%-2d hl=%ld l=%4ld ", | 154 | if (BIO_printf(bp,"d=%-2d hl=%ld l=%4ld ", |
155 | depth,(long)hl,len) <= 0) | 155 | depth,(long)hl,len) <= 0) |
156 | goto end; | 156 | goto end; |
157 | } | 157 | } |
158 | else | 158 | else |
159 | { | 159 | { |
160 | if (BIO_printf(bp,"d=%-2d hl=%ld l=inf ", | 160 | if (BIO_printf(bp,"d=%-2d hl=%ld l=inf ", |
161 | depth,(long)hl) <= 0) | 161 | depth,(long)hl) <= 0) |
162 | goto end; | 162 | goto end; |
163 | } | 163 | } |
164 | if (!asn1_print_info(bp,tag,xclass,j,(indent)?depth:0)) | 164 | if (!asn1_print_info(bp,tag,xclass,j,(indent)?depth:0)) |
165 | goto end; | 165 | goto end; |
166 | if (j & V_ASN1_CONSTRUCTED) | 166 | if (j & V_ASN1_CONSTRUCTED) |
167 | { | 167 | { |
168 | ep=p+len; | 168 | ep=p+len; |
169 | if (BIO_write(bp,"\n",1) <= 0) goto end; | 169 | if (BIO_write(bp,"\n",1) <= 0) goto end; |
170 | if (len > length) | 170 | if (len > length) |
171 | { | 171 | { |
172 | BIO_printf(bp, | 172 | BIO_printf(bp, |
173 | "length is greater than %ld\n",length); | 173 | "length is greater than %ld\n",length); |
174 | ret=0; | 174 | ret=0; |
175 | goto end; | 175 | goto end; |
176 | } | 176 | } |
177 | if ((j == 0x21) && (len == 0)) | 177 | if ((j == 0x21) && (len == 0)) |
178 | { | 178 | { |
179 | for (;;) | 179 | for (;;) |
180 | { | 180 | { |
181 | r=asn1_parse2(bp,&p,(long)(tot-p), | 181 | r=asn1_parse2(bp,&p,(long)(tot-p), |
182 | offset+(p - *pp),depth+1, | 182 | offset+(p - *pp),depth+1, |
183 | indent,dump); | 183 | indent,dump); |
184 | if (r == 0) { ret=0; goto end; } | 184 | if (r == 0) { ret=0; goto end; } |
185 | if ((r == 2) || (p >= tot)) break; | 185 | if ((r == 2) || (p >= tot)) break; |
186 | } | ||
187 | } | 186 | } |
187 | } | ||
188 | else | 188 | else |
189 | while (p < ep) | 189 | while (p < ep) |
190 | { | 190 | { |
191 | r=asn1_parse2(bp,&p,(long)len, | 191 | r=asn1_parse2(bp,&p,(long)len, |
192 | offset+(p - *pp),depth+1, | 192 | offset+(p - *pp),depth+1, |
193 | indent,dump); | 193 | indent,dump); |
194 | if (r == 0) { ret=0; goto end; } | 194 | if (r == 0) { ret=0; goto end; } |
195 | } | 195 | } |
196 | } | 196 | } |
197 | else if (xclass != 0) | 197 | else if (xclass != 0) |
198 | { | 198 | { |
199 | p+=len; | 199 | p+=len; |
200 | if (BIO_write(bp,"\n",1) <= 0) goto end; | 200 | if (BIO_write(bp,"\n",1) <= 0) goto end; |
201 | } | 201 | } |
202 | else | 202 | else |
203 | { | 203 | { |
204 | nl=0; | 204 | nl=0; |
205 | if ( (tag == V_ASN1_PRINTABLESTRING) || | 205 | if ( (tag == V_ASN1_PRINTABLESTRING) || |
206 | (tag == V_ASN1_T61STRING) || | 206 | (tag == V_ASN1_T61STRING) || |
@@ -210,97 +210,97 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse | |||
210 | (tag == V_ASN1_UTF8STRING) || | 210 | (tag == V_ASN1_UTF8STRING) || |
211 | (tag == V_ASN1_UTCTIME) || | 211 | (tag == V_ASN1_UTCTIME) || |
212 | (tag == V_ASN1_GENERALIZEDTIME)) | 212 | (tag == V_ASN1_GENERALIZEDTIME)) |
213 | { | 213 | { |
214 | if (BIO_write(bp,":",1) <= 0) goto end; | 214 | if (BIO_write(bp,":",1) <= 0) goto end; |
215 | if ((len > 0) && | 215 | if ((len > 0) && |
216 | BIO_write(bp,(const char *)p,(int)len) | 216 | BIO_write(bp,(const char *)p,(int)len) |
217 | != (int)len) | 217 | != (int)len) |
218 | goto end; | 218 | goto end; |
219 | } | 219 | } |
220 | else if (tag == V_ASN1_OBJECT) | 220 | else if (tag == V_ASN1_OBJECT) |
221 | { | 221 | { |
222 | opp=op; | 222 | opp=op; |
223 | if (d2i_ASN1_OBJECT(&o,&opp,len+hl) != NULL) | 223 | if (d2i_ASN1_OBJECT(&o,&opp,len+hl) != NULL) |
224 | { | 224 | { |
225 | if (BIO_write(bp,":",1) <= 0) goto end; | 225 | if (BIO_write(bp,":",1) <= 0) goto end; |
226 | i2a_ASN1_OBJECT(bp,o); | 226 | i2a_ASN1_OBJECT(bp,o); |
227 | } | 227 | } |
228 | else | 228 | else |
229 | { | 229 | { |
230 | if (BIO_write(bp,":BAD OBJECT",11) <= 0) | 230 | if (BIO_write(bp,":BAD OBJECT",11) <= 0) |
231 | goto end; | 231 | goto end; |
232 | } | ||
233 | } | 232 | } |
233 | } | ||
234 | else if (tag == V_ASN1_BOOLEAN) | 234 | else if (tag == V_ASN1_BOOLEAN) |
235 | { | 235 | { |
236 | int ii; | 236 | int ii; |
237 | 237 | ||
238 | opp=op; | 238 | opp=op; |
239 | ii=d2i_ASN1_BOOLEAN(NULL,&opp,len+hl); | 239 | ii=d2i_ASN1_BOOLEAN(NULL,&opp,len+hl); |
240 | if (ii < 0) | 240 | if (ii < 0) |
241 | { | 241 | { |
242 | if (BIO_write(bp,"Bad boolean\n",12) <= 0) | 242 | if (BIO_write(bp,"Bad boolean\n",12) <= 0) |
243 | goto end; | 243 | goto end; |
244 | } | ||
245 | BIO_printf(bp,":%d",ii); | ||
246 | } | 244 | } |
245 | BIO_printf(bp,":%d",ii); | ||
246 | } | ||
247 | else if (tag == V_ASN1_BMPSTRING) | 247 | else if (tag == V_ASN1_BMPSTRING) |
248 | { | 248 | { |
249 | /* do the BMP thang */ | 249 | /* do the BMP thang */ |
250 | } | 250 | } |
251 | else if (tag == V_ASN1_OCTET_STRING) | 251 | else if (tag == V_ASN1_OCTET_STRING) |
252 | { | 252 | { |
253 | int i,printable=1; | 253 | int i,printable=1; |
254 | 254 | ||
255 | opp=op; | 255 | opp=op; |
256 | os=d2i_ASN1_OCTET_STRING(NULL,&opp,len+hl); | 256 | os=d2i_ASN1_OCTET_STRING(NULL,&opp,len+hl); |
257 | if (os != NULL && os->length > 0) | 257 | if (os != NULL && os->length > 0) |
258 | { | 258 | { |
259 | opp = os->data; | 259 | opp = os->data; |
260 | /* testing whether the octet string is | 260 | /* testing whether the octet string is |
261 | * printable */ | 261 | * printable */ |
262 | for (i=0; i<os->length; i++) | 262 | for (i=0; i<os->length; i++) |
263 | { | 263 | { |
264 | if (( (opp[i] < ' ') && | 264 | if (( (opp[i] < ' ') && |
265 | (opp[i] != '\n') && | 265 | (opp[i] != '\n') && |
266 | (opp[i] != '\r') && | 266 | (opp[i] != '\r') && |
267 | (opp[i] != '\t')) || | 267 | (opp[i] != '\t')) || |
268 | (opp[i] > '~')) | 268 | (opp[i] > '~')) |
269 | { | 269 | { |
270 | printable=0; | 270 | printable=0; |
271 | break; | 271 | break; |
272 | } | ||
273 | } | 272 | } |
273 | } | ||
274 | if (printable) | 274 | if (printable) |
275 | /* printable string */ | 275 | /* printable string */ |
276 | { | 276 | { |
277 | if (BIO_write(bp,":",1) <= 0) | 277 | if (BIO_write(bp,":",1) <= 0) |
278 | goto end; | 278 | goto end; |
279 | if (BIO_write(bp,(const char *)opp, | 279 | if (BIO_write(bp,(const char *)opp, |
280 | os->length) <= 0) | 280 | os->length) <= 0) |
281 | goto end; | 281 | goto end; |
282 | } | 282 | } |
283 | else if (!dump) | 283 | else if (!dump) |
284 | /* not printable => print octet string | 284 | /* not printable => print octet string |
285 | * as hex dump */ | 285 | * as hex dump */ |
286 | { | 286 | { |
287 | if (BIO_write(bp,"[HEX DUMP]:",11) <= 0) | 287 | if (BIO_write(bp,"[HEX DUMP]:",11) <= 0) |
288 | goto end; | 288 | goto end; |
289 | for (i=0; i<os->length; i++) | 289 | for (i=0; i<os->length; i++) |
290 | { | 290 | { |
291 | if (BIO_printf(bp,"%02X" | 291 | if (BIO_printf(bp,"%02X" |
292 | , opp[i]) <= 0) | 292 | , opp[i]) <= 0) |
293 | goto end; | 293 | goto end; |
294 | } | ||
295 | } | 294 | } |
295 | } | ||
296 | else | 296 | else |
297 | /* print the normal dump */ | 297 | /* print the normal dump */ |
298 | { | 298 | { |
299 | if (!nl) | 299 | if (!nl) |
300 | { | 300 | { |
301 | if (BIO_write(bp,"\n",1) <= 0) | 301 | if (BIO_write(bp,"\n",1) <= 0) |
302 | goto end; | 302 | goto end; |
303 | } | 303 | } |
304 | if (BIO_dump_indent(bp, | 304 | if (BIO_dump_indent(bp, |
305 | (const char *)opp, | 305 | (const char *)opp, |
306 | ((dump == -1 || dump > | 306 | ((dump == -1 || dump > |
@@ -308,112 +308,112 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse | |||
308 | dump_indent) <= 0) | 308 | dump_indent) <= 0) |
309 | goto end; | 309 | goto end; |
310 | nl=1; | 310 | nl=1; |
311 | } | ||
312 | } | 311 | } |
312 | } | ||
313 | if (os != NULL) | 313 | if (os != NULL) |
314 | { | 314 | { |
315 | M_ASN1_OCTET_STRING_free(os); | 315 | M_ASN1_OCTET_STRING_free(os); |
316 | os=NULL; | 316 | os=NULL; |
317 | } | ||
318 | } | 317 | } |
318 | } | ||
319 | else if (tag == V_ASN1_INTEGER) | 319 | else if (tag == V_ASN1_INTEGER) |
320 | { | 320 | { |
321 | ASN1_INTEGER *bs; | 321 | ASN1_INTEGER *bs; |
322 | int i; | 322 | int i; |
323 | 323 | ||
324 | opp=op; | 324 | opp=op; |
325 | bs=d2i_ASN1_INTEGER(NULL,&opp,len+hl); | 325 | bs=d2i_ASN1_INTEGER(NULL,&opp,len+hl); |
326 | if (bs != NULL) | 326 | if (bs != NULL) |
327 | { | 327 | { |
328 | if (BIO_write(bp,":",1) <= 0) goto end; | 328 | if (BIO_write(bp,":",1) <= 0) goto end; |
329 | if (bs->type == V_ASN1_NEG_INTEGER) | 329 | if (bs->type == V_ASN1_NEG_INTEGER) |
330 | if (BIO_write(bp,"-",1) <= 0) | 330 | if (BIO_write(bp,"-",1) <= 0) |
331 | goto end; | 331 | goto end; |
332 | for (i=0; i<bs->length; i++) | 332 | for (i=0; i<bs->length; i++) |
333 | { | 333 | { |
334 | if (BIO_printf(bp,"%02X", | 334 | if (BIO_printf(bp,"%02X", |
335 | bs->data[i]) <= 0) | 335 | bs->data[i]) <= 0) |
336 | goto end; | 336 | goto end; |
337 | } | 337 | } |
338 | if (bs->length == 0) | 338 | if (bs->length == 0) |
339 | { | 339 | { |
340 | if (BIO_write(bp,"00",2) <= 0) | 340 | if (BIO_write(bp,"00",2) <= 0) |
341 | goto end; | 341 | goto end; |
342 | } | ||
343 | } | 342 | } |
343 | } | ||
344 | else | 344 | else |
345 | { | 345 | { |
346 | if (BIO_write(bp,"BAD INTEGER",11) <= 0) | 346 | if (BIO_write(bp,"BAD INTEGER",11) <= 0) |
347 | goto end; | 347 | goto end; |
348 | } | ||
349 | M_ASN1_INTEGER_free(bs); | ||
350 | } | 348 | } |
349 | M_ASN1_INTEGER_free(bs); | ||
350 | } | ||
351 | else if (tag == V_ASN1_ENUMERATED) | 351 | else if (tag == V_ASN1_ENUMERATED) |
352 | { | 352 | { |
353 | ASN1_ENUMERATED *bs; | 353 | ASN1_ENUMERATED *bs; |
354 | int i; | 354 | int i; |
355 | 355 | ||
356 | opp=op; | 356 | opp=op; |
357 | bs=d2i_ASN1_ENUMERATED(NULL,&opp,len+hl); | 357 | bs=d2i_ASN1_ENUMERATED(NULL,&opp,len+hl); |
358 | if (bs != NULL) | 358 | if (bs != NULL) |
359 | { | 359 | { |
360 | if (BIO_write(bp,":",1) <= 0) goto end; | 360 | if (BIO_write(bp,":",1) <= 0) goto end; |
361 | if (bs->type == V_ASN1_NEG_ENUMERATED) | 361 | if (bs->type == V_ASN1_NEG_ENUMERATED) |
362 | if (BIO_write(bp,"-",1) <= 0) | 362 | if (BIO_write(bp,"-",1) <= 0) |
363 | goto end; | 363 | goto end; |
364 | for (i=0; i<bs->length; i++) | 364 | for (i=0; i<bs->length; i++) |
365 | { | 365 | { |
366 | if (BIO_printf(bp,"%02X", | 366 | if (BIO_printf(bp,"%02X", |
367 | bs->data[i]) <= 0) | 367 | bs->data[i]) <= 0) |
368 | goto end; | 368 | goto end; |
369 | } | 369 | } |
370 | if (bs->length == 0) | 370 | if (bs->length == 0) |
371 | { | 371 | { |
372 | if (BIO_write(bp,"00",2) <= 0) | 372 | if (BIO_write(bp,"00",2) <= 0) |
373 | goto end; | 373 | goto end; |
374 | } | ||
375 | } | 374 | } |
375 | } | ||
376 | else | 376 | else |
377 | { | 377 | { |
378 | if (BIO_write(bp,"BAD ENUMERATED",14) <= 0) | 378 | if (BIO_write(bp,"BAD ENUMERATED",14) <= 0) |
379 | goto end; | 379 | goto end; |
380 | } | ||
381 | M_ASN1_ENUMERATED_free(bs); | ||
382 | } | 380 | } |
381 | M_ASN1_ENUMERATED_free(bs); | ||
382 | } | ||
383 | else if (len > 0 && dump) | 383 | else if (len > 0 && dump) |
384 | { | 384 | { |
385 | if (!nl) | 385 | if (!nl) |
386 | { | 386 | { |
387 | if (BIO_write(bp,"\n",1) <= 0) | 387 | if (BIO_write(bp,"\n",1) <= 0) |
388 | goto end; | 388 | goto end; |
389 | } | 389 | } |
390 | if (BIO_dump_indent(bp,(const char *)p, | 390 | if (BIO_dump_indent(bp,(const char *)p, |
391 | ((dump == -1 || dump > len)?len:dump), | 391 | ((dump == -1 || dump > len)?len:dump), |
392 | dump_indent) <= 0) | 392 | dump_indent) <= 0) |
393 | goto end; | 393 | goto end; |
394 | nl=1; | 394 | nl=1; |
395 | } | 395 | } |
396 | 396 | ||
397 | if (!nl) | 397 | if (!nl) |
398 | { | 398 | { |
399 | if (BIO_write(bp,"\n",1) <= 0) goto end; | 399 | if (BIO_write(bp,"\n",1) <= 0) goto end; |
400 | } | 400 | } |
401 | p+=len; | 401 | p+=len; |
402 | if ((tag == V_ASN1_EOC) && (xclass == 0)) | 402 | if ((tag == V_ASN1_EOC) && (xclass == 0)) |
403 | { | 403 | { |
404 | ret=2; /* End of sequence */ | 404 | ret=2; /* End of sequence */ |
405 | goto end; | 405 | goto end; |
406 | } | ||
407 | } | 406 | } |
408 | length-=len; | ||
409 | } | 407 | } |
408 | length-=len; | ||
409 | } | ||
410 | ret=1; | 410 | ret=1; |
411 | end: | 411 | end: |
412 | if (o != NULL) ASN1_OBJECT_free(o); | 412 | if (o != NULL) ASN1_OBJECT_free(o); |
413 | if (os != NULL) M_ASN1_OCTET_STRING_free(os); | 413 | if (os != NULL) M_ASN1_OCTET_STRING_free(os); |
414 | *pp=p; | 414 | *pp=p; |
415 | return(ret); | 415 | return(ret); |
416 | } | 416 | } |
417 | 417 | ||
418 | const char *ASN1_tag2str(int tag) | 418 | const char *ASN1_tag2str(int tag) |
419 | { | 419 | { |
@@ -426,7 +426,7 @@ const char *ASN1_tag2str(int tag) | |||
426 | "VIDEOTEXSTRING", "IA5STRING", "UTCTIME","GENERALIZEDTIME", /* 21-24 */ | 426 | "VIDEOTEXSTRING", "IA5STRING", "UTCTIME","GENERALIZEDTIME", /* 21-24 */ |
427 | "GRAPHICSTRING", "VISIBLESTRING", "GENERALSTRING", /* 25-27 */ | 427 | "GRAPHICSTRING", "VISIBLESTRING", "GENERALSTRING", /* 25-27 */ |
428 | "UNIVERSALSTRING", "<ASN1 29>", "BMPSTRING" /* 28-30 */ | 428 | "UNIVERSALSTRING", "<ASN1 29>", "BMPSTRING" /* 28-30 */ |
429 | }; | 429 | }; |
430 | 430 | ||
431 | if((tag == V_ASN1_NEG_INTEGER) || (tag == V_ASN1_NEG_ENUMERATED)) | 431 | if((tag == V_ASN1_NEG_INTEGER) || (tag == V_ASN1_NEG_ENUMERATED)) |
432 | tag &= ~0x100; | 432 | tag &= ~0x100; |