diff options
Diffstat (limited to 'src/lib/libcrypto/x509/x509_obj.c')
| -rw-r--r-- | src/lib/libcrypto/x509/x509_obj.c | 75 |
1 files changed, 61 insertions, 14 deletions
diff --git a/src/lib/libcrypto/x509/x509_obj.c b/src/lib/libcrypto/x509/x509_obj.c index c0576fd6f6..1e718f76eb 100644 --- a/src/lib/libcrypto/x509/x509_obj.c +++ b/src/lib/libcrypto/x509/x509_obj.c | |||
| @@ -58,27 +58,27 @@ | |||
| 58 | 58 | ||
| 59 | #include <stdio.h> | 59 | #include <stdio.h> |
| 60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
| 61 | #include "lhash.h" | 61 | #include <openssl/lhash.h> |
| 62 | #include "objects.h" | 62 | #include <openssl/objects.h> |
| 63 | #include "x509.h" | 63 | #include <openssl/x509.h> |
| 64 | #include "buffer.h" | 64 | #include <openssl/buffer.h> |
| 65 | 65 | ||
| 66 | char *X509_NAME_oneline(a,buf,len) | 66 | char *X509_NAME_oneline(X509_NAME *a, char *buf, int len) |
| 67 | X509_NAME *a; | ||
| 68 | char *buf; | ||
| 69 | int len; | ||
| 70 | { | 67 | { |
| 71 | X509_NAME_ENTRY *ne; | 68 | X509_NAME_ENTRY *ne; |
| 72 | unsigned int i; | 69 | int i; |
| 73 | int n,lold,l,l1,l2,num,j,type; | 70 | int n,lold,l,l1,l2,num,j,type; |
| 74 | char *s,*p; | 71 | const char *s; |
| 72 | char *p; | ||
| 75 | unsigned char *q; | 73 | unsigned char *q; |
| 76 | BUF_MEM *b=NULL; | 74 | BUF_MEM *b=NULL; |
| 77 | static char hex[17]="0123456789ABCDEF"; | 75 | static char hex[17]="0123456789ABCDEF"; |
| 78 | int gs_doit[4]; | 76 | int gs_doit[4]; |
| 79 | char tmp_buf[80]; | 77 | char tmp_buf[80]; |
| 78 | #ifdef CHARSET_EBCDIC | ||
| 79 | char ebcdic_buf[1024]; | ||
| 80 | #endif | ||
| 80 | 81 | ||
| 81 | if (a == NULL) return("NO X509_NAME"); | ||
| 82 | if (buf == NULL) | 82 | if (buf == NULL) |
| 83 | { | 83 | { |
| 84 | if ((b=BUF_MEM_new()) == NULL) goto err; | 84 | if ((b=BUF_MEM_new()) == NULL) goto err; |
| @@ -86,12 +86,23 @@ int len; | |||
| 86 | b->data[0]='\0'; | 86 | b->data[0]='\0'; |
| 87 | len=200; | 87 | len=200; |
| 88 | } | 88 | } |
| 89 | if (a == NULL) | ||
| 90 | { | ||
| 91 | if(b) | ||
| 92 | { | ||
| 93 | buf=b->data; | ||
| 94 | OPENSSL_free(b); | ||
| 95 | } | ||
| 96 | strncpy(buf,"NO X509_NAME",len); | ||
| 97 | buf[len-1]='\0'; | ||
| 98 | return buf; | ||
| 99 | } | ||
| 89 | 100 | ||
| 90 | len--; /* space for '\0' */ | 101 | len--; /* space for '\0' */ |
| 91 | l=0; | 102 | l=0; |
| 92 | for (i=0; (int)i<sk_num(a->entries); i++) | 103 | for (i=0; i<sk_X509_NAME_ENTRY_num(a->entries); i++) |
| 93 | { | 104 | { |
| 94 | ne=(X509_NAME_ENTRY *)sk_value(a->entries,i); | 105 | ne=sk_X509_NAME_ENTRY_value(a->entries,i); |
| 95 | n=OBJ_obj2nid(ne->object); | 106 | n=OBJ_obj2nid(ne->object); |
| 96 | if ((n == NID_undef) || ((s=OBJ_nid2sn(n)) == NULL)) | 107 | if ((n == NID_undef) || ((s=OBJ_nid2sn(n)) == NULL)) |
| 97 | { | 108 | { |
| @@ -103,6 +114,19 @@ int len; | |||
| 103 | type=ne->value->type; | 114 | type=ne->value->type; |
| 104 | num=ne->value->length; | 115 | num=ne->value->length; |
| 105 | q=ne->value->data; | 116 | q=ne->value->data; |
| 117 | #ifdef CHARSET_EBCDIC | ||
| 118 | if (type == V_ASN1_GENERALSTRING || | ||
| 119 | type == V_ASN1_VISIBLESTRING || | ||
| 120 | type == V_ASN1_PRINTABLESTRING || | ||
| 121 | type == V_ASN1_TELETEXSTRING || | ||
| 122 | type == V_ASN1_VISIBLESTRING || | ||
| 123 | type == V_ASN1_IA5STRING) { | ||
| 124 | ascii2ebcdic(ebcdic_buf, q, | ||
| 125 | (num > sizeof ebcdic_buf) | ||
| 126 | ? sizeof ebcdic_buf : num); | ||
| 127 | q=ebcdic_buf; | ||
| 128 | } | ||
| 129 | #endif | ||
| 106 | 130 | ||
| 107 | if ((type == V_ASN1_GENERALSTRING) && ((num%4) == 0)) | 131 | if ((type == V_ASN1_GENERALSTRING) && ((num%4) == 0)) |
| 108 | { | 132 | { |
| @@ -125,7 +149,12 @@ int len; | |||
| 125 | { | 149 | { |
| 126 | if (!gs_doit[j&3]) continue; | 150 | if (!gs_doit[j&3]) continue; |
| 127 | l2++; | 151 | l2++; |
| 152 | #ifndef CHARSET_EBCDIC | ||
| 128 | if ((q[j] < ' ') || (q[j] > '~')) l2+=3; | 153 | if ((q[j] < ' ') || (q[j] > '~')) l2+=3; |
| 154 | #else | ||
| 155 | if ((os_toascii[q[j]] < os_toascii[' ']) || | ||
| 156 | (os_toascii[q[j]] > os_toascii['~'])) l2+=3; | ||
| 157 | #endif | ||
| 129 | } | 158 | } |
| 130 | 159 | ||
| 131 | lold=l; | 160 | lold=l; |
| @@ -145,11 +174,14 @@ int len; | |||
| 145 | memcpy(p,s,(unsigned int)l1); p+=l1; | 174 | memcpy(p,s,(unsigned int)l1); p+=l1; |
| 146 | *(p++)='='; | 175 | *(p++)='='; |
| 147 | 176 | ||
| 177 | #ifndef CHARSET_EBCDIC /* q was assigned above already. */ | ||
| 148 | q=ne->value->data; | 178 | q=ne->value->data; |
| 179 | #endif | ||
| 149 | 180 | ||
| 150 | for (j=0; j<num; j++) | 181 | for (j=0; j<num; j++) |
| 151 | { | 182 | { |
| 152 | if (!gs_doit[j&3]) continue; | 183 | if (!gs_doit[j&3]) continue; |
| 184 | #ifndef CHARSET_EBCDIC | ||
| 153 | n=q[j]; | 185 | n=q[j]; |
| 154 | if ((n < ' ') || (n > '~')) | 186 | if ((n < ' ') || (n > '~')) |
| 155 | { | 187 | { |
| @@ -160,16 +192,31 @@ int len; | |||
| 160 | } | 192 | } |
| 161 | else | 193 | else |
| 162 | *(p++)=n; | 194 | *(p++)=n; |
| 195 | #else | ||
| 196 | n=os_toascii[q[j]]; | ||
| 197 | if ((n < os_toascii[' ']) || | ||
| 198 | (n > os_toascii['~'])) | ||
| 199 | { | ||
| 200 | *(p++)='\\'; | ||
| 201 | *(p++)='x'; | ||
| 202 | *(p++)=hex[(n>>4)&0x0f]; | ||
| 203 | *(p++)=hex[n&0x0f]; | ||
| 204 | } | ||
| 205 | else | ||
| 206 | *(p++)=q[j]; | ||
| 207 | #endif | ||
| 163 | } | 208 | } |
| 164 | *p='\0'; | 209 | *p='\0'; |
| 165 | } | 210 | } |
| 166 | if (b != NULL) | 211 | if (b != NULL) |
| 167 | { | 212 | { |
| 168 | p=b->data; | 213 | p=b->data; |
| 169 | Free((char *)b); | 214 | OPENSSL_free(b); |
| 170 | } | 215 | } |
| 171 | else | 216 | else |
| 172 | p=buf; | 217 | p=buf; |
| 218 | if (i == 0) | ||
| 219 | *p = '\0'; | ||
| 173 | return(p); | 220 | return(p); |
| 174 | err: | 221 | err: |
| 175 | X509err(X509_F_X509_NAME_ONELINE,ERR_R_MALLOC_FAILURE); | 222 | X509err(X509_F_X509_NAME_ONELINE,ERR_R_MALLOC_FAILURE); |
