Mercurial > pidgin
changeset 18935:cb9d2b9ad6bc
- Add GnuTLS SHA1 key fingerprinter
author | William Ehlhardt <williamehlhardt@gmail.com> |
---|---|
date | Fri, 22 Jun 2007 03:18:43 +0000 |
parents | 04be1b885ef3 |
children | 895831f93380 |
files | libpurple/plugins/ssl/ssl-gnutls.c |
diffstat | 1 files changed, 29 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/plugins/ssl/ssl-gnutls.c Thu Jun 21 23:39:26 2007 +0000 +++ b/libpurple/plugins/ssl/ssl-gnutls.c Fri Jun 22 03:18:43 2007 +0000 @@ -521,6 +521,34 @@ /* Control does not reach this point */ } +static GByteArray * +x509_sha1sum(PurpleCertificate *crt) +{ + size_t hashlen = 20; /* SHA1 hashes are 20 bytes */ + size_t tmpsz = hashlen; /* Throw-away variable for GnuTLS to stomp on*/ + gnutls_x509_crt_t crt_dat; + GByteArray *hash; /**< Final hash container */ + guchar hashbuf[hashlen]; /**< Temporary buffer to contain hash */ + + g_return_val_if_fail(crt, NULL); + + crt_dat = *( (gnutls_x509_crt_t *) crt->data ); + + /* Extract the fingerprint */ + /* TODO: Errorcheck? */ + gnutls_x509_crt_get_fingerprint(crt_dat, GNUTLS_MAC_SHA, + hashbuf, &tmpsz); + + /* This shouldn't happen */ + g_return_val_if_fail(tmpsz == hashlen, NULL); + + /* Okay, now create and fill hash array */ + hash = g_byte_array_new(); + g_byte_array_append(hash, hashbuf, hashlen); + + return hash; +} + /* X.509 certificate operations provided by this plugin */ /* TODO: Flesh this out! */ static PurpleCertificateScheme x509_gnutls = { @@ -528,7 +556,7 @@ N_("X.509 Certificates"), /* User-visible scheme name */ x509_import_from_file, /* Certificate import function */ x509_destroy_certificate, /* Destroy cert */ - NULL, /* SHA1 fingerprint */ + x509_sha1sum, /* SHA1 fingerprint */ NULL, /* Subject */ NULL, /* Unique ID */ NULL /* Issuer Unique ID */