comparison libpurple/protocols/silc/silc.c @ 22710:a666d3e7447f

Prompt for silc private key passphrase if it is not saved for the account and we are unable to open the private key without it
author Stu Tomlinson <stu@nosnilmot.com>
date Wed, 23 Apr 2008 16:37:28 +0000
parents 3d092dd95ec1
children 67a4c8c46f78 718a9c287839
comparison
equal deleted inserted replaced
22709:3d092dd95ec1 22710:a666d3e7447f
431 silc_socket_tcp_stream_create(source, TRUE, FALSE, 431 silc_socket_tcp_stream_create(source, TRUE, FALSE,
432 sg->client->schedule, 432 sg->client->schedule,
433 silcpurple_stream_created, gc); 433 silcpurple_stream_created, gc);
434 } 434 }
435 435
436 static void silcpurple_running(SilcClient client, void *context) 436 static void silcpurple_continue_running(SilcPurple sg)
437 { 437 {
438 SilcPurple sg = context;
439 PurpleConnection *gc = sg->gc; 438 PurpleConnection *gc = sg->gc;
440 PurpleAccount *account = purple_connection_get_account(gc); 439 PurpleAccount *account = purple_connection_get_account(gc);
441 char pkd[256], prd[256];
442
443
444 /* Progress */
445 purple_connection_update_progress(gc, _("Connecting to SILC Server"), 1, 5);
446
447 /* Load SILC key pair */
448 g_snprintf(pkd, sizeof(pkd), "%s" G_DIR_SEPARATOR_S "public_key.pub", silcpurple_silcdir());
449 g_snprintf(prd, sizeof(prd), "%s" G_DIR_SEPARATOR_S "private_key.prv", silcpurple_silcdir());
450 if (!silc_load_key_pair((char *)purple_account_get_string(account, "public-key", pkd),
451 (char *)purple_account_get_string(account, "private-key", prd),
452 (gc->password == NULL) ? "" : gc->password,
453 &sg->public_key, &sg->private_key)) {
454 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_OTHER_ERROR,
455 _("Could not load SILC key pair"));
456 gc->proto_data = NULL;
457 silc_free(sg);
458 return;
459 }
460 440
461 /* Connect to the SILC server */ 441 /* Connect to the SILC server */
462 if (purple_proxy_connect(gc, account, 442 if (purple_proxy_connect(gc, account,
463 purple_account_get_string(account, "server", 443 purple_account_get_string(account, "server",
464 "silc.silcnet.org"), 444 "silc.silcnet.org"),
469 _("Unable to create connection")); 449 _("Unable to create connection"));
470 gc->proto_data = NULL; 450 gc->proto_data = NULL;
471 silc_free(sg); 451 silc_free(sg);
472 return; 452 return;
473 } 453 }
454 }
455
456 static void silcpurple_got_password_cb(PurpleConnection *gc, PurpleRequestFields *fields)
457 {
458 SilcPurple sg = (SilcPurple)gc->proto_data;
459 PurpleAccount *account = purple_connection_get_account(gc);
460 char pkd[256], prd[256];
461 const char *password;
462 gboolean remember;
463
464 /* The password prompt dialog doesn't get disposed if the account disconnects */
465 if (!PURPLE_CONNECTION_IS_VALID(gc))
466 return;
467
468 password = purple_request_fields_get_string(fields, "password");
469 remember = purple_request_fields_get_bool(fields, "remember");
470
471 if (!password || !*password)
472 {
473 purple_notify_error(gc, NULL, _("Password is required to sign on."), NULL);
474 gc->proto_data = NULL;
475 silc_free(sg);
476 return;
477 }
478
479 if (remember)
480 purple_account_set_remember_password(account, TRUE);
481
482 purple_account_set_password(account, password);
483
484 /* Load SILC key pair */
485 g_snprintf(pkd, sizeof(pkd), "%s" G_DIR_SEPARATOR_S "public_key.pub", silcpurple_silcdir());
486 g_snprintf(prd, sizeof(prd), "%s" G_DIR_SEPARATOR_S "private_key.prv", silcpurple_silcdir());
487 if (!silc_load_key_pair((char *)purple_account_get_string(account, "public-key", pkd),
488 (char *)purple_account_get_string(account, "private-key", prd),
489 password,
490 &sg->public_key, &sg->private_key)) {
491 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_OTHER_ERROR,
492 _("Could not load SILC key pair"));
493 gc->proto_data = NULL;
494 silc_free(sg);
495 return;
496 }
497 silcpurple_continue_running(sg);
498 }
499
500 static void silcpurple_no_password_cb(PurpleConnection *gc, PurpleRequestFields *fields)
501 {
502 SilcPurple sg;
503 /* The password prompt dialog doesn't get disposed if the account disconnects */
504 if (!PURPLE_CONNECTION_IS_VALID(gc))
505 return;
506 sg = gc->proto_data;
507 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_OTHER_ERROR,
508 _("Could not load SILC key pair"));
509 gc->proto_data = NULL;
510 silc_free(sg);
511 }
512
513 static void silcpurple_running(SilcClient client, void *context)
514 {
515 SilcPurple sg = context;
516 PurpleConnection *gc = sg->gc;
517 PurpleAccount *account = purple_connection_get_account(gc);
518 char pkd[256], prd[256];
519
520
521 /* Progress */
522 purple_connection_update_progress(gc, _("Connecting to SILC Server"), 1, 5);
523
524 /* Load SILC key pair */
525 g_snprintf(pkd, sizeof(pkd), "%s" G_DIR_SEPARATOR_S "public_key.pub", silcpurple_silcdir());
526 g_snprintf(prd, sizeof(prd), "%s" G_DIR_SEPARATOR_S "private_key.prv", silcpurple_silcdir());
527 if (!silc_load_key_pair((char *)purple_account_get_string(account, "public-key", pkd),
528 (char *)purple_account_get_string(account, "private-key", prd),
529 (gc->password == NULL) ? "" : gc->password,
530 &sg->public_key, &sg->private_key)) {
531 if (!purple_account_get_password(account)) {
532 purple_account_request_password(account, G_CALLBACK(silcpurple_got_password_cb),
533 G_CALLBACK(silcpurple_no_password_cb), gc);
534 return;
535 }
536 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_OTHER_ERROR,
537 _("Could not load SILC key pair"));
538 gc->proto_data = NULL;
539 silc_free(sg);
540 return;
541 }
542 silcpurple_continue_running(sg);
474 } 543 }
475 544
476 static void 545 static void
477 silcpurple_login(PurpleAccount *account) 546 silcpurple_login(PurpleAccount *account)
478 { 547 {