From e947f3968926b2ab2b2de895b7a0e2fe3730beb8 Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Tue, 16 Nov 1999 00:56:03 +0000 Subject: [PATCH] New function X509_cmp(). --- CHANGES | 6 ++++++ crypto/x509/x509.h | 2 ++ crypto/x509/x509_cmp.c | 11 +++++++++++ crypto/x509v3/v3_purp.c | 4 +++- 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index f37645a502..574c3190ad 100644 --- a/CHANGES +++ b/CHANGES @@ -4,6 +4,12 @@ Changes between 0.9.4 and 0.9.5 [xx XXX 1999] + *) New function X509_cmp(). Oddly enough there wasn't a function + to compare two certificates. We do this by working out the SHA1 + hash and comparing that. X509_cmp() will be needed by the trust + code. + [Steve Henson] + *) Correctly increment the reference count in the SSL_SESSION pointer returned from SSL_get_session(). [Geoff Thorpe ] diff --git a/crypto/x509/x509.h b/crypto/x509/x509.h index a6e61cf6c7..d3d8030086 100644 --- a/crypto/x509/x509.h +++ b/crypto/x509/x509.h @@ -269,6 +269,7 @@ typedef struct x509_st unsigned long ex_kusage; unsigned long ex_xkusage; unsigned long ex_nscert; + unsigned char sha1_hash[SHA_DIGEST_LENGTH]; X509_CERT_AUX *aux; } X509; @@ -869,6 +870,7 @@ unsigned long X509_issuer_name_hash(X509 *a); int X509_subject_name_cmp(X509 *a,X509 *b); unsigned long X509_subject_name_hash(X509 *x); +int X509_cmp (X509 *a, X509 *b); int X509_NAME_cmp (X509_NAME *a, X509_NAME *b); unsigned long X509_NAME_hash(X509_NAME *x); diff --git a/crypto/x509/x509_cmp.c b/crypto/x509/x509_cmp.c index 0b0f1605da..62d8013360 100644 --- a/crypto/x509/x509_cmp.c +++ b/crypto/x509/x509_cmp.c @@ -61,6 +61,7 @@ #include #include #include +#include int X509_issuer_and_serial_cmp(X509 *a, X509 *b) { @@ -135,6 +136,16 @@ unsigned long X509_subject_name_hash(X509 *x) { return(X509_NAME_hash(x->cert_info->subject)); } +/* Compare two certificates: they must be identical for + * this to work. + */ +int X509_cmp(X509 *a, X509 *b) +{ + /* ensure hash is valid */ + X509_check_purpose(a, -1, 0); + X509_check_purpose(b, -1, 0); + return memcmp(a->sha1_hash, b->sha1_hash, SHA_DIGEST_LENGTH); +} int X509_NAME_cmp(X509_NAME *a, X509_NAME *b) { diff --git a/crypto/x509v3/v3_purp.c b/crypto/x509v3/v3_purp.c index d7e561e58e..6ec5f957e9 100644 --- a/crypto/x509v3/v3_purp.c +++ b/crypto/x509v3/v3_purp.c @@ -103,12 +103,13 @@ int X509_check_purpose(X509 *x, int id, int ca) x509v3_cache_extensions(x); CRYPTO_w_unlock(CRYPTO_LOCK_X509); } + if(id == -1) return 1; idx = x509_purpose_get_idx(id); if(idx == -1) return -1; pt = sk_X509_PURPOSE_value(xptable, idx); return pt->check_purpose(pt, x,ca); } - + @@ -199,6 +200,7 @@ static void x509v3_cache_extensions(X509 *x) STACK_OF(ASN1_OBJECT) *extusage; int i; if(x->ex_flags & EXFLAG_SET) return; + X509_digest(x, EVP_sha1(), x->sha1_hash, NULL); /* Does subject name match issuer ? */ if(X509_NAME_cmp(X509_get_subject_name(x), X509_get_issuer_name(x))) x->ex_flags |= EXFLAG_SS;