summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/x509/x509_obj.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/x509/x509_obj.c')
-rw-r--r--src/lib/libcrypto/x509/x509_obj.c140
1 files changed, 75 insertions, 65 deletions
diff --git a/src/lib/libcrypto/x509/x509_obj.c b/src/lib/libcrypto/x509/x509_obj.c
index d0c02f833e..a50b05bb7a 100644
--- a/src/lib/libcrypto/x509/x509_obj.c
+++ b/src/lib/libcrypto/x509/x509_obj.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
@@ -63,105 +63,115 @@
63#include <openssl/x509.h> 63#include <openssl/x509.h>
64#include <openssl/buffer.h> 64#include <openssl/buffer.h>
65 65
66char *X509_NAME_oneline(X509_NAME *a, char *buf, int len) 66char *
67X509_NAME_oneline(X509_NAME *a, char *buf, int len)
67{ 68{
68 X509_NAME_ENTRY *ne; 69 X509_NAME_ENTRY *ne;
69int i; 70 int i;
70 int n,lold,l,l1,l2,num,j,type; 71 int n, lold, l,l1, l2, num, j, type;
71 const char *s; 72 const char *s;
72 char *p; 73 char *p;
73 unsigned char *q; 74 unsigned char *q;
74 BUF_MEM *b=NULL; 75 BUF_MEM *b = NULL;
75 static const char hex[17]="0123456789ABCDEF"; 76 static const char hex[17] = "0123456789ABCDEF";
76 int gs_doit[4]; 77 int gs_doit[4];
77 char tmp_buf[80]; 78 char tmp_buf[80];
78 79
79 if (buf == NULL) { 80 if (buf == NULL) {
80 if ((b=BUF_MEM_new()) == NULL) goto err; 81 if ((b = BUF_MEM_new()) == NULL)
81 if (!BUF_MEM_grow(b,200)) goto err; 82 goto err;
82 b->data[0]='\0'; 83 if (!BUF_MEM_grow(b, 200))
83 len=200; 84 goto err;
85 b->data[0] = '\0';
86 len = 200;
84 } 87 }
85 if (a == NULL) { 88 if (a == NULL) {
86 if(b) { 89 if (b) {
87 buf=b->data; 90 buf = b->data;
88 free(b); 91 free(b);
89 } 92 }
90 strlcpy(buf,"NO X509_NAME",len); 93 strlcpy(buf, "NO X509_NAME", len);
91 return buf; 94 return buf;
92 } 95 }
93 96
94 len--; /* space for '\0' */ 97 len--; /* space for '\0' */
95 l=0; 98 l = 0;
96 for (i=0; i<sk_X509_NAME_ENTRY_num(a->entries); i++) { 99 for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
97 ne=sk_X509_NAME_ENTRY_value(a->entries,i); 100 ne = sk_X509_NAME_ENTRY_value(a->entries, i);
98 n=OBJ_obj2nid(ne->object); 101 n = OBJ_obj2nid(ne->object);
99 if ((n == NID_undef) || ((s=OBJ_nid2sn(n)) == NULL)) { 102 if ((n == NID_undef) || ((s = OBJ_nid2sn(n)) == NULL)) {
100 i2t_ASN1_OBJECT(tmp_buf,sizeof(tmp_buf),ne->object); 103 i2t_ASN1_OBJECT(tmp_buf, sizeof(tmp_buf), ne->object);
101 s=tmp_buf; 104 s = tmp_buf;
102 } 105 }
103 l1=strlen(s); 106 l1 = strlen(s);
104 107
105 type=ne->value->type; 108 type = ne->value->type;
106 num=ne->value->length; 109 num = ne->value->length;
107 q=ne->value->data; 110 q = ne->value->data;
108 if ((type == V_ASN1_GENERALSTRING) && ((num%4) == 0)) { 111 if ((type == V_ASN1_GENERALSTRING) && ((num % 4) == 0)) {
109 gs_doit[0]=gs_doit[1]=gs_doit[2]=gs_doit[3]=0; 112 gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 0;
110 for (j=0; j<num; j++) 113 for (j = 0; j < num; j++)
111 if (q[j] != 0) gs_doit[j&3]=1; 114 if (q[j] != 0)
115 gs_doit[j & 3] = 1;
112 116
113 if (gs_doit[0]|gs_doit[1]|gs_doit[2]) 117 if (gs_doit[0]|gs_doit[1]|gs_doit[2])
114 gs_doit[0]=gs_doit[1]=gs_doit[2]=gs_doit[3]=1; 118 gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;
115 else { 119 else {
116 gs_doit[0]=gs_doit[1]=gs_doit[2]=0; 120 gs_doit[0] = gs_doit[1] = gs_doit[2] = 0;
117 gs_doit[3]=1; 121 gs_doit[3] = 1;
118 } 122 }
119 } else 123 } else
120 gs_doit[0]=gs_doit[1]=gs_doit[2]=gs_doit[3]=1; 124 gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;
121 125
122 for (l2=j=0; j<num; j++) { 126 for (l2 = j=0; j < num; j++) {
123 if (!gs_doit[j&3]) continue; 127 if (!gs_doit[j&3])
128 continue;
124 l2++; 129 l2++;
125 if ((q[j] < ' ') || (q[j] > '~')) l2+=3; 130 if ((q[j] < ' ') || (q[j] > '~'))
131 l2 += 3;
126 } 132 }
127 133
128 lold=l; 134 lold = l;
129 l+=1+l1+1+l2; 135 l += 1 + l1 + 1 + l2;
130 if (b != NULL) { 136 if (b != NULL) {
131 if (!BUF_MEM_grow(b,l+1)) goto err; 137 if (!BUF_MEM_grow(b, l + 1))
132 p= &(b->data[lold]); 138 goto err;
139 p = &(b->data[lold]);
133 } else if (l > len) { 140 } else if (l > len) {
134 break; 141 break;
135 } else 142 } else
136 p= &(buf[lold]); 143 p = &(buf[lold]);
137 *(p++)='/'; 144 *(p++) = '/';
138 memcpy(p,s,(unsigned int)l1); p+=l1; 145 memcpy(p, s, (unsigned int)l1);
139 *(p++)='='; 146 p += l1;
140 q=ne->value->data; 147 *(p++) = '=';
141 for (j=0; j<num; j++) { 148 q = ne->value->data;
142 if (!gs_doit[j&3]) continue; 149 for (j = 0; j < num; j++) {
143 n=q[j]; 150 if (!gs_doit[j & 3])
151 continue;
152 n = q[j];
144 if ((n < ' ') || (n > '~')) { 153 if ((n < ' ') || (n > '~')) {
145 *(p++)='\\'; 154 *(p++) = '\\';
146 *(p++)='x'; 155 *(p++) = 'x';
147 *(p++)=hex[(n>>4)&0x0f]; 156 *(p++) = hex[(n >> 4) & 0x0f];
148 *(p++)=hex[n&0x0f]; 157 *(p++) = hex[n & 0x0f];
149 } else 158 } else
150 *(p++)=n; 159 *(p++) = n;
151 } 160 }
152 *p='\0'; 161 *p = '\0';
153 } 162 }
154 if (b != NULL) { 163 if (b != NULL) {
155 p=b->data; 164 p = b->data;
156 free(b); 165 free(b);
157 } else 166 } else
158 p=buf; 167 p = buf;
159 if (i == 0) 168 if (i == 0)
160 *p = '\0'; 169 *p = '\0';
161 return(p); 170 return (p);
171
162err: 172err:
163 X509err(X509_F_X509_NAME_ONELINE,ERR_R_MALLOC_FAILURE); 173 X509err(X509_F_X509_NAME_ONELINE, ERR_R_MALLOC_FAILURE);
164 if (b != NULL) BUF_MEM_free(b); 174 if (b != NULL)
165 return(NULL); 175 BUF_MEM_free(b);
176 return (NULL);
166} 177}
167