talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit 574c22a71d592c6a3998f8c728917b40ea8fb5df
parent 1d4b435e302056db1a4888cc61a0c6d8a6176f0f
Author: Colin Leroy <colin@colino.net>
Date:   Tue, 30 Aug 2011 06:18:09 +0000

2011-08-30 [colin]	3.7.10cvs8

	* src/ssl_manager.c
	* src/common/ssl.c
	* src/common/ssl_certificate.c
	* src/common/ssl_certificate.h
	* src/etpan/imap-thread.c
	* src/etpan/nntp-thread.c
		Fix bug #2127, "SSL cert check uses canonical name instead of
		specified name"

Diffstat:
MChangeLog | 11+++++++++++
MPATCHSETS | 1+
Mconfigure.ac | 2+-
Msrc/common/ssl.c | 2+-
Msrc/common/ssl_certificate.c | 96+++++++++----------------------------------------------------------------------
Msrc/common/ssl_certificate.h | 5++---
Msrc/etpan/imap-thread.c | 8++++----
Msrc/etpan/nntp-thread.c | 4++--
Msrc/ssl_manager.c | 2+-
9 files changed, 34 insertions(+), 97 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,14 @@ +2011-08-30 [colin] 3.7.10cvs8 + + * src/ssl_manager.c + * src/common/ssl.c + * src/common/ssl_certificate.c + * src/common/ssl_certificate.h + * src/etpan/imap-thread.c + * src/etpan/nntp-thread.c + Fix bug #2127, "SSL cert check uses canonical name instead of + specified name" + 2011-08-29 [colin] 3.7.10cvs7 * src/prefs_account.c diff --git a/PATCHSETS b/PATCHSETS @@ -4211,3 +4211,4 @@ ( cvs diff -u -r 1.61.2.97 -r 1.61.2.98 src/account.c; cvs diff -u -r 1.382.2.579 -r 1.382.2.580 src/compose.c; cvs diff -u -r 1.105.2.166 -r 1.105.2.167 src/prefs_account.c; cvs diff -u -r 1.49.2.45 -r 1.49.2.46 src/prefs_account.h; ) > 3.7.10cvs5.patchset ( cvs diff -u -r 1.1.2.12 -r 1.1.2.13 src/plugins/pgpcore/Makefile.am; cvs diff -u -r 1.1.2.9 -r 1.1.2.10 src/plugins/pgpinline/Makefile.am; cvs diff -u -r 1.1.2.12 -r 1.1.2.13 src/plugins/pgpmime/Makefile.am; cvs diff -u -r 1.1.2.3 -r 1.1.2.4 src/plugins/smime/Makefile.am; ) > 3.7.10cvs6.patchset ( cvs diff -u -r 1.105.2.167 -r 1.105.2.168 src/prefs_account.c; ) > 3.7.10cvs7.patchset +( cvs diff -u -r 1.3.2.34 -r 1.3.2.35 src/ssl_manager.c; cvs diff -u -r 1.9.2.44 -r 1.9.2.45 src/common/ssl.c; cvs diff -u -r 1.4.2.39 -r 1.4.2.40 src/common/ssl_certificate.c; cvs diff -u -r 1.1.4.15 -r 1.1.4.16 src/common/ssl_certificate.h; cvs diff -u -r 1.1.4.115 -r 1.1.4.116 src/etpan/imap-thread.c; cvs diff -u -r 1.1.2.17 -r 1.1.2.18 src/etpan/nntp-thread.c; ) > 3.7.10cvs8.patchset diff --git a/configure.ac b/configure.ac @@ -12,7 +12,7 @@ MINOR_VERSION=7 MICRO_VERSION=10 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=7 +EXTRA_VERSION=8 EXTRA_RELEASE= EXTRA_GTK2_VERSION= diff --git a/src/common/ssl.c b/src/common/ssl.c @@ -319,7 +319,7 @@ gboolean ssl_init_socket_with_method(SockInfo *sockinfo, SSLMethod method) r = gnutls_certificate_verify_peers2(session, &status); - if (!ssl_certificate_check(cert, status, sockinfo->canonical_name, sockinfo->hostname, sockinfo->port)) { + if (!ssl_certificate_check(cert, status, sockinfo->hostname, sockinfo->port)) { gnutls_x509_crt_deinit(cert); gnutls_certificate_free_credentials(xcred); gnutls_deinit(session); diff --git a/src/common/ssl_certificate.c b/src/common/ssl_certificate.c @@ -63,52 +63,6 @@ static gchar *get_certificate_path(const gchar *host, const gchar *port, const g host, ".", port, ".cert", NULL); } -static SSLCertificate *ssl_certificate_new_lookup(gnutls_x509_crt x509_cert, gchar *host, gushort port, gboolean lookup); -static char * get_fqdn(char *host) -{ -#ifdef INET6 - gint gai_err; - struct addrinfo hints, *res; -#else - struct hostent *hp; -#endif - - if (host == NULL || strlen(host) == 0) - return g_strdup(""); -#ifdef INET6 - memset(&hints, 0, sizeof(hints)); - hints.ai_flags = AI_CANONNAME; - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - hints.ai_protocol = IPPROTO_TCP; - - gai_err = getaddrinfo(host, NULL, &hints, &res); - if (gai_err != 0) { - g_warning("getaddrinfo for %s failed: %s\n", - host, gai_strerror(gai_err)); - return g_strdup(host); - } - if (res != NULL) { - if (res->ai_canonname && strlen(res->ai_canonname)) { - gchar *fqdn = g_strdup(res->ai_canonname); - freeaddrinfo(res); - return fqdn; - } else { - freeaddrinfo(res); - return g_strdup(host); - } - } else { - return g_strdup(host); - } -#else - hp = my_gethostbyname(host); - if (hp == NULL) - return g_strdup(host); /*caller should free*/ - else - return g_strdup(hp->h_name); -#endif -} - char * readable_fingerprint(unsigned char *src, int len) { int i=0; @@ -173,7 +127,7 @@ static gnutls_x509_crt x509_crt_copy(gnutls_x509_crt src) } #endif -static SSLCertificate *ssl_certificate_new_lookup(gnutls_x509_crt x509_cert, gchar *host, gushort port, gboolean lookup) +static SSLCertificate *ssl_certificate_new(gnutls_x509_crt x509_cert, const gchar *host, gushort port) { SSLCertificate *cert = g_new0(SSLCertificate, 1); size_t n; @@ -185,10 +139,7 @@ static SSLCertificate *ssl_certificate_new_lookup(gnutls_x509_crt x509_cert, gch } cert->x509_cert = x509_crt_copy(x509_cert); cert->status = (guint)-1; - if (lookup) - cert->host = get_fqdn(host); - else - cert->host = g_strdup(host); + cert->host = g_strdup(host); cert->port = port; /* fingerprint */ @@ -402,37 +353,26 @@ void ssl_certificate_delete_from_disk(SSLCertificate *cert) g_free(buf); } -SSLCertificate *ssl_certificate_find (gchar *host, gushort port, const gchar *fingerprint) -{ - return ssl_certificate_find_lookup (host, port, fingerprint, TRUE); -} - -SSLCertificate *ssl_certificate_find_lookup (gchar *host, gushort port, const gchar *fingerprint, gboolean lookup) +SSLCertificate *ssl_certificate_find (const gchar *host, gushort port, const gchar *fingerprint) { gchar *file = NULL; gchar *buf; - gchar *fqdn_host; SSLCertificate *cert = NULL; gnutls_x509_crt tmp_x509; FILE *fp = NULL; gboolean must_rename = FALSE; - if (lookup) - fqdn_host = get_fqdn(host); - else - fqdn_host = g_strdup(host); - buf = g_strdup_printf("%d", port); if (fingerprint != NULL) { - file = get_certificate_path(fqdn_host, buf, fingerprint); + file = get_certificate_path(host, buf, fingerprint); fp = g_fopen(file, "rb"); } if (fp == NULL) { /* see if we have the old one */ debug_print("didn't get %s\n", file); g_free(file); - file = get_certificate_path(fqdn_host, buf, NULL); + file = get_certificate_path(host, buf, NULL); fp = g_fopen(file, "rb"); if (fp) { @@ -444,13 +384,12 @@ SSLCertificate *ssl_certificate_find_lookup (gchar *host, gushort port, const gc } if (fp == NULL) { g_free(file); - g_free(fqdn_host); g_free(buf); return NULL; } if ((tmp_x509 = gnutls_d2i_X509_fp(fp, 0)) != NULL) { - cert = ssl_certificate_new_lookup(tmp_x509, fqdn_host, port, lookup); + cert = ssl_certificate_new(tmp_x509, host, port); debug_print("got cert %p\n", cert); gnutls_x509_crt_deinit(tmp_x509); } @@ -458,15 +397,14 @@ SSLCertificate *ssl_certificate_find_lookup (gchar *host, gushort port, const gc g_free(file); if (must_rename) { - gchar *old = get_certificate_path(fqdn_host, buf, NULL); - gchar *new = get_certificate_path(fqdn_host, buf, fingerprint); + gchar *old = get_certificate_path(host, buf, NULL); + gchar *new = get_certificate_path(host, buf, fingerprint); if (strcmp(old, new)) move_file(old, new, TRUE); g_free(old); g_free(new); } g_free(buf); - g_free(fqdn_host); return cert; } @@ -605,30 +543,19 @@ char *ssl_certificate_check_signer (gnutls_x509_crt cert, guint status) return NULL; } -gboolean ssl_certificate_check (gnutls_x509_crt x509_cert, guint status, gchar *fqdn, gchar *host, gushort port) +gboolean ssl_certificate_check (gnutls_x509_crt x509_cert, guint status, const gchar *host, gushort port) { SSLCertificate *current_cert = NULL; SSLCertificate *known_cert; SSLCertHookData cert_hook_data; - gchar *fqdn_host = NULL; gchar *fingerprint; size_t n; unsigned char md[128]; - if (fqdn) - fqdn_host = g_strdup(fqdn); - else if (host) - fqdn_host = get_fqdn(host); - else { - g_warning("no host!\n"); - return FALSE; - } - - current_cert = ssl_certificate_new_lookup(x509_cert, fqdn_host, port, FALSE); + current_cert = ssl_certificate_new(x509_cert, host, port); if (current_cert == NULL) { debug_print("Buggy certificate !\n"); - g_free(fqdn_host); return FALSE; } @@ -638,10 +565,9 @@ gboolean ssl_certificate_check (gnutls_x509_crt x509_cert, guint status, gchar * gnutls_x509_crt_get_fingerprint(x509_cert, GNUTLS_DIG_MD5, md, &n); fingerprint = readable_fingerprint(md, n); - known_cert = ssl_certificate_find_lookup (fqdn_host, port, fingerprint, FALSE); + known_cert = ssl_certificate_find(host, port, fingerprint); g_free(fingerprint); - g_free(fqdn_host); if (known_cert == NULL) { cert_hook_data.cert = current_cert; diff --git a/src/common/ssl_certificate.h b/src/common/ssl_certificate.h @@ -56,9 +56,8 @@ struct _SSLCertHookData gboolean accept; }; -SSLCertificate *ssl_certificate_find (gchar *host, gushort port, const gchar *fingerprint); -SSLCertificate *ssl_certificate_find_lookup (gchar *host, gushort port, const gchar *fingerprint, gboolean lookup); -gboolean ssl_certificate_check (gnutls_x509_crt x509_cert, guint status, gchar *fqdn, gchar *host, gushort port); +SSLCertificate *ssl_certificate_find (const gchar *host, gushort port, const gchar *fingerprint); +gboolean ssl_certificate_check (gnutls_x509_crt x509_cert, guint status, const gchar *host, gushort port); void ssl_certificate_destroy(SSLCertificate *cert); void ssl_certificate_delete_from_disk(SSLCertificate *cert); char * readable_fingerprint(unsigned char *src, int len); diff --git a/src/etpan/imap-thread.c b/src/etpan/imap-thread.c @@ -535,8 +535,8 @@ static int etpan_certificate_check(const unsigned char *certificate, int len, vo if (cert == NULL) { g_warning("IMAP: can't get cert\n"); return 0; - } else if (ssl_certificate_check(cert, NULL, - (gchar *)param->server, (gushort)param->port) == TRUE) { + } else if (ssl_certificate_check(cert, (gchar *)param->server, + (gushort)param->port) == TRUE) { X509_free(cert); return 0; } else { @@ -560,8 +560,8 @@ static int etpan_certificate_check(const unsigned char *certificate, int len, vo if (gnutls_x509_crt_import(cert, &tmp, GNUTLS_X509_FMT_DER) < 0) { g_warning("IMAP: can't get cert\n"); return 0; - } else if (ssl_certificate_check(cert, (guint)-1, NULL, - (gchar *)param->server, (gushort)param->port) == TRUE) { + } else if (ssl_certificate_check(cert, (guint)-1, (gchar *)param->server, + (gushort)param->port) == TRUE) { gnutls_x509_crt_deinit(cert); return 0; } else { diff --git a/src/etpan/nntp-thread.c b/src/etpan/nntp-thread.c @@ -386,7 +386,7 @@ static int etpan_certificate_check(const unsigned char *certificate, int len, vo if (cert == NULL) { g_warning("nntp: can't get cert\n"); return 0; - } else if (ssl_certificate_check(cert, NULL, + } else if (ssl_certificate_check(cert, (gchar *)param->server, (gushort)param->port) == TRUE) { X509_free(cert); return 0; @@ -411,7 +411,7 @@ static int etpan_certificate_check(const unsigned char *certificate, int len, vo if (gnutls_x509_crt_import(cert, &tmp, GNUTLS_X509_FMT_DER) < 0) { g_warning("nntp: can't get cert\n"); return 0; - } else if (ssl_certificate_check(cert, (guint)-1, NULL, + } else if (ssl_certificate_check(cert, (guint)-1, (gchar *)param->server, (gushort)param->port) == TRUE) { gnutls_x509_crt_deinit(cert); return 0; diff --git a/src/ssl_manager.c b/src/ssl_manager.c @@ -348,7 +348,7 @@ static void ssl_manager_load_certs (void) port = get_port(d->d_name); fp = get_fingerprint(d->d_name); - cert = ssl_certificate_find_lookup(server, atoi(port), fp, FALSE); + cert = ssl_certificate_find(server, atoi(port), fp); ssl_manager_list_view_insert_cert(manager.certlist, NULL, server, port, cert);