Thu, 25 Dec 2003 09:23:27 +0000
[gaim-migrate @ 8598]
De-uglify the insert link and insert image buttons a bit. Closing the
insert image dialog via the window manager now makes the insert image
button un-depress itself.
| 7016 | 1 | /** |
| 2 | * @file ssl-gnutls.c GNUTLS SSL plugin. | |
| 3 | * | |
| 4 | * gaim | |
| 5 | * | |
| 6 | * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> | |
| 7 | * | |
| 8 | * This program is free software; you can redistribute it and/or modify | |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation; either version 2 of the License, or | |
| 11 | * (at your option) any later version. | |
| 12 | * | |
| 13 | * This program is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU General Public License | |
| 19 | * along with this program; if not, write to the Free Software | |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 | */ | |
| 22 | #include "internal.h" | |
|
7051
8ddb8f560399
[gaim-migrate @ 7614]
Christian Hammond <chipx86@chipx86.com>
parents:
7050
diff
changeset
|
23 | #include "debug.h" |
| 7016 | 24 | #include "plugin.h" |
|
7051
8ddb8f560399
[gaim-migrate @ 7614]
Christian Hammond <chipx86@chipx86.com>
parents:
7050
diff
changeset
|
25 | #include "sslconn.h" |
| 7016 | 26 | |
| 27 | #define SSL_GNUTLS_PLUGIN_ID "ssl-gnutls" | |
| 28 | ||
| 29 | #ifdef HAVE_GNUTLS | |
| 30 | ||
| 31 | #include <gnutls/gnutls.h> | |
| 32 | ||
| 33 | typedef struct | |
| 34 | { | |
| 35 | gnutls_session session; | |
| 36 | ||
| 37 | } GaimSslGnutlsData; | |
| 38 | ||
| 39 | #define GAIM_SSL_GNUTLS_DATA(gsc) ((GaimSslGnutlsData *)gsc->private_data) | |
| 40 | ||
| 41 | static gnutls_certificate_client_credentials xcred; | |
| 42 | ||
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
43 | static void |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
44 | ssl_gnutls_init_gnutls(void) |
| 7016 | 45 | { |
| 46 | gnutls_global_init(); | |
| 47 | ||
| 48 | gnutls_certificate_allocate_credentials(&xcred); | |
| 49 | gnutls_certificate_set_x509_trust_file(xcred, "ca.pem", | |
| 50 | GNUTLS_X509_FMT_PEM); | |
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
51 | } |
| 7016 | 52 | |
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
53 | static gboolean |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
54 | ssl_gnutls_init(void) |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
55 | { |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
56 | return TRUE; |
| 7016 | 57 | } |
| 58 | ||
| 59 | static void | |
| 60 | ssl_gnutls_uninit(void) | |
| 61 | { | |
| 62 | gnutls_global_deinit(); | |
| 63 | ||
| 64 | gnutls_certificate_free_credentials(xcred); | |
| 65 | } | |
| 66 | ||
| 67 | static void | |
| 68 | ssl_gnutls_connect_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 69 | { | |
| 70 | GaimSslConnection *gsc = (GaimSslConnection *)data; | |
| 71 | GaimSslGnutlsData *gnutls_data; | |
| 72 | static const int cert_type_priority[2] = { GNUTLS_CRT_X509, 0 }; | |
| 73 | int ret; | |
| 74 | ||
| 75 | if (source < 0) | |
| 76 | return; | |
| 77 | ||
| 78 | gsc->fd = source; | |
| 79 | ||
| 80 | gnutls_data = g_new0(GaimSslGnutlsData, 1); | |
| 81 | gsc->private_data = gnutls_data; | |
| 82 | ||
| 83 | gnutls_init(&gnutls_data->session, GNUTLS_CLIENT); | |
| 84 | gnutls_set_default_priority(gnutls_data->session); | |
| 85 | ||
| 86 | gnutls_certificate_type_set_priority(gnutls_data->session, | |
| 87 | cert_type_priority); | |
| 88 | ||
| 89 | gnutls_credentials_set(gnutls_data->session, GNUTLS_CRD_CERTIFICATE, | |
| 90 | xcred); | |
| 91 | ||
| 92 | gnutls_transport_set_ptr(gnutls_data->session, GINT_TO_POINTER(source)); | |
| 93 | ||
| 94 | gaim_debug_info("gnutls", "Handshaking\n"); | |
| 7834 | 95 | |
| 96 | do | |
| 97 | { | |
| 98 | ret = gnutls_handshake(gnutls_data->session); | |
| 99 | } | |
| 100 | while ((ret == GNUTLS_E_AGAIN) || (ret == GNUTLS_E_INTERRUPTED)); | |
| 101 | ||
| 102 | gaim_debug_info("gnutls", "Handshake complete\n"); | |
| 7016 | 103 | |
| 104 | if (ret < 0) | |
| 105 | { | |
|
7325
714ca91f70d0
[gaim-migrate @ 7911]
Christian Hammond <chipx86@chipx86.com>
parents:
7274
diff
changeset
|
106 | gaim_debug_error("gnutls", "Handshake failed. Error %d\n", ret); |
| 7016 | 107 | |
|
7274
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
7051
diff
changeset
|
108 | if (gsc->error_cb != NULL) |
| 7481 | 109 | gsc->error_cb(gsc, GAIM_SSL_HANDSHAKE_FAILED, |
| 110 | gsc->connect_cb_data); | |
|
7274
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
7051
diff
changeset
|
111 | |
| 7016 | 112 | gaim_ssl_close(gsc); |
| 113 | } | |
| 114 | else | |
| 115 | { | |
| 116 | gsc->connect_cb(gsc->connect_cb_data, gsc, cond); | |
| 117 | } | |
| 118 | } | |
| 119 | ||
| 120 | static void | |
| 121 | ssl_gnutls_close(GaimSslConnection *gsc) | |
| 122 | { | |
| 123 | GaimSslGnutlsData *gnutls_data = GAIM_SSL_GNUTLS_DATA(gsc); | |
| 124 | ||
| 7467 | 125 | if(!gnutls_data) |
| 126 | return; | |
| 127 | ||
| 7016 | 128 | gnutls_bye(gnutls_data->session, GNUTLS_SHUT_RDWR); |
| 129 | ||
| 130 | gnutls_deinit(gnutls_data->session); | |
| 131 | ||
| 132 | g_free(gnutls_data); | |
| 133 | } | |
| 134 | ||
| 135 | static size_t | |
| 136 | ssl_gnutls_read(GaimSslConnection *gsc, void *data, size_t len) | |
| 137 | { | |
| 138 | GaimSslGnutlsData *gnutls_data = GAIM_SSL_GNUTLS_DATA(gsc); | |
| 139 | int s; | |
| 140 | ||
| 7834 | 141 | do |
| 142 | { | |
| 143 | s = gnutls_record_recv(gnutls_data->session, data, len); | |
| 144 | } | |
| 145 | while ((s == GNUTLS_E_AGAIN) || (s == GNUTLS_E_INTERRUPTED)); | |
| 7016 | 146 | |
| 147 | if (s < 0) | |
| 7834 | 148 | { |
| 149 | gaim_debug_error("gnutls", "receive failed: %d\n", s); | |
| 7016 | 150 | s = 0; |
| 7834 | 151 | } |
| 7016 | 152 | |
| 153 | return s; | |
| 154 | } | |
| 155 | ||
| 156 | static size_t | |
| 157 | ssl_gnutls_write(GaimSslConnection *gsc, const void *data, size_t len) | |
| 158 | { | |
| 159 | GaimSslGnutlsData *gnutls_data = GAIM_SSL_GNUTLS_DATA(gsc); | |
| 7467 | 160 | size_t s = 0; |
| 7016 | 161 | |
| 7467 | 162 | if(gnutls_data) |
| 163 | s = gnutls_record_send(gnutls_data->session, data, len); | |
| 7016 | 164 | |
| 165 | return s; | |
| 166 | } | |
| 167 | ||
| 168 | static GaimSslOps ssl_ops = | |
| 169 | { | |
| 170 | ssl_gnutls_init, | |
| 171 | ssl_gnutls_uninit, | |
| 172 | ssl_gnutls_connect_cb, | |
| 173 | ssl_gnutls_close, | |
| 174 | ssl_gnutls_read, | |
| 175 | ssl_gnutls_write | |
| 176 | }; | |
| 177 | ||
| 178 | #endif /* HAVE_GNUTLS */ | |
| 179 | ||
| 180 | static gboolean | |
| 181 | plugin_load(GaimPlugin *plugin) | |
| 182 | { | |
| 183 | #ifdef HAVE_GNUTLS | |
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
184 | if (!gaim_ssl_get_ops()) { |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
185 | gaim_ssl_set_ops(&ssl_ops); |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
186 | } |
| 7016 | 187 | |
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
188 | /* Init GNUTLS now so others can use it even if sslconn never does */ |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
189 | ssl_gnutls_init_gnutls(); |
| 7016 | 190 | return TRUE; |
| 191 | #else | |
| 192 | return FALSE; | |
| 193 | #endif | |
| 194 | } | |
| 195 | ||
| 196 | static gboolean | |
| 197 | plugin_unload(GaimPlugin *plugin) | |
| 198 | { | |
|
7050
12730863b0f9
[gaim-migrate @ 7613]
Christian Hammond <chipx86@chipx86.com>
parents:
7016
diff
changeset
|
199 | #ifdef HAVE_GNUTLS |
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
200 | if (gaim_ssl_get_ops() == &ssl_ops) { |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
201 | gaim_ssl_set_ops(NULL); |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7834
diff
changeset
|
202 | } |
|
7050
12730863b0f9
[gaim-migrate @ 7613]
Christian Hammond <chipx86@chipx86.com>
parents:
7016
diff
changeset
|
203 | #endif |
|
12730863b0f9
[gaim-migrate @ 7613]
Christian Hammond <chipx86@chipx86.com>
parents:
7016
diff
changeset
|
204 | |
| 7016 | 205 | return TRUE; |
| 206 | } | |
| 207 | ||
| 208 | static GaimPluginInfo info = | |
| 209 | { | |
| 210 | 2, /**< api_version */ | |
| 211 | GAIM_PLUGIN_STANDARD, /**< type */ | |
| 212 | NULL, /**< ui_requirement */ | |
| 213 | GAIM_PLUGIN_FLAG_INVISIBLE, /**< flags */ | |
| 214 | NULL, /**< dependencies */ | |
| 215 | GAIM_PRIORITY_DEFAULT, /**< priority */ | |
| 216 | ||
| 217 | SSL_GNUTLS_PLUGIN_ID, /**< id */ | |
| 218 | N_("GNUTLS"), /**< name */ | |
| 219 | VERSION, /**< version */ | |
| 220 | /** summary */ | |
| 221 | N_("Provides SSL support through GNUTLS."), | |
| 222 | /** description */ | |
| 223 | N_("Provides SSL support through GNUTLS."), | |
| 224 | "Christian Hammond <chipx86@gnupdate.org>", | |
| 225 | GAIM_WEBSITE, /**< homepage */ | |
| 226 | ||
| 227 | plugin_load, /**< load */ | |
| 228 | plugin_unload, /**< unload */ | |
| 229 | NULL, /**< destroy */ | |
| 230 | ||
| 231 | NULL, /**< ui_info */ | |
| 232 | NULL /**< extra_info */ | |
| 233 | }; | |
| 234 | ||
| 235 | static void | |
| 236 | init_plugin(GaimPlugin *plugin) | |
| 237 | { | |
| 238 | } | |
| 239 | ||
| 240 | GAIM_INIT_PLUGIN(ssl_gnutls, init_plugin, info) |