2 * Copyright (C) 2010 Collabora Ltd.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301 USA
19 * Authors: Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
26 #include <glib/gi18n.h>
29 #define DEBUG_FLAG EMPATHY_DEBUG_TLS
30 #include <libempathy/empathy-debug.h>
31 #include <libempathy/empathy-auth-factory.h>
32 #include <libempathy/empathy-server-tls-handler.h>
33 #include <libempathy/empathy-tls-verifier.h>
35 #include <libempathy-gtk/empathy-tls-dialog.h>
36 #include <libempathy-gtk/empathy-ui-utils.h>
38 #include <gnutls/gnutls.h>
40 #include <extensions/extensions.h>
43 tls_dialog_response_cb (GtkDialog *dialog,
47 EmpathyTLSCertificate *certificate = NULL;
48 EmpTLSCertificateRejectReason reason = 0;
49 EmpathyTLSDialog *tls_dialog = EMPATHY_TLS_DIALOG (dialog);
50 gboolean remember = FALSE;
52 DEBUG ("Response %d", response_id);
54 g_object_get (tls_dialog,
55 "certificate", &certificate,
57 "remember", &remember,
60 gtk_widget_destroy (GTK_WIDGET (dialog));
62 if (response_id == GTK_RESPONSE_YES)
63 empathy_tls_certificate_accept_async (certificate, NULL, NULL);
65 empathy_tls_certificate_reject_async (certificate, reason, TRUE,
69 empathy_tls_certificate_store_ca (certificate);
71 g_object_unref (certificate);
75 display_interactive_dialog (EmpathyTLSCertificate *certificate,
76 EmpTLSCertificateRejectReason reason,
79 GtkWidget *tls_dialog;
81 tls_dialog = empathy_tls_dialog_new (certificate, reason, details);
82 g_signal_connect (tls_dialog, "response",
83 G_CALLBACK (tls_dialog_response_cb), NULL);
85 gtk_widget_show (tls_dialog);
89 verifier_verify_cb (GObject *source,
94 EmpTLSCertificateRejectReason reason;
96 EmpathyTLSCertificate *certificate = NULL;
97 GHashTable *details = NULL;
100 "certificate", &certificate,
103 res = empathy_tls_verifier_verify_finish (EMPATHY_TLS_VERIFIER (source),
104 result, &reason, &details, &error);
108 DEBUG ("Error: %s", error->message);
109 display_interactive_dialog (certificate, reason, details);
111 g_error_free (error);
115 empathy_tls_certificate_accept_async (certificate, NULL, NULL);
118 g_object_unref (certificate);
122 auth_factory_new_handler_cb (EmpathyAuthFactory *factory,
123 EmpathyServerTLSHandler *handler,
126 EmpathyTLSCertificate *certificate = NULL;
127 gchar *hostname = NULL;
128 EmpathyTLSVerifier *verifier;
130 DEBUG ("New TLS server handler received from the factory");
132 g_object_get (handler,
133 "certificate", &certificate,
134 "hostname", &hostname,
137 verifier = empathy_tls_verifier_new (certificate, hostname);
138 empathy_tls_verifier_verify_async (verifier,
139 verifier_verify_cb, NULL);
141 g_object_unref (verifier);
142 g_object_unref (certificate);
150 GOptionContext *context;
151 GError *error = NULL;
152 EmpathyAuthFactory *factory;
154 g_thread_init (NULL);
156 context = g_option_context_new (N_(" - Empathy authentication helper"));
157 g_option_context_add_group (context, gtk_get_option_group (TRUE));
158 g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
160 if (!g_option_context_parse (context, &argc, &argv, &error))
162 g_print ("%s\nRun '%s --help' to see a full list of available command "
163 "line options.\n", error->message, argv[0]);
164 g_warning ("Error in empathy-auth-helper init: %s", error->message);
168 g_option_context_free (context);
171 gnutls_global_init ();
172 g_set_application_name (_("Empathy authentication helper"));
174 gtk_window_set_default_icon_name ("empathy");
175 textdomain (GETTEXT_PACKAGE);
177 factory = empathy_auth_factory_dup_singleton ();
179 g_signal_connect (factory, "new-server-tls-handler",
180 G_CALLBACK (auth_factory_new_handler_cb), NULL);
182 if (!empathy_auth_factory_register (factory, &error))
184 g_critical ("Failed to register the auth factory: %s\n", error->message);
185 g_error_free (error);
186 g_object_unref (factory);
191 DEBUG ("Empathy auth client started.");
195 g_object_unref (factory);