Mercurial > pidgin.yaz
annotate src/ssl-gnutls.c @ 6755:ea289c6f2382
[gaim-migrate @ 7287]
fix a bug with removing buddies, and the start of support for aliasing contacts
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Fri, 05 Sep 2003 17:04:39 +0000 |
parents | 82348b5ab87e |
children | 424647996866 |
rev | line source |
---|---|
6738 | 1 /** |
2 * @file ssl-gnutls.c SSL Operations for GNUTLS | |
3 * @ingroup core | |
4 * | |
5 * gaim | |
6 * | |
7 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> | |
8 * | |
9 * This program is free software; you can redistribute it and/or modify | |
10 * it under the terms of the GNU General Public License as published by | |
11 * the Free Software Foundation; either version 2 of the License, or | |
12 * (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program; if not, write to the Free Software | |
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
22 */ | |
6747
82348b5ab87e
[gaim-migrate @ 7279]
Christian Hammond <chipx86@chipx86.com>
parents:
6738
diff
changeset
|
23 #include "internal.h" |
82348b5ab87e
[gaim-migrate @ 7279]
Christian Hammond <chipx86@chipx86.com>
parents:
6738
diff
changeset
|
24 |
82348b5ab87e
[gaim-migrate @ 7279]
Christian Hammond <chipx86@chipx86.com>
parents:
6738
diff
changeset
|
25 #ifdef HAVE_GNUTLS |
82348b5ab87e
[gaim-migrate @ 7279]
Christian Hammond <chipx86@chipx86.com>
parents:
6738
diff
changeset
|
26 |
6738 | 27 #include "debug.h" |
28 #include "sslconn.h" | |
29 | |
30 #include <gnutls/gnutls.h> | |
31 | |
32 typedef struct | |
33 { | |
34 gnutls_session session; | |
35 gnutls_certificate_client_credentials xcred; | |
36 | |
37 } GaimSslGnutlsData; | |
38 | |
39 #define GAIM_SSL_GNUTLS_DATA(gsc) ((GaimSslGnutlsData *)gsc->private_data) | |
40 | |
41 static gnutls_certificate_client_credentials xcred; | |
42 | |
43 static gboolean | |
44 ssl_gnutls_init(void) | |
45 { | |
46 gnutls_global_init(); | |
47 | |
48 gnutls_certificate_allocate_credentials(&xcred); | |
49 gnutls_certificate_set_x509_trust_file(xcred, "ca.pem", GNUTLS_X509_FMT_PEM); | |
50 | |
51 return TRUE; | |
52 } | |
53 | |
54 static void | |
55 ssl_gnutls_uninit(void) | |
56 { | |
57 gnutls_global_deinit(); | |
58 | |
59 gnutls_certificate_free_credentials(xcred); | |
60 } | |
61 | |
62 static void | |
63 ssl_gnutls_connect_cb(gpointer data, gint source, GaimInputCondition cond) | |
64 { | |
65 GaimSslConnection *gsc = (GaimSslConnection *)data; | |
66 GaimSslGnutlsData *gnutls_data; | |
67 int ret; | |
68 const int cert_type_priority[2] = { GNUTLS_CRT_X509, 0 }; | |
69 | |
70 gsc->fd = source; | |
71 | |
72 gnutls_data = g_new0(GaimSslGnutlsData, 1); | |
73 gsc->private_data = gnutls_data; | |
74 | |
75 gnutls_init(&gnutls_data->session, GNUTLS_CLIENT); | |
76 gnutls_set_default_priority(gnutls_data->session); | |
77 | |
78 gnutls_certificate_type_set_priority(gnutls_data->session, | |
79 cert_type_priority); | |
80 | |
81 gnutls_credentials_set(gnutls_data->session, GNUTLS_CRD_CERTIFICATE, | |
82 xcred); | |
83 | |
84 gnutls_transport_set_ptr(gnutls_data->session, GINT_TO_POINTER(source)); | |
85 | |
86 gaim_debug_info("gnutls", "Handshaking\n"); | |
87 ret = gnutls_handshake(gnutls_data->session); | |
88 | |
89 if (ret < 0) | |
90 { | |
91 } | |
92 else | |
93 { | |
94 gaim_debug_info("gnutls", "Calling input function\n"); | |
95 gsc->input_func(gsc->user_data, (GaimSslConnection *)gsc, cond); | |
96 } | |
97 } | |
98 | |
99 static void | |
100 ssl_gnutls_close(GaimSslConnection *gsc) | |
101 { | |
102 GaimSslGnutlsData *gnutls_data = GAIM_SSL_GNUTLS_DATA(gsc); | |
103 | |
104 gnutls_bye(gnutls_data->session, GNUTLS_SHUT_RDWR); | |
105 | |
106 gnutls_deinit(gnutls_data->session); | |
107 // gnutls_certificate_free_credentials(gnutls_data->xcred); | |
108 | |
109 g_free(gnutls_data); | |
110 } | |
111 | |
112 static size_t | |
113 ssl_gnutls_read(GaimSslConnection *gsc, void *data, size_t len) | |
114 { | |
115 GaimSslGnutlsData *gnutls_data = GAIM_SSL_GNUTLS_DATA(gsc); | |
116 int s; | |
117 | |
118 s = gnutls_record_recv(gnutls_data->session, data, len); | |
119 | |
120 if (s < 0) | |
121 s = 0; | |
122 | |
123 gaim_debug_misc("gnutls", "s = %d\n", s); | |
124 | |
125 return s; | |
126 } | |
127 | |
128 static size_t | |
129 ssl_gnutls_write(GaimSslConnection *gsc, const void *data, size_t len) | |
130 { | |
131 GaimSslGnutlsData *gnutls_data = GAIM_SSL_GNUTLS_DATA(gsc); | |
132 size_t s; | |
133 | |
134 gaim_debug_misc("gnutls", "Writing: {%s}\n", data); | |
135 | |
136 s = gnutls_record_send(gnutls_data->session, data, len); | |
137 } | |
138 | |
139 static GaimSslOps ssl_ops = | |
140 { | |
141 ssl_gnutls_init, | |
142 ssl_gnutls_uninit, | |
143 ssl_gnutls_connect_cb, | |
144 ssl_gnutls_close, | |
145 ssl_gnutls_read, | |
146 ssl_gnutls_write | |
147 }; | |
148 | |
149 GaimSslOps * | |
150 gaim_ssl_gnutls_get_ops() | |
151 { | |
152 return &ssl_ops; | |
153 } | |
6747
82348b5ab87e
[gaim-migrate @ 7279]
Christian Hammond <chipx86@chipx86.com>
parents:
6738
diff
changeset
|
154 |
82348b5ab87e
[gaim-migrate @ 7279]
Christian Hammond <chipx86@chipx86.com>
parents:
6738
diff
changeset
|
155 #endif /* HAVE_GNUTLS */ |