From 00cc78476a3926f64b531be08ff96dc817e63367 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Wed, 18 Apr 2012 15:25:27 +0200 Subject: Use TpTpTLSCertificate https://bugzilla.gnome.org/show_bug.cgi?id=674318 --- libempathy/empathy-server-tls-handler.c | 31 +++++++---------- libempathy/empathy-server-tls-handler.h | 6 ++-- libempathy/empathy-tls-verifier.c | 61 ++++++++++++++++----------------- libempathy/empathy-tls-verifier.h | 8 ++--- 4 files changed, 46 insertions(+), 60 deletions(-) (limited to 'libempathy') diff --git a/libempathy/empathy-server-tls-handler.c b/libempathy/empathy-server-tls-handler.c index b19e9cfde..dd3e7bb78 100644 --- a/libempathy/empathy-server-tls-handler.c +++ b/libempathy/empathy-server-tls-handler.c @@ -22,12 +22,8 @@ #include "empathy-server-tls-handler.h" -#include -#include - #define DEBUG_FLAG EMPATHY_DEBUG_TLS #include "empathy-debug.h" -#include "empathy-tls-certificate.h" #include "empathy-utils.h" #include "extensions/extensions.h" @@ -45,7 +41,7 @@ enum { typedef struct { TpChannel *channel; - EmpathyTLSCertificate *certificate; + TpTLSCertificate *certificate; gchar *hostname; gchar **reference_identities; @@ -63,14 +59,12 @@ tls_certificate_prepared_cb (GObject *source, GAsyncResult *result, gpointer user_data) { - EmpathyTLSCertificate *certificate = EMPATHY_TLS_CERTIFICATE (source); + TpTLSCertificate *certificate = TP_TLS_CERTIFICATE (source); EmpathyServerTLSHandler *self = user_data; GError *error = NULL; EmpathyServerTLSHandlerPriv *priv = GET_PRIV (self); - empathy_tls_certificate_prepare_finish (certificate, result, &error); - - if (error != NULL) + if (!tp_proxy_prepare_finish (certificate, result, &error)) { g_simple_async_result_set_from_error (priv->async_init_res, error); g_error_free (error); @@ -106,8 +100,8 @@ tls_handler_init_async (GAsyncInitable *initable, const gchar *hostname; const gchar * const *identities; const gchar *bus_name; - TpDBusDaemon *dbus; GError *error = NULL; + GQuark features[] = { TP_TLS_CERTIFICATE_FEATURE_CORE, 0 }; /* * Used when channel doesn't implement ReferenceIdentities. A GStrv * with [0] the hostname, and [1] a NULL terminator. @@ -155,17 +149,16 @@ tls_handler_init_async (GAsyncInitable *initable, cert_object_path = tp_asv_get_object_path (properties, EMP_IFACE_CHANNEL_TYPE_SERVER_TLS_CONNECTION ".ServerCertificate"); bus_name = tp_proxy_get_bus_name (TP_PROXY (priv->channel)); - dbus = tp_proxy_get_dbus_daemon (TP_PROXY (priv->channel)); - DEBUG ("Creating an EmpathyTLSCertificate for path %s, bus name %s", + DEBUG ("Creating an TpTLSCertificate for path %s, bus name %s", cert_object_path, bus_name); - priv->certificate = empathy_tls_certificate_new (dbus, bus_name, + priv->certificate = tp_tls_certificate_new (TP_PROXY (priv->channel), cert_object_path, &error); if (error != NULL) { - DEBUG ("Unable to create the EmpathyTLSCertificate: error %s", + DEBUG ("Unable to create the TpTLSCertificate: error %s", error->message); g_simple_async_result_set_from_error (priv->async_init_res, error); @@ -177,7 +170,7 @@ tls_handler_init_async (GAsyncInitable *initable, return; } - empathy_tls_certificate_prepare_async (priv->certificate, + tp_proxy_prepare_async (priv->certificate, features, tls_certificate_prepared_cb, self); } @@ -268,9 +261,9 @@ empathy_server_tls_handler_class_init (EmpathyServerTLSHandlerClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); g_object_class_install_property (oclass, PROP_CHANNEL, pspec); - pspec = g_param_spec_object ("certificate", "The EmpathyTLSCertificate", - "The EmpathyTLSCertificate carried by the channel.", - EMPATHY_TYPE_TLS_CERTIFICATE, + pspec = g_param_spec_object ("certificate", "The TpTLSCertificate", + "The TpTLSCertificate carried by the channel.", + TP_TYPE_TLS_CERTIFICATE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); g_object_class_install_property (oclass, PROP_TLS_CERTIFICATE, pspec); @@ -325,7 +318,7 @@ empathy_server_tls_handler_new_finish (GAsyncResult *result, return NULL; } -EmpathyTLSCertificate * +TpTLSCertificate * empathy_server_tls_handler_get_certificate (EmpathyServerTLSHandler *self) { EmpathyServerTLSHandlerPriv *priv = GET_PRIV (self); diff --git a/libempathy/empathy-server-tls-handler.h b/libempathy/empathy-server-tls-handler.h index 1fae98b0a..f4caf3539 100644 --- a/libempathy/empathy-server-tls-handler.h +++ b/libempathy/empathy-server-tls-handler.h @@ -24,9 +24,7 @@ #include #include -#include - -#include +#include G_BEGIN_DECLS @@ -65,7 +63,7 @@ void empathy_server_tls_handler_new_async (TpChannel *channel, EmpathyServerTLSHandler * empathy_server_tls_handler_new_finish ( GAsyncResult *result, GError **error); -EmpathyTLSCertificate * empathy_server_tls_handler_get_certificate ( +TpTLSCertificate * empathy_server_tls_handler_get_certificate ( EmpathyServerTLSHandler *self); G_END_DECLS diff --git a/libempathy/empathy-tls-verifier.c b/libempathy/empathy-tls-verifier.c index dbf083dba..a9a4f3818 100644 --- a/libempathy/empathy-tls-verifier.c +++ b/libempathy/empathy-tls-verifier.c @@ -24,8 +24,6 @@ #include #include -#include - #include "empathy-tls-verifier.h" #include @@ -48,7 +46,7 @@ enum { }; typedef struct { - EmpathyTLSCertificate *certificate; + TpTLSCertificate *certificate; gchar *hostname; gchar **reference_identities; @@ -61,7 +59,7 @@ typedef struct { static gboolean verification_output_to_reason (gint res, guint verify_output, - EmpTLSCertificateRejectReason *reason) + TpTLSCertificateRejectReason *reason) { gboolean retval = TRUE; @@ -75,13 +73,13 @@ verification_output_to_reason (gint res, switch (res) { case GNUTLS_E_INSUFFICIENT_CREDENTIALS: - *reason = EMP_TLS_CERTIFICATE_REJECT_REASON_UNTRUSTED; + *reason = TP_TLS_CERTIFICATE_REJECT_REASON_UNTRUSTED; break; case GNUTLS_E_CONSTRAINT_ERROR: - *reason = EMP_TLS_CERTIFICATE_REJECT_REASON_LIMIT_EXCEEDED; + *reason = TP_TLS_CERTIFICATE_REJECT_REASON_LIMIT_EXCEEDED; break; default: - *reason = EMP_TLS_CERTIFICATE_REJECT_REASON_UNKNOWN; + *reason = TP_TLS_CERTIFICATE_REJECT_REASON_UNKNOWN; break; } @@ -94,17 +92,17 @@ verification_output_to_reason (gint res, retval = FALSE; if (verify_output & GNUTLS_CERT_SIGNER_NOT_FOUND) - *reason = EMP_TLS_CERTIFICATE_REJECT_REASON_SELF_SIGNED; + *reason = TP_TLS_CERTIFICATE_REJECT_REASON_SELF_SIGNED; else if (verify_output & GNUTLS_CERT_SIGNER_NOT_CA) - *reason = EMP_TLS_CERTIFICATE_REJECT_REASON_UNTRUSTED; + *reason = TP_TLS_CERTIFICATE_REJECT_REASON_UNTRUSTED; else if (verify_output & GNUTLS_CERT_INSECURE_ALGORITHM) - *reason = EMP_TLS_CERTIFICATE_REJECT_REASON_INSECURE; + *reason = TP_TLS_CERTIFICATE_REJECT_REASON_INSECURE; else if (verify_output & GNUTLS_CERT_NOT_ACTIVATED) - *reason = EMP_TLS_CERTIFICATE_REJECT_REASON_NOT_ACTIVATED; + *reason = TP_TLS_CERTIFICATE_REJECT_REASON_NOT_ACTIVATED; else if (verify_output & GNUTLS_CERT_EXPIRED) - *reason = EMP_TLS_CERTIFICATE_REJECT_REASON_EXPIRED; + *reason = TP_TLS_CERTIFICATE_REJECT_REASON_EXPIRED; else - *reason = EMP_TLS_CERTIFICATE_REJECT_REASON_UNKNOWN; + *reason = TP_TLS_CERTIFICATE_REJECT_REASON_UNKNOWN; goto out; } @@ -201,7 +199,7 @@ complete_verification (EmpathyTLSVerifier *self) static void abort_verification (EmpathyTLSVerifier *self, - EmpTLSCertificateRejectReason reason) + TpTLSCertificateRejectReason reason) { EmpathyTLSVerifierPriv *priv = GET_PRIV (self); @@ -251,8 +249,8 @@ perform_verification (EmpathyTLSVerifier *self, GcrCertificateChain *chain) { gboolean ret = FALSE; - EmpTLSCertificateRejectReason reason = - EMP_TLS_CERTIFICATE_REJECT_REASON_UNKNOWN; + TpTLSCertificateRejectReason reason = + TP_TLS_CERTIFICATE_REJECT_REASON_UNKNOWN; gnutls_x509_crt_t *list, *anchors; guint n_list, n_anchors; guint verify_output; @@ -282,7 +280,7 @@ perform_verification (EmpathyTLSVerifier *self, &anchors, &n_anchors); if (list == NULL || n_list == 0) { g_warn_if_reached (); - abort_verification (self, EMP_TLS_CERTIFICATE_REJECT_REASON_UNKNOWN); + abort_verification (self, TP_TLS_CERTIFICATE_REJECT_REASON_UNKNOWN); goto out; } @@ -328,7 +326,7 @@ perform_verification (EmpathyTLSVerifier *self, g_free (certified_hostname); abort_verification (self, - EMP_TLS_CERTIFICATE_REJECT_REASON_HOSTNAME_MISMATCH); + TP_TLS_CERTIFICATE_REJECT_REASON_HOSTNAME_MISMATCH); goto out; } @@ -465,9 +463,9 @@ empathy_tls_verifier_class_init (EmpathyTLSVerifierClass *klass) oclass->finalize = empathy_tls_verifier_finalize; oclass->dispose = empathy_tls_verifier_dispose; - pspec = g_param_spec_object ("certificate", "The EmpathyTLSCertificate", - "The EmpathyTLSCertificate to be verified.", - EMPATHY_TYPE_TLS_CERTIFICATE, + pspec = g_param_spec_object ("certificate", "The TpTLSCertificate", + "The TpTLSCertificate to be verified.", + TP_TYPE_TLS_CERTIFICATE, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); g_object_class_install_property (oclass, PROP_TLS_CERTIFICATE, pspec); @@ -486,10 +484,11 @@ empathy_tls_verifier_class_init (EmpathyTLSVerifierClass *klass) } EmpathyTLSVerifier * -empathy_tls_verifier_new (EmpathyTLSCertificate *certificate, - const gchar *hostname, const gchar **reference_identities) +empathy_tls_verifier_new (TpTLSCertificate *certificate, + const gchar *hostname, + const gchar **reference_identities) { - g_assert (EMPATHY_IS_TLS_CERTIFICATE (certificate)); + g_assert (TP_IS_TLS_CERTIFICATE (certificate)); g_assert (hostname != NULL); g_assert (reference_identities != NULL); @@ -507,7 +506,7 @@ empathy_tls_verifier_verify_async (EmpathyTLSVerifier *self, { GcrCertificateChain *chain; GcrCertificate *cert; - GPtrArray *cert_data = NULL; + GPtrArray *cert_data; GArray *data; guint idx; EmpathyTLSVerifierPriv *priv = GET_PRIV (self); @@ -516,7 +515,7 @@ empathy_tls_verifier_verify_async (EmpathyTLSVerifier *self, g_return_if_fail (priv->verify_result == NULL); - g_object_get (priv->certificate, "cert-data", &cert_data, NULL); + cert_data = tp_tls_certificate_get_cert_data (priv->certificate); g_return_if_fail (cert_data); priv->verify_result = g_simple_async_result_new (G_OBJECT (self), @@ -535,13 +534,12 @@ empathy_tls_verifier_verify_async (EmpathyTLSVerifier *self, NULL, perform_verification_cb, g_object_ref (self)); g_object_unref (chain); - g_boxed_free (TP_ARRAY_TYPE_UCHAR_ARRAY_LIST, cert_data); } gboolean empathy_tls_verifier_verify_finish (EmpathyTLSVerifier *self, GAsyncResult *res, - EmpTLSCertificateRejectReason *reason, + TpTLSCertificateRejectReason *reason, GHashTable **details, GError **error) { @@ -565,7 +563,7 @@ empathy_tls_verifier_verify_finish (EmpathyTLSVerifier *self, } if (reason != NULL) - *reason = EMP_TLS_CERTIFICATE_REJECT_REASON_UNKNOWN; + *reason = TP_TLS_CERTIFICATE_REJECT_REASON_UNKNOWN; return TRUE; } @@ -575,11 +573,11 @@ empathy_tls_verifier_store_exception (EmpathyTLSVerifier *self) { GArray *data; GcrCertificate *cert; - GPtrArray *cert_data = NULL; + GPtrArray *cert_data; GError *error = NULL; EmpathyTLSVerifierPriv *priv = GET_PRIV (self); - g_object_get (priv->certificate, "cert-data", &cert_data, NULL); + cert_data = tp_tls_certificate_get_cert_data (priv->certificate); g_return_if_fail (cert_data); if (!cert_data->len) @@ -600,5 +598,4 @@ empathy_tls_verifier_store_exception (EmpathyTLSVerifier *self) DEBUG ("Can't store the pinned certificate: %s", error->message); g_object_unref (cert); - g_boxed_free (TP_ARRAY_TYPE_UCHAR_ARRAY_LIST, cert_data); } diff --git a/libempathy/empathy-tls-verifier.h b/libempathy/empathy-tls-verifier.h index 436149336..2f66acb9c 100644 --- a/libempathy/empathy-tls-verifier.h +++ b/libempathy/empathy-tls-verifier.h @@ -24,9 +24,7 @@ #include #include -#include - -#include +#include G_BEGIN_DECLS @@ -61,7 +59,7 @@ GType empathy_tls_verifier_get_type (void); EmpathyTLSVerifierClass)) EmpathyTLSVerifier * empathy_tls_verifier_new ( - EmpathyTLSCertificate *certificate, + TpTLSCertificate *certificate, const gchar *hostname, const gchar **reference_identities); @@ -71,7 +69,7 @@ void empathy_tls_verifier_verify_async (EmpathyTLSVerifier *self, gboolean empathy_tls_verifier_verify_finish (EmpathyTLSVerifier *self, GAsyncResult *res, - EmpTLSCertificateRejectReason *reason, + TpTLSCertificateRejectReason *reason, GHashTable **details, GError **error); -- cgit v1.2.3