/* SYNTAX: UPGRADE [<irssi binary path>] */ static void cmd_upgrade(const char *data) { CONFIG_REC *session; char *session_file, *str; char *binary; if (*data == '\0') data = irssi_binary; if ((binary = g_find_program_in_path(data)) == NULL) cmd_return_error(CMDERR_PROGRAM_NOT_FOUND); /* save the session */ session_file = g_strdup_printf("%s/session", get_irssi_dir()); session = config_open(session_file, 0600); unlink(session_file); signal_emit("session save", 1, session); config_write(session, NULL, -1); config_close(session); /* data may contain some other program as well, like /UPGRADE /usr/bin/screen irssi */ str = g_strdup_printf("%s --noconnect --session=%s --home=%s --config=%s", binary, session_file, get_irssi_dir(), get_irssi_config()); g_free(binary); g_free(session_file); session_args = g_strsplit(str, " ", -1); g_free(str); signal_emit("gui exit", 0); }
void get_ini_password_hash(int password_size, char* password) { strcpy(iniPath, get_irssi_config()); // path to irssi config file strcpy(strrchr(iniPath, '/'), blow_ini); getIniValue("FiSH", "ini_password_Hash", "0", password, password_size, iniPath); }
/* SYNTAX: RELOAD [<file>] */ static void cmd_reload(const char *data) { const char *fname; fname = *data == '\0' ? get_irssi_config() : data; if (settings_reread(fname)) { printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_CONFIG_RELOADED, fname); } }
static CONFIG_REC *parse_configfile(const char *fname) { CONFIG_REC *config; struct stat statbuf; const char *path; char *str; if (fname == NULL) fname = get_irssi_config(); if (stat(fname, &statbuf) == 0) path = fname; else { /* user configuration file not found, use the default one from sysconfdir */ path = SYSCONFDIR"/"IRSSI_GLOBAL_CONFIG; if (stat(path, &statbuf) != 0) { /* no configuration file in sysconfdir .. use the build-in configuration */ path = NULL; } } config = config_open(path, -1); if (config == NULL) { str = g_strdup_printf("Error opening configuration file %s: %s", path, g_strerror(errno)); signal_emit("gui dialog", 2, "error", str); g_free(str); config = config_open(NULL, -1); } if (config->fname != NULL) config_parse(config); else config_parse_data(config, default_config, "internal"); config_change_file_name(config, fname, 0660); irssi_config_save_state(fname); return config; }
BOOL DH1080_Init() { unsigned char raw_buf[256], iniHash[33]; FILE *hRnd; hRnd = fopen("/dev/urandom", "rb"); // don't use /dev/random, it's a blocking device if(!hRnd) return FALSE; // #*#*#*#*#* RNG START #*#*#*#*#* if(fread(raw_buf, 1, sizeof(raw_buf), hRnd) < 128) /* At least 128 bytes of seeding */ { ZeroMemory(raw_buf, sizeof(raw_buf)); fclose(hRnd); return FALSE; } fclose(hRnd); sha_file(iniPath, (char *)iniHash); memXOR((char *)raw_buf+128, (char *)iniHash, 32); sha_file((char *)get_irssi_config(), (char *)iniHash); memXOR((char *)raw_buf+128, (char *)iniHash, 32); ZeroMemory(iniHash, sizeof(iniHash)); // first 128 byte in raw_buf: output from /dev/urandom // last 32 byte in raw_buf: SHA-256 digest from blow.ini and irssi.conf /* Seed and initialize ISAAC */ memcpy(csprng.randrsl, raw_buf, sizeof(raw_buf)); randinit(&csprng, TRUE); /* RNG END */ initb64(); mpz_init(b_prime1080); mpz_import(b_prime1080, DH1080_PRIME_BYTES, 1, 1, 0, 0, prime1080); return TRUE; }
void fish_init(void) { char iniPasswordHash[50], SHA256digest[35], B64digest[50], *iniPass_ptr; int i; strcpy(iniPath, get_irssi_config()); // path to irssi config file strcpy(tempPath, iniPath); strcpy(strrchr(iniPath, '/'), blow_ini); strcpy(strrchr(tempPath, '/'), "/temp_FiSH.$$$"); if (DH1080_Init()==FALSE) return; GetPrivateProfileString("FiSH", "ini_password_Hash", "0", iniPasswordHash, sizeof(iniPasswordHash), iniPath); if (strlen(iniPasswordHash) == 43) { iniPass_ptr = getpass(" --> Please enter your blow.ini password: "******"\002FiSH:\002 Wrong blow.ini password entered, try again..."); printtext(NULL, NULL, MSGLEVEL_CRAP, "\002FiSH module NOT loaded.\002"); return; } printtext(NULL, NULL, MSGLEVEL_CRAP, "\002FiSH:\002 Correct blow.ini password entered, lets go!"); } else { strcpy(iniKey, default_iniKey); printtext(NULL, NULL, MSGLEVEL_CRAP, "\002FiSH:\002 Using default password to decrypt blow.ini... Try /setinipw to set a custom password."); } signal_add_first("server sendmsg", (SIGNAL_FUNC) encrypt_msg); signal_add_first("message private", (SIGNAL_FUNC) decrypt_msg); signal_add_first("message public", (SIGNAL_FUNC) decrypt_msg); signal_add_first("message irc notice", (SIGNAL_FUNC) decrypt_notice); signal_add_first("message irc action", (SIGNAL_FUNC) decrypt_action); signal_add_first("message own_private", (SIGNAL_FUNC) format_msg); signal_add_first("message own_public", (SIGNAL_FUNC) format_msg); signal_add_first("channel topic changed", (SIGNAL_FUNC) decrypt_changed_topic); signal_add_first("message topic", (SIGNAL_FUNC) decrypt_topic); signal_add_first("server incoming", (SIGNAL_FUNC) raw_handler); signal_add("query created", (SIGNAL_FUNC) do_auto_keyx); signal_add("query nick changed", (SIGNAL_FUNC) query_nick_changed); command_bind("topic+", NULL, (SIGNAL_FUNC) cmd_crypt_TOPIC); command_bind("notice+", NULL, (SIGNAL_FUNC) cmd_crypt_notice); command_bind("notfish", NULL, (SIGNAL_FUNC) cmd_crypt_notice); command_bind("me+", NULL, (SIGNAL_FUNC) cmd_crypt_action); command_bind("setkey", NULL, (SIGNAL_FUNC) cmd_setkey); command_bind("delkey", NULL, (SIGNAL_FUNC) cmd_delkey); command_bind("key", NULL, (SIGNAL_FUNC) cmd_key); command_bind("showkey", NULL, (SIGNAL_FUNC) cmd_key); command_bind("keyx", NULL, (SIGNAL_FUNC) cmd_keyx); command_bind("setinipw", NULL, (SIGNAL_FUNC) cmd_setinipw); command_bind("unsetinipw", NULL, (SIGNAL_FUNC) cmd_unsetinipw); command_bind("fishhelp", NULL, (SIGNAL_FUNC) cmd_helpfish); command_bind("helpfish", NULL, (SIGNAL_FUNC) cmd_helpfish); printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE, "FiSH v1.00 - encryption module for irssi loaded! URL: https://github.com/falsovsky/FiSH-irssi\n" "Try /helpfish or /fishhelp for a short command overview"); module_register("fish", "core"); }
// Input: priv_key = buffer of 200 bytes // pub_key = buffer of 200 bytes // Output: priv_key = Your private key // pub_key = Your public key int DH1080_gen(char *priv_key, char *pub_key) { unsigned char raw_buf[160], iniHash[33]; unsigned long seed; int len, iRet; big b_privkey, b_pubkey; csprng myRNG; FILE *hRnd; priv_key[0]='0'; priv_key[1]='\0'; pub_key[0]='0'; pub_key[1]='\0'; hRnd = fopen("/dev/urandom", "r"); // don't use /dev/random, it's a blocking device if(!hRnd) return 0; b_privkey=mirvar(0); b_pubkey=mirvar(0); // #*#*#*#*#* RNG START #*#*#*#*#* time((time_t *)&seed); seed ^= (long)hRnd << 16; if(fread(raw_buf, 1, sizeof(raw_buf), hRnd) < 32) { ZeroMemory(raw_buf, sizeof(raw_buf)); fclose(hRnd); mirkill(b_privkey); mirkill(b_pubkey); return 0; } fclose(hRnd); sha_file(iniPath, iniHash); memXOR(raw_buf+128, iniHash, 32); sha_file((unsigned char *)get_irssi_config(), iniHash); memXOR(raw_buf+128, iniHash, 32); ZeroMemory(iniHash, sizeof(iniHash)); // first 128 byte in raw_buf: output from /dev/urandom // last 32 byte in raw_buf: SHA-256 digest from blow.ini and irssi.conf seed *= (unsigned long)mip; strong_init(&myRNG, sizeof(raw_buf), raw_buf, (unsigned int)seed); strong_rng(&myRNG); strong_bigdig(&myRNG, 1080, 2, b_privkey); strong_kill(&myRNG); seed=0; // #*#*#*#*#* RNG END #*#*#*#*#* powltr(2, b_privkey, b_prime1080, b_pubkey); if(DH_verifyPubKey(b_pubkey)) { len=big_to_bytes(sizeof(raw_buf), b_privkey, raw_buf, FALSE); htob64(raw_buf, priv_key, len); len=big_to_bytes(sizeof(raw_buf), b_pubkey, raw_buf, FALSE); htob64(raw_buf, pub_key, len); iRet=1; } else iRet=0; ZeroMemory(raw_buf, sizeof(raw_buf)); mirkill(b_privkey); mirkill(b_pubkey); return iRet; }
void fish_init(void) { char iniPasswordHash[50], B64digest[50]; strcpy(iniPath, get_irssi_config()); // path to irssi config file strcpy(strrchr(iniPath, '/'), blow_ini); if (DH1080_Init() == FALSE) return; getIniValue("FiSH", "ini_password_Hash", "0", iniPasswordHash, sizeof(iniPasswordHash), iniPath); if (strlen(iniPasswordHash) == 43) { prompt_for_password(iniKey); calculate_password_key_and_hash(iniKey, iniKey, B64digest); if (strcmp(B64digest, iniPasswordHash) != 0) { printtext(NULL, NULL, MSGLEVEL_CRAP, "\002FiSH:\002 Wrong blow.ini password entered, try again..."); printtext(NULL, NULL, MSGLEVEL_CRAP, "\002FiSH module NOT loaded.\002"); return; } printtext(NULL, NULL, MSGLEVEL_CRAP, "\002FiSH:\002 Correct blow.ini password entered, lets go!"); } else { strcpy(iniKey, default_iniKey); printtext(NULL, NULL, MSGLEVEL_CRAP, "\002FiSH:\002 Using default password to decrypt blow.ini... Try /setinipw to set a custom password."); } signal_add_first("server sendmsg", (SIGNAL_FUNC) encrypt_msg); signal_add_first("message private", (SIGNAL_FUNC) decrypt_msg); signal_add_first("message public", (SIGNAL_FUNC) decrypt_msg); signal_add_first("message irc notice", (SIGNAL_FUNC) decrypt_notice); signal_add_first("message irc action", (SIGNAL_FUNC) decrypt_action); signal_add_first("message own_private", (SIGNAL_FUNC) format_msg); signal_add_first("message own_public", (SIGNAL_FUNC) format_msg); signal_add_first("channel topic changed", (SIGNAL_FUNC) decrypt_changed_topic); signal_add_first("message topic", (SIGNAL_FUNC) decrypt_topic); signal_add_first("server incoming", (SIGNAL_FUNC) raw_handler); signal_add("query created", (SIGNAL_FUNC) do_auto_keyx); signal_add("query nick changed", (SIGNAL_FUNC) query_nick_changed); command_bind("topic+", NULL, (SIGNAL_FUNC) cmd_crypt_topic); command_bind("notice+", NULL, (SIGNAL_FUNC) cmd_crypt_notice); command_bind("notfish", NULL, (SIGNAL_FUNC) cmd_crypt_notice); command_bind("me+", NULL, (SIGNAL_FUNC) cmd_crypt_action); command_bind("setkey", NULL, (SIGNAL_FUNC) cmd_setkey); command_bind("delkey", NULL, (SIGNAL_FUNC) cmd_delkey); command_bind("key", NULL, (SIGNAL_FUNC) cmd_key); command_bind("showkey", NULL, (SIGNAL_FUNC) cmd_key); command_bind("keyx", NULL, (SIGNAL_FUNC) cmd_keyx); command_bind("setinipw", NULL, (SIGNAL_FUNC) cmd_setinipw); command_bind("unsetinipw", NULL, (SIGNAL_FUNC) cmd_unsetinipw); command_bind("fishhelp", NULL, (SIGNAL_FUNC) cmd_helpfish); command_bind("helpfish", NULL, (SIGNAL_FUNC) cmd_helpfish); settings_add_bool_module("fish", "FiSH", "process_outgoing", 1); settings_add_bool_module("fish", "FiSH", "process_incoming", 1); settings_add_bool_module("fish", "FiSH", "auto_keyxchange", 1); settings_add_bool_module("fish", "FiSH", "nicktracker", 1); settings_add_str_module("fish", "FiSH", "mark_broken_block", " \002&\002"); settings_add_str_module("fish", "FiSH", "mark_encrypted", ""); settings_add_str_module("fish", "FiSH", "plain_prefix", "+p "); settings_add_int_module("fish", "FiSH", "mark_position", 0); printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE, "FiSH v1.00 - encryption module for irssi loaded! URL: https://github.com/falsovsky/FiSH-irssi\n" "Try /helpfish or /fishhelp for a short command overview"); module_register("fish", "core"); }