comparison src/protocols/silc/silc.c @ 12167:5851a9219bc7

[gaim-migrate @ 14468] Some SILC fixes from Pekka for whiteboard support, preferences, and documentation. Let's hear a big thanks to Pekka for keeping up with this stuff! Enclosed patch fixes couple crashbugs from the SILC whiteboard code, fixes the preferences (which are not used anymore in Gaim) by eliminating some of the old preferences and moving some of the preferences to account options, and introduces Create SILC Key Pair protocol action which can be used to generate new SILC key pair from Gaim. committer: Tailor Script <tailor@pidgin.im>
author Ethan Blanton <elb@pidgin.im>
date Sun, 20 Nov 2005 00:59:36 +0000
parents 4e46eeec4ace
children 4d3119205a33
comparison
equal deleted inserted replaced
12166:d6417efb990c 12167:5851a9219bc7
314 g_snprintf(prd, sizeof(prd), "%s" G_DIR_SEPARATOR_S "private_key.prv", silcgaim_silcdir()); 314 g_snprintf(prd, sizeof(prd), "%s" G_DIR_SEPARATOR_S "private_key.prv", silcgaim_silcdir());
315 if (!silc_load_key_pair((char *)gaim_account_get_string(account, "public-key", pkd), 315 if (!silc_load_key_pair((char *)gaim_account_get_string(account, "public-key", pkd),
316 (char *)gaim_account_get_string(account, "private-key", prd), 316 (char *)gaim_account_get_string(account, "private-key", prd),
317 (gc->password == NULL) ? "" : gc->password, &client->pkcs, 317 (gc->password == NULL) ? "" : gc->password, &client->pkcs,
318 &client->public_key, &client->private_key)) { 318 &client->public_key, &client->private_key)) {
319 gaim_connection_error(gc, ("Could not load SILC key pair")); 319 g_snprintf(pkd, sizeof(pkd), ("Could not load SILC key pair: %s"), strerror(errno));
320 gaim_connection_error(gc, pkd);
320 return; 321 return;
321 } 322 }
322 323
323 sg = silc_calloc(1, sizeof(*sg)); 324 sg = silc_calloc(1, sizeof(*sg));
324 if (!sg) 325 if (!sg)
510 val = NULL; 511 val = NULL;
511 f = gaim_request_fields_get_field(fields, "vcard"); 512 f = gaim_request_fields_get_field(fields, "vcard");
512 if (f) 513 if (f)
513 val = gaim_request_field_string_get_value(f); 514 val = gaim_request_field_string_get_value(f);
514 if (val && *val) { 515 if (val && *val) {
515 gaim_prefs_set_string("/plugins/prpl/silc/vcard", val); 516 gaim_account_set_string(sg->account, "vcard", val);
516 tmp = silc_file_readfile(val, &tmp_len); 517 tmp = silc_file_readfile(val, &tmp_len);
517 if (tmp) { 518 if (tmp) {
518 tmp[tmp_len] = 0; 519 tmp[tmp_len] = 0;
519 if (silc_vcard_decode((unsigned char *)tmp, tmp_len, &vcard)) 520 if (silc_vcard_decode((unsigned char *)tmp, tmp_len, &vcard))
520 silc_client_attribute_add(client, conn, 521 silc_client_attribute_add(client, conn,
522 (void *)&vcard, 523 (void *)&vcard,
523 sizeof(vcard)); 524 sizeof(vcard));
524 } 525 }
525 silc_vcard_free(&vcard); 526 silc_vcard_free(&vcard);
526 silc_free(tmp); 527 silc_free(tmp);
528 } else {
529 gaim_account_set_string(sg->account, "vcard", "");
527 } 530 }
528 531
529 #ifdef HAVE_SYS_UTSNAME_H 532 #ifdef HAVE_SYS_UTSNAME_H
530 /* Set device info */ 533 /* Set device info */
531 f = gaim_request_fields_get_field(fields, "device"); 534 f = gaim_request_fields_get_field(fields, "device");
694 #endif 697 #endif
695 gaim_request_fields_add_group(fields, g); 698 gaim_request_fields_add_group(fields, g);
696 699
697 g = gaim_request_field_group_new(NULL); 700 g = gaim_request_field_group_new(NULL);
698 f = gaim_request_field_string_new("vcard", _("Your VCard File"), 701 f = gaim_request_field_string_new("vcard", _("Your VCard File"),
699 gaim_prefs_get_string("/plugins/prpl/silc/vcard"), 702 gaim_account_get_string(sg->account, "vcard", ""),
700 FALSE); 703 FALSE);
701 gaim_request_field_group_add_field(g, f); 704 gaim_request_field_group_add_field(g, f);
702 #ifdef _WIN32 705 #ifdef _WIN32
703 f = gaim_request_field_string_new("timezone", _("Timezone"), _tzname[0], FALSE); 706 f = gaim_request_field_string_new("timezone", _("Timezone"), _tzname[0], FALSE);
704 #else 707 #else
705 f = gaim_request_field_string_new("timezone", _("Timezone"), tzname[0], FALSE); 708 f = gaim_request_field_string_new("timezone", _("Timezone"), tzname[0], FALSE);
706 #endif 709 #endif
707 gaim_request_field_group_add_field(g, f); 710 gaim_request_field_group_add_field(g, f);
708 gaim_request_fields_add_group(fields, g); 711 gaim_request_fields_add_group(fields, g);
709
710 712
711 gaim_request_fields(gc, _("User Online Status Attributes"), 713 gaim_request_fields(gc, _("User Online Status Attributes"),
712 _("User Online Status Attributes"), 714 _("User Online Status Attributes"),
713 _("You can let other users see your online status information " 715 _("You can let other users see your online status information "
714 "and your personal information. Please fill the information " 716 "and your personal information. Please fill the information "
760 tmp, NULL, NULL); 762 tmp, NULL, NULL);
761 g_free(tmp); 763 g_free(tmp);
762 } 764 }
763 765
764 static void 766 static void
767 silcgaim_create_keypair_cancel(GaimConnection *gc, GaimRequestFields *fields)
768 {
769 /* Nothing */
770 }
771
772 static void
773 silcgaim_create_keypair_cb(GaimConnection *gc, GaimRequestFields *fields)
774 {
775 SilcGaim sg = gc->proto_data;
776 GaimRequestField *f;
777 const char *val, *pkfile = NULL, *prfile = NULL;
778 const char *pass1 = NULL, *pass2 = NULL, *un = NULL, *hn = NULL;
779 const char *rn = NULL, *e = NULL, *o = NULL, *c = NULL;
780 char *identifier;
781 int keylen = SILCGAIM_DEF_PKCS_LEN;
782 SilcPublicKey public_key;
783
784 sg = gc->proto_data;
785 if (!sg)
786 return;
787
788 val = NULL;
789 f = gaim_request_fields_get_field(fields, "pass1");
790 if (f)
791 val = gaim_request_field_string_get_value(f);
792 if (val && *val)
793 pass1 = val;
794 else
795 pass1 = "";
796 val = NULL;
797 f = gaim_request_fields_get_field(fields, "pass2");
798 if (f)
799 val = gaim_request_field_string_get_value(f);
800 if (val && *val)
801 pass2 = val;
802 else
803 pass2 = "";
804
805 if (strcmp(pass1, pass2)) {
806 gaim_notify_error(
807 gc, _("Create New SILC Key Pair"), _("Passphrases do not match"), NULL);
808 return;
809 }
810
811 val = NULL;
812 f = gaim_request_fields_get_field(fields, "key");
813 if (f)
814 val = gaim_request_field_string_get_value(f);
815 if (val && *val)
816 keylen = atoi(val);
817 f = gaim_request_fields_get_field(fields, "pkfile");
818 if (f)
819 pkfile = gaim_request_field_string_get_value(f);
820 f = gaim_request_fields_get_field(fields, "prfile");
821 if (f)
822 prfile = gaim_request_field_string_get_value(f);
823
824 f = gaim_request_fields_get_field(fields, "un");
825 if (f)
826 un = gaim_request_field_string_get_value(f);
827 f = gaim_request_fields_get_field(fields, "hn");
828 if (f)
829 hn = gaim_request_field_string_get_value(f);
830 f = gaim_request_fields_get_field(fields, "rn");
831 if (f)
832 rn = gaim_request_field_string_get_value(f);
833 f = gaim_request_fields_get_field(fields, "e");
834 if (f)
835 e = gaim_request_field_string_get_value(f);
836 f = gaim_request_fields_get_field(fields, "o");
837 if (f)
838 o = gaim_request_field_string_get_value(f);
839 f = gaim_request_fields_get_field(fields, "c");
840 if (f)
841 c = gaim_request_field_string_get_value(f);
842
843 identifier = silc_pkcs_encode_identifier((char *)un, (char *)hn,
844 (char *)rn, (char *)e, (char *)o, (char *)c);
845
846 /* Create the key pair */
847 if (!silc_create_key_pair(SILCGAIM_DEF_PKCS, keylen, pkfile, prfile,
848 identifier, pass1, NULL, &public_key, NULL,
849 FALSE)) {
850 gaim_notify_error(
851 gc, _("Create New SILC Key Pair"), _("Key Pair Generation failed"), NULL);
852 return;
853 }
854
855 silcgaim_show_public_key(sg, NULL, public_key, NULL, NULL);
856
857 silc_pkcs_public_key_free(public_key);
858 silc_free(identifier);
859 }
860
861 static void
862 silcgaim_create_keypair(GaimPluginAction *action)
863 {
864 GaimConnection *gc = (GaimConnection *) action->context;
865 SilcGaim sg = gc->proto_data;
866 GaimRequestFields *fields;
867 GaimRequestFieldGroup *g;
868 GaimRequestField *f;
869 const char *username, *realname;
870 char *hostname, **u;
871 char tmp[256], pkd[256], pkd2[256], prd[256], prd2[256];
872
873 username = gaim_account_get_username(sg->account);
874 u = g_strsplit(username, "@", 2);
875 username = u[0];
876 realname = gaim_account_get_user_info(sg->account);
877 hostname = silc_net_localhost();
878 g_snprintf(tmp, sizeof(tmp), "%s@%s", username, hostname);
879
880 g_snprintf(pkd2, sizeof(pkd2), "%s" G_DIR_SEPARATOR_S"public_key.pub", silcgaim_silcdir());
881 g_snprintf(prd2, sizeof(prd2), "%s" G_DIR_SEPARATOR_S"private_key.prv", silcgaim_silcdir());
882 g_snprintf(pkd, sizeof(pkd) - 1, "%s",
883 gaim_account_get_string(gc->account, "public-key", pkd2));
884 g_snprintf(prd, sizeof(prd) - 1, "%s",
885 gaim_account_get_string(gc->account, "private-key", prd2));
886
887 fields = gaim_request_fields_new();
888
889 g = gaim_request_field_group_new(NULL);
890 f = gaim_request_field_string_new("key", _("Key Length"), "2048", FALSE);
891 gaim_request_field_group_add_field(g, f);
892 f = gaim_request_field_string_new("pkfile", _("Public Key File"), pkd, FALSE);
893 gaim_request_field_group_add_field(g, f);
894 f = gaim_request_field_string_new("prfile", _("Private Key File"), prd, FALSE);
895 gaim_request_field_group_add_field(g, f);
896 gaim_request_fields_add_group(fields, g);
897
898 g = gaim_request_field_group_new(NULL);
899 f = gaim_request_field_string_new("un", _("Username"), username ? username : "", FALSE);
900 gaim_request_field_group_add_field(g, f);
901 f = gaim_request_field_string_new("hn", _("Hostname"), hostname ? hostname : "", FALSE);
902 gaim_request_field_group_add_field(g, f);
903 f = gaim_request_field_string_new("rn", _("Real Name"), realname ? realname : "", FALSE);
904 gaim_request_field_group_add_field(g, f);
905 f = gaim_request_field_string_new("e", _("Email"), tmp, FALSE);
906 gaim_request_field_group_add_field(g, f);
907 f = gaim_request_field_string_new("o", _("Organization"), "", FALSE);
908 gaim_request_field_group_add_field(g, f);
909 f = gaim_request_field_string_new("c", _("Country"), "", FALSE);
910 gaim_request_field_group_add_field(g, f);
911 gaim_request_fields_add_group(fields, g);
912
913 g = gaim_request_field_group_new(NULL);
914 f = gaim_request_field_string_new("pass1", _("Passphrase"), "", FALSE);
915 gaim_request_field_string_set_masked(f, TRUE);
916 gaim_request_field_group_add_field(g, f);
917 f = gaim_request_field_string_new("pass2", _("Re-type Passphrase"), "", FALSE);
918 gaim_request_field_string_set_masked(f, TRUE);
919 gaim_request_field_group_add_field(g, f);
920 gaim_request_fields_add_group(fields, g);
921
922 gaim_request_fields(gc, _("Create New SILC Key Pair"),
923 _("Create New SILC Key Pair"), NULL, fields,
924 _("Generate Key Pair"), G_CALLBACK(silcgaim_create_keypair_cb),
925 _("Cancel"), G_CALLBACK(silcgaim_create_keypair_cancel), gc);
926
927 g_strfreev(u);
928 silc_free(hostname);
929 }
930
931 static void
765 silcgaim_change_pass(GaimPluginAction *action) 932 silcgaim_change_pass(GaimPluginAction *action)
766 { 933 {
767 GaimConnection *gc = (GaimConnection *) action->context; 934 GaimConnection *gc = (GaimConnection *) action->context;
768 gaim_account_request_change_password(gaim_connection_get_account(gc)); 935 gaim_account_request_change_password(gaim_connection_get_account(gc));
769 } 936 }
807 silcgaim_detach); 974 silcgaim_detach);
808 list = g_list_append(list, act); 975 list = g_list_append(list, act);
809 976
810 act = gaim_plugin_action_new(_("View Message of the Day"), 977 act = gaim_plugin_action_new(_("View Message of the Day"),
811 silcgaim_view_motd); 978 silcgaim_view_motd);
979 list = g_list_append(list, act);
980
981 act = gaim_plugin_action_new(_("Create SILC Key Pair..."),
982 silcgaim_create_keypair);
812 list = g_list_append(list, act); 983 list = g_list_append(list, act);
813 984
814 act = gaim_plugin_action_new(_("Change Password..."), 985 act = gaim_plugin_action_new(_("Change Password..."),
815 silcgaim_change_pass); 986 silcgaim_change_pass);
816 list = g_list_append(list, act); 987 list = g_list_append(list, act);
899 SilcClientConnection conn = sg->conn; 1070 SilcClientConnection conn = sg->conn;
900 SilcClientEntry *clients; 1071 SilcClientEntry *clients;
901 SilcUInt32 clients_count, mflags; 1072 SilcUInt32 clients_count, mflags;
902 char *nickname; 1073 char *nickname;
903 int ret; 1074 int ret;
904 gboolean sign = gaim_prefs_get_bool("/plugins/prpl/silc/sign_im"); 1075 gboolean sign = gaim_account_get_bool(sg->account, "sign-verify", FALSE);
905 1076
906 if (!who || !msg) 1077 if (!who || !msg)
907 return 0; 1078 return 0;
908 1079
909 mflags = SILC_MESSAGE_FLAG_UTF8; 1080 mflags = SILC_MESSAGE_FLAG_UTF8;
1441 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", silcgaim_cmd_names, 1612 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", silcgaim_cmd_names,
1442 _("names [-count|-ops|-halfops|-voices|-normal] &lt;channel(s)&gt;: List specific users in channel(s)")); 1613 _("names [-count|-ops|-halfops|-voices|-normal] &lt;channel(s)&gt;: List specific users in channel(s)"));
1443 #endif 1614 #endif
1444 } 1615 }
1445 1616
1446 static GaimPluginPrefFrame *
1447 silcgaim_pref_frame(GaimPlugin *plugin)
1448 {
1449 GaimPluginPrefFrame *frame;
1450 GaimPluginPref *ppref;
1451
1452 frame = gaim_plugin_pref_frame_new();
1453
1454 ppref = gaim_plugin_pref_new_with_label(_("Instant Messages"));
1455 gaim_plugin_pref_frame_add(frame, ppref);
1456
1457 ppref = gaim_plugin_pref_new_with_name_and_label(
1458 "/plugins/prpl/silc/sign_im",
1459 _("Digitally sign all IM messages"));
1460 gaim_plugin_pref_frame_add(frame, ppref);
1461
1462 ppref = gaim_plugin_pref_new_with_name_and_label(
1463 "/plugins/prpl/silc/verify_im",
1464 _("Verify all IM message signatures"));
1465 gaim_plugin_pref_frame_add(frame, ppref);
1466
1467 ppref = gaim_plugin_pref_new_with_label(_("Channel Messages"));
1468 gaim_plugin_pref_frame_add(frame, ppref);
1469
1470 ppref = gaim_plugin_pref_new_with_name_and_label(
1471 "/plugins/prpl/silc/sign_chat",
1472 _("Digitally sign all channel messages"));
1473 gaim_plugin_pref_frame_add(frame, ppref);
1474
1475 ppref = gaim_plugin_pref_new_with_name_and_label(
1476 "/plugins/prpl/silc/verify_chat",
1477 _("Verify all channel message signatures"));
1478 gaim_plugin_pref_frame_add(frame, ppref);
1479
1480 return frame;
1481 }
1482
1483 static GaimPluginUiInfo prefs_info =
1484 {
1485 silcgaim_pref_frame,
1486 };
1487
1488 static GaimWhiteboardPrplOps silcgaim_wb_ops = 1617 static GaimWhiteboardPrplOps silcgaim_wb_ops =
1489 { 1618 {
1490 silcgaim_wb_start, 1619 silcgaim_wb_start,
1491 silcgaim_wb_end, 1620 silcgaim_wb_end,
1492 silcgaim_wb_get_dimensions, 1621 silcgaim_wb_get_dimensions,
1586 NULL, /**< unload */ 1715 NULL, /**< unload */
1587 NULL, /**< destroy */ 1716 NULL, /**< destroy */
1588 1717
1589 NULL, /**< ui_info */ 1718 NULL, /**< ui_info */
1590 &prpl_info, /**< extra_info */ 1719 &prpl_info, /**< extra_info */
1591 &prefs_info, /**< prefs_info */ 1720 NULL, /**< prefs_info */
1592 silcgaim_actions 1721 silcgaim_actions
1593 }; 1722 };
1594 1723
1595 static void 1724 static void
1596 init_plugin(GaimPlugin *plugin) 1725 init_plugin(GaimPlugin *plugin)
1633 "block-ims", FALSE); 1762 "block-ims", FALSE);
1634 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 1763 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
1635 option = gaim_account_option_bool_new(_("Reject online status attribute requests"), 1764 option = gaim_account_option_bool_new(_("Reject online status attribute requests"),
1636 "reject-attrs", FALSE); 1765 "reject-attrs", FALSE);
1637 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 1766 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
1638 1767 option = gaim_account_option_bool_new(_("Block messages to whiteboard"),
1639 /* Preferences */ 1768 "block-wb", FALSE);
1640 gaim_prefs_add_none("/plugins/prpl/silc"); 1769 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
1641 gaim_prefs_add_bool("/plugins/prpl/silc/sign_im", FALSE); 1770 option = gaim_account_option_bool_new(_("Automatically open whiteboard"),
1642 gaim_prefs_add_bool("/plugins/prpl/silc/verify_im", FALSE); 1771 "open-wb", FALSE);
1643 gaim_prefs_add_bool("/plugins/prpl/silc/sign_chat", FALSE); 1772 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
1644 gaim_prefs_add_bool("/plugins/prpl/silc/verify_chat", FALSE); 1773 option = gaim_account_option_bool_new(_("Digitally sign and verify all messages"),
1645 gaim_prefs_add_string("/plugins/prpl/silc/vcard", ""); 1774 "sign-verify", FALSE);
1775 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
1776
1777 gaim_prefs_remove("/plugins/prpl/silc");
1646 1778
1647 silcgaim_register_commands(); 1779 silcgaim_register_commands();
1648 1780
1649 #ifdef _WIN32 1781 #ifdef _WIN32
1650 silc_net_win32_init(); 1782 silc_net_win32_init();