From 82fa83288652fb6b856b442145b10791941f3113 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Wed, 8 Sep 2010 16:56:54 +0200 Subject: Move _get_certificate_hostname() out of the verifier --- libempathy/empathy-utils.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'libempathy/empathy-utils.c') diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c index 0ee1bbcc0..89dd8003c 100644 --- a/libempathy/empathy-utils.c +++ b/libempathy/empathy-utils.c @@ -20,6 +20,10 @@ * Authors: Richard Hult * Martyn Russell * Xavier Claessens + * + * Some snippets are taken from GnuTLS 2.8.6, which is distributed under the + * same GNU Lesser General Public License 2.1 (or later) version. See + * empathy_get_x509_certified_hostname (). */ #include "config.h" @@ -739,3 +743,34 @@ tp_chanel_group_change_reason_from_folks_groups_change_reason ( { return (TpChannelGroupChangeReason) reason; } + +gchar * +empathy_get_x509_certificate_hostname (gnutls_x509_crt_t cert) +{ + gchar dns_name[256]; + gsize dns_name_size; + gint idx; + gint res = 0; + + /* this snippet is taken from GnuTLS. + * see gnutls/lib/x509/rfc2818_hostname.c + */ + for (idx = 0; res >= 0; idx++) + { + dns_name_size = sizeof (dns_name); + res = gnutls_x509_crt_get_subject_alt_name (cert, idx, + dns_name, &dns_name_size, NULL); + + if (res == GNUTLS_SAN_DNSNAME || res == GNUTLS_SAN_IPADDRESS) + return g_strndup (dns_name, dns_name_size); + } + + dns_name_size = sizeof (dns_name); + res = gnutls_x509_crt_get_dn_by_oid (cert, GNUTLS_OID_X520_COMMON_NAME, + 0, 0, dns_name, &dns_name_size); + + if (res >= 0) + return g_strndup (dns_name, dns_name_size); + + return NULL; +} -- cgit v1.2.3