X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=apps%2Firssi%2Fsrc%2Fsilc%2Fcore%2Fclientutil.c;h=836347338a3457deaa8af281f5d37ef4d6775dc1;hb=52e57c880aba9c5e89f59d962eb9af75670b76e0;hp=4ebf2e9d2e61092af3db2882b3decddb39a054af;hpb=6e259b8f13ead96a13f6a5467487ea2e7b64c248;p=silc.git diff --git a/apps/irssi/src/silc/core/clientutil.c b/apps/irssi/src/silc/core/clientutil.c index 4ebf2e9d..83634733 100644 --- a/apps/irssi/src/silc/core/clientutil.c +++ b/apps/irssi/src/silc/core/clientutil.c @@ -41,15 +41,40 @@ #include "fe-common/core/printtext.h" #include "fe-common/core/keyboard.h" +#include "fe-common/silc/module-formats.h" #include "core.h" +#ifdef SILC_PLUGIN +void silc_client_print_list(char *list) +{ + char **items; + int i=0; + + items = g_strsplit(list, ",", -1); + + while (items[i] != NULL) + printformat_module("fe-common/silc", NULL, NULL, + MSGLEVEL_CRAP, SILCTXT_CONFIG_LIST, + items[i++]); + + g_strfreev(items); +} +#endif + /* Lists supported ciphers */ void silc_client_list_ciphers() { char *ciphers = silc_cipher_get_supported(); +#ifdef SILC_PLUGIN + printformat_module("fe-common/silc", NULL, NULL, + MSGLEVEL_CRAP, SILCTXT_CONFIG_ALGOS, + "cipher"); + silc_client_print_list(ciphers); +#else fprintf(stdout, "%s\n", ciphers); +#endif silc_free(ciphers); } @@ -58,7 +83,14 @@ void silc_client_list_ciphers() void silc_client_list_hash_funcs() { char *hash = silc_hash_get_supported(); +#ifdef SILC_PLUGIN + printformat_module("fe-common/silc", NULL, NULL, + MSGLEVEL_CRAP, SILCTXT_CONFIG_ALGOS, + "hash"); + silc_client_print_list(hash); +#else fprintf(stdout, "%s\n", hash); +#endif silc_free(hash); } @@ -67,7 +99,14 @@ void silc_client_list_hash_funcs() void silc_client_list_hmacs() { char *hash = silc_hmac_get_supported(); +#ifdef SILC_PLUGIN + printformat_module("fe-common/silc", NULL, NULL, + MSGLEVEL_CRAP, SILCTXT_CONFIG_ALGOS, + "hmac"); + silc_client_print_list(hash); +#else fprintf(stdout, "%s\n", hash); +#endif silc_free(hash); } @@ -76,7 +115,14 @@ void silc_client_list_hmacs() void silc_client_list_pkcs() { char *pkcs = silc_pkcs_get_supported(); +#ifdef SILC_PLUGIN + printformat_module("fe-common/silc", NULL, NULL, + MSGLEVEL_CRAP, SILCTXT_CONFIG_ALGOS, + "pkcs"); + silc_client_print_list(pkcs); +#else fprintf(stdout, "%s\n", pkcs); +#endif silc_free(pkcs); } @@ -318,5 +364,108 @@ int silc_client_load_keys(SilcClient client) if (!ret) ret = silc_load_key_pair(pub, prv, NULL, &irssi_pubkey, &irssi_privkey); + if (!ret) + SILC_LOG_ERROR(("Could not load key pair")); + return ret; } + +#ifdef SILC_PLUGIN +void create_key_passphrase(const char *answer, CREATE_KEY_REC *rec) +{ + char priv_key_file[128], pub_key_file[128]; + + signal_stop(); + + if ((rec->passphrase == NULL) && (answer) && (*answer != '\0')) { + rec->passphrase = g_strdup(answer); + keyboard_entry_redirect((SIGNAL_FUNC) create_key_passphrase, + format_get_text("fe-common/silc", NULL, NULL, + NULL, SILCTXT_CONFIG_PASS_ASK2), + ENTRY_REDIRECT_FLAG_HIDDEN, rec); + return; + } + + if ((answer) && (*answer != '\0') && (rec->passphrase != NULL)) { + if (strcmp(answer, rec->passphrase)) { + printformat_module("fe-common/silc", NULL, NULL, + MSGLEVEL_CRAP, SILCTXT_CONFIG_PASSMISMATCH); + g_free(rec->pkcs); + g_free(rec->passphrase); + g_free(rec); + return; + } + } + + memset(priv_key_file, 0, sizeof(priv_key_file)); + memset(pub_key_file, 0, sizeof(pub_key_file)); + snprintf(priv_key_file, sizeof(priv_key_file) - 1, "%s/%s", + get_irssi_dir(), SILC_CLIENT_PRIVATE_KEY_NAME); + snprintf(pub_key_file, sizeof(pub_key_file) - 1, "%s/%s", + get_irssi_dir(), SILC_CLIENT_PUBLIC_KEY_NAME); + + if (silc_create_key_pair(rec->pkcs, rec->bits, pub_key_file, priv_key_file, + NULL, (rec->passphrase == NULL ? "" : rec->passphrase), + NULL, NULL, FALSE) == TRUE) + printformat_module("fe-common/silc", NULL, NULL, + MSGLEVEL_CRAP, SILCTXT_CONFIG_CREATE); + else + printformat_module("fe-common/silc", NULL, NULL, + MSGLEVEL_CRAP, SILCTXT_CONFIG_CREATE_FAIL); + + g_free(rec->passphrase); + g_free(rec->pkcs); + g_free(rec); +} + +void change_private_key_passphrase(const char *answer, CREATE_KEY_REC *rec) +{ + signal_stop(); + + if (rec->old == NULL) { + rec->old = g_strdup((answer == NULL ? "" : answer)); + keyboard_entry_redirect((SIGNAL_FUNC) change_private_key_passphrase, + format_get_text("fe-common/silc", NULL, NULL, + NULL, SILCTXT_CONFIG_PASS_ASK2), + ENTRY_REDIRECT_FLAG_HIDDEN, rec); + return; + } + + if ((rec->passphrase == NULL) && (answer) && (*answer != '\0')) { + rec->passphrase = g_strdup(answer); + keyboard_entry_redirect((SIGNAL_FUNC) change_private_key_passphrase, + format_get_text("fe-common/silc", NULL, NULL, + NULL, SILCTXT_CONFIG_PASS_ASK3), + ENTRY_REDIRECT_FLAG_HIDDEN, rec); + return; + } + + if ((answer) && (*answer != '\0') && (rec->passphrase != NULL)) { + if (strcmp(answer, rec->passphrase)) { + printformat_module("fe-common/silc", NULL, NULL, + MSGLEVEL_CRAP, SILCTXT_CONFIG_PASSMISMATCH); + g_free(rec->old); + g_free(rec->file); + g_free(rec->pkcs); + g_free(rec->passphrase); + g_free(rec); + return; + } + } + + if (silc_change_private_key_passphrase(rec->file, rec->old, + (rec->passphrase == NULL ? + "" : rec->passphrase)) == TRUE) + printformat_module("fe-common/silc", NULL, NULL, + MSGLEVEL_CRAP, SILCTXT_CONFIG_PASSCHANGE); + else + printformat_module("fe-common/silc", NULL, NULL, + MSGLEVEL_CRAP, SILCTXT_CONFIG_PASSCHANGE_FAIL); + g_free(rec->old); + g_free(rec->file); + g_free(rec->passphrase); + g_free(rec->pkcs); + g_free(rec); + +} +#endif