comparison libpurple/sslconn.c @ 19265:ce892eddb8f1

propagate from branch 'im.pidgin.pidgin' (head 37a828a3519f5c2fe7a6d94dc41d607b807dd371) to branch 'im.pidgin.soc.2007.certmgr' (head 462298218a3d857c74beff14713b6b92743e3b08)
author William Ehlhardt <williamehlhardt@gmail.com>
date Tue, 14 Aug 2007 04:52:22 +0000
parents ab7cd6c95b2f
children d5ecaf5bce93 c3405700c2fe
comparison
equal deleted inserted replaced
19264:d5e76ad4b365 19265:ce892eddb8f1
22 * along with this program; if not, write to the Free Software 22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */ 24 */
25 #include "internal.h" 25 #include "internal.h"
26 26
27 #include "certificate.h"
27 #include "debug.h" 28 #include "debug.h"
28 #include "sslconn.h" 29 #include "sslconn.h"
29 30
30 static gboolean _ssl_initialized = FALSE; 31 static gboolean _ssl_initialized = FALSE;
31 static PurpleSslOps *_ssl_ops = NULL; 32 static PurpleSslOps *_ssl_ops = NULL;
115 gsc->port = port; 116 gsc->port = port;
116 gsc->connect_cb_data = data; 117 gsc->connect_cb_data = data;
117 gsc->connect_cb = func; 118 gsc->connect_cb = func;
118 gsc->error_cb = error_func; 119 gsc->error_cb = error_func;
119 120
121 /* TODO: Move this elsewhere */
122 gsc->verifier = purple_certificate_find_verifier("x509","tls_cached");
123
120 gsc->connect_data = purple_proxy_connect(NULL, account, host, port, purple_ssl_connect_cb, gsc); 124 gsc->connect_data = purple_proxy_connect(NULL, account, host, port, purple_ssl_connect_cb, gsc);
121 125
122 if (gsc->connect_data == NULL) 126 if (gsc->connect_data == NULL)
123 { 127 {
124 g_free(gsc->host); 128 g_free(gsc->host);
147 151
148 gsc->recv_cb_data = data; 152 gsc->recv_cb_data = data;
149 gsc->recv_cb = func; 153 gsc->recv_cb = func;
150 154
151 gsc->inpa = purple_input_add(gsc->fd, PURPLE_INPUT_READ, recv_cb, gsc); 155 gsc->inpa = purple_input_add(gsc->fd, PURPLE_INPUT_READ, recv_cb, gsc);
156 }
157
158 const gchar *
159 purple_ssl_strerror(PurpleSslErrorType error)
160 {
161 switch(error) {
162 case PURPLE_SSL_CONNECT_FAILED:
163 return _("SSL Connection Failed");
164 case PURPLE_SSL_HANDSHAKE_FAILED:
165 return _("SSL Handshake Failed");
166 case PURPLE_SSL_CERTIFICATE_INVALID:
167 return _("SSL peer presented an invalid certificate");
168 default:
169 purple_debug_warning("sslconn", "Unknown SSL error code %d\n", error);
170 return _("Unknown SSL error");
171 }
152 } 172 }
153 173
154 PurpleSslConnection * 174 PurpleSslConnection *
155 purple_ssl_connect_fd(PurpleAccount *account, int fd, 175 purple_ssl_connect_fd(PurpleAccount *account, int fd,
156 PurpleSslInputFunction func, 176 PurpleSslInputFunction func,
157 PurpleSslErrorFunction error_func, void *data) 177 PurpleSslErrorFunction error_func,
178 void *data)
179 {
180 return purple_ssl_connect_with_host_fd(account, fd, func, error_func, NULL, data);
181 }
182
183 PurpleSslConnection *
184 purple_ssl_connect_with_host_fd(PurpleAccount *account, int fd,
185 PurpleSslInputFunction func,
186 PurpleSslErrorFunction error_func,
187 const char *host,
188 void *data)
158 { 189 {
159 PurpleSslConnection *gsc; 190 PurpleSslConnection *gsc;
160 PurpleSslOps *ops; 191 PurpleSslOps *ops;
161 192
162 g_return_val_if_fail(fd != -1, NULL); 193 g_return_val_if_fail(fd != -1, NULL);
173 204
174 gsc->connect_cb_data = data; 205 gsc->connect_cb_data = data;
175 gsc->connect_cb = func; 206 gsc->connect_cb = func;
176 gsc->error_cb = error_func; 207 gsc->error_cb = error_func;
177 gsc->fd = fd; 208 gsc->fd = fd;
178 209 if(host)
210 gsc->host = g_strdup(host);
211
212 /* TODO: Move this elsewhere */
213 gsc->verifier = purple_certificate_find_verifier("x509","tls_cached");
214
215
179 ops = purple_ssl_get_ops(); 216 ops = purple_ssl_get_ops();
180 ops->connectfunc(gsc); 217 ops->connectfunc(gsc);
181 218
182 return (PurpleSslConnection *)gsc; 219 return (PurpleSslConnection *)gsc;
183 } 220 }
229 266
230 ops = purple_ssl_get_ops(); 267 ops = purple_ssl_get_ops();
231 return (ops->write)(gsc, data, len); 268 return (ops->write)(gsc, data, len);
232 } 269 }
233 270
271 GList *
272 purple_ssl_get_peer_certificates(PurpleSslConnection *gsc)
273 {
274 PurpleSslOps *ops;
275
276 g_return_val_if_fail(gsc != NULL, NULL);
277
278 ops = purple_ssl_get_ops();
279 return (ops->get_peer_certificates)(gsc);
280 }
281
234 void 282 void
235 purple_ssl_set_ops(PurpleSslOps *ops) 283 purple_ssl_set_ops(PurpleSslOps *ops)
236 { 284 {
237 _ssl_ops = ops; 285 _ssl_ops = ops;
238 } 286 }
244 } 292 }
245 293
246 void 294 void
247 purple_ssl_init(void) 295 purple_ssl_init(void)
248 { 296 {
249 /* This doesn't do anything at the moment. All the actual init work 297 /* Although purple_ssl_is_supported will do the initialization on
250 * is handled by purple_ssl_is_supported upon demand. */ 298 command, SSL plugins tend to register CertificateSchemes as well
299 as providing SSL ops. */
300 g_assert(ssl_init());
251 } 301 }
252 302
253 void 303 void
254 purple_ssl_uninit(void) 304 purple_ssl_uninit(void)
255 { 305 {