comparison libpurple/plugins/ssl/ssl-nss.c @ 15823:32c366eeeb99

sed -ie 's/gaim/purple/g'
author Sean Egan <seanegan@gmail.com>
date Mon, 19 Mar 2007 07:01:17 +0000
parents 5fe8042783c1
children 634b96915d2e
comparison
equal deleted inserted replaced
15822:84b0f9b23ede 15823:32c366eeeb99
1 /** 1 /**
2 * @file ssl-nss.c Mozilla NSS SSL plugin. 2 * @file ssl-nss.c Mozilla NSS SSL plugin.
3 * 3 *
4 * gaim 4 * purple
5 * 5 *
6 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> 6 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org>
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 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 9 * it under the terms of the GNU General Public License as published by
46 { 46 {
47 PRFileDesc *fd; 47 PRFileDesc *fd;
48 PRFileDesc *in; 48 PRFileDesc *in;
49 guint handshake_handler; 49 guint handshake_handler;
50 50
51 } GaimSslNssData; 51 } PurpleSslNssData;
52 52
53 #define GAIM_SSL_NSS_DATA(gsc) ((GaimSslNssData *)gsc->private_data) 53 #define PURPLE_SSL_NSS_DATA(gsc) ((PurpleSslNssData *)gsc->private_data)
54 54
55 static const PRIOMethods *_nss_methods = NULL; 55 static const PRIOMethods *_nss_methods = NULL;
56 static PRDescIdentity _identity; 56 static PRDescIdentity _identity;
57 57
58 /* Thank you, Evolution */ 58 /* Thank you, Evolution */
118 #endif 118 #endif
119 SECMOD_AddNewModule("Builtins", lib, 0, 0); 119 SECMOD_AddNewModule("Builtins", lib, 0, 0);
120 g_free(lib); 120 g_free(lib);
121 NSS_SetDomesticPolicy(); 121 NSS_SetDomesticPolicy();
122 122
123 _identity = PR_GetUniqueIdentity("Gaim"); 123 _identity = PR_GetUniqueIdentity("Purple");
124 _nss_methods = PR_GetDefaultIOMethods(); 124 _nss_methods = PR_GetDefaultIOMethods();
125 } 125 }
126 126
127 static SECStatus 127 static SECStatus
128 ssl_auth_cert(void *arg, PRFileDesc *socket, PRBool checksig, 128 ssl_auth_cert(void *arg, PRFileDesc *socket, PRBool checksig,
140 140
141 status = CERT_VerifyCertNow((CERTCertDBHandle *)arg, cert, checksig, 141 status = CERT_VerifyCertNow((CERTCertDBHandle *)arg, cert, checksig,
142 certUsageSSLClient, pinArg); 142 certUsageSSLClient, pinArg);
143 143
144 if (status != SECSuccess) { 144 if (status != SECSuccess) {
145 gaim_debug_error("nss", "CERT_VerifyCertNow failed\n"); 145 purple_debug_error("nss", "CERT_VerifyCertNow failed\n");
146 CERT_DestroyCertificate(cert); 146 CERT_DestroyCertificate(cert);
147 return status; 147 return status;
148 } 148 }
149 149
150 CERT_DestroyCertificate(cert); 150 CERT_DestroyCertificate(cert);
185 default: 185 default:
186 status = SECFailure; 186 status = SECFailure;
187 break; 187 break;
188 } 188 }
189 189
190 gaim_debug_error("nss", "Bad certificate: %d\n", err); 190 purple_debug_error("nss", "Bad certificate: %d\n", err);
191 191
192 return status; 192 return status;
193 } 193 }
194 194
195 static gboolean 195 static gboolean
205 205
206 _nss_methods = NULL; 206 _nss_methods = NULL;
207 } 207 }
208 208
209 static void 209 static void
210 ssl_nss_handshake_cb(gpointer data, int fd, GaimInputCondition cond) 210 ssl_nss_handshake_cb(gpointer data, int fd, PurpleInputCondition cond)
211 { 211 {
212 GaimSslConnection *gsc = (GaimSslConnection *)data; 212 PurpleSslConnection *gsc = (PurpleSslConnection *)data;
213 GaimSslNssData *nss_data = gsc->private_data; 213 PurpleSslNssData *nss_data = gsc->private_data;
214 214
215 /* I don't think this the best way to do this... 215 /* I don't think this the best way to do this...
216 * It seems to work because it'll eventually use the cached value 216 * It seems to work because it'll eventually use the cached value
217 */ 217 */
218 if(SSL_ForceHandshake(nss_data->in) != SECSuccess) { 218 if(SSL_ForceHandshake(nss_data->in) != SECSuccess) {
219 set_errno(PR_GetError()); 219 set_errno(PR_GetError());
220 if (errno == EAGAIN || errno == EWOULDBLOCK) 220 if (errno == EAGAIN || errno == EWOULDBLOCK)
221 return; 221 return;
222 222
223 gaim_debug_error("nss", "Handshake failed %d\n", PR_GetError()); 223 purple_debug_error("nss", "Handshake failed %d\n", PR_GetError());
224 224
225 if (gsc->error_cb != NULL) 225 if (gsc->error_cb != NULL)
226 gsc->error_cb(gsc, GAIM_SSL_HANDSHAKE_FAILED, gsc->connect_cb_data); 226 gsc->error_cb(gsc, PURPLE_SSL_HANDSHAKE_FAILED, gsc->connect_cb_data);
227 227
228 gaim_ssl_close(gsc); 228 purple_ssl_close(gsc);
229 229
230 return; 230 return;
231 } 231 }
232 232
233 gaim_input_remove(nss_data->handshake_handler); 233 purple_input_remove(nss_data->handshake_handler);
234 nss_data->handshake_handler = 0; 234 nss_data->handshake_handler = 0;
235 235
236 gsc->connect_cb(gsc->connect_cb_data, gsc, cond); 236 gsc->connect_cb(gsc->connect_cb_data, gsc, cond);
237 } 237 }
238 238
239 static void 239 static void
240 ssl_nss_connect(GaimSslConnection *gsc) 240 ssl_nss_connect(PurpleSslConnection *gsc)
241 { 241 {
242 GaimSslNssData *nss_data = g_new0(GaimSslNssData, 1); 242 PurpleSslNssData *nss_data = g_new0(PurpleSslNssData, 1);
243 PRSocketOptionData socket_opt; 243 PRSocketOptionData socket_opt;
244 244
245 gsc->private_data = nss_data; 245 gsc->private_data = nss_data;
246 246
247 nss_data->fd = PR_ImportTCPSocket(gsc->fd); 247 nss_data->fd = PR_ImportTCPSocket(gsc->fd);
248 248
249 if (nss_data->fd == NULL) 249 if (nss_data->fd == NULL)
250 { 250 {
251 gaim_debug_error("nss", "nss_data->fd == NULL!\n"); 251 purple_debug_error("nss", "nss_data->fd == NULL!\n");
252 252
253 if (gsc->error_cb != NULL) 253 if (gsc->error_cb != NULL)
254 gsc->error_cb(gsc, GAIM_SSL_CONNECT_FAILED, gsc->connect_cb_data); 254 gsc->error_cb(gsc, PURPLE_SSL_CONNECT_FAILED, gsc->connect_cb_data);
255 255
256 gaim_ssl_close((GaimSslConnection *)gsc); 256 purple_ssl_close((PurpleSslConnection *)gsc);
257 257
258 return; 258 return;
259 } 259 }
260 260
261 socket_opt.option = PR_SockOpt_Nonblocking; 261 socket_opt.option = PR_SockOpt_Nonblocking;
262 socket_opt.value.non_blocking = PR_TRUE; 262 socket_opt.value.non_blocking = PR_TRUE;
263 263
264 if (PR_SetSocketOption(nss_data->fd, &socket_opt) != PR_SUCCESS) 264 if (PR_SetSocketOption(nss_data->fd, &socket_opt) != PR_SUCCESS)
265 gaim_debug_warning("nss", "unable to set socket into non-blocking mode: %d\n", PR_GetError()); 265 purple_debug_warning("nss", "unable to set socket into non-blocking mode: %d\n", PR_GetError());
266 266
267 nss_data->in = SSL_ImportFD(NULL, nss_data->fd); 267 nss_data->in = SSL_ImportFD(NULL, nss_data->fd);
268 268
269 if (nss_data->in == NULL) 269 if (nss_data->in == NULL)
270 { 270 {
271 gaim_debug_error("nss", "nss_data->in == NUL!\n"); 271 purple_debug_error("nss", "nss_data->in == NUL!\n");
272 272
273 if (gsc->error_cb != NULL) 273 if (gsc->error_cb != NULL)
274 gsc->error_cb(gsc, GAIM_SSL_CONNECT_FAILED, gsc->connect_cb_data); 274 gsc->error_cb(gsc, PURPLE_SSL_CONNECT_FAILED, gsc->connect_cb_data);
275 275
276 gaim_ssl_close((GaimSslConnection *)gsc); 276 purple_ssl_close((PurpleSslConnection *)gsc);
277 277
278 return; 278 return;
279 } 279 }
280 280
281 SSL_OptionSet(nss_data->in, SSL_SECURITY, PR_TRUE); 281 SSL_OptionSet(nss_data->in, SSL_SECURITY, PR_TRUE);
295 SSL_HandshakeCallback(nss_data->in, 295 SSL_HandshakeCallback(nss_data->in,
296 (SSLHandshakeCallback) ssl_nss_handshake_cb, gsc); 296 (SSLHandshakeCallback) ssl_nss_handshake_cb, gsc);
297 #endif 297 #endif
298 SSL_ResetHandshake(nss_data->in, PR_FALSE); 298 SSL_ResetHandshake(nss_data->in, PR_FALSE);
299 299
300 nss_data->handshake_handler = gaim_input_add(gsc->fd, 300 nss_data->handshake_handler = purple_input_add(gsc->fd,
301 GAIM_INPUT_READ, ssl_nss_handshake_cb, gsc); 301 PURPLE_INPUT_READ, ssl_nss_handshake_cb, gsc);
302 302
303 ssl_nss_handshake_cb(gsc, gsc->fd, GAIM_INPUT_READ); 303 ssl_nss_handshake_cb(gsc, gsc->fd, PURPLE_INPUT_READ);
304 } 304 }
305 305
306 static void 306 static void
307 ssl_nss_close(GaimSslConnection *gsc) 307 ssl_nss_close(PurpleSslConnection *gsc)
308 { 308 {
309 GaimSslNssData *nss_data = GAIM_SSL_NSS_DATA(gsc); 309 PurpleSslNssData *nss_data = PURPLE_SSL_NSS_DATA(gsc);
310 310
311 if(!nss_data) 311 if(!nss_data)
312 return; 312 return;
313 313
314 if (nss_data->in) PR_Close(nss_data->in); 314 if (nss_data->in) PR_Close(nss_data->in);
315 /* if (nss_data->fd) PR_Close(nss_data->fd); */ 315 /* if (nss_data->fd) PR_Close(nss_data->fd); */
316 316
317 if (nss_data->handshake_handler) 317 if (nss_data->handshake_handler)
318 gaim_input_remove(nss_data->handshake_handler); 318 purple_input_remove(nss_data->handshake_handler);
319 319
320 g_free(nss_data); 320 g_free(nss_data);
321 gsc->private_data = NULL; 321 gsc->private_data = NULL;
322 } 322 }
323 323
324 static size_t 324 static size_t
325 ssl_nss_read(GaimSslConnection *gsc, void *data, size_t len) 325 ssl_nss_read(PurpleSslConnection *gsc, void *data, size_t len)
326 { 326 {
327 ssize_t ret; 327 ssize_t ret;
328 GaimSslNssData *nss_data = GAIM_SSL_NSS_DATA(gsc); 328 PurpleSslNssData *nss_data = PURPLE_SSL_NSS_DATA(gsc);
329 329
330 ret = PR_Read(nss_data->in, data, len); 330 ret = PR_Read(nss_data->in, data, len);
331 331
332 if (ret == -1) 332 if (ret == -1)
333 set_errno(PR_GetError()); 333 set_errno(PR_GetError());
334 334
335 return ret; 335 return ret;
336 } 336 }
337 337
338 static size_t 338 static size_t
339 ssl_nss_write(GaimSslConnection *gsc, const void *data, size_t len) 339 ssl_nss_write(PurpleSslConnection *gsc, const void *data, size_t len)
340 { 340 {
341 ssize_t ret; 341 ssize_t ret;
342 GaimSslNssData *nss_data = GAIM_SSL_NSS_DATA(gsc); 342 PurpleSslNssData *nss_data = PURPLE_SSL_NSS_DATA(gsc);
343 343
344 if(!nss_data) 344 if(!nss_data)
345 return 0; 345 return 0;
346 346
347 ret = PR_Write(nss_data->in, data, len); 347 ret = PR_Write(nss_data->in, data, len);
350 set_errno(PR_GetError()); 350 set_errno(PR_GetError());
351 351
352 return ret; 352 return ret;
353 } 353 }
354 354
355 static GaimSslOps ssl_ops = 355 static PurpleSslOps ssl_ops =
356 { 356 {
357 ssl_nss_init, 357 ssl_nss_init,
358 ssl_nss_uninit, 358 ssl_nss_uninit,
359 ssl_nss_connect, 359 ssl_nss_connect,
360 ssl_nss_close, 360 ssl_nss_close,
364 364
365 #endif /* HAVE_NSS */ 365 #endif /* HAVE_NSS */
366 366
367 367
368 static gboolean 368 static gboolean
369 plugin_load(GaimPlugin *plugin) 369 plugin_load(PurplePlugin *plugin)
370 { 370 {
371 #ifdef HAVE_NSS 371 #ifdef HAVE_NSS
372 if (!gaim_ssl_get_ops()) { 372 if (!purple_ssl_get_ops()) {
373 gaim_ssl_set_ops(&ssl_ops); 373 purple_ssl_set_ops(&ssl_ops);
374 } 374 }
375 375
376 /* Init NSS now, so others can use it even if sslconn never does */ 376 /* Init NSS now, so others can use it even if sslconn never does */
377 ssl_nss_init_nss(); 377 ssl_nss_init_nss();
378 378
381 return FALSE; 381 return FALSE;
382 #endif 382 #endif
383 } 383 }
384 384
385 static gboolean 385 static gboolean
386 plugin_unload(GaimPlugin *plugin) 386 plugin_unload(PurplePlugin *plugin)
387 { 387 {
388 #ifdef HAVE_NSS 388 #ifdef HAVE_NSS
389 if (gaim_ssl_get_ops() == &ssl_ops) { 389 if (purple_ssl_get_ops() == &ssl_ops) {
390 gaim_ssl_set_ops(NULL); 390 purple_ssl_set_ops(NULL);
391 } 391 }
392 #endif 392 #endif
393 393
394 return TRUE; 394 return TRUE;
395 } 395 }
396 396
397 static GaimPluginInfo info = 397 static PurplePluginInfo info =
398 { 398 {
399 GAIM_PLUGIN_MAGIC, 399 PURPLE_PLUGIN_MAGIC,
400 GAIM_MAJOR_VERSION, 400 PURPLE_MAJOR_VERSION,
401 GAIM_MINOR_VERSION, 401 PURPLE_MINOR_VERSION,
402 GAIM_PLUGIN_STANDARD, /**< type */ 402 PURPLE_PLUGIN_STANDARD, /**< type */
403 NULL, /**< ui_requirement */ 403 NULL, /**< ui_requirement */
404 GAIM_PLUGIN_FLAG_INVISIBLE, /**< flags */ 404 PURPLE_PLUGIN_FLAG_INVISIBLE, /**< flags */
405 NULL, /**< dependencies */ 405 NULL, /**< dependencies */
406 GAIM_PRIORITY_DEFAULT, /**< priority */ 406 PURPLE_PRIORITY_DEFAULT, /**< priority */
407 407
408 SSL_NSS_PLUGIN_ID, /**< id */ 408 SSL_NSS_PLUGIN_ID, /**< id */
409 N_("NSS"), /**< name */ 409 N_("NSS"), /**< name */
410 VERSION, /**< version */ 410 VERSION, /**< version */
411 /** summary */ 411 /** summary */
412 N_("Provides SSL support through Mozilla NSS."), 412 N_("Provides SSL support through Mozilla NSS."),
413 /** description */ 413 /** description */
414 N_("Provides SSL support through Mozilla NSS."), 414 N_("Provides SSL support through Mozilla NSS."),
415 "Christian Hammond <chipx86@gnupdate.org>", 415 "Christian Hammond <chipx86@gnupdate.org>",
416 GAIM_WEBSITE, /**< homepage */ 416 PURPLE_WEBSITE, /**< homepage */
417 417
418 plugin_load, /**< load */ 418 plugin_load, /**< load */
419 plugin_unload, /**< unload */ 419 plugin_unload, /**< unload */
420 NULL, /**< destroy */ 420 NULL, /**< destroy */
421 421
424 NULL, /**< prefs_info */ 424 NULL, /**< prefs_info */
425 NULL /**< actions */ 425 NULL /**< actions */
426 }; 426 };
427 427
428 static void 428 static void
429 init_plugin(GaimPlugin *plugin) 429 init_plugin(PurplePlugin *plugin)
430 { 430 {
431 } 431 }
432 432
433 GAIM_INIT_PLUGIN(ssl_nss, init_plugin, info) 433 PURPLE_INIT_PLUGIN(ssl_nss, init_plugin, info)