diff options
Diffstat (limited to 'src/lib/libcrypto/x509/x509_cmp.c')
-rw-r--r-- | src/lib/libcrypto/x509/x509_cmp.c | 119 |
1 files changed, 7 insertions, 112 deletions
diff --git a/src/lib/libcrypto/x509/x509_cmp.c b/src/lib/libcrypto/x509/x509_cmp.c index f460102f49..cd20b6d66f 100644 --- a/src/lib/libcrypto/x509/x509_cmp.c +++ b/src/lib/libcrypto/x509/x509_cmp.c | |||
@@ -57,7 +57,6 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <ctype.h> | ||
61 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
62 | #include <openssl/asn1.h> | 61 | #include <openssl/asn1.h> |
63 | #include <openssl/objects.h> | 62 | #include <openssl/objects.h> |
@@ -82,14 +81,13 @@ unsigned long X509_issuer_and_serial_hash(X509 *a) | |||
82 | unsigned long ret=0; | 81 | unsigned long ret=0; |
83 | EVP_MD_CTX ctx; | 82 | EVP_MD_CTX ctx; |
84 | unsigned char md[16]; | 83 | unsigned char md[16]; |
85 | char *f; | 84 | char str[256]; |
86 | 85 | ||
87 | EVP_MD_CTX_init(&ctx); | 86 | EVP_MD_CTX_init(&ctx); |
88 | f=X509_NAME_oneline(a->cert_info->issuer,NULL,0); | 87 | X509_NAME_oneline(a->cert_info->issuer,str,256); |
89 | ret=strlen(f); | 88 | ret=strlen(str); |
90 | EVP_DigestInit_ex(&ctx, EVP_md5(), NULL); | 89 | EVP_DigestInit_ex(&ctx, EVP_md5(), NULL); |
91 | EVP_DigestUpdate(&ctx,(unsigned char *)f,ret); | 90 | EVP_DigestUpdate(&ctx,(unsigned char *)str,ret); |
92 | OPENSSL_free(f); | ||
93 | EVP_DigestUpdate(&ctx,(unsigned char *)a->cert_info->serialNumber->data, | 91 | EVP_DigestUpdate(&ctx,(unsigned char *)a->cert_info->serialNumber->data, |
94 | (unsigned long)a->cert_info->serialNumber->length); | 92 | (unsigned long)a->cert_info->serialNumber->length); |
95 | EVP_DigestFinal_ex(&ctx,&(md[0]),NULL); | 93 | EVP_DigestFinal_ex(&ctx,&(md[0]),NULL); |
@@ -161,99 +159,6 @@ int X509_cmp(const X509 *a, const X509 *b) | |||
161 | } | 159 | } |
162 | #endif | 160 | #endif |
163 | 161 | ||
164 | |||
165 | /* Case insensitive string comparision */ | ||
166 | static int nocase_cmp(const ASN1_STRING *a, const ASN1_STRING *b) | ||
167 | { | ||
168 | int i; | ||
169 | |||
170 | if (a->length != b->length) | ||
171 | return (a->length - b->length); | ||
172 | |||
173 | for (i=0; i<a->length; i++) | ||
174 | { | ||
175 | int ca, cb; | ||
176 | |||
177 | ca = tolower(a->data[i]); | ||
178 | cb = tolower(b->data[i]); | ||
179 | |||
180 | if (ca != cb) | ||
181 | return(ca-cb); | ||
182 | } | ||
183 | return 0; | ||
184 | } | ||
185 | |||
186 | /* Case insensitive string comparision with space normalization | ||
187 | * Space normalization - ignore leading, trailing spaces, | ||
188 | * multiple spaces between characters are replaced by single space | ||
189 | */ | ||
190 | static int nocase_spacenorm_cmp(const ASN1_STRING *a, const ASN1_STRING *b) | ||
191 | { | ||
192 | unsigned char *pa = NULL, *pb = NULL; | ||
193 | int la, lb; | ||
194 | |||
195 | la = a->length; | ||
196 | lb = b->length; | ||
197 | pa = a->data; | ||
198 | pb = b->data; | ||
199 | |||
200 | /* skip leading spaces */ | ||
201 | while (la > 0 && isspace(*pa)) | ||
202 | { | ||
203 | la--; | ||
204 | pa++; | ||
205 | } | ||
206 | while (lb > 0 && isspace(*pb)) | ||
207 | { | ||
208 | lb--; | ||
209 | pb++; | ||
210 | } | ||
211 | |||
212 | /* skip trailing spaces */ | ||
213 | while (la > 0 && isspace(pa[la-1])) | ||
214 | la--; | ||
215 | while (lb > 0 && isspace(pb[lb-1])) | ||
216 | lb--; | ||
217 | |||
218 | /* compare strings with space normalization */ | ||
219 | while (la > 0 && lb > 0) | ||
220 | { | ||
221 | int ca, cb; | ||
222 | |||
223 | /* compare character */ | ||
224 | ca = tolower(*pa); | ||
225 | cb = tolower(*pb); | ||
226 | if (ca != cb) | ||
227 | return (ca - cb); | ||
228 | |||
229 | pa++; pb++; | ||
230 | la--; lb--; | ||
231 | |||
232 | if (la <= 0 || lb <= 0) | ||
233 | break; | ||
234 | |||
235 | /* is white space next character ? */ | ||
236 | if (isspace(*pa) && isspace(*pb)) | ||
237 | { | ||
238 | /* skip remaining white spaces */ | ||
239 | while (la > 0 && isspace(*pa)) | ||
240 | { | ||
241 | la--; | ||
242 | pa++; | ||
243 | } | ||
244 | while (lb > 0 && isspace(*pb)) | ||
245 | { | ||
246 | lb--; | ||
247 | pb++; | ||
248 | } | ||
249 | } | ||
250 | } | ||
251 | if (la > 0 || lb > 0) | ||
252 | return la - lb; | ||
253 | |||
254 | return 0; | ||
255 | } | ||
256 | |||
257 | int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b) | 162 | int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b) |
258 | { | 163 | { |
259 | int i,j; | 164 | int i,j; |
@@ -267,20 +172,10 @@ int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b) | |||
267 | { | 172 | { |
268 | na=sk_X509_NAME_ENTRY_value(a->entries,i); | 173 | na=sk_X509_NAME_ENTRY_value(a->entries,i); |
269 | nb=sk_X509_NAME_ENTRY_value(b->entries,i); | 174 | nb=sk_X509_NAME_ENTRY_value(b->entries,i); |
270 | j=na->value->type-nb->value->type; | 175 | j=na->value->length-nb->value->length; |
271 | if (j) return(j); | 176 | if (j) return(j); |
272 | if (na->value->type == V_ASN1_PRINTABLESTRING) | 177 | j=memcmp(na->value->data,nb->value->data, |
273 | j=nocase_spacenorm_cmp(na->value, nb->value); | 178 | na->value->length); |
274 | else if (na->value->type == V_ASN1_IA5STRING | ||
275 | && OBJ_obj2nid(na->object) == NID_pkcs9_emailAddress) | ||
276 | j=nocase_cmp(na->value, nb->value); | ||
277 | else | ||
278 | { | ||
279 | j=na->value->length-nb->value->length; | ||
280 | if (j) return(j); | ||
281 | j=memcmp(na->value->data,nb->value->data, | ||
282 | na->value->length); | ||
283 | } | ||
284 | if (j) return(j); | 179 | if (j) return(j); |
285 | j=na->set-nb->set; | 180 | j=na->set-nb->set; |
286 | if (j) return(j); | 181 | if (j) return(j); |