/** * Sets the key for a nick / channel in a server * @param data command * @param server irssi server record * @param item irssi window/item */ void cmd_setkey(const char *data, SERVER_REC *server, WI_ITEM_REC *item) { GHashTable *optlist; char contactName[CONTACT_SIZE]="", encryptedKey[150]=""; const char *target, *key; void *free_arg; if (IsNULLorEmpty(data)) { printtext(server, item!=NULL ? window_item_get_target(item) : NULL, MSGLEVEL_CRAP, "\002FiSH:\002 No parameters. Usage: /setkey [-<server tag>] [<nick | #channel>] <key>"); return; } if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS | PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST, "setkey", &optlist, &target, &key)) return; if (*target=='\0') { printtext(server, item!=NULL ? window_item_get_target(item) : NULL, MSGLEVEL_CRAP, "\002FiSH:\002 No parameters. Usage: /setkey [-<server tag>] [<nick | #channel>] <key>"); cmd_params_free(free_arg); return; } server = cmd_options_get_server("setkey", optlist, server); if (server == NULL || !server->connected) cmd_param_error(CMDERR_NOT_CONNECTED); if (*key=='\0') { // one paramter given - it's the key key = target; if (item != NULL) target = window_item_get_target(item); else { printtext(NULL, NULL, MSGLEVEL_CRAP, "\002FiSH:\002 Please define nick/#channel. Usage: /setkey [-<server tag>] [<nick | #channel>] <key>"); cmd_params_free(free_arg); return; } } encrypt_key((char *)key, encryptedKey); if (GetIniSectionForContact(server, target, contactName)==FALSE) return; if (WritePrivateProfileString(contactName, "key", encryptedKey, iniPath) == -1) { ZeroMemory(encryptedKey, sizeof(encryptedKey)); printtext(server, item!=NULL ? window_item_get_target(item) : NULL, MSGLEVEL_CRAP, "\002FiSH ERROR:\002 Unable to write to blow.ini, probably out of space or permission denied."); cmd_params_free(free_arg); return; } ZeroMemory(encryptedKey, sizeof(encryptedKey)); printtext(server, item!=NULL ? window_item_get_target(item) : NULL, MSGLEVEL_CRAP, "\002FiSH:\002 Key for %s@%s successfully set!", target, server->tag); cmd_params_free(free_arg); }
void DH1080_received(SERVER_REC * server, char *msg, char *nick, char *address, char *target) { int i; char hisPubKey[300], contactName[CONTACT_SIZE] = "", encryptedKey[KEYBUF_SIZE] = ""; if (ischannel(*target) || ischannel(*nick)) return; // no KeyXchange for channels... i = strlen(msg); if (i < 191 || i > 195) return; if (strncmp(msg, "DH1080_INIT ", 12) == 0) { strcpy(hisPubKey, msg + 12); if (strspn(hisPubKey, B64ABC) != strlen(hisPubKey)) return; if (query_find(server, nick) == NULL) { // query window not found, lets create one keyx_query_created = 1; irc_query_create(server->tag, nick, TRUE); keyx_query_created = 0; } printtext(server, nick, MSGLEVEL_CRAP, "\002FiSH:\002 Received DH1080 public key from %s, sending mine...", nick); DH1080_gen(g_myPrivKey, g_myPubKey); irc_send_cmdv((IRC_SERVER_REC *) server, "NOTICE %s :%s %s", nick, "DH1080_FINISH", g_myPubKey); } else if (strncmp(msg, "DH1080_FINISH ", 14) == 0) strcpy(hisPubKey, msg + 14); else return; if (DH1080_comp(g_myPrivKey, hisPubKey) == 0) return; signal_stop(); encrypt_key(hisPubKey, encryptedKey); ZeroMemory(hisPubKey, sizeof(hisPubKey)); if (getIniSectionForContact(server, nick, contactName) == FALSE) return; if (setIniValue(contactName, "key", encryptedKey, iniPath) == -1) { ZeroMemory(encryptedKey, KEYBUF_SIZE); printtext(server, nick, MSGLEVEL_CRAP, "\002FiSH ERROR:\002 Unable to write to blow.ini, probably out of space or permission denied."); return; } ZeroMemory(encryptedKey, KEYBUF_SIZE); printtext(server, nick, MSGLEVEL_CRAP, "\002FiSH:\002 Key for %s successfully set!", nick); }