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_par.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_par.c')
| -rw-r--r-- | src/lib/libcrypto/asn1/asn1_par.c | 351 |
1 files changed, 189 insertions, 162 deletions
diff --git a/src/lib/libcrypto/asn1/asn1_par.c b/src/lib/libcrypto/asn1/asn1_par.c index d3d2f52481..064b3dcb22 100644 --- a/src/lib/libcrypto/asn1/asn1_par.c +++ b/src/lib/libcrypto/asn1/asn1_par.c | |||
| @@ -5,21 +5,21 @@ | |||
| 5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
| 6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
| 7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
| 8 | * | 8 | * |
| 9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
| 10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
| 13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
| 15 | * | 15 | * |
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
| 17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
| 18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
| 19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
| 20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
| 21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
| 22 | * | 22 | * |
| 23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
| 24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
| 25 | * are met: | 25 | * are met: |
| @@ -34,10 +34,10 @@ | |||
| 34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
| 36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
| 38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
| 40 | * | 40 | * |
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| @@ -49,7 +49,7 @@ | |||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
| 52 | * | 52 | * |
| 53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
| 55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
| @@ -62,14 +62,16 @@ | |||
| 62 | #include <openssl/objects.h> | 62 | #include <openssl/objects.h> |
| 63 | #include <openssl/asn1.h> | 63 | #include <openssl/asn1.h> |
| 64 | 64 | ||
| 65 | static int asn1_print_info(BIO *bp, int tag, int xclass,int constructed, | ||
| 66 | int indent); | ||
| 67 | static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, | ||
| 68 | int offset, int depth, int indent, int dump); | ||
| 69 | 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, |
| 70 | int indent) | 66 | int indent); |
| 67 | static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, | ||
| 68 | int offset, int depth, int indent, int dump); | ||
| 69 | |||
| 70 | static int | ||
| 71 | asn1_print_info(BIO *bp, int tag, int xclass, int constructed, | ||
| 72 | int indent) | ||
| 71 | { | 73 | { |
| 72 | static const char fmt[]="%-18s"; | 74 | static const char fmt[] = "%-18s"; |
| 73 | char str[128]; | 75 | char str[128]; |
| 74 | const char *p; | 76 | const char *p; |
| 75 | 77 | ||
| @@ -77,47 +79,51 @@ static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed, | |||
| 77 | p="cons: "; | 79 | p="cons: "; |
| 78 | else | 80 | else |
| 79 | p="prim: "; | 81 | p="prim: "; |
| 80 | if (BIO_write(bp,p,6) < 6) goto err; | 82 | if (BIO_write(bp, p, 6) < 6) |
| 81 | BIO_indent(bp,indent,128); | 83 | goto err; |
| 84 | BIO_indent(bp, indent, 128); | ||
| 82 | 85 | ||
| 83 | p=str; | 86 | p = str; |
| 84 | if ((xclass & V_ASN1_PRIVATE) == V_ASN1_PRIVATE) | 87 | if ((xclass & V_ASN1_PRIVATE) == V_ASN1_PRIVATE) |
| 85 | (void) snprintf(str,sizeof str,"priv [ %d ] ",tag); | 88 | (void) snprintf(str, sizeof str, "priv [ %d ] ", tag); |
| 86 | else if ((xclass & V_ASN1_CONTEXT_SPECIFIC) == V_ASN1_CONTEXT_SPECIFIC) | 89 | else if ((xclass & V_ASN1_CONTEXT_SPECIFIC) == V_ASN1_CONTEXT_SPECIFIC) |
| 87 | (void) snprintf(str,sizeof str,"cont [ %d ]",tag); | 90 | (void) snprintf(str, sizeof str, "cont [ %d ]", tag); |
| 88 | else if ((xclass & V_ASN1_APPLICATION) == V_ASN1_APPLICATION) | 91 | else if ((xclass & V_ASN1_APPLICATION) == V_ASN1_APPLICATION) |
| 89 | (void) snprintf(str,sizeof str,"appl [ %d ]",tag); | 92 | (void) snprintf(str, sizeof str, "appl [ %d ]", tag); |
| 90 | else if (tag > 30) | 93 | else if (tag > 30) |
| 91 | (void) snprintf(str,sizeof str,"<ASN1 %d>",tag); | 94 | (void) snprintf(str, sizeof str, "<ASN1 %d>", tag); |
| 92 | else | 95 | else |
| 93 | p = ASN1_tag2str(tag); | 96 | p = ASN1_tag2str(tag); |
| 94 | 97 | ||
| 95 | if (BIO_printf(bp,fmt,p) <= 0) | 98 | if (BIO_printf(bp, fmt, p) <= 0) |
| 96 | goto err; | 99 | goto err; |
| 97 | return(1); | 100 | return (1); |
| 98 | err: | 101 | err: |
| 99 | return(0); | 102 | return (0); |
| 100 | } | 103 | } |
| 101 | 104 | ||
| 102 | int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent) | 105 | int |
| 106 | ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent) | ||
| 103 | { | 107 | { |
| 104 | return(asn1_parse2(bp,&pp,len,0,0,indent,0)); | 108 | return (asn1_parse2(bp, &pp, len, 0, 0, indent, 0)); |
| 105 | } | 109 | } |
| 106 | 110 | ||
| 107 | int ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent, int dump) | 111 | int |
| 112 | ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent, int dump) | ||
| 108 | { | 113 | { |
| 109 | return(asn1_parse2(bp,&pp,len,0,0,indent,dump)); | 114 | return (asn1_parse2(bp, &pp, len, 0, 0, indent, dump)); |
| 110 | } | 115 | } |
| 111 | 116 | ||
| 112 | static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offset, | 117 | static int |
| 113 | int depth, int indent, int dump) | 118 | asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offset, |
| 119 | int depth, int indent, int dump) | ||
| 114 | { | 120 | { |
| 115 | const unsigned char *p,*ep,*tot,*op,*opp; | 121 | const unsigned char *p, *ep, *tot, *op, *opp; |
| 116 | long len; | 122 | long len; |
| 117 | int tag,xclass,ret=0; | 123 | int tag, xclass, ret = 0; |
| 118 | int nl,hl,j,r; | 124 | int nl, hl, j, r; |
| 119 | ASN1_OBJECT *o=NULL; | 125 | ASN1_OBJECT *o = NULL; |
| 120 | ASN1_OCTET_STRING *os=NULL; | 126 | ASN1_OCTET_STRING *os = NULL; |
| 121 | /* ASN1_BMPSTRING *bmp=NULL;*/ | 127 | /* ASN1_BMPSTRING *bmp=NULL;*/ |
| 122 | int dump_indent; | 128 | int dump_indent; |
| 123 | 129 | ||
| @@ -126,179 +132,194 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse | |||
| 126 | #else | 132 | #else |
| 127 | dump_indent = 6; /* Because we know BIO_dump_indent() */ | 133 | dump_indent = 6; /* Because we know BIO_dump_indent() */ |
| 128 | #endif | 134 | #endif |
| 129 | p= *pp; | 135 | p = *pp; |
| 130 | tot=p+length; | 136 | tot = p + length; |
| 131 | op=p-1; | 137 | op = p - 1; |
| 132 | while ((p < tot) && (op < p)) { | 138 | while ((p < tot) && (op < p)) { |
| 133 | op=p; | 139 | op = p; |
| 134 | j=ASN1_get_object(&p,&len,&tag,&xclass,length); | 140 | j = ASN1_get_object(&p, &len, &tag, &xclass, length); |
| 135 | #ifdef LINT | 141 | #ifdef LINT |
| 136 | j=j; | 142 | j = j; |
| 137 | #endif | 143 | #endif |
| 138 | if (j & 0x80) { | 144 | if (j & 0x80) { |
| 139 | if (BIO_write(bp,"Error in encoding\n",18) <= 0) | 145 | if (BIO_write(bp, "Error in encoding\n", 18) <= 0) |
| 140 | goto end; | 146 | goto end; |
| 141 | ret=0; | 147 | ret = 0; |
| 142 | goto end; | 148 | goto end; |
| 143 | } | 149 | } |
| 144 | hl=(p-op); | 150 | hl = (p - op); |
| 145 | length-=hl; | 151 | length -= hl; |
| 146 | /* if j == 0x21 it is a constructed indefinite length object */ | 152 | /* if j == 0x21 it is a constructed indefinite length object */ |
| 147 | if (BIO_printf(bp,"%5ld:",(long)offset+(long)(op- *pp)) | 153 | if (BIO_printf(bp, "%5ld:", (long)offset + |
| 148 | <= 0) goto end; | 154 | (long)(op - *pp)) <= 0) |
| 155 | goto end; | ||
| 149 | 156 | ||
| 150 | if (j != (V_ASN1_CONSTRUCTED | 1)) { | 157 | if (j != (V_ASN1_CONSTRUCTED | 1)) { |
| 151 | if (BIO_printf(bp,"d=%-2d hl=%ld l=%4ld ", | 158 | if (BIO_printf(bp, "d=%-2d hl=%ld l=%4ld ", |
| 152 | depth,(long)hl,len) <= 0) | 159 | depth, (long)hl, len) <= 0) |
| 153 | goto end; | 160 | goto end; |
| 154 | } else { | 161 | } else { |
| 155 | if (BIO_printf(bp,"d=%-2d hl=%ld l=inf ", | 162 | if (BIO_printf(bp, "d=%-2d hl=%ld l=inf ", |
| 156 | depth,(long)hl) <= 0) | 163 | depth, (long)hl) <= 0) |
| 157 | goto end; | 164 | goto end; |
| 158 | } | 165 | } |
| 159 | if (!asn1_print_info(bp,tag,xclass,j,(indent)?depth:0)) | 166 | if (!asn1_print_info(bp, tag, xclass, j, (indent) ? depth : 0)) |
| 160 | goto end; | 167 | goto end; |
| 161 | if (j & V_ASN1_CONSTRUCTED) { | 168 | if (j & V_ASN1_CONSTRUCTED) { |
| 162 | ep=p+len; | 169 | ep = p + len; |
| 163 | if (BIO_write(bp,"\n",1) <= 0) goto end; | 170 | if (BIO_write(bp, "\n", 1) <= 0) |
| 171 | goto end; | ||
| 164 | if (len > length) { | 172 | if (len > length) { |
| 165 | BIO_printf(bp, | 173 | BIO_printf(bp, "length is greater than %ld\n", |
| 166 | "length is greater than %ld\n",length); | 174 | length); |
| 167 | ret=0; | 175 | ret = 0; |
| 168 | goto end; | 176 | goto end; |
| 169 | } | 177 | } |
| 170 | if ((j == 0x21) && (len == 0)) { | 178 | if ((j == 0x21) && (len == 0)) { |
| 171 | for (;;) { | 179 | for (;;) { |
| 172 | r=asn1_parse2(bp,&p,(long)(tot-p), | 180 | r = asn1_parse2(bp, &p, (long)(tot - p), |
| 173 | offset+(p - *pp),depth+1, | 181 | offset + (p - *pp), depth + 1, |
| 174 | indent,dump); | 182 | indent, dump); |
| 175 | if (r == 0) { ret=0; goto end; } | 183 | if (r == 0) { |
| 176 | if ((r == 2) || (p >= tot)) break; | 184 | ret = 0; |
| 185 | goto end; | ||
| 186 | } | ||
| 187 | if ((r == 2) || (p >= tot)) | ||
| 188 | break; | ||
| 177 | } | 189 | } |
| 178 | } | 190 | } else |
| 179 | else | ||
| 180 | while (p < ep) { | 191 | while (p < ep) { |
| 181 | r=asn1_parse2(bp,&p,(long)len, | 192 | r = asn1_parse2(bp, &p, (long)len, |
| 182 | offset+(p - *pp),depth+1, | 193 | offset + (p - *pp), depth + 1, |
| 183 | indent,dump); | 194 | indent, dump); |
| 184 | if (r == 0) { ret=0; goto end; } | 195 | if (r == 0) { |
| 196 | ret = 0; | ||
| 197 | goto end; | ||
| 198 | } | ||
| 185 | } | 199 | } |
| 186 | } else if (xclass != 0) { | 200 | } else if (xclass != 0) { |
| 187 | p+=len; | 201 | p += len; |
| 188 | if (BIO_write(bp,"\n",1) <= 0) goto end; | 202 | if (BIO_write(bp, "\n", 1) <= 0) |
| 203 | goto end; | ||
| 189 | } else { | 204 | } else { |
| 190 | nl=0; | 205 | nl = 0; |
| 191 | if ( (tag == V_ASN1_PRINTABLESTRING) || | 206 | if ((tag == V_ASN1_PRINTABLESTRING) || |
| 192 | (tag == V_ASN1_T61STRING) || | 207 | (tag == V_ASN1_T61STRING) || |
| 193 | (tag == V_ASN1_IA5STRING) || | 208 | (tag == V_ASN1_IA5STRING) || |
| 194 | (tag == V_ASN1_VISIBLESTRING) || | 209 | (tag == V_ASN1_VISIBLESTRING) || |
| 195 | (tag == V_ASN1_NUMERICSTRING) || | 210 | (tag == V_ASN1_NUMERICSTRING) || |
| 196 | (tag == V_ASN1_UTF8STRING) || | 211 | (tag == V_ASN1_UTF8STRING) || |
| 197 | (tag == V_ASN1_UTCTIME) || | 212 | (tag == V_ASN1_UTCTIME) || |
| 198 | (tag == V_ASN1_GENERALIZEDTIME)) { | 213 | (tag == V_ASN1_GENERALIZEDTIME)) { |
| 199 | if (BIO_write(bp,":",1) <= 0) goto end; | 214 | if (BIO_write(bp, ":", 1) <= 0) |
| 215 | goto end; | ||
| 200 | if ((len > 0) && | 216 | if ((len > 0) && |
| 201 | BIO_write(bp,(const char *)p,(int)len) | 217 | BIO_write(bp, (const char *)p, (int)len) != |
| 202 | != (int)len) | 218 | (int)len) |
| 203 | goto end; | 219 | goto end; |
| 204 | } else if (tag == V_ASN1_OBJECT) { | 220 | } else if (tag == V_ASN1_OBJECT) { |
| 205 | opp=op; | 221 | opp = op; |
| 206 | if (d2i_ASN1_OBJECT(&o,&opp,len+hl) != NULL) { | 222 | if (d2i_ASN1_OBJECT(&o, &opp, len + hl) != |
| 207 | if (BIO_write(bp,":",1) <= 0) goto end; | 223 | NULL) { |
| 208 | i2a_ASN1_OBJECT(bp,o); | 224 | if (BIO_write(bp, ":", 1) <= 0) |
| 225 | goto end; | ||
| 226 | i2a_ASN1_OBJECT(bp, o); | ||
| 209 | } else { | 227 | } else { |
| 210 | if (BIO_write(bp,":BAD OBJECT",11) <= 0) | 228 | if (BIO_write(bp, ":BAD OBJECT", |
| 229 | 11) <= 0) | ||
| 211 | goto end; | 230 | goto end; |
| 212 | } | 231 | } |
| 213 | } else if (tag == V_ASN1_BOOLEAN) { | 232 | } else if (tag == V_ASN1_BOOLEAN) { |
| 214 | int ii; | 233 | int ii; |
| 215 | 234 | ||
| 216 | opp=op; | 235 | opp = op; |
| 217 | ii=d2i_ASN1_BOOLEAN(NULL,&opp,len+hl); | 236 | ii = d2i_ASN1_BOOLEAN(NULL, &opp, len + hl); |
| 218 | if (ii < 0) { | 237 | if (ii < 0) { |
| 219 | if (BIO_write(bp,"Bad boolean\n",12) <= 0) | 238 | if (BIO_write(bp, "Bad boolean\n", |
| 239 | 12) <= 0) | ||
| 220 | goto end; | 240 | goto end; |
| 221 | } | 241 | } |
| 222 | BIO_printf(bp,":%d",ii); | 242 | BIO_printf(bp, ":%d", ii); |
| 223 | } else if (tag == V_ASN1_BMPSTRING) { | 243 | } else if (tag == V_ASN1_BMPSTRING) { |
| 224 | /* do the BMP thang */ | 244 | /* do the BMP thang */ |
| 225 | } else if (tag == V_ASN1_OCTET_STRING) { | 245 | } else if (tag == V_ASN1_OCTET_STRING) { |
| 226 | int i,printable=1; | 246 | int i, printable = 1; |
| 227 | 247 | ||
| 228 | opp=op; | 248 | opp = op; |
| 229 | os=d2i_ASN1_OCTET_STRING(NULL,&opp,len+hl); | 249 | os = d2i_ASN1_OCTET_STRING(NULL, &opp, len + hl); |
| 230 | if (os != NULL && os->length > 0) { | 250 | if (os != NULL && os->length > 0) { |
| 231 | opp = os->data; | 251 | opp = os->data; |
| 232 | /* testing whether the octet string is | 252 | /* testing whether the octet string is |
| 233 | * printable */ | 253 | * printable */ |
| 234 | for (i=0; i<os->length; i++) { | 254 | for (i = 0; i < os->length; i++) { |
| 235 | if (( (opp[i] < ' ') && | 255 | if (((opp[i] < ' ') && |
| 236 | (opp[i] != '\n') && | 256 | (opp[i] != '\n') && |
| 237 | (opp[i] != '\r') && | 257 | (opp[i] != '\r') && |
| 238 | (opp[i] != '\t')) || | 258 | (opp[i] != '\t')) || |
| 239 | (opp[i] > '~')) { | 259 | (opp[i] > '~')) { |
| 240 | printable=0; | 260 | printable = 0; |
| 241 | break; | 261 | break; |
| 242 | } | 262 | } |
| 243 | } | 263 | } |
| 244 | if (printable) { | 264 | if (printable) { |
| 245 | /* printable string */ | 265 | /* printable string */ |
| 246 | if (BIO_write(bp,":",1) <= 0) | 266 | if (BIO_write(bp, ":", 1) <= 0) |
| 247 | goto end; | 267 | goto end; |
| 248 | if (BIO_write(bp,(const char *)opp, | 268 | if (BIO_write(bp, (const char *)opp, |
| 249 | os->length) <= 0) | 269 | os->length) <= 0) |
| 250 | goto end; | 270 | goto end; |
| 251 | } else if (!dump) { | 271 | } else if (!dump) { |
| 252 | /* not printable => print octet string | 272 | /* not printable => print octet string |
| 253 | * as hex dump */ | 273 | * as hex dump */ |
| 254 | if (BIO_write(bp,"[HEX DUMP]:",11) <= 0) | 274 | if (BIO_write(bp, "[HEX DUMP]:", 11) <= 0) |
| 255 | goto end; | 275 | goto end; |
| 256 | for (i=0; i<os->length; i++) { | 276 | for (i = 0; i < os->length; i++) { |
| 257 | if (BIO_printf(bp,"%02X" | 277 | if (BIO_printf(bp, |
| 258 | , opp[i]) <= 0) | 278 | "%02X", opp[i]) <= 0) |
| 259 | goto end; | 279 | goto end; |
| 260 | } | 280 | } |
| 261 | } else { | 281 | } else { |
| 262 | /* print the normal dump */ | 282 | /* print the normal dump */ |
| 263 | if (!nl) { | 283 | if (!nl) { |
| 264 | if (BIO_write(bp,"\n",1) <= 0) | 284 | if (BIO_write(bp, "\n", 1) <= 0) |
| 265 | goto end; | 285 | goto end; |
| 266 | } | 286 | } |
| 267 | if (BIO_dump_indent(bp, | 287 | if (BIO_dump_indent(bp, |
| 268 | (const char *)opp, | 288 | (const char *)opp, |
| 269 | ((dump == -1 || dump > | 289 | ((dump == -1 || dump > |
| 270 | os->length)?os->length:dump), | 290 | os->length) ? os->length : dump), |
| 271 | dump_indent) <= 0) | 291 | dump_indent) <= 0) |
| 272 | goto end; | 292 | goto end; |
| 273 | nl=1; | 293 | nl = 1; |
| 274 | } | 294 | } |
| 275 | } | 295 | } |
| 276 | if (os != NULL) { | 296 | if (os != NULL) { |
| 277 | M_ASN1_OCTET_STRING_free(os); | 297 | M_ASN1_OCTET_STRING_free(os); |
| 278 | os=NULL; | 298 | os = NULL; |
| 279 | } | 299 | } |
| 280 | } else if (tag == V_ASN1_INTEGER) { | 300 | } else if (tag == V_ASN1_INTEGER) { |
| 281 | ASN1_INTEGER *bs; | 301 | ASN1_INTEGER *bs; |
| 282 | int i; | 302 | int i; |
| 283 | 303 | ||
| 284 | opp=op; | 304 | opp = op; |
| 285 | bs=d2i_ASN1_INTEGER(NULL,&opp,len+hl); | 305 | bs = d2i_ASN1_INTEGER(NULL, &opp, len + hl); |
| 286 | if (bs != NULL) { | 306 | if (bs != NULL) { |
| 287 | if (BIO_write(bp,":",1) <= 0) goto end; | 307 | if (BIO_write(bp, ":", 1) <= 0) |
| 308 | goto end; | ||
| 288 | if (bs->type == V_ASN1_NEG_INTEGER) | 309 | if (bs->type == V_ASN1_NEG_INTEGER) |
| 289 | if (BIO_write(bp,"-",1) <= 0) | 310 | if (BIO_write(bp, "-", 1) <= 0) |
| 290 | goto end; | 311 | goto end; |
| 291 | for (i=0; i<bs->length; i++) { | 312 | for (i = 0; i < bs->length; i++) { |
| 292 | if (BIO_printf(bp,"%02X", | 313 | if (BIO_printf(bp, "%02X", |
| 293 | bs->data[i]) <= 0) | 314 | bs->data[i]) <= 0) |
| 294 | goto end; | 315 | goto end; |
| 295 | } | 316 | } |
| 296 | if (bs->length == 0) { | 317 | if (bs->length == 0) { |
| 297 | if (BIO_write(bp,"00",2) <= 0) | 318 | if (BIO_write(bp, "00", 2) <= 0) |
| 298 | goto end; | 319 | goto end; |
| 299 | } | 320 | } |
| 300 | } else { | 321 | } else { |
| 301 | if (BIO_write(bp,"BAD INTEGER",11) <= 0) | 322 | if (BIO_write(bp, "BAD INTEGER", 11) <= 0) |
| 302 | goto end; | 323 | goto end; |
| 303 | } | 324 | } |
| 304 | M_ASN1_INTEGER_free(bs); | 325 | M_ASN1_INTEGER_free(bs); |
| @@ -306,75 +327,81 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse | |||
| 306 | ASN1_ENUMERATED *bs; | 327 | ASN1_ENUMERATED *bs; |
| 307 | int i; | 328 | int i; |
| 308 | 329 | ||
| 309 | opp=op; | 330 | opp = op; |
| 310 | bs=d2i_ASN1_ENUMERATED(NULL,&opp,len+hl); | 331 | bs = d2i_ASN1_ENUMERATED(NULL, &opp, len + hl); |
| 311 | if (bs != NULL) { | 332 | if (bs != NULL) { |
| 312 | if (BIO_write(bp,":",1) <= 0) goto end; | 333 | if (BIO_write(bp, ":", 1) <= 0) |
| 334 | goto end; | ||
| 313 | if (bs->type == V_ASN1_NEG_ENUMERATED) | 335 | if (bs->type == V_ASN1_NEG_ENUMERATED) |
| 314 | if (BIO_write(bp,"-",1) <= 0) | 336 | if (BIO_write(bp, "-", 1) <= 0) |
| 315 | goto end; | 337 | goto end; |
| 316 | for (i=0; i<bs->length; i++) { | 338 | for (i = 0; i < bs->length; i++) { |
| 317 | if (BIO_printf(bp,"%02X", | 339 | if (BIO_printf(bp, "%02X", |
| 318 | bs->data[i]) <= 0) | 340 | bs->data[i]) <= 0) |
| 319 | goto end; | 341 | goto end; |
| 320 | } | 342 | } |
| 321 | if (bs->length == 0) { | 343 | if (bs->length == 0) { |
| 322 | if (BIO_write(bp,"00",2) <= 0) | 344 | if (BIO_write(bp, "00", 2) <= 0) |
| 323 | goto end; | 345 | goto end; |
| 324 | } | 346 | } |
| 325 | } else { | 347 | } else { |
| 326 | if (BIO_write(bp,"BAD ENUMERATED",14) <= 0) | 348 | if (BIO_write(bp, "BAD ENUMERATED", 14) <= 0) |
| 327 | goto end; | 349 | goto end; |
| 328 | } | 350 | } |
| 329 | M_ASN1_ENUMERATED_free(bs); | 351 | M_ASN1_ENUMERATED_free(bs); |
| 330 | } else if (len > 0 && dump) { | 352 | } else if (len > 0 && dump) { |
| 331 | if (!nl) { | 353 | if (!nl) { |
| 332 | if (BIO_write(bp,"\n",1) <= 0) | 354 | if (BIO_write(bp, "\n", 1) <= 0) |
| 333 | goto end; | 355 | goto end; |
| 334 | } | 356 | } |
| 335 | if (BIO_dump_indent(bp,(const char *)p, | 357 | if (BIO_dump_indent(bp, (const char *)p, |
| 336 | ((dump == -1 || dump > len)?len:dump), | 358 | ((dump == -1 || dump > len) ? len : dump), |
| 337 | dump_indent) <= 0) | 359 | dump_indent) <= 0) |
| 338 | goto end; | 360 | goto end; |
| 339 | nl=1; | 361 | nl = 1; |
| 340 | } | 362 | } |
| 341 | 363 | ||
| 342 | if (!nl) { | 364 | if (!nl) { |
| 343 | if (BIO_write(bp,"\n",1) <= 0) goto end; | 365 | if (BIO_write(bp, "\n", 1) <= 0) |
| 366 | goto end; | ||
| 344 | } | 367 | } |
| 345 | p+=len; | 368 | p += len; |
| 346 | if ((tag == V_ASN1_EOC) && (xclass == 0)) { | 369 | if ((tag == V_ASN1_EOC) && (xclass == 0)) { |
| 347 | ret=2; /* End of sequence */ | 370 | ret = 2; /* End of sequence */ |
| 348 | goto end; | 371 | goto end; |
| 349 | } | 372 | } |
| 350 | } | 373 | } |
| 351 | length-=len; | 374 | length -= len; |
| 352 | } | 375 | } |
| 353 | ret=1; | 376 | ret = 1; |
| 377 | |||
| 354 | end: | 378 | end: |
| 355 | if (o != NULL) ASN1_OBJECT_free(o); | 379 | if (o != NULL) |
| 356 | if (os != NULL) M_ASN1_OCTET_STRING_free(os); | 380 | ASN1_OBJECT_free(o); |
| 357 | *pp=p; | 381 | if (os != NULL) |
| 358 | return(ret); | 382 | M_ASN1_OCTET_STRING_free(os); |
| 383 | *pp = p; | ||
| 384 | return (ret); | ||
| 359 | } | 385 | } |
| 360 | 386 | ||
| 361 | const char *ASN1_tag2str(int tag) | 387 | const char * |
| 388 | ASN1_tag2str(int tag) | ||
| 362 | { | 389 | { |
| 363 | static const char * const tag2str[] = { | 390 | static const char * const tag2str[] = { |
| 364 | "EOC", "BOOLEAN", "INTEGER", "BIT STRING", "OCTET STRING", /* 0-4 */ | 391 | "EOC", "BOOLEAN", "INTEGER", "BIT STRING", "OCTET STRING", /* 0-4 */ |
| 365 | "NULL", "OBJECT", "OBJECT DESCRIPTOR", "EXTERNAL", "REAL", /* 5-9 */ | 392 | "NULL", "OBJECT", "OBJECT DESCRIPTOR", "EXTERNAL", "REAL", /* 5-9 */ |
| 366 | "ENUMERATED", "<ASN1 11>", "UTF8STRING", "<ASN1 13>", /* 10-13 */ | 393 | "ENUMERATED", "<ASN1 11>", "UTF8STRING", "<ASN1 13>", /* 10-13 */ |
| 367 | "<ASN1 14>", "<ASN1 15>", "SEQUENCE", "SET", /* 15-17 */ | 394 | "<ASN1 14>", "<ASN1 15>", "SEQUENCE", "SET", /* 15-17 */ |
| 368 | "NUMERICSTRING", "PRINTABLESTRING", "T61STRING", /* 18-20 */ | 395 | "NUMERICSTRING", "PRINTABLESTRING", "T61STRING", /* 18-20 */ |
| 369 | "VIDEOTEXSTRING", "IA5STRING", "UTCTIME","GENERALIZEDTIME", /* 21-24 */ | 396 | "VIDEOTEXSTRING", "IA5STRING", "UTCTIME", "GENERALIZEDTIME", /* 21-24 */ |
| 370 | "GRAPHICSTRING", "VISIBLESTRING", "GENERALSTRING", /* 25-27 */ | 397 | "GRAPHICSTRING", "VISIBLESTRING", "GENERALSTRING", /* 25-27 */ |
| 371 | "UNIVERSALSTRING", "<ASN1 29>", "BMPSTRING" /* 28-30 */ | 398 | "UNIVERSALSTRING", "<ASN1 29>", "BMPSTRING" /* 28-30 */ |
| 372 | }; | 399 | }; |
| 373 | 400 | ||
| 374 | if((tag == V_ASN1_NEG_INTEGER) || (tag == V_ASN1_NEG_ENUMERATED)) | 401 | if ((tag == V_ASN1_NEG_INTEGER) || (tag == V_ASN1_NEG_ENUMERATED)) |
| 375 | tag &= ~0x100; | 402 | tag &= ~0x100; |
| 376 | 403 | ||
| 377 | if(tag < 0 || tag > 30) return "(unknown)"; | 404 | if (tag < 0 || tag > 30) |
| 405 | return "(unknown)"; | ||
| 378 | return tag2str[tag]; | 406 | return tag2str[tag]; |
| 379 | } | 407 | } |
| 380 | |||
