Thu, 01 Jun 2017 21:35:39 -0500
libpurple: Use default marshaller for GObject signals
Since 2.30 it's been possible to use a default c_marshaller by
passing NULL to g_signal_new(). It has since become the recommended
way of creating signals.
https://developer.gnome.org/gobject/stable/howto-signals.html
This patch ports libpurple to use this method instead of generating
its own marshallers with glib-genmarshal.
|
37620
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
1 | /* |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
2 | * |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
3 | * purple |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
4 | * |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
5 | * Purple is the legal property of its developers, whose names are too numerous |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
6 | * to list here. Please refer to the COPYRIGHT file distributed with this |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
7 | * source distribution. |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
8 | * |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
9 | * This program is free software; you can redistribute it and/or modify |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
10 | * it under the terms of the GNU General Public License as published by |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
11 | * the Free Software Foundation; either version 2 of the License, or |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
12 | * (at your option) any later version. |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
13 | * |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
14 | * This program is distributed in the hope that it will be useful, |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
17 | * GNU General Public License for more details. |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
18 | * |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
19 | * You should have received a copy of the GNU General Public License |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
20 | * along with this program; if not, write to the Free Software |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
22 | */ |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
23 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
24 | #include "internal.h" |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
25 | #include "tls-certificate.h" |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
26 | #include "debug.h" |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
27 | #include "util.h" |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
28 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
29 | /* Makes a filename path for a certificate. If id is NULL, |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
30 | * just return the directory |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
31 | */ |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
32 | static gchar * |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
33 | make_certificate_path(const gchar *id) |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
34 | { |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
35 | return g_build_filename(purple_user_dir(), |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
36 | "certificates", "tls", |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
37 | id != NULL ? purple_escape_filename(id) : NULL, |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
38 | NULL); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
39 | } |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
40 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
41 | /* Creates the certificate directory if it doesn't exist, |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
42 | * returns TRUE if it's successful or it already exists, |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
43 | * returns FALSE if there was an error. |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
44 | */ |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
45 | static gboolean |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
46 | ensure_certificate_dir(GError **error) |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
47 | { |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
48 | gchar *dir = make_certificate_path(NULL); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
49 | gboolean ret = TRUE; |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
50 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
51 | if (purple_build_dir(dir, 0700) != 0) { |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
52 | g_set_error_literal(error, G_FILE_ERROR, |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
53 | g_file_error_from_errno(errno), |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
54 | g_strerror(errno)); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
55 | ret = FALSE; |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
56 | } |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
57 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
58 | g_free(dir); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
59 | return ret; |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
60 | } |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
61 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
62 | GList * |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
63 | purple_tls_certificate_list_ids() |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
64 | { |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
65 | gchar *dir_path; |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
66 | GDir *dir; |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
67 | const gchar *entry; |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
68 | GList *idlist = NULL; |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
69 | GError *error = NULL; |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
70 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
71 | /* Ensure certificate directory exists */ |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
72 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
73 | if (!ensure_certificate_dir(&error)) { |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
74 | purple_debug_error("tls-certificate", |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
75 | "Error creating certificate directory: %s", |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
76 | error->message); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
77 | g_clear_error(&error); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
78 | return NULL; |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
79 | } |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
80 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
81 | /* Open certificate directory */ |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
82 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
83 | dir_path = make_certificate_path(NULL); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
84 | dir = g_dir_open(dir_path, 0, &error); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
85 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
86 | if (dir == NULL) { |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
87 | purple_debug_error("tls-certificate", |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
88 | "Error opening certificate directory (%s): %s", |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
89 | dir_path, error->message); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
90 | g_free(dir_path); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
91 | g_clear_error(&error); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
92 | return NULL; |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
93 | } |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
94 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
95 | g_free(dir_path); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
96 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
97 | /* Traverse the directory listing and create an idlist */ |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
98 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
99 | while ((entry = g_dir_read_name(dir)) != NULL) { |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
100 | /* Unescape the filename |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
101 | * (GLib owns original string) |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
102 | */ |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
103 | const char *unescaped = purple_unescape_filename(entry); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
104 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
105 | /* Copy the entry name into our list |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
106 | * (Purple own the escaped string) |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
107 | */ |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
108 | idlist = g_list_prepend(idlist, g_strdup(unescaped)); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
109 | } |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
110 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
111 | g_dir_close(dir); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
112 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
113 | return idlist; |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
114 | } |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
115 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
116 | void |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
117 | purple_tls_certificate_free_ids(GList *ids) |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
118 | { |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
119 | g_list_free_full(ids, g_free); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
120 | } |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
121 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
122 | GTlsCertificate * |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
123 | purple_tls_certificate_new_from_id(const gchar *id, GError **error) |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
124 | { |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
125 | GTlsCertificate *cert; |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
126 | gchar *path; |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
127 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
128 | g_return_val_if_fail(id != NULL && id[0] != '\0', NULL); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
129 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
130 | /* Load certificate from file if it exists */ |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
131 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
132 | path = make_certificate_path(id); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
133 | cert = g_tls_certificate_new_from_file(path, error); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
134 | g_free(path); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
135 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
136 | return cert; |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
137 | } |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
138 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
139 | gboolean |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
140 | purple_tls_certificate_trust(const gchar *id, GTlsCertificate *certificate, |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
141 | GError **error) |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
142 | { |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
143 | gchar *path; |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
144 | gchar *pem = NULL; |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
145 | gboolean ret; |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
146 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
147 | g_return_val_if_fail(id != NULL && id[0] != '\0', FALSE); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
148 | g_return_val_if_fail(G_IS_TLS_CERTIFICATE(certificate), FALSE); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
149 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
150 | /* Ensure certificate directory exists */ |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
151 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
152 | if (!ensure_certificate_dir(error)) { |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
153 | return FALSE; |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
154 | } |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
155 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
156 | /* Get the text representation of the certificate */ |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
157 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
158 | g_object_get(certificate, "certificate-pem", &pem, NULL); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
159 | g_return_val_if_fail(pem != NULL, FALSE); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
160 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
161 | /* Save certificate text to a fail */ |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
162 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
163 | path = make_certificate_path(id); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
164 | ret = g_file_set_contents(path, pem, -1, error); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
165 | g_free(path); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
166 | g_free(pem); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
167 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
168 | return ret; |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
169 | } |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
170 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
171 | gboolean |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
172 | purple_tls_certificate_distrust(const gchar *id, GError **error) |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
173 | { |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
174 | gchar *path; |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
175 | gboolean ret = TRUE; |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
176 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
177 | g_return_val_if_fail(id != NULL && id[0] != '\0', FALSE); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
178 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
179 | /* Delete certificate file if it exists */ |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
180 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
181 | path = make_certificate_path(id); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
182 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
183 | if (g_unlink(path) != 0) { |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
184 | g_set_error_literal(error, G_FILE_ERROR, |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
185 | g_file_error_from_errno(errno), |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
186 | g_strerror(errno)); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
187 | ret = FALSE; |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
188 | } |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
189 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
190 | g_free(path); |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
191 | |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
192 | return ret; |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
193 | } |
|
5467197bd084
Implement new, simplified TLS certificate API in libpurple
Mike Ruprecht <cmaiku@gmail.com>
parents:
diff
changeset
|
194 | |
|
37627
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
195 | /* Converts GTlsCertificateFlags to a translated string representation |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
196 | * of the first set error flag in the order checked |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
197 | */ |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
198 | static const gchar * |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
199 | tls_certificate_flags_to_reason(GTlsCertificateFlags flags) |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
200 | { |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
201 | if (flags & G_TLS_CERTIFICATE_UNKNOWN_CA) { |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
202 | return _("The certificate is not trusted because no " |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
203 | "certificate that can verify it is " |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
204 | "currently trusted."); |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
205 | } else if (flags & G_TLS_CERTIFICATE_BAD_IDENTITY) { |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
206 | /* Translators: "domain" refers to a DNS domain |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
207 | * (e.g. talk.google.com) |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
208 | */ |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
209 | return _("The certificate presented is not issued to " |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
210 | "this domain."); |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
211 | } else if (flags & G_TLS_CERTIFICATE_NOT_ACTIVATED) { |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
212 | return _("The certificate is not valid yet. Check that your " |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
213 | "computer's date and time are accurate."); |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
214 | } else if (flags & G_TLS_CERTIFICATE_EXPIRED) { |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
215 | return _("The certificate has expired and should not be " |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
216 | "considered valid. Check that your " |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
217 | "computer's date and time are accurate."); |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
218 | } else if (flags & G_TLS_CERTIFICATE_REVOKED) { |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
219 | return _("The certificate has been revoked."); |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
220 | } else if (flags & G_TLS_CERTIFICATE_INSECURE) { |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
221 | return _("The certificate's algorithm is considered insecure."); |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
222 | } else { |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
223 | /* Also catches G_TLS_CERTIFICATE_GENERIC_ERROR here */ |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
224 | return _("An unknown certificate error occurred."); |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
225 | } |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
226 | } |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
227 | |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
228 | /* Holds data for requesting the user to accept a given certificate */ |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
229 | typedef struct { |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
230 | gchar *identity; |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
231 | GTlsCertificate *cert; |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
232 | } UserCertRequestData; |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
233 | |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
234 | static void |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
235 | user_cert_request_data_free(UserCertRequestData *data) |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
236 | { |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
237 | g_return_if_fail(data != NULL); |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
238 | |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
239 | g_free(data->identity); |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
240 | g_object_unref(data->cert); |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
241 | |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
242 | g_free(data); |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
243 | } |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
244 | |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
245 | static void |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
246 | user_cert_request_accept_cb(UserCertRequestData *data) |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
247 | { |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
248 | GError *error = NULL; |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
249 | |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
250 | g_return_if_fail(data != NULL); |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
251 | |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
252 | /* User accepted. Trust this certificate */ |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
253 | if(!purple_tls_certificate_trust(data->identity, data->cert, &error)) { |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
254 | purple_debug_error("tls-certificate", |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
255 | "Error trusting certificate '%s': %s", |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
256 | data->identity, error->message); |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
257 | g_clear_error(&error); |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
258 | } |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
259 | |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
260 | user_cert_request_data_free(data); |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
261 | } |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
262 | |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
263 | static void |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
264 | user_cert_request_deny_cb(UserCertRequestData *data) |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
265 | { |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
266 | /* User denied. Free data related to the requst */ |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
267 | user_cert_request_data_free(data); |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
268 | } |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
269 | |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
270 | /* Prompts the user to accept the certificate as it failed due to the |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
271 | * passed errors. |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
272 | */ |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
273 | static void |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
274 | request_accept_certificate(const gchar *identity, GTlsCertificate *peer_cert, |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
275 | GTlsCertificateFlags errors) |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
276 | { |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
277 | UserCertRequestData *data; |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
278 | gchar *primary; |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
279 | |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
280 | g_return_if_fail(identity != NULL && identity[0] != '\0'); |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
281 | g_return_if_fail(G_IS_TLS_CERTIFICATE(peer_cert)); |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
282 | g_return_if_fail(errors != 0); |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
283 | |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
284 | data = g_new(UserCertRequestData, 1); |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
285 | data->identity = g_strdup(identity); |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
286 | data->cert = g_object_ref(peer_cert); |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
287 | |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
288 | primary = g_strdup_printf(_("Accept certificate for %s?"), identity); |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
289 | purple_request_certificate(data, |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
290 | _("TLS Certificate Verification"), |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
291 | primary, |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
292 | tls_certificate_flags_to_reason(errors), |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
293 | data->cert, |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
294 | _("Accept"), G_CALLBACK(user_cert_request_accept_cb), |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
295 | _("Reject"), G_CALLBACK(user_cert_request_deny_cb), |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
296 | data); |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
297 | g_free(primary); |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
298 | } |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
299 | |
|
37621
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
300 | /* Called when a GTlsConnection (which this handler has been connected to) |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
301 | * has an error validating its certificate. |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
302 | * Returns TRUE if the certificate is already trusted, so the connection |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
303 | * can continue. |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
304 | * Returns FALSE if the certificate is not trusted, causing the |
|
37627
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
305 | * connection's handshake to fail, and then prompts the user to accept |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
306 | * the certificate. |
|
37621
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
307 | */ |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
308 | static gboolean |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
309 | accept_certificate_cb(GTlsConnection *conn, GTlsCertificate *peer_cert, |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
310 | GTlsCertificateFlags errors, gpointer user_data) |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
311 | { |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
312 | GTlsCertificate *trusted_cert; |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
313 | GSocketConnectable *connectable; |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
314 | const gchar *identity; |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
315 | |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
316 | g_return_val_if_fail(G_IS_TLS_CLIENT_CONNECTION(conn), FALSE); |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
317 | g_return_val_if_fail(G_IS_TLS_CERTIFICATE(peer_cert), FALSE); |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
318 | |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
319 | /* Get the certificate identity from the GTlsClientConnection */ |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
320 | |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
321 | connectable = g_tls_client_connection_get_server_identity( |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
322 | G_TLS_CLIENT_CONNECTION(conn)); |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
323 | |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
324 | g_return_val_if_fail(G_IS_SOCKET_CONNECTABLE(connectable), FALSE); |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
325 | |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
326 | /* identity is owned by the connectable */ |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
327 | if (G_IS_NETWORK_ADDRESS(connectable)) { |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
328 | identity = g_network_address_get_hostname( |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
329 | G_NETWORK_ADDRESS(connectable)); |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
330 | } else if (G_IS_NETWORK_SERVICE(connectable)) { |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
331 | identity = g_network_service_get_domain( |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
332 | G_NETWORK_SERVICE(connectable)); |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
333 | } else { |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
334 | g_return_val_if_reached(FALSE); |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
335 | } |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
336 | |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
337 | /* See if a trusted certificate matching the peer certificate exists */ |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
338 | |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
339 | trusted_cert = purple_tls_certificate_new_from_id(identity, NULL); |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
340 | |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
341 | if (trusted_cert != NULL && |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
342 | g_tls_certificate_is_same(peer_cert, trusted_cert)) { |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
343 | /* It's manually trusted. Accept certificate */ |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
344 | g_object_unref(trusted_cert); |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
345 | return TRUE; |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
346 | } |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
347 | |
|
37627
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
348 | g_clear_object(&trusted_cert); |
|
37621
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
349 | |
|
37627
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
350 | /* Certificate failed and isn't trusted. |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
351 | * Fail certificate and prompt user. |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
352 | */ |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
353 | |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
354 | request_accept_certificate(identity, peer_cert, errors); |
|
a1591cb7c087
Implement manually trusting certificates with TLS helper API
Mike Ruprecht <cmaiku@gmail.com>
parents:
37622
diff
changeset
|
355 | |
|
37621
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
356 | return FALSE; |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
357 | } |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
358 | |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
359 | gpointer |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
360 | purple_tls_certificate_attach_to_tls_connection(GTlsConnection *conn) |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
361 | { |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
362 | return g_object_connect(conn, "signal::accept-certificate", |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
363 | accept_certificate_cb, NULL, NULL); |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
364 | } |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
365 | |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
366 | /* Called when GSocketClient signals an event. |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
367 | * Calls purple_tls_certificate_attach_to_tls_connection() on the client's |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
368 | * connection when it's about to handshake. |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
369 | */ |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
370 | static void |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
371 | socket_client_event_cb(GSocketClient *client, GSocketClientEvent event, |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
372 | GSocketConnectable *connectable, GIOStream *connection, |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
373 | gpointer user_data) |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
374 | { |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
375 | if (event == G_SOCKET_CLIENT_TLS_HANDSHAKING) { |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
376 | /* Attach libpurple's certificate subsystem to the |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
377 | * GTlsConnection right before it starts the handshake |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
378 | */ |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
379 | purple_tls_certificate_attach_to_tls_connection( |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
380 | G_TLS_CONNECTION(connection)); |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
381 | } |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
382 | } |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
383 | |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
384 | gpointer |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
385 | purple_tls_certificate_attach_to_socket_client(GSocketClient *client) |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
386 | { |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
387 | return g_object_connect(client, "signal::event", |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
388 | socket_client_event_cb, NULL, NULL); |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
389 | } |
|
2a2f1068e0f0
Add helper API for using Purple TLS subsystem with GTlsConnections
Mike Ruprecht <cmaiku@gmail.com>
parents:
37620
diff
changeset
|
390 |