diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/f_string.c')
| -rw-r--r-- | src/lib/libcrypto/asn1/f_string.c | 164 |
1 files changed, 90 insertions, 74 deletions
diff --git a/src/lib/libcrypto/asn1/f_string.c b/src/lib/libcrypto/asn1/f_string.c index 87d7aaa0dd..d42bcdb6ea 100644 --- a/src/lib/libcrypto/asn1/f_string.c +++ b/src/lib/libcrypto/asn1/f_string.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 |
| @@ -61,43 +61,50 @@ | |||
| 61 | #include <openssl/buffer.h> | 61 | #include <openssl/buffer.h> |
| 62 | #include <openssl/asn1.h> | 62 | #include <openssl/asn1.h> |
| 63 | 63 | ||
| 64 | int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type) | 64 | int |
| 65 | i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type) | ||
| 65 | { | 66 | { |
| 66 | int i,n=0; | 67 | int i, n = 0; |
| 67 | static const char *h="0123456789ABCDEF"; | 68 | static const char *h = "0123456789ABCDEF"; |
| 68 | char buf[2]; | 69 | char buf[2]; |
| 69 | 70 | ||
| 70 | if (a == NULL) return(0); | 71 | if (a == NULL) |
| 72 | return (0); | ||
| 71 | 73 | ||
| 72 | if (a->length == 0) { | 74 | if (a->length == 0) { |
| 73 | if (BIO_write(bp,"0",1) != 1) goto err; | 75 | if (BIO_write(bp, "0", 1) != 1) |
| 74 | n=1; | 76 | goto err; |
| 77 | n = 1; | ||
| 75 | } else { | 78 | } else { |
| 76 | for (i=0; i<a->length; i++) { | 79 | for (i = 0; i < a->length; i++) { |
| 77 | if ((i != 0) && (i%35 == 0)) { | 80 | if ((i != 0) && (i % 35 == 0)) { |
| 78 | if (BIO_write(bp,"\\\n",2) != 2) goto err; | 81 | if (BIO_write(bp, "\\\n", 2) != 2) |
| 79 | n+=2; | 82 | goto err; |
| 83 | n += 2; | ||
| 80 | } | 84 | } |
| 81 | buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; | 85 | buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f]; |
| 82 | buf[1]=h[((unsigned char)a->data[i] )&0x0f]; | 86 | buf[1] = h[((unsigned char)a->data[i]) & 0x0f]; |
| 83 | if (BIO_write(bp,buf,2) != 2) goto err; | 87 | if (BIO_write(bp, buf, 2) != 2) |
| 84 | n+=2; | 88 | goto err; |
| 89 | n += 2; | ||
| 85 | } | 90 | } |
| 86 | } | 91 | } |
| 87 | return(n); | 92 | return (n); |
| 93 | |||
| 88 | err: | 94 | err: |
| 89 | return(-1); | 95 | return (-1); |
| 90 | } | 96 | } |
| 91 | 97 | ||
| 92 | int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) | 98 | int |
| 99 | a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) | ||
| 93 | { | 100 | { |
| 94 | int ret=0; | 101 | int ret = 0; |
| 95 | int i,j,k,m,n,again,bufsize; | 102 | int i, j, k, m, n, again, bufsize; |
| 96 | unsigned char *s=NULL,*sp; | 103 | unsigned char *s = NULL, *sp; |
| 97 | unsigned char *bufp; | 104 | unsigned char *bufp; |
| 98 | int num=0,slen=0,first=1; | 105 | int num = 0, slen = 0, first = 1; |
| 99 | 106 | ||
| 100 | bufsize=BIO_gets(bp,buf,size); | 107 | bufsize = BIO_gets(bp, buf, size); |
| 101 | for (;;) { | 108 | for (;;) { |
| 102 | if (bufsize < 1) { | 109 | if (bufsize < 1) { |
| 103 | if (first) | 110 | if (first) |
| @@ -105,83 +112,92 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) | |||
| 105 | else | 112 | else |
| 106 | goto err_sl; | 113 | goto err_sl; |
| 107 | } | 114 | } |
| 108 | first=0; | 115 | first = 0; |
| 109 | 116 | ||
| 110 | i=bufsize; | 117 | i = bufsize; |
| 111 | if (buf[i-1] == '\n') buf[--i]='\0'; | 118 | if (buf[i-1] == '\n') |
| 112 | if (i == 0) goto err_sl; | 119 | buf[--i] = '\0'; |
| 113 | if (buf[i-1] == '\r') buf[--i]='\0'; | 120 | if (i == 0) |
| 114 | if (i == 0) goto err_sl; | 121 | goto err_sl; |
| 115 | again=(buf[i-1] == '\\'); | 122 | if (buf[i-1] == '\r') |
| 123 | buf[--i] = '\0'; | ||
| 124 | if (i == 0) | ||
| 125 | goto err_sl; | ||
| 126 | again = (buf[i - 1] == '\\'); | ||
| 116 | 127 | ||
| 117 | for (j=i-1; j>0; j--) { | 128 | for (j = i - 1; j > 0; j--) { |
| 118 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || | 129 | if (!(((buf[j] >= '0') && (buf[j] <= '9')) || |
| 119 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || | 130 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || |
| 120 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) { | 131 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) { |
| 121 | i=j; | 132 | i = j; |
| 122 | break; | 133 | break; |
| 123 | } | 134 | } |
| 124 | } | 135 | } |
| 125 | buf[i]='\0'; | 136 | buf[i] = '\0'; |
| 126 | /* We have now cleared all the crap off the end of the | 137 | /* We have now cleared all the crap off the end of the |
| 127 | * line */ | 138 | * line */ |
| 128 | if (i < 2) goto err_sl; | 139 | if (i < 2) |
| 140 | goto err_sl; | ||
| 129 | 141 | ||
| 130 | bufp=(unsigned char *)buf; | 142 | bufp = (unsigned char *)buf; |
| 131 | 143 | ||
| 132 | k=0; | 144 | k = 0; |
| 133 | i-=again; | 145 | i -= again; |
| 134 | if (i%2 != 0) { | 146 | if (i % 2 != 0) { |
| 135 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_ODD_NUMBER_OF_CHARS); | 147 | ASN1err(ASN1_F_A2I_ASN1_STRING, |
| 148 | ASN1_R_ODD_NUMBER_OF_CHARS); | ||
| 136 | goto err; | 149 | goto err; |
| 137 | } | 150 | } |
| 138 | i/=2; | 151 | i /= 2; |
| 139 | if (num+i > slen) { | 152 | if (num + i > slen) { |
| 140 | if (s == NULL) | 153 | if (s == NULL) |
| 141 | sp=(unsigned char *)malloc( | 154 | sp = (unsigned char *)malloc( |
| 142 | (unsigned int)num+i*2); | 155 | (unsigned int)num + i * 2); |
| 143 | else | 156 | else |
| 144 | sp=(unsigned char *)realloc(s, | 157 | sp = (unsigned char *)realloc(s, |
| 145 | (unsigned int)num+i*2); | 158 | (unsigned int)num + i * 2); |
| 146 | if (sp == NULL) { | 159 | if (sp == NULL) { |
| 147 | ASN1err(ASN1_F_A2I_ASN1_STRING,ERR_R_MALLOC_FAILURE); | 160 | ASN1err(ASN1_F_A2I_ASN1_STRING, |
| 148 | if (s != NULL) free(s); | 161 | ERR_R_MALLOC_FAILURE); |
| 162 | if (s != NULL) | ||
| 163 | free(s); | ||
| 149 | goto err; | 164 | goto err; |
| 150 | } | 165 | } |
| 151 | s=sp; | 166 | s = sp; |
| 152 | slen=num+i*2; | 167 | slen = num + i * 2; |
| 153 | } | 168 | } |
| 154 | for (j=0; j<i; j++,k+=2) { | 169 | for (j = 0; j < i; j++, k += 2) { |
| 155 | for (n=0; n<2; n++) { | 170 | for (n = 0; n < 2; n++) { |
| 156 | m=bufp[k+n]; | 171 | m = bufp[k + n]; |
| 157 | if ((m >= '0') && (m <= '9')) | 172 | if ((m >= '0') && (m <= '9')) |
| 158 | m-='0'; | 173 | m -= '0'; |
| 159 | else if ((m >= 'a') && (m <= 'f')) | 174 | else if ((m >= 'a') && (m <= 'f')) |
| 160 | m=m-'a'+10; | 175 | m = m - 'a' + 10; |
| 161 | else if ((m >= 'A') && (m <= 'F')) | 176 | else if ((m >= 'A') && (m <= 'F')) |
| 162 | m=m-'A'+10; | 177 | m = m - 'A' + 10; |
| 163 | else { | 178 | else { |
| 164 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_NON_HEX_CHARACTERS); | 179 | ASN1err(ASN1_F_A2I_ASN1_STRING, |
| 180 | ASN1_R_NON_HEX_CHARACTERS); | ||
| 165 | goto err; | 181 | goto err; |
| 166 | } | 182 | } |
| 167 | s[num+j]<<=4; | 183 | s[num + j] <<= 4; |
| 168 | s[num+j]|=m; | 184 | s[num + j] |= m; |
| 169 | } | 185 | } |
| 170 | } | 186 | } |
| 171 | num+=i; | 187 | num += i; |
| 172 | if (again) | 188 | if (again) |
| 173 | bufsize=BIO_gets(bp,buf,size); | 189 | bufsize = BIO_gets(bp, buf, size); |
| 174 | else | 190 | else |
| 175 | break; | 191 | break; |
| 176 | } | 192 | } |
| 177 | bs->length=num; | 193 | bs->length = num; |
| 178 | bs->data=s; | 194 | bs->data = s; |
| 179 | ret=1; | 195 | ret = 1; |
| 196 | |||
| 180 | err: | 197 | err: |
| 181 | if (0) { | 198 | if (0) { |
| 182 | err_sl: | 199 | err_sl: |
| 183 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_SHORT_LINE); | 200 | ASN1err(ASN1_F_A2I_ASN1_STRING, ASN1_R_SHORT_LINE); |
| 184 | } | 201 | } |
| 185 | return(ret); | 202 | return (ret); |
| 186 | } | 203 | } |
| 187 | |||
