summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Ehlhardt <williamehlhardt@gmail.com>2007-08-18 05:54:49 +0000
committerWilliam Ehlhardt <williamehlhardt@gmail.com>2007-08-18 05:54:49 +0000
commitfc2e6e4f268f04986ce2802d0543f35e99d16b98 (patch)
treeda5eae69829b79159959f33343642dccfceede16
parent75a172c9113d65ec339a027a528fa0ed2c2968de (diff)
downloadpidgin-fc2e6e4f268f04986ce2802d0543f35e99d16b98.tar.gz
- Add purple_certificate_display_x509
-rw-r--r--libpurple/certificate.c61
-rw-r--r--libpurple/certificate.h10
2 files changed, 71 insertions, 0 deletions
diff --git a/libpurple/certificate.c b/libpurple/certificate.c
index 63176b64dc..f713df2b71 100644
--- a/libpurple/certificate.c
+++ b/libpurple/certificate.c
@@ -1719,3 +1719,64 @@ purple_certificate_unregister_pool(PurpleCertificatePool *pool)
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);
+}
+
+
+
+
diff --git a/libpurple/certificate.h b/libpurple/certificate.h
index d15ffe1beb..88b56a9f9e 100644
--- a/libpurple/certificate.h
+++ b/libpurple/certificate.h
@@ -762,6 +762,16 @@ purple_certificate_unregister_pool(PurpleCertificatePool *pool);
/*@}*/
+/**
+ * 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 */