Mercurial > pidgin.yaz
changeset 19329:e93db0c87b26
- Add purple_certificate_display_x509
author | William Ehlhardt <williamehlhardt@gmail.com> |
---|---|
date | Sat, 18 Aug 2007 05:54:49 +0000 |
parents | 8634792bdaad |
children | b65a23799dc2 |
files | libpurple/certificate.c libpurple/certificate.h |
diffstat | 2 files changed, 71 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/certificate.c Sat Aug 18 04:13:16 2007 +0000 +++ b/libpurple/certificate.c Sat Aug 18 05:54:49 2007 +0000 @@ -1719,3 +1719,64 @@ pool->name); return TRUE; } + +/****************************************************************************/ +/* Scheme-specific functions */ +/****************************************************************************/ + +void +purple_certificate_display_x509(PurpleCertificate *crt) +{ + gchar *sha_asc; + GByteArray *sha_bin; + gchar *cn; + time_t activation, expiration; + /* Length of these buffers is dictated by 'man ctime_r' */ + gchar activ_str[26], expir_str[26]; + gchar *title, *primary, *secondary; + + /* Pull out the SHA1 checksum */ + sha_bin = purple_certificate_get_fingerprint_sha1(crt); + /* Now decode it for display */ + sha_asc = purple_base16_encode_chunked(sha_bin->data, + sha_bin->len); + + /* Get the cert Common Name */ + /* TODO: Will break on CA certs */ + cn = purple_certificate_get_subject_name(crt); + + /* Get the certificate times */ + /* TODO: Check the times against localtime */ + /* TODO: errorcheck? */ + g_assert(purple_certificate_get_times(crt, &activation, &expiration)); + ctime_r(&activation, activ_str); + ctime_r(&expiration, expir_str); + + /* Make messages */ + title = g_strdup_printf(_("Certificate: %s"), cn); + primary = NULL; + secondary = g_strdup_printf(_("Common name: %s\n\n" + "Fingerprint (SHA1): %s\n\n" + "Activation date: %s\n" + "Expiration date: %s\n"), + cn, sha_asc, activ_str, expir_str); + + /* Make a semi-pretty display */ + purple_notify_info( + NULL, /* TODO: Find what the handle ought to be */ + title, + primary, + secondary); + + /* Cleanup */ + g_free(cn); + g_free(title); + g_free(primary); + g_free(secondary); + g_free(sha_asc); + g_byte_array_free(sha_bin, TRUE); +} + + + +
--- a/libpurple/certificate.h Sat Aug 18 04:13:16 2007 +0000 +++ b/libpurple/certificate.h Sat Aug 18 05:54:49 2007 +0000 @@ -762,6 +762,16 @@ /*@}*/ +/** + * Displays a window showing X.509 certificate information + * + * @param crt Certificate under an "x509" Scheme + * @TODO Will break on CA certs, as they have no Common Name + */ +void +purple_certificate_display_x509(PurpleCertificate *crt); + + #ifdef __cplusplus } #endif /* __cplusplus */