/pidgin/main: d8633f765a9e: Move x509_display_string() from ssl-...
Mark Doliner <[email protected]>
| Newsgroups | gmane.comp.gnome.gaim.cvs |
|---|---|
| Message-ID | <[email protected]> |
Changeset: d8633f765a9e5f57ab2db380c0307fc2043048af Author: Mark Doliner <[email protected]> Date: 2014-07-07 23:57 -0700 Branch: default URL: https://hg.pidgin.im/pidgin/main/rev/d8633f765a9e Description: Move x509_display_string() from ssl-nss.c and ssl-gnutls.c to certificate.c. We should try to keep the library-specific abstraction files as small as possible and avoid putting display logic there. The larger the files, the more likely it is that behavior will differ, and that's bad. diffstat: libpurple/certificate.c | 72 +++++++++++++++++++++++++++++++++--- libpurple/certificate.h | 8 ---- libpurple/plugins/ssl/ssl-gnutls.c | 74 -------------------------------------- libpurple/plugins/ssl/ssl-nss.c | 73 ------------------------------------- 4 files changed, 65 insertions(+), 162 deletions(-) diffs (296 lines): diff --git a/libpurple/certificate.c b/libpurple/certificate.c --- a/libpurple/certificate.c +++ b/libpurple/certificate.c @@ -491,21 +491,79 @@ purple_certificate_get_der_data(PurpleCe gchar * purple_certificate_get_display_string(PurpleCertificate *crt) { - PurpleCertificateScheme *scheme; - gchar *str; + gchar *sha_asc; + GByteArray *sha_bin; + gchar *cn, *issuer_id; + gint64 activation, expiration; + gchar *activ_str, *expir_str; + gboolean self_signed; + gchar *text; +#if GLIB_CHECK_VERSION(2,26,0) + GDateTime *act_dt, *exp_dt; +#endif g_return_val_if_fail(crt, NULL); - g_return_val_if_fail(crt->scheme, NULL); - scheme = crt->scheme; + /* Pull out the SHA1 checksum */ + sha_bin = purple_certificate_get_fingerprint_sha1(crt); + g_return_val_if_fail(sha_bin != NULL, NULL); + sha_asc = purple_base16_encode_chunked(sha_bin->data, sha_bin->len); - g_return_val_if_fail(scheme->get_display_string, NULL); + /* Get the cert Common Name */ + /* TODO: Will break on CA certs */ + cn = purple_certificate_get_subject_name(crt); - str = (scheme->get_display_string)(crt); + issuer_id = purple_certificate_get_issuer_unique_id(crt); - return str; + /* Get the certificate times */ + /* TODO: Check the times against localtime */ + /* TODO: errorcheck? */ + if (!purple_certificate_get_times(crt, &activation, &expiration)) { + purple_debug_error("certificate", + "Failed to get certificate times!\n"); + activation = expiration = 0; + } + +#if GLIB_CHECK_VERSION(2,26,0) + act_dt = g_date_time_new_from_unix_local(activation); + activ_str = g_date_time_format(act_dt, "%c"); + g_date_time_unref(act_dt); + + exp_dt = g_date_time_new_from_unix_local(expiration); + expir_str = g_date_time_format(exp_dt, "%c"); + g_date_time_unref(exp_dt); +#else + activ_str = g_strdup(ctime(&activation)); + expir_str = g_strdup(ctime(&expiration)); +#endif + + self_signed = purple_certificate_signed_by(crt, crt); + + /* Make messages */ + text = g_strdup_printf( + _("Common name: %s\n\n" + "Issued by: %s\n\n" + "Fingerprint (SHA1): %s\n\n" + "Activation date: %s\n" + "Expiration date: %s\n"), + cn ? cn : "(null)", + self_signed ? _("(self-signed)") : (issuer_id ? issuer_id : "(null)"), + sha_asc ? sha_asc : "(null)", + activ_str ? activ_str : "(null)", + expir_str ? expir_str : "(null)"); + + /* Cleanup */ + g_free(cn); + g_free(issuer_id); + g_free(sha_asc); + g_free(activ_str); + g_free(expir_str); + g_byte_array_free(sha_bin, TRUE); + + return text; } + GType purple_certificate_get_type(void) { diff --git a/libpurple/certificate.h b/libpurple/certificate.h --- a/libpurple/certificate.h +++ b/libpurple/certificate.h @@ -236,12 +236,6 @@ struct _PurpleCertificatePool * <sbr/>@crt: Certificate instance * <sbr/>Returns: Binary DER representation of certificate - must * be freed using g_byte_array_free(). - * @get_display_string: Retrieves a string representation of the certificate - * suitable for display - * <sbr/>@crt: Certificate instance - * <sbr/>Returns: User-displayable string representation of - * certificate - must be freed using - * g_free(). * * A certificate type. * @@ -275,8 +269,6 @@ struct _PurpleCertificateScheme GSList * (* import_certificates)(const gchar * filename); GByteArray * (* get_der_data)(PurpleCertificate *crt); - gchar * (* get_display_string)(PurpleCertificate *crt); - /*< private >*/ void (*_purple_reserved1)(void); }; diff --git a/libpurple/plugins/ssl/ssl-gnutls.c b/libpurple/plugins/ssl/ssl-gnutls.c --- a/libpurple/plugins/ssl/ssl-gnutls.c +++ b/libpurple/plugins/ssl/ssl-gnutls.c @@ -1227,79 +1227,6 @@ x509_get_der_data(PurpleCertificate *crt return data; } -static gchar * -x509_display_string(PurpleCertificate *crt) -{ - gchar *sha_asc; - GByteArray *sha_bin; - gchar *cn, *issuer_id; - gint64 activation, expiration; - gchar *activ_str, *expir_str; - gboolean self_signed; - gchar *text; -#if GLIB_CHECK_VERSION(2,26,0) - GDateTime *act_dt, *exp_dt; -#endif - - /* Pull out the SHA1 checksum */ - sha_bin = x509_sha1sum(crt); - g_return_val_if_fail(sha_bin != NULL, NULL); - sha_asc = purple_base16_encode_chunked(sha_bin->data, sha_bin->len); - - /* Get the cert Common Name */ - /* TODO: Will break on CA certs */ - cn = x509_common_name(crt); - - issuer_id = purple_certificate_get_issuer_unique_id(crt); - - /* Get the certificate times */ - /* TODO: Check the times against localtime */ - /* TODO: errorcheck? */ - if (!x509_times(crt, &activation, &expiration)) { - purple_debug_error("certificate", - "Failed to get certificate times!\n"); - activation = expiration = 0; - } - -#if GLIB_CHECK_VERSION(2,26,0) - act_dt = g_date_time_new_from_unix_local(activation); - activ_str = g_date_time_format(act_dt, "%c"); - g_date_time_unref(act_dt); - - exp_dt = g_date_time_new_from_unix_local(expiration); - expir_str = g_date_time_format(exp_dt, "%c"); - g_date_time_unref(exp_dt); -#else - activ_str = g_strdup(ctime(&activation)); - expir_str = g_strdup(ctime(&expiration)); -#endif - - self_signed = purple_certificate_signed_by(crt, crt); - - /* Make messages */ - text = g_strdup_printf( - _("Common name: %s\n\n" - "Issued by: %s\n\n" - "Fingerprint (SHA1): %s\n\n" - "Activation date: %s\n" - "Expiration date: %s\n"), - cn ? cn : "(null)", - self_signed ? _("(self-signed)") : (issuer_id ? issuer_id : "(null)"), - sha_asc ? sha_asc : "(null)", - activ_str ? activ_str : "(null)", - expir_str ? expir_str : "(null)"); - - /* Cleanup */ - g_free(cn); - g_free(issuer_id); - g_free(sha_asc); - g_free(activ_str); - g_free(expir_str); - g_byte_array_free(sha_bin, TRUE); - - return text; -} - /* X.509 certificate operations provided by this plugin */ static PurpleCertificateScheme x509_gnutls = { "x509", /* Scheme name */ @@ -1317,7 +1244,6 @@ static PurpleCertificateScheme x509_gnut x509_times, /* Activation/Expiration time */ x509_importcerts_from_file, /* Multiple certificates import function */ x509_get_der_data, /* Binary DER data */ - x509_display_string, /* Display representation */ NULL diff --git a/libpurple/plugins/ssl/ssl-nss.c b/libpurple/plugins/ssl/ssl-nss.c --- a/libpurple/plugins/ssl/ssl-nss.c +++ b/libpurple/plugins/ssl/ssl-nss.c @@ -946,78 +946,6 @@ x509_get_der_data(PurpleCertificate *crt return data; } -static gchar * -x509_display_string(PurpleCertificate *crt) -{ - gchar *sha_asc; - GByteArray *sha_bin; - gchar *cn, *issuer_id; - gint64 activation, expiration; - gchar *activ_str, *expir_str; - gboolean self_signed; - gchar *text; -#if GLIB_CHECK_VERSION(2,26,0) - GDateTime *act_dt, *exp_dt; -#endif - - /* Pull out the SHA1 checksum */ - sha_bin = x509_sha1sum(crt); - sha_asc = purple_base16_encode_chunked(sha_bin->data, sha_bin->len); - - /* Get the cert Common Name */ - /* TODO: Will break on CA certs */ - cn = x509_common_name(crt); - - issuer_id = purple_certificate_get_issuer_unique_id(crt); - - /* Get the certificate times */ - /* TODO: Check the times against localtime */ - /* TODO: errorcheck? */ - if (!x509_times(crt, &activation, &expiration)) { - purple_debug_error("certificate", - "Failed to get certificate times!\n"); - activation = expiration = 0; - } - -#if GLIB_CHECK_VERSION(2,26,0) - act_dt = g_date_time_new_from_unix_local(activation); - activ_str = g_date_time_format(act_dt, "%c"); - g_date_time_unref(act_dt); - - exp_dt = g_date_time_new_from_unix_local(expiration); - expir_str = g_date_time_format(exp_dt, "%c"); - g_date_time_unref(exp_dt); -#else - activ_str = g_strdup(ctime(&activation)); - expir_str = g_strdup(ctime(&expiration)); -#endif - - self_signed = purple_certificate_signed_by(crt, crt); - - /* Make messages */ - text = g_strdup_printf( - _("Common name: %s\n\n" - "Issued by: %s\n\n" - "Fingerprint (SHA1): %s\n\n" - "Activation date: %s\n" - "Expiration date: %s\n"), - cn ? cn : "(null)", - self_signed ? _("(self-signed)") : (issuer_id ? issuer_id : "(null)"), - sha_asc ? sha_asc : "(null)", - activ_str ? activ_str : "(null)", - expir_str ? expir_str : "(null)"); - - /* Cleanup */ - g_free(cn); - g_free(issuer_id); - g_free(sha_asc); - g_free(activ_str); - g_free(expir_str); - g_byte_array_free(sha_bin, TRUE); - - return text; -} - static PurpleCertificateScheme x509_nss = { "x509", /* Scheme name */ N_("X.509 Certificates"), /* User-visible scheme name */ @@ -1034,7 +962,6 @@ static PurpleCertificateScheme x509_nss x509_times, /* Activation/Expiration time */ x509_importcerts_from_file, /* Multiple certificate import function */ x509_get_der_data, /* Binary DER data */ - x509_display_string, /* Display representation */ NULL };