Mercurial > pidgin
changeset 17767:34bf1a607d51
propagate from branch 'im.pidgin.pidgin' (head 371fb91ec4fdb33fa482efe55111fe58d8758c3b)
to branch 'im.pidgin.soc.2007.certmgr' (head 2d309d214816bda0f32a1c69d4cdf467607173f3)
author | William Ehlhardt <williamehlhardt@gmail.com> |
---|---|
date | Fri, 25 May 2007 22:34:16 +0000 |
parents | fe571cfcf225 (diff) 8c056932bcc2 (current diff) |
children | 5ba545dfe2d6 |
files | |
diffstat | 3 files changed, 103 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/plugins/ssl/ssl-gnutls.c Fri May 25 20:06:37 2007 +0000 +++ b/libpurple/plugins/ssl/ssl-gnutls.c Fri May 25 22:34:16 2007 +0000 @@ -24,12 +24,14 @@ #include "plugin.h" #include "sslconn.h" #include "version.h" +#include "util.h" #define SSL_GNUTLS_PLUGIN_ID "ssl-gnutls" #ifdef HAVE_GNUTLS #include <gnutls/gnutls.h> +#include <gnutls/x509.h> typedef struct { @@ -94,6 +96,67 @@ } else { purple_debug_info("gnutls", "Handshake complete\n"); + { + const gnutls_datum_t *cert_list; + unsigned int cert_list_size = 0; + gnutls_session_t session=gnutls_data->session; + + cert_list = + gnutls_certificate_get_peers(session, &cert_list_size); + + purple_debug_info("gnutls", + "Peer provided %d certs\n", + cert_list_size); + int i; + for (i=0; i<cert_list_size; i++) + { + gchar fpr_bin[256]; + gsize fpr_bin_sz = sizeof(fpr_bin); + gchar * fpr_asc = NULL; + gchar tbuf[256]; + gsize tsz=sizeof(tbuf); + gchar * tasc = NULL; + gnutls_x509_crt_t cert; + + gnutls_x509_crt_init(&cert); + gnutls_x509_crt_import (cert, &cert_list[i], + GNUTLS_X509_FMT_DER); + + gnutls_x509_crt_get_fingerprint(cert, GNUTLS_MAC_SHA, + fpr_bin, &fpr_bin_sz); + + fpr_asc = + purple_base16_encode_chunked(fpr_bin,fpr_bin_sz); + + purple_debug_info("gnutls", + "Lvl %d SHA1 fingerprint: %s\n", + i, fpr_asc); + + tsz=sizeof(tbuf); + gnutls_x509_crt_get_serial(cert,tbuf,&tsz); + tasc= + purple_base16_encode_chunked(tbuf, tsz); + purple_debug_info("gnutls", + "Serial: %s\n", + tasc); + g_free(tasc); + + tsz=sizeof(tbuf); + gnutls_x509_crt_get_dn (cert, tbuf, &tsz); + purple_debug_info("gnutls", + "Cert DN: %s\n", + tbuf); + tsz=sizeof(tbuf); + gnutls_x509_crt_get_issuer_dn (cert, tbuf, &tsz); + purple_debug_info("gnutls", + "Cert Issuer DN: %s\n", + tbuf); + + g_free(fpr_asc); fpr_asc = NULL; + gnutls_x509_crt_deinit(cert); + } + + } gsc->connect_cb(gsc->connect_cb_data, gsc, cond); }
--- a/libpurple/util.c Fri May 25 20:06:37 2007 +0000 +++ b/libpurple/util.c Fri May 25 22:34:16 2007 +0000 @@ -155,6 +155,31 @@ return data; } +gchar * +purple_base16_encode_chunked(const guchar *data, gsize len) +{ + int i; + gchar *ascii = NULL; + + g_return_val_if_fail(data != NULL, NULL); + g_return_val_if_fail(len > 0, NULL); + + /* For each byte of input, we need 2 bytes for the hex representation + * and 1 for the colon. + * The final colon will be replaced by a terminating NULL + */ + ascii = g_malloc(len * 3 + 1); + + for (i = 0; i < len; i++) + g_snprintf(&ascii[i * 3], 4, "%02hhx:", data[i]); + + /* Replace the final colon with NULL */ + ascii[len * 3 - 1] = 0; + + return ascii; +} + + /************************************************************************** * Base64 Functions **************************************************************************/
--- a/libpurple/util.h Fri May 25 20:06:37 2007 +0000 +++ b/libpurple/util.h Fri May 25 22:34:16 2007 +0000 @@ -118,6 +118,21 @@ */ guchar *purple_base16_decode(const char *str, gsize *ret_len); +/** + * Converts a chunk of binary data to a chunked base-16 representation + * (handy for key fingerprints) + * + * Example output: 01:23:45:67:89:AB:CD:EF + * + * @param data The data to convert. + * @param len The length of the data. + * + * @return The base-16 string in the ASCII chunked encoding. Must be + * g_free'd when no longer needed. + */ +gchar *purple_base16_encode_chunked(const guchar *data, gsize len); + + /*@}*/ /**************************************************************************/